Crates.io | geoms |
lib.rs | geoms |
version | 0.0.1 |
source | src |
created_at | 2022-12-09 07:36:53.394598 |
updated_at | 2022-12-10 06:29:04.383848 |
description | Optimized geometry primitives for Microsoft platforms with the same memory layout as DirectX and Direct2D and types |
homepage | |
repository | https://github.com/connorpower/geoms/ |
max_upload_size | |
id | 733043 |
size | 35,650 |
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.
"d2d"
is enabled, then some primitives can be directly
converted into a Direct2D structures."win32"
is enabled, then some primitives can be directly
converted into a Win32 structures.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"] }
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);
Only a small number of primitives have been implemented as required for personal projects. The API is unstable and expected to change.
This project is licensed under the MIT license
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.