Skip to main content

Transform

Struct Transform 

Source
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: f32

Radians, 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

Source

pub const fn identity() -> Self

Source

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.

Source

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.

Source

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.

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 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> 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 = 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.