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_custom(
sx: f64,
shy: f64,
shx: f64,
sy: f64,
tx: f64,
ty: f64,
) -> Self
pub fn new_custom( sx: f64, shy: f64, shx: f64, sy: f64, tx: f64, ty: f64, ) -> Self
Custom matrix from six components.
Sourcepub fn from_array(m: &[f64; 6]) -> Self
pub fn from_array(m: &[f64; 6]) -> Self
Construct from a [6] array: [sx, shy, shx, sy, tx, ty].
Sourcepub fn new_rotation(a: f64) -> Self
pub fn new_rotation(a: f64) -> Self
Rotation matrix.
Sourcepub fn new_scaling(x: f64, y: f64) -> Self
pub fn new_scaling(x: f64, y: f64) -> Self
Non-uniform scaling matrix.
Sourcepub fn new_scaling_uniform(s: f64) -> Self
pub fn new_scaling_uniform(s: f64) -> Self
Uniform scaling matrix.
Sourcepub fn new_translation(x: f64, y: f64) -> Self
pub fn new_translation(x: f64, y: f64) -> Self
Translation matrix.
Sourcepub fn new_skewing(x: f64, y: f64) -> Self
pub fn new_skewing(x: f64, y: f64) -> Self
Skewing (shear) matrix.
Sourcepub fn new_line_segment(x1: f64, y1: f64, x2: f64, y2: f64, dist: f64) -> Self
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).
Sourcepub fn new_reflection(a: f64) -> Self
pub fn new_reflection(a: f64) -> Self
Reflection across a line through the origin at angle a.
Sourcepub fn new_reflection_xy(x: f64, y: f64) -> Self
pub fn new_reflection_xy(x: f64, y: f64) -> Self
Reflection across a line through the origin containing the non-unit
vector (x, y).
Sourcepub fn new_reflection_unit(ux: f64, uy: f64) -> Self
pub fn new_reflection_unit(ux: f64, uy: f64) -> Self
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 Self
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.
Sourcepub fn rect_to_parl(
&mut self,
x1: f64,
y1: f64,
x2: f64,
y2: f64,
parl: &[f64; 6],
) -> &mut Self
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.
Sourcepub fn parl_to_rect(
&mut self,
parl: &[f64; 6],
x1: f64,
y1: f64,
x2: f64,
y2: f64,
) -> &mut Self
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.
Sourcepub fn scale_uniform(&mut self, s: f64) -> &mut Self
pub fn scale_uniform(&mut self, s: f64) -> &mut Self
Uniform scale.
Sourcepub fn multiply(&mut self, m: &TransAffine) -> &mut Self
pub fn multiply(&mut self, m: &TransAffine) -> &mut Self
Post-multiply: self = self * m.
Sourcepub fn premultiply(&mut self, m: &TransAffine) -> &mut Self
pub fn premultiply(&mut self, m: &TransAffine) -> &mut Self
Pre-multiply: self = m * self.
Sourcepub fn multiply_inv(&mut self, m: &TransAffine) -> &mut Self
pub fn multiply_inv(&mut self, m: &TransAffine) -> &mut Self
Post-multiply by inverse of m.
Sourcepub fn premultiply_inv(&mut self, m: &TransAffine) -> &mut Self
pub fn premultiply_inv(&mut self, m: &TransAffine) -> &mut Self
Pre-multiply by inverse of m.
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 moreimpl Copy for TransAffine
Source§impl Debug for TransAffine
impl Debug for TransAffine
Source§impl Default for TransAffine
impl Default for 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 more