Transform2

Struct Transform2 

Source
#[repr(C)]
pub struct Transform2<T> { pub a11: T, pub a12: T, pub a13: T, pub a21: T, pub a22: T, pub a23: T, }
Expand description

2D affine transformation matrix.

Each field aij represents the i-th row and j-th column of the matrix.

The third row is implied to be [0, 0, 1] and is omitted.

Row-major storage with column-major semantics.

Stored in row-major order (fields appear in reading order), but interpreted as column-major: each column is a transformed basis vector, and matrices are applied to column vectors via mat * vec.

Fields§

§a11: T§a12: T§a13: T§a21: T§a22: T§a23: T

Implementations§

Source§

impl<T> Transform2<T>

Source

pub const fn new( a11: T, a12: T, a13: T, a21: T, a22: T, a23: T, ) -> Transform2<T>

Constructs a new matrix from components.

Source§

impl<T: Zero> Transform2<T>

Source

pub const ZERO: Transform2<T>

Zero matrix.

Source§

impl<T: Zero + One> Transform2<T>

Source

pub const IDENTITY: Transform2<T>

Identity matrix.

Source§

impl<T: Float> Transform2<T>

Source

pub fn translate(trans: Vec2<T>) -> Transform2<T>

Translation matrix.

Source

pub fn scale(scale: Vec2<T>) -> Transform2<T>

Scaling matrix.

Scales around the origin.

Source

pub fn rotate(angle: Angle<T>) -> Transform2<T>

Rotation matrix.

Rotates around the origin.

Source

pub fn skew(skew: Vec2<T>) -> Transform2<T>

Skewing matrix.

Source

pub fn reflect(line: Vec2<T>) -> Transform2<T>

Reflection matrix.

Reflects around the given axis. If axis is the zero vector, returns a point reflection around the origin.

Source

pub fn project(line: Vec2<T>) -> Transform2<T>

Projection matrix.

Projects onto the given axis. If axis is the zero vector, returns the zero matrix.

Source

pub fn fit(source: Bounds2<T>, target: Bounds2<T>) -> Transform2<T>

Fit matrix.

Fits coordinates from a source rect into a target rect.

Source

pub fn ortho(rect: Bounds2<T>) -> Transform2<T>

Orthographic matrix.

Fits the coordinates from a rectangle to x = [-1, 1] and y = [1, -1].

Source§

impl<T: Zero + One> Transform2<T>

Source

pub fn mat3(self) -> Mat3<T>

Converts to a 3x3 matrix.

Source§

impl<T> Transform2<T>

Source

pub fn from_row_major(mat: [[T; 3]; 2]) -> Transform2<T>

Imports the matrix from a row-major layout.

Source

pub fn from_column_major(mat: [[T; 2]; 3]) -> Transform2<T>

Imports the matrix from a column-major layout.

Source

pub fn into_row_major(self) -> [[T; 3]; 2]

Exports the matrix as a row-major array.

Source

pub fn into_column_major(self) -> [[T; 2]; 3]

Exports the matrix as a column-major array.

Source§

impl<T> Transform2<T>

Source

pub fn compose(x: Vec2<T>, y: Vec2<T>, t: Vec2<T>) -> Transform2<T>

Composes the matrix from basis vectors.

Source

pub fn x(self) -> Vec2<T>

Gets the transformed X basis vector.

Source

pub fn y(self) -> Vec2<T>

Gets the transformed Y basis vector.

Source

pub fn t(self) -> Vec2<T>

Gets the translation vector.

Source

pub fn mat2(self) -> Mat2<T>

Gets the rotation matrix.

Source§

impl<T: Scalar> Transform2<T>

Source

pub fn det(self) -> T

Computes the determinant.

Source

pub fn trace(self) -> T

Computes the trace.

Source

pub fn flat_norm_sqr(self) -> T

Computes the squared Frobenius norm (sum of squares of all matrix elements).

This measure is useful for quickly checking matrix magnitude or comparing matrices without the cost of a square root operation.

