diff --git a/src/Math/Matrix.h b/src/Math/Matrix.h index 5f12ba887..e1e759939 100644 --- a/src/Math/Matrix.h +++ b/src/Math/Matrix.h @@ -231,6 +231,21 @@ template class Matrix { }; #endif +#ifndef DOXYGEN_GENERATING_OUTPUT +template Corrade::Utility::Debug& operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Matrix& value) { + debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false); + debug << "Matrix("; + for(size_t row = 0; row != size; ++row) { + if(row != 0) debug << ",\n "; + for(size_t col = 0; col != size; ++col) { + if(col != 0) debug << ", "; + debug << value.at(row, col); + } + } + return debug << ')'; +} +#endif + }} #endif diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 81add54f7..51ef33f17 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -58,6 +58,12 @@ template class Matrix3: public Matrix { inline Matrix3 inverse() const { return Matrix::inverse(); } }; +#ifndef DOXYGEN_GENERATING_OUTPUT +template Corrade::Utility::Debug& operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Matrix3& value) { + return debug << static_cast&>(value); +} +#endif + }} #endif diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index b0c2742de..68e1599f7 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -161,6 +161,12 @@ template class Matrix4: public Matrix { inline Matrix4 inverse() const { return Matrix::inverse(); } }; +#ifndef DOXYGEN_GENERATING_OUTPUT +template Corrade::Utility::Debug& operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Matrix4& value) { + return debug << static_cast&>(value); +} +#endif + }} #endif diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index b0a5d036d..aaa6ea6d2 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -1,8 +1,17 @@ corrade_add_test(VectorTest VectorTest.h VectorTest.cpp) +target_link_libraries(VectorTest ${CORRADE_UTILITY_LIBRARY}) +corrade_add_test(Vector2Test Vector2Test.h Vector2Test.cpp) +target_link_libraries(Vector2Test ${CORRADE_UTILITY_LIBRARY}) corrade_add_test(Vector3Test Vector3Test.h Vector3Test.cpp) +target_link_libraries(Vector3Test ${CORRADE_UTILITY_LIBRARY}) corrade_add_test(Vector4Test Vector4Test.h Vector4Test.cpp) +target_link_libraries(Vector4Test ${CORRADE_UTILITY_LIBRARY}) corrade_add_test(MatrixTest MatrixTest.h MatrixTest.cpp) +target_link_libraries(MatrixTest ${CORRADE_UTILITY_LIBRARY}) +corrade_add_test(Matrix3Test Matrix3Test.h Matrix3Test.cpp) +target_link_libraries(Matrix3Test ${CORRADE_UTILITY_LIBRARY}) corrade_add_test(Matrix4Test Matrix4Test.h Matrix4Test.cpp) +target_link_libraries(Matrix4Test ${CORRADE_UTILITY_LIBRARY}) corrade_add_test(GeometryUtilsTest GeometryUtilsTest.h GeometryUtilsTest.cpp) diff --git a/src/Math/Test/Matrix3Test.cpp b/src/Math/Test/Matrix3Test.cpp new file mode 100644 index 000000000..21282c265 --- /dev/null +++ b/src/Math/Test/Matrix3Test.cpp @@ -0,0 +1,46 @@ +/* + Copyright © 2010, 2011 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Matrix3Test.h" + +#include +#include + +#include "Matrix3.h" + +QTEST_APPLESS_MAIN(Magnum::Math::Test::Matrix3Test) + +using namespace std; +using namespace Corrade::Utility; + +namespace Magnum { namespace Math { namespace Test { + +typedef Math::Matrix3 Matrix3; + +void Matrix3Test::debug() { + float m[] = { + 3, 5, 8, + 4, 4, 7, + 7, -1, 8, + }; + + ostringstream o; + Debug(&o) << Matrix3(m); + QCOMPARE(QString::fromStdString(o.str()), QString("Matrix(3, 4, 7,\n" + " 5, 4, -1,\n" + " 8, 7, 8)\n")); +} + +}}} diff --git a/src/Math/Test/Matrix3Test.h b/src/Math/Test/Matrix3Test.h new file mode 100644 index 000000000..409b9a1b6 --- /dev/null +++ b/src/Math/Test/Matrix3Test.h @@ -0,0 +1,31 @@ +#ifndef Magnum_Math_Test_Matrix3Test_h +#define Magnum_Math_Test_Matrix3Test_h +/* + Copyright © 2010, 2011 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +namespace Magnum { namespace Math { namespace Test { + +class Matrix3Test: public QObject { + Q_OBJECT + + private slots: + void debug(); +}; + +}}} + +#endif diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index b5922c505..0e4886618 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -15,6 +15,7 @@ #include "Matrix4Test.h" +#include #include #include "Matrix4.h" @@ -22,6 +23,9 @@ QTEST_APPLESS_MAIN(Magnum::Math::Test::Matrix4Test) +using namespace std; +using namespace Corrade::Utility; + namespace Magnum { namespace Math { namespace Test { typedef Math::Matrix4 Matrix4; @@ -59,4 +63,20 @@ void Matrix4Test::rotation() { QVERIFY(Matrix4::rotation(-74*PI/180.0f, -1.0f, 2.0f, 2.0f) == Matrix4(matrix)); } +void Matrix4Test::debug() { + float m[] = { + 3, 5, 8, 4, + 4, 4, 7, 3, + 7, -1, 8, 0, + 9, 4, 5, 9 + }; + + ostringstream o; + Debug(&o) << Matrix4(m); + QCOMPARE(QString::fromStdString(o.str()), QString("Matrix(3, 4, 7, 9,\n" + " 5, 4, -1, 4,\n" + " 8, 7, 8, 5,\n" + " 4, 3, 0, 9)\n")); +} + }}} diff --git a/src/Math/Test/Matrix4Test.h b/src/Math/Test/Matrix4Test.h index 51f11d138..ce83001c7 100644 --- a/src/Math/Test/Matrix4Test.h +++ b/src/Math/Test/Matrix4Test.h @@ -26,6 +26,8 @@ class Matrix4Test: public QObject { void translation(); void scaling(); void rotation(); + + void debug(); }; }}} diff --git a/src/Math/Test/MatrixTest.cpp b/src/Math/Test/MatrixTest.cpp index 8c1fdc000..8d97c4b7d 100644 --- a/src/Math/Test/MatrixTest.cpp +++ b/src/Math/Test/MatrixTest.cpp @@ -15,12 +15,16 @@ #include "MatrixTest.h" +#include #include #include "Matrix.h" QTEST_APPLESS_MAIN(Magnum::Math::Test::MatrixTest) +using namespace std; +using namespace Corrade::Utility; + namespace Magnum { namespace Math { namespace Test { typedef Matrix Matrix4; @@ -229,4 +233,20 @@ void MatrixTest::inverse() { QVERIFY(_inverse*Matrix4(m) == Matrix4()); } +void MatrixTest::debug() { + float m[] = { + 3, 5, 8, 4, + 4, 4, 7, 3, + 7, -1, 8, 0, + 9, 4, 5, 9 + }; + + ostringstream o; + Debug(&o) << Matrix4(m); + QCOMPARE(QString::fromStdString(o.str()), QString("Matrix(3, 4, 7, 9,\n" + " 5, 4, -1, 4,\n" + " 8, 7, 8, 5,\n" + " 4, 3, 0, 9)\n")); +} + }}} diff --git a/src/Math/Test/MatrixTest.h b/src/Math/Test/MatrixTest.h index 97616657a..cbc6f518c 100644 --- a/src/Math/Test/MatrixTest.h +++ b/src/Math/Test/MatrixTest.h @@ -34,6 +34,8 @@ class MatrixTest: public QObject { void ij(); void determinant(); void inverse(); + + void debug(); }; }}} diff --git a/src/Math/Test/Vector2Test.cpp b/src/Math/Test/Vector2Test.cpp new file mode 100644 index 000000000..b43ca762a --- /dev/null +++ b/src/Math/Test/Vector2Test.cpp @@ -0,0 +1,38 @@ +/* + Copyright © 2010, 2011 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Vector2Test.h" + +#include +#include + +#include "Vector2.h" + +QTEST_APPLESS_MAIN(Magnum::Math::Test::Vector2Test) + +using namespace std; +using namespace Corrade::Utility; + +namespace Magnum { namespace Math { namespace Test { + +typedef Math::Vector2 Vector2; + +void Vector2Test::debug() { + ostringstream o; + Debug(&o) << Vector2(0.5f, 15.0f); + QCOMPARE(QString::fromStdString(o.str()), QString("Vector(0.5, 15)\n")); +} + +}}} diff --git a/src/Math/Test/Vector2Test.h b/src/Math/Test/Vector2Test.h new file mode 100644 index 000000000..ce55007e6 --- /dev/null +++ b/src/Math/Test/Vector2Test.h @@ -0,0 +1,31 @@ +#ifndef Magnum_Math_Test_Vector2Test_h +#define Magnum_Math_Test_Vector2Test_h +/* + Copyright © 2010, 2011 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +namespace Magnum { namespace Math { namespace Test { + +class Vector2Test: public QObject { + Q_OBJECT + + private slots: + void debug(); +}; + +}}} + +#endif diff --git a/src/Math/Test/Vector3Test.cpp b/src/Math/Test/Vector3Test.cpp index b9196c112..eb0ec786e 100644 --- a/src/Math/Test/Vector3Test.cpp +++ b/src/Math/Test/Vector3Test.cpp @@ -15,12 +15,16 @@ #include "Vector3Test.h" +#include #include #include "Vector3.h" QTEST_APPLESS_MAIN(Magnum::Math::Test::Vector3Test) +using namespace std; +using namespace Corrade::Utility; + namespace Magnum { namespace Math { namespace Test { typedef Math::Vector3 Vector3; @@ -32,4 +36,10 @@ void Vector3Test::cross() { QVERIFY(Vector3::cross(a, b) == Vector3(-10, -3, 7)); } +void Vector3Test::debug() { + ostringstream o; + Debug(&o) << Vector3(0.5f, 15.0f, 1.0f); + QCOMPARE(QString::fromStdString(o.str()), QString("Vector(0.5, 15, 1)\n")); +} + }}} diff --git a/src/Math/Test/Vector3Test.h b/src/Math/Test/Vector3Test.h index d00bfde58..cd0b79cf6 100644 --- a/src/Math/Test/Vector3Test.h +++ b/src/Math/Test/Vector3Test.h @@ -24,6 +24,8 @@ class Vector3Test: public QObject { private slots: void cross(); + + void debug(); }; }}} diff --git a/src/Math/Test/Vector4Test.cpp b/src/Math/Test/Vector4Test.cpp index 516645746..3d37bf501 100644 --- a/src/Math/Test/Vector4Test.cpp +++ b/src/Math/Test/Vector4Test.cpp @@ -15,12 +15,16 @@ #include "Vector4Test.h" +#include #include #include "Vector4.h" QTEST_APPLESS_MAIN(Magnum::Math::Test::Vector4Test) +using namespace std; +using namespace Corrade::Utility; + namespace Magnum { namespace Math { namespace Test { typedef Math::Vector4 Vector4; @@ -34,4 +38,10 @@ void Vector4Test::threeComponent() { QVERIFY(Vector4(1.0f, 2.0f, 3.0f, 4.0f).xyz() == Vector3(1.0f, 2.0f, 3.0f)); } +void Vector4Test::debug() { + ostringstream o; + Debug(&o) << Vector4(0.5f, 15.0f, 1.0f, 1.0f); + QCOMPARE(QString::fromStdString(o.str()), QString("Vector(0.5, 15, 1, 1)\n")); +} + }}} diff --git a/src/Math/Test/Vector4Test.h b/src/Math/Test/Vector4Test.h index c16fc4820..807ff0d91 100644 --- a/src/Math/Test/Vector4Test.h +++ b/src/Math/Test/Vector4Test.h @@ -25,6 +25,8 @@ class Vector4Test: public QObject { private slots: void construct(); void threeComponent(); + + void debug(); }; }}} diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index 085e21b73..fb6e4b4dd 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -15,6 +15,7 @@ #include "VectorTest.h" +#include #include #include "Vector.h" @@ -22,6 +23,7 @@ QTEST_APPLESS_MAIN(Magnum::Math::Test::VectorTest) using namespace std; +using namespace Corrade::Utility; namespace Magnum { namespace Math { namespace Test { @@ -132,4 +134,12 @@ void VectorTest::negative() { QVERIFY(-Vector4(vec) == negative); } +void VectorTest::debug() { + float vec[] = { 0.5f, 15.0f, 1.0f, 1.0f }; + + ostringstream o; + Debug(&o) << Vector4(vec); + QCOMPARE(QString::fromStdString(o.str()), QString("Vector(0.5, 15, 1, 1)\n")); +} + }}} diff --git a/src/Math/Test/VectorTest.h b/src/Math/Test/VectorTest.h index f81d15130..9b896047d 100644 --- a/src/Math/Test/VectorTest.h +++ b/src/Math/Test/VectorTest.h @@ -34,6 +34,8 @@ class VectorTest: public QObject { void normalized(); void angle(); void negative(); + + void debug(); }; }}} diff --git a/src/Math/Vector.h b/src/Math/Vector.h index d8949a579..b57dd2c33 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -22,6 +22,7 @@ #include #include +#include "Utility/Debug.h" #include "constants.h" namespace Magnum { namespace Math { @@ -176,6 +177,18 @@ template class Vector { T _data[size]; }; +#ifndef DOXYGEN_GENERATING_OUTPUT +template Corrade::Utility::Debug& operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Vector& value) { + debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false); + debug << "Vector("; + for(size_t i = 0; i != size; ++i) { + if(i != 0) debug << ", "; + debug << value.at(i); + } + return debug << ')'; +} +#endif + }} #endif diff --git a/src/Math/Vector2.h b/src/Math/Vector2.h index 7a6c27c2d..08fe80124 100644 --- a/src/Math/Vector2.h +++ b/src/Math/Vector2.h @@ -75,6 +75,12 @@ template class Vector2: public Vector { inline Vector2 normalized() const { return Vector::normalized(); } }; +#ifndef DOXYGEN_GENERATING_OUTPUT +template Corrade::Utility::Debug& operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Vector2& value) { + return debug << static_cast&>(value); +} +#endif + }} #endif diff --git a/src/Math/Vector3.h b/src/Math/Vector3.h index 15eaca6e6..facf31ead 100644 --- a/src/Math/Vector3.h +++ b/src/Math/Vector3.h @@ -102,6 +102,12 @@ template class Vector3: public Vector { inline Vector3 normalized() const { return Vector::normalized(); } }; +#ifndef DOXYGEN_GENERATING_OUTPUT +template Corrade::Utility::Debug& operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Vector3& value) { + return debug << static_cast&>(value); +} +#endif + }} #endif diff --git a/src/Math/Vector4.h b/src/Math/Vector4.h index 11f82593f..71dc57008 100644 --- a/src/Math/Vector4.h +++ b/src/Math/Vector4.h @@ -118,6 +118,12 @@ template class Vector4: public Vector { inline Vector4 normalized() const { return Vector::normalized(); } }; +#ifndef DOXYGEN_GENERATING_OUTPUT +template Corrade::Utility::Debug& operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Vector4& value) { + return debug << static_cast&>(value); +} +#endif + }} #endif