pub struct Transform {
pub position: (f32, f32),
pub scale: (f32, f32),
pub rotation: f32,
pub anchor: (f32, f32),
pub skew: (f32, f32),
}Expand description
Affine placement on the canvas. Applied in this order: translate → anchor-relative rotate → scale → skew.
Fields§
§position: (f32, f32)§scale: (f32, f32)§rotation: f32Radians, counter-clockwise, around anchor.
anchor: (f32, f32)Pivot point in normalised object-local coordinates (0..=1).
(0.5, 0.5) is the object centre.
skew: (f32, f32)Shear in radians, per axis.
Implementations§
Source§impl Transform
impl Transform
pub const fn identity() -> Self
Sourcepub fn to_matrix(&self, width: f32, height: f32) -> Transform2D
pub fn to_matrix(&self, width: f32, height: f32) -> Transform2D
Lower this high-level transform into a flat
oxideav_core::Transform2D (the SVG / PDF matrix(a,b,c,d,e,f)
form) for a content box of the given (width, height).
The struct’s per-field semantics are realised in the documented
order: a point in object-local space is first moved so the
normalised anchor sits at the origin, then
rotated, scaled, and sheared about that anchor, and finally
translated by position. Concretely the
returned matrix M satisfies
M = T(position) · T(+pivot) · skew · scale · rotate · T(-pivot)where pivot = (anchor.0 * width, anchor.1 * height). Applying
M to a local point yields its canvas-space coordinate. The
identity Transform over any content size lowers to
Transform2D::identity.
width / height are the object’s intrinsic content extent in
canvas units — only the anchor pivot depends on them, so a
zero-size content box still produces a well-formed (pivot-at-
origin) matrix.
Sourcepub fn apply_to_point(&self, width: f32, height: f32, point: Point) -> Point
pub fn apply_to_point(&self, width: f32, height: f32, point: Point) -> Point
Map an object-local point into canvas space under this
transform, for a content box of (width, height). Convenience
over to_matrix +
Transform2D::apply.
Sourcepub fn bbox(&self, width: f32, height: f32) -> Rect
pub fn bbox(&self, width: f32, height: f32) -> Rect
Axis-aligned bounding box, in canvas space, of a
(width, height) content box placed at the local origin
(0, 0)..(width, height) and run through this transform.
Computed by mapping the box’s four corners and taking the min /
max of the results, so it is tight for translate / scale / skew
and a correct (rotation-aware) enclosing box for rotations —
the AABB grows to contain a rotated rectangle rather than
rotating with it. The returned oxideav_core::Rect always has
non-negative width / height.