Skip to main content

Crate math_geometry_2d

Crate math_geometry_2d 

Source
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.

  • video-analysis-core
  • image-analysis-processing
  • video-analysis-posture

Modules§

surface
Library-owned runtime surface for math-geometry-2d.

Structs§

Affine2
Data type for affine2.
Bounds2f
Data type for bounds2f.
BroadPhase2Config
Options for 2D broad-phase collision detection.
BroadPhaseStats
Runtime statistics for broad-phase collision detection.
Circle2
Data type for circle2.
CollisionPair
Data type for a broad-phase collision pair.
LineIntersection2
Intersection details for two finite 2D line segments.
LineSegment2
Data type for line segment2.
NormalizedPoint2
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.
SpatialHashGrid2
Reusable spatial hash grid for 2D broad-phase collision detection.
Vector2f
Data type for vector2f.

Enums§

BroadPhase2Strategy
Strategy used for broad-phase 2D collision detection.
GeometryError
Error type for validated 2D geometry contracts.
SpatialCellSize2
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.