Browse Source

Math: function for negating Quaternion, improved tests.

pull/7/head
Vladimír Vondruš 14 years ago
parent
commit
b55f3a2071
  1. 11
      src/Math/Quaternion.h
  2. 2
      src/Math/RectangularMatrix.h
  3. 9
      src/Math/Test/MathQuaternionTest.cpp

11
src/Math/Quaternion.h

@ -112,6 +112,17 @@ template<class T> class Quaternion {
};
}
/**
* @brief Negated quaternion
*
* @f[
* -q = [-\boldsymbol q_V, -q_S]
* @f]
*/
inline Quaternion<T> operator-() const {
return {-_vector, -_scalar};
}
/**
* @brief Multiply with scalar and assign
*

2
src/Math/RectangularMatrix.h

@ -221,7 +221,7 @@ template<std::size_t cols, std::size_t rows, class T> class RectangularMatrix {
return *this;
}
/** @brief Negative matrix */
/** @brief Negated matrix */
RectangularMatrix<cols, rows, T> operator-() const {
RectangularMatrix<cols, rows, T> out;

9
src/Math/Test/MathQuaternionTest.cpp

@ -27,6 +27,7 @@ class QuaternionTest: public Corrade::TestSuite::Tester {
explicit QuaternionTest();
void construct();
void negated();
void multiplyDivideScalar();
void multiply();
void length();
@ -45,6 +46,7 @@ typedef Math::Vector3<float> Vector3;
QuaternionTest::QuaternionTest() {
addTests(&QuaternionTest::construct,
&QuaternionTest::negated,
&QuaternionTest::multiplyDivideScalar,
&QuaternionTest::multiply,
&QuaternionTest::length,
@ -65,6 +67,10 @@ void QuaternionTest::construct() {
CORRADE_COMPARE(Quaternion(), Quaternion({0.0f, 0.0f, 0.0f}, {1.0f}));
}
void QuaternionTest::negated() {
CORRADE_COMPARE(-Quaternion({1.0f, 2.0f, -3.0f}, -4.0f), Quaternion({-1.0f, -2.0f, 3.0f}, 4.0f));
}
void QuaternionTest::multiplyDivideScalar() {
Quaternion a({1.0f, 3.0f, -2.0f}, -4.0f);
Quaternion b({-1.5f, -4.5f, 3.0f}, 6.0f);
@ -141,6 +147,9 @@ void QuaternionTest::matrix() {
Quaternion q = Quaternion::fromRotation(angle, axis);
Matrix<3, float> expected = Matrix4<float>::rotation(angle, axis).rotationScaling();
CORRADE_COMPARE(q.matrix(), expected);
/* Verify that negated quaternion gives the same rotation */
CORRADE_COMPARE((-q).matrix(), expected);
}
void QuaternionTest::debug() {

Loading…
Cancel
Save