pub struct Transform { /* private fields */ }Expand description
A slot-local rigid transform applied after an item’s local geometry.
Rotation is about the local origin. Positive angles rotate clockwise in display coordinates, where Y increases downward, and translation is applied after rotation.
Implementations§
Source§impl Transform
impl Transform
Sourcepub fn new(x: Fixed, y: Fixed, rotation: Angle) -> Result<Self, ShapeError>
pub fn new(x: Fixed, y: Fixed, rotation: Angle) -> Result<Self, ShapeError>
Creates a validated translation and rotation.
Angles are normalized into the range 0..360 degrees.
Sourcepub const fn direction_q16(self) -> (i32, i32)
pub const fn direction_q16(self) -> (i32, i32)
Returns the cached (cosine, sine) direction used by this transform.
Each signed component uses 16 fractional bits, so 1.0 is represented
by 65_536. These are the exact normalized components used by
Self::try_transform_raw_point and
Self::try_inverse_raw_point, allowing a custom renderer to match the
built-in fixed-point mapping without recomputing trigonometry.
Sourcepub fn try_transform_raw_point(
self,
x_q24_8: i64,
y_q24_8: i64,
) -> Option<(i64, i64)>
pub fn try_transform_raw_point( self, x_q24_8: i64, y_q24_8: i64, ) -> Option<(i64, i64)>
Maps a local point using the built-in fixed-point transform arithmetic.
Inputs and outputs are Q24.8 coordinates stored in i64; for example,
a Fixed coordinate can be passed as i64::from(value.bits()).
Rotation uses the cached 16-fractional-bit direction returned by
Self::direction_q16, truncating integer division toward zero, then
translation is applied. This is the exact mapping used by the built-in
integer rasterizer.
Returns None if an intermediate product, sum, or difference cannot be
represented by i64.
Sourcepub fn try_inverse_raw_point(
self,
x_q24_8: i64,
y_q24_8: i64,
) -> Option<(i64, i64)>
pub fn try_inverse_raw_point( self, x_q24_8: i64, y_q24_8: i64, ) -> Option<(i64, i64)>
Inverse-maps a display point using the built-in fixed-point arithmetic.
Inputs and outputs are Q24.8 coordinates stored in i64. The inverse
uses the actual squared length of Self::direction_q16 instead of
assuming its quantized components have exactly unit length. Its
quotient/remainder calculation preserves the built-in truncation toward
zero without first multiplying the entire numerator by 65_536.
Returns None if an intermediate product, sum, or difference cannot be
represented by i64.
Sourcepub const fn is_identity(self) -> bool
pub const fn is_identity(self) -> bool
Returns true when this transform changes neither position nor angle.
Sourcepub fn transform_bounds(self, bounds: Bounds) -> Bounds
pub fn transform_bounds(self, bounds: Bounds) -> Bounds
Conservatively transforms half-open pixel bounds into display space.
Cardinal rotations are exact. Other rotations are expanded by one pixel to cover fixed-point direction rounding and sampling at pixel centers.
Sourcepub fn inverse_axis_aligned_bounds(self, bounds: Bounds) -> Option<Bounds>
pub fn inverse_axis_aligned_bounds(self, bounds: Bounds) -> Option<Bounds>
Inverse-maps display bounds when the result is exactly axis aligned.
This is available only for quarter turns with integral translation, which map destination pixel centers exactly onto local pixel centers.