diff --git a/src/Magnum/Math/RectangularMatrix.h b/src/Magnum/Math/RectangularMatrix.h index 6c5cbb60c..4085ee08b 100644 --- a/src/Magnum/Math/RectangularMatrix.h +++ b/src/Magnum/Math/RectangularMatrix.h @@ -224,6 +224,42 @@ template class RectangularMatrix { return !operator==(other); } + /** + * @brief Component-wise less than + * + * Calls @ref Vector::operator<() on @ref toVector(). + */ + BoolVector operator<(const RectangularMatrix& other) const { + return toVector() < other.toVector(); + } + + /** + * @brief Component-wise less than or equal + * + * Calls @ref Vector::operator<=() on @ref toVector(). + */ + BoolVector operator<=(const RectangularMatrix& other) const { + return toVector() <= other.toVector(); + } + + /** + * @brief Component-wise greater than or equal + * + * Calls @ref Vector::operator>=() on @ref toVector(). + */ + BoolVector operator>=(const RectangularMatrix& other) const { + return toVector() >= other.toVector(); + } + + /** + * @brief Component-wise greater than + * + * Calls @ref Vector::operator>() on @ref toVector(). + */ + BoolVector operator>(const RectangularMatrix& other) const { + return toVector() > other.toVector(); + } + /** * @brief Negated matrix * diff --git a/src/Magnum/Math/Test/RectangularMatrixTest.cpp b/src/Magnum/Math/Test/RectangularMatrixTest.cpp index f19425038..5ffcc75b3 100644 --- a/src/Magnum/Math/Test/RectangularMatrixTest.cpp +++ b/src/Magnum/Math/Test/RectangularMatrixTest.cpp @@ -70,6 +70,7 @@ struct RectangularMatrixTest: Corrade::TestSuite::Tester { void row(); void compare(); + void compareComponentWise(); void negative(); void addSubtract(); @@ -119,6 +120,7 @@ RectangularMatrixTest::RectangularMatrixTest() { &RectangularMatrixTest::row, &RectangularMatrixTest::compare, + &RectangularMatrixTest::compareComponentWise, &RectangularMatrixTest::negative, &RectangularMatrixTest::addSubtract, @@ -331,6 +333,15 @@ void RectangularMatrixTest::compare() { CORRADE_VERIFY(ai != bi); } +void RectangularMatrixTest::compareComponentWise() { + typedef BoolVector<3> BoolVector3; + typedef RectangularMatrix<3, 1, Float> Matrix3x1; + CORRADE_COMPARE(Matrix3x1(1.0f, -1.0f, 5.0f) < Matrix3x1(1.1f, -1.0f, 3.0f), BoolVector3(0x1)); + CORRADE_COMPARE(Matrix3x1(1.0f, -1.0f, 5.0f) <= Matrix3x1(1.1f, -1.0f, 3.0f), BoolVector3(0x3)); + CORRADE_COMPARE(Matrix3x1(1.0f, -1.0f, 5.0f) >= Matrix3x1(1.1f, -1.0f, 3.0f), BoolVector3(0x6)); + CORRADE_COMPARE(Matrix3x1(1.0f, -1.0f, 5.0f) > Matrix3x1(1.1f, -1.0f, 3.0f), BoolVector3(0x4)); +} + void RectangularMatrixTest::negative() { Matrix2x2 matrix(Vector2(1.0f, -3.0f), Vector2(5.0f, -10.0f));