Skip to main content

Matrix

Struct Matrix 

pub struct Matrix { /* private fields */ }

Implementations§

§

impl Matrix

pub fn scale(_: (f32, f32)) -> Matrix

Sets the matrix to scale by (sx, sy). The returned matrix is:

| sx  0  0 |
|  0 sy  0 |
|  0  0  1 |
  • sx horizontal scale factor
  • sy vertical scale factor

pub fn translate(d: impl Into<Point>) -> Matrix

Sets the matrix to translate by (dx, dy). The returned matrix is:

| 1 0 dx |
| 0 1 dy |
| 0 0  1 |
  • d translation as a vector

pub fn scale_translate(_: (f32, f32), t: impl Into<Point>) -> Matrix

pub fn rotate_deg(deg: f32) -> Matrix

Sets the matrix to rotate by deg about a pivot point at (0, 0).

  • deg rotation angle in degrees (positive rotates clockwise)

pub fn rotate_deg_pivot(deg: f32, pivot: impl Into<Point>) -> Matrix

pub fn rotate_rad(rad: f32) -> Matrix

pub fn skew(_: (f32, f32)) -> Matrix

Sets the matrix to skew by (kx, ky) about the pivot point (0, 0).

  • kx horizontal skew factor
  • ky vertical skew factor
§

impl Matrix

pub fn rect_to_rect( src: impl AsRef<Rect>, dst: impl AsRef<Rect>, scale_to_fit: impl Into<Option<SkMatrix_ScaleToFit>>, ) -> Option<Matrix>

👎Deprecated since 0.89.0:

Use rect_2_rect

pub fn new_all( scale_x: f32, skew_x: f32, trans_x: f32, skew_y: f32, scale_y: f32, trans_y: f32, pers_0: f32, pers_1: f32, pers_2: f32, ) -> Matrix

Sets the matrix to:

| scaleX  skewX transX |
|  skewY scaleY transY |
|  pers0  pers1  pers2 |
  • scale_x horizontal scale factor
  • skew_x horizontal skew factor
  • trans_x horizontal translation
  • skew_y vertical skew factor
  • scale_y vertical scale factor
  • trans_y vertical translation
  • pers_0 input x-axis perspective factor
  • pers_1 input y-axis perspective factor
  • pers_2 perspective scale factor
§

impl Matrix

pub fn get_type(&self) -> TypeMask

Returns a bit field describing the transformations the matrix may perform. The bit field is computed conservatively, so it may include false positives. For example, when TypeMask::PERSPECTIVE is set, all other bits are set.

pub fn is_identity(&self) -> bool

Returns true if the matrix is identity. The identity matrix is:

| 1 0 0 |
| 0 1 0 |
| 0 0 1 |

pub fn is_scale_translate(&self) -> bool

Returns true if the matrix at most scales and translates. The matrix may be identity, contain only scale elements, only translate elements, or both. The matrix form is:

| scale-x    0    translate-x |
|    0    scale-y translate-y |
|    0       0         1      |

pub fn is_translate(&self) -> bool

Returns true if the matrix is identity, or translates. The matrix form is:

| 1 0 translate-x |
| 0 1 translate-y |
| 0 0      1      |

pub fn rect_stays_rect(&self) -> bool

Returns true if the matrix maps a Rect to another Rect. If true, the matrix is identity, or scales, or rotates a multiple of 90 degrees, or mirrors on axes. In all cases, the matrix may also have translation. The matrix form is either:

| scale-x    0    translate-x |
|    0    scale-y translate-y |
|    0       0         1      |

or

|    0     rotate-x translate-x |
| rotate-y    0     translate-y |
|    0        0          1      |

for non-zero values of scale-x, scale-y, rotate-x, and rotate-y.

Also called Self::preserves_axis_alignment(); use the one that provides better inline documentation.

pub fn preserves_axis_alignment(&self) -> bool

Returns true if the matrix maps a Rect to another Rect. If true, the matrix is identity, or scales, or rotates a multiple of 90 degrees, or mirrors on axes. In all cases, the matrix may also have translation. The matrix form is either:

| scale-x    0    translate-x |
|    0    scale-y translate-y |
|    0       0         1      |

or

|    0     rotate-x translate-x |
| rotate-y    0     translate-y |
|    0        0          1      |

for non-zero values of scale-x, scale-y, rotate-x, and rotate-y.

Also called Self::rect_stays_rect(); use the one that provides better inline documentation.

pub fn has_perspective(&self) -> bool

Returns true if the matrix contains perspective elements. The matrix form is:

|       --            --              --          |
|       --            --              --          |
| perspective-x  perspective-y  perspective-scale |

where perspective-x or perspective-y is non-zero, or perspective-scale is not one. All other elements may have any value.

pub fn is_similarity(&self) -> bool

Returns true if the matrix contains only translation, rotation, reflection, and uniform scale. Returns false if the matrix contains different scales, skewing, perspective, or degenerate forms that collapse to a line or point.

Describes that the matrix makes rendering with and without the matrix visually alike; a transformed circle remains a circle. Mathematically, this is referred to as similarity of a Euclidean space, or a similarity transformation.

Preserves right angles, keeping the arms of the angle equal lengths.

