Browse Source

Math: reverse scalar/quaternion multiplication and division operators.

Also updated related documentation in RectangularMatrix.
pull/7/head
Vladimír Vondruš 14 years ago
parent
commit
705bf3f597
  1. 21
      src/Math/Quaternion.h
  2. 10
      src/Math/RectangularMatrix.h
  3. 3
      src/Math/Test/MathQuaternionTest.cpp

21
src/Math/Quaternion.h

@ -257,6 +257,27 @@ template<class T> class Quaternion {
T _scalar; T _scalar;
}; };
/** @relates Quaternion
@brief Multiply scalar with quaternion
Same as Quaternion::operator*(T) const.
*/
template<class T> inline Quaternion<T> operator*(T scalar, const Quaternion<T>& quaternion) {
return quaternion*scalar;
}
/** @relates Quaternion
@brief Divide quaternion with number and invert
@f[
\frac a q = [\frac a {\boldsymbol q_V}, \frac a {q_S}]
@f]
@see Quaternion::operator/()
*/
template<class T> inline Quaternion<T> operator/(T scalar, const Quaternion<T>& quaternion) {
return {scalar/quaternion.vector(), scalar/quaternion.scalar()};
}
/** @debugoperator{Magnum::Math::Geometry::Rectangle} */ /** @debugoperator{Magnum::Math::Geometry::Rectangle} */
template<class T> Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Quaternion<T>& value) { template<class T> Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Quaternion<T>& value) {
debug << "Quaternion({"; debug << "Quaternion({";

10
src/Math/RectangularMatrix.h

@ -385,7 +385,7 @@ template<std::size_t cols, std::size_t rows, class T> class RectangularMatrix {
/** @relates RectangularMatrix /** @relates RectangularMatrix
@brief Multiply number with matrix @brief Multiply number with matrix
@see RectangularMatrix::operator*(U) const Same as RectangularMatrix::operator*(U) const.
*/ */
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
template<std::size_t cols, std::size_t rows, class T, class U> inline typename std::enable_if<std::is_arithmetic<U>::value, RectangularMatrix<cols, rows, T>>::type operator*(U number, const RectangularMatrix<cols, rows, T>& matrix) { template<std::size_t cols, std::size_t rows, class T, class U> inline typename std::enable_if<std::is_arithmetic<U>::value, RectangularMatrix<cols, rows, T>>::type operator*(U number, const RectangularMatrix<cols, rows, T>& matrix) {
@ -398,11 +398,9 @@ template<std::size_t cols, std::size_t rows, class T, class U> inline Rectangula
/** @relates RectangularMatrix /** @relates RectangularMatrix
@brief Divide matrix with number and invert @brief Divide matrix with number and invert
Example: @f[
@code \boldsymbol B_{ji} = \frac a {\boldsymbol A_{ji}}
RectangularMatrix<2, 3, float> mat(1.0f, 2.0f, -4.0f, 8.0f, -1.0f, 0.5f); @f]
RectangularMatrix<2, 3, float> another = 1.0f/mat; // {1.0f, 0.5f, -0.25f, 0.128f, -1.0f, 2.0f}
@endcode
@see RectangularMatrix::operator/() @see RectangularMatrix::operator/()
*/ */
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT

3
src/Math/Test/MathQuaternionTest.cpp

@ -76,7 +76,10 @@ void QuaternionTest::multiplyDivideScalar() {
Quaternion b({-1.5f, -4.5f, 3.0f}, 6.0f); Quaternion b({-1.5f, -4.5f, 3.0f}, 6.0f);
CORRADE_COMPARE(a*-1.5f, b); CORRADE_COMPARE(a*-1.5f, b);
CORRADE_COMPARE(-1.5f*a, b);
CORRADE_COMPARE(b/-1.5f, a); CORRADE_COMPARE(b/-1.5f, a);
CORRADE_COMPARE(2.0f/a, Quaternion({2.0f, 0.666666f, -1.0f}, -0.5f));
} }
void QuaternionTest::multiply() { void QuaternionTest::multiply() {

Loading…
Cancel
Save