vox_geometry_rust/matrix.rs
1/*
2 * // Copyright (c) 2021 Feng Yang
3 * //
4 * // I am making my contributions/submissions to this project solely in my
5 * // personal capacity and am not conveying any rights to any intellectual
6 * // property of any third parties.
7 */
8
9use crate::matrix_expression::MatrixExpression;
10use crate::usize2::USize2;
11
12///
13/// # Static-sized M x N matrix class.
14///
15/// This class defines M x N row-major matrix data where its size is determined
16/// statically at compile time.
17///
18/// - tparam T - Real number type.
19/// - tparam M - Number of rows.
20/// - tparam N - Number of columns.
21///
22
23pub struct Matrix<const M: usize, const N: usize, const TOTAL: usize> {
24 _elements: [f64; TOTAL],
25}
26
27impl<const M: usize, const N: usize, const TOTAL: usize> MatrixExpression for Matrix<M, N, TOTAL> {
28 fn size(&self) -> USize2 {
29 return USize2::new(M, N);
30 }
31
32 fn rows(&self) -> usize {
33 return M;
34 }
35
36 fn cols(&self) -> usize {
37 return N;
38 }
39
40 fn eval(&self, x: usize, y: usize) -> f64 {
41 return self._elements[x * N + y];
42 }
43}