Example (C++): https://fiddle.skia.org/c/@Matrix_isSimilarity

pub fn preserves_right_angles(&self) -> bool

Returns true if the matrix contains only translation, rotation, reflection, and scale. Scale may differ along rotated axes. Returns false if the matrix skews, has perspective, or has degenerate forms that collapse to a line or point.

Preserves right angles, but does not require that the arms of the angle retain equal lengths.

Example (C++): https://fiddle.skia.org/c/@Matrix_preservesRightAngles

pub fn rc(&self, r: usize, c: usize) -> f32

Returns one matrix value from a particular row/column. Asserts if the index is out of range and SK_DEBUG is defined.

  • r matrix row to fetch
  • c matrix column to fetch

pub fn scale_x(&self) -> f32

Returns the scale factor multiplied by the x-axis input, contributing to the x-axis output. With Self::map_points(), scales Point along the x-axis.

pub fn scale_y(&self) -> f32

Returns the scale factor multiplied by the y-axis input, contributing to the y-axis output. With Self::map_points(), scales Point along the y-axis.

pub fn skew_y(&self) -> f32

Returns the scale factor multiplied by the x-axis input, contributing to the y-axis output. With Self::map_points(), skews Point along the y-axis. Skewing both axes can rotate Point.

pub fn skew_x(&self) -> f32

Returns the scale factor multiplied by the y-axis input, contributing to the x-axis output. With Self::map_points(), skews Point along the x-axis. Skewing both axes can rotate Point.

pub fn translate_x(&self) -> f32

Returns the translation contributing to the x-axis output. With Self::map_points(), moves Point along the x-axis.

pub fn translate_y(&self) -> f32

Returns the translation contributing to the y-axis output. With Self::map_points(), moves Point along the y-axis.

pub fn persp_x(&self) -> f32

Returns the factor scaling input x-axis relative to input y-axis.

pub fn persp_y(&self) -> f32

Returns the factor scaling input y-axis relative to input x-axis.

pub fn set_scale_x(&mut self, v: f32) -> &mut Matrix

Sets the horizontal scale factor.

  • v horizontal scale factor to store

pub fn set_scale_y(&mut self, v: f32) -> &mut Matrix

Sets the vertical scale factor.

  • v vertical scale factor to store

pub fn set_skew_y(&mut self, v: f32) -> &mut Matrix

Sets the vertical skew factor.

  • v vertical skew factor to store

pub fn set_skew_x(&mut self, v: f32) -> &mut Matrix

Sets the horizontal skew factor.

  • v horizontal skew factor to store

pub fn set_translate_x(&mut self, v: f32) -> &mut Matrix

Sets the horizontal translation.

  • v horizontal translation to store

pub fn set_translate_y(&mut self, v: f32) -> &mut Matrix

Sets the vertical translation.

  • v vertical translation to store

pub fn set_persp_x(&mut self, v: f32) -> &mut Matrix

Sets the input x-axis perspective factor, which causes Self::map_points() to vary input x-axis values inversely proportional to input y-axis values.

  • v perspective factor

pub fn set_persp_y(&mut self, v: f32) -> &mut Matrix

Sets the input y-axis perspective factor, which causes Self::map_points() to vary input y-axis values inversely proportional to input x-axis values.

  • v perspective factor

pub fn set_all( &mut self, scale_x: f32, skew_x: f32, trans_x: f32, skew_y: f32, scale_y: f32, trans_y: f32, persp_0: f32, persp_1: f32, persp_2: f32, ) -> &mut Matrix

Sets all values from parameters. Sets the matrix to:

| scaleX  skewX transX |
|  skewY scaleY transY |
| persp0 persp1 persp2 |
  • scale_x horizontal scale factor to store
  • skew_x horizontal skew factor to store
  • trans_x horizontal translation to store
  • skew_y vertical skew factor to store
  • scale_y vertical scale factor to store
  • trans_y vertical translation to store
  • persp_0 input x-axis values perspective factor to store
  • persp_1 input y-axis values perspective factor to store
  • persp_2 perspective scale factor to store

pub fn get_9(&self, buffer: &mut [f32; 9])

Copies the nine scalar values contained by the matrix into buffer, in member value ascending order: scale-x, skew-x, trans-x, skew-y, scale-y, trans-y, persp-0, persp-1, persp-2.

  • buffer storage for nine scalar values

pub fn set_9(&mut self, buffer: &[f32; 9]) -> &mut Matrix

Sets the matrix to the nine scalar values in buffer, in member value ascending order: scale-x, skew-x, trans-x, skew-y, scale-y, trans-y, persp-0, persp-1, persp-2.

Sets the matrix to:

| buffer[0] buffer[1] buffer[2] |
| buffer[3] buffer[4] buffer[5] |
| buffer[6] buffer[7] buffer[8] |

In the future, set_9 followed by get_9 may not return the same values. Since the matrix maps non-homogeneous coordinates, scaling all nine values produces an equivalent transformation, possibly improving precision.

  • buffer nine scalar values

pub fn reset(&mut self) -> &mut Matrix

Sets the matrix to identity, which has no effect on mapped points. Sets the matrix to:

| 1 0 0 |
| 0 1 0 |
| 0 0 1 |

