| Crates.io | math2 |
| lib.rs | math2 |
| version | 0.0.2 |
| created_at | 2025-06-09 11:11:39.874991+00 |
| updated_at | 2025-06-10 09:29:13.930367+00 |
| description | Geometry, layout and rasterization utilities powering the Grida canvas |
| homepage | https://grida.co |
| repository | https://github.com/gridaco/grida |
| max_upload_size | |
| id | 1705790 |
| size | 133,996 |
math2 is a collection of lightweight geometry and math utilities used across the Grida canvas engine. It includes helpers for working with vectors, rectangles, affine transforms, rasterization and many other 2D operations.
This crate is a direct port of the original TypeScript grida-cmath library. The APIs mostly follow the functional style of the source project.
Add the crate to your Cargo.toml:
[dependencies]
math2 = "0.0.1"
use math2::{Rectangle, vector2, rect_transform};
use math2::transform::AffineTransform;
let rect = Rectangle { x: 0.0, y: 0.0, width: 100.0, height: 50.0 };
let transform = AffineTransform::translate(10.0, 20.0);
let moved = rect_transform(rect, &transform);
assert_eq!(moved.x, 10.0);
assert_eq!(moved.y, 20.0);
The current code mirrors the functional API of the original TypeScript version. Some potential refinements for a more idiomatic Rust API include:
Vector2 and Rectangle.Add, Sub, etc.) for math types.no_std builds.Licensed under the MIT license.