Skip to main content

Matrix

Struct Matrix 

Source
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

Source

pub const IDENTITY: Self

单位矩阵常量。Identity matrix constant.

Source

pub const fn identity() -> Self

返回单位矩阵。Returns the identity matrix.

Source

pub fn invalid() -> Self

非法/哨兵矩阵占位, Skia 单例;系数全为 f32::MAX,勿用于几何变换。 Sentinel / invalid placeholder (not the Skia singleton); all coeffs f32::MAX; do not use for mapping.

Source

pub fn scale(sx: f32, sy: f32) -> Self

缩放矩阵:内部 setScale(sx, sy)。Scale matrix via setScale(sx, sy).

Source

pub fn translate(dx: f32, dy: f32) -> Self

平移矩阵:setTranslate。Translation matrix via setTranslate.

Source

pub fn rotate_deg(degrees: f32) -> Self

绕原点旋转;正角度顺时针(Skia 约定)。Rotate about origin; positive degrees = clockwise (Skia).

Source

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

Source

pub const fn from_row_major_9(mat: [f32; 9]) -> Self

从已有 get9 顺序数组封装,校验数值。Wrap raw get9 array; no validation.

Source

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

矩阵乘积 a * b,对齐 SkMatrix::Concat(a, b)。Matrix product a * b (SkMatrix::Concat).

Source

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

置为单位矩阵。Reset to identity (SkMatrix::reset).

Source

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

Self::reset。Alias for Self::reset.

Source

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

Source

pub fn set_translate(&mut self, dx: f32, dy: f32) -> &mut Self

替换为纯平移。Replace with translation (setTranslate).

Source

pub fn set_scale(&mut self, sx: f32, sy: f32) -> &mut Self

替换为以原点为基准的缩放。Replace with scale about origin.

Source

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

Source

pub fn set_rotate(&mut self, degrees: f32) -> &mut Self

替换为绕原点旋转(正角度顺时针)。Replace with rotation about origin (CW positive).

Source

pub fn set_rotate_pivot(&mut self, degrees: f32, px: f32, py: f32) -> &mut Self

替换为绕 (px, py) 旋转。Replace with rotation about (px, py).

Source

pub fn set_sin_cos(&mut self, sin_v: f32, cos_v: f32) -> &mut Self

替换为由 sin/cos 给出的旋转(绕原点)。Rotation from sin/cos about origin.

Source

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

Source

pub fn set_skew(&mut self, kx: f32, ky: f32) -> &mut Self

替换为错切(原点)。Replace with skew about origin.

Source

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

Source

pub fn set_scale_translate( &mut self, sx: f32, sy: f32, tx: f32, ty: f32, ) -> &mut Self

替换为无错切、无透视的缩放+平移(常用优化形式)。Replace with scale+translate only.

Source

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

self = a * bSelf::concat)。self = a * b (setConcat).

Source

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.

Source

pub fn pre_translate(&mut self, dx: f32, dy: f32) -> &mut Self

self = self * T(dx, dy)preTranslate.

Source

pub fn pre_scale(&mut self, sx: f32, sy: f32) -> &mut Self

self = self * S(sx, sy)preScale.

Source

pub fn pre_scale_pivot( &mut self, sx: f32, sy: f32, px: f32, py: f32, ) -> &mut Self

带支点的 preScalepreScale with pivot.

Source

pub fn pre_rotate(&mut self, degrees: f32) -> &mut Self

preRotate(正角度顺时针)。preRotate (CW positive).

Source

pub fn pre_rotate_pivot(&mut self, degrees: f32, px: f32, py: f32) -> &mut Self

带支点的 preRotatepreRotate with pivot.

Source

pub fn pre_skew(&mut self, kx: f32, ky: f32) -> &mut Self

preSkewpreSkew.

Source

pub fn pre_skew_pivot( &mut self, kx: f32, ky: f32, px: f32, py: f32, ) -> &mut Self

带支点的 preSkewpreSkew with pivot.

Source

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

self = self * otherpreConcat.

Source

pub fn post_translate(&mut self, dx: f32, dy: f32) -> &mut Self

self = T(dx, dy) * selfpostTranslate.

Source

pub fn post_scale(&mut self, sx: f32, sy: f32) -> &mut Self

postScalepostScale.

Source

pub fn post_scale_pivot( &mut self, sx: f32, sy: f32, px: f32, py: f32, ) -> &mut Self

带支点的 postScalepostScale with pivot.

Source

pub fn post_rotate(&mut self, degrees: f32) -> &mut Self

postRotate(正角度顺时针)。postRotate (CW positive).

Source

pub fn post_rotate_pivot(&mut self, degrees: f32, px: f32, py: f32) -> &mut Self

带支点的 postRotatepostRotate with pivot.

Source

pub fn post_skew(&mut self, kx: f32, ky: f32) -> &mut Self

postSkewpostSkew.

Source

pub fn post_skew_pivot( &mut self, kx: f32, ky: f32, px: f32, py: f32, ) -> &mut Self

带支点的 postSkewpostSkew with pivot.

Source

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

self = other * selfpostConcat.

Source

pub fn get_type(&self) -> u32

类型掩码(matrix_type 中的位)。Type mask (getType).

Source

pub fn is_identity(&self) -> bool

