From 728b9a3f2ea291cbedae1cfb60bc33a17c3c833b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 22 Feb 2013 15:00:46 +0100 Subject: [PATCH] Math: construct identity transformation by default. Square matrices already had that, (dual) quaternions too, making that the default also with complex numbers. Updated the documentation to reflect that. --- src/Math/Complex.h | 6 +++--- src/Math/DualQuaternion.h | 4 ++-- src/Math/Matrix3.h | 10 ++++++++-- src/Math/Matrix4.h | 10 ++++++++-- src/Math/Quaternion.h | 4 ++-- src/Math/Test/ComplexTest.cpp | 5 +++-- src/Math/Test/DualQuaternionTest.cpp | 5 +---- src/Math/Test/QuaternionTest.cpp | 1 + src/Math/Vector.h | 2 +- 9 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/Math/Complex.h b/src/Math/Complex.h index 72fed26e3..a0c640d53 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -52,11 +52,11 @@ template class Complex { /** * @brief Default constructor * - * @f[ - * c = 0 + i0 + * Constructs unit complex number. @f[ + * c = 1 + i0 * @f] */ - inline constexpr /*implicit*/ Complex(): _real(T(0)), _imaginary(T(0)) {} + inline constexpr /*implicit*/ Complex(): _real(T(1)), _imaginary(T(0)) {} /** * @brief Construct complex number from real and imaginary part diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index 05cf448d4..bd68b8d36 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -69,7 +69,7 @@ template class DualQuaternion: public Dual> { /** * @brief Default constructor * - * @f[ + * Creates unit dual quaternion. @f[ * \hat q = [\boldsymbol 0, 1] + \epsilon [\boldsymbol 0, 0] * @f] * @todoc Remove workaround when Doxygen is predictable @@ -212,7 +212,7 @@ template class DualQuaternion: public Dual> { return Math::sqrt(lengthSquared()); } - /** @brief Normalized quaternion (of length 1) */ + /** @brief Normalized quaternion (of unit length) */ inline DualQuaternion normalized() const { return (*this)/length(); } diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 4e60a23bf..d93050281 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -116,8 +116,14 @@ template class Matrix3: public Matrix<3, T> { /** @copydoc Matrix::Matrix(ZeroType) */ inline constexpr explicit Matrix3(typename Matrix<3, T>::ZeroType): Matrix<3, T>(Matrix<3, T>::Zero) {} - /** @copydoc Matrix::Matrix(IdentityType, T) */ - /** @todo Use constexpr implementation in Matrix, when done */ + /** + * @brief Default constructor + * + * Creates identity matrix. You can also explicitly call this + * constructor with `Matrix3 m(Matrix3::Identity);`. Optional parameter + * @p value allows you to specify value on diagonal. + * @todo Use constexpr implementation in Matrix, when done + */ inline constexpr /*implicit*/ Matrix3(typename Matrix<3, T>::IdentityType = (Matrix<3, T>::Identity), T value = T(1)): Matrix<3, T>( Vector<3, T>(value, T(0), T(0)), Vector<3, T>( T(0), value, T(0)), diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index eb6e3fb8e..b77f5bbf6 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -249,8 +249,14 @@ template class Matrix4: public Matrix<4, T> { /** @copydoc Matrix::Matrix(ZeroType) */ inline constexpr explicit Matrix4(typename Matrix<4, T>::ZeroType): Matrix<4, T>(Matrix<4, T>::Zero) {} - /** @copydoc Matrix::Matrix(IdentityType, T) */ - /** @todo Use constexpr implementation in Matrix, when done */ + /** + * @brief Default constructor + * + * Creates identity matrix. You can also explicitly call this + * constructor with `Matrix4 m(Matrix4::Identity);`. Optional parameter + * @p value allows you to specify value on diagonal. + * @todo Use constexpr implementation in Matrix, when done + */ inline constexpr /*implicit*/ Matrix4(typename Matrix<4, T>::IdentityType = (Matrix<4, T>::Identity), T value = T(1)): Matrix<4, T>( Vector<4, T>(value, T(0), T(0), T(0)), Vector<4, T>( T(0), value, T(0), T(0)), diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 6eeb8d37a..1c11fea04 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -127,7 +127,7 @@ template class Quaternion { /** * @brief Default constructor * - * @f[ + * Creates unit quaternion. @f[ * q = [\boldsymbol 0, 1] * @f] */ @@ -356,7 +356,7 @@ template class Quaternion { return std::sqrt(dot()); } - /** @brief Normalized quaternion (of length 1) */ + /** @brief Normalized quaternion (of unit length) */ inline Quaternion normalized() const { return (*this)/length(); } diff --git a/src/Math/Test/ComplexTest.cpp b/src/Math/Test/ComplexTest.cpp index 9916ed582..d8ffeb85d 100644 --- a/src/Math/Test/ComplexTest.cpp +++ b/src/Math/Test/ComplexTest.cpp @@ -74,7 +74,8 @@ void ComplexTest::construct() { } void ComplexTest::constructDefault() { - CORRADE_COMPARE(Complex(), Complex(0.0f, 0.0f)); + CORRADE_COMPARE(Complex(), Complex(1.0f, 0.0f)); + CORRADE_COMPARE(Complex().length(), 1.0f); } void ComplexTest::compare() { @@ -87,7 +88,7 @@ void ComplexTest::compare() { void ComplexTest::constExpressions() { /* Default constructor */ constexpr Complex a; - CORRADE_COMPARE(a, Complex(0.0f, 0.0f)); + CORRADE_COMPARE(a, Complex(1.0f, 0.0f)); /* Value constructor */ constexpr Complex b(2.5f, -5.0f); diff --git a/src/Math/Test/DualQuaternionTest.cpp b/src/Math/Test/DualQuaternionTest.cpp index 771acf398..da954935f 100644 --- a/src/Math/Test/DualQuaternionTest.cpp +++ b/src/Math/Test/DualQuaternionTest.cpp @@ -92,6 +92,7 @@ void DualQuaternionTest::construct() { void DualQuaternionTest::constructDefault() { CORRADE_COMPARE(DualQuaternion(), DualQuaternion({{0.0f, 0.0f, 0.0f}, 1.0f}, {{0.0f, 0.0f, 0.0f}, 0.0f})); + CORRADE_COMPARE(DualQuaternion().length(), 1.0f); } void DualQuaternionTest::constructFromVector() { @@ -117,15 +118,11 @@ void DualQuaternionTest::constExpressions() { } void DualQuaternionTest::lengthSquared() { - CORRADE_COMPARE(DualQuaternion().lengthSquared(), 1.0f); - DualQuaternion a({{1.0f, 2.0f, 3.0f}, -4.0f}, {{0.5f, -3.0f, 3.0f}, 2.0f}); CORRADE_COMPARE(a.lengthSquared(), Dual(30.0f, -9.0f)); } void DualQuaternionTest::length() { - CORRADE_COMPARE(DualQuaternion().length(), 1.0f); - DualQuaternion a({{1.0f, 2.0f, 3.0f}, -4.0f}, {{0.5f, -3.0f, 3.0f}, 2.0f}); CORRADE_COMPARE(a.length(), Dual(5.477226f, -0.821584f)); } diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index e35d3ffc3..6b2e357ae 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -106,6 +106,7 @@ void QuaternionTest::construct() { void QuaternionTest::constructDefault() { CORRADE_COMPARE(Quaternion(), Quaternion({0.0f, 0.0f, 0.0f}, 1.0f)); + CORRADE_COMPARE(Quaternion().length(), 1.0f); } void QuaternionTest::constructFromVector() { diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 9d3f472fa..e07862b63 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -405,7 +405,7 @@ template class Vector { return std::sqrt(dot()); } - /** @brief Normalized vector (of length 1) */ + /** @brief Normalized vector (of unit length) */ inline Vector normalized() const { return *this/length(); }