Skip to main content

Matrix

Struct Matrix 

Source
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: f64

a.

§b: f64

b.

§c: f64

c.

§d: f64

d.

§e: f64

e, the x translation.

§f: f64

f, the y translation.

Implementations§

Source§

impl Matrix

Source

pub const IDENTITY: Matrix

The identity.

Added in 0.2.0.

Source

pub const fn new(_: [f64; 6]) -> Matrix

The matrix [a b c d e f].

Added in 0.2.0.

Source

pub const fn to_array(self) -> [f64; 6]

[a b c d e f].

Added in 0.2.0.

Source

pub const fn translate(x: f64, y: f64) -> Matrix

A translation by (x, y).

Added in 0.2.0.

Source

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

A scaling by sx horizontally and sy vertically.

Added in 0.2.0.

Source

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.

Source

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.

Source

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.

Source

pub fn invert(&self) -> Option<Matrix>

The inverse, None for a singular matrix.

Added in 0.2.0.

Source

pub fn apply(&self, x: f64, y: f64) -> (f64, f64)

The image of the point (x, y).

Added in 0.2.0.

Source

pub fn from_slice(values: &[f64]) -> Option<Matrix>

The matrix from six numbers (None unless there are exactly six).

Added in 0.2.0.

Trait Implementations§

Source§

impl Clone for Matrix

Source§

fn clone(&self) -> Matrix

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 Matrix

Source§

impl Debug for Matrix

Source§

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

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

impl Default for Matrix

Source§

fn default() -> Matrix

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

impl PartialEq for Matrix

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Matrix

Auto Trait Implementations§

§

impl Forget for Matrix

§

impl Freeze for Matrix

§

impl Move for Matrix

§

impl RefUnwindSafe for Matrix

§

impl Send for Matrix

§

impl Sync for Matrix

§

impl Unpin for Matrix

§

impl UnsafeUnpin for Matrix

§

impl UnwindSafe for Matrix

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> ErasedDestructor for T
where T: 'static,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

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

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.