pub trait VectorSpace:
Mul<Self::Scalar, Output = Self>
+ Div<Self::Scalar, Output = Self>
+ Add<Self, Output = Self>
+ Sub<Self, Output = Self>
+ Neg<Output = Self>
+ Default
+ Debug
+ Clone
+ Copy {
type Scalar: ScalarField;
const ZERO: Self;
// Provided method
fn lerp(self, rhs: Self, t: Self::Scalar) -> Self { ... }
}Expand description
A type that supports the mathematical operations of a real vector space, irrespective of dimension. In particular, this means that the implementing type supports:
- Scalar multiplication and division on the right by elements of
Self::Scalar - Negation
- Addition and subtraction
- Zero
Within the limitations of floating point arithmetic, all the following are required to hold:
- (Associativity of addition) For all
u, v, w: Self,(u + v) + w == u + (v + w). - (Commutativity of addition) For all
u, v: Self,u + v == v + u. - (Additive identity) For all
v: Self,v + Self::ZERO == v. - (Additive inverse) For all
v: Self,v - v == v + (-v) == Self::ZERO. - (Compatibility of multiplication) For all
a, b: Self::Scalar,v: Self,v * (a * b) == (v * a) * b. - (Multiplicative identity) For all
v: Self,v * 1.0 == v. - (Distributivity for vector addition) For all
a: Self::Scalar,u, v: Self,(u + v) * a == u * a + v * a. - (Distributivity for scalar addition) For all
a, b: Self::Scalar,v: Self,v * (a + b) == v * a + v * b.
Note that, because implementing types use floating point arithmetic, they are not required to actually
implement PartialEq or Eq.
Required Associated Constants§
Required Associated Types§
Sourcetype Scalar: ScalarField
type Scalar: ScalarField
The scalar type of this vector space.
Provided Methods§
Sourcefn lerp(self, rhs: Self, t: Self::Scalar) -> Self
fn lerp(self, rhs: Self, t: Self::Scalar) -> Self
Perform vector space linear interpolation between this element and another, based
on the parameter t. When t is 0, self is recovered. When t is 1, rhs
is recovered.
Note that the value of t is not clamped by this function, so extrapolating outside
of the interval [0,1] is allowed.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.