# Matrix

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-base/struct-matrix/

**struct** · [`ferroui-base`](/docs/0.5.0/api/ferroui-base/) · v0.5.0

```rust
struct Matrix
```

A 3x3 matrix.

Matrix layout:
```text
        | 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.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L23)

## Members

- [`m11`](#struct_field-m11)
- [`m12`](#struct_field-m12)
- [`m13`](#struct_field-m13)
- [`m21`](#struct_field-m21)
- [`m22`](#struct_field-m22)
- [`m23`](#struct_field-m23)
- [`m31`](#struct_field-m31)
- [`m32`](#struct_field-m32)
- [`m33`](#struct_field-m33)
- [`IDENTITY`](#assoc_const-identity)
- [`new`](#function-new)
- [`new_3x3`](#function-new_3x3)
- [`is_identity`](#function-is_identity)
- [`has_inverse`](#function-has_inverse)
- [`create_rotation`](#function-create_rotation)
- [`create_rotation_at`](#function-create_rotation_at)
- [`create_skew`](#function-create_skew)
- [`create_scale`](#function-create_scale)
- [`create_scale_vector`](#function-create_scale_vector)
- [`create_translation_vector`](#function-create_translation_vector)
- [`create_translation`](#function-create_translation)
- [`to_radians`](#function-to_radians)
- [`append`](#function-append)
- [`prepend`](#function-prepend)
- [`get_determinant`](#function-get_determinant)
- [`transform`](#function-transform)
- [`equals`](#function-equals)
- [`contains_perspective`](#function-contains_perspective)
- [`try_invert`](#function-try_invert)
- [`invert`](#function-invert)
- [`parse`](#function-parse)
- [`try_decompose_transform`](#function-try_decompose_transform)

<a id="struct_field-m11"></a>

### m11

```rust
m11: f64
```

The first element of the first row (scaleX).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L25)

<a id="struct_field-m12"></a>

### m12

```rust
m12: f64
```

The second element of the first row (skewY).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L27)

<a id="struct_field-m13"></a>

### m13

```rust
m13: f64
```

The third element of the first row (perspX).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L29)

<a id="struct_field-m21"></a>

### m21

```rust
m21: f64
```

The first element of the second row (skewX).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L31)

<a id="struct_field-m22"></a>

### m22

```rust
m22: f64
```

The second element of the second row (scaleY).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L33)

<a id="struct_field-m23"></a>

### m23

```rust
m23: f64
```

The third element of the second row (perspY).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L35)

<a id="struct_field-m31"></a>

### m31

```rust
m31: f64
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L37)

<a id="struct_field-m32"></a>

### m32

```rust
m32: f64
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L39)

<a id="struct_field-m33"></a>

### m33

```rust
m33: f64
```

The third element of the third row (perspZ).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L41)

<a id="assoc_const-identity"></a>

### IDENTITY

```rust
const IDENTITY: Matrix
```

A multiplicative identity matrix.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L55)

<a id="function-new"></a>

### new

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L59)

<a id="function-new_3x3"></a>

### new_3x3

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L75)

<a id="function-is_identity"></a>

### is_identity

```rust
fn is_identity(self: &Self) -> bool
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L101)

<a id="function-has_inverse"></a>

### has_inverse

```rust
fn has_inverse(self: &Self) -> bool
```

Returns whether the matrix has an inverse.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L107)

<a id="function-create_rotation"></a>

### create_rotation

```rust
fn create_rotation(radians: f64) -> Matrix
```

Creates a rotation matrix using the given rotation in radians.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L113)

<a id="function-create_rotation_at"></a>

### create_rotation_at

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

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L121)

<a id="function-create_skew"></a>

### create_skew

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

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L138)

<a id="function-create_scale"></a>

### create_scale

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

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L146)

<a id="function-create_scale_vector"></a>

### create_scale_vector

```rust
const fn create_scale_vector(scales: Vector) -> Matrix
```

Creates a scale matrix from the given vector scale.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L152)

<a id="function-create_translation_vector"></a>

### create_translation_vector

```rust
const fn create_translation_vector(position: Vector) -> Matrix
```

Creates a translation matrix from the given vector.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L158)

<a id="function-create_translation"></a>

### create_translation

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

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L164)

<a id="function-to_radians"></a>

### to_radians

```rust
fn to_radians(angle: f64) -> f64
```

Converts an angle in degrees to radians.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L170)

<a id="function-append"></a>

### append

```rust
fn append(self: &Self, value: Matrix) -> Matrix
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L177)

<a id="function-prepend"></a>

### prepend

```rust
fn prepend(self: &Self, value: Matrix) -> Matrix
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L184)

<a id="function-get_determinant"></a>

### get_determinant

```rust
fn get_determinant(self: &Self) -> f64
```

Calculates the determinant for this matrix.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L190)

<a id="function-transform"></a>

### transform

```rust
fn transform(self: &Self, p: Point) -> Point
```

Transforms the point with the matrix.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L199)

<a id="function-equals"></a>

### equals

```rust
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).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L226)

<a id="function-contains_perspective"></a>

### contains_perspective

```rust
fn contains_perspective(self: &Self) -> bool
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L232)

<a id="function-try_invert"></a>

### try_invert

```rust
fn try_invert(self: &Self) -> Option<Matrix>
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L237)

<a id="function-invert"></a>

### invert

```rust
fn invert(self: &Self) -> Matrix
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L265)

<a id="function-parse"></a>

### parse

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L275)

<a id="function-try_decompose_transform"></a>

### try_decompose_transform

```rust
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.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/matrix.rs#L303)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`PropertyValue`](/docs/0.5.0/api/ferroui-base/trait-propertyvalue/)
- [`AnyValue`](/docs/0.5.0/api/ferroui-base/trait-anyvalue/)
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `Borrow<T>`
- `BorrowMut<T>`
- `CloneToUninit`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ToOwned`
- `ToString`
- `ErasedDestructor`
- `IntoEither`
- `From<Matrix>`
- `ExpressionVariantValue`
- `ServerPropertyValue`
- `BatchValue`
- [`MarkupTyped`](/docs/0.5.0/api/ferroui-base/metadata/trait-markuptyped/)
- [`ValueTypeRegistration`](/docs/0.5.0/api/ferroui-base/data/core/trait-valuetyperegistration/)
- `Clone`
- `Copy`
- `Debug`
- `StructuralPartialEq`
- `PartialEq`
- `Default`
- `Mul`
- `MulAssign`
- `Neg`
- `FromStr`
- `Display`
- `Mul<Matrix>`
- `MulAssign<Matrix>`

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
