pub struct Affine(/* private fields */);Expand description
A 2D affine transform.
Implementations§
Source§impl Affine
impl Affine
Sourcepub const FLIP_Y: Affine
pub const FLIP_Y: Affine
A transform that is flipped on the y-axis. Useful for converting between y-up and y-down spaces.
Sourcepub const fn new(c: [f64; 6]) -> Affine
pub const fn new(c: [f64; 6]) -> Affine
Construct an affine transform from coefficients.
If the coefficients are (a, b, c, d, e, f), then the resulting
transformation represents this augmented matrix:
| a c e |
| b d f |
| 0 0 1 |Note that this convention is transposed from PostScript and
Direct2D, but is consistent with the
Wikipedia
formulation of affine transformation as augmented matrix. The
idea is that (A * B) * v == A * (B * v), where * is the
Mul trait.
Sourcepub const fn scale_non_uniform(s_x: f64, s_y: f64) -> Affine
pub const fn scale_non_uniform(s_x: f64, s_y: f64) -> Affine
An affine transform representing non-uniform scaling with different scale values for x and y
Sourcepub fn rotate(th: f64) -> Affine
pub fn rotate(th: f64) -> Affine
An affine transform representing rotation.
The convention for rotation is that a positive angle rotates a positive X direction into positive Y. Thus, in a Y-down coordinate system (as is common for graphics), it is a clockwise rotation, and in Y-up (traditional for math), it is anti-clockwise.
The angle, th, is expressed in radians.
Sourcepub fn rotate_about(th: f64, center: Point) -> Affine
pub fn rotate_about(th: f64, center: Point) -> Affine
An affine transform representing a rotation of th radians about center.
See Affine::rotate for more info.
Sourcepub fn skew(skew_x: f64, skew_y: f64) -> Affine
pub fn skew(skew_x: f64, skew_y: f64) -> Affine
An affine transformation representing a skew.
The skew_x and skew_y parameters represent skew factors for the horizontal and vertical directions, respectively.
This is commonly used to generate a faux oblique transform for font rendering. In this case, you can slant the glyph 20 degrees clockwise in the horizontal direction (assuming a Y-up coordinate system):
let oblique_transform = kurbo::Affine::skew(20f64.to_radians().tan(), 0.0);Sourcepub fn pre_rotate(self, th: f64) -> Affine
pub fn pre_rotate(self, th: f64) -> Affine
A rotation by th followed by self.
Equivalent to self * Affine::rotate(th)
Sourcepub fn pre_rotate_about(self, th: f64, center: Point) -> Affine
pub fn pre_rotate_about(self, th: f64, center: Point) -> Affine
A rotation by th about center followed by self.
Equivalent to self * Affine::rotate_about(th)
Sourcepub fn pre_scale(self, scale: f64) -> Affine
pub fn pre_scale(self, scale: f64) -> Affine
A scale by scale followed by self.
Equivalent to self * Affine::scale(scale)
Sourcepub fn pre_scale_non_uniform(self, scale_x: f64, scale_y: f64) -> Affine
pub fn pre_scale_non_uniform(self, scale_x: f64, scale_y: f64) -> Affine
A scale by (scale_x, scale_y) followed by self.
Equivalent to self * Affine::scale_non_uniform(scale_x, scale_y)
Sourcepub fn pre_translate(self, trans: Vec2) -> Affine
pub fn pre_translate(self, trans: Vec2) -> Affine
A translation of trans followed by self.
Equivalent to self * Affine::translate(trans)
Sourcepub fn then_rotate(self, th: f64) -> Affine
pub fn then_rotate(self, th: f64) -> Affine
self followed by a rotation of th.
Equivalent to Affine::rotate(th) * self
Sourcepub fn then_rotate_about(self, th: f64, center: Point) -> Affine
pub fn then_rotate_about(self, th: f64, center: Point) -> Affine
self followed by a rotation of th about `center.
Equivalent to Affine::rotate_about(th, center) * self
Sourcepub fn then_scale(self, scale: f64) -> Affine
pub fn then_scale(self, scale: f64) -> Affine
self followed by a scale of scale.
Equivalent to Affine::scale(scale) * self
Sourcepub fn then_scale_non_uniform(self, scale_x: f64, scale_y: f64) -> Affine
pub fn then_scale_non_uniform(self, scale_x: f64, scale_y: f64) -> Affine
self followed by a scale of (scale_x, scale_y).
Equivalent to Affine::scale_non_uniform(scale_x, scale_y) * self
Sourcepub fn then_translate(self, trans: Vec2) -> Affine
pub fn then_translate(self, trans: Vec2) -> Affine
self followed by a translation of trans.
Equivalent to Affine::translate(trans) * self
Sourcepub fn map_unit_square(rect: Rect) -> Affine
pub fn map_unit_square(rect: Rect) -> Affine
Creates an affine transformation that takes the unit square to the given rectangle.
Useful when you want to draw into the unit square but have your output fill any rectangle.
In this case push the Affine onto the transform stack.
Sourcepub fn determinant(self) -> f64
pub fn determinant(self) -> f64
Compute the determinant of this transform.
Sourcepub fn inverse(self) -> Affine
pub fn inverse(self) -> Affine
Compute the inverse transform.
Produces NaN values when the determinant is zero.
Sourcepub fn transform_rect_bbox(self, rect: Rect) -> Rect
pub fn transform_rect_bbox(self, rect: Rect) -> Rect
Compute the bounding box of a transformed rectangle.
Returns the minimal Rect that encloses the given Rect after affine transformation.
If the transform is axis-aligned, then this bounding box is “tight”, in other words the
returned Rect is the transformed rectangle.
The returned rectangle always has non-negative width and height.
Sourcepub fn translation(self) -> Vec2
pub fn translation(self) -> Vec2
Returns the translation part of this affine map ((self.0[4], self.0[5])).
Sourcepub fn with_translation(self, trans: Vec2) -> Affine
pub fn with_translation(self, trans: Vec2) -> Affine
Replaces the translation portion of this affine map
The translation can be seen as being applied after the linear part of the map.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Affine
impl<'de> Deserialize<'de> for Affine
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Affine, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Affine, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl From<TranslateScale> for Affine
impl From<TranslateScale> for Affine
Source§fn from(ts: TranslateScale) -> Affine
fn from(ts: TranslateScale) -> Affine
Source§impl Into<Affine> for GlifMatrix
impl Into<Affine> for GlifMatrix
Source§impl MulAssign for Affine
impl MulAssign for Affine
Source§fn mul_assign(&mut self, other: Affine)
fn mul_assign(&mut self, other: Affine)
*= operation. Read moreSource§impl Serialize for Affine
impl Serialize for Affine
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Copy for Affine
impl StructuralPartialEq for Affine
Auto Trait Implementations§
impl Freeze for Affine
impl RefUnwindSafe for Affine
impl Send for Affine
impl Sync for Affine
impl Unpin for Affine
impl UnwindSafe for Affine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more