webgl_matrix/matrix.rs
1/// The base Matrix trait
2pub trait Matrix {
3 type MatrixType;
4 type VectorType;
5
6 /// Create a matrix filled with zeros
7 fn zeros() -> Self::MatrixType;
8
9 /// Create a matrix filled with ones
10 fn ones() -> Self::MatrixType;
11
12 /// Create the identity matrix
13 fn identity() -> Self::MatrixType;
14
15 /// Copy values to another matrix
16 fn copy_to(&self, dst: &mut Self::MatrixType);
17
18 /// Compute the transpose of this matrix
19 fn transpose(&mut self) -> &mut Self::MatrixType;
20
21 /// Perform matrix-multiplication with the given right-hand-side operand
22 fn mul(&mut self, rhs: &Self::MatrixType) -> &mut Self::MatrixType;
23
24 /// Multiplies this matrix with the given right-hand-side vector, i.e. `Matrix * rhs`
25 ///
26 /// Depending on dimensionality, the homogenous coordinate can be omitted,
27 /// if so, it will be assumed to be equal to 1.
28 fn mul_vector(&self, rhs: &[f32]) -> Self::VectorType;
29
30 /// Multiplies the given row vector with this matrix, i.e. `lhs * Matrix`
31 ///
32 /// Depending on dimensionality, the homogenous coordinate can be omitted,
33 /// if so, it will be assumed to be equal to 1.
34 fn mul_vector_left(&self, lhs: &[f32]) -> Self::VectorType;
35
36 /// Perform element-wise addition with the given right-hand-side operand
37 fn add(&mut self, rhs: &Self::MatrixType) -> &mut Self::MatrixType;
38 /// Perform element-wise substraction with the given right-hand-side operand
39 fn sub(&mut self, rhs: &Self::MatrixType) -> &mut Self::MatrixType;
40
41 /// Scale the matrix elment-wise by the given constant
42 fn scale(&mut self, factor: f32) -> &mut Self::MatrixType;
43
44 /// Compute the inverse of this matrix. Returns `None` if it is singular.
45 fn inverse(&mut self) -> Option<&mut Self::MatrixType>;
46
47 /// Compute the determinant of this matrix.
48 fn det(&self) -> f32;
49
50 /// Compute the adjugate of this matrix
51 fn adjugate(&mut self) -> &mut Self::MatrixType;
52
53 /// Translate this matrix into the given direction
54 ///
55 /// Depending on dimensionality, the homogenous coordinate of `direction` can be omitted,
56 /// if so, it will be assumed to be equal to 1.
57 fn translate(&mut self, direction: &[f32]) -> &mut Self::MatrixType;
58
59 /// Rotate this matrix by the given angle (radians) around the given axis
60 ///
61 /// Depending on dimensionality, the homogenous coordinate of `axis` can be omitted,
62 /// if so, it will be assumed to be equal to 1.
63 fn rotate(&mut self, angle: f32, axis: &[f32]) -> &mut Self::MatrixType;
64}