mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
Merge pull request #20 from orange-cpp/u/orange-cpp/mat_sqr_brackets_op
Added brand new operator[] support for Mat/Matrix class
This commit is contained in:
@@ -66,6 +66,11 @@ namespace omath
|
|||||||
m_data = other.m_data;
|
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
|
OMATH_API constexpr Mat(Mat&& other) noexcept
|
||||||
{
|
{
|
||||||
m_data = std::move(other.m_data);
|
m_data = std::move(other.m_data);
|
||||||
|
|||||||
@@ -37,6 +37,13 @@ namespace omath
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API size_t RowCount() const noexcept;
|
OMATH_API size_t RowCount() const noexcept;
|
||||||
|
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
OMATH_API float& operator[](size_t row, size_t column)
|
||||||
|
{
|
||||||
|
return At(row, column);
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API size_t ColumnsCount() const noexcept;
|
OMATH_API size_t ColumnsCount() const noexcept;
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,14 @@ TEST_F(UnitTestMat, Constructor_InitializerList)
|
|||||||
EXPECT_FLOAT_EQ(m.At(1, 1), 4.0f);
|
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)
|
TEST_F(UnitTestMat, Constructor_Copy)
|
||||||
{
|
{
|
||||||
Mat<2, 2> m3 = m2;
|
Mat<2, 2> m3 = m2;
|
||||||
|
|||||||
@@ -29,6 +29,15 @@ TEST_F(UnitTestMatrix, Constructor_Size)
|
|||||||
EXPECT_EQ(m.ColumnsCount(), 3);
|
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)
|
TEST_F(UnitTestMatrix, Constructor_InitializerList)
|
||||||
{
|
{
|
||||||
Matrix m{{1.0f, 2.0f}, {3.0f, 4.0f}};
|
Matrix m{{1.0f, 2.0f}, {3.0f, 4.0f}};
|
||||||
|
|||||||
Reference in New Issue
Block a user