Browse Source

Math: avoid copypaste code in DualComplex.

Ugh this class is ugly (but works!).
pull/114/merge
Vladimír Vondruš 11 years ago
parent
commit
d3f528093e
  1. 4
      src/Magnum/Math/Dual.h
  2. 24
      src/Magnum/Math/DualComplex.h
  3. 1
      src/Magnum/Math/DualQuaternion.h
  4. 1
      src/Magnum/Math/Test/DualTest.cpp

4
src/Magnum/Math/Dual.h

@ -201,7 +201,9 @@ template<class T> class Dual {
} \
Type<T> operator-(const Math::Dual<Underlying<T>>& other) const { \
return Math::Dual<Underlying<T>>::operator-(other); \
} \
}
/* DualComplex needs its own special implementation of multiplication/division */
#define MAGNUM_DUAL_SUBCLASS_MULTIPLICATION_IMPLEMENTATION(Type, Underlying) \
template<class U> Type<T> operator*(const Math::Dual<U>& other) const { \
return Math::Dual<Underlying<T>>::operator*(other); \
} \

24
src/Magnum/Math/DualComplex.h

@ -339,27 +339,9 @@ template<class T> class DualComplex: public Dual<Complex<T>> {
return Vector2<T>(((*this)*DualComplex<T>(vector)).dual());
}
/* Verbatim copy of DUAL_SUBCLASS_IMPLEMENTATION(), as we need to hide
Dual's operator*() and operator/() */
#ifndef DOXYGEN_GENERATING_OUTPUT
DualComplex<T> operator-() const {
return Dual<Complex<T>>::operator-();
}
DualComplex<T>& operator+=(const Dual<Complex<T>>& other) {
Dual<Complex<T>>::operator+=(other);
return *this;
}
DualComplex<T> operator+(const Dual<Complex<T>>& other) const {
return Dual<Complex<T>>::operator+(other);
}
DualComplex<T>& operator-=(const Dual<Complex<T>>& other) {
Dual<Complex<T>>::operator-=(other);
return *this;
}
DualComplex<T> operator-(const Dual<Complex<T>>& other) const {
return Dual<Complex<T>>::operator-(other);
}
#endif
MAGNUM_DUAL_SUBCLASS_IMPLEMENTATION(DualComplex, Vector2)
/* Not using MAGNUM_DUAL_SUBCLASS_MULTIPLICATION_IMPLEMENTATION(), as
we have special multiplication/division implementation */
private:
/* Just to be sure nobody uses this, as it wouldn't probably work with

1
src/Magnum/Math/DualQuaternion.h

@ -355,6 +355,7 @@ template<class T> class DualQuaternion: public Dual<Quaternion<T>> {
}
MAGNUM_DUAL_SUBCLASS_IMPLEMENTATION(DualQuaternion, Quaternion)
MAGNUM_DUAL_SUBCLASS_MULTIPLICATION_IMPLEMENTATION(DualQuaternion, Quaternion)
};
/** @debugoperator{Magnum::Math::DualQuaternion} */

1
src/Magnum/Math/Test/DualTest.cpp

@ -171,6 +171,7 @@ template<class T> class BasicDualVec2: public Math::Dual<Math::Vector2<T>> {
template<class ...U> constexpr BasicDualVec2(U&&... args): Math::Dual<Math::Vector2<T>>(args...) {}
MAGNUM_DUAL_SUBCLASS_IMPLEMENTATION(BasicDualVec2, Math::Vector2)
MAGNUM_DUAL_SUBCLASS_MULTIPLICATION_IMPLEMENTATION(BasicDualVec2, Math::Vector2)
};
typedef BasicDualVec2<Float> DualVec2;

Loading…
Cancel
Save