Affine

Trait Affine 

Source
pub trait Affine: Sized {
    type Space;
    type Diff: Linear;

    const DIM: usize;

    // Required methods
    fn add(&self, diff: &Self::Diff) -> Self;
    fn sub(&self, other: &Self) -> Self::Diff;

    // Provided method
    fn combine<S: Copy, const N: usize>(
        weights: &[S; N],
        points: &[Self; N],
    ) -> Self
       where Self: Clone,
             Self::Diff: Linear<Scalar = S> { ... }
}
Expand description

Trait for types representing elements of an affine space.

TODO More documentation, definition of affine space

Required Associated Constants§

Source

const DIM: usize

The dimension of Self.

Required Associated Types§

Source

type Space

The space that Self is the element type of.

Source

type Diff: Linear

The (signed) difference of two values of Self. Diff must have the same dimension as Self.

Required Methods§

Source

fn add(&self, diff: &Self::Diff) -> Self

Adds diff to self component-wise.

add is commutative and associative.

Source

fn sub(&self, other: &Self) -> Self::Diff

Subtracts other from self, returning the (signed) difference.

sub is anti-commutative: v.sub(w) == w.sub(v).neg().

Provided Methods§

Source

fn combine<S: Copy, const N: usize>( weights: &[S; N], points: &[Self; N], ) -> Self
where Self: Clone, Self::Diff: Linear<Scalar = S>,

Returns an affine combination of points.

Given a list of weights (w1, …, wn) and points (P1, …, Pn), returns

w1 * P1 + … + wn * Pn

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

Source§

const DIM: usize = 1usize

Source§

type Space = ()

Source§

type Diff = f32

Source§

fn add(&self, other: &f32) -> f32

Source§

fn sub(&self, other: &f32) -> f32

Source§

impl Affine for i32

Source§

const DIM: usize = 1usize

Source§

type Space = ()

Source§

type Diff = i32

Source§

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

Source§

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

Source§

impl Affine for u32

Source§

const DIM: usize = 1usize

Source§

type Space = ()

Source§

type Diff = i32

Source§

fn add(&self, rhs: &i32) -> u32

Source§

fn sub(&self, rhs: &u32) -> i32

Implementors§

Source§

impl Affine for Angle

Source§

const DIM: usize = 1usize

Source§

type Space = ()

Source§

type Diff = Angle

Source§

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

Source§

const DIM: usize = DIM

Source§

type Space = Sp

Source§

type Diff = Vector<[Sc; DIM], Sp>

Source§

impl<ScSelf, ScDiff, Sp, const N: usize> Affine for Point<[ScSelf; N], Sp>
where ScSelf: Affine<Diff = ScDiff> + Copy, ScDiff: Linear<Scalar = ScDiff> + Copy,

Source§

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

Source§

const DIM: usize = DIM

Source§

type Space = Sp

Source§

type Diff = Color<[f32; DIM], Sp>

Source§

impl<Sp, const DIM: usize> Affine for Color<[u8; DIM], Sp>

Source§

const DIM: usize = DIM

Source§

type Space = Sp

Source§

type Diff = Vector<[i32; DIM], Sp>