alloy::math::mat

Struct Mat4

source
pub struct Mat4(/* private fields */);
Expand description

A 4x4 non-owning view of a matrix.

§Guarantees

This type has the strict requirement that it can only reference a 4x4-component slice of f32 values. It is guaranteed to never refer to more or less than 2 entries.

This type is always in row-column order, meaning that the first index is the row, and the second index is the column.

§Relation to Matrix4

This type is a non-owning view of a 4x4 matrix, and is used to provide a way to reference a 4x4 matrix without taking ownership of the data.

Implementations§

source§

impl Mat4

source

pub const COLS: usize = 4usize

The number of columns this matrix contains

source

pub const ROWS: usize = 4usize

The number of rows this matrix contains.

source

pub const fn from_arrays(data: &[[f32; 4]; 4]) -> &Mat4

Creates a new 4x4 matrix view from a slice of 16 f32 values.

§Parameters
  • data - A slice of 16 f32 values.
source

pub fn from_mut_array(data: &mut [[f32; 4]; 4]) -> &mut Mat4

Creates a new 4x4 matrix view from a mutable slice of 16 f32 values.

§Parameters
  • data - A slice of 16 f32 values.
source

pub const fn from_array_slice(data: &[[f32; 4]]) -> Option<&Mat4>

Creates a new 4x4 matrix view from a slice of 16 f32 values. If the length of the slice is not 16, this function will return None.

§Parameters
  • data - A slice of 16 f32 values.
source

pub fn from_mut_array_slice(data: &mut [[f32; 4]]) -> Option<&mut Mat4>

Creates a new 4x4 matrix view from a mutable slice of 16 f32 values. If the length of the slice is not 16, this function will return None.

§Parameters
  • data - A slice of 16 f32 values.
source

pub const unsafe fn from_array_slice_unchecked(data: &[[f32; 4]]) -> &Mat4

Creates a new 4x4 matrix view from a slice of 16 f32 values without performing bounds checking.

§Safety

This function is unsafe because it does not check that the given slice has a length of 16. If this constraint is violated, memory safety errors can occur.

§Parameters
  • data - A slice of 16 f32 values.
source

pub unsafe fn from_mut_array_slice_unchecked(data: &mut [[f32; 4]]) -> &mut Mat4

Creates a new 4x4 matrix view from a mutable slice of 16 f32 values without performing bounds checking.

§Safety

This function is unsafe because it does not check that the given slice has a length of 16. If this constraint is violated, memory safety errors can occur.

§Parameters
  • data - A slice of 16 f32 values.
source

pub const fn from_slice(data: &[f32]) -> Option<&Mat4>

Creates a new 4x4 matrix view from a slice of at least 16 f32 values. If the length of the slice is less than 16, this function will return None.

§Parameters
  • data - A slice of at least 16 f32 values.
source

pub fn from_mut_slice(data: &mut [f32]) -> Option<&mut Mat4>

Creates a new 4x4 matrix view from a mutable slice of at least 16 f32 values. If the length of the slice is less than 16, this function will return None.

§Parameters
  • data - A slice of at least 16 f32 values.
source

pub const unsafe fn from_slice_unchecked(data: &[f32]) -> &Mat4

Forms a reference to a Mat4 from a flat slice of at least 16 f32 values.

§Safety

The caller must guarantee that the slice has a length of 16.

§Parameters
  • data - the slice of f32 values
source

pub unsafe fn from_mut_slice_unchecked(data: &mut [f32]) -> &mut Mat4

Forms a mutable reference to a Mat4 from a flat slice of at least 16 f32 values.

§Safety

The caller must guarantee that the slice has a length of 16.

§Parameters
  • data - the slice of f32 values
source

pub const unsafe fn from_ptr_unchecked<'a>(ptr: *const f32) -> &'a Mat4

Forms a reference to a Mat4 from a pointer to a contiguous sequence of at least 16 f32s.

§Parameters
  • ptr - the pointer to a sequence of f32 values
§Safety

ptr must point to an allocated object that references at least two entries

source

pub unsafe fn from_mut_ptr_unchecked<'a>(ptr: *mut f32) -> &'a mut Vec4

Forms a mutable reference to a Mat4 from a pointer to a contiguous sequence of at least 16 f32s.

§Parameters
  • ptr - the pointer to a sequence of f32 values
§Safety

ptr must point to an allocated object that references at least two entries

source§

impl Mat4

source

pub const fn as_slice(&self) -> &[f32]

Returns this Mat4 as a slice of f32.

source

pub fn as_mut_slice(&mut self) -> &mut [f32]

Returns this Mat4 as a mutable slice of f32.

source

