pub struct Affine {
pub m: [f32; 6],
}Expand description
A 2D affine transform (a 2×3 matrix). A point (x, y) becomes
(a·x + c·y + e, b·x + d·y + f): a 2×2 linear part [[a, c], [b, d]] (scale,
rotation, shear) plus a translation (e, f).
Compositions read “right to left”: a.then(b) applies a then b. This is
the unified representation of a crate::LayerTransform’s paint transforms:
translation, scale (uniform or per axis) and rotation all fold into a single
matrix, with no approximation introduced by composing them.
Fields§
§m: [f32; 6][a, b, c, d, e, f]: x' = a·x + c·y + e, y' = b·x + d·y + f.
Implementations§
Source§impl Affine
impl Affine
Sourcepub const fn translation(tx: f32, ty: f32) -> Affine
pub const fn translation(tx: f32, ty: f32) -> Affine
A pure translation by (tx, ty).
Sourcepub fn rotation(angle: f32) -> Affine
pub fn rotation(angle: f32) -> Affine
A rotation of angle radians (clockwise, with y pointing down), about the
origin.
Sourcepub fn about(self, pivot: Point) -> Affine
pub fn about(self, pivot: Point) -> Affine
The same transform, but about pivot, which stays fixed:
T(pivot) ∘ self ∘ T(-pivot).
Sourcepub fn is_axis_aligned(self) -> bool
pub fn is_axis_aligned(self) -> bool
true when the transform is axis-aligned: its linear part is diagonal
(scale and/or translation, with no rotation and no shear), so the image of a
rectangle is still a rectangle.
Sourcepub fn apply_rect(self, r: Rect) -> Rect
pub fn apply_rect(self, r: Rect) -> Rect
The image of a rectangle under the transform. Exact when the matrix is
axis-aligned (Affine::is_axis_aligned); otherwise it returns the image’s
bounding box, since a rectangle cannot represent a rotated shape.