pub struct Matrix {
pub a: f64,
pub b: f64,
pub c: f64,
pub d: f64,
pub e: f64,
pub f: f64,
}Expand description
An affine transformation [a b c d e f] (§8.3.3): a point (x, y) maps to
(a·x + c·y + e, b·x + d·y + f).
Composition has two names, one per order: p.then(&q) applies p first, q.after(&p)
is the same matrix. cm sets CTM′ = M × CTM (§8.4.4), which is m.then(&ctm).
use laminapdf_model::Matrix;
let scale = Matrix::scale(2.0, 2.0);
let shift = Matrix::translate(10.0, 0.0);
assert_eq!(scale.then(&shift).apply(1.0, 1.0), (12.0, 2.0));
assert_eq!(shift.after(&scale), scale.then(&shift));Added in 0.2.0.
Fields§
§a: f64a.
b: f64b.
c: f64c.
d: f64d.
e: f64e, the x translation.
f: f64f, the y translation.
Implementations§
Source§impl Matrix
impl Matrix
Sourcepub const fn scale(sx: f64, sy: f64) -> Matrix
pub const fn scale(sx: f64, sy: f64) -> Matrix
A scaling by sx horizontally and sy vertically.
Added in 0.2.0.
Sourcepub fn rotate(degrees: f64) -> Matrix
pub fn rotate(degrees: f64) -> Matrix
A rotation by degrees about the origin, from the x axis towards the y axis: clockwise
as displayed in page space (y down), counter-clockwise in user space (y up).
Added in 0.2.0.
Sourcepub fn then(&self, next: &Matrix) -> Matrix
pub fn then(&self, next: &Matrix) -> Matrix
self first, then next: the matrix that maps p to next(self(p)), the product
self × next of §8.3.4.
Added in 0.2.0.
Sourcepub fn after(&self, first: &Matrix) -> Matrix
pub fn after(&self, first: &Matrix) -> Matrix
self after first: the matrix that maps p to self(first(p)), the same as
first.then(self).
Added in 0.2.0.
Sourcepub fn invert(&self) -> Option<Matrix>
pub fn invert(&self) -> Option<Matrix>
The inverse, None for a singular matrix.
Added in 0.2.0.
Sourcepub fn apply(&self, x: f64, y: f64) -> (f64, f64)
pub fn apply(&self, x: f64, y: f64) -> (f64, f64)
The image of the point (x, y).
Added in 0.2.0.
Sourcepub fn from_slice(values: &[f64]) -> Option<Matrix>
pub fn from_slice(values: &[f64]) -> Option<Matrix>
The matrix from six numbers (None unless there are exactly six).
Added in 0.2.0.