pub const fn as_ptr(&self) -> *const f32

Returns this vector as a ptr of f32.

source

pub fn as_mut_ptr(&mut self) -> *mut f32

Returns this vector as a mutable ptr of f32.

source

pub const fn as_array_slice(&self) -> &[[f32; 4]]

Returns this Mat4 as a slice of 4-component arrays of f32.

source

pub fn as_mut_array_slice(&mut self) -> &mut [[f32; 4]]

Returns this Mat4 as a mutable slice of 4-component arrays of f32.

source

pub const fn as_array_ref(&self) -> &[[f32; 4]; 4]

Returns this Mat4 as a reference to a 4x4 array of f32.

source

pub fn as_mut_array_ref(&mut self) -> &mut [[f32; 4]; 4]

Returns this Mat4 as a mutable reference to a 4x4 array of f32.

source

pub const fn to_matrix4(&self) -> Matrix4

Returns this Mat4 as a Matrix4.

This function is const, unlike the equivalent From or ToOwned implementations.

source§

impl Mat4

source

pub const fn row(&self, index: usize) -> &Vec4

Returns the row at the given index.

This function will panic if the given index is out of bounds.

§Parameters
  • index - The index of the row to return.
source

pub const unsafe fn row_unchecked(&self, index: usize) -> &Vec4

Returns the row at the given index without performing bounds checking.

§Safety

This function is unsafe because it does not check that the given index is less than 4. If this constraint is violated, memory safety errors can occur.

§Parameters
  • index - The index of the row to return.
source

pub fn mut_row(&mut self, index: usize) -> &mut Vec4

Returns a mutable reference to the row at the given index.

This function will panic if the given index is out of bounds.

§Parameters
  • index - The index of the row to return.
source

pub unsafe fn mut_row_unchecked(&mut self, index: usize) -> &mut Vec4

Returns a mutable reference to the row at the given index without performing bounds checking.

§Safety

This function is unsafe because it does not check that the given index is less than 4. If this constraint is violated, memory safety errors can occur.

§Parameters
  • index - The index of the row to return.
source

pub const fn col(&self, index: usize) -> &Col4

Returns the column at the given index.

This function will panic if the given index is out of bounds.

§Parameters
  • index - The index of the column to return.
source

pub const unsafe fn col_unchecked(&self, index: usize) -> &Col4

Returns the column at the given index without performing bounds checking.

Note: Unlike Mat4::row_unchecked, this function returns an owning Vector4 instead of a reference of Vec4.

§Safety

This function is unsafe because it does not check that the given index is less than 4. If this constraint is violated, memory safety errors can occur.

§Parameters
  • index - The index of the column to return.
source

pub fn mut_col(&mut self, index: usize) -> &mut Col4

Returns a mutable reference to the column at the given index.

This function will panic if the given index is out of bounds.

§Parameters
  • index - The index of the column to return.
source

pub unsafe fn mut_col_unchecked(&mut self, index: usize) -> &mut Col4

Returns a mutable reference to the column at the given index without performing bounds checking.

§Safety

This function is unsafe because it does not check that the given index is less than 4. If this constraint is violated, memory safety errors can occur.

§Parameters
  • index - The index of the column to return.
source

pub const fn get(&self, row: usize, col: usize) -> f32

Returns the value at the given column and row.

This function will panic if the given index is out of bounds.

§Parameters
  • row - The index of the row to return.
  • col - The index of the column to return.
source

pub const unsafe fn get_unchecked(&self, row: usize, col: usize) -> f32

Returns the value at the given column and row without performing bounds checking.

§Safety

This function is unsafe because it does not check that the given index is less than 4. If this constraint is violated, memory safety errors can occur.

§Parameters
  • row - The index of the row to return.
  • col - The index of the column to return.
source

pub fn get_mut(&mut self, row: usize, col: usize) -> &mut f32

Returns a mutable reference to the value at the given column and row.

This function will panic if the given index is out of bounds.

§Parameters
  • row - The index of the row to return.
  • col - The index of the column to return.
source

pub unsafe fn get_mut_unchecked(&mut self, row: usize, col: usize) -> &mut f32

Returns a mutable reference to the value at the given column and row without performing bounds checking.

§Safety

This function is unsafe because it does not check that the given index is less than 4. If this constraint is violated, memory safety errors can occur.

§Parameters
  • row - The index of the row to return.
  • col - The index of the column to return.
source§

impl Mat4

source

pub fn scale(&mut self, scale: f32)

Scales each component of the matrix by the given scalar.

§Parameters
  • scale - The scalar to multiply each component by.
source

pub fn scale_vec(&mut self, scale: &Vec4)

