Linear

Trait Linear 

Source
pub trait Linear: Affine<Diff = Self> {
    type Scalar: Sized;

    // Required methods
    fn zero() -> Self;
    fn mul(&self, scalar: Self::Scalar) -> Self;

    // Provided method
    fn neg(&self) -> Self { ... }
}
Expand description

Trait for types representing elements of a linear space (vector space).

A Linear type is a type that is Affine and additionally satisfies the following conditions:

  • The difference type Diff is equal to Self
  • The type has an additive identity, returned by the zero method
  • Every value has an additive inverse, returned by the neg method

TODO More documentation

Required Associated Types§

Source

type Scalar: Sized

The scalar type associated with Self.

Required Methods§

Source

fn zero() -> Self

Returns the additive identity of Self.

Source

fn mul(&self, scalar: Self::Scalar) -> Self

Multiplies all components of self by scalar.

mul is commutative and associative, and distributes over add and sub (up to rounding errors):

v.mul(w) == w.mul(v);
v.mul(w).mul(x) == v.mul(w.mul(x));
v.mul(a).add(&w.mul(a)) == v.add(&w).mul(a);
v.mul(a).sub(&w.mul(a)) == v.add(&w).sub(&a);

Provided Methods§

Source

fn neg(&self) -> Self

Returns the additive inverse of self.

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 Linear for f32

Source§

type Scalar = f32

Source§

fn zero() -> f32

Source§

fn mul(&self, rhs: f32) -> f32

Source§

impl Linear for i32

Source§

type Scalar = i32

Source§

fn zero() -> i32

Source§

fn mul(&self, rhs: i32) -> i32

Implementors§

Source§

impl Linear for Angle

Source§

impl<Sc, Sp, const DIM: usize> Linear for Vector<[Sc; DIM], Sp>
where Sc: Linear<Scalar = Sc> + Copy,

Source§

type Scalar = Sc

Source§

impl<Sp, const DIM: usize> Linear for Color<[f32; DIM], Sp>