Struct Matrix3x2f

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

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)

Implementations§

Source§

impl Matrix3x2f

Source

pub const IDENTITY: Matrix3x2f

The 2D affine identity matrix.

Source

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

Construct the matrix from an array of the row values.

Source

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

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.

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Example Effect of Skewing

Read More

Source

pub fn linear_transpose(&self) -> Matrix3x2f

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

Source

pub fn determinant(&self) -> f32

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.

Source

pub fn is_invertible(&self) -> bool

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.

Source

pub fn inverse(&self) -> Matrix3x2f

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

Source

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

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

Source

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

Performs the inverse of the matrix without checking for invertibility.

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

Source

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

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

Source

pub fn decompose(&self) -> Decomposition

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

Source

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

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.

Source

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

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.

Source

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

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

Source

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

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

Source

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

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

Source

pub fn is_identity(&self) -> bool

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

Trait Implementations§

Source§

impl Clone for Matrix3x2f

Source§

fn clone(&self) -> Matrix3x2f

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

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Matrix3x2f

Source§

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

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

impl Default for Matrix3x2f

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Matrix3x2f

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

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

Source§

fn from(parts: [[f32; 2]; 3]) -> Matrix3x2f

Converts to this type from the input type.
Source§

impl From<D2D_MATRIX_3X2_F> for Matrix3x2f

Source§

fn from(m: D2D_MATRIX_3X2_F) -> Matrix3x2f

Converts to this type from the input type.
Source§

impl From<DWRITE_MATRIX> for Matrix3x2f

Source§

fn from(m: DWRITE_MATRIX) -> Matrix3x2f

Converts to this type from the input type.
Source§

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

Source§

fn from(m: Matrix3x2f) -> [[f32; 2]; 3]

Converts to this type from the input type.
Source§

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

Source§

fn from(m: Matrix3x2f) -> [[f32; 3]; 3]

Converts to this type from the input type.
Source§

impl From<Matrix3x2f> for D2D_MATRIX_3X2_F

Source§

fn from(m: Matrix3x2f) -> D2D_MATRIX_3X2_F

Converts to this type from the input type.
Source§

impl From<Matrix3x2f> for DWRITE_MATRIX

Source§

fn from(m: Matrix3x2f) -> DWRITE_MATRIX

Converts to this type from the input type.
Source§

impl From<Matrix3x2f> for RowMatrix3x2<f32>

Source§

fn from(mat: Matrix3x2f) -> RowMatrix3x2<f32>

Converts to this type from the input type.
Source§

impl Mul<Matrix3x2f> for Point2f

Source§

type Output = Point2f

The resulting type after applying the * operator.
Source§

fn mul(self, m: Matrix3x2f) -> Point2f

Performs the * operation. Read more
Source§

impl Mul<Matrix3x2f> for Vector2f

Source§

type Output = Vector2f

The resulting type after applying the * operator.
Source§

fn mul(self, m: Matrix3x2f) -> Vector2f

Performs the * operation. Read more
Source§

impl Mul for Matrix3x2f

Source§

type Output = Matrix3x2f

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Matrix3x2f) -> Matrix3x2f

Performs the * operation. Read more
Source§

impl PartialEq for Matrix3x2f

Source§

fn eq(&self, other: &Matrix3x2f) -> 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 Serialize for Matrix3x2f

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for Matrix3x2f

Source§

impl StructuralPartialEq for Matrix3x2f

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, 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.
Source§

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