Scales each row of the matrix by the given vector. This is equivalent to multiplying the matrix by a diagonal matrix with the given vector on the diagonal.

§Parameters
  • scale - The vector to multiply each row by.
source

pub fn transpose(&mut self)

Transposes all the elements of this matrix, swapping rows and columns.

source

pub fn invert(&mut self)

Inverts this matrix.

source§

impl Mat4

source

pub fn determinant(&self) -> f32

Returns the determinant of the matrix.

source

pub fn trace(&self) -> f32

Returns the trace of the matrix.

source

pub const fn transposed(&self) -> Matrix4

Returns the transpose of the matrix.

source

pub fn inverted(&self) -> Matrix4

Returns the inverse of the matrix.

source§

impl Mat4

source

pub fn mul_mat4(&self, other: &Mat4) -> Matrix4

Combines this matrix with another matrix by performing matrix multiplication.

§Parameters
  • other - The matrix to combine with.
source

pub fn mul_col_vec4(&self, vec: &Vec4) -> Vector4

Combines this matrix with a column vector, returning the resultant vector.

This implements matrix-vector of:

| a b c d |   | x |   | ax + by + cz + dw |
| e f g h | * | y | = | ex + fy + gz + hw |
| i j k l |   | z |   | ix + jy + kz + lw |
| m n o p |   | w |   | mx + ny + oz + pw |
§Parameters
  • vec - The vector to combine with.
source

pub fn mul_row_vec4(&self, vec: &Vec4) -> Vector4

Combines this matrix with a row vector, returning the resultant vector.

This implements vector-matrix multiplication of:

| x y z w |   | a b c d |   | ax + ey + iz + mw |
            * | e f g h | = | bx + fy + jz + nw |
              | i j k l |   | cx + gy + kz + ow |
              | m n o p |   | dx + hy + lz + pw |

Trait Implementations§

source§

impl Add<&Mat4> for &Matrix4

source§

type Output = Matrix4

The resulting type after applying the + operator.
source§

fn add(self, rhs: &Mat4) -> Self::Output

Performs the + operation. Read more
source§

impl Add<&Mat4> for Matrix4

source§

type Output = Matrix4

The resulting type after applying the + operator.
source§

fn add(self, rhs: &Mat4) -> Self::Output

Performs the + operation. Read more
source§

impl Add<&Matrix4> for &Mat4

source§

type Output = Matrix4

The resulting type after applying the + operator.
source§

fn add(self, rhs: &Matrix4) -> Self::Output

Performs the + operation. Read more
source§

impl Add<Matrix4> for &Mat4

source§

type Output = Matrix4

The resulting type after applying the + operator.
source§

fn add(self, rhs: Matrix4) -> Self::Output

Performs the + operation. Read more
source§

impl Add for &Mat4

source§

type Output = Matrix4

The resulting type after applying the + operator.
source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
source§

impl AddAssign<&Mat4> for Mat4

source§

fn add_assign(&mut self, rhs: &Mat4)

Performs the += operation. Read more
source§

impl AddAssign<&Mat4> for Matrix4

source§

fn add_assign(&mut self, rhs: &Mat4)

Performs the += operation. Read more
source§

impl AddAssign<&Matrix4> for Mat4

source§

fn add_assign(&mut self, rhs: &Matrix4)

Performs the += operation. Read more
source§

impl AddAssign<Matrix4> for Mat4

source§

fn add_assign(&mut self, rhs: Matrix4)

Performs the += operation. Read more
source§

impl AsMut<Mat4> for Matrix4

source§

fn as_mut(&mut self) -> &mut Mat4

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl AsRef<Mat4> for Matrix4

source§

fn as_ref(&self) -> &Mat4

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl AsRef<Mat4> for Projection

source§

fn as_ref(&self) -> &Mat4

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Borrow<Mat4> for Matrix4

source§

fn borrow(&self) -> &Mat4

Immutably borrows from an owned value. Read more
source§

impl BorrowMut<Mat4> for Matrix4

source§

fn borrow_mut(&mut self) -> &mut Mat4

Mutably borrows from an owned value. Read more
source§

impl Debug for Mat4

source§

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

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

impl Display for Mat4

source§

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

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

impl Div<f32> for &Mat4

source§

type Output = Matrix4

The resulting type after applying the / operator.
source§

fn div(self, rhs: f32) -> Self::Output

Performs the / operation. Read more
source§

impl DivAssign<f32> for Mat4

source§

fn div_assign(&mut self, rhs: f32)

Performs the /= operation. Read more
source§

impl Index<(usize, usize)> for Mat4

source§

type Output = f32

The returned type after indexing.
source§

