Skip to main content

Transform

Struct Transform 

Source
pub struct Transform { /* private fields */ }
Expand description

A two-dimensional affine transform in double-precision design coordinates.

Coefficients are column-major [xx, yx, xy, yy, translation_x, translation_y]. Positive rotation is clockwise in the downward-positive coordinate system. Self::then applies transforms in reading order, not matrix-product order. Device-space geometry retains these f64 coefficients until explicit storage boundaries.

Implementations§

Source§

impl Transform

Source

pub const IDENTITY: Self

Leaves positions and vectors unchanged

Source

pub const fn from_coefficients(coefficients: [f64; 6]) -> Self

Preserves raw affine coefficients; consuming geometry validates them.

Source

pub const fn coefficients(self) -> [f64; 6]

Returns column-major affine coefficients without reducing precision.

Source

pub const fn translate(horizontal: f64, vertical: f64) -> Self

Translates positions without changing vectors.

Source

pub fn rotate(radians: f64) -> Self

Rotates clockwise around the coordinate origin, in radians.

Source

pub const fn scale(factor: f64) -> Self

Uniformly scales around the coordinate origin; negative values reflect.

Source

pub const fn scale_non_uniform(horizontal: f64, vertical: f64) -> Self

Scales each axis independently around the coordinate origin.

Source

pub fn skew(horizontal: f64, vertical: f64) -> Self

Skews each axis by the tangent of its angle in radians. Both shears act in one matrix, rather than as sequential operations.

Source

pub fn then(self, next: Self) -> Self

Applies this transform first, followed by next.

use motion_core::{Point, Transform};
let transform = Transform::translate(10.0, 0.0).then(Transform::scale(2.0));
assert_eq!(transform.apply(Point::new(1.0, 3.0)), Point::new(22.0, 6.0));
Source

pub fn apply(self, point: Point) -> Point

Maps a position, including translation.

Source

pub fn apply_vector(self, vector: Vector2) -> Vector2

Maps a displacement, ignoring translation.

Source

pub fn is_finite(self) -> bool

Returns whether all affine coefficients are finite.

Source

pub fn inverse(self) -> Option<Self>

Inverts a finite nonsingular transform when its inverse remains finite. Returns None for singular/nonfinite inputs or unrepresentable results. Rows are scaled before computing the determinant to avoid ordinary underflow/overflow for extremely small, large or unequal axis scales.

Source

pub fn decompose(self) -> Option<TransformComponents>

Decomposes into scale, horizontal shear, rotation, then translation.

The horizontal scale is positive; reflection is carried by vertical scale. Returns None for singular/nonfinite inputs or nonfinite components. Shear is stored as a coefficient, not an angle, to avoid losing precision when a large tangent is rounded to a right angle.

Source

pub fn interpolate(&self, target: &Self, progress: f64) -> Self

Interpolates decomposed components and takes the shortest rotation arc. A half-turn tie rotates clockwise; progress may extrapolate. Exact zero/one return the original matrices. If either endpoint cannot be decomposed, coefficients interpolate directly, allowing singular endpoints such as zero-scale entrances. Reflection changes can pass through a singular scale.

Trait Implementations§

Source§

impl Clone for Transform

Source§

fn clone(&self) -> Self

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 Interpolate for Transform

Source§

fn interpolate(&self, target: &Self, progress: f64) -> Self

Blends toward target with nominal progress zero at self and one at target. Read more
Source§

impl PartialEq for Transform

Source§

fn eq(&self, other: &Self) -> 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.