Transform

Struct Transform 

Source
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

Source

pub const IDENTITY: Transform

The identity transformation

Source

pub fn rotate(angle: f32) -> Transform

Create a rotation transformation

Source

pub fn translate(vec: Vector) -> Transform

Create a translation transformation

Source

pub fn scale(vec: Vector) -> Transform

Create a scale transformation

Source

pub fn orthographic(rect: Rectangle) -> Transform

Create an orthographic projection

Source

pub fn then(self, next: Transform) -> Transform

Source

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

Note you probably want Mul to combine Transforms. Addition is only useful in less common use cases like interpolation

Source§

type Output = Transform

The resulting type after applying the + operator.
Source§

fn add(self, other: Transform) -> Transform

Performs the + operation. Read more
Source§

impl AddAssign for Transform

Uses the impl Add<Transform> for Transform internally

Source§

fn add_assign(&mut self, other: Transform)

Performs the += operation. Read more
Source§

impl Clone for Transform

Source§

fn clone(&self) -> Transform

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Transform

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Transform

Source§

fn default() -> Transform

Returns the “default value” for a type. Read more
Source§

impl Display for Transform

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<[[f32; 3]; 3]> for Transform

Source§

fn from(array: [[f32; 3]; 3]) -> Transform

Converts to this type from the input type.
Source§

impl From<RowMatrix3<f32>> for Transform

Source§

fn from(mat: RowMatrix3<f32>) -> Transform

Converts to this type from the input type.
Source§

impl From<Transform> for [[f32; 3]; 3]

Source§

fn from(trans: Transform) -> [[f32; 3]; 3]

Converts to this type from the input type.
Source§

impl From<Transform> for RowMatrix3<f32>

Source§

fn from(trans: Transform) -> RowMatrix3<f32>

Converts to this type from the input type.
Source§

impl Mul<Vector> for Transform

Transform a vector

Source§

type Output = Vector

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vector) -> Vector

Performs the * operation. Read more
Source§

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§

type Output = Transform

The resulting type after applying the * operator.
Source§

fn mul(self, other: f32) -> Transform

Performs the * operation. Read more
Source§

impl Mul for Transform

Concat two transforms A and B such that A * B * v = A * (B * v)

Source§

type Output = Transform

The resulting type after applying the * operator.
Source§

fn mul(self, other: Transform) -> Transform

Performs the * operation. Read more
Source§

impl MulAssign<f32> for Transform

Uses the impl Mul<f32> for Transform internally.

Source§

fn mul_assign(&mut self, other: f32)

Performs the *= operation. Read more
Source§

impl MulAssign for Transform

Uses the impl Mul<Transform> for Transform internally.

Source§

fn mul_assign(&mut self, other: Transform)

Performs the *= operation. Read more
Source§

impl PartialEq for Transform

Source§

fn eq(&self, other: &Transform) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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§

type Output = Transform

The resulting type after applying the - operator.
Source§

fn sub(self, other: Transform) -> Transform

Performs the - operation. Read more
Source§

impl SubAssign for Transform

Uses the impl Sub<Transform> for Transform internally

Source§

fn sub_assign(&mut self, other: Transform)

Performs the -= operation. Read more
Source§

impl Copy for Transform

Source§

impl Eq for Transform

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.