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: f64Implementations§
Source§impl TransAffine
impl TransAffine
Sourcepub fn new() -> TransAffine
pub fn new() -> TransAffine
Identity matrix.
Sourcepub fn new_custom(
sx: f64,
shy: f64,
shx: f64,
sy: f64,
tx: f64,
ty: f64,
) -> TransAffine
pub fn new_custom( sx: f64, shy: f64, shx: f64, sy: f64, tx: f64, ty: f64, ) -> TransAffine
Custom matrix from six components.
Sourcepub fn from_array(m: &[f64; 6]) -> TransAffine
pub fn from_array(m: &[f64; 6]) -> TransAffine
Construct from a [6] array: [sx, shy, shx, sy, tx, ty].
Sourcepub fn new_rotation(a: f64) -> TransAffine
pub fn new_rotation(a: f64) -> TransAffine
Rotation matrix.
Sourcepub fn new_scaling(x: f64, y: f64) -> TransAffine
pub fn new_scaling(x: f64, y: f64) -> TransAffine
Non-uniform scaling matrix.
Sourcepub fn new_scaling_uniform(s: f64) -> TransAffine
pub fn new_scaling_uniform(s: f64) -> TransAffine
Uniform scaling matrix.
Sourcepub fn new_translation(x: f64, y: f64) -> TransAffine
pub fn new_translation(x: f64, y: f64) -> TransAffine
Translation matrix.
Sourcepub fn new_skewing(x: f64, y: f64) -> TransAffine
pub fn new_skewing(x: f64, y: f64) -> TransAffine
Skewing (shear) matrix.
Sourcepub fn new_line_segment(
x1: f64,
y1: f64,
x2: f64,
y2: f64,
dist: f64,
) -> TransAffine
pub fn new_line_segment( x1: f64, y1: f64, x2: f64, y2: f64, dist: f64, ) -> TransAffine
Line segment transformation: maps 0..dist to the segment (x1,y1)-(x2,y2).
Sourcepub fn new_reflection(a: f64) -> TransAffine
pub fn new_reflection(a: f64) -> TransAffine
Reflection across a line through the origin at angle a.
Sourcepub fn new_reflection_xy(x: f64, y: f64) -> TransAffine
pub fn new_reflection_xy(x: f64, y: f64) -> TransAffine
Reflection across a line through the origin containing the non-unit
vector (x, y).
Sourcepub fn new_reflection_unit(ux: f64, uy: f64) -> TransAffine
pub fn new_reflection_unit(ux: f64, uy: f64) -> TransAffine
Reflection across a line through the origin containing unit vector
(ux, uy).
Sourcepub fn parl_to_parl(
&mut self,
src: &[f64; 6],
dst: &[f64; 6],
) -> &mut TransAffine
pub fn parl_to_parl( &mut self, src: &[f64; 6], dst: &[f64; 6], ) -> &mut TransAffine
Map one parallelogram to another.
src and dst are [x1,y1, x2,y2, x3,y3] — three corners,
the fourth is implicit.
Sourcepub fn rect_to_parl(
&mut self,
x1: f64,
y1: f64,
x2: f64,
y2: f64,
parl: &[f64; 6],
) -> &mut TransAffine
pub fn rect_to_parl( &mut self, x1: f64, y1: f64, x2: f64, y2: f64, parl: &[f64; 6], ) -> &mut TransAffine
Map a rectangle to a parallelogram.
Sourcepub fn parl_to_rect(
&mut self,
parl: &[f64; 6],
x1: f64,
y1: f64,
x2: f64,
y2: f64,
) -> &mut TransAffine
pub fn parl_to_rect( &mut self, parl: &[f64; 6], x1: f64, y1: f64, x2: f64, y2: f64, ) -> &mut TransAffine
Map a parallelogram to a rectangle.
Sourcepub fn reset(&mut self) -> &mut TransAffine
pub fn reset(&mut self) -> &mut TransAffine
Reset to identity.
Sourcepub fn translate(&mut self, x: f64, y: f64) -> &mut TransAffine
pub fn translate(&mut self, x: f64, y: f64) -> &mut TransAffine
Translate.
Sourcepub fn rotate(&mut self, a: f64) -> &mut TransAffine
pub fn rotate(&mut self, a: f64) -> &mut TransAffine
Rotate by angle a (radians).
Sourcepub fn scale(&mut self, x: f64, y: f64) -> &mut TransAffine
pub fn scale(&mut self, x: f64, y: f64) -> &mut TransAffine
Non-uniform scale.
Sourcepub fn scale_uniform(&mut self, s: f64) -> &mut TransAffine
pub fn scale_uniform(&mut self, s: f64) -> &mut TransAffine
Uniform scale.
Sourcepub fn multiply(&mut self, m: &TransAffine) -> &mut TransAffine
pub fn multiply(&mut self, m: &TransAffine) -> &mut TransAffine
Post-multiply: self = self * m.
Sourcepub fn premultiply(&mut self, m: &TransAffine) -> &mut TransAffine
pub fn premultiply(&mut self, m: &TransAffine) -> &mut TransAffine
Pre-multiply: self = m * self.
Sourcepub fn multiply_inv(&mut self, m: &TransAffine) -> &mut TransAffine
pub fn multiply_inv(&mut self, m: &TransAffine) -> &mut TransAffine
Post-multiply by inverse of m.
Sourcepub fn premultiply_inv(&mut self, m: &TransAffine) -> &mut TransAffine
pub fn premultiply_inv(&mut self, m: &TransAffine) -> &mut TransAffine
Pre-multiply by inverse of m.
Sourcepub fn invert(&mut self) -> &mut TransAffine
pub fn invert(&mut self) -> &mut TransAffine
Invert the matrix in place.
Sourcepub fn flip_x(&mut self) -> &mut TransAffine
pub fn flip_x(&mut self) -> &mut TransAffine
Mirror around X axis.
Sourcepub fn flip_y(&mut self) -> &mut TransAffine
pub fn flip_y(&mut self) -> &mut TransAffine
Mirror around Y axis.
Sourcepub fn load_from(&mut self, m: &[f64; 6]) -> &mut TransAffine
pub fn load_from(&mut self, m: &[f64; 6]) -> &mut TransAffine
Load from a [6] array.
Sourcepub fn transform_2x2(&self, x: &mut f64, y: &mut f64)
pub fn transform_2x2(&self, x: &mut f64, y: &mut f64)
Forward transform (2x2 only, no translation).
Sourcepub fn inverse_transform(&self, x: &mut f64, y: &mut f64)
pub fn inverse_transform(&self, x: &mut f64, y: &mut f64)
Inverse transform: (x', y') -> (x, y).
Sourcepub fn determinant(&self) -> f64
pub fn determinant(&self) -> f64
Determinant of the 2x2 portion.
Sourcepub fn determinant_reciprocal(&self) -> f64
pub fn determinant_reciprocal(&self) -> f64
Reciprocal of the determinant.
Sourcepub fn get_scale(&self) -> f64
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.
Sourcepub fn is_identity(&self, epsilon: f64) -> bool
pub fn is_identity(&self, epsilon: f64) -> bool
Check if this is an identity matrix.
Sourcepub fn is_equal(&self, m: &TransAffine, epsilon: f64) -> bool
pub fn is_equal(&self, m: &TransAffine, epsilon: f64) -> bool
Check if two matrices are equal within epsilon.
Sourcepub fn translation(&self) -> (f64, f64)
pub fn translation(&self) -> (f64, f64)
Extract the translation components.
Sourcepub fn scaling_abs(&self) -> (f64, f64)
pub fn scaling_abs(&self) -> (f64, f64)
Absolute scaling (from matrix magnitudes).
Trait Implementations§
Source§impl Clone for TransAffine
impl Clone for TransAffine
Source§fn clone(&self) -> TransAffine
fn clone(&self) -> TransAffine
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TransAffine
impl Debug for TransAffine
Source§impl Default for TransAffine
impl Default for TransAffine
Source§fn default() -> TransAffine
fn default() -> TransAffine
Source§impl Mul for TransAffine
impl Mul for TransAffine
Source§type Output = TransAffine
type Output = TransAffine
* operator.Source§fn mul(self, rhs: TransAffine) -> TransAffine
fn mul(self, rhs: TransAffine) -> TransAffine
* operation. Read moreSource§impl MulAssign for TransAffine
impl MulAssign for TransAffine
Source§fn mul_assign(&mut self, rhs: TransAffine)
fn mul_assign(&mut self, rhs: TransAffine)
*= operation. Read moreSource§impl PartialEq for TransAffine
impl PartialEq for TransAffine
Source§fn eq(&self, other: &TransAffine) -> bool
fn eq(&self, other: &TransAffine) -> bool
self and other values to be equal, and is used by ==.Source§impl Transformer for TransAffine
impl Transformer for TransAffine
impl Copy for TransAffine
Auto Trait Implementations§
impl Freeze for TransAffine
impl RefUnwindSafe for TransAffine
impl Send for TransAffine
impl Sync for TransAffine
impl Unpin for TransAffine
impl UnsafeUnpin for TransAffine
impl UnwindSafe for TransAffine
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().