Skip to main content

TransAffine

Struct TransAffine 

Source
pub struct TransAffine {
    pub sx: f64,
    pub shy: f64,
    pub shx: f64,
    pub sy: f64,
    pub tx: f64,
    pub ty: f64,
}
Expand description

2D affine transformation matrix.

Stores six components: [sx, shy, shx, sy, tx, ty] representing the matrix:

  | sx  shx tx |
  | shy  sy ty |
  |  0    0  1 |

Transform: x' = x*sx + y*shx + tx, y' = x*shy + y*sy + ty.

Port of C++ agg::trans_affine.

Fields§

§sx: f64§shy: f64§shx: f64§sy: f64§tx: f64§ty: f64

Implementations§

Source§

impl TransAffine

Source

pub fn new() -> Self

Identity matrix.

Source

pub fn new_custom( sx: f64, shy: f64, shx: f64, sy: f64, tx: f64, ty: f64, ) -> Self

Custom matrix from six components.

Source

pub fn from_array(m: &[f64; 6]) -> Self

Construct from a [6] array: [sx, shy, shx, sy, tx, ty].

Source

pub fn new_rotation(a: f64) -> Self

Rotation matrix.

Source

pub fn new_scaling(x: f64, y: f64) -> Self

Non-uniform scaling matrix.

Source

pub fn new_scaling_uniform(s: f64) -> Self

Uniform scaling matrix.

Source

pub fn new_translation(x: f64, y: f64) -> Self

Translation matrix.

Source

pub fn new_skewing(x: f64, y: f64) -> Self

Skewing (shear) matrix.

Source

pub fn new_line_segment(x1: f64, y1: f64, x2: f64, y2: f64, dist: f64) -> Self

Line segment transformation: maps 0..dist to the segment (x1,y1)-(x2,y2).

Source

pub fn new_reflection(a: f64) -> Self

Reflection across a line through the origin at angle a.

Source

pub fn new_reflection_xy(x: f64, y: f64) -> Self

Reflection across a line through the origin containing the non-unit vector (x, y).

Source

pub fn new_reflection_unit(ux: f64, uy: f64) -> Self

Reflection across a line through the origin containing unit vector (ux, uy).

Source

pub fn parl_to_parl(&mut self, src: &[f64; 6], dst: &[f64; 6]) -> &mut Self

Map one parallelogram to another.

src and dst are [x1,y1, x2,y2, x3,y3] — three corners, the fourth is implicit.

Source

pub fn rect_to_parl( &mut self, x1: f64, y1: f64, x2: f64, y2: f64, parl: &[f64; 6], ) -> &mut Self

Map a rectangle to a parallelogram.

Source

pub fn parl_to_rect( &mut self, parl: &[f64; 6], x1: f64, y1: f64, x2: f64, y2: f64, ) -> &mut Self

Map a parallelogram to a rectangle.

Source

pub fn reset(&mut self) -> &mut Self

Reset to identity.

Source

pub fn translate(&mut self, x: f64, y: f64) -> &mut Self

Translate.

Source

pub fn rotate(&mut self, a: f64) -> &mut Self

Rotate by angle a (radians).

Source

pub fn scale(&mut self, x: f64, y: f64) -> &mut Self

Non-uniform scale.

Source

pub fn scale_uniform(&mut self, s: f64) -> &mut Self

Uniform scale.

Source

pub fn multiply(&mut self, m: &TransAffine) -> &mut Self

Post-multiply: self = self * m.

Source

pub fn premultiply(&mut self, m: &TransAffine) -> &mut Self

Pre-multiply: self = m * self.

Source

pub fn multiply_inv(&mut self, m: &TransAffine) -> &mut Self

Post-multiply by inverse of m.

Source

pub fn premultiply_inv(&mut self, m: &TransAffine) -> &mut Self

Pre-multiply by inverse of m.

Source

pub fn invert(&mut self) -> &mut Self

Invert the matrix in place.

Source

pub fn flip_x(&mut self) -> &mut Self

Mirror around X axis.

Source

pub fn flip_y(&mut self) -> &mut Self

Mirror around Y axis.

Source

pub fn store_to(&self, m: &mut [f64; 6])

Store to a [6] array.

Source

pub fn load_from(&mut self, m: &[f64; 6]) -> &mut Self

Load from a [6] array.

Source

pub fn transform(&self, x: &mut f64, y: &mut f64)

Forward transform: (x, y) -> (x', y').

Source

pub fn transform_2x2(&self, x: &mut f64, y: &mut f64)

Forward transform (2x2 only, no translation).

Source

pub fn inverse_transform(&self, x: &mut f64, y: &mut f64)

Inverse transform: (x', y') -> (x, y).

Source

pub fn determinant(&self) -> f64

Determinant of the 2x2 portion.

Source

pub fn determinant_reciprocal(&self) -> f64

Reciprocal of the determinant.

Source

pub fn get_scale(&self) -> f64

Average scale factor (useful for approximation_scale on curves).

Uses the same truncated 1/sqrt(2) constant as C++ AGG (0.707106781) to match its behavior exactly. Using full-precision FRAC_1_SQRT_2 would produce a slightly different result that causes the line profile width computation to take a different branch, amplifying the difference.

Source

pub fn is_valid(&self, epsilon: f64) -> bool

Check if the matrix is non-degenerate.

Source

pub fn is_identity(&self, epsilon: f64) -> bool

Check if this is an identity matrix.

Source

pub fn is_equal(&self, m: &TransAffine, epsilon: f64) -> bool

Check if two matrices are equal within epsilon.

Source

pub fn rotation(&self) -> f64

Extract the rotation angle.

Source

pub fn translation(&self) -> (f64, f64)

Extract the translation components.

Source

pub fn scaling(&self) -> (f64, f64)

Extract scaling by removing rotation first.

Source

pub fn scaling_abs(&self) -> (f64, f64)

Absolute scaling (from matrix magnitudes).

Trait Implementations§

Source§

impl Clone for TransAffine

Source§

fn clone(&self) -> TransAffine

Returns a duplicate 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 TransAffine

Source§

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

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

impl Default for TransAffine

Source§

fn default() -> Self

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

impl Mul for TransAffine

Source§

type Output = TransAffine

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: TransAffine) -> TransAffine

Performs the * operation. Read more
Source§

impl MulAssign for TransAffine

Source§

fn mul_assign(&mut self, rhs: TransAffine)

Performs the *= operation. Read more
Source§

impl PartialEq for TransAffine

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 Transformer for TransAffine

Source§

fn transform(&self, x: &mut f64, y: &mut f64)

Source§

impl Copy for TransAffine

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