use-geometry
Scaffolded Pre-1.0 crate surface with canonical RustUse-hosted API docs.
use-geometry is the supported RustUse crate for small 2D Euclidean geometry primitives, validated construction at API boundaries, and direct measurement helpers.
Purpose
Section titled “Purpose”The crate is designed to provide direct structs and standalone helpers for common geometry work without a large abstraction layer.
Current direction
Section titled “Current direction”use-geometry favors:
- direct 2D structs
- standalone measurement helpers
- validated construction at app boundaries
- predictable naming
- exact and tolerance-aware checks where ambiguity matters
- small APIs
- primitives that compose into larger geometry operations
Current surface areas include:
Point2Vector2Line2Segment2CircleTriangleAabb2- distance, midpoint, and orientation helpers
API reference
Section titled “API reference”Copyable source
Copy use-geometry into your codebase
Copy the direct 2D geometry crate as a complete source bundle or browse the file-level implementation from the docs UI.
Browse crate files
[package]
name = "use-geometry"
description = "Utility-first 2D geometry primitives for RustUse"
publish = true
authors.workspace = true
version.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
rust-version.workspace = true
readme = "README.md"
homepage = "https://github.com/RustUse/use-math"
documentation = "https://docs.rs/use-geometry"
keywords = ["math", "geometry", "2d", "vectors", "shapes"]
categories = ["mathematics", "science"]
[dev-dependencies]
proptest.workspace = true
[lints]
workspace = true
Triangle API
Section titled “Triangle API”Triangle remains a key primitive represented by three 2D vertices:
abc
The triangle surface keeps raw assembly and validated construction separate:
Triangle::new(a, b, c)for already-trusted pointsTriangle::try_new(a, b, c)for points that still need validationTriangle::area()Triangle::perimeter()Triangle::sides()Triangle::twice_signed_area()Triangle::twice_area()Triangle::is_degenerate()triangle_area(a, b, c)
Standalone helpers mirror the measurement surface that exists today:
triangle_twice_signed_area(a, b, c)triangle_twice_area(a, b, c)Triangle::is_degenerate_with_tolerance(tolerance)
Perimeter currently stays on the Triangle type itself; there is no standalone triangle_perimeter(...) helper.
Signed twice-area is the foundation for triangle measurement. It preserves orientation, avoids unnecessary division, and provides a direct base for area and degeneracy checks.
Degeneracy
Section titled “Degeneracy”Degeneracy occurs when a geometric value collapses into a lower-dimensional or invalid form.
For triangles, exact degeneracy means the three vertices are collinear and the signed twice-area is exactly zero. Triangle::is_degenerate() is that exact check.
f64::EPSILON is usually not a useful geometry tolerance. It is tied to floating-point precision around 1.0, not the coordinate scale of a triangle. Practical degeneracy checks should use a caller-provided tolerance chosen for the coordinate scale, input source, and expected numeric noise.
use-geometry keeps exact and tolerance-based degeneracy separate:
triangle.is_degenerate();triangle.is_degenerate_with_tolerance(tolerance)?;Use exact degeneracy when checking mathematical collapse. Use tolerance-based degeneracy when working with measured data, generated geometry, simulations, or CAD-like inputs.
Examples
Section titled “Examples”These examples describe the current API shape.
Validated construction at an API boundary
Section titled “Validated construction at an API boundary”use use_geometry::{Point2, Triangle};
let triangle = Triangle::try_new( Point2::try_new(0.0, 0.0).expect("valid vertex"), Point2::try_new(4.0, 0.0).expect("valid vertex"), Point2::try_new(0.0, 3.0).expect("valid vertex"),).expect("valid triangle");
assert_eq!(triangle.area(), 6.0);assert_eq!(triangle.perimeter(), 12.0);Working with trusted coordinates
Section titled “Working with trusted coordinates”use use_geometry::{Point2, Triangle};
let triangle = Triangle::new( Point2::new(0.0, 0.0), Point2::new(4.0, 0.0), Point2::new(0.0, 3.0),);
assert_eq!(triangle.sides(), [4.0, 5.0, 3.0]);Checking exact vs tolerance-based degeneracy
Section titled “Checking exact vs tolerance-based degeneracy”use use_geometry::{Point2, Triangle};
let triangle = Triangle::try_new( Point2::try_new(0.0, 0.0).expect("valid vertex"), Point2::try_new(4.0, 0.0).expect("valid vertex"), Point2::try_new(8.0, 1.0e-13).expect("valid vertex"),).expect("valid triangle");
assert!(!triangle.is_degenerate());assert_eq!(triangle.is_degenerate_with_tolerance(1.0e-12), Ok(true));Status
Section titled “Status”use-geometry is a scaffolded public crate in the RustUse docs surface. The API remains pre-1.0, and the RustUse-hosted generated rustdocs stay canonical while external crates.io and docs.rs pages remain staged.