diff --git a/src/Matrix.cpp b/src/Matrix.cpp index 013e87c..bc1e443 100644 --- a/src/Matrix.cpp +++ b/src/Matrix.cpp @@ -134,7 +134,7 @@ Matrix::Mult(const Matrix &other, // the result's index is equal to the dot product of these two vectors result[row_idx][column_idx] = - Matrix::dotProduct(this_row, other_column.Transpose()); + Matrix::DotProduct(this_row, other_column.Transpose()); } } @@ -394,7 +394,7 @@ Matrix Matrix::operator*(float scalar) const template template -float Matrix::dotProduct(const Matrix<1, vector_size> &vec1, +float Matrix::DotProduct(const Matrix<1, vector_size> &vec1, const Matrix<1, vector_size> &vec2) { float sum{0}; @@ -408,7 +408,7 @@ float Matrix::dotProduct(const Matrix<1, vector_size> &vec1, template template -float Matrix::dotProduct(const Matrix &vec1, +float Matrix::DotProduct(const Matrix &vec1, const Matrix &vec2) { float sum{0}; @@ -553,23 +553,17 @@ Matrix Matrix::SubMatrix() const } template -template -void Matrix::SetSubMatrix(const Matrix &sub_matrix, uint8_t row_offset, uint8_t column_offset) +template +void Matrix::SetSubMatrix(const Matrix &sub_matrix) { - uint8_t corrected_sub_rows = sub_rows; - uint8_t corrected_sub_columns = sub_columns; - if (sub_rows + row_offset > rows) - { - corrected_sub_rows = rows - row_offset; - } - if (sub_columns + column_offset > columns) - { - corrected_sub_columns = columns - column_offset; - } + static_assert(sub_rows + row_offset <= rows, + "The submatrix you're trying to set is out of bounds (rows)"); + static_assert(sub_columns + column_offset <= columns, + "The submatrix you're trying to set is out of bounds (columns)"); - for (uint8_t row_idx{0}; row_idx < corrected_sub_rows; row_idx++) + for (uint8_t row_idx{0}; row_idx < sub_rows; row_idx++) { - for (uint8_t column_idx{0}; column_idx < corrected_sub_columns; column_idx++) + for (uint8_t column_idx{0}; column_idx < sub_columns; column_idx++) { this->matrix[(row_idx + row_offset) * columns + column_idx + column_offset] = sub_matrix.Get(row_idx, column_idx); } diff --git a/src/Matrix.hpp b/src/Matrix.hpp index 4c64771..ea31748 100644 --- a/src/Matrix.hpp +++ b/src/Matrix.hpp @@ -196,27 +196,27 @@ public: template Matrix SubMatrix() const; - template - void SetSubMatrix(const Matrix &sub_matrix, uint8_t row_offset, uint8_t column_offset); + template + void SetSubMatrix(const Matrix &sub_matrix); + + /** + * @brief take the dot product of the two vectors + */ + template + static float DotProduct(const Matrix<1, vector_size> &vec1, + const Matrix<1, vector_size> &vec2); + + template + static float DotProduct(const Matrix &vec1, + const Matrix &vec2); + + static float DotProduct(const Matrix<1, 1> &vec1, + const Matrix<1, 1> &vec2) { return vec1.Get(0, 0) * vec2.Get(0, 0); } protected: std::array matrix; private: - /** - * @brief take the dot product of the two vectors - */ - template - static float dotProduct(const Matrix<1, vector_size> &vec1, - const Matrix<1, vector_size> &vec2); - - template - static float dotProduct(const Matrix &vec1, - const Matrix &vec2); - - static float dotProduct(const Matrix<1, 1> &vec1, - const Matrix<1, 1> &vec2) { return vec1.Get(0, 0) * vec2.Get(0, 0); } - Matrix &adjugate(Matrix &result) const; void setMatrixToArray(const std::array &array);