Trait bevy::math::VectorSpace

pub trait VectorSpace: Mul<f32, Output = Self> + Div<f32, Output = Self> + Add<Output = Self> + Sub<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§

const ZERO: Self

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

Provided Methods§

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 interpolating outside of the interval [0,1] is allowed.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

§

impl VectorSpace for f32

§

const ZERO: f32 = 0f32

Implementors§

§

impl VectorSpace for Laba

§

const ZERO: Laba = _

§

impl VectorSpace for LinearRgba

§

const ZERO: LinearRgba = _

§

impl VectorSpace for Oklaba

§

const ZERO: Oklaba = _

§

impl VectorSpace for Srgba

§

const ZERO: Srgba = _

§

impl VectorSpace for Xyza

§

const ZERO: Xyza = _

§

impl VectorSpace for Vec2

§

const ZERO: Vec2 = Vec2::ZERO

§

impl VectorSpace for Vec3

§

const ZERO: Vec3 = Vec3::ZERO

§

impl VectorSpace for Vec3A

§

const ZERO: Vec3A = Vec3A::ZERO

§

impl VectorSpace for Vec4

§

const ZERO: Vec4 = Vec4::ZERO