Skip to main content

Affine2x3

Struct Affine2x3 

Source
pub struct Affine2x3 {
    pub xx: Fixed,
    pub yx: Fixed,
    pub xy: Fixed,
    pub yy: Fixed,
    pub dx: Fixed,
    pub dy: Fixed,
}
Expand description

A simple Fixed 2×3 affine transformation [ xxyx xyyy dxdy ].

Fields§

§xx: Fixed

X-component of transformed X-basis vector.

§yx: Fixed

Y-component of transformed X-basis vector.

§xy: Fixed

X-component of transformed Y-basis vector.

§yy: Fixed

Y-component of transformed Y-basis vector.

§dx: Fixed

Translation in X direction.

§dy: Fixed

Translation in Y direction.

Implementations§

Source§

impl Affine2x3

Source

pub const IDENTITY: Self

The identity transform [ 10 01 00 ].

assert_eq!(Affine2x3::IDENTITY.to_tuple_f64(), (1.0, 0.0, 0.0, 1.0, 0.0, 0.0));
Source

pub const fn new( xx: Fixed, yx: Fixed, xy: Fixed, yy: Fixed, dx: Fixed, dy: Fixed, ) -> Self

Creates an Affine2x3 with [ xxyx xyyy dxdy ].

Source

pub const fn transform(xx: Fixed, yx: Fixed, xy: Fixed, yy: Fixed) -> Self

Creates an Affine2x3 with [ xxyx xyyy 00 ].

Source

pub const fn translate(dx: Fixed, dy: Fixed) -> Self

Creates an Affine2x3 with [ 10 01 dxdy ].

Source

pub const fn scale(scale: Fixed) -> Self

Creates an Affine2x3 with [ scale0 0scale 00 ].

Source

pub const fn scale_xy(x: Fixed, y: Fixed) -> Self

Creates an Affine2x3 with [ x0 0y 00 ].

Source

pub fn rotation(radians: f64) -> Self

Creates an Affine2x3 with [ cos(θ)-sin(θ) sin(θ)cos(θ) 00 ], rotating the image counter-clockwise by specified angle.

Source

pub fn rotation_degrees(degrees: f64) -> Self

Creates an Affine2x3 with [ cos(θ)-sin(θ) sin(θ)cos(θ) 00 ], rotating the image counter-clockwise by specified angle.

Source

pub const fn map(&self, x: Fixed, y: Fixed) -> (Fixed, Fixed)

Applies this Affine2x3 transformation to the point [x y 1]:

[x y 1] × [ xxyx xyyy dxdy ] = [ xx*x+xy*y +dx , yx*x+yy*y +dy ]

§Examples
use ttf_view::types::Affine2x3;

assert_eq!(Affine2x3::IDENTITY.map_f64(10.0, -10.0), (10.0, -10.0));
assert_eq!(Affine2x3::IDENTITY.map_f64(-2583.2, 1842.2), (-2583.2, 1842.2));

let rot90 = Affine2x3::rotation_degrees(90.0);
assert_eq!(rot90.map_f64(23.5, 9.8), (9.8, -23.5));
Source

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

Applies this Affine2x3 transformation to the point [x y 1].

Source

pub const fn wrapping_mul(self, other: Self) -> Self

Multiplies this Affine2x3 by another, wrapping and truncating at Fixed’s bounds.

Source

pub const fn saturating_mul(self, other: Self) -> Self

Multiplies this Affine2x3 by another, saturating at Fixed’s bounds.

Source

pub const fn checked_mul(self, other: Self) -> Option<Self>

Multiplies this Affine2x3 by another, returning None if overflow occurs.

Source

pub const fn from_be_bytes(bytes: [u8; 24]) -> Self

Creates an Affine2x3 from big-endian bytes.

Source

pub const fn to_be_bytes(self) -> [u8; 24]

Returns this Affine2x3 as big-endian bytes.

Source

pub const fn to_tuple(self) -> (Fixed, Fixed, Fixed, Fixed, Fixed, Fixed)

Returns this Affine2x3’s (xx, yx, xy, yy, dx, dy) as a tuple.

Source

pub const fn to_tuple_f64(self) -> (f64, f64, f64, f64, f64, f64)

Returns this Affine2x3’s (xx, yx, xy, yy, dx, dy) as a tuple of f64s.

Source

pub const fn from_array([xx, yx, xy, yy, dx, dy]: [Fixed; 6]) -> Self

Creates an Affine2x3 from a [xx, yx, xy, yy, dx, dy] array.

Source

pub const fn to_array(self) -> [Fixed; 6]

Returns this Affine2x3’s [xx, yx, xy, yy, dx, dy] as an array.

Trait Implementations§

Source§

impl Clone for Affine2x3

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 Affine2x3

Source§

impl Debug for Affine2x3

Source§

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

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

impl Default for Affine2x3

Source§

fn default() -> Self

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

impl Eq for Affine2x3

Source§

impl Hash for Affine2x3

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 Mul for Affine2x3

Performs multiplication * (panics on overflow in debug configuration).

Source§

type Output = Affine2x3

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl PartialEq for Affine2x3

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 Affine2x3

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.