To check if a matrix is effectively zero, test if flat_norm_sqr() is below a small epsilon threshold.

Source

pub fn try_invert(self) -> Option<Transform2<T>>
where T: Float,

Source

pub fn inverse(self) -> Transform2<T>
where T: Float,

Computes the inverse matrix.

Returns the zero matrix if the determinant is near zero.

Source

pub fn lerp(self, other: Transform2<T>, t: T) -> Transform2<T>
where T: Float,

Linear interpolation between the matrix elements.

Trait Implementations§

Source§

impl<T: Clone> Clone for Transform2<T>

Source§

fn clone(&self) -> Transform2<T>

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<T: Debug> Debug for Transform2<T>

Source§

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

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

impl<T: Default> Default for Transform2<T>

Source§

fn default() -> Transform2<T>

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

impl<T: Display> Display for Transform2<T>

Source§

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

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

impl<T: Zero + One> From<Transform2<T>> for Mat3<T>

Source§

fn from(mat: Transform2<T>) -> Mat3<T>

Converts to this type from the input type.
Source§

impl<T> Mul<&T> for &Transform2<T>
where Transform2<T>: Copy + Mul<T, Output = Transform2<T>>, T: Copy,

Source§

type Output = Transform2<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &T) -> Transform2<T>

Performs the * operation. Read more
Source§

impl<T> Mul<&T> for Transform2<T>
where Transform2<T>: Mul<T, Output = Transform2<T>>, T: Copy,

Source§

type Output = Transform2<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &T) -> Transform2<T>

Performs the * operation. Read more
Source§

impl<T> Mul<&Transform2<T>> for &Transform2<T>
where Transform2<T>: Copy + Mul<Transform2<T>, Output = Transform2<T>>,

Source§

type Output = Transform2<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Transform2<T>) -> Transform2<T>

Performs the * operation. Read more
Source§

impl<T> Mul<&Transform2<T>> for Transform2<T>
where Transform2<T>: Mul<Transform2<T>, Output = Transform2<T>> + Copy,

Source§

type Output = Transform2<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Transform2<T>) -> Transform2<T>

Performs the * operation. Read more
Source§

impl<T> Mul<&Vec2<T>> for &Transform2<T>
where Transform2<T>: Copy + Mul<Vec2<T>, Output = Vec2<T>>, Vec2<T>: Copy,

Source§

type Output = Vec2<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Vec2<T>) -> Vec2<T>

Performs the * operation. Read more
Source§

impl<T> Mul<&Vec2<T>> for Transform2<T>
where Transform2<T>: Mul<Vec2<T>, Output = Vec2<T>>, Vec2<T>: Copy,

Source§

type Output = Vec2<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Vec2<T>) -> Vec2<T>

Performs the * operation. Read more
Source§

impl<T> Mul<&Vec3<T>> for &Transform2<T>
where Transform2<T>: Copy + Mul<Vec3<T>, Output = Vec3<T>>, Vec3<T>: Copy,

Source§

type Output = Vec3<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Vec3<T>) -> Vec3<T>

Performs the * operation. Read more
Source§

impl<T> Mul<&Vec3<T>> for Transform2<T>
where Transform2<T>: Mul<Vec3<T>, Output = Vec3<T>>, Vec3<T>: Copy,

Source§

type Output = Vec3<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Vec3<T>) -> Vec3<T>

Performs the * operation. Read more
Source§

impl<T: Copy + Add<Output = T> + Mul<Output = T>> Mul<Mat2<T>> for Transform2<T>

Source§

type Output = Transform2<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Mat2<T>) -> Transform2<T>

Performs the * operation. Read more
Source§

impl<T: Float> Mul<Ray2<T>> for Transform2<T>

Source§

type Output = Ray2<T>

The resulting type after applying the * operator.
Source§

fn mul(self, ray: Ray2<T>) -> Ray2<T>

Performs the * operation. Read more
Source§

