From 67e28a5a2ec0e33764165608ee38385e00d1a339 Mon Sep 17 00:00:00 2001 From: Orange Date: Sun, 18 Aug 2024 08:52:16 +0300 Subject: [PATCH] updated matrix name --- include/omath/matrix.h | 36 ++++++++++---------- source/matrix.cpp | 72 ++++++++++++++++++++-------------------- tests/UnitTestMatrix.cpp | 2 +- 3 files changed, 55 insertions(+), 55 deletions(-) diff --git a/include/omath/matrix.h b/include/omath/matrix.h index 6ac8003..920f94c 100644 --- a/include/omath/matrix.h +++ b/include/omath/matrix.h @@ -8,21 +8,21 @@ namespace omath { class Vector3; - class matrix + class Matrix { public: - matrix(size_t rows, size_t columns); + Matrix(size_t rows, size_t columns); - explicit matrix(const std::vector> &rows); + explicit Matrix(const std::vector> &rows); [[nodiscard]] - static matrix to_screen_matrix(float screenWidth, float screenHeight); + static Matrix to_screen_matrix(float screenWidth, float screenHeight); - matrix(const matrix &other); + Matrix(const Matrix &other); - matrix(size_t rows, size_t columns, const float *pRaw); + Matrix(size_t rows, size_t columns, const float *pRaw); - matrix(matrix &&other) noexcept; + Matrix(Matrix &&other) noexcept; [[nodiscard]] size_t get_rows_count() const noexcept; @@ -42,27 +42,27 @@ namespace omath void set_from_raw(const float* pRawMatrix); [[nodiscard]] - matrix transpose(); + Matrix transpose(); void set(float val); [[nodiscard]] const float &at(size_t iRow, size_t iCol) const; - matrix operator*(const matrix &other) const; + Matrix operator*(const Matrix &other) const; - matrix operator*(float f) const; + Matrix operator*(float f) const; - matrix operator*(const Vector3 &vec3) const; + Matrix operator*(const Vector3 &vec3) const; - matrix &operator*=(float f); + Matrix &operator*=(float f); - matrix &operator/=(float f); + Matrix &operator/=(float f); void clear(); [[nodiscard]] - matrix strip(size_t row, size_t column) const; + Matrix strip(size_t row, size_t column) const; [[nodiscard]] float minor(size_t i, size_t j) const; @@ -76,16 +76,16 @@ namespace omath [[nodiscard]] const float* raw() const; - matrix &operator=(const matrix &other); + Matrix &operator=(const Matrix &other); - matrix &operator=(matrix &&other) noexcept; + Matrix &operator=(Matrix &&other) noexcept; - matrix operator/(float f) const; + Matrix operator/(float f) const; [[nodiscard]] std::string to_string() const; - ~matrix(); + ~Matrix(); private: size_t m_rows = 0; diff --git a/source/matrix.cpp b/source/matrix.cpp index e520129..493da78 100644 --- a/source/matrix.cpp +++ b/source/matrix.cpp @@ -9,7 +9,7 @@ namespace omath { - matrix::matrix(const size_t rows, const size_t columns) + Matrix::Matrix(const size_t rows, const size_t columns) { if (rows == 0 and columns == 0) throw std::runtime_error("Matrix cannot be 0x0"); @@ -22,7 +22,7 @@ namespace omath set(0.f); } - matrix::matrix(const std::vector> &rows) + Matrix::Matrix(const std::vector> &rows) { m_rows = rows.size(); m_columns = rows[0].size(); @@ -35,7 +35,7 @@ namespace omath at(i,j) = rows[i][j]; } - matrix::matrix(const matrix &other) + Matrix::Matrix(const Matrix &other) { m_rows = other.m_rows; m_columns = other.m_columns; @@ -47,7 +47,7 @@ namespace omath at(i, j) = other.at(i, j); } - matrix::matrix(const size_t rows, const size_t columns, const float *pRaw) + Matrix::Matrix(const size_t rows, const size_t columns, const float *pRaw) { m_rows = rows; m_columns = columns; @@ -60,12 +60,12 @@ namespace omath } - size_t matrix::get_rows_count() const noexcept + size_t Matrix::get_rows_count() const noexcept { return m_rows; } - matrix::matrix(matrix &&other) noexcept + Matrix::Matrix(Matrix &&other) noexcept { m_rows = other.m_rows; m_columns = other.m_columns; @@ -73,22 +73,22 @@ namespace omath } - size_t matrix::get_columns_count() const noexcept + size_t Matrix::get_columns_count() const noexcept { return m_columns; } - std::pair matrix::get_size() const noexcept + std::pair Matrix::get_size() const noexcept { return {get_rows_count(), get_columns_count()}; } - float &matrix::at(const size_t iRow, const size_t iCol) + float &Matrix::at(const size_t iRow, const size_t iCol) { return const_cast(std::as_const(*this).at(iRow, iCol)); } - float matrix::get_sum() + float Matrix::get_sum() { float sum = 0; @@ -99,17 +99,17 @@ namespace omath return sum; } - const float &matrix::at(const size_t iRow, const size_t iCol) const + const float &Matrix::at(const size_t iRow, const size_t iCol) const { return m_pData[iRow * m_columns + iCol]; } - matrix matrix::operator*(const matrix &other) const + Matrix Matrix::operator*(const Matrix &other) const { if (m_columns != other.m_rows) throw std::runtime_error("n != m"); - auto outMat = matrix(m_rows, other.m_columns); + auto outMat = Matrix(m_rows, other.m_columns); for (size_t d = 0; d < m_rows; ++d) for (size_t i = 0; i < other.m_columns; ++i) @@ -120,7 +120,7 @@ namespace omath return outMat; } - matrix matrix::operator*(const float f) const + Matrix Matrix::operator*(const float f) const { auto out = *this; for (size_t i = 0; i < m_rows; ++i) @@ -130,7 +130,7 @@ namespace omath return out; } - matrix &matrix::operator*=(const float f) + Matrix &Matrix::operator*=(const float f) { for (size_t i = 0; i < get_rows_count(); i++) for (size_t j = 0; j < get_columns_count(); j++) @@ -138,14 +138,14 @@ namespace omath return *this; } - void matrix::clear() + void Matrix::clear() { set(0.f); } - matrix matrix::operator*(const Vector3 &vec3) const + Matrix Matrix::operator*(const Vector3 &vec3) const { - auto vecmatrix = matrix(m_rows, 1); + auto vecmatrix = Matrix(m_rows, 1); vecmatrix.set(1.f); vecmatrix.at(0, 0) = vec3.x; vecmatrix.at(1, 0) = vec3.y; @@ -156,7 +156,7 @@ namespace omath } - matrix &matrix::operator=(const matrix &other) + Matrix &Matrix::operator=(const Matrix &other) { if (this == &other) return *this; @@ -169,7 +169,7 @@ namespace omath } - matrix &matrix::operator=(matrix &&other) noexcept + Matrix &Matrix::operator=(Matrix &&other) noexcept { if (this == &other) return *this; @@ -182,7 +182,7 @@ namespace omath } - matrix &matrix::operator/=(const float f) + Matrix &Matrix::operator/=(const float f) { for (size_t i = 0; i < m_rows; ++i) for (size_t j = 0; j < m_columns; ++j) @@ -191,7 +191,7 @@ namespace omath return *this; } - matrix matrix::operator/(const float f) const + Matrix Matrix::operator/(const float f) const { auto out = *this; for (size_t i = 0; i < m_rows; ++i) @@ -201,7 +201,7 @@ namespace omath return out; } - std::string matrix::to_string() const + std::string Matrix::to_string() const { std::string str; @@ -220,7 +220,7 @@ namespace omath return str; } - float matrix::det() const + float Matrix::det() const { if (m_rows + m_columns == 2) return at(0, 0); @@ -235,15 +235,15 @@ namespace omath return fDet; } - float matrix::alg_complement(const size_t i, const size_t j) const + float Matrix::alg_complement(const size_t i, const size_t j) const { const auto tmp = minor(i, j); return ((i + j + 2) % 2 == 0) ? tmp : -tmp; } - matrix matrix::transpose() + Matrix Matrix::transpose() { - matrix transposed = {m_columns, m_rows}; + Matrix transposed = {m_columns, m_rows}; for (size_t i = 0; i < m_rows; ++i) for (size_t j = 0; j < m_columns; ++j) @@ -252,18 +252,18 @@ namespace omath return transposed; } - matrix::~matrix() = default; + Matrix::~Matrix() = default; - void matrix::set(const float val) + void Matrix::set(const float val) { for (size_t i = 0; i < m_rows; ++i) for (size_t j = 0; j < m_columns; ++j) at(i, j) = val; } - matrix matrix::strip(const size_t row, const size_t column) const + Matrix Matrix::strip(const size_t row, const size_t column) const { - matrix stripped = {m_rows - 1, m_columns - 1}; + Matrix stripped = {m_rows - 1, m_columns - 1}; size_t iStripRowIndex = 0; for (size_t i = 0; i < m_rows; i++) @@ -287,14 +287,14 @@ namespace omath return stripped; } - float matrix::minor(const size_t i, const size_t j) const + float Matrix::minor(const size_t i, const size_t j) const { return strip(i, j).det(); } - matrix matrix::to_screen_matrix(float screenWidth, float screenHeight) + Matrix Matrix::to_screen_matrix(float screenWidth, float screenHeight) { - return matrix({ + return Matrix({ {screenWidth / 2.f, 0.f, 0.f, 0.f}, {0.f, -screenHeight / 2.f, 0.f, 0.f}, {0.f, 0.f, 1.f, 0.f}, @@ -302,12 +302,12 @@ namespace omath }); } - const float * matrix::raw() const + const float * Matrix::raw() const { return m_pData.get(); } - void matrix::set_from_raw(const float *pRawMatrix) + void Matrix::set_from_raw(const float *pRawMatrix) { for (size_t i = 0; i < m_columns*m_rows; ++i) at(i / m_rows, i % m_columns) = pRawMatrix[i]; diff --git a/tests/UnitTestMatrix.cpp b/tests/UnitTestMatrix.cpp index 4b98613..f7fc112 100644 --- a/tests/UnitTestMatrix.cpp +++ b/tests/UnitTestMatrix.cpp @@ -8,7 +8,7 @@ TEST(UnitTestMatrix, ToString) { - omath::matrix matrix(2, 2); + omath::Matrix matrix(2, 2); matrix.set(1.1); const auto str = matrix.to_string();