Skip to main content

Matrix2D

Struct Matrix2D 

Source
pub struct Matrix2D {
    pub a: f64,
    pub b: f64,
    pub c: f64,
    pub d: f64,
    pub h: f64,
    pub v: f64,
}
Expand description

A 2D affine transformation matrix.

Fields§

§a: f64§b: f64§c: f64§d: f64§h: f64§v: f64

Implementations§

Source§

impl Matrix2D

Source

pub fn new(a: f64, b: f64, c: f64, d: f64, h: f64, v: f64) -> Self

Create a new matrix with explicit components.

Source

pub fn identity() -> Self

The identity matrix.

Source

pub fn translation(h: f64, v: f64) -> Self

Create a translation matrix.

Source

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

Create a scaling matrix.

Source

pub fn rotation(angle: f64) -> Self

Create a rotation matrix (angle in radians).

Source

pub fn multiply(&self, other: &Matrix2D) -> Matrix2D

Multiply this matrix by another: self * other. This concatenates transformations: first other is applied, then self.

Source

pub fn concat(&self, other: &Matrix2D) -> Matrix2D

Concatenate: equivalent to other * self (apply self first, then other).

Source

pub fn determinant(&self) -> f64

Compute the determinant.

Source

pub fn inverse(&self) -> Option<Matrix2D>

Compute the inverse matrix. Returns None if the matrix is singular.

Source

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

Transform a point through this matrix.

Trait Implementations§

Source§

impl Clone for Matrix2D

Source§

fn clone(&self) -> Matrix2D

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 Matrix2D

Source§

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

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

impl Default for Matrix2D

Source§

fn default() -> Self

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

impl Mul for Matrix2D

Source§

type Output = Matrix2D

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl PartialEq for Matrix2D

Source§

fn eq(&self, other: &Matrix2D) -> 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 Copy for Matrix2D

Source§

impl StructuralPartialEq for Matrix2D

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.