Struct Matrix
pub struct Matrix { /* private fields */ }Implementations§
§impl Matrix
impl Matrix
pub fn scale(_: (f32, f32)) -> 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 |sxhorizontal scale factorsyvertical scale factor
pub fn translate(d: impl Into<Point>) -> Matrix
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 |dtranslation as a vector
pub fn scale_translate(_: (f32, f32), t: impl Into<Point>) -> Matrix
pub fn rotate_deg(deg: f32) -> Matrix
pub fn rotate_deg(deg: f32) -> Matrix
Sets the matrix to rotate by deg about a pivot point at (0, 0).
degrotation 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
§impl Matrix
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>
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
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_xhorizontal scale factorskew_xhorizontal skew factortrans_xhorizontal translationskew_yvertical skew factorscale_yvertical scale factortrans_yvertical translationpers_0input x-axis perspective factorpers_1input y-axis perspective factorpers_2perspective scale factor
§impl Matrix
impl Matrix
pub fn get_type(&self) -> TypeMask
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
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
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
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
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
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
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
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
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
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.
rmatrix row to fetchcmatrix column to fetch
pub fn scale_x(&self) -> f32
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
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
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
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
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
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 set_scale_x(&mut self, v: f32) -> &mut Matrix
pub fn set_scale_x(&mut self, v: f32) -> &mut Matrix
Sets the horizontal scale factor.
vhorizontal scale factor to store
pub fn set_scale_y(&mut self, v: f32) -> &mut Matrix
pub fn set_scale_y(&mut self, v: f32) -> &mut Matrix
Sets the vertical scale factor.
vvertical scale factor to store
pub fn set_skew_y(&mut self, v: f32) -> &mut Matrix
pub fn set_skew_y(&mut self, v: f32) -> &mut Matrix
Sets the vertical skew factor.
vvertical skew factor to store
pub fn set_skew_x(&mut self, v: f32) -> &mut Matrix
pub fn set_skew_x(&mut self, v: f32) -> &mut Matrix
Sets the horizontal skew factor.
vhorizontal skew factor to store
pub fn set_translate_x(&mut self, v: f32) -> &mut Matrix
pub fn set_translate_x(&mut self, v: f32) -> &mut Matrix
Sets the horizontal translation.
vhorizontal translation to store
pub fn set_translate_y(&mut self, v: f32) -> &mut Matrix
pub fn set_translate_y(&mut self, v: f32) -> &mut Matrix
Sets the vertical translation.
vvertical translation to store
pub fn set_persp_x(&mut self, v: f32) -> &mut Matrix
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.
vperspective factor
pub fn set_persp_y(&mut self, v: f32) -> &mut Matrix
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.
vperspective 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
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_xhorizontal scale factor to storeskew_xhorizontal skew factor to storetrans_xhorizontal translation to storeskew_yvertical skew factor to storescale_yvertical scale factor to storetrans_yvertical translation to storepersp_0input x-axis values perspective factor to storepersp_1input y-axis values perspective factor to storepersp_2perspective scale factor to store
pub fn get_9(&self, buffer: &mut [f32; 9])
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.
bufferstorage for nine scalar values
pub fn set_9(&mut self, buffer: &[f32; 9]) -> &mut Matrix
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.
buffernine scalar values
pub fn reset(&mut self) -> &mut Matrix
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
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
pub fn set_translate(&mut self, v: impl Into<Point>) -> &mut Matrix
Sets the matrix to translate by v.
vvector containing horizontal and vertical translation
pub fn set_scale(
&mut self,
_: (f32, f32),
pivot: impl Into<Option<Point>>,
) -> &mut Matrix
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.
sxhorizontal scale factorsyvertical scale factorpivotpivot on x- and y-axes
pub fn set_rotate(
&mut self,
degrees: f32,
pivot: impl Into<Option<Point>>,
) -> &mut Matrix
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.
degreesangle of axes relative to upright axespivotpivot on x- and y-axes
pub fn set_sin_cos(
&mut self,
_: (f32, f32),
pivot: impl Into<Option<Point>>,
) -> &mut Matrix
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_valuerotation vector x-axis componentcos_valuerotation vector y-axis componentpivotpivot on x- and y-axes
pub fn set_rsxform(&mut self, rsxform: &RSXform) -> &mut Matrix
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).
rsxformcompressedRSXformmatrix
Example (C++): https://fiddle.skia.org/c/@Matrix_setRSXform
pub fn set_skew(
&mut self,
_: (f32, f32),
pivot: impl Into<Option<Point>>,
) -> &mut Matrix
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.
kxhorizontal skew factorkyvertical skew factorpivotpivot on x- and y-axes
pub fn set_concat(&mut self, a: &Matrix, b: &Matrix) -> &mut Matrix
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 |amatrix on left side of multiply expressionbmatrix on right side of multiply expression
pub fn pre_translate(&mut self, delta: impl Into<Point>) -> &mut Matrix
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 |deltax- and y-axis translation before applying the matrix
pub fn pre_scale(
&mut self,
_: (f32, f32),
pivot: impl Into<Option<Point>>,
) -> &mut 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 * pysets 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 |sxhorizontal scale factorsyvertical scale factorpivotpivot on x- and y-axes
pub fn pre_rotate(
&mut self,
degrees: f32,
pivot: impl Into<Option<Point>>,
) -> &mut Matrix
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) * pysets 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 |degreesangle of axes relative to upright axespivotpivot on x- and y-axes
pub fn pre_skew(
&mut self,
_: (f32, f32),
pivot: impl Into<Option<Point>>,
) -> &mut Matrix
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 * pxsets 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 |kxhorizontal skew factorkyvertical skew factorpivotpivot on x- and y-axes
pub fn pre_concat(&mut self, other: &Matrix) -> &mut Matrix
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 |othermatrix on the right side of the multiply expression
pub fn post_translate(&mut self, delta: impl Into<Point>) -> &mut Matrix
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 |deltax- and y-axis translation after applying the matrix
pub fn post_scale(
&mut self,
_: (f32, f32),
pivot: impl Into<Option<Point>>,
) -> &mut 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 * pysets 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 |sxhorizontal scale factorsyvertical scale factorpivotpivot on x- and y-axes
pub fn post_idiv(&mut self, _: (i32, i32)) -> bool
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
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) * pysets 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 |degreesangle of axes relative to upright axespivotpivot on x- and y-axes
pub fn post_skew(
&mut self,
_: (f32, f32),
pivot: impl Into<Option<Point>>,
) -> &mut Matrix
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 * pxsets 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 |kxhorizontal skew factorkyvertical skew factorpivotpivot on x- and y-axes
pub fn post_concat(&mut self, other: &Matrix) -> &mut Matrix
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 |othermatrix 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>
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>
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).
srcsource rectangledstdestination rectanglestfscale-to-fit mode, defaults toScaleToFit::Fill
pub fn rect_to_rect_or_identity(
src: impl AsRef<Rect>,
dst: impl AsRef<Rect>,
stf: impl Into<Option<SkMatrix_ScaleToFit>>,
) -> Matrix
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).
srcsource rectangledstdestination rectanglestfscale-to-fit mode, defaults toScaleToFit::Fill
pub fn poly_to_poly(src: &[Point], dst: &[Point]) -> Option<Matrix>
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.
srcsource polygon pointsdstdestination polygon points
Example (C++): https://fiddle.skia.org/c/@Matrix_setPolyToPoly
pub fn set_poly_to_poly(&mut self, src: &[Point], dst: &[Point]) -> bool
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.
srcsource polygon pointsdstdestination polygon points
pub fn from_poly_to_poly(src: &[Point], dst: &[Point]) -> Option<Matrix>
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.
srcsource polygon pointsdstdestination polygon points
pub fn invert(&self) -> Option<Matrix>
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])
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.
affinestorage for the 3 by 2 affine matrix
Example (C++): https://fiddle.skia.org/c/@Matrix_SetAffineIdentity
pub fn to_affine(self) -> Option<[f32; 6]>
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
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 |affine3 by 2 affine matrix
pub fn from_affine(affine: &[f32; 6]) -> 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 |affine3 by 2 affine matrix
pub fn normalize_perspective(&mut self)
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])
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+Isrc and dst may point to the same storage.
dststorage where the transformed points are writtensrcstorage where the points are read from
Example (C++): https://fiddle.skia.org/c/@Matrix_mapPoints
pub fn map_points_inplace(&self, pts: &mut [Point])
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+Iptspoints to be transformed in place
pub fn map_homogeneous_points(&self, dst: &mut [Point3], src: &[Point3])
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|dststorage where the transformed points are writtensrcstorage where the points are read from
Example (C++): https://fiddle.skia.org/c/@Matrix_mapHomogeneousPoints
pub fn map_homogeneous_point(&self, src: Point3) -> Point3
pub fn map_homogeneous_point(&self, src: Point3) -> Point3
Maps src point by the matrix.
srcpoint to map
pub fn map_homogeneous_points_2d(&self, dst: &mut [Point3], src: &[Point])
use map_points_to_homogeneous()
pub fn map_points_to_homogeneous(&self, dst: &mut [Point3], src: &[Point])
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).
dststorage where the transformed points are writtensrcstorage where the points are read from
pub fn map_point_to_homogeneous(&self, src: Point) -> Point3
pub fn map_point_to_homogeneous(&self, src: Point) -> Point3
Returns src mapped to a homogeneous point.
srcpoint to map
pub fn map_xy(&self, x: f32, y: f32) -> Point
use map_point((x, y))
pub fn map_point(&self, point: impl Into<Point>) -> Point
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+Ipointpoint to map
pub fn map_point_affine(&self, point: impl Into<Point>) -> Point
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().
pointpoint to map
pub fn map_origin(&self) -> Point
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 Ipub fn map_vectors(&self, dst: &mut [Point], src: &[Point])
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+Isrc and dst may point to the same storage.
dststorage where the transformed vectors are writtensrcstorage where the vectors are read from
Example (C++): https://fiddle.skia.org/c/@Matrix_mapVectors
pub fn map_vectors_inplace(&self, vecs: &mut [Point])
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.
vecsvectors to transform, and storage for the mapped vectors
pub fn map_vector(&self, vec: impl Into<Point>) -> Point
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+Ivecvector to map
pub fn map_rect(&self, src: impl AsRef<Rect>) -> (Rect, bool)
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().
srcrectangle to map
Example (C++): https://fiddle.skia.org/c/@Matrix_mapRect
pub fn map_rect_to_quad(&self, rect: impl AsRef<Rect>) -> [Point; 4]
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).
rectrectangle to map
pub fn map_rect_scale_translate(&self, src: impl AsRef<Rect>) -> Option<Rect>
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).
srcrectangle to map
Example (C++): https://fiddle.skia.org/c/@Matrix_mapRectScaleTranslate
pub fn map_radius(&self, radius: f32) -> Option<f32>
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.
radiuscircle size to map
Example (C++): https://fiddle.skia.org/c/@Matrix_mapRadius
pub fn is_fixed_step_in_x(&self) -> !
removed without replacement
pub fn fixed_step_in_x(&self, _y: f32) -> !
removed without replacement
pub fn cheap_equal_to(&self, _other: &Matrix) -> !
removed without replacement
pub fn dump(&self)
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
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
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)
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>
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.
remainingmatrix without scaling; may beNone
Example (C++): https://fiddle.skia.org/c/@Matrix_decomposeScale
pub fn i() -> &'static Matrix
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
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
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 |amatrix on the left side of the multiply expressionbmatrix on the right side of the multiply expression
pub fn dirty_matrix_type_cache(&mut self)
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
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 |shorizontal and vertical scale factors to storethorizontal and vertical translation to store
pub fn is_finite(&self) -> bool
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 Copy for Matrix
§impl Index<AffineMember> for Matrix
impl Index<AffineMember> for Matrix
§impl IndexMut<AffineMember> for Matrix
impl IndexMut<AffineMember> for Matrix
§fn index_mut(
&mut self,
index: AffineMember,
) -> &mut <Matrix as Index<AffineMember>>::Output
fn index_mut( &mut self, index: AffineMember, ) -> &mut <Matrix as Index<AffineMember>>::Output
container[index]) operation. Read moreAuto Trait Implementations§
impl Freeze for Matrix
impl RefUnwindSafe for Matrix
impl Send for Matrix
impl Sync for Matrix
impl Unpin for Matrix
impl UnsafeUnpin for Matrix
impl UnwindSafe for Matrix
Blanket Implementations§
§impl<T> AnyEq for T
impl<T> AnyEq for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.