diff --git a/include/omath/Mat.hpp b/include/omath/Mat.hpp index 7b05f42..63cbdef 100644 --- a/include/omath/Mat.hpp +++ b/include/omath/Mat.hpp @@ -66,6 +66,11 @@ namespace omath m_data = other.m_data; } + OMATH_API constexpr Type& operator[](const size_t row, const size_t col) + { + return At(row, col); + } + OMATH_API constexpr Mat(Mat&& other) noexcept { m_data = std::move(other.m_data); diff --git a/include/omath/Matrix.hpp b/include/omath/Matrix.hpp index 3ffe5ec..78314a3 100644 --- a/include/omath/Matrix.hpp +++ b/include/omath/Matrix.hpp @@ -37,6 +37,13 @@ namespace omath [[nodiscard]] OMATH_API size_t RowCount() const noexcept; + + [[nodiscard]] + OMATH_API float& operator[](size_t row, size_t column) + { + return At(row, column); + } + [[nodiscard]] OMATH_API size_t ColumnsCount() const noexcept; diff --git a/tests/general/UnitTestMat.cpp b/tests/general/UnitTestMat.cpp index 0105c28..cdaecfc 100644 --- a/tests/general/UnitTestMat.cpp +++ b/tests/general/UnitTestMat.cpp @@ -40,6 +40,14 @@ TEST_F(UnitTestMat, Constructor_InitializerList) EXPECT_FLOAT_EQ(m.At(1, 1), 4.0f); } +TEST_F(UnitTestMat, Operator_SquareBrackets) +{ + EXPECT_EQ((m2[0, 0]), 1.0f); + EXPECT_EQ((m2[0, 1]), 2.0f); + EXPECT_EQ((m2[1, 0]), 3.0f); + EXPECT_EQ((m2[1, 1]), 4.0f); +} + TEST_F(UnitTestMat, Constructor_Copy) { Mat<2, 2> m3 = m2; diff --git a/tests/general/UnitTestMatrix.cpp b/tests/general/UnitTestMatrix.cpp index bc749d0..1fa94b0 100644 --- a/tests/general/UnitTestMatrix.cpp +++ b/tests/general/UnitTestMatrix.cpp @@ -29,6 +29,15 @@ TEST_F(UnitTestMatrix, Constructor_Size) EXPECT_EQ(m.ColumnsCount(), 3); } +TEST_F(UnitTestMatrix, Operator_SquareBrackets) +{ + EXPECT_EQ((m2[0, 0]), 1.0f); + EXPECT_EQ((m2[0, 1]), 2.0f); + EXPECT_EQ((m2[1, 0]), 3.0f); + EXPECT_EQ((m2[1, 1]), 4.0f); +} + + TEST_F(UnitTestMatrix, Constructor_InitializerList) { Matrix m{{1.0f, 2.0f}, {3.0f, 4.0f}};