2 releases
0.0.1 | Dec 10, 2022 |
---|---|
0.0.0 | Dec 9, 2022 |
#5 in #direct2d
32KB
478 lines
geoms
Geometry for Microsoft platforms - a set of geometry primitives with memory layouts optimized for native APIs (Win32, Direct2D, and Direct3D).
The goal of this crate is to provide an idiomatic but zero-cost interface to
common geometric types used in Microsoft graphics APIs. Integration with the
excellent ::num_traits
crate allows for geometric types to be represented
by
arbitrary numeric types, and allows conversion between different numeric
representations of entire higher-level types.
Optional Features
- If feature
"d2d"
is enabled, then some primitives can be directly converted into a Direct2D structures. - If feature
"win32"
is enabled, then some primitives can be directly converted into a Win32 structures.
Usage
To use geoms
, add the following to your Cargo.toml
:
[dependencies]
geoms = "0.0.1"
To enable optional conversions to native Microsoft types, activate the appropriate features. E.g. for Direct2D support:
[dependencies]
geoms = { version = "0.0.1", features = ["d2d"] }
Example
use ::geoms::d2::{Rect2D, Point2D, Size2D};
use ::windows::Win32::Graphics::Direct2D::Common::D2D_RECT_F;
// Construct our Rust rectangle, 100x20 pixels at point 10,10
let rect = Rect2D::with_size_and_origin(
Size2D { width: 100.0, height: 20.0 },
Point2D { x: 10.0, y: 10.0 },
);
// Convert our Rust rectangle into a Direct2D rectangle. This merely
// transmutes under the hood as the memory layouts are the same.
let d2d_rect: D2D_RECT_F = rect.into();
// Confirm our Direct2D rectangle has the expected properties.
assert_eq!(rect.left, 10.0);
assert_eq!(rect.right, 110.0);
// Cast our entire rect to a u32 representation of the same primitive:
let u_rect = rect.cast::<u32>();
assert_eq!(u_rect.left, 10);
assert_eq!(u_rect.right, 110);
Current Status
Only a small number of primitives have been implemented as required for personal projects. The API is unstable and expected to change.
License
This project is licensed under the MIT license
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this repository by you, shall be licensed as MIT, without any additional terms or conditions.
Dependencies
~0.1–38MB
~527K SLoC