Struct quicksilver::geom::Transform [−][src]
pub struct Transform(_);
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) * Transform::translate(Vector::new(0, -6));
and then applied to a Vector
transform * Vector::new(5, 5)
Methods
impl Transform
[src]
impl Transform
pub fn identity() -> Transform
[src]
pub fn identity() -> Transform
Create an identity transformation
pub fn rotate<T: Scalar>(angle: T) -> Transform
[src]
pub fn rotate<T: Scalar>(angle: T) -> Transform
Create a rotation transformation
pub fn translate(vec: Vector) -> Transform
[src]
pub fn translate(vec: Vector) -> Transform
Create a translation transformation
pub fn scale(vec: Vector) -> Transform
[src]
pub fn scale(vec: Vector) -> Transform
Create a scale transformation
pub fn into_matrix(self) -> Matrix3<f32>
[src]
pub fn into_matrix(self) -> Matrix3<f32>
Convert the Transform into an nalgebra Matrix3
pub fn inverse(&self) -> Transform
[src]
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, 5)); let inverse = transform.inverse(); let vector = Vector::new(10, 10); assert_eq!(vector, transform * inverse * vector); assert_eq!(vector, inverse * transform * vector);
Trait Implementations
impl Clone for Transform
[src]
impl Clone for Transform
fn clone(&self) -> Transform
[src]
fn clone(&self) -> Transform
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Copy for Transform
[src]
impl Copy for Transform
impl Debug for Transform
[src]
impl Debug for Transform
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Mul<Transform> for Transform
[src]
impl Mul<Transform> for Transform
Concat two transforms A and B such that A * B * v = A * (B * v)
type Output = Transform
The resulting type after applying the *
operator.
fn mul(self, other: Transform) -> Transform
[src]
fn mul(self, other: Transform) -> Transform
Performs the *
operation.
impl Mul<Vector> for Transform
[src]
impl Mul<Vector> for Transform
Transform a vector
type Output = Vector
The resulting type after applying the *
operator.
fn mul(self, other: Vector) -> Vector
[src]
fn mul(self, other: Vector) -> Vector
Performs the *
operation.
impl<T: Scalar> Mul<T> for Transform
[src]
impl<T: Scalar> Mul<T> 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.
type Output = Transform
The resulting type after applying the *
operator.
fn mul(self, other: T) -> Transform
[src]
fn mul(self, other: T) -> Transform
Performs the *
operation.
impl Display for Transform
[src]
impl Display for Transform
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Default for Transform
[src]
impl Default for Transform
impl PartialEq for Transform
[src]
impl PartialEq for Transform
fn eq(&self, other: &Transform) -> bool
[src]
fn eq(&self, other: &Transform) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl Eq for Transform
[src]
impl Eq for Transform
impl From<Matrix3<f32>> for Transform
[src]
impl From<Matrix3<f32>> for Transform