Browse Source

Math: minor code cleanup.

pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
b0d79bbad8
  1. 4
      src/Math/DualQuaternion.h
  2. 4
      src/Math/Math.h
  3. 4
      src/Math/Test/CMakeLists.txt
  4. 1
      src/Math/Test/DualQuaternionTest.cpp
  5. 4
      src/Math/Test/QuaternionTest.cpp

4
src/Math/DualQuaternion.h

@ -239,7 +239,7 @@ template<class T> class DualQuaternion: public Dual<Quaternion<T>> {
* @see inverted() * @see inverted()
*/ */
inline DualQuaternion<T> invertedNormalized() const { inline DualQuaternion<T> invertedNormalized() const {
CORRADE_ASSERT(MathTypeTraits<T>::equals(lengthSquared(), T(1)), CORRADE_ASSERT(lengthSquared() == Dual<T>(1),
"Math::DualQuaternion::invertedNormalized(): dual quaternion must be normalized", {}); "Math::DualQuaternion::invertedNormalized(): dual quaternion must be normalized", {});
return quaternionConjugated(); return quaternionConjugated();
} }
@ -269,7 +269,7 @@ template<class T> class DualQuaternion: public Dual<Quaternion<T>> {
* Quaternion::transformVectorNormalized() * Quaternion::transformVectorNormalized()
*/ */
inline Vector3<T> transformPointNormalized(const Vector3<T>& vector) const { inline Vector3<T> transformPointNormalized(const Vector3<T>& vector) const {
CORRADE_ASSERT(MathTypeTraits<Dual<T>>::equals(lengthSquared(), Dual<T>(1)), CORRADE_ASSERT(lengthSquared() == Dual<T>(1),
"Math::DualQuaternion::transformPointNormalized(): dual quaternion must be normalized", "Math::DualQuaternion::transformPointNormalized(): dual quaternion must be normalized",
Vector3<T>(std::numeric_limits<T>::quiet_NaN())); Vector3<T>(std::numeric_limits<T>::quiet_NaN()));
return ((*this)*DualQuaternion<T>(vector)*conjugated()).dual().vector(); return ((*this)*DualQuaternion<T>(vector)*conjugated()).dual().vector();

4
src/Math/Math.h

@ -27,8 +27,8 @@ namespace Magnum { namespace Math {
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
/* Class Constants used only statically */ /* Class Constants used only statically */
template<class T> class Complex; template<class> class Complex;
template<class T> class Dual; template<class> class Dual;
template<class> class DualQuaternion; template<class> class DualQuaternion;
template<std::size_t, class> class Matrix; template<std::size_t, class> class Matrix;

4
src/Math/Test/CMakeLists.txt

@ -17,8 +17,8 @@ corrade_add_test(MathSwizzleTest SwizzleTest.cpp LIBRARIES MagnumMathTestLib)
corrade_add_test(MathUnitTest UnitTest.cpp) corrade_add_test(MathUnitTest UnitTest.cpp)
corrade_add_test(MathAngleTest AngleTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathAngleTest AngleTest.cpp LIBRARIES MagnumMathTestLib)
corrade_add_test(MathComplexTest ComplexTest.cpp LIBRARIES MagnumMathTestLib)
corrade_add_test(MathDualTest DualTest.cpp) corrade_add_test(MathDualTest DualTest.cpp)
corrade_add_test(MathComplexTest ComplexTest.cpp LIBRARIES MagnumMathTestLib)
corrade_add_test(MathQuaternionTest QuaternionTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathQuaternionTest QuaternionTest.cpp LIBRARIES MagnumMathTestLib)
corrade_add_test(MathDualQuaternionTest DualQuaternionTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathDualQuaternionTest DualQuaternionTest.cpp LIBRARIES MagnumMathTestLib)
@ -27,6 +27,6 @@ set_target_properties(
MathMatrix3Test MathMatrix3Test
MathMatrix4Test MathMatrix4Test
MathComplexTest MathComplexTest
MathDualQuaternionTest
MathQuaternionTest MathQuaternionTest
MathDualQuaternionTest
PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT)

1
src/Math/Test/DualQuaternionTest.cpp

@ -56,7 +56,6 @@ typedef Math::Matrix4<float> Matrix4;
typedef Math::DualQuaternion<float> DualQuaternion; typedef Math::DualQuaternion<float> DualQuaternion;
typedef Math::Quaternion<float> Quaternion; typedef Math::Quaternion<float> Quaternion;
typedef Math::Vector3<float> Vector3; typedef Math::Vector3<float> Vector3;
typedef Math::Vector4<float> Vector4;
DualQuaternionTest::DualQuaternionTest() { DualQuaternionTest::DualQuaternionTest() {
addTests(&DualQuaternionTest::construct, addTests(&DualQuaternionTest::construct,

4
src/Math/Test/QuaternionTest.cpp

@ -212,7 +212,7 @@ void QuaternionTest::invertedNormalized() {
Quaternion a = Quaternion({1.0f, 3.0f, -2.0f}, -4.0f); Quaternion a = Quaternion({1.0f, 3.0f, -2.0f}, -4.0f);
std::ostringstream o; std::ostringstream o;
Corrade::Utility::Error::setOutput(&o); Error::setOutput(&o);
Quaternion notInverted = a.invertedNormalized(); Quaternion notInverted = a.invertedNormalized();
CORRADE_COMPARE(notInverted.vector(), Vector3()); CORRADE_COMPARE(notInverted.vector(), Vector3());
CORRADE_COMPARE(notInverted.scalar(), std::numeric_limits<float>::quiet_NaN()); CORRADE_COMPARE(notInverted.scalar(), std::numeric_limits<float>::quiet_NaN());
@ -221,7 +221,7 @@ void QuaternionTest::invertedNormalized() {
Quaternion aNormalized = a.normalized(); Quaternion aNormalized = a.normalized();
Quaternion inverted = aNormalized.invertedNormalized(); Quaternion inverted = aNormalized.invertedNormalized();
CORRADE_COMPARE(aNormalized*inverted, Quaternion()); CORRADE_COMPARE(aNormalized*inverted, Quaternion());
CORRADE_COMPARE(inverted*aNormalized.normalized(), Quaternion()); CORRADE_COMPARE(inverted*aNormalized, Quaternion());
CORRADE_COMPARE(inverted, Quaternion({-1.0f, -3.0f, 2.0f}, -4.0f)/std::sqrt(30.0f)); CORRADE_COMPARE(inverted, Quaternion({-1.0f, -3.0f, 2.0f}, -4.0f)/std::sqrt(30.0f));
} }

Loading…
Cancel
Save