pub struct Matrix<const N: usize, T, A: Alignment>(/* private fields */)
where
Length<N>: SupportedLength,
T: Scalar;Expand description
A square column major matrix.
Matrix is the generic form of:
Matrix is generic over:
To initialize matrices, use the macros mat2,
mat3, mat4. To initialize a matrix of an
unknown length, use Matrix::from_col_array.
§Guarantees
Matrix<N, T, A> represents N consecutive values of Vector<N, T, A>
followed by optional padding due to alignment.
Padding bytes are initialized and accept any bit-pattern. It is sound to
store any bit-pattern in padding, and it is unsound to assume that
padding contains valid values of T unless T accepts all bit-patterns.
-
Matrix<N, T, Unaligned>: has no padding, has no additional alignment. -
Matrix<2, T, Aligned>: has memory layout identical toVector<4, T, Aligned>. -
Matrix<3, T, Aligned>: may have one padding vector, may have additional alignment. -
Matrix<4, T, Aligned>: has no padding, may have additional alignment.
Matrices of scalar types with the same Scalar::Repr are guaranteed to
have compatible memory layouts, unless Repr = (). They are guaranteed to
have the same size and element positions, but their alignment may differ.
Types containing Matrix are not guaranteed to have the same memory
layout as types containing equivalent arrays. For example, even though
Mat2U<T> and [T; 4] have the same memory layout, Option<Mat2U<T>> and
Option<[T; 4]> may not.
Implementations§
Source§impl<const N: usize, T, A: Alignment> Matrix<N, T, A>
impl<const N: usize, T, A: Alignment> Matrix<N, T, A>
Sourcepub const fn from_col_array(array: &[Vector<N, T, A>; N]) -> Self
pub const fn from_col_array(array: &[Vector<N, T, A>; N]) -> Self
Sourcepub fn from_col_fn<F>(f: F) -> Self
pub fn from_col_fn<F>(f: F) -> Self
Creates a matrix by calling function f for each column index.
Equivalent to [f(0), f(1), f(2), ...] where each item is a column.
Sourcepub const fn from_diagonal(diagonal: Vector<N, T, A>) -> Selfwhere
T: Zero,
pub const fn from_diagonal(diagonal: Vector<N, T, A>) -> Selfwhere
T: Zero,
Creates a matrix with its diagonal set to diagonal and all other entries set to 0.
Sourcepub const fn to_alignment<A2: Alignment>(&self) -> Matrix<N, T, A2>
pub const fn to_alignment<A2: Alignment>(&self) -> Matrix<N, T, A2>
Converts the matrix to the specified alignment.
See Alignment for more information.
Sourcepub const fn to_col_array(&self) -> [Vector<N, T, A>; N]
pub const fn to_col_array(&self) -> [Vector<N, T, A>; N]
Converts the matrix to an array of columns.
Sourcepub const fn as_col_array_ref(&self) -> &[Vector<N, T, A>; N]
pub const fn as_col_array_ref(&self) -> &[Vector<N, T, A>; N]
Returns a reference to the matrix’s columns.
Sourcepub const fn as_col_array_mut(&mut self) -> &mut [Vector<N, T, A>; N]
pub const fn as_col_array_mut(&mut self) -> &mut [Vector<N, T, A>; N]
Returns a mutable reference to the matrix’s columns.
Sourcepub const fn col_mut(&mut self, index: usize) -> &mut Vector<N, T, A>
pub const fn col_mut(&mut self, index: usize) -> &mut Vector<N, T, A>
Returns a mutable reference to the column at the given index.
§Panics
Panics if the index is out of bounds.
Sourcepub const unsafe fn to_repr<T2>(self) -> Matrix<N, T2, A>
pub const unsafe fn to_repr<T2>(self) -> Matrix<N, T2, A>
Reinterprets the bits of the matrix to a different scalar type.
The two scalar types must have compatible memory layouts. This is enforced via trait bounds in this function’s signature.
This function is used to make SIMD optimizations in implementations of Scalar.
§Safety
The components of the input must be valid for the output matrix type.
For example, when converting matrices from u8 to bool the
input components must be either 0 or 1.
The optional padding does not need to be a valid value of T2.
Trait Implementations§
Source§impl<const N: usize, T, A: Alignment> AddAssign<&Matrix<N, T, A>> for Matrix<N, T, A>
impl<const N: usize, T, A: Alignment> AddAssign<&Matrix<N, T, A>> for Matrix<N, T, A>
Source§fn add_assign(&mut self, rhs: &Self)
fn add_assign(&mut self, rhs: &Self)
+= operation. Read moreSource§impl<const N: usize, T, A: Alignment> AddAssign for Matrix<N, T, A>
impl<const N: usize, T, A: Alignment> AddAssign for Matrix<N, T, A>
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl<T, A: Alignment> From<(Vector<2, T, A>, Vector<2, T, A>)> for Matrix<2, T, A>where
T: Scalar,
impl<T, A: Alignment> From<(Vector<2, T, A>, Vector<2, T, A>)> for Matrix<2, T, A>where
T: Scalar,
Source§impl<T, A: Alignment> From<(Vector<3, T, A>, Vector<3, T, A>, Vector<3, T, A>)> for Matrix<3, T, A>where
T: Scalar,
impl<T, A: Alignment> From<(Vector<3, T, A>, Vector<3, T, A>, Vector<3, T, A>)> for Matrix<3, T, A>where
T: Scalar,
Source§impl<T, A: Alignment> From<(Vector<4, T, A>, Vector<4, T, A>, Vector<4, T, A>, Vector<4, T, A>)> for Matrix<4, T, A>where
T: Scalar,
impl<T, A: Alignment> From<(Vector<4, T, A>, Vector<4, T, A>, Vector<4, T, A>, Vector<4, T, A>)> for Matrix<4, T, A>where
T: Scalar,
Source§impl<const N: usize, T, A: Alignment> SubAssign<&Matrix<N, T, A>> for Matrix<N, T, A>
impl<const N: usize, T, A: Alignment> SubAssign<&Matrix<N, T, A>> for Matrix<N, T, A>
Source§fn sub_assign(&mut self, rhs: &Self)
fn sub_assign(&mut self, rhs: &Self)
-= operation. Read moreSource§impl<const N: usize, T, A: Alignment> SubAssign for Matrix<N, T, A>
impl<const N: usize, T, A: Alignment> SubAssign for Matrix<N, T, A>
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read more