retrofire_core::math::mat

Struct Matrix

Source
#[repr(transparent)]
pub struct Matrix<Repr, Map>(pub Repr, _);
Expand description

A generic matrix type.

Tuple Fields§

§0: Repr

Implementations§

Source§

impl<Repr, Map> Matrix<Repr, Map>

Source

pub const fn new(els: Repr) -> Self

Returns a matrix with the given elements.

Source

pub fn to<M>(&self) -> Matrix<Repr, M>
where Repr: Clone,

Returns a matrix equal to self but with mapping M.

This method can be used to coerce a matrix to a different mapping in case it is needed to make types match.

Source§

impl<Sc, const N: usize, const M: usize, Map> Matrix<[[Sc; N]; M], Map>
where Sc: Copy, Map: LinearMap,

Source

pub fn row_vec(&self, i: usize) -> Vector<[Sc; N], Map::Source>

Returns the row vector of self with index i. The returned vector is in space Map::Source.

§Panics

If i >= M.

Source

pub fn col_vec(&self, i: usize) -> Vector<[Sc; M], Map::Dest>

Returns the column vector of self with index i.

The returned vector is in space Map::Dest.

§Panics

If i >= N.

Source§

impl<Sc: Copy, const N: usize, const DIM: usize, S, D> Matrix<[[Sc; N]; N], RealToReal<DIM, S, D>>

Source

pub fn transpose(self) -> Matrix<[[Sc; N]; N], RealToReal<DIM, D, S>>

Returns self with its rows and columns swapped.

Source§

impl<const N: usize, Map> Matrix<[[f32; N]; N], Map>

Source

pub const fn identity() -> Self

Returns the N×N identity matrix.

Source§

impl<M: LinearMap> Matrix<[[f32; 4]; 4], M>

Source

pub const fn from_basis(i: Vec3, j: Vec3, k: Vec3) -> Self

Constructs a matrix from a set of basis vectors.

Source§

impl<Sc, const N: usize, Map> Matrix<[[Sc; N]; N], Map>
where Sc: Linear<Scalar = Sc> + Copy, Map: LinearMap,

Source

pub fn compose<Inner: LinearMap>( &self, other: &Matrix<[[Sc; N]; N], Inner>, ) -> Matrix<[[Sc; N]; N], <Map as Compose<Inner>>::Result>
where Map: Compose<Inner>,

Returns the composite transform of self and other.

Computes the matrix product of self and other such that applying the resulting transformation is equivalent to first applying other and then self. More succinctly,

(𝗠 ∘ 𝗡)𝘃 = 𝗠(𝗡𝘃)

for some matrices 𝗠 and 𝗡 and a vector 𝘃.

Source

pub fn then<Outer: Compose<Map>>( &self, other: &Matrix<[[Sc; N]; N], Outer>, ) -> Matrix<[[Sc; N]; N], <Outer as Compose<Map>>::Result>

Returns the composite transform of other and self.

Computes the matrix product of self and other such that applying the resulting matrix is equivalent to first applying self and then other. The call self.then(other) is thus equivalent to other.compose(self).

Source§

impl<Src, Dst> Matrix<[[f32; 3]; 3], RealToReal<2, Src, Dst>>

Source

pub fn apply(&self, v: &Vec2<Src>) -> Vec2<Dst>

Maps the real 2-vector 𝘃 from basis Src to basis Dst.

Computes the matrix–vector multiplication 𝝡𝘃 where 𝘃 is interpreted as a column vector with an implicit 𝘃2 component with value 1:

        / M00 ·  ·  \ / v0 \
 Mv  =  |  ·  ·  ·  | | v1 |  =  ( v0' v1' 1 )
        \  ·  · M22 / \  1 /
Source§

impl<Src, Dst> Matrix<[[f32; 4]; 4], RealToReal<3, Src, Dst>>

Source

pub fn apply(&self, v: &Vec3<Src>) -> Vec3<Dst>

Maps the real 3-vector 𝘃 from basis Src to basis Dst.

Computes the matrix–vector multiplication 𝝡𝘃 where 𝘃 is interpreted as a column vector with an implicit 𝘃3 component with value 1:

        / M00 ·  ·  ·  \ / v0 \
 Mv  =  |  ·  ·  ·  ·  | | v1 |  =  ( v0' v1' v2' 1 )
        |  ·  ·  ·  ·  | | v2 |
        \  ·  ·  · M33 / \  1 /
Source

pub fn determinant(&self) -> f32

Returns the determinant of self.

Given a matrix M,

        / a  b  c  d \
 M  =   | e  f  g  h |
        | i  j  k  l |
        \ m  n  o  p /

its determinant can be computed by recursively computing the determinants of sub-matrices on rows 1.. and multiplying them by the elements on row 0:

             | f g h |       | e g h |
det(M) = a · | j k l | - b · | i k l |  + - ···
             | n o p |       | m o p |
Source

pub fn inverse(&self) -> Mat4x4<RealToReal<3, Dst, Src>>

Returns the inverse matrix of self.

The inverse 𝝡-1 of matrix 𝝡 is a matrix that, when composed with 𝝡, results in the identity matrix:

𝝡 ∘ 𝝡-1 = 𝝡-1 ∘ 𝝡 = 𝐈

In other words, it applies the transform of 𝝡 in reverse. Given vectors 𝘃 and 𝘂,

𝝡𝘃 = 𝘂 ⇔ 𝝡-1 𝘂 = 𝘃.

Only matrices with a nonzero determinant have a defined inverse. A matrix without an inverse is said to be singular.

Note: This method uses naive Gauss–Jordan elimination and may suffer from imprecision or numerical instability in certain cases.

§Panics

If self is singular or near-singular:

  • Panics in debug mode.
  • Does not panic in release mode, but the result may be inaccurate or contain Infs or NaNs.
Source§

impl<Src> Matrix<[[f32; 4]; 4], RealToProj<Src>>

Source

pub fn apply(&self, v: &Vec3<Src>) -> ProjVec4

Maps the real 3-vector 𝘃 from basis 𝖡 to the projective 4-space.

Computes the matrix–vector multiplication 𝝡𝘃 where 𝘃 is interpreted as a column vector with an implicit 𝘃3 component with value 1:

        / M00  ·  · \ / v0 \
 Mv  =  |    ·      | | v1 |  =  ( v0' v1' v2' v3' )
        |      ·    | | v2 |
        \ ·  ·  M33 / \  1 /

Trait Implementations§

Source§

impl<R: Clone, M> Clone for Matrix<R, M>

Source§

fn clone(&self) -> Self

Returns a copy 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<S: Debug, Map: Debug + Default, const N: usize, const M: usize> Debug for Matrix<[[S; N]; M], Map>

Source§

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

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

impl<const N: usize, Map> Default for Matrix<[[f32; N]; N], Map>

Source§

fn default() -> Self

Returns the N×N identity matrix.

Source§

impl<Repr, M> From<Repr> for Matrix<Repr, M>

Source§

fn from(repr: Repr) -> Self

Converts to this type from the input type.
Source§

impl<Repr: PartialEq, Map: PartialEq> PartialEq for Matrix<Repr, Map>

Source§

fn eq(&self, other: &Matrix<Repr, Map>) -> 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<Repr: Copy, Map: Copy> Copy for Matrix<Repr, Map>

Source§

impl<Repr: Eq, Map: Eq> Eq for Matrix<Repr, Map>

Source§

impl<Repr, Map> StructuralPartialEq for Matrix<Repr, Map>

Auto Trait Implementations§

§

impl<Repr, Map> Freeze for Matrix<Repr, Map>
where Repr: Freeze,

§

impl<Repr, Map> RefUnwindSafe for Matrix<Repr, Map>
where Repr: RefUnwindSafe, Map: RefUnwindSafe,

§

impl<Repr, Map> Send for Matrix<Repr, Map>
where Repr: Send, Map: Send,

§

impl<Repr, Map> Sync for Matrix<Repr, Map>
where Repr: Sync, Map: Sync,

§

impl<Repr, Map> Unpin for Matrix<Repr, Map>
where Repr: Unpin, Map: Unpin,

§

impl<Repr, Map> UnwindSafe for Matrix<Repr, Map>
where Repr: UnwindSafe, Map: 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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
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.