Also called Self::set_identity(); use the one that provides better inline documentation.

pub fn set_identity(&mut self) -> &mut Matrix

Sets the matrix to identity, which has no effect on mapped points. Sets the matrix to:

| 1 0 0 |
| 0 1 0 |
| 0 0 1 |

Also called Self::reset(); use the one that provides better inline documentation.

pub fn set_translate(&mut self, v: impl Into<Point>) -> &mut Matrix

Sets the matrix to translate by v.

  • v vector containing horizontal and vertical translation

pub fn set_scale( &mut self, _: (f32, f32), pivot: impl Into<Option<Point>>, ) -> &mut Matrix

Sets the matrix to scale by (sx, sy), about a pivot point at pivot. The pivot point is unchanged when mapped with the matrix.

  • sx horizontal scale factor
  • sy vertical scale factor
  • pivot pivot on x- and y-axes

pub fn set_rotate( &mut self, degrees: f32, pivot: impl Into<Option<Point>>, ) -> &mut Matrix

Sets the matrix to rotate by degrees about a pivot point at pivot. The pivot point is unchanged when mapped with the matrix.

Positive degrees rotates clockwise.

  • degrees angle of axes relative to upright axes
  • pivot pivot on x- and y-axes

pub fn set_sin_cos( &mut self, _: (f32, f32), pivot: impl Into<Option<Point>>, ) -> &mut Matrix

Sets the matrix to rotate by sin_value and cos_value, about a pivot point at pivot. The pivot point is unchanged when mapped with the matrix.

Vector (sin_value, cos_value) describes the angle of rotation relative to (0, 1). Vector length specifies scale.

  • sin_value rotation vector x-axis component
  • cos_value rotation vector y-axis component
  • pivot pivot on x- and y-axes

pub fn set_rsxform(&mut self, rsxform: &RSXform) -> &mut Matrix

Sets the matrix to rotate, scale, and translate using a compressed matrix form.

Vector (rsxform.scos, rsxform.ssin) describes the angle of rotation relative to (0, 1). Vector length specifies scale. The mapped point is rotated and scaled by the vector, then translated by (rsxform.tx, rsxform.ty).

  • rsxform compressed RSXform matrix

Example (C++): https://fiddle.skia.org/c/@Matrix_setRSXform

pub fn set_skew( &mut self, _: (f32, f32), pivot: impl Into<Option<Point>>, ) -> &mut Matrix

Sets the matrix to skew by (kx, ky), about a pivot point at pivot. The pivot point is unchanged when mapped with the matrix.

  • kx horizontal skew factor
  • ky vertical skew factor
  • pivot pivot on x- and y-axes

pub fn set_concat(&mut self, a: &Matrix, b: &Matrix) -> &mut Matrix

Sets the matrix to matrix a multiplied by matrix b. Either a or b may be this.

Given:

        | A B C |      | J K L |
    a = | D E F |, b = | M N O |
        | G H I |      | P Q R |

sets the matrix to:

            | A B C |   | J K L |   | AJ+BM+CP AK+BN+CQ AL+BO+CR |
    a * b = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR |
            | G H I |   | P Q R |   | GJ+HM+IP GK+HN+IQ GL+HO+IR |
  • a matrix on left side of multiply expression
  • b matrix on right side of multiply expression

pub fn pre_translate(&mut self, delta: impl Into<Point>) -> &mut Matrix

Sets the matrix to the matrix multiplied by a matrix constructed from translation delta. This can be thought of as moving the point to be mapped before applying the matrix.

Given:

             | A B C |               | 1 0 dx |
    Matrix = | D E F |,  T(dx, dy) = | 0 1 dy |
             | G H I |               | 0 0  1 |

sets the matrix to:

                         | A B C | | 1 0 dx |   | A B A*dx+B*dy+C |
    Matrix * T(dx, dy) = | D E F | | 0 1 dy | = | D E D*dx+E*dy+F |
                         | G H I | | 0 0  1 |   | G H G*dx+H*dy+I |
  • delta x- and y-axis translation before applying the matrix

pub fn pre_scale( &mut self, _: (f32, f32), pivot: impl Into<Option<Point>>, ) -> &mut Matrix

Sets the matrix to the matrix multiplied by a matrix constructed from scaling by (sx, sy) about the pivot point pivot. This can be thought of as scaling about a pivot point before applying the matrix.

Given:

             | A B C |                       | sx  0 dx |
    Matrix = | D E F |,  S(sx, sy, px, py) = |  0 sy dy |
             | G H I |                       |  0  0  1 |

where

    dx = px - sx * px
    dy = py - sy * py

sets the matrix to:

                                     | A B C | | sx  0 dx |   | A*sx B*sy A*dx+B*dy+C |
    Matrix * S(sx, sy, px, py) =     | D E F | |  0 sy dy | = | D*sx E*sy D*dx+E*dy+F |
                                     | G H I | |  0  0  1 |   | G*sx H*sy G*dx+H*dy+I |
  • sx horizontal scale factor
  • sy vertical scale factor
  • pivot pivot on x- and y-axes

pub fn pre_rotate( &mut self, degrees: f32, pivot: impl Into<Option<Point>>, ) -> &mut Matrix

