Theon is a Rust library that abstracts Euclidean spaces.

Build Status Documentation Crate

Geometric Traits

Theon provides geometric traits that abstract group theory, category theory, and linear algebra to 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, though 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 that appropriate geometric traits.

```rust use nalgebra::Point2;

use crate::query::{Aabb, Intersection, Ray, Unit}; use crate::space::{Basis, EuclideanSpace}; use crate::Converged;

type E2 = Point2;

let aabb = Aabb:: { origin: EuclideanSpace::origin(), extent: Converged::converged(1.0), }; let ray = Ray:: { origin: EuclideanSpace::fromxy(-1.0, 0.5), direction: Unit::tryfrominner(Basis::x()).unwrap(), }; asserteq!(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.