Browse Source

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.
pull/7/head
Vladimír Vondruš 13 years ago
parent
commit
728b9a3f2e
  1. 6
      src/Math/Complex.h
  2. 4
      src/Math/DualQuaternion.h
  3. 10
      src/Math/Matrix3.h
  4. 10
      src/Math/Matrix4.h
  5. 4
      src/Math/Quaternion.h
  6. 5
      src/Math/Test/ComplexTest.cpp
  7. 5
      src/Math/Test/DualQuaternionTest.cpp
  8. 1
      src/Math/Test/QuaternionTest.cpp
  9. 2
      src/Math/Vector.h

6
src/Math/Complex.h

@ -52,11 +52,11 @@ template<class T> 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

4
src/Math/DualQuaternion.h

@ -69,7 +69,7 @@ template<class T> class DualQuaternion: public Dual<Quaternion<T>> {
/**
* @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 T> class DualQuaternion: public Dual<Quaternion<T>> {
return Math::sqrt(lengthSquared());
}
/** @brief Normalized quaternion (of length 1) */
/** @brief Normalized quaternion (of unit length) */
inline DualQuaternion<T> normalized() const {
return (*this)/length();
}

10
src/Math/Matrix3.h

@ -116,8 +116,14 @@ template<class T> 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)),

10
src/Math/Matrix4.h

@ -249,8 +249,14 @@ template<class T> 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)),

4
src/Math/Quaternion.h

@ -127,7 +127,7 @@ template<class T> class Quaternion {
/**
* @brief Default constructor
*
* @f[
* Creates unit quaternion. @f[
* q = [\boldsymbol 0, 1]
* @f]
*/
@ -356,7 +356,7 @@ template<class T> class Quaternion {
return std::sqrt(dot());
}
/** @brief Normalized quaternion (of length 1) */
/** @brief Normalized quaternion (of unit length) */
inline Quaternion<T> normalized() const {
return (*this)/length();
}

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

5
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));
}

1
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() {

2
src/Math/Vector.h

@ -405,7 +405,7 @@ template<std::size_t size, class T> class Vector {
return std::sqrt(dot());
}
/** @brief Normalized vector (of length 1) */
/** @brief Normalized vector (of unit length) */
inline Vector<size, T> normalized() const {
return *this/length();
}

Loading…
Cancel
Save