pub struct Matrix {
pub mat: [f32; 9],
}Expand description
3×3 变换矩阵(列向量形式 p' = M * p),系数布局见模块说明。
3×3 transform (column vectors p' = M * p); layout described at module level.
Fields§
§mat: [f32; 9]与 SkMatrix::fMat / get9 / set9 顺序一致。
Same order as SkMatrix::fMat / get9 / set9.
Implementations§
Source§impl Matrix
impl Matrix
Sourcepub fn invalid() -> Self
pub fn invalid() -> Self
非法/哨兵矩阵占位,非 Skia 单例;系数全为 f32::MAX,勿用于几何变换。
Sentinel / invalid placeholder (not the Skia singleton); all coeffs f32::MAX; do not use for mapping.
Sourcepub fn scale(sx: f32, sy: f32) -> Self
pub fn scale(sx: f32, sy: f32) -> Self
缩放矩阵:内部 setScale(sx, sy)。Scale matrix via setScale(sx, sy).
Sourcepub fn translate(dx: f32, dy: f32) -> Self
pub fn translate(dx: f32, dy: f32) -> Self
平移矩阵:setTranslate。Translation matrix via setTranslate.
Sourcepub fn rotate_deg(degrees: f32) -> Self
pub fn rotate_deg(degrees: f32) -> Self
绕原点旋转;正角度顺时针(Skia 约定)。Rotate about origin; positive degrees = clockwise (Skia).
Sourcepub fn make_all(
scale_x: f32,
skew_x: f32,
trans_x: f32,
skew_y: f32,
scale_y: f32,
trans_y: f32,
pers0: f32,
pers1: f32,
pers2: f32,
) -> Self
pub fn make_all( scale_x: f32, skew_x: f32, trans_x: f32, skew_y: f32, scale_y: f32, trans_y: f32, pers0: f32, pers1: f32, pers2: f32, ) -> Self
由九个系数构造,等价 SkMatrix::MakeAll / setAll。Build from nine coeffs (MakeAll / setAll).
Sourcepub const fn from_row_major_9(mat: [f32; 9]) -> Self
pub const fn from_row_major_9(mat: [f32; 9]) -> Self
从已有 get9 顺序数组封装,不校验数值。Wrap raw get9 array; no validation.
Sourcepub fn concat(a: &Matrix, b: &Matrix) -> Matrix
pub fn concat(a: &Matrix, b: &Matrix) -> Matrix
矩阵乘积 a * b,对齐 SkMatrix::Concat(a, b)。Matrix product a * b (SkMatrix::Concat).
Sourcepub fn set_identity(&mut self) -> &mut Self
pub fn set_identity(&mut self) -> &mut Self
同 Self::reset。Alias for Self::reset.
Sourcepub fn set_all(
&mut self,
scale_x: f32,
skew_x: f32,
trans_x: f32,
skew_y: f32,
scale_y: f32,
trans_y: f32,
pers0: f32,
pers1: f32,
pers2: f32,
) -> &mut Self
pub fn set_all( &mut self, scale_x: f32, skew_x: f32, trans_x: f32, skew_y: f32, scale_y: f32, trans_y: f32, pers0: f32, pers1: f32, pers2: f32, ) -> &mut Self
一次性写入九个系数,见模块「存储」说明。Set all nine coeffs (setAll).
Sourcepub fn set_translate(&mut self, dx: f32, dy: f32) -> &mut Self
pub fn set_translate(&mut self, dx: f32, dy: f32) -> &mut Self
替换为纯平移。Replace with translation (setTranslate).
Sourcepub fn set_scale(&mut self, sx: f32, sy: f32) -> &mut Self
pub fn set_scale(&mut self, sx: f32, sy: f32) -> &mut Self
替换为以原点为基准的缩放。Replace with scale about origin.
Sourcepub fn set_scale_pivot(
&mut self,
sx: f32,
sy: f32,
px: f32,
py: f32,
) -> &mut Self
pub fn set_scale_pivot( &mut self, sx: f32, sy: f32, px: f32, py: f32, ) -> &mut Self
替换为绕 (px, py) 的缩放。Replace with scale about pivot (px, py).
Sourcepub fn set_rotate(&mut self, degrees: f32) -> &mut Self
pub fn set_rotate(&mut self, degrees: f32) -> &mut Self
替换为绕原点旋转(正角度顺时针)。Replace with rotation about origin (CW positive).
Sourcepub fn set_rotate_pivot(&mut self, degrees: f32, px: f32, py: f32) -> &mut Self
pub fn set_rotate_pivot(&mut self, degrees: f32, px: f32, py: f32) -> &mut Self
替换为绕 (px, py) 旋转。Replace with rotation about (px, py).
Sourcepub fn set_sin_cos(&mut self, sin_v: f32, cos_v: f32) -> &mut Self
pub fn set_sin_cos(&mut self, sin_v: f32, cos_v: f32) -> &mut Self
替换为由 sin/cos 给出的旋转(绕原点)。Rotation from sin/cos about origin.
Sourcepub fn set_sin_cos_pivot(
&mut self,
sin_v: f32,
cos_v: f32,
px: f32,
py: f32,
) -> &mut Self
pub fn set_sin_cos_pivot( &mut self, sin_v: f32, cos_v: f32, px: f32, py: f32, ) -> &mut Self
同上,支点为 (px, py)。Same with pivot (px, py).
Sourcepub fn set_skew(&mut self, kx: f32, ky: f32) -> &mut Self
pub fn set_skew(&mut self, kx: f32, ky: f32) -> &mut Self
替换为错切(原点)。Replace with skew about origin.
Sourcepub fn set_skew_pivot(
&mut self,
kx: f32,
ky: f32,
px: f32,
py: f32,
) -> &mut Self
pub fn set_skew_pivot( &mut self, kx: f32, ky: f32, px: f32, py: f32, ) -> &mut Self
替换为绕 (px, py) 的错切。Replace with skew about (px, py).
Sourcepub fn set_scale_translate(
&mut self,
sx: f32,
sy: f32,
tx: f32,
ty: f32,
) -> &mut Self
pub fn set_scale_translate( &mut self, sx: f32, sy: f32, tx: f32, ty: f32, ) -> &mut Self
替换为无错切、无透视的缩放+平移(常用优化形式)。Replace with scale+translate only.
Sourcepub fn set_concat(&mut self, a: &Matrix, b: &Matrix) -> &mut Self
pub fn set_concat(&mut self, a: &Matrix, b: &Matrix) -> &mut Self
self = a * b(Self::concat)。self = a * b (setConcat).
Sourcepub fn set_rect_to_rect(
&mut self,
src: &Rect,
dst: &Rect,
stf: ScaleToFit,
) -> bool
pub fn set_rect_to_rect( &mut self, src: &Rect, dst: &Rect, stf: ScaleToFit, ) -> bool
构造将 src 映射到 dst 的变换(按 ScaleToFit);成功时覆盖 self,失败时行为与 Skia 一致。
Map src onto dst per ScaleToFit; on failure matches Skia setRectToRect.
Sourcepub fn pre_translate(&mut self, dx: f32, dy: f32) -> &mut Self
pub fn pre_translate(&mut self, dx: f32, dy: f32) -> &mut Self
self = self * T(dx, dy)。preTranslate.
Sourcepub fn pre_scale_pivot(
&mut self,
sx: f32,
sy: f32,
px: f32,
py: f32,
) -> &mut Self
pub fn pre_scale_pivot( &mut self, sx: f32, sy: f32, px: f32, py: f32, ) -> &mut Self
带支点的 preScale。preScale with pivot.
Sourcepub fn pre_rotate(&mut self, degrees: f32) -> &mut Self
pub fn pre_rotate(&mut self, degrees: f32) -> &mut Self
preRotate(正角度顺时针)。preRotate (CW positive).
Sourcepub fn pre_rotate_pivot(&mut self, degrees: f32, px: f32, py: f32) -> &mut Self
pub fn pre_rotate_pivot(&mut self, degrees: f32, px: f32, py: f32) -> &mut Self
带支点的 preRotate。preRotate with pivot.
Sourcepub fn pre_skew_pivot(
&mut self,
kx: f32,
ky: f32,
px: f32,
py: f32,
) -> &mut Self
pub fn pre_skew_pivot( &mut self, kx: f32, ky: f32, px: f32, py: f32, ) -> &mut Self
带支点的 preSkew。preSkew with pivot.
Sourcepub fn pre_concat(&mut self, other: &Matrix) -> &mut Self
pub fn pre_concat(&mut self, other: &Matrix) -> &mut Self
self = self * other。preConcat.
Sourcepub fn post_translate(&mut self, dx: f32, dy: f32) -> &mut Self
pub fn post_translate(&mut self, dx: f32, dy: f32) -> &mut Self
self = T(dx, dy) * self。postTranslate.
Sourcepub fn post_scale(&mut self, sx: f32, sy: f32) -> &mut Self
pub fn post_scale(&mut self, sx: f32, sy: f32) -> &mut Self
postScale。postScale.
Sourcepub fn post_scale_pivot(
&mut self,
sx: f32,
sy: f32,
px: f32,
py: f32,
) -> &mut Self
pub fn post_scale_pivot( &mut self, sx: f32, sy: f32, px: f32, py: f32, ) -> &mut Self
带支点的 postScale。postScale with pivot.
Sourcepub fn post_rotate(&mut self, degrees: f32) -> &mut Self
pub fn post_rotate(&mut self, degrees: f32) -> &mut Self
postRotate(正角度顺时针)。postRotate (CW positive).
Sourcepub fn post_rotate_pivot(&mut self, degrees: f32, px: f32, py: f32) -> &mut Self
pub fn post_rotate_pivot(&mut self, degrees: f32, px: f32, py: f32) -> &mut Self
带支点的 postRotate。postRotate with pivot.
Sourcepub fn post_skew_pivot(
&mut self,
kx: f32,
ky: f32,
px: f32,
py: f32,
) -> &mut Self
pub fn post_skew_pivot( &mut self, kx: f32, ky: f32, px: f32, py: f32, ) -> &mut Self
带支点的 postSkew。postSkew with pivot.
Sourcepub fn post_concat(&mut self, other: &Matrix) -> &mut Self
pub fn post_concat(&mut self, other: &Matrix) -> &mut Self
self = other * self。postConcat.
Sourcepub fn get_type(&self) -> u32
pub fn get_type(&self) -> u32
类型掩码(matrix_type 中的位)。Type mask (getType).
Sourcepub fn is_identity(&self) -> bool
pub fn is_identity(&self) -> bool
是否单位矩阵(容差内)。isIdentity.
Sourcepub fn is_scale_translate(&self) -> bool
pub fn is_scale_translate(&self) -> bool
是否可表示为仅有缩放与平移(无错切/旋转/透视)。isScaleTranslate.
Sourcepub fn rect_stays_rect(&self) -> bool
pub fn rect_stays_rect(&self) -> bool
是否将任意轴对齐矩形仍映射为轴对齐矩形。rectStaysRect.
Sourcepub fn preserves_axis_alignment(&self) -> bool
pub fn preserves_axis_alignment(&self) -> bool
同 SkMatrix::preservesAxisAlignment(等同于 Self::rect_stays_rect。)。
Same as preservesAxisAlignment (alias of Self::rect_stays_rect).
Sourcepub fn has_perspective(&self) -> bool
pub fn has_perspective(&self) -> bool
是否含透视分量。hasPerspective.
Sourcepub fn get_scale_x(&self) -> f32
pub fn get_scale_x(&self) -> f32
mat[coeff::M_SCALE_X]。getScaleX.
Sourcepub fn get_skew_x(&self) -> f32
pub fn get_skew_x(&self) -> f32
getSkewX.
Sourcepub fn get_translate_x(&self) -> f32
pub fn get_translate_x(&self) -> f32
getTranslateX.
Sourcepub fn get_skew_y(&self) -> f32
pub fn get_skew_y(&self) -> f32
getSkewY.
Sourcepub fn get_scale_y(&self) -> f32
pub fn get_scale_y(&self) -> f32
getScaleY.
Sourcepub fn get_translate_y(&self) -> f32
pub fn get_translate_y(&self) -> f32
getTranslateY.
Sourcepub fn get_persp_x(&self) -> f32
pub fn get_persp_x(&self) -> f32
透视行:getPerspX / fMat[kMPersp0].
Sourcepub fn get_persp_y(&self) -> f32
pub fn get_persp_y(&self) -> f32
getPerspY.
Sourcepub fn get_persp_z(&self) -> f32
pub fn get_persp_z(&self) -> f32
getPerspZ(末元通常 1)。getPerspZ (often 1).
Sourcepub fn set_coeff(&mut self, index: usize, value: f32) -> &mut Self
pub fn set_coeff(&mut self, index: usize, value: f32) -> &mut Self
按线性下标写系数(不更新 Skia 内部缓存分类;仅改数组)。Set coeff by index (raw write; no Skia type cache update).
Sourcepub fn invert_to(&self, out_or_inverse: &mut Matrix) -> bool
pub fn invert_to(&self, out_or_inverse: &mut Matrix) -> bool
求逆写入 out_or_inverse;不可逆返回 false。SkMatrix::invert.
Sourcepub fn try_inverse(&self) -> Option<Matrix>
pub fn try_inverse(&self) -> Option<Matrix>
可逆时 Some(逆矩阵),否则 None。invert wrapped in Option.
Sourcepub fn map_xy(&self, x: f32, y: f32) -> Point
pub fn map_xy(&self, x: f32, y: f32) -> Point
映射 (x, y)(透视下含 projective divide),与 SkMatrix::mapXY 一致。Map point (mapXY).
Sourcepub fn map_point(&self, p: Point) -> Point
pub fn map_point(&self, p: Point) -> Point
Self::map_xy 的便捷封装。Convenience over Self::map_xy.
Sourcepub fn map_homogeneous(&self, x: f32, y: f32, z: f32) -> [f32; 3]
pub fn map_homogeneous(&self, x: f32, y: f32, z: f32) -> [f32; 3]
线性部分左乘齐次向量 [x,y,z]^T,不做透视除法;与 SkMatrix::mapHomogeneousPoints 的线性步骤一致。
Homogeneous multiply without divide-by-w; matches linear step of mapHomogeneousPoints.
Sourcepub fn map_points(&self, dst: &mut [Point], src: &[Point])
pub fn map_points(&self, dst: &mut [Point], src: &[Point])
将 src 前 min(len) 项映射写入 dst(与 mapPoints(dst, src) 批量语义一致)。Batch map like mapPoints.
Sourcepub fn map_points_inplace(&self, pts: &mut [Point])
pub fn map_points_inplace(&self, pts: &mut [Point])
原地映射点集。In-place mapPoints.
Sourcepub fn map_origin(&self) -> Point
pub fn map_origin(&self) -> Point
mapXY(0, 0),即原点经本矩阵映射后的位置。SkMatrix::mapOrigin.
Sourcepub fn map_rect(&self, src: &Rect) -> (Rect, bool)
pub fn map_rect(&self, src: &Rect) -> (Rect, bool)
将矩形 src 经本矩阵映射;返回 (包围盒, 是否仍为轴对齐矩形)。SkMatrix::mapRect.
Sourcepub fn map_rect_scale_translate(&self, src: &Rect) -> Rect
pub fn map_rect_scale_translate(&self, src: &Rect) -> Rect
当 Self::is_scale_translate 为真时的快速矩形映射(行为 undefined 若矩阵不满足前提——与 Skia 一致)。Fast path mapRectScaleTranslate.
Sourcepub fn get_min_scale(&self) -> f32
pub fn get_min_scale(&self) -> f32
局部最小缩放因子(Skia 定义)。getMinScale.
Sourcepub fn get_max_scale(&self) -> f32
pub fn get_max_scale(&self) -> f32
局部最大缩放因子。getMaxScale.
Sourcepub fn get_min_max_scales(&self) -> Option<(f32, f32)>
pub fn get_min_max_scales(&self) -> Option<(f32, f32)>
同时取得最小/最大缩放;若矩阵退化或无法计算则 None。getMinMaxScales.
Sourcepub fn write_to_memory(&self, buf: &mut [u8]) -> usize
pub fn write_to_memory(&self, buf: &mut [u8]) -> usize
序列化 9×f32 到 buf;返回实际写入字节数,不足时写入 0。writeToMemory.
Sourcepub fn read_from_memory(&mut self, buf: &[u8]) -> usize
pub fn read_from_memory(&mut self, buf: &[u8]) -> usize
从 buf 反序列化;成功返回读取字节数。readFromMemory.
Trait Implementations§
Source§impl Mul for &Matrix
同上。Same as Matrix::concat.
impl Mul for &Matrix
同上。Same as Matrix::concat.
Source§impl Mul for Matrix
矩阵乘法:lhs * rhs 与 Matrix::concat 语义相同。Mul: same as Matrix::concat.
impl Mul for Matrix
矩阵乘法:lhs * rhs 与 Matrix::concat 语义相同。Mul: same as Matrix::concat.