#[repr(C)]
pub struct Transform2D<T, Src, Dst> { pub m11: T, pub m12: T, pub m21: T, pub m22: T, pub m31: T, pub m32: T, /* private fields */ }
Expand description

A 2d transform represented by a column-major 3 by 3 matrix, compressed down to 3 by 2.

Transforms can be parametrized over the source and destination units, to describe a transformation from a space to another. For example, Transform2D<f32, WorldSpace, ScreenSpace>::transform_point4d takes a Point2D<f32, WorldSpace> and returns a Point2D<f32, ScreenSpace>.

Transforms expose a set of convenience methods for pre- and post-transformations. Pre-transformations (pre_* methods) correspond to adding an operation that is applied before the rest of the transformation, while post-transformations (then_* methods) add an operation that is applied after.

The matrix representation is conceptually equivalent to a 3 by 3 matrix transformation compressed to 3 by 2 with the components that aren’t needed to describe the set of 2d transformations we are interested in implicitly defined:

 | m11 m12 0 |   |x|   |x'|
 | m21 m22 0 | x |y| = |y'|
 | m31 m32 1 |   |1|   |w |

When translating Transform2D into general matrix representations, consider that the representation follows the column-major notation with column vectors.

The translation terms are m31 and m32.

Fields

m11: Tm12: Tm21: Tm22: Tm31: Tm32: T

Implementations

Create a transform specifying its components in using the column-major-column-vector matrix notation.

For example, the translation terms m31 and m32 are the last two parameters parameters.

use euclid::default::Transform2D;
let tx = 1.0;
let ty = 2.0;
let translation = Transform2D::new(
  1.0, 0.0,
  0.0, 1.0,
  tx,  ty,
);

Returns true is this transform is approximately equal to the other one, using T’s default epsilon value.

The same as ApproxEq::approx_eq() but available without importing trait.

Returns true is this transform is approximately equal to the other one, using a provided epsilon value.

The same as ApproxEq::approx_eq_eps() but available without importing trait.

Returns an array containing this transform’s terms.

The terms are laid out in the same order as they are specified in Transform2D::new, that is following the column-major-column-vector matrix notation.

For example the translation terms are found in the last two slots of the array.

Returns an array containing this transform’s terms transposed.

The terms are laid out in transposed order from the same order of Transform3D::new and Transform3D::to_array, that is following the row-major-column-vector matrix notation.

For example the translation terms are found at indices 2 and 5 in the array.

Equivalent to to_array with elements packed two at a time in an array of arrays.

Create a transform providing its components via an array of 6 elements instead of as individual parameters.

The order of the components corresponds to the column-major-column-vector matrix notation (the same order as Transform2D::new).

Equivalent to from_array with elements packed two at a time in an array of arrays.

The order of the components corresponds to the column-major-column-vector matrix notation (the same order as Transform3D::new).

Drop the units, preserving only the numeric value.

Tag a unitless value with units.

Returns the same transform with a different source unit.

Returns the same transform with a different destination unit.

Create a 3D transform from the current transform

Cast from one numeric representation to another, preserving the units.

Fallible cast from one numeric representation to another, preserving the units.

Create an identity matrix:

1 0
0 1
0 0

Methods for combining generic transformations

Returns the multiplication of the two matrices such that mat’s transformation applies after self’s transformation.

Methods for creating and combining translation transformations

Create a 2d translation transform:

1 0
0 1
x y

Applies a translation after self’s transformation and returns the resulting transform.

Applies a translation before self’s transformation and returns the resulting transform.

Methods for creating and combining rotation transformations

Returns a rotation transform.

Applies a rotation after self’s transformation and returns the resulting transform.

Applies a rotation before self’s transformation and returns the resulting transform.

Methods for creating and combining scale transformations

Create a 2d scale transform:

x 0
0 y
0 0

Applies a scale after self’s transformation and returns the resulting transform.

Applies a scale before self’s transformation and returns the resulting transform.

Methods for apply transformations to objects

Returns the given point transformed by this transform.

Returns the given vector transformed by this matrix.

Returns a rectangle that encompasses the result of transforming the given rectangle by this transform.

Returns a box that encompasses the result of transforming the given box by this transform.

Computes and returns the determinant of this transform.

Returns whether it is possible to compute the inverse transform.

Returns the inverse transform if possible.

Trait Implementations

Returns true is this transform is approximately equal to the other one, using a provided epsilon value.

Default epsilon value

Returns true is this object is approximately equal to the other one, using the approx_epsilon() epsilon value. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the identity transform.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

Converts this type into the (usually inferred) input type.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.