Skip to main content

Crate apollonius

Crate apollonius 

Source
Expand description

§Apollonius

Apollonius is a lightweight, N-dimensional Euclidean geometry library for Rust. It provides points, vectors, and geometric primitives (lines, segments, hyperspheres, hyperplanes, AABBs, triangles) with a unified intersection API and spatial queries, all built with const generics for type-safe 2D, 3D, or arbitrary dimension.

§Design goals

  • Pure geometry — No physics, no units; only shapes, distances, and intersections.
  • N-dimensional — Same types and traits work in 2D, 3D, or N-D via Point<T, N> and Vector<T, N>.
  • Minimal dependencies — Core logic depends only on num-traits; optional serde for serialization.

§Core types

ModuleTypes / traits
PointsPoint, Point2D, Point3D, MetricSquared, EuclideanMetric
VectorsVector, Vector2D, Vector3D, VectorMetricSquared, EuclideanVector
MatricesMatrix<T, N, Tag>, tags General, Isometry, Affine; traits MatrixTag, IsAffine, IsIsometry; AffineTransform
PrimitivesLine, Segment, Hypersphere (Circle, Sphere), Hyperplane, AABB, Triangle
TraitsSpatialRelation (closest_point, distance_to_point, contains), Bounded (aabb)
ResultsIntersectionResult (None, Tangent, Secant, Collinear, Single, HalfSpacePenetration)
Utilsclassify_to_zero, FloatSign for robust float comparison

For one-shot imports of the most used types, use prelude.

§Quick example

use apollonius::{Point, Vector, Line, Hypersphere, IntersectionResult};

let line = Line::new(Point::new([-5.0, 0.0]), Vector::new([1.0, 0.0]));
let sphere = Hypersphere::new(Point::new([0.0, 0.0]), 2.0);

match line.intersect_hypersphere(&sphere) {
    IntersectionResult::Secant(p1, p2) => { /* line pierces sphere at p1, p2 */ }
    IntersectionResult::Tangent(p) => { /* line touches sphere at p */ }
    _ => { /* no intersection */ }
}

§Features

  • serde — Enables Serialize / Deserialize for points, vectors, and primitives. Use with apollonius = { version = "...", features = ["serde"] }.

Re-exports§

pub use crate::algebra::angle::Angle;
pub use crate::algebra::matrix::Affine;
pub use crate::algebra::matrix::General;
pub use crate::algebra::matrix::Isometry;
pub use crate::algebra::matrix::IsAffine;
pub use crate::algebra::matrix::IsIsometry;
pub use crate::algebra::matrix::Matrix;
pub use crate::algebra::matrix::MatrixTag;
pub use crate::algebra::points::EuclideanMetric;
pub use crate::algebra::points::MetricSquared;
pub use crate::algebra::points::Point;
pub use crate::algebra::points::Point2D;
pub use crate::algebra::points::Point3D;
pub use crate::algebra::vectors::EuclideanVector;
pub use crate::algebra::vectors::Vector;
pub use crate::algebra::vectors::Vector2D;
pub use crate::algebra::vectors::Vector3D;
pub use crate::algebra::vectors::VectorMetricSquared;
pub use crate::primitives::aabb::AABB;
pub use crate::primitives::hyperplane::Hyperplane;
pub use crate::primitives::hypersphere::Circle;
pub use crate::primitives::hypersphere::Hypersphere;
pub use crate::primitives::hypersphere::Sphere;
pub use crate::primitives::line::Line;
pub use crate::primitives::segment::Segment;
pub use crate::primitives::triangle::Triangle;
pub use crate::primitives::Bounded;
pub use crate::primitives::IntersectionResult;
pub use crate::primitives::SpatialRelation;
pub use crate::space::AffineTransform;
pub use crate::utils::classify_to_zero;
pub use crate::utils::FloatSign;

Modules§

algebra
prelude
Prelude for convenient imports.
primitives
space
Affine transformations and their actions on geometry.
utils
Utilities for robust floating-point comparisons in geometric code.