#[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,
impl<T> Matrix2<T>where
T: Scalar,
Sourcepub fn new(m0: T, m1: T, m2: T, m3: T) -> Matrix2<T>
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]
Sourcepub fn determinant(&self) -> T
pub fn determinant(&self) -> T
Computes the determinant of the matrix.
For a 2x2 matrix:
det(M) = m₀₀m₁₁ - m₀₁m₁₀
Sourcepub fn inverse(&self) -> Matrix2<T>
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).
Sourcepub fn mul_matrix_matrix(l: &Matrix2<T>, r: &Matrix2<T>) -> Matrix2<T>
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]
Sourcepub fn mul_matrix_vector(l: &Matrix2<T>, r: &Vector2<T>) -> Vector2<T>
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
Sourcepub fn mul_vector_matrix(l: &Vector2<T>, r: &Matrix2<T>) -> Vector2<T>
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
Sourcepub fn add_matrix_matrix(l: &Matrix2<T>, r: &Matrix2<T>) -> Matrix2<T>
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]
Sourcepub fn sub_matrix_matrix(l: &Matrix2<T>, r: &Matrix2<T>) -> Matrix2<T>
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 AttributeDataTypeGetter for Matrix2<f32>
impl AttributeDataTypeGetter for Matrix2<f32>
Source§impl UniformDataTypeGetter for Matrix2<f32>
impl UniformDataTypeGetter for Matrix2<f32>
impl<T> Copy for Matrix2<T>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more