Browse Source

Math: component-wise comparison for RectangularMatrix.

Required for TestSuite::Compare::Around.
pull/196/head
Vladimír Vondruš 9 years ago
parent
commit
61e511dbc4
  1. 36
      src/Magnum/Math/RectangularMatrix.h
  2. 11
      src/Magnum/Math/Test/RectangularMatrixTest.cpp

36
src/Magnum/Math/RectangularMatrix.h

@ -224,6 +224,42 @@ template<std::size_t cols, std::size_t rows, class T> class RectangularMatrix {
return !operator==(other);
}
/**
* @brief Component-wise less than
*
* Calls @ref Vector::operator<() on @ref toVector().
*/
BoolVector<cols*rows> operator<(const RectangularMatrix<cols, rows, T>& other) const {
return toVector() < other.toVector();
}
/**
* @brief Component-wise less than or equal
*
* Calls @ref Vector::operator<=() on @ref toVector().
*/
BoolVector<cols*rows> operator<=(const RectangularMatrix<cols, rows, T>& other) const {
return toVector() <= other.toVector();
}
/**
* @brief Component-wise greater than or equal
*
* Calls @ref Vector::operator>=() on @ref toVector().
*/
BoolVector<cols*rows> operator>=(const RectangularMatrix<cols, rows, T>& other) const {
return toVector() >= other.toVector();
}
/**
* @brief Component-wise greater than
*
* Calls @ref Vector::operator>() on @ref toVector().
*/
BoolVector<cols*rows> operator>(const RectangularMatrix<cols, rows, T>& other) const {
return toVector() > other.toVector();
}
/**
* @brief Negated matrix
*

11
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));

Loading…
Cancel
Save