Skip to main content

Transform2D

Struct Transform2D 

Source
pub struct Transform2D {
    pub a: f64,
    pub b: f64,
    pub c: f64,
    pub d: f64,
    pub e: f64,
    pub f: f64,
}
Expand description

A two-dimensional affine transform stored as the six meaningful entries of a 3×3 matrix.

The matrix is applied to a point (x, y) as:

x' = a·x + c·y + e
y' = b·x + d·y + f

This is the same layout SVG and Canvas2D use, so a transform built here can be handed to a Canvas2D context verbatim.

Fields§

§a: f64

The horizontal scale / shear term applied to x.

§b: f64

The vertical shear term applied to x.

§c: f64

The horizontal shear term applied to y.

§d: f64

The vertical scale / shear term applied to y.

§e: f64

The horizontal translation.

§f: f64

The vertical translation.

Implementations§

Source§

impl Transform2D

Inherent implementation of Transform2D.

Source

pub fn identity() -> Self

Returns the identity transform.

Source

pub fn translate(tx: f64, ty: f64) -> Self

Returns a pure translation.

§Arguments
  • f64 - A 64-bit float (f64).
Source

pub fn scale(sx: f64, sy: f64) -> Self

Returns a pure scale.

§Arguments
  • f64 - A 64-bit float (f64).
Source

pub fn rotate(angle: f64) -> Self

Returns a pure rotation, in radians, around the origin.

§Arguments
  • f64 - A 64-bit float (f64).
Source

pub fn from_rect_to_rect(from: BBox, to: BBox) -> Self

Returns the transform that maps the from rectangle onto the to rectangle, scaling uniformly on both axes and centering the result.

§Arguments
  • BBox - A BBox parameter.
Source

pub fn then(&self, other: &Self) -> Self

Returns the composition of this transform with other, where other is applied first.

§Arguments
  • &Self - Shared reference to a Self.
Source

pub fn apply(&self, x: f64, y: f64) -> (f64, f64)

Applies the transform to a point.

§Arguments
  • f64 - A 64-bit float (f64).
§Returns
  • (f64, f64) - A (f64, f64) value.
Source

pub fn apply_f32(&self, x: f32, y: f32) -> (f32, f32)

Applies the transform to a point, keeping 32-bit precision.

§Arguments
  • f32 - A 32-bit float (f32).
§Returns
  • (f32, f32) - A (f32, f32) value.
Source

pub fn determinant(&self) -> f64

Returns the transform’s determinant.

A determinant of zero means the transform collapses the plane onto a line or a point; such a transform has no inverse.

§Returns
  • f64 - A 64-bit float.
Source

pub fn invert(&self) -> Option<Self>

Returns the inverse transform, or None when the transform is not invertible.

§Returns
  • Option<Self> - Some(...) on success, None otherwise.
Source§

impl Transform2D

Source

pub fn get_a(&self) -> f64

Source

pub fn get_mut_a(&mut self) -> &mut f64

Source

pub fn set_a(&mut self, val: f64) -> &mut Self

Source

pub fn get_b(&self) -> f64

Source

pub fn get_mut_b(&mut self) -> &mut f64

Source

pub fn set_b(&mut self, val: f64) -> &mut Self

Source

pub fn get_c(&self) -> f64

Source

pub fn get_mut_c(&mut self) -> &mut f64

Source

pub fn set_c(&mut self, val: f64) -> &mut Self

Source

pub fn get_d(&self) -> f64

Source

pub fn get_mut_d(&mut self) -> &mut f64

Source

pub fn set_d(&mut self, val: f64) -> &mut Self

Source

pub fn get_e(&self) -> f64

Source

pub fn get_mut_e(&mut self) -> &mut f64

Source

pub fn set_e(&mut self, val: f64) -> &mut Self

Source

pub fn get_f(&self) -> f64

Source

pub fn get_mut_f(&mut self) -> &mut f64

Source

pub fn set_f(&mut self, val: f64) -> &mut Self

Trait Implementations§

Source§

impl Clone for Transform2D

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 Transform2D

Source§

impl Debug for Transform2D

Source§

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

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

impl PartialEq for Transform2D

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 Transform2D

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.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more