From 2b9575311eb777e5b4a7553a2bb00281b2f8613e Mon Sep 17 00:00:00 2001 From: Orange Date: Sat, 21 Dec 2024 19:32:09 +0300 Subject: [PATCH] added operator for matrix --- include/omath/Matrix.hpp | 7 +++++++ tests/general/UnitTestMatrix.cpp | 9 +++++++++ 2 files changed, 16 insertions(+) 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/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}};