pub struct Affine2x2 {
pub xx: F2Dot14,
pub yx: F2Dot14,
pub xy: F2Dot14,
pub yy: F2Dot14,
}Expand description
A simple F2Dot14 2×2 affine transformation
[xx, yx; xy, yy]
.
Fields§
§xx: F2Dot14X-component of transformed X-basis vector.
yx: F2Dot14Y-component of transformed X-basis vector (aka. scale01 in glyf).
xy: F2Dot14X-component of transformed Y-basis vector (aka. scale10 in glyf).
yy: F2Dot14Y-component of transformed Y-basis vector.
Implementations§
Source§impl Affine2x2
impl Affine2x2
Sourcepub const IDENTITY: Self
pub const IDENTITY: Self
The identity transform
[1, 0; 0, 1]
.
§Examples
assert_eq!(Affine2x2::IDENTITY.to_tuple_f32(), (1.0, 0.0, 0.0, 1.0));Sourcepub const fn new(xx: F2Dot14, yx: F2Dot14, xy: F2Dot14, yy: F2Dot14) -> Self
pub const fn new(xx: F2Dot14, yx: F2Dot14, xy: F2Dot14, yy: F2Dot14) -> Self
Creates an Affine2x2 with
[xx, yx; xy, yy]
.
Sourcepub fn rotation(radians: f32) -> Self
pub fn rotation(radians: f32) -> Self
Creates an Affine2x2 with
[cos(θ),-sin(θ);sin(θ),cos(θ)]
,
rotating the image counter-clockwise by specified angle.
Sourcepub fn rotation_degrees(degrees: f32) -> Self
pub fn rotation_degrees(degrees: f32) -> Self
Creates an Affine2x2 with
[cos(θ),-sin(θ); sin(θ),cos(θ)]
,
rotating the image counter-clockwise by specified angle.
Sourcepub const fn map(&self, x: F2Dot14, y: F2Dot14) -> (F2Dot14, F2Dot14)
pub const fn map(&self, x: F2Dot14, y: F2Dot14) -> (F2Dot14, F2Dot14)
Applies this Affine2x2 transformation to the point
[x, y]
:
[x,y]×[xx,yx; xy,yy]=[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));Sourcepub const fn map_i16(&self, x: i16, y: i16) -> (i16, i16)
pub const fn map_i16(&self, x: i16, y: i16) -> (i16, i16)
Applies this Affine2x2 transformation to the point
[x, y]
.
Sourcepub const fn map_f32(&self, x: f32, y: f32) -> (f32, f32)
pub const fn map_f32(&self, x: f32, y: f32) -> (f32, f32)
Applies this Affine2x2 transformation to the point
[x, y]
.
Sourcepub const fn wrapping_mul(self, rhs: Self) -> Self
pub const fn wrapping_mul(self, rhs: Self) -> Self
Sourcepub const fn saturating_mul(self, rhs: Self) -> Self
pub const fn saturating_mul(self, rhs: Self) -> Self
Sourcepub const fn checked_mul(self, rhs: Self) -> Option<Self>
pub const fn checked_mul(self, rhs: Self) -> Option<Self>
Multiplies this Affine2x2 by another, returning None if overflow occurs.
Sourcepub const fn from_be_bytes(bytes: [u8; 8]) -> Self
pub const fn from_be_bytes(bytes: [u8; 8]) -> Self
Creates an Affine2x2 from big-endian bytes.
Sourcepub const fn to_be_bytes(self) -> [u8; 8]
pub const fn to_be_bytes(self) -> [u8; 8]
Returns this Affine2x2 as big-endian bytes.
Sourcepub const fn to_tuple(self) -> (F2Dot14, F2Dot14, F2Dot14, F2Dot14)
pub const fn to_tuple(self) -> (F2Dot14, F2Dot14, F2Dot14, F2Dot14)
Returns this Affine2x2’s (xx, yx, xy, yy) as a tuple.
Sourcepub const fn from_array([xx, yx, xy, yy]: [F2Dot14; 4]) -> Self
pub const fn from_array([xx, yx, xy, yy]: [F2Dot14; 4]) -> Self
Creates an Affine2x2 from a [xx, yx, xy, yy] array.