pub trait Transform: Sized {
    type Scalar: FloatingScalar;

    // Required methods
    fn identity() -> Self;
    fn then(self, next: Self) -> Self;
    fn apply<V>(self, vector: V) -> V
       where V: Vector2<Scalar = Self::Scalar>;
    fn new_translate<V>(offset: V) -> Self
       where V: Vector2<Scalar = Self::Scalar>;
    fn new_rotate(radians: Self::Scalar) -> Self;
    fn new_scale<V>(ratio: V) -> Self
       where V: Vector2<Scalar = Self::Scalar>;

    // Provided methods
    fn but_first(self, prev: Self) -> Self { ... }
    fn translate<V>(self, offset: V) -> Self
       where V: Vector2<Scalar = Self::Scalar> { ... }
    fn rotate(self, radians: Self::Scalar) -> Self { ... }
    fn scale<V>(self, ratio: V) -> Self
       where V: Vector2<Scalar = Self::Scalar> { ... }
    fn zoom(self, ratio: Self::Scalar) -> Self { ... }
    fn rotate_about<V>(self, radians: Self::Scalar, pivot: V) -> Self
       where V: Vector2<Scalar = Self::Scalar> { ... }
}
Expand description

Trait for defining vector transformations

Transforms should be able to be chained without allocating extra space. The standard way to do this is with a matrix. For transforming 2D vectors, a 2×3 matrix can be used.

Required Associated Types§

source

type Scalar: FloatingScalar

The scalar type

Required Methods§

source

fn identity() -> Self

Create a new identity transform

source

fn then(self, next: Self) -> Self

Chain this transform with another

source

fn apply<V>(self, vector: V) -> Vwhere V: Vector2<Scalar = Self::Scalar>,

Apply this transform to a vector

source

fn new_translate<V>(offset: V) -> Selfwhere V: Vector2<Scalar = Self::Scalar>,

Create a translation from an offset vector

source

fn new_rotate(radians: Self::Scalar) -> Self

Create a rotation from a radian angle

source

fn new_scale<V>(ratio: V) -> Selfwhere V: Vector2<Scalar = Self::Scalar>,

Create a scaling from a ratio vector

Provided Methods§

source

fn but_first(self, prev: Self) -> Self

Chain another transform with this one

source

fn translate<V>(self, offset: V) -> Selfwhere V: Vector2<Scalar = Self::Scalar>,

Translate the transform

source

fn rotate(self, radians: Self::Scalar) -> Self

Rotate the transform

source

fn scale<V>(self, ratio: V) -> Selfwhere V: Vector2<Scalar = Self::Scalar>,

Scale the transform

source

fn zoom(self, ratio: Self::Scalar) -> Self

Uniformly scale the transform

source

fn rotate_about<V>(self, radians: Self::Scalar, pivot: V) -> Selfwhere V: Vector2<Scalar = Self::Scalar>,

Rotate the transform about a pivot

Implementors§

source§

impl<M, C> Transform for Mwhere M: Pair<Item = C>, C: Trio + Copy, C::Item: FloatingScalar,

§

type Scalar = <C as Trio>::Item