Skip to main content

Transform

Struct Transform 

Source
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

Source

pub const IDENTITY: Self

The identity transform.

Source

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.

Source

pub const fn x(self) -> Fixed

Returns the horizontal translation.

Source

pub const fn y(self) -> Fixed

Returns the vertical translation.

Source

pub const fn rotation(self) -> Angle

Returns the normalized clockwise rotation.

Source

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.

Source

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.

Source

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.

Source

pub const fn is_identity(self) -> bool

Returns true when this transform changes neither position nor angle.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Transform

Source§

fn clone(&self) -> Transform

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Transform

Source§

impl Debug for Transform

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Transform

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Transform

Source§

impl Hash for Transform

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Transform

Source§

fn eq(&self, other: &Transform) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Transform

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.