是否单位矩阵(容差内)。isIdentity.

Source

pub fn is_scale_translate(&self) -> bool

是否可表示为仅有缩放与平移(无错切/旋转/透视)。isScaleTranslate.

Source

pub fn rect_stays_rect(&self) -> bool

是否将任意轴对齐矩形仍映射为轴对齐矩形。rectStaysRect.

Source

pub fn preserves_axis_alignment(&self) -> bool

SkMatrix::preservesAxisAlignment(等同于 Self::rect_stays_rect。)。 Same as preservesAxisAlignment (alias of Self::rect_stays_rect).

Source

pub fn has_perspective(&self) -> bool

是否含透视分量。hasPerspective.

Source

pub fn is_finite(&self) -> bool

所有系数是否均为有限浮点。SkMatrix finite check (isFinite-class API).

Source

pub fn get_scale_x(&self) -> f32

mat[coeff::M_SCALE_X]getScaleX.

Source

pub fn get_skew_x(&self) -> f32

getSkewX.

Source

pub fn get_translate_x(&self) -> f32

getTranslateX.

Source

pub fn get_skew_y(&self) -> f32

getSkewY.

Source

pub fn get_scale_y(&self) -> f32

getScaleY.

Source

pub fn get_translate_y(&self) -> f32

getTranslateY.

Source

pub fn get_persp_x(&self) -> f32

透视行:getPerspX / fMat[kMPersp0].

Source

pub fn get_persp_y(&self) -> f32

getPerspY.

Source

pub fn get_persp_z(&self) -> f32

getPerspZ(末元通常 1)。getPerspZ (often 1).

Source

pub fn get(&self, index: usize) -> f32

按线性下标 0..9 读系数。Raw index 0..9 into Self::mat.

Source

pub fn set_coeff(&mut self, index: usize, value: f32) -> &mut Self

按线性下标写系数(更新 Skia 内部缓存分类;仅改数组)。Set coeff by index (raw write; no Skia type cache update).

Source

pub fn invert_to(&self, out_or_inverse: &mut Matrix) -> bool

求逆写入 out_or_inverse;不可逆返回 falseSkMatrix::invert.

Source

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

可逆时 Some(逆矩阵),否则 Noneinvert wrapped in Option.

Source

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

映射 (x, y)(透视下含 projective divide),与 SkMatrix::mapXY 一致。Map point (mapXY).

Source

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

Self::map_xy 的便捷封装。Convenience over Self::map_xy.

Source

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.

Source

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

srcmin(len) 项映射写入 dst(与 mapPoints(dst, src) 批量语义一致)。Batch map like mapPoints.

Source

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

原地映射点集。In-place mapPoints.

Source

pub fn map_origin(&self) -> Point

mapXY(0, 0),即原点经本矩阵映射后的位置。SkMatrix::mapOrigin.

Source

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

将矩形 src 经本矩阵映射;返回 (包围盒, 是否仍为轴对齐矩形)SkMatrix::mapRect.

Source

pub fn map_rect_scale_translate(&self, src: &Rect) -> Rect

Self::is_scale_translate 为真时的快速矩形映射(行为 undefined 若矩阵不满足前提——与 Skia 一致)。Fast path mapRectScaleTranslate.

Source

pub fn get_min_scale(&self) -> f32

局部最小缩放因子(Skia 定义)。getMinScale.

Source

pub fn get_max_scale(&self) -> f32

局部最大缩放因子。getMaxScale.

Source

pub fn get_min_max_scales(&self) -> Option<(f32, f32)>

同时取得最小/最大缩放;若矩阵退化或无法计算则 NonegetMinMaxScales.

Source

pub fn write_to_memory(&self, buf: &mut [u8]) -> usize

序列化 f32buf;返回实际写入字节数,不足时写入 0。writeToMemory.

Source

pub fn read_from_memory(&mut self, buf: &[u8]) -> usize

buf 反序列化;成功返回读取字节数。readFromMemory.

Trait Implementations§

Source§

impl Clone for Matrix

Source§

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

impl Copy for Matrix

Source§

impl Debug for Matrix

Source§

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

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

impl Default for Matrix

Source§

fn default() -> Self

单位矩阵。Identity.

Source§

impl Eq for Matrix

Source§

impl Index<usize> for Matrix

Source§

type Output = f32

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &f32

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

impl IndexMut<usize> for Matrix

Source§

fn index_mut(&mut self, index: usize) -> &mut f32

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

impl Mul for Matrix

矩阵乘法:lhs * rhsMatrix::concat 语义相同。Mul: same as Matrix::concat.

Source§

type Output = Matrix

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul for &Matrix

同上。Same as Matrix::concat.

Source§

type Output = Matrix

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Matrix) -> Matrix

Performs the * operation. Read more
Source§

impl Mul<&Matrix> for Matrix

同上。Same as Matrix::concat.

Source§

type Output = Matrix

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Matrix) -> Matrix

Performs the * operation. Read more
Source§

impl Mul<Matrix> for &Matrix

同上。Same as Matrix::concat.

Source§

type Output = Matrix

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl PartialEq for Matrix

Source§

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

Skia SkMatrix 相等语义(非简单逐位 ==)。Skia matrix equality (not naive bit-compare).

1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.