geoms

Crates.iogeoms
lib.rsgeoms
version0.0.1
sourcesrc
created_at2022-12-09 07:36:53.394598
updated_at2022-12-10 06:29:04.383848
descriptionOptimized geometry primitives for Microsoft platforms with the same memory layout as DirectX and Direct2D and types
homepage
repositoryhttps://github.com/connorpower/geoms/
max_upload_size
id733043
size35,650
Connor Power (connorpower)

documentation

README

geoms

Documentation MIT licensed Build Status

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.

→ Documentation

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.

Commit count: 151

cargo fmt