Sets the matrix to the matrix multiplied by a matrix constructed from rotating by degrees about the pivot point pivot. This can be thought of as rotating about a pivot point before applying the matrix.

Positive degrees rotates clockwise.

Given:

             | A B C |                        | c -s dx |
    Matrix = | D E F |,  R(degrees, px, py) = | s  c dy |
             | G H I |                        | 0  0  1 |

where

    c  = cos(degrees)
    s  = sin(degrees)
    dx =  s * py + (1 - c) * px
    dy = -s * px + (1 - c) * py

sets the matrix to:

                                      | A B C | | c -s dx |   | Ac+Bs -As+Bc A*dx+B*dy+C |
    Matrix * R(degrees, px, py) =     | D E F | | s  c dy | = | Dc+Es -Ds+Ec D*dx+E*dy+F |
                                      | G H I | | 0  0  1 |   | Gc+Hs -Gs+Hc G*dx+H*dy+I |
  • degrees angle of axes relative to upright axes
  • pivot pivot on x- and y-axes

pub fn pre_skew( &mut self, _: (f32, f32), pivot: impl Into<Option<Point>>, ) -> &mut Matrix

Sets the matrix to the matrix multiplied by a matrix constructed from skewing by (kx, ky) about the pivot point pivot. This can be thought of as skewing about a pivot point before applying the matrix.

Given:

             | A B C |                       |  1 kx dx |
    Matrix = | D E F |,  K(kx, ky, px, py) = | ky  1 dy |
             | G H I |                       |  0  0  1 |

where

    dx = -kx * py
    dy = -ky * px

sets the matrix to:

                                     | A B C | |  1 kx dx |   | A+B*ky A*kx+B A*dx+B*dy+C |
    Matrix * K(kx, ky, px, py) =     | D E F | | ky  1 dy | = | D+E*ky D*kx+E D*dx+E*dy+F |
                                     | G H I | |  0  0  1 |   | G+H*ky G*kx+H G*dx+H*dy+I |
  • kx horizontal skew factor
  • ky vertical skew factor
  • pivot pivot on x- and y-axes

pub fn pre_concat(&mut self, other: &Matrix) -> &mut Matrix

Sets the matrix to the matrix multiplied by the matrix other. This can be thought of as mapping by other before applying the matrix.

Given:

             | A B C |          | J K L |
    Matrix = | D E F |, other = | M N O |
             | G H I |          | P Q R |

sets the matrix to:

                     | A B C |   | J K L |   | AJ+BM+CP AK+BN+CQ AL+BO+CR |
    Matrix * other = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR |
                     | G H I |   | P Q R |   | GJ+HM+IP GK+HN+IQ GL+HO+IR |
  • other matrix on the right side of the multiply expression

pub fn post_translate(&mut self, delta: impl Into<Point>) -> &mut Matrix

Sets the matrix to a matrix constructed from translation delta multiplied by the matrix. This can be thought of as moving the point to be mapped after applying the matrix.

Given:

             | J K L |               | 1 0 dx |
    Matrix = | M N O |,  T(dx, dy) = | 0 1 dy |
             | P Q R |               | 0 0  1 |

sets the matrix to:

                         | 1 0 dx | | J K L |   | J+dx*P K+dx*Q L+dx*R |
    T(dx, dy) * Matrix = | 0 1 dy | | M N O | = | M+dy*P N+dy*Q O+dy*R |
                         | 0 0  1 | | P Q R |   |      P      Q      R |
  • delta x- and y-axis translation after applying the matrix

pub fn post_scale( &mut self, _: (f32, f32), pivot: impl Into<Option<Point>>, ) -> &mut Matrix

Sets the matrix to a matrix constructed from scaling by (sx, sy) about the pivot point pivot, multiplied by the matrix. This can be thought of as scaling about a pivot point after applying the matrix.

Given:

             | J K L |                       | sx  0 dx |
    Matrix = | M N O |,  S(sx, sy, px, py) = |  0 sy dy |
             | P Q R |                       |  0  0  1 |

where

    dx = px - sx * px
    dy = py - sy * py

sets the matrix to:

                                     | sx  0 dx | | J K L |   | sx*J+dx*P sx*K+dx*Q sx*L+dx*R |
    S(sx, sy, px, py) * Matrix =     |  0 sy dy | | M N O | = | sy*M+dy*P sy*N+dy*Q sy*O+dy*R |
                                     |  0  0  1 | | P Q R |   |         P         Q         R |
  • sx horizontal scale factor
  • sy vertical scale factor
  • pivot pivot on x- and y-axes

pub fn post_idiv(&mut self, _: (i32, i32)) -> bool

👎Deprecated since 0.27.0:

use post_scale((1.0 / x as scalar, 1.0 / y as scalar), None)

pub fn post_rotate( &mut self, degrees: f32, pivot: impl Into<Option<Point>>, ) -> &mut Matrix

Sets the matrix to a matrix constructed from rotating by degrees about the pivot point pivot, multiplied by the matrix. This can be thought of as rotating about a pivot point after applying the matrix.

Positive degrees rotates clockwise.

Given:

             | J K L |                        | c -s dx |
    Matrix = | M N O |,  R(degrees, px, py) = | s  c dy |
             | P Q R |                        | 0  0  1 |

