pub struct Transform(/* private fields */);
Expand description
A 2D transformation represented by a matrix
Transforms can be composed together through matrix multiplication, and are applied to Vectors through multiplication, meaning the notation used is the ‘*’ operator. A property of matrix multiplication is that for some matrices A, B, C and vector V is
Transform = A * B * C
Transform * V = A * (B * (C * V))
This property allows encoding multiple transformations in a single matrix. A transformation that involves rotating a shape 30 degrees and then moving it six units up could be written as
use quicksilver::geom::{Transform, Vector};
let transform = Transform::rotate(30.0) * Transform::translate(Vector::new(0.0, -6.0));
and then applied to a Vector
transform * Vector::new(5.0, 5.0)
Implementations§
Source§impl Transform
impl Transform
Sourcepub fn orthographic(rect: Rectangle) -> Transform
pub fn orthographic(rect: Rectangle) -> Transform
Create an orthographic projection
pub fn then(self, next: Transform) -> Transform
Sourcepub fn inverse(&self) -> Transform
pub fn inverse(&self) -> Transform
Find the inverse of a Transform
A transform’s inverse will cancel it out when multplied with it, as seen below:
let transform = Transform::translate(Vector::new(4.0, 5.0));
let inverse = transform.inverse();
let vector = Vector::new(10.0, 10.0);
assert_eq!(vector, transform * inverse * vector);
assert_eq!(vector, inverse * transform * vector);
Trait Implementations§
Source§impl Add for Transform
Add the values of two transforms together
impl Add for Transform
Add the values of two transforms together
Note you probably want Mul to combine Transforms. Addition is only useful in less common use cases like interpolation
Source§impl AddAssign for Transform
Uses the impl Add<Transform> for Transform
internally
impl AddAssign for Transform
Uses the impl Add<Transform> for Transform
internally
Source§fn add_assign(&mut self, other: Transform)
fn add_assign(&mut self, other: Transform)
+=
operation. Read moreSource§impl Mul<f32> for Transform
Scale all of the internal values of the Transform matrix
impl Mul<f32> for Transform
Scale all of the internal values of the Transform matrix
Note this will NOT scale vectors multiplied by this transform, and generally you shouldn’t need to use this.
Source§impl MulAssign<f32> for Transform
Uses the impl Mul<f32> for Transform
internally.
impl MulAssign<f32> for Transform
Uses the impl Mul<f32> for Transform
internally.
Source§fn mul_assign(&mut self, other: f32)
fn mul_assign(&mut self, other: f32)
*=
operation. Read moreSource§impl MulAssign for Transform
Uses the impl Mul<Transform> for Transform
internally.
impl MulAssign for Transform
Uses the impl Mul<Transform> for Transform
internally.
Source§fn mul_assign(&mut self, other: Transform)
fn mul_assign(&mut self, other: Transform)
*=
operation. Read moreSource§impl Sub for Transform
Subtract the values of one transform from another
impl Sub for Transform
Subtract the values of one transform from another
Note you probably want Mul to combine Transforms. Subtraction is only useful in less common use cases like interpolation
Source§impl SubAssign for Transform
Uses the impl Sub<Transform> for Transform
internally
impl SubAssign for Transform
Uses the impl Sub<Transform> for Transform
internally
Source§fn sub_assign(&mut self, other: Transform)
fn sub_assign(&mut self, other: Transform)
-=
operation. Read more