Skip to main content

Matrix

Struct Matrix 

Source
pub struct Matrix {
    pub m11: f64,
    pub m12: f64,
    pub m13: f64,
    pub m21: f64,
    pub m22: f64,
    pub m23: f64,
    pub m31: f64,
    pub m32: f64,
    pub m33: f64,
}
Expand description

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.

Fields§

§m11: f64

The first element of the first row (scaleX).

§m12: f64

The second element of the first row (skewY).

§m13: f64

The third element of the first row (perspX).

§m21: f64

The first element of the second row (skewX).

§m22: f64

The second element of the second row (scaleY).

§m23: f64

The third element of the second row (perspY).

§m31: f64

The first element of the third row (offsetX/translateX).

§m32: f64

The second element of the third row (offsetY/translateY).

§m33: f64

The third element of the third row (perspZ).

Implementations§

Source§

impl Matrix

Source

pub const IDENTITY: Matrix

A multiplicative identity matrix.

Source

pub 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).

Source

pub 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.

Source

pub fn is_identity(&self) -> bool

Returns whether the matrix is the multiplicative identity matrix or not.

Source

pub fn has_inverse(&self) -> bool

Returns whether the matrix has an inverse.

Source

pub fn create_rotation(radians: f64) -> Matrix

Creates a rotation matrix using the given rotation in radians.

Source

pub fn create_rotation_at(radians: f64, center: Point) -> Matrix

Creates a rotation matrix using the given rotation in radians around a center point.

Source

pub fn create_skew(x_angle: f64, y_angle: f64) -> Matrix

Creates a skew matrix from the given axis skew angles in radians.

Source

pub const fn create_scale(x_scale: f64, y_scale: f64) -> Matrix

Creates a scale matrix from the given X and Y components.

Source

pub const fn create_scale_vector(scales: Vector) -> Matrix

Creates a scale matrix from the given vector scale.

Source

pub const fn create_translation_vector(position: Vector) -> Matrix

Creates a translation matrix from the given vector.

Source

pub const fn create_translation(x_position: f64, y_position: f64) -> Matrix

Creates a translation matrix from the given X and Y components.

Source

pub fn to_radians(angle: f64) -> f64

Converts an angle in degrees to radians.

Source

pub fn append(&self, value: Matrix) -> Matrix

Appends another matrix as post-multiplication operation. Equivalent to self * value.

Source

pub fn prepend(&self, value: Matrix) -> Matrix

Prepends another matrix as pre-multiplication operation. Equivalent to value * self.

Source

pub fn get_determinant(&self) -> f64

Calculates the determinant for this matrix.

Source

pub fn transform(&self, p: Point) -> Point

Transforms the point with the matrix.

Source

pub fn equals(&self, other: Matrix) -> bool

Returns a boolean indicating whether the matrix is equal to the other given matrix (exact comparison of every element).

Source

pub fn contains_perspective(&self) -> bool

Determines if the current matrix contains perspective (non-affine) transforms.

Source

pub fn try_invert(&self) -> Option<Matrix>

Attempts to invert the matrix. Returns None when it is not invertible.

Source

pub fn invert(&self) -> Matrix

Inverts the matrix.

§Panics

Panics if the matrix is not invertible; use try_invert when that is a possibility.

Source

pub 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.

Source

pub 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§

Source§

impl BatchValue for Matrix

Source§

fn write_to(&self, out: &mut Vec<u8>)

Source§

fn read_from(input: &mut BatchValueReader<'_>) -> Self

Source§

impl Clone for Matrix

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Matrix

Source§

impl Debug for Matrix

Source§

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

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

impl Default for Matrix

Source§

fn default() -> Self

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

impl Display for Matrix

Source§

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

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

impl ExpressionVariantValue for Matrix

Source§

const FFI_VARIANT_TYPE: Option<VariantType> = None

The variant type a foreign function parameter of this type is matched against, or None when the type cannot be a foreign function parameter.
Source§

fn try_from_variant(v: &ExpressionVariant) -> Option<Self>

Source§

fn into_variant(self) -> ExpressionVariant

Source§

impl From<Matrix> for ExpressionVariant

Source§

fn from(value: Matrix) -> ExpressionVariant

Converts to this type from the input type.
Source§

impl FromStr for Matrix

Source§

type Err = FormatError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, FormatError>

Parses a string s to return a value of this type. Read more
Source§

impl MarkupTyped for Matrix

Source§

const MARKUP: &'static MarkupType

The markup metadata of the type.
Source§

impl Mul for Matrix

Multiplies two matrices together and returns the resulting matrix.

Source§

type Output = Matrix

The resulting type after applying the * operator.
Source§

fn mul(self, value2: Matrix) -> Matrix

Performs the * operation. Read more
Source§

impl Mul<Matrix> for Point

Applies a matrix to a point.

Source§

type Output = Point

The resulting type after applying the * operator.
Source§

fn mul(self, matrix: Matrix) -> Point

Performs the * operation. Read more
Source§

impl MulAssign for Matrix

Source§

fn mul_assign(&mut self, value: Matrix)

Performs the *= operation. Read more
Source§

impl MulAssign<Matrix> for Point

Source§

fn mul_assign(&mut self, matrix: Matrix)

Performs the *= operation. Read more
Source§

impl Neg for Matrix

Negation is defined as inversion of the matrix.

§Panics

Panics if the matrix is not invertible.

Source§

type Output = Matrix

The resulting type after applying the - operator.
Source§

fn neg(self) -> Matrix

Performs the unary - operation. Read more
Source§

impl PartialEq for Matrix

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl ServerPropertyValue for Matrix

Source§

fn differs(&self, other: &Self) -> bool

Source§

fn default_equals(&self, other: &Self) -> bool

Source§

impl StructuralPartialEq for Matrix

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> AnyValue for T
where T: PartialEq + 'static,

Source§

fn any_value_as_any(&self) -> &(dyn Any + 'static)

Source§

fn any_value_eq(&self, other: &(dyn AnyValue + 'static)) -> bool

Source§

fn any_value_type_name(&self) -> &'static str

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> ClassDefaults for T
where T: ?Sized,

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). 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> PropertyValue for T
where T: Clone + PartialEq + 'static,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.