where

    c  = cos(degrees)
    s  = sin(degrees)
    dx =  s * py + (1 - c) * px
    dy = -s * px + (1 - c) * py

sets the matrix to:

                                      | c -s dx | | J K L |   | cJ-sM+dx*P cK-sN+dx*Q cL-sO+dx*R |
    R(degrees, px, py) * Matrix =     | s  c dy | | M N O | = | sJ+cM+dy*P sK+cN+dy*Q sL+cO+dy*R |
                                      | 0  0  1 | | P Q R |   |         P          Q          R |
  • degrees angle of axes relative to upright axes
  • pivot pivot on x- and y-axes

pub fn post_skew( &mut self, _: (f32, f32), pivot: impl Into<Option<Point>>, ) -> &mut Matrix

Sets the matrix to a matrix constructed from skewing by (kx, ky) about the pivot point pivot, multiplied by the matrix. This can be thought of as skewing about a pivot point after applying the matrix.

Given:

             | J K L |                       |  1 kx dx |
    Matrix = | M N O |,  K(kx, ky, px, py) = | ky  1 dy |
             | P Q R |                       |  0  0  1 |

where

    dx = -kx * py
    dy = -ky * px

sets the matrix to:

                                     | 1 kx dx | | J K L |   | J+kx*M+dx*P K+kx*N+dx*Q L+kx*O+dx*R |
    K(kx, ky, px, py) * Matrix =     | ky  1 dy | | M N O | = | ky*J+M+dy*P ky*K+N+dy*Q ky*L+O+dy*R |
                                     | 0  0  1 | | P Q R |   |          P           Q           R |
  • kx horizontal skew factor
  • ky vertical skew factor
  • pivot pivot on x- and y-axes

pub fn post_concat(&mut self, other: &Matrix) -> &mut Matrix

Sets the matrix to the matrix other multiplied by the matrix. This can be thought of as mapping by other after applying the matrix.

Given:

             | J K L |           | A B C |
    Matrix = | M N O |,  other = | D E F |
             | P Q R |           | G H I |

sets the matrix to:

                     | A B C |   | J K L |   | AJ+BM+CP AK+BN+CQ AL+BO+CR |
    other * Matrix = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR |
                     | G H I |   | P Q R |   | GJ+HM+IP GK+HN+IQ GL+HO+IR |
  • other matrix on the left side of the multiply expression

pub fn from_rect_to_rect( src: impl AsRef<Rect>, dst: impl AsRef<Rect>, stf: SkMatrix_ScaleToFit, ) -> Option<Matrix>

👎Deprecated since 0.88.0:

Use rect_2_rect

pub fn rect_2_rect( src: impl AsRef<Rect>, dst: impl AsRef<Rect>, stf: impl Into<Option<SkMatrix_ScaleToFit>>, ) -> Option<Matrix>

If possible, returns a matrix that will transform the src rect to the dst rect. If src is empty, this will return None. If dst is empty, this will return the zero matrix (degenerate).

  • src source rectangle
  • dst destination rectangle
  • stf scale-to-fit mode, defaults to ScaleToFit::Fill

pub fn rect_to_rect_or_identity( src: impl AsRef<Rect>, dst: impl AsRef<Rect>, stf: impl Into<Option<SkMatrix_ScaleToFit>>, ) -> Matrix

Returns the matrix that transforms the src rect to the dst rect, or the identity matrix if such a matrix does not exist (e.g. if src is empty).

  • src source rectangle
  • dst destination rectangle
  • stf scale-to-fit mode, defaults to ScaleToFit::Fill

pub fn poly_to_poly(src: &[Point], dst: &[Point]) -> Option<Matrix>

Computes a matrix from two polygons, such that if the matrix was applied to the src polygon, it would produce the dst polygon.

If the size of the two spans are not equal, or if they are greater than 4, returns None. If the resulting matrix is non-invertible, returns None.

  • src source polygon points
  • dst destination polygon points

Example (C++): https://fiddle.skia.org/c/@Matrix_setPolyToPoly

pub fn set_poly_to_poly(&mut self, src: &[Point], dst: &[Point]) -> bool

Sets the matrix to a matrix computed from two polygons, such that if the matrix was applied to the src polygon, it would produce the dst polygon.

If the size of the two spans are not equal, or if they are greater than 4, returns false. If the resulting matrix is non-invertible, returns false.

  • src source polygon points
  • dst destination polygon points

pub fn from_poly_to_poly(src: &[Point], dst: &[Point]) -> Option<Matrix>

Computes a matrix from two polygons, such that if the matrix was applied to the src polygon, it would produce the dst polygon.

If the size of the two spans are not equal, or if they are greater than 4, returns None. If the resulting matrix is non-invertible, returns None.

  • src source polygon points
  • dst destination polygon points

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

If this matrix is invertible, returns its inverse; otherwise, returns None.

pub fn set_affine_identity(affine: &mut [f32; 6])

Fills affine with identity values in column major order. Sets affine to:

| 1 0 0 |
| 0 1 0 |

Affine 3 by 2 matrices in column major order are used by OpenGL and XPS.

  • affine storage for the 3 by 2 affine matrix

Example (C++): https://fiddle.skia.org/c/@Matrix_SetAffineIdentity

