Matrix
struct · ferroui-base · v0.5.0
struct Matrix
A 3x3 matrix.
Matrix layout:
| 1st col | 2nd col | 3rd col |
1st row | scaleX | skewY | perspX |
2nd row | skewX | scaleY | perspY |
3rd row | transX | transY | perspZ |
Note: the default value is the all-zero matrix, not the identity.
Members
m11m12m13m21m22m23m31m32m33IDENTITYnewnew_3x3is_identityhas_inversecreate_rotationcreate_rotation_atcreate_skewcreate_scalecreate_scale_vectorcreate_translation_vectorcreate_translationto_radiansappendprependget_determinanttransformequalscontains_perspectivetry_invertinvertparsetry_decompose_transform
m11
m11: f64
The first element of the first row (scaleX).
m12
m12: f64
The second element of the first row (skewY).
m13
m13: f64
The third element of the first row (perspX).
m21
m21: f64
The first element of the second row (skewX).
m22
m22: f64
The second element of the second row (scaleY).
m23
m23: f64
The third element of the second row (perspY).
m31
m31: f64
The first element of the third row (offsetX/translateX).
m32
m32: f64
The second element of the third row (offsetY/translateY).
m33
m33: f64
The third element of the third row (perspZ).
IDENTITY
const IDENTITY: Matrix
A multiplicative identity matrix.
new
const fn new(scale_x: f64, skew_y: f64, skew_x: f64, scale_y: f64, offset_x: f64, offset_y: f64) -> Self
Initializes an affine Matrix (the third column is 0, 0, 1).
new_3x3
const fn new_3x3(scale_x: f64, skew_y: f64, persp_x: f64, skew_x: f64, scale_y: f64, persp_y: f64, offset_x: f64, offset_y: f64, persp_z: f64) -> Self
Initializes a full 3x3 Matrix, given in row order.
is_identity
fn is_identity(self: &Self) -> bool
Returns whether the matrix is the multiplicative identity matrix or not.
has_inverse
fn has_inverse(self: &Self) -> bool
Returns whether the matrix has an inverse.
create_rotation
fn create_rotation(radians: f64) -> Matrix
Creates a rotation matrix using the given rotation in radians.
create_rotation_at
fn create_rotation_at(radians: f64, center: Point) -> Matrix
Creates a rotation matrix using the given rotation in radians around a center point.
create_skew
fn create_skew(x_angle: f64, y_angle: f64) -> Matrix
Creates a skew matrix from the given axis skew angles in radians.
create_scale
const fn create_scale(x_scale: f64, y_scale: f64) -> Matrix
Creates a scale matrix from the given X and Y components.
create_scale_vector
const fn create_scale_vector(scales: Vector) -> Matrix
Creates a scale matrix from the given vector scale.
create_translation_vector
const fn create_translation_vector(position: Vector) -> Matrix
Creates a translation matrix from the given vector.
create_translation
const fn create_translation(x_position: f64, y_position: f64) -> Matrix
Creates a translation matrix from the given X and Y components.
to_radians
fn to_radians(angle: f64) -> f64
Converts an angle in degrees to radians.
append
fn append(self: &Self, value: Matrix) -> Matrix
Appends another matrix as post-multiplication operation.
Equivalent to self * value.
prepend
fn prepend(self: &Self, value: Matrix) -> Matrix
Prepends another matrix as pre-multiplication operation.
Equivalent to value * self.
get_determinant
fn get_determinant(self: &Self) -> f64
Calculates the determinant for this matrix.
transform
fn transform(self: &Self, p: Point) -> Point
Transforms the point with the matrix.
equals
fn equals(self: &Self, other: Matrix) -> bool
Returns a boolean indicating whether the matrix is equal to the other given matrix (exact comparison of every element).
contains_perspective
fn contains_perspective(self: &Self) -> bool
Determines if the current matrix contains perspective (non-affine) transforms.
try_invert
fn try_invert(self: &Self) -> Option<Matrix>
Attempts to invert the matrix. Returns None when it is not invertible.
invert
fn invert(self: &Self) -> Matrix
Inverts the matrix.
Panics
Panics if the matrix is not invertible; use try_invert
when that is a possibility.
parse
fn parse(s: &str) -> Result<Self, FormatError>
Parses a Matrix string: six (affine) or nine comma/space separated values.
Nine values are given in the order m11, m12, m21, m22, m31, m32, m13, m23, m33.
try_decompose_transform
fn try_decompose_transform(matrix: Matrix) -> Option<MatrixDecomposed>
Decomposes the given matrix into translation, rotation, scale and skew.
Returns None for singular matrices and matrices containing perspective.
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafePropertyValueAnyValueClassDefaultsBorrow<T>BorrowMut<T>CloneToUninitInto<U>From<T>TryInto<U>TryFrom<U>AnyToOwnedToStringErasedDestructorIntoEitherFrom<Matrix>ExpressionVariantValueServerPropertyValueBatchValueMarkupTypedValueTypeRegistrationCloneCopyDebugStructuralPartialEqPartialEqDefaultMulMulAssignNegFromStrDisplayMul<Matrix>MulAssign<Matrix>
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.