fn index(&self, (row, col): (usize, usize)) -> &f32

Performs the indexing (container[index]) operation. Read more
source§

impl Index<usize> for Mat4

source§

type Output = Vec4

The returned type after indexing.
source§

fn index(&self, index: usize) -> &Vec4

Performs the indexing (container[index]) operation. Read more
source§

impl IndexMut<(usize, usize)> for Mat4

source§

fn index_mut(&mut self, (row, col): (usize, usize)) -> &mut f32

Performs the mutable indexing (container[index]) operation. Read more
source§

impl IndexMut<usize> for Mat4

source§

fn index_mut(&mut self, index: usize) -> &mut Vec4

Performs the mutable indexing (container[index]) operation. Read more
source§

impl Mul<&Mat4> for &Matrix4

source§

type Output = Matrix4

The resulting type after applying the * operator.
source§

fn mul(self, rhs: &Mat4) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<&Mat4> for Matrix4

source§

type Output = Matrix4

The resulting type after applying the * operator.
source§

fn mul(self, rhs: &Mat4) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<&Mat4> for f32

source§

type Output = Matrix4

The resulting type after applying the * operator.
source§

fn mul(self, rhs: &Mat4) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<&Matrix4> for &Mat4

source§

type Output = Matrix4

The resulting type after applying the * operator.
source§

fn mul(self, rhs: &Matrix4) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<&Vec4> for &Mat4

source§

type Output = Vector4

The resulting type after applying the * operator.
source§

fn mul(self, rhs: &Vec4) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<Matrix4> for &Mat4

source§

type Output = Matrix4

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Matrix4) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<f32> for &Mat4

source§

type Output = Matrix4

The resulting type after applying the * operator.
source§

fn mul(self, rhs: f32) -> Self::Output

Performs the * operation. Read more
source§

impl Mul for &Mat4

source§

type Output = Matrix4

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
source§

impl MulAssign<&Mat4> for Mat4

source§

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

Performs the *= operation. Read more
source§

impl MulAssign<&Mat4> for Matrix4

source§

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

Performs the *= operation. Read more
source§

impl MulAssign<&Matrix4> for Mat4

source§

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

Performs the *= operation. Read more
source§

impl MulAssign<Matrix4> for Mat4

source§

fn mul_assign(&mut self, rhs: Matrix4)

Performs the *= operation. Read more
source§

impl MulAssign<f32> for Mat4

source§

fn mul_assign(&mut self, rhs: f32)

Performs the *= operation. Read more
source§

impl Neg for &Mat4

source§

type Output = Matrix4

The resulting type after applying the - operator.
source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
source§

impl PartialEq for Mat4

source§

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

source§

fn partial_cmp(&self, other: &Mat4) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Sub<&Mat4> for &Matrix4

source§

type Output = Matrix4

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &Mat4) -> Self::Output

Performs the - operation. Read more
source§

impl Sub<&Mat4> for Matrix4

source§

type Output = Matrix4

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &Mat4) -> Self::Output

Performs the - operation. Read more
source§

impl Sub<&Matrix4> for &Mat4

source§

type Output = Matrix4

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &Matrix4) -> Self::Output

Performs the - operation. Read more
source§

impl Sub<Matrix4> for &Mat4

source§

type Output = Matrix4

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Matrix4) -> Self::Output

Performs the - operation. Read more
source§

impl Sub for &Mat4

source§

type Output = Matrix4

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
source§

impl SubAssign<&Mat4> for Mat4

source§

fn sub_assign(&mut self, rhs: &Mat4)

Performs the -= operation. Read more
source§

impl SubAssign<&Mat4> for Matrix4

source§

fn sub_assign(&mut self, rhs: &Mat4)

Performs the -= operation. Read more
source§

impl SubAssign<&Matrix4> for Mat4

source§

fn sub_assign(&mut self, rhs: &Matrix4)

Performs the -= operation. Read more
source§

impl SubAssign<Matrix4> for Mat4

source§

fn sub_assign(&mut self, rhs: Matrix4)

Performs the -= operation. Read more
source§

impl ToOwned for Mat4

source§

type Owned = Matrix4

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> Self::Owned

Creates owned data from borrowed data, usually by cloning. Read more
1.63.0 · source§

fn clone_into(&self, target: &mut Self::Owned)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl StructuralPartialEq for Mat4

Auto Trait Implementations§

§

impl Freeze for Mat4

§

impl RefUnwindSafe for Mat4

§

impl Send for Mat4

§

impl !Sized for Mat4

§

impl Sync for Mat4

§

impl Unpin for Mat4

§

impl UnwindSafe for Mat4

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

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more