Crate linear_isomorphic

Source
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§

prelude

Traits§

ArithmeticType
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.
InnerSpace
RealField
Trait representing a type which can be multiplied by, i.e. a scalar.
RefIterable
VMul
VectorSpace
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.