Expand description
Set of traits to abstract over linear algebra types.
Provides an abstraction over vector-like types. This makes it easier to implement generic math algorithms.
§Example
use linear_isomorphic::*;
pub fn point_segment_distance<Vec>(start: &Vec, end: &Vec, point: &Vec) -> f32
where
Vec: VectorSpace<Scalar = f32>,
{
let dir = end.clone() - start.clone();
let t = (point.clone() - start.clone()).dot(&dir) / dir.norm_squared();
let t = t.clamp(0.0, 1.0);
let closest = start.clone() + dir * t;
(closest - point.clone()).norm()
}
Modules§
Traits§
- Arithmetic
Type - Trait representing a type isomorphic to a lin alg vector in the most basic sense. That is, it supports addition and scalar multiplication. Useful to write functions that work on arithmetic types.
- Inner
Space - Real
Field - Trait representing a type which can be multiplied by, i.e. a scalar.
- RefIterable
- VMul
- Vector
Space - Extension of the
ArithmeticType
trait. It also demands that the type is indexable and can be default initialised (default initialisation is assumed to be equivalent to the 0 vector). Additionally, provides methods common to vectors.