pub fn to_affine(self) -> Option<[f32; 6]>

Fills affine in column major order. Sets affine to:

| scale-x  skew-x translate-x |
|  skew-y scale-y translate-y |

If the matrix contains perspective, returns None and leaves affine unchanged.

pub fn set_affine(&mut self, affine: &[f32; 6]) -> &mut Matrix

Sets the matrix to affine values, passed in column major order. Given affine, column, then row, as:

| scale-x  skew-x translate-x |
|  skew-y scale-y translate-y |

the matrix is set, row, then column, to:

| scale-x  skew-x translate-x |
|  skew-y scale-y translate-y |
|       0       0           1 |
  • affine 3 by 2 affine matrix

pub fn from_affine(affine: &[f32; 6]) -> Matrix

Creates a matrix from affine values, passed in column major order. Given affine, column, then row, as:

| scale-x  skew-x translate-x |
|  skew-y scale-y translate-y |

the matrix is set, row, then column, to:

| scale-x  skew-x translate-x |
|  skew-y scale-y translate-y |
|       0       0           1 |
  • affine 3 by 2 affine matrix

pub fn normalize_perspective(&mut self)

A matrix is categorized as ‘perspective’ if the bottom row is not [0, 0, 1]. However, for most uses (e.g. Self::map_points()) a bottom row of [0, 0, X] behaves like a non-perspective matrix, though it will be categorized as perspective. Calling normalize_perspective() will change the matrix such that, if its bottom row was [0, 0, X], it will be changed to [0, 0, 1] by scaling the rest of the matrix by 1/X.

| A B C |    | A/X B/X C/X |
| D E F | -> | D/X E/X F/X |   for X != 0
| 0 0 X |    |  0   0   1  |

pub fn map_points(&self, dst: &mut [Point], src: &[Point])

Maps the src point array to the dst point array. Points are mapped by multiplying each point by the matrix. Given:

             | A B C |        | x |
    Matrix = | D E F |,  pt = | y |
             | G H I |        | 1 |

each dst point is computed as:

                  |A B C| |x|                               Ax+By+C   Dx+Ey+F
    Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , -------
                  |G H I| |1|                               Gx+Hy+I   Gx+Hy+I

src and dst may point to the same storage.

  • dst storage where the transformed points are written
  • src storage where the points are read from

Example (C++): https://fiddle.skia.org/c/@Matrix_mapPoints

pub fn map_points_inplace(&self, pts: &mut [Point])

Maps the point array in place. Points are mapped by multiplying each point by the matrix. Given:

             | A B C |        | x |
    Matrix = | D E F |,  pt = | y |
             | G H I |        | 1 |

each resulting point is computed as:

                  |A B C| |x|                               Ax+By+C   Dx+Ey+F
    Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , -------
                  |G H I| |1|                               Gx+Hy+I   Gx+Hy+I
  • pts points to be transformed in place

pub fn map_homogeneous_points(&self, dst: &mut [Point3], src: &[Point3])

Maps the src point array to the dst point array. Points are mapped by multiplying each point by the matrix. Given:

             | A B C |         | x |
    Matrix = | D E F |,  src = | y |
             | G H I |         | z |

each resulting point is computed as:

               |A B C| |x|
    Matrix * src = |D E F| |y| = |Ax+By+Cz Dx+Ey+Fz Gx+Hy+Iz|
               |G H I| |z|
  • dst storage where the transformed points are written
  • src storage where the points are read from

Example (C++): https://fiddle.skia.org/c/@Matrix_mapHomogeneousPoints

pub fn map_homogeneous_point(&self, src: Point3) -> Point3

Maps src point by the matrix.

  • src point to map

pub fn map_homogeneous_points_2d(&self, dst: &mut [Point3], src: &[Point])

👎Deprecated since 0.88.0:

use map_points_to_homogeneous()

pub fn map_points_to_homogeneous(&self, dst: &mut [Point3], src: &[Point])

Returns homogeneous points, starting with the 2D src points (with implied w = 1).

  • dst storage where the transformed points are written
  • src storage where the points are read from

pub fn map_point_to_homogeneous(&self, src: Point) -> Point3

Returns src mapped to a homogeneous point.

  • src point to map

pub fn map_xy(&self, x: f32, y: f32) -> Point

👎Deprecated since 0.88.0:

use map_point((x, y))

pub fn map_point(&self, point: impl Into<Point>) -> Point

Returns the point multiplied by the matrix. Given:

             | A B C |        | x |
    Matrix = | D E F |,  pt = | y |
             | G H I |        | 1 |

the result is computed as:

                  |A B C| |x|                               Ax+By+C   Dx+Ey+F
    Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , -------
                  |G H I| |1|                               Gx+Hy+I   Gx+Hy+I
  • point point to map

pub fn map_point_affine(&self, point: impl Into<Point>) -> Point

If the caller knows the matrix has no perspective, this will inline the math, making it more efficient than calling Self::map_point().

  • point point to map

pub fn map_origin(&self) -> Point

Returns (0, 0) multiplied by the matrix. Given:

             | A B C |        | 0 |
    Matrix = | D E F |,  pt = | 0 |
             | G H I |        | 1 |

