summary refs log tree commit diff
path: root/src/Math/Matrix.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Math/Matrix.hpp')
-rw-r--r--src/Math/Matrix.hpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/Math/Matrix.hpp b/src/Math/Matrix.hpp
index 69241d3..d467f72 100644
--- a/src/Math/Matrix.hpp
+++ b/src/Math/Matrix.hpp
@@ -9,14 +9,14 @@ template <size_t R, size_t C, typename T = float>
 struct Matrix {
     Matrix() : elements{} {};
 
-    explicit Matrix(T scalar) {
+    explicit Matrix(const T scalar) {
         std::fill(elements, elements + R * C, scalar);
     };
 
     template<typename ...Args, typename std::enable_if_t<sizeof...(Args) == R * C, int> = 0>
     Matrix(Args... args): elements{ args... } {};
 
-    explicit Matrix(T values[R * C]) {
+    explicit Matrix(const T values[R * C]) {
         std::copy(values, values + R * C, elements);
     };
 
@@ -67,11 +67,11 @@ struct Matrix {
         return rotation_x * rotation_y * rotation_z;
     }
 
-    Vector<C, T> row(size_t index) {
+    Vector<C, T> row(size_t index) const {
         return { &elements[index * C] };
     }
 
-    Vector<R, T> col(size_t index) {
+    Vector<R, T> col(size_t index) const {
         Vector<R, T> result{};
         for (int i = 0; i < R; i++) {
             result[i] = this->operator()(index, i);
@@ -79,7 +79,7 @@ struct Matrix {
         return result;
     }
 
-    Matrix transpose() {
+    Matrix transpose() const {
         Matrix result{};
         for (int y = 0; y < R; y++) {
             for (int x = 0; x < C; x++) {
@@ -89,7 +89,7 @@ struct Matrix {
         return result;
     }
 
-    Matrix operator+(Matrix other) {
+    Matrix operator+(const Matrix other) const {
         Matrix result{};
         for (int i = 0; i < R * C; i++) {
             result.elements[i] = elements[i] + other.elements[i];
@@ -106,7 +106,7 @@ struct Matrix {
     }
 
     template<size_t N>
-    Matrix<R, N, T> operator*(Matrix<C, N, T> other) {
+    Matrix<R, N, T> operator*(const Matrix<C, N, T> other) const {
         Matrix<R, N, T> result{};
         for (int y = 0; y < R; y++) {
             for (int x = 0; x < N; x++) {
@@ -121,13 +121,16 @@ struct Matrix {
         return result;
     }
 
-    Vector<R, T> operator*(Vector<R, T> vector) {
+    Vector<R, T> operator*(const Vector<R, T> vector) const {
         Matrix<R, 1, T> matrix(vector.elements);
         matrix = this->operator*(matrix);
         return { matrix.elements };
     }
 
-    auto& operator()(size_t x, size_t y) {
+    const T& operator()(const size_t x, const size_t y) const {
+        return elements[y * C + x];
+    }
+    T& operator()(const size_t x, const size_t y) {
         return elements[y * C + x];
     }