From 742a75277d9d98382b599ff711307435bae15158 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 26 Aug 2012 17:57:23 +0200 Subject: [PATCH] Moved unary operator- from Vector to RectangularMatrix. --- src/Math/RectangularMatrix.h | 13 +++++++++++++ src/Math/Test/RectangularMatrixTest.cpp | 5 +++++ src/Math/Test/RectangularMatrixTest.h | 1 + src/Math/Test/VectorTest.cpp | 5 ----- src/Math/Test/VectorTest.h | 1 - src/Math/Vector.h | 11 ----------- 6 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index 86293fc86..6c52764a8 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -183,6 +183,16 @@ template class RectangularMatrix { return *this; } + /** @brief Negative matrix */ + RectangularMatrix operator-() const { + RectangularMatrix out; + + for(size_t i = 0; i != cols*rows; ++i) + out._data[i] = -_data[i]; + + return out; + } + /** * @brief Subtract matrix * @@ -379,6 +389,9 @@ template Corrade::Utility::Debug operator<<(C } #define MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(cols, rows, ...) \ + inline __VA_ARGS__ operator-() const { \ + return Math::RectangularMatrix::operator-(); \ + } \ inline __VA_ARGS__ operator+(const Math::RectangularMatrix& other) const { \ return Math::RectangularMatrix::operator+(other); \ } \ diff --git a/src/Math/Test/RectangularMatrixTest.cpp b/src/Math/Test/RectangularMatrixTest.cpp index 51cfed605..da0762179 100644 --- a/src/Math/Test/RectangularMatrixTest.cpp +++ b/src/Math/Test/RectangularMatrixTest.cpp @@ -37,6 +37,7 @@ RectangularMatrixTest::RectangularMatrixTest() { &RectangularMatrixTest::constructZero, &RectangularMatrixTest::data, + &RectangularMatrixTest::negative, &RectangularMatrixTest::addSubtract, &RectangularMatrixTest::multiplyDivide, &RectangularMatrixTest::multiply, @@ -111,6 +112,10 @@ void RectangularMatrixTest::data() { CORRADE_COMPARE(m, expected); } +void RectangularMatrixTest::negative() { + CORRADE_COMPARE(-Matrix2(1.0f, -3.0f, 5.0f, -10.0f), Matrix2(-1.0f, 3.0f, -5.0f, 10.0f)); +} + void RectangularMatrixTest::addSubtract() { Matrix4x3 a(0.0f, 1.0f, 3.0f, 4.0f, 5.0f, 7.0f, diff --git a/src/Math/Test/RectangularMatrixTest.h b/src/Math/Test/RectangularMatrixTest.h index 211d767bd..0eae0204a 100644 --- a/src/Math/Test/RectangularMatrixTest.h +++ b/src/Math/Test/RectangularMatrixTest.h @@ -28,6 +28,7 @@ class RectangularMatrixTest: public Corrade::TestSuite::Tester { void min(); void max(); void angle(); - void negative(); void debug(); void configuration(); diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 6776fcbd0..da1372ee2 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -169,16 +169,6 @@ template class Vector: public RectangularMatrix<1, s, T> { return *this; } - /** @brief Negative vector */ - Vector operator-() const { - Vector out; - - for(size_t i = 0; i != size; ++i) - out[i] = -(*this)[i]; - - return out; - } - /** * @brief Dot product of the vector * @@ -321,7 +311,6 @@ template Corrade::Utility::Debug operator<<(Corrade::Utili return *this; \ } \ \ - inline Type operator-() const { return Math::Vector::operator-(); } \ inline Type normalized() const { return Math::Vector::normalized(); } #define MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Type, size) \