Matrix2

Struct Matrix2 

Source
#[repr(C)]
pub struct Matrix2<T>
where T: Scalar,
{ pub col: [Vector2<T>; 2], }
Expand description

A 2x2 matrix stored in column-major order.

§Layout

[m₀₀ m₀₁]
[m₁₀ m₁₁]

where col[j][i] represents element at row i, column j.

Fields§

§col: [Vector2<T>; 2]

Column vectors of the matrix

Implementations§

Source§

impl<T> Matrix2<T>
where T: Scalar,

Source

pub fn new(m0: T, m1: T, m2: T, m3: T) -> Matrix2<T>

Creates a new 2x2 matrix from individual elements.

Elements are provided in column-major order:

[m0 m2]
[m1 m3]
Source

pub fn identity() -> Matrix2<T>

Returns the 2x2 identity matrix.

[1 0]
[0 1]
Source

pub fn determinant(&self) -> T

Computes the determinant of the matrix.

For a 2x2 matrix:

det(M) = m₀₀m₁₁ - m₀₁m₁₀
Source

pub fn transpose(&self) -> Matrix2<T>

Returns the transpose of the matrix.

Mᵀ[i,j] = M[j,i]
Source

pub fn inverse(&self) -> Matrix2<T>

Computes the inverse of the matrix.

For a 2x2 matrix:

M⁻¹ = (1/det(M)) * [m₁₁  -m₀₁]
                   [-m₁₀  m₀₀]
§Note

Returns NaN or Inf if the matrix is singular (determinant = 0).

Source

pub fn mul_matrix_matrix(l: &Matrix2<T>, r: &Matrix2<T>) -> Matrix2<T>

Multiplies two 2x2 matrices.

Matrix multiplication follows the rule:

C[i,j] = Σₖ A[i,k] * B[k,j]
Source

pub fn mul_matrix_vector(l: &Matrix2<T>, r: &Vector2<T>) -> Vector2<T>

Multiplies a 2x2 matrix by a 2D vector.

Transforms the vector by the matrix:

v' = M * v
Source

pub fn mul_vector_matrix(l: &Vector2<T>, r: &Matrix2<T>) -> Vector2<T>

Multiplies a 2D vector by a 2x2 matrix (row vector).

v' = vᵀ * M
Source

pub fn add_matrix_matrix(l: &Matrix2<T>, r: &Matrix2<T>) -> Matrix2<T>

Adds two matrices element-wise.

C[i,j] = A[i,j] + B[i,j]
Source

pub fn sub_matrix_matrix(l: &Matrix2<T>, r: &Matrix2<T>) -> Matrix2<T>

Subtracts two matrices element-wise.

C[i,j] = A[i,j] - B[i,j]

Trait Implementations§

Source§

impl<T> Add for Matrix2<T>
where T: Scalar,

Source§

type Output = Matrix2<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Matrix2<T>) -> Matrix2<T>

Performs the + operation. Read more
Source§

impl AttributeDataTypeGetter for Matrix2<f32>

Source§

impl<T> Clone for Matrix2<T>
where T: Clone + Scalar,

Source§

fn clone(&self) -> Matrix2<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 for Matrix2<T>
where T: Debug + Scalar,

Source§

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

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

impl<T> Mul<Matrix2<T>> for Vector2<T>
where T: Scalar,

Source§

type Output = Vector2<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T> Mul<Vector2<T>> for Matrix2<T>
where T: Scalar,

Source§

type Output = Vector2<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T> Mul for Matrix2<T>
where T: Scalar,

Source§

type Output = Matrix2<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T> Sub for Matrix2<T>
where T: Scalar,

Source§

type Output = Matrix2<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Matrix2<T>) -> Matrix2<T>

Performs the - operation. Read more
Source§

impl UniformDataTypeGetter for Matrix2<f32>

Source§

impl<T> Copy for Matrix2<T>
where T: Copy + Scalar,

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for Matrix2<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, 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.