Skip to main content

Affine

Struct Affine 

Source
pub struct Affine {
    pub m: [f64; 6],
}
Expand description

A 2D affine transform [a b c d e f] with the SVG convention:

x' = a·x + c·y + e
y' = b·x + d·y + f

Serialized as a 6-element array.

Fields§

§m: [f64; 6]

Coefficients [a, b, c, d, e, f].

Implementations§

Source§

impl Affine

Source

pub const SINGULAR_EPS: f64 = 1e-14

Determinants with magnitude below this are treated as singular.

Source

pub const IDENTITY: Self

The identity transform.

Source

pub const fn translate(v: Vector) -> Self

Translation by v.

Source

pub fn rotate(angle: f64) -> Self

Counter-clockwise rotation by angle radians about the origin.

Source

pub fn rotate_about(angle: f64, center: Point) -> Self

Rotation about center.

Source

pub const fn scale(sx: f64, sy: f64) -> Self

Scale about the origin.

Source

pub fn scale_about(sx: f64, sy: f64, center: Point) -> Self

Scale about center.

Source

pub fn mirror(p: Point, dir: Vector) -> GeoResult<Self>

Reflection across the line through p with direction dir.

Source

pub fn then(self, next: Self) -> Self

Composition: apply self first, then next.

Source

pub fn determinant(self) -> f64

Determinant of the linear part.

Source

pub fn is_finite(self) -> bool

All coefficients are finite.

Source

pub fn is_identity(self) -> bool

Whether this is exactly the identity.

Source

pub fn inverse(self) -> GeoResult<Self>

Inverse transform. Fails for singular or non-finite transforms.

Source

pub fn apply(self, p: Point) -> Point

Transform a point.

Source

pub fn apply_vector(self, v: Vector) -> Vector

Transform a vector (ignores translation).

Source

pub fn translation(self) -> Vector

Translation part.

Source

pub fn linear_kind(self, rel: f64) -> LinearKind

Classify the linear part with relative tolerance rel.

Source

pub fn rotation_angle(self) -> f64

Rotation angle of the linear part (meaningful for similarities).

Source

pub fn is_axis_aligned(self, rel: f64) -> bool

Whether the linear part is a diagonal (axis aligned) scale with positive or negative factors: no rotation or shear.

Trait Implementations§

Source§

impl Clone for Affine

Source§

fn clone(&self) -> Affine

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 Affine

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() -> Self

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 [f64; 6]

Source§

fn from(a: Affine) -> Self

Converts to this type from the input type.
Source§

impl From<[f64; 6]> for Affine

Source§

fn from(m: [f64; 6]) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Affine

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

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 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> 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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,

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

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.