Crate geoms

source ·
Expand description


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.


To use geoms, add the following to your Cargo.toml:

geoms = "0.0.1"

To enable optional conversions to native Microsoft types, activate the appropriate features. E.g. for Direct2D support:

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);

Current Status

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.


2-Dimensional types optimized for Win32 and Direct2D APIs with some rusty conveniences.