VectorSpace

Trait VectorSpace 

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

Source

const ZERO: Self

The zero vector, which is the identity of addition for the vector space type.

Required Associated Types§

Source

type Scalar: ScalarField

The scalar type of this vector space.

Provided Methods§

Source

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.

Implementors§

Source§

impl VectorSpace for DVec2

Source§

const ZERO: Self = DVec2::ZERO

Source§

type Scalar = f64

Source§

impl VectorSpace for DVec3

Source§

const ZERO: Self = DVec3::ZERO

Source§

type Scalar = f64

Source§

impl VectorSpace for DVec4

Source§

const ZERO: Self = DVec4::ZERO

Source§

type Scalar = f64

Source§

impl VectorSpace for Vec2

Source§

const ZERO: Self = Vec2::ZERO

Source§

type Scalar = f32

Source§

impl VectorSpace for Vec3

Source§

const ZERO: Self = Vec3::ZERO

Source§

type Scalar = f32

Source§

impl VectorSpace for Vec3A

Source§

const ZERO: Self = Vec3A::ZERO

Source§

type Scalar = f32

Source§

impl VectorSpace for Vec4

Source§

const ZERO: Self = Vec4::ZERO

Source§

type Scalar = f32

Source§

impl<F: ScalarField, V, W> VectorSpace for Sum<V, W>
where V: VectorSpace<Scalar = F>, W: VectorSpace<Scalar = F>,

Source§

const ZERO: Self

Source§

type Scalar = F

Source§

impl<T: ScalarField> VectorSpace for T

Source§

const ZERO: Self = Self::ZERO

Source§

type Scalar = T