impl<T> Mul<T> for &Transform2<T>
where Transform2<T>: Copy + Mul<T, Output = Transform2<T>>,

Source§

type Output = Transform2<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: T) -> Transform2<T>

Performs the * operation. Read more
Source§

impl<T> Mul<Transform2<T>> for &Transform2<T>
where Transform2<T>: Copy + Mul<Transform2<T>, Output = Transform2<T>>,

Source§

type Output = Transform2<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Transform2<T>) -> Transform2<T>

Performs the * operation. Read more
Source§

impl<T: Copy + Add<Output = T> + Mul<Output = T>> Mul<Transform2<T>> for Mat2<T>

Source§

type Output = Transform2<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Transform2<T>) -> Transform2<T>

Performs the * operation. Read more
Source§

impl<T: Copy + Add<Output = T> + Mul<Output = T>> Mul<Transform2<T>> for Mat3<T>

Source§

type Output = Mat3<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Transform2<T>) -> Mat3<T>

Performs the * operation. Read more
Source§

impl<T> Mul<Vec2<T>> for &Transform2<T>
where Transform2<T>: Copy + Mul<Vec2<T>, Output = Vec2<T>>,

Source§

type Output = Vec2<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vec2<T>) -> Vec2<T>

Performs the * operation. Read more
Source§

impl<T: Copy + Add<Output = T> + Mul<Output = T>> Mul<Vec2<T>> for Transform2<T>

Source§

type Output = Vec2<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vec2<T>) -> Vec2<T>

Performs the * operation. Read more
Source§

impl<T> Mul<Vec3<T>> for &Transform2<T>
where Transform2<T>: Copy + Mul<Vec3<T>, Output = Vec3<T>>,

Source§

type Output = Vec3<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vec3<T>) -> Vec3<T>

Performs the * operation. Read more
Source§

impl<T: Copy + Add<Output = T> + Mul<Output = T>> Mul<Vec3<T>> for Transform2<T>

Source§

type Output = Vec2<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vec3<T>) -> Vec2<T>

Performs the * operation. Read more
Source§

impl<T: Copy + Add<Output = T> + Mul<Output = T>> Mul for Transform2<T>

Source§

type Output = Transform2<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Transform2<T>) -> Transform2<T>

Performs the * operation. Read more
Source§

impl<T> MulAssign<&T> for Transform2<T>
where Transform2<T>: MulAssign<T>, T: Copy,

Source§

fn mul_assign(&mut self, rhs: &T)

Performs the *= operation. Read more
Source§

impl<T> MulAssign<&Transform2<T>> for Transform2<T>

Source§

fn mul_assign(&mut self, rhs: &Transform2<T>)

Performs the *= operation. Read more
Source§

impl<T: Copy + Add<Output = T> + Mul<Output = T>> MulAssign<Mat2<T>> for Transform2<T>

Source§

fn mul_assign(&mut self, rhs: Mat2<T>)

Performs the *= operation. Read more
Source§

impl<T: Copy + Add<Output = T> + Mul<Output = T>> MulAssign<Transform2<T>> for Mat3<T>

Source§

fn mul_assign(&mut self, rhs: Transform2<T>)

Performs the *= operation. Read more
Source§

impl<T: Copy + Add<Output = T> + Mul<Output = T>> MulAssign for Transform2<T>

Source§

fn mul_assign(&mut self, rhs: Transform2<T>)

Performs the *= operation. Read more
Source§

impl<T: PartialEq> PartialEq for Transform2<T>

Source§

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

Source§

impl<T> StructuralPartialEq for Transform2<T>

Auto Trait Implementations§

§

impl<T> Freeze for Transform2<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Transform2<T>
where T: RefUnwindSafe,

§

impl<T> Send for Transform2<T>
where T: Send,

§

impl<T> Sync for Transform2<T>
where T: Sync,

§

impl<T> Unpin for Transform2<T>
where T: Unpin,

§

impl<T> UnwindSafe for Transform2<T>
where T: UnwindSafe,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.