From 6f4f12d1eda685f03a2e4b54b479813d134248cf Mon Sep 17 00:00:00 2001 From: Tal Hadad Date: Mon, 17 Oct 2016 22:23:47 +0300 Subject: Add isApprox() and cast() functions. test cases included --- unsupported/test/EulerAngles.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'unsupported/test/EulerAngles.cpp') diff --git a/unsupported/test/EulerAngles.cpp b/unsupported/test/EulerAngles.cpp index 3f4523ccc..149cf7f94 100644 --- a/unsupported/test/EulerAngles.cpp +++ b/unsupported/test/EulerAngles.cpp @@ -13,6 +13,13 @@ using namespace Eigen; +// Unfortunately, we need to specialize it in order to work. (We could add it in main.h test framework) +template +bool verifyIsApprox(const Eigen::EulerAngles& a, const Eigen::EulerAngles& b) +{ + return verifyIsApprox(a.angles(), b.angles()); +} + // Verify that x is in the approxed range [a, b] #define VERIFY_APPROXED_RANGE(a, x, b) \ do { \ @@ -24,7 +31,7 @@ const char X = EULER_X; const char Y = EULER_Y; const char Z = EULER_Z; -template +template void verify_euler(const EulerAngles& e) { typedef EulerAngles EulerAnglesType; @@ -68,6 +75,11 @@ void verify_euler(const EulerAngles& e) const Vector3 I = EulerAnglesType::AlphaAxisVector(); const Vector3 J = EulerAnglesType::BetaAxisVector(); const Vector3 K = EulerAnglesType::GammaAxisVector(); + + // Is approx checks + VERIFY(e.isApprox(e)); + VERIFY_IS_APPROX(e, e); + VERIFY_IS_NOT_APPROX(e, EulerAnglesType(e.alpha() + ONE, e.beta() + ONE, e.gamma() + ONE)); const Matrix3 m(e); VERIFY_IS_APPROX(Scalar(m.determinant()), ONE); @@ -108,6 +120,11 @@ void verify_euler(const EulerAngles& e) const QuaternionType qbis(AngleAxisType(eabis[0], I) * AngleAxisType(eabis[1], J) * AngleAxisType(eabis[2], K)); VERIFY(internal::isApprox(std::abs(q.dot(qbis)), ONE, precision)); //VERIFY_IS_APPROX(eabis, eabis2);// Verify that the euler angles are still the same + + // A suggestion for simple product test when will be supported. + /*EulerAnglesType e2(PI/2, PI/2, PI/2); + Matrix3 m2(e2); + VERIFY_IS_APPROX(e*e2, m*m2);*/ } template @@ -250,6 +267,11 @@ template void eulerangles_rand() void test_EulerAngles() { + // Simple cast test + EulerAnglesXYZd onesEd(1, 1, 1); + EulerAnglesXYZf onesEf = onesEd.cast(); + VERIFY_IS_APPROX(onesEd, onesEf.cast()); + CALL_SUBTEST_1( eulerangles_manual() ); CALL_SUBTEST_2( eulerangles_manual() ); -- cgit v1.2.3