pub struct Transform2D {
pub a: f32,
pub b: f32,
pub c: f32,
pub d: f32,
pub e: f32,
pub f: f32,
}Expand description
2D 仿射变换矩阵,按 SVG 规范表示:
§$$ \begin{bmatrix} x’ \ y’ \ 1 \end{bmatrix}
\begin{bmatrix} a & c & e \ b & d & f \ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \ y \ 1 \end{bmatrix} $$
Fields§
§a: f32§b: f32§c: f32§d: f32§e: f32§f: f32Implementations§
Source§impl Transform2D
impl Transform2D
Sourcepub const fn new(a: f32, b: f32, c: f32, d: f32, e: f32, f: f32) -> Self
pub const fn new(a: f32, b: f32, c: f32, d: f32, e: f32, f: f32) -> Self
构造任意 2D 仿射矩阵 [a, b, c, d, e, f]。
Sourcepub fn rotate_around(deg: f32, cx: f32, cy: f32) -> Self
pub fn rotate_around(deg: f32, cx: f32, cy: f32) -> Self
绕指定中心 (cx, cy) 顺时针旋转(角度制 deg)。
Sourcepub fn is_identity(self) -> bool
pub fn is_identity(self) -> bool
判断是否为单位变换矩阵。
Sourcepub fn transform_region(self, r: Region) -> Region
pub fn transform_region(self, r: Region) -> Region
计算逻辑矩形经当前仿射变换后的轴对齐外接包围盒(像素向外取整)。
Sourcepub fn centered_at(self, cx: f32, cy: f32) -> Self
pub fn centered_at(self, cx: f32, cy: f32) -> Self
将当前绕局部中心 (cx, cy) 表达的变换转换到屏幕空间(T(cx,cy) * self * T(-cx,-cy))。
Sourcepub fn approx_scale(self) -> f32
pub fn approx_scale(self) -> f32
估算该仿射变换对应的平均各向同性缩放系数(用于缩放 stroke-width)。
Sourcepub fn parse_svg_attr(input: &str) -> Self
pub fn parse_svg_attr(input: &str) -> Self
解析 SVG transform 属性字符串(支持 translate/scale/rotate/skewX/skewY/matrix 任意组合)。
Trait Implementations§
Source§impl Clone for Transform2D
impl Clone for Transform2D
impl Copy for Transform2D
Source§impl Debug for Transform2D
impl Debug for Transform2D
Source§impl Default for Transform2D
impl Default for Transform2D
Source§impl PartialEq for Transform2D
impl PartialEq for Transform2D
impl StructuralPartialEq for Transform2D
Auto Trait Implementations§
impl Forget for Transform2D
impl Freeze for Transform2D
impl Move for Transform2D
impl RefUnwindSafe for Transform2D
impl Send for Transform2D
impl Sync for Transform2D
impl Unpin for Transform2D
impl UnsafeUnpin for Transform2D
impl UnwindSafe for Transform2D
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
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,
Source§impl<T> FluentBuilder for T
impl<T> FluentBuilder for T
Source§fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self
fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self
当
condition 为 true 时执行闭包修饰自身,否则原样返回。Source§fn when_else(
self,
condition: bool,
then: impl FnOnce(Self) -> Self,
else_fn: impl FnOnce(Self) -> Self,
) -> Self
fn when_else( self, condition: bool, then: impl FnOnce(Self) -> Self, else_fn: impl FnOnce(Self) -> Self, ) -> Self
根据
condition 在两个修饰分支之间二选一。Source§fn when_some<O>(
self,
option: Option<O>,
then: impl FnOnce(Self, O) -> Self,
) -> Self
fn when_some<O>( self, option: Option<O>, then: impl FnOnce(Self, O) -> Self, ) -> Self
当
option 为 Some(value) 时执行闭包修饰自身,否则原样返回。