Browse Source

Math: converting DualComplex to matrix.

pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
268c07acc5
  1. 2
      src/Math/Complex.h
  2. 10
      src/Math/DualComplex.h
  3. 10
      src/Math/Test/DualComplexTest.cpp

2
src/Math/Complex.h

@ -155,7 +155,7 @@ template<class T> class Complex {
* b & a
* \end{pmatrix}
* @f]
* @see Matrix3::from(const Matrix<2, T>&, const Vector2<T>&)
* @see DualComplex::matrix(), Matrix3::from(const Matrix<2, T>&, const Vector2<T>&)
*/
Matrix<2, T> matrix() const {
return {Vector<2, T>(_real, _imaginary),

10
src/Math/DualComplex.h

@ -21,6 +21,7 @@
#include "Math/Dual.h"
#include "Math/Complex.h"
#include "Math/Matrix3.h"
namespace Magnum { namespace Math {
@ -126,6 +127,15 @@ template<class T> class DualComplex: public Dual<Complex<T>> {
return Vector2<T>(this->dual());
}
/**
* @brief Convert dual complex number to transformation matrix
*
* @see Complex::matrix()
*/
inline Matrix3<T> matrix() const {
return Matrix3<T>::from(this->real().matrix(), translation());
}
/**
* @brief Multipy with dual complex number
*

10
src/Math/Test/DualComplexTest.cpp

@ -46,6 +46,7 @@ class DualComplexTest: public Corrade::TestSuite::Tester {
void rotation();
void translation();
void combinedTransformParts();
void matrix();
void debug();
};
@ -55,6 +56,7 @@ typedef Math::Rad<float> Rad;
typedef Math::Complex<float> Complex;
typedef Math::Dual<float> Dual;
typedef Math::DualComplex<float> DualComplex;
typedef Math::Matrix3<float> Matrix3;
typedef Math::Vector2<float> Vector2;
DualComplexTest::DualComplexTest() {
@ -79,6 +81,7 @@ DualComplexTest::DualComplexTest() {
&DualComplexTest::rotation,
&DualComplexTest::translation,
&DualComplexTest::combinedTransformParts,
&DualComplexTest::matrix,
&DualComplexTest::debug);
}
@ -206,6 +209,13 @@ void DualComplexTest::combinedTransformParts() {
CORRADE_COMPARE(b.translation(), Complex::rotation(Deg(23.0f)).transformVector(translation));
}
void DualComplexTest::matrix() {
DualComplex a = DualComplex::rotation(Deg(23.0f))*DualComplex::translation({2.0f, 3.0f});
Matrix3 m = Matrix3::rotation(Deg(23.0f))*Matrix3::translation({2.0f, 3.0f});
CORRADE_COMPARE(a.matrix(), m);
}
void DualComplexTest::debug() {
std::ostringstream o;

Loading…
Cancel
Save