diff --git a/src/Math/DualComplex.h b/src/Math/DualComplex.h index 4cc1deea2..c150f378d 100644 --- a/src/Math/DualComplex.h +++ b/src/Math/DualComplex.h @@ -88,6 +88,20 @@ template class DualComplex: public Dual> { */ inline constexpr /*implicit*/ DualComplex(const Complex& real, const Complex& dual): Dual>(real, dual) {} + /** + * @brief Construct dual complex number from vector + * + * To be used in transformations later. @f[ + * \hat c = (0 + i1) + \epsilon(v_x + iv_y) + * @f] + * @todoc Remove workaround when Doxygen is predictable + */ + #ifdef DOXYGEN_GENERATING_OUTPUT + inline constexpr explicit DualComplex(const Vector2& vector); + #else + inline constexpr explicit DualComplex(const Vector2& vector): Dual>({}, Complex(vector)) {} + #endif + /** * @brief Rotation angle of dual complex number * diff --git a/src/Math/Test/DualComplexTest.cpp b/src/Math/Test/DualComplexTest.cpp index 2a37f25c1..4922e4ecb 100644 --- a/src/Math/Test/DualComplexTest.cpp +++ b/src/Math/Test/DualComplexTest.cpp @@ -27,6 +27,7 @@ class DualComplexTest: public Corrade::TestSuite::Tester { void construct(); void constructDefault(); + void constructFromVector(); void constExpressions(); @@ -59,6 +60,7 @@ typedef Math::Vector2 Vector2; DualComplexTest::DualComplexTest() { addTests(&DualComplexTest::construct, &DualComplexTest::constructDefault, + &DualComplexTest::constructFromVector, &DualComplexTest::constExpressions, @@ -92,6 +94,10 @@ void DualComplexTest::constructDefault() { CORRADE_COMPARE(DualComplex().length(), 1.0f); } +void DualComplexTest::constructFromVector() { + CORRADE_COMPARE(DualComplex(Vector2(1.5f, -3.0f)), DualComplex({1.0f, 0.0f}, {1.5f, -3.0f})); +} + void DualComplexTest::constExpressions() { /* Default constructor */ constexpr DualComplex a; @@ -101,6 +107,10 @@ void DualComplexTest::constExpressions() { constexpr DualComplex b({-1.0f, 2.5f}, {3.0f, -7.5f}); CORRADE_COMPARE(b, DualComplex({-1.0f, 2.5f}, {3.0f, -7.5f})); + /* Vector constructor */ + constexpr DualComplex c(Vector2(-3.0f, 7.5f)); + CORRADE_COMPARE(c, DualComplex({}, {-3.0f, 7.5f})); + /* Copy constructor */ constexpr DualComplex d(b); CORRADE_COMPARE(d, DualComplex({-1.0f, 2.5f}, {3.0f, -7.5f}));