Expand description
§math-geometry-2d
Shared 2D geometry contracts for multimodal image, video, and layout processing. This crate is part of the Analytical Math Crates family.
§Highlights
- Checked pixel and normalized 2D primitives
- Rectangle intersection, union, and clamping helpers
- Rectangle IoU and directional overlap ratios
- Finite line-segment intersection parameters
- Affine transforms with compose and invert support
- Polygon area, centroid, winding, containment, and bounds helpers
- Normalized and pixel coordinate conversion helpers
§Example
use math_geometry_2d::{Affine2, NormalizedPoint2, RectU32, Size2u};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let rect = RectU32::new(10, 12, 32, 24)?;
let point = NormalizedPoint2::new(0.5, 0.5)?.to_pixel_point(Size2u::new(64, 48)?);
let shifted = Affine2::translation(4.0, -2.0).apply_point(rect.center_f32());
assert_eq!(point.x, 32);
assert!(shifted.x > 0.0);
Ok(())
}§Package surface
Primary workflow: geometry.bounds.
Workflow operations:
geometry.bounds: Computes 2D bounds, dimensions, and center for finite points.geometry.transform: Applies an affine transform to finite 2D points and returns transformed bounds.geometry.intersections: Checks every rectangle pair and returns intersection rectangles when present.geometry.overlap: Computes intersection area, IoU, and directional overlap ratios for two rectangles.geometry.segmentIntersection: Computes the point and segment parameters for two finite 2D segment intersections.geometry.polygonSummary: Reports area, winding, centroid, and bounds for a finite 2D polygon.
Debug operations:
describe: inspect package metadata and runtime support.
Runtime support: library, CLI, server, and WASM wrappers expose these operations.
Run the primary workflow through the CLI:
cargo run -p moritzbrantner-math-geometry-2d-cli -- run \
--operation geometry.bounds \
--json '{"points":[[0.0,1.0],[2.0,3.0]]}'Successful responses use the shared package-surface shape with operation,
title, message, summary, and result. Default surface calls are
deterministic, local-first, and do not download models, write persistent files,
or execute external tools unless an operation explicitly documents native or
external-tool execution.
§Related crates
video-analysis-coreimage-analysis-processingvideo-analysis-posture
Modules§
- surface
- Library-owned runtime surface for
math-geometry-2d.
Structs§
- Affine2
- Data type for affine2.
- Bounds2f
- Data type for bounds2f.
- Broad
Phase2 Config - Options for 2D broad-phase collision detection.
- Broad
Phase Stats - Runtime statistics for broad-phase collision detection.
- Circle2
- Data type for circle2.
- Collision
Pair - Data type for a broad-phase collision pair.
- Line
Intersection2 - Intersection details for two finite 2D line segments.
- Line
Segment2 - Data type for line segment2.
- Normalized
Point2 - Data type for normalized point2.
- Point2f
- Data type for point2f.
- Point2i
- Data type for point2i.
- Polygon2f
- Data type for polygon2f.
- RectF32
- Data type for rect f32.
- RectU32
- Data type for rect u32.
- Size2u
- Data type for size2u.
- Spatial
Hash Grid2 - Reusable spatial hash grid for 2D broad-phase collision detection.
- Vector2f
- Data type for vector2f.
Enums§
- Broad
Phase2 Strategy - Strategy used for broad-phase 2D collision detection.
- Geometry
Error - Error type for validated 2D geometry contracts.
- Spatial
Cell Size2 - Cell size selection for 2D spatial hashing.
Functions§
- broad_
phase_ pairs_ 2d - Returns broad-phase candidate pairs for 2D rectangles.
Type Aliases§
- Result
- Result type for 2D geometry operations.