Browse Source

Math: creating DualComplex from Vector2.

pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
8e562316e8
  1. 14
      src/Math/DualComplex.h
  2. 10
      src/Math/Test/DualComplexTest.cpp

14
src/Math/DualComplex.h

@ -88,6 +88,20 @@ template<class T> class DualComplex: public Dual<Complex<T>> {
*/
inline constexpr /*implicit*/ DualComplex(const Complex<T>& real, const Complex<T>& dual): Dual<Complex<T>>(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<T>& vector);
#else
inline constexpr explicit DualComplex(const Vector2<T>& vector): Dual<Complex<T>>({}, Complex<T>(vector)) {}
#endif
/**
* @brief Rotation angle of dual complex number
*

10
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<float> 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}));

Loading…
Cancel
Save