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: VectorLike<Scalar = f32>,
{
let dir = *end - *start;
let t = (*point - *start).dot(&dir) / dir.norm_squared();
let t = t.clamp(0.0, 1.0);
let closest = *start + dir * t;
(closest - *point).norm()
}
Traits§
- 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.
- Trait representing a type which can be multiplied by, i.e. a scalar.
- Extension of the
LinAlg
trait. It also demands that the type is indexable and can be default initialized (default initialization is assumed to be equivalent to the 0 vector). Additionally, provides methods common to vectors.