pub struct AffineTransform { /* private fields */ }Expand description
A 2D affine transformation (translate, rotate, scale, skew).
Stored as a 3×2 matrix internally via glam::Affine2, which gives
us SIMD-optimized operations on supported platforms. The matrix layout:
| a c tx |
| b d ty |
| 0 0 1 |Use this for standard 2D UI work — CSS transforms, canvas drawing,
element positioning. For 3D perspective and rotations around X/Y axes,
use Transform3D instead.
Implementations§
Source§impl AffineTransform
impl AffineTransform
pub const IDENTITY: Self
Sourcepub fn new(a: f32, b: f32, c: f32, d: f32, tx: f32, ty: f32) -> Self
pub fn new(a: f32, b: f32, c: f32, d: f32, tx: f32, ty: f32) -> Self
Construct from the six matrix components directly.
pub fn translate(tx: f32, ty: f32) -> Self
pub fn scale(sx: f32, sy: f32) -> Self
pub fn uniform_scale(s: f32) -> Self
pub fn is_identity(&self) -> bool
Sourcepub fn is_translation_only(&self) -> bool
pub fn is_translation_only(&self) -> bool
True when the transform only translates (no rotation, scale, or skew).
Sourcepub fn preserves_axis_alignment(&self) -> bool
pub fn preserves_axis_alignment(&self) -> bool
True when axis-aligned rectangles stay axis-aligned after transformation (no rotation or skew — only scale and translation).
Sourcepub fn pre_translate(&self, tx: f32, ty: f32) -> Self
pub fn pre_translate(&self, tx: f32, ty: f32) -> Self
Prepend a translation to this transform.
Sourcepub fn inverse(&self) -> Option<Self>
pub fn inverse(&self) -> Option<Self>
Compute the inverse. Returns None for singular (degenerate)
transforms where the determinant is zero.
pub fn determinant(&self) -> f32
pub fn transform_point(&self, p: Point) -> Point
Sourcepub fn transform_rect(&self, r: &Rect) -> Rect
pub fn transform_rect(&self, r: &Rect) -> Rect
Transform a rectangle. When the transform involves rotation or skew, the result is the axis-aligned bounding box of the transformed corners.
Trait Implementations§
Source§impl Clone for AffineTransform
impl Clone for AffineTransform
Source§fn clone(&self) -> AffineTransform
fn clone(&self) -> AffineTransform
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more