the result is computed as:

                  |A B C| |0|             C    F
    Matrix * pt = |D E F| |0| = |C F I| = -  , -
                  |G H I| |1|             I    I

pub fn map_vectors(&self, dst: &mut [Point], src: &[Point])

Maps the src vector array to the dst vector array. Vectors are mapped by multiplying each vector by the matrix, treating the matrix translation as zero. Given:

             | A B 0 |         | x |
    Matrix = | D E 0 |,  src = | y |
             | G H I |         | 1 |

each dst vector is computed as:

               |A B 0| |x|                            Ax+By     Dx+Ey
    Matrix * src = |D E 0| |y| = |Ax+By Dx+Ey Gx+Hy+I| = ------- , -------
               |G H I| |1|                           Gx+Hy+I   Gx+Hy+I

src and dst may point to the same storage.

  • dst storage where the transformed vectors are written
  • src storage where the vectors are read from

Example (C++): https://fiddle.skia.org/c/@Matrix_mapVectors

pub fn map_vectors_inplace(&self, vecs: &mut [Point])

Maps the vector array in place, multiplying each vector by the matrix, treating the matrix translation as zero.

  • vecs vectors to transform, and storage for the mapped vectors

pub fn map_vector(&self, vec: impl Into<Point>) -> Point

Returns the vector multiplied by the matrix, treating the matrix translation as zero. Given:

             | A B 0 |         | dx |
    Matrix = | D E 0 |,  vec = | dy |
             | G H I |         |  1 |

the result vector is computed as:

               |A B 0| |dx|                                        A*dx+B*dy     D*dx+E*dy
    Matrix * vec = |D E 0| |dy| = |A*dx+B*dy D*dx+E*dy G*dx+H*dy+I| = ----------- , -----------
               |G H I| | 1|                                       G*dx+H*dy+I   G*dx+H*dy+I
  • vec vector to map

pub fn map_rect(&self, src: impl AsRef<Rect>) -> (Rect, bool)

Sets dst to the bounds of the src corners mapped by the matrix. Returns true if the mapped corners are the dst corners.

The returned value is the same as calling Self::rect_stays_rect().

  • src rectangle to map

Example (C++): https://fiddle.skia.org/c/@Matrix_mapRect

pub fn map_rect_to_quad(&self, rect: impl AsRef<Rect>) -> [Point; 4]

Maps the four corners of rect to a quad. Points are mapped by multiplying each rect corner by the matrix. The rect corner is processed in this order: (rect.left, rect.top), (rect.right, rect.top), (rect.right, rect.bottom), (rect.left, rect.bottom).

rect may be empty: rect.left may be greater than or equal to rect.right; rect.top may be greater than or equal to rect.bottom.

This does not perform perspective clipping (as that might result in more than 4 points, so results are suspect if the matrix contains perspective).

  • rect rectangle to map

pub fn map_rect_scale_translate(&self, src: impl AsRef<Rect>) -> Option<Rect>

Sets the result to the bounds of the src corners mapped by the matrix. If the matrix contains elements other than scale or translate, returns None (asserts if SK_DEBUG is defined; otherwise, results are undefined).

  • src rectangle to map

Example (C++): https://fiddle.skia.org/c/@Matrix_mapRectScaleTranslate

pub fn map_radius(&self, radius: f32) -> Option<f32>

Returns the geometric mean radius of the ellipse formed by constructing a circle of size radius, and mapping the constructed circle with the matrix. The result squared is equal to the major axis length times the minor axis length.

The result is not meaningful if the matrix contains perspective elements.

  • radius circle size to map

Example (C++): https://fiddle.skia.org/c/@Matrix_mapRadius

pub fn is_fixed_step_in_x(&self) -> !

👎Deprecated since 0.27.0:

removed without replacement

pub fn fixed_step_in_x(&self, _y: f32) -> !

👎Deprecated since 0.27.0:

removed without replacement

pub fn cheap_equal_to(&self, _other: &Matrix) -> !

👎Deprecated since 0.27.0:

removed without replacement

pub fn dump(&self)

Writes a text representation of the matrix to standard output. Floating point values are written with limited precision; it may not be possible to reconstruct the original matrix from the output.

Example (C++): https://fiddle.skia.org/c/@Matrix_dump

pub fn min_scale(&self) -> f32

Returns the minimum scaling factor of the matrix by decomposing the scaling and skewing elements.

Returns -1 if the scale factor overflows or the matrix contains perspective.

Example (C++): https://fiddle.skia.org/c/@Matrix_getMinScale

pub fn max_scale(&self) -> f32

Returns the maximum scaling factor of the matrix by decomposing the scaling and skewing elements.

Returns -1 if the scale factor overflows or the matrix contains perspective.

Example (C++): https://fiddle.skia.org/c/@Matrix_getMaxScale

pub fn min_max_scales(&self) -> (f32, f32)

Sets the first element of the result to the minimum scaling factor, and the second to the maximum scaling factor. Scaling factors are computed by decomposing the matrix scaling and skewing elements.

Returns a tuple of the minimum and maximum scale factors if they are found; otherwise, returns undefined values.

pub fn decompose_scale(&self, remaining: Option<&mut Matrix>) -> Option<Size>

Decomposes the matrix into scale components and whatever remains. Returns None if the matrix could not be decomposed.

Sets scale to the portion of the matrix that scales axes. Sets remaining to the matrix with scaling factored out. remaining may be passed as None to determine if the matrix can be decomposed without computing the remainder.

Returns the scale components if they are found. The scale and remaining are unchanged if the matrix contains perspective, the scale factors are not finite, or are nearly zero.

On success: Matrix = remaining * scale.

  • remaining matrix without scaling; may be None

Example (C++): https://fiddle.skia.org/c/@Matrix_decomposeScale

pub fn i() -> &'static Matrix

Returns a reference to the const identity matrix. The returned matrix is set to:

| 1 0 0 |
| 0 1 0 |
| 0 0 1 |

Example (C++): https://fiddle.skia.org/c/@Matrix_I

pub fn invalid_matrix() -> &'static Matrix

Returns a reference to a const matrix with invalid values. The returned matrix is set to:

| SK_ScalarMax SK_ScalarMax SK_ScalarMax |
| SK_ScalarMax SK_ScalarMax SK_ScalarMax |
| SK_ScalarMax SK_ScalarMax SK_ScalarMax |

Example (C++): https://fiddle.skia.org/c/@Matrix_InvalidMatrix

pub fn concat(a: &Matrix, b: &Matrix) -> Matrix

Returns matrix a multiplied by matrix b.

Given:

        | A B C |      | J K L |
    a = | D E F |, b = | M N O |
        | G H I |      | P Q R |

the result is:

            | A B C |   | J K L |   | AJ+BM+CP AK+BN+CQ AL+BO+CR |
    a * b = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR |
            | G H I |   | P Q R |   | GJ+HM+IP GK+HN+IQ GL+HO+IR |
  • a matrix on the left side of the multiply expression
  • b matrix on the right side of the multiply expression

pub fn dirty_matrix_type_cache(&mut self)

Sets the internal cache to the unknown state. Use to force an update after repeated modifications to matrix element references returned by indexing.

pub fn set_scale_translate( &mut self, s: (f32, f32), t: impl Into<Point>, ) -> &mut Matrix

Initializes the matrix with scale and translate elements.

| sx  0 tx |
|  0 sy ty |
|  0  0  1 |
  • s horizontal and vertical scale factors to store
  • t horizontal and vertical translation to store

pub fn is_finite(&self) -> bool

Returns true if all elements of the matrix are finite. Returns false if any element is infinity, or NaN.

pub const fn new_identity() -> Matrix

Trait Implementations§

§

impl Clone for Matrix

§

fn clone(&self) -> Matrix

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
§

impl Copy for Matrix

§

impl Debug for Matrix

§

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

Formats the value using the given formatter. Read more
§

impl Default for Matrix

§

fn default() -> Matrix

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

impl From<&Matrix> for M44

§

fn from(src: &Matrix) -> M44

Converts to this type from the input type.
§

impl From<Matrix> for M44

§

fn from(m: Matrix) -> M44

Converts to this type from the input type.
§

impl Index<AffineMember> for Matrix

§

type Output = f32

The returned type after indexing.
§

fn index(&self, index: AffineMember) -> &<Matrix as Index<AffineMember>>::Output

Performs the indexing (container[index]) operation. Read more
§

impl Index<Member> for Matrix

§

type Output = f32

The returned type after indexing.
§

fn index(&self, index: Member) -> &<Matrix as Index<Member>>::Output

Performs the indexing (container[index]) operation. Read more
§

impl Index<usize> for Matrix

§

type Output = f32

The returned type after indexing.
§

fn index(&self, index: usize) -> &<Matrix as Index<usize>>::Output

Performs the indexing (container[index]) operation. Read more
§

impl IndexMut<AffineMember> for Matrix

§

fn index_mut( &mut self, index: AffineMember, ) -> &mut <Matrix as Index<AffineMember>>::Output

Performs the mutable indexing (container[index]) operation. Read more
§

impl IndexMut<Member> for Matrix

§

fn index_mut(&mut self, index: Member) -> &mut <Matrix as Index<Member>>::Output

Performs the mutable indexing (container[index]) operation. Read more
§

impl IndexMut<usize> for Matrix

§

fn index_mut(&mut self, index: usize) -> &mut <Matrix as Index<usize>>::Output

Performs the mutable indexing (container[index]) operation. Read more
§

impl Mul for Matrix

§

type Output = Matrix

The resulting type after applying the * operator.
§

fn mul(self, rhs: Matrix) -> <Matrix as Mul>::Output

Performs the * operation. Read more
§

impl PartialEq for Matrix

§

fn eq(&self, rhs: &Matrix) -> bool

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

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

Inequality operator !=. Read more

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
§

impl<T> AnyEq for T
where T: Any + PartialEq,

§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

§

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

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

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

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

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

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<N, T> NativeTransmutableWrapper<N> for T
where T: NativeTransmutable<N>,

§

fn wrap(native: N) -> T

§

fn unwrap(self) -> N

§

fn inner(&self) -> &N

§

fn inner_mut(&mut self) -> &mut N

§

impl<T> NoneValue for T
where T: Default,

§

type NoneType = T

§

fn null_value() -> T

The none-equivalent value.
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

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 = !

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

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more