Skip to main content

Affine2x2

Struct Affine2x2 

Source
pub struct Affine2x2 {
    pub xx: F2Dot14,
    pub yx: F2Dot14,
    pub xy: F2Dot14,
    pub yy: F2Dot14,
}
Expand description

A simple F2Dot14 2×2 affine transformation [ xxyx xyyy ].

Fields§

§xx: F2Dot14

X-component of transformed X-basis vector.

§yx: F2Dot14

Y-component of transformed X-basis vector (aka. scale01 in glyf).

§xy: F2Dot14

X-component of transformed Y-basis vector (aka. scale10 in glyf).

§yy: F2Dot14

Y-component of transformed Y-basis vector.

Implementations§

Source§

impl Affine2x2

Source

pub const IDENTITY: Self

The identity transform [ 10 01 ].

§Examples
assert_eq!(Affine2x2::IDENTITY.to_tuple_f32(), (1.0, 0.0, 0.0, 1.0));
Source

pub const fn new(xx: F2Dot14, yx: F2Dot14, xy: F2Dot14, yy: F2Dot14) -> Self

Creates an Affine2x2 with [ xxyx xyyy ].

Source

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

Creates an Affine2x2 with [ scale0 0scale ].

Source

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

Creates an Affine2x2 with [ x0 0y ].

Source

pub fn rotation(radians: f32) -> Self

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

Source

pub fn rotation_degrees(degrees: f32) -> Self

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

Source

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

Applies this Affine2x2 transformation to the point [x y]:

[x y] × [ xxyx xyyy ] = [ xx*x+xy*y , yx*x+yy*y ]

§Examples
use ttf_view::types::Affine2x2;

assert_eq!(Affine2x2::IDENTITY.map_f32(10.0, -10.0), (10.0, -10.0));
assert_eq!(Affine2x2::IDENTITY.map_f32(-2583.2, 1842.2), (-2583.2, 1842.2));

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

pub const fn map_i16(&self, x: i16, y: i16) -> (i16, i16)

Applies this Affine2x2 transformation to the point [x y].

Source

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

Applies this Affine2x2 transformation to the point [x y].

Source

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

Multiplies this Affine2x2 by another, wrapping and truncating at F2Dot14’s bounds.

Source

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

Multiplies this Affine2x2 by another, saturating at F2Dot14’s bounds.

Source

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

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

Source

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

Creates an Affine2x2 from big-endian bytes.

Source

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

Returns this Affine2x2 as big-endian bytes.

Source

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

Returns this Affine2x2’s (xx, yx, xy, yy) as a tuple.

Source

pub const fn to_tuple_f32(self) -> (f32, f32, f32, f32)

Returns this Affine2x2’s (xx, yx, xy, yy) as a tuple of f32s.

Source

pub const fn from_array([xx, yx, xy, yy]: [F2Dot14; 4]) -> Self

Creates an Affine2x2 from a [xx, yx, xy, yy] array.

Source

pub const fn to_array(self) -> [F2Dot14; 4]

Returns this Affine2x2’s [xx, yx, xy, yy] as an array.

Trait Implementations§

Source§

impl Clone for Affine2x2

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 Affine2x2

Source§

impl Debug for Affine2x2

Source§

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

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

impl Default for Affine2x2

Source§

fn default() -> Self

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

impl Eq for Affine2x2

Source§

impl From<BigEndian<Affine2x2>> for Affine2x2

Source§

fn from(value: BigEndian<Affine2x2>) -> Self

Converts to this type from the input type.
Source§

impl Hash for Affine2x2

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 Affine2x2

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

Source§

type Output = Affine2x2

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl PartialEq for Affine2x2

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 Primitive for Affine2x2

Source§

type BigEndian = [u8; 8]

Source§

fn from_big_endian(x: Self::BigEndian) -> Self

Source§

fn to_big_endian(x: Self) -> Self::BigEndian

Source§

impl StructuralPartialEq for Affine2x2

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.