diff --git a/src/Magnum/Math/Dual.h b/src/Magnum/Math/Dual.h index 3979af08b..b39472901 100644 --- a/src/Magnum/Math/Dual.h +++ b/src/Magnum/Math/Dual.h @@ -201,7 +201,9 @@ template class Dual { } \ Type operator-(const Math::Dual>& other) const { \ return Math::Dual>::operator-(other); \ - } \ + } +/* DualComplex needs its own special implementation of multiplication/division */ +#define MAGNUM_DUAL_SUBCLASS_MULTIPLICATION_IMPLEMENTATION(Type, Underlying) \ template Type operator*(const Math::Dual& other) const { \ return Math::Dual>::operator*(other); \ } \ diff --git a/src/Magnum/Math/DualComplex.h b/src/Magnum/Math/DualComplex.h index d9d2ac98e..f8927caac 100644 --- a/src/Magnum/Math/DualComplex.h +++ b/src/Magnum/Math/DualComplex.h @@ -339,27 +339,9 @@ template class DualComplex: public Dual> { return Vector2(((*this)*DualComplex(vector)).dual()); } - /* Verbatim copy of DUAL_SUBCLASS_IMPLEMENTATION(), as we need to hide - Dual's operator*() and operator/() */ - #ifndef DOXYGEN_GENERATING_OUTPUT - DualComplex operator-() const { - return Dual>::operator-(); - } - DualComplex& operator+=(const Dual>& other) { - Dual>::operator+=(other); - return *this; - } - DualComplex operator+(const Dual>& other) const { - return Dual>::operator+(other); - } - DualComplex& operator-=(const Dual>& other) { - Dual>::operator-=(other); - return *this; - } - DualComplex operator-(const Dual>& other) const { - return Dual>::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 diff --git a/src/Magnum/Math/DualQuaternion.h b/src/Magnum/Math/DualQuaternion.h index 154afb96f..8d0c6d412 100644 --- a/src/Magnum/Math/DualQuaternion.h +++ b/src/Magnum/Math/DualQuaternion.h @@ -355,6 +355,7 @@ template class DualQuaternion: public Dual> { } MAGNUM_DUAL_SUBCLASS_IMPLEMENTATION(DualQuaternion, Quaternion) + MAGNUM_DUAL_SUBCLASS_MULTIPLICATION_IMPLEMENTATION(DualQuaternion, Quaternion) }; /** @debugoperator{Magnum::Math::DualQuaternion} */ diff --git a/src/Magnum/Math/Test/DualTest.cpp b/src/Magnum/Math/Test/DualTest.cpp index 071fd7ce8..4ff641ad9 100644 --- a/src/Magnum/Math/Test/DualTest.cpp +++ b/src/Magnum/Math/Test/DualTest.cpp @@ -171,6 +171,7 @@ template class BasicDualVec2: public Math::Dual> { template constexpr BasicDualVec2(U&&... args): Math::Dual>(args...) {} MAGNUM_DUAL_SUBCLASS_IMPLEMENTATION(BasicDualVec2, Math::Vector2) + MAGNUM_DUAL_SUBCLASS_MULTIPLICATION_IMPLEMENTATION(BasicDualVec2, Math::Vector2) }; typedef BasicDualVec2 DualVec2;