Struct kurbo::Affine

source ·
pub struct Affine(/* private fields */);
Expand description

A 2D affine transform.

Implementations§

source§

impl Affine

source

pub const IDENTITY: Affine = _

The identity transform.

source

pub const FLIP_Y: Affine = _

A transform that is flipped on the y-axis. Useful for converting between y-up and y-down spaces.

source

pub const FLIP_X: Affine = _

A transform that is flipped on the x-axis.

source

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.

source

pub const fn scale(s: f64) -> Affine

An affine transform representing uniform scaling.

source

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

source

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.

source

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.

source

pub fn translate<V: Into<Vec2>>(p: V) -> Affine

An affine transform representing translation.

source

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);
source

pub fn reflect(point: impl Into<Point>, direction: impl Into<Vec2>) -> Self

Create an affine transform that represents reflection about the line point + direction * t, t in (-infty, infty)

§Examples
let point = Point::new(1., 0.);
let vec = Vec2::new(1., 1.);
let map = Affine::reflect(point, vec);
assert_near(map * Point::new(1., 0.), Point::new(1., 0.));
assert_near(map * Point::new(2., 1.), Point::new(2., 1.));
assert_near(map * Point::new(2., 2.), Point::new(3., 1.));
source

pub fn pre_rotate(self, th: f64) -> Self

A rotation by th followed by self.

Equivalent to self * Affine::rotate(th)

source

pub fn pre_rotate_about(self, th: f64, center: Point) -> Self

A rotation by th about center followed by self.

Equivalent to self * Affine::rotate_about(th)

source

pub fn pre_scale(self, scale: f64) -> Self

A scale by scale followed by self.

Equivalent to self * Affine::scale(scale)

source

pub fn pre_scale_non_uniform(self, scale_x: f64, scale_y: f64) -> Self

A scale by (scale_x, scale_y) followed by self.

Equivalent to self * Affine::scale_non_uniform(scale_x, scale_y)

source

pub fn pre_translate(self, trans: Vec2) -> Self

A translation of trans followed by self.

Equivalent to self * Affine::translate(trans)

source

pub fn then_rotate(self, th: f64) -> Self

self followed by a rotation of th.

Equivalent to Affine::rotate(th) * self

source

pub fn then_rotate_about(self, th: f64, center: Point) -> Self

self followed by a rotation of th about center.

Equivalent to Affine::rotate_about(th, center) * self

source

pub fn then_scale(self, scale: f64) -> Self

self followed by a scale of scale.

Equivalent to Affine::scale(scale) * self

source

pub fn then_scale_non_uniform(self, scale_x: f64, scale_y: f64) -> Self

self followed by a scale of (scale_x, scale_y).

Equivalent to Affine::scale_non_uniform(scale_x, scale_y) * self

source

pub fn then_translate(self, trans: Vec2) -> Self

self followed by a translation of trans.

Equivalent to Affine::translate(trans) * self

source

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.

source

pub fn as_coeffs(self) -> [f64; 6]

Get the coefficients of the transform.

source

pub fn determinant(self) -> f64

Compute the determinant of this transform.

source

pub fn inverse(self) -> Affine

Compute the inverse transform.

Produces NaN values when the determinant is zero.

source

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.

source

pub fn is_finite(&self) -> bool

Is this map finite?

source

pub fn is_nan(&self) -> bool

Is this map NaN?

source

pub fn translation(self) -> Vec2

Returns the translation part of this affine map ((self.0[4], self.0[5])).

source

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 Clone for Affine

source§

fn clone(&self) -> Affine

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Affine

source§

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

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

impl Default for Affine

source§

fn default() -> Affine

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

impl<'de> Deserialize<'de> for Affine

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl From<Affine> for ColumnMatrix2x3<f64>

source§

fn from(a: Affine) -> ColumnMatrix2x3<f64>

Converts to this type from the input type.
source§

impl From<ColumnMatrix2x3<f64>> for Affine

source§

fn from(m: ColumnMatrix2x3<f64>) -> Affine

Converts to this type from the input type.
source§

impl From<TranslateScale> for Affine

source§

fn from(ts: TranslateScale) -> Affine

Converts to this type from the input type.
source§

impl JsonSchema for Affine

source§

fn schema_name() -> String

The name of the generated JSON Schema. Read more
source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
source§

fn json_schema(gen: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
source§

fn is_referenceable() -> bool

Whether JSON Schemas generated for this type should be re-used where possible using the $ref keyword. Read more
source§

impl<'a> Mul<&'a BezPath> for Affine

§

type Output = BezPath

The resulting type after applying the * operator.
source§

fn mul(self, other: &BezPath) -> BezPath

Performs the * operation. Read more
source§

impl Mul<Affine> for f64

§

type Output = Affine

The resulting type after applying the * operator.
source§

fn mul(self, other: Affine) -> Affine

Performs the * operation. Read more
source§

impl Mul<Arc> for Affine

§

type Output = Arc

The resulting type after applying the * operator.
source§

fn mul(self, arc: Arc) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<BezPath> for Affine

§

type Output = BezPath

The resulting type after applying the * operator.
source§

fn mul(self, other: BezPath) -> BezPath

Performs the * operation. Read more
source§

impl Mul<Circle> for Affine

§

type Output = Ellipse

The resulting type after applying the * operator.
source§

fn mul(self, other: Circle) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<CubicBez> for Affine

§

type Output = CubicBez

The resulting type after applying the * operator.
source§

fn mul(self, c: CubicBez) -> CubicBez

Performs the * operation. Read more
source§

impl Mul<Ellipse> for Affine

§

type Output = Ellipse

The resulting type after applying the * operator.
source§

fn mul(self, other: Ellipse) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<Line> for Affine

§

type Output = Line

The resulting type after applying the * operator.
source§

fn mul(self, other: Line) -> Line

Performs the * operation. Read more
source§

impl Mul<PathEl> for Affine

§

type Output = PathEl

The resulting type after applying the * operator.
source§

fn mul(self, other: PathEl) -> PathEl

Performs the * operation. Read more
source§

impl Mul<PathSeg> for Affine

§

type Output = PathSeg

The resulting type after applying the * operator.
source§

fn mul(self, other: PathSeg) -> PathSeg

Performs the * operation. Read more
source§

impl Mul<Point> for Affine

§

type Output = Point

The resulting type after applying the * operator.
source§

fn mul(self, other: Point) -> Point

Performs the * operation. Read more
source§

impl Mul<QuadBez> for Affine

§

type Output = QuadBez

The resulting type after applying the * operator.
source§

fn mul(self, other: QuadBez) -> QuadBez

Performs the * operation. Read more
source§

impl Mul for Affine

§

type Output = Affine

The resulting type after applying the * operator.
source§

fn mul(self, other: Affine) -> Affine

Performs the * operation. Read more
source§

impl MulAssign for Affine

source§

fn mul_assign(&mut self, other: Affine)

Performs the *= operation. Read more
source§

impl PartialEq for Affine

source§

fn eq(&self, other: &Affine) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Affine

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Copy for Affine

source§

impl StructuralPartialEq for Affine

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<T> DynClone for T
where T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

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> ToOwned for T
where T: Clone,

§

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>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,