[][src]Struct math2d::Matrix3x2f

#[repr(C)]
pub struct Matrix3x2f { pub a: f32, pub b: f32, pub c: f32, pub d: f32, pub x: f32, pub y: f32, }

2D Affine Transformation Matrix.

Mathematically you can think of this matrix as if it were the following:

[a, b, 0]
[c, d, 0]
[x, y, 1]

Composing matrices

Affine transformations are performed in "Row-Major" order. What this means, if you're familiar with linear algebra, is that when you compose multiple affine transformations together, the matrix representing the set of operations that should happen "first" must be the left hand operand of the multiplication operator.

This is also why points and vectors are the left-hand operand when multiplied with matrices.

Fields

a: f32

Horizontal scaling / cosine of rotation

b: f32

Vertical shear / sine of rotation

c: f32

Horizontal shear / negative sine of rotation

d: f32

Vertical scaling / cosine of rotation

x: f32

Horizontal translation (always orthogonal regardless of rotation)

y: f32

Vertical translation (always orthogonal regardless of rotation)

Methods

impl Matrix3x2f[src]

pub const IDENTITY: Matrix3x2f[src]

The 2D affine identity matrix.

pub fn new(parts: [[f32; 2]; 3]) -> Matrix3x2f[src]

Construct the matrix from an array of the row values.

pub fn from_slice(values: &[f32]) -> Matrix3x2f[src]

Constructs the matrix from a slice of 6 values as [a, b, c, d, x, y].

Panics if values does not contain exactly 6 elements.

pub fn from_tuple(values: (f32, f32, f32, f32, f32, f32)) -> Matrix3x2f[src]

Constructs the matrix from a tuple of 6 values as (a, b, c, d, x, y).

pub fn translation(trans: impl Into<Vector2f>) -> Matrix3x2f[src]

Creates an affine translation matrix that translates points by the passed vector. The linear part of the matrix is the identity.

Example Translation

Read More

pub fn scaling(
    scale: impl Into<Vector2f>,
    center: impl Into<Point2f>
) -> Matrix3x2f
[src]

Creates a scaling matrix that performs scaling around a specified point of origin. This is equivalent to translating the center point back to the origin, scaling around the origin by the scaling value, and then translating the center point back to its original location.

Example Scaling

Read More

pub fn rotation(angle: f32, center: impl Into<Point2f>) -> Matrix3x2f[src]

Creates a rotation matrix that performs rotation around a specified point of origin. This is equivalent to translating the center point back to the origin, rotating around the origin by the specified angle, and then translating the center point back to its original location.

Example Rotation

Read More

pub fn skew(
    angle_x: f32,
    angle_y: f32,
    center: impl Into<Point2f>
) -> Matrix3x2f
[src]

Creates a matrix that skews an object by a tangent angle around the center point.

Example Effect of Skewing

Read More

pub fn linear_transpose(&self) -> Matrix3x2f[src]

Computes the transpose of the linear part of this matrix i.e. swap(b, c).

pub fn determinant(&self) -> f32[src]

Returns the determinant of the matrix. Since this matrix is conceptually 3x3, and the bottom-right element is always 1, this value works out to be a * d - b * c.

pub fn is_invertible(&self) -> bool[src]

Determines if the inverse or try_inverse functions would succeed if called. A matrix is invertible if its determinant is nonzero. Since we're dealing with floats, we check that the absolute value of the determinant is greater than f32::EPSILON.

pub fn inverse(&self) -> Matrix3x2f[src]

Calculates the inverse of this matrix. Panics if the matrix is not invertible (see above).

pub fn try_inverse(&self) -> Option<Matrix3x2f>[src]

Calculates the inverse of the matrix. Returns None if the determinant is less than f32::EPSILON.

pub fn unchecked_inverse(&self, det: f32) -> Matrix3x2f[src]

Performs the inverse of the matrix without checking for invertibility.

WARNING: If this matrix is not invertible, you may get NaN or INF!

pub fn compose(
    scaling: impl Into<Vector2f>,
    rotation: f32,
    translation: impl Into<Vector2f>
) -> Matrix3x2f
[src]

Compose a matrix from a scaling, rotation, and translation value (combined in that order).

pub fn decompose(&self) -> Decomposition[src]

Decomposes a simple affine transformation into its scaling, rotation, and translation parts.

pub fn transform_point(&self, point: impl Into<Point2f>) -> Point2f[src]

A more explicit way to do point * matrix, while also allowing any type that may be converted into a Point2F with a From/Into impl.

pub fn transform_vector(&self, vec: impl Into<Vector2f>) -> Vector2f[src]

A more explicit way to do vec * matrix, while also allowing any type that may be converted into a Vector2F with a From/Into impl.

pub fn to_row_major(&self) -> [[f32; 3]; 3][src]

Returns this matrix as a 3x3 float array using the mathematical form described above.

pub fn to_column_major(&self) -> [[f32; 3]; 3][src]

Returns the matrix as a 3x3 float array in column major form, i.e. the transpose of the row-major version.

pub fn is_approx_eq(&self, other: &Matrix3x2f, epsilon: f32) -> bool[src]

Checks if two matrices are approximately equal given an epsilon value.

pub fn is_identity(&self) -> bool[src]

Checks if this matrix is equal to the identity matrix within 1e-5

Trait Implementations

impl Copy for Matrix3x2f[src]

impl PartialEq<Matrix3x2f> for Matrix3x2f[src]

impl Default for Matrix3x2f[src]

impl From<[[f32; 2]; 3]> for Matrix3x2f[src]

impl From<Matrix3x2f> for [[f32; 2]; 3][src]

impl From<Matrix3x2f> for [[f32; 3]; 3][src]

impl From<Matrix3x2f> for D2D_MATRIX_3X2_F[src]

impl From<D2D_MATRIX_3X2_F> for Matrix3x2f[src]

impl From<Matrix3x2f> for DWRITE_MATRIX[src]

impl From<DWRITE_MATRIX> for Matrix3x2f[src]

impl From<Matrix3x2f> for RowMatrix3x2<f32>[src]

impl Clone for Matrix3x2f[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for Matrix3x2f[src]

impl Mul<Matrix3x2f> for Matrix3x2f[src]

type Output = Matrix3x2f

The resulting type after applying the * operator.

impl Mul<Matrix3x2f> for Point2f[src]

type Output = Point2f

The resulting type after applying the * operator.

impl Mul<Matrix3x2f> for Vector2f[src]

type Output = Vector2f

The resulting type after applying the * operator.

impl Serialize for Matrix3x2f[src]

impl<'de> Deserialize<'de> for Matrix3x2f[src]

Auto Trait Implementations

impl Send for Matrix3x2f

impl Sync for Matrix3x2f

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]