#graphics #geometry

theon

Abstraction of Euclidean spaces

2 releases

0.0.1 May 31, 2019
0.0.0 May 18, 2019

#231 in #geometry

MIT license

73KB
2K SLoC

Theon is a Rust library that abstracts Euclidean spaces.

Build Status Documentation Crate

Geometric Traits

Theon provides geometric traits that model Euclidean spaces. These traits are not always mathematically rigorous, but this allows them to be implemented for many types. Most features are limited to two- and three-dimensional Euclidean spaces, but traits tend to be generic with respect to dimensionality.

Theon uses a bring-your-own-types model, wherein a crate owner can use features of Theon by implementing certain traits for their types. Theon also provides optional implementations for commonly used crates in the Rust ecosystem, including cgmath, mint, and nalgebra. These implementations can be enabled using Cargo features.

Feature Default Crate Support
geometry-cgmath No cgmath Complete
geometry-mint No mint Partial
geometry-nalgebra Yes nalgebra Complete

Spatial Queries

Geometric queries can be performed using any types that implement the appropriate geometric traits.

use nalgebra::Point2;
use theon::query::{Aabb, Intersection, Ray, Unit};
use theon::space::{Basis, EuclideanSpace};
use theon::Converged;

type E2 = Point2<f64>;

let aabb = Aabb::<E2> {
    origin: EuclideanSpace::origin(),
    extent: Converged::converged(1.0),
};
let ray = Ray::<E2> {
    origin: EuclideanSpace::from_xy(-1.0, 0.5),
    direction: Unit::try_from_inner(Basis::x()).unwrap(),
};
assert_eq!(Some((1.0, 2.0)), ray.intersection(&aabb));
assert_eq!(None, ray.reverse().intersection(&aabb));

In the above example, it is possible to replace the E2 type definition with types from cgmath or any other type that implements EuclideanSpace and the necessary operational traits.

LAPACK

Some queries require solving linear systems of arbitrary and non-trivial size. To support these queries, the array feature depends on ndarray and LAPACK. For example, Plane::from_points is enabled by the array feature and computes a best-fit plane using a singular value decomposition.

These operations are exposed in terms of geometric traits and the implementing types that are being used.

The array feature only supports Linux at this time.

Dependencies

~1.1–3MB
~67K SLoC