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
[xx, yx; xy, yy; dx, dy]
.
Fields§
§xx: FixedX-component of transformed X-basis vector.
yx: FixedY-component of transformed X-basis vector.
xy: FixedX-component of transformed Y-basis vector.
yy: FixedY-component of transformed Y-basis vector.
dx: FixedTranslation in X direction.
dy: FixedTranslation in Y direction.
Implementations§
Source§impl Affine2x3
impl Affine2x3
Sourcepub const IDENTITY: Self
pub const IDENTITY: Self
The identity transform
[1, 0; 0, 1; 0, 0]
.
assert_eq!(Affine2x3::IDENTITY.to_tuple_f64(), (1.0, 0.0, 0.0, 1.0, 0.0, 0.0));Sourcepub const fn new(
xx: Fixed,
yx: Fixed,
xy: Fixed,
yy: Fixed,
dx: Fixed,
dy: Fixed,
) -> Self
pub const fn new( xx: Fixed, yx: Fixed, xy: Fixed, yy: Fixed, dx: Fixed, dy: Fixed, ) -> Self
Creates an Affine2x3 with
[xx, yx; xy, yy; dx, dy]
.
Sourcepub const fn transform(xx: Fixed, yx: Fixed, xy: Fixed, yy: Fixed) -> Self
pub const fn transform(xx: Fixed, yx: Fixed, xy: Fixed, yy: Fixed) -> Self
Creates an Affine2x3 with
[xx, yx; xy, yy; 0, 0]
.
Sourcepub const fn translate(dx: Fixed, dy: Fixed) -> Self
pub const fn translate(dx: Fixed, dy: Fixed) -> Self
Creates an Affine2x3 with
[1, 0; 0, 1; dx, dy]
.
Sourcepub const fn scale(scale: Fixed) -> Self
pub const fn scale(scale: Fixed) -> Self
Creates an Affine2x3 with
[scale, 0; 0, scale; 0, 0]
.
Sourcepub const fn scale_xy(x: Fixed, y: Fixed) -> Self
pub const fn scale_xy(x: Fixed, y: Fixed) -> Self
Creates an Affine2x3 with
[x, 0; 0, y; 0, 0]
.
Sourcepub fn rotation(radians: f64) -> Self
pub fn rotation(radians: f64) -> Self
Creates an Affine2x3 with
[cos(θ),-sin(θ);sin(θ),cos(θ); 0, 0]
,
rotating the image counter-clockwise by specified angle.
Sourcepub fn rotation_degrees(degrees: f64) -> Self
pub fn rotation_degrees(degrees: f64) -> Self
Creates an Affine2x3 with
[cos(θ),-sin(θ);sin(θ),cos(θ); 0, 0]
,
rotating the image counter-clockwise by specified angle.
Sourcepub const fn map(&self, x: Fixed, y: Fixed) -> (Fixed, Fixed)
pub const fn map(&self, x: Fixed, y: Fixed) -> (Fixed, Fixed)
Applies this Affine2x3 transformation to the point
[x, y, 1]
:
[x,y,1]×[xx,yx; xy,yy; dx,dy]=[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));Sourcepub const fn map_f64(&self, x: f64, y: f64) -> (f64, f64)
pub const fn map_f64(&self, x: f64, y: f64) -> (f64, f64)
Applies this Affine2x3 transformation to the point
[x, y, 1]
.
Sourcepub const fn wrapping_mul(self, other: Self) -> Self
pub const fn wrapping_mul(self, other: Self) -> Self
Sourcepub const fn saturating_mul(self, other: Self) -> Self
pub const fn saturating_mul(self, other: Self) -> Self
Sourcepub const fn checked_mul(self, other: Self) -> Option<Self>
pub const fn checked_mul(self, other: Self) -> Option<Self>
Multiplies this Affine2x3 by another, returning None if overflow occurs.
Sourcepub const fn from_be_bytes(bytes: [u8; 24]) -> Self
pub const fn from_be_bytes(bytes: [u8; 24]) -> Self
Creates an Affine2x3 from big-endian bytes.
Sourcepub const fn to_be_bytes(self) -> [u8; 24]
pub const fn to_be_bytes(self) -> [u8; 24]
Returns this Affine2x3 as big-endian bytes.
Sourcepub const fn to_tuple(self) -> (Fixed, Fixed, Fixed, Fixed, Fixed, Fixed)
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.
Sourcepub const fn from_array([xx, yx, xy, yy, dx, dy]: [Fixed; 6]) -> Self
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.