glsl_linalg/
matrix.rs

1pub mod m2;
2pub mod m3;
3pub mod m4;
4
5use crate::float::Float;
6use std::ops::Div;
7
8#[derive(Default, Copy, Clone, PartialEq, Debug)]
9pub struct M2<T>(pub [[T; 2]; 2]);
10
11#[derive(Default, Copy, Clone, PartialEq, Debug)]
12pub struct M3<T>(pub [[T; 3]; 3]);
13
14#[derive(Default, Copy, Clone, PartialEq, Debug)]
15pub struct M4<T>(pub [[T; 4]; 4]);
16
17pub trait Matrix {
18    fn transpose(&mut self);
19}
20
21pub trait FloatMatrix<F>: Matrix
22where
23    F: Float,
24    Self: Clone + Div<F, Output = Self>,
25{
26    fn determinant(&self) -> F;
27    fn cofactor(&self) -> Self;
28    fn inverse(&self) -> Self {
29        self.cofactor() / self.determinant()
30    }
31}
32
33pub trait IntoVectors<V> {
34    fn into_cols(&self) -> V;
35    fn into_rows(&self) -> V;
36}
37
38pub trait FromVectors<V> {
39    fn from_cols(v: V) -> Self;
40    fn from_rows(v: V) -> Self;
41}