Trait vector2math::Transform
source · 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§
sourcetype Scalar: FloatingScalar
type Scalar: FloatingScalar
The scalar type
Required Methods§
sourcefn apply<V>(self, vector: V) -> Vwhere
V: Vector2<Scalar = Self::Scalar>,
fn apply<V>(self, vector: V) -> Vwhere V: Vector2<Scalar = Self::Scalar>,
Apply this transform to a vector
sourcefn new_translate<V>(offset: V) -> Selfwhere
V: Vector2<Scalar = Self::Scalar>,
fn new_translate<V>(offset: V) -> Selfwhere V: Vector2<Scalar = Self::Scalar>,
Create a translation from an offset vector
sourcefn new_rotate(radians: Self::Scalar) -> Self
fn new_rotate(radians: Self::Scalar) -> Self
Create a rotation from a radian angle
Provided Methods§
sourcefn translate<V>(self, offset: V) -> Selfwhere
V: Vector2<Scalar = Self::Scalar>,
fn translate<V>(self, offset: V) -> Selfwhere V: Vector2<Scalar = Self::Scalar>,
Translate the transform
sourcefn scale<V>(self, ratio: V) -> Selfwhere
V: Vector2<Scalar = Self::Scalar>,
fn scale<V>(self, ratio: V) -> Selfwhere V: Vector2<Scalar = Self::Scalar>,
Scale the transform
sourcefn rotate_about<V>(self, radians: Self::Scalar, pivot: V) -> Selfwhere
V: Vector2<Scalar = Self::Scalar>,
fn rotate_about<V>(self, radians: Self::Scalar, pivot: V) -> Selfwhere V: Vector2<Scalar = Self::Scalar>,
Rotate the transform about a pivot