bevy_math::common_traits

Trait VectorSpace

Source
pub trait VectorSpace:
    Mul<f32, Output = Self>
    + Div<f32, Output = Self>
    + Add<Self, Output = Self>
    + Sub<Self, Output = Self>
    + Neg
    + Default
    + Debug
    + Clone
    + Copy {
    const ZERO: Self;

    // Provided method
    fn lerp(self, rhs: Self, t: f32) -> 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 f32
  • 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: f32, 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: f32, u, v: Self, (u + v) * a == u * a + v * a.
  • (Distributivity for scalar addition) For all a, b: f32, 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.

Provided Methods§

Source

fn lerp(self, rhs: Self, t: f32) -> 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.

Implementations on Foreign Types§

Source§

impl VectorSpace for f32

Source§

const ZERO: Self = 0f32

Implementors§

Source§

impl VectorSpace for Vec2

Source§

const ZERO: Self = Vec2::ZERO

Source§

impl VectorSpace for Vec3

Source§

const ZERO: Self = Vec3::ZERO

Source§

impl VectorSpace for Vec3A

Source§

const ZERO: Self = Vec3A::ZERO

Source§

impl VectorSpace for Vec4

Source§

const ZERO: Self = Vec4::ZERO