aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2013-01-20 10:21:54 +0100
committerGravatar Gael Guennebaud <g.gael@free.fr>2013-01-20 10:21:54 +0100
commit392ffce3b92302007b1b6769d08ff4896b489ffe (patch)
tree87a1675dc1faed0953d4a55755083b1c792ca68a /test
parentfb89b662290857ab2133613cd9a84cc532720da4 (diff)
Fix traits of Map<Quaternion>, and respectively extend the unit tests
Diffstat (limited to 'test')
-rw-r--r--test/geo_quaternion.cpp42
1 files changed, 36 insertions, 6 deletions
diff --git a/test/geo_quaternion.cpp b/test/geo_quaternion.cpp
index c3fceafdf..568a5f582 100644
--- a/test/geo_quaternion.cpp
+++ b/test/geo_quaternion.cpp
@@ -172,23 +172,36 @@ template<typename Scalar, int Options> void quaternion(void)
template<typename Scalar> void mapQuaternion(void){
typedef Map<Quaternion<Scalar>, Aligned> MQuaternionA;
+ typedef Map<const Quaternion<Scalar>, Aligned> MCQuaternionA;
typedef Map<Quaternion<Scalar> > MQuaternionUA;
typedef Map<const Quaternion<Scalar> > MCQuaternionUA;
typedef Quaternion<Scalar> Quaternionx;
+ typedef Matrix<Scalar,3,1> Vector3;
+ typedef AngleAxis<Scalar> AngleAxisx;
+
+ Vector3 v0 = Vector3::Random(),
+ v1 = Vector3::Random();
+ Scalar a = internal::random<Scalar>(-Scalar(M_PI), Scalar(M_PI));
EIGEN_ALIGN16 Scalar array1[4];
EIGEN_ALIGN16 Scalar array2[4];
EIGEN_ALIGN16 Scalar array3[4+1];
Scalar* array3unaligned = array3+1;
+
+ MQuaternionA mq1(array1);
+ MCQuaternionA mcq1(array1);
+ MQuaternionA mq2(array2);
+ MQuaternionUA mq3(array3unaligned);
+ MCQuaternionUA mcq3(array3unaligned);
// std::cerr << array1 << " " << array2 << " " << array3 << "\n";
- MQuaternionA(array1).coeffs().setRandom();
- (MQuaternionA(array2)) = MQuaternionA(array1);
- (MQuaternionUA(array3unaligned)) = MQuaternionA(array1);
+ mq1 = AngleAxisx(a, v0.normalized());
+ mq2 = mq1;
+ mq3 = mq1;
- Quaternionx q1 = MQuaternionA(array1);
- Quaternionx q2 = MQuaternionA(array2);
- Quaternionx q3 = MQuaternionUA(array3unaligned);
+ Quaternionx q1 = mq1;
+ Quaternionx q2 = mq2;
+ Quaternionx q3 = mq3;
Quaternionx q4 = MCQuaternionUA(array3unaligned);
VERIFY_IS_APPROX(q1.coeffs(), q2.coeffs());
@@ -198,6 +211,23 @@ template<typename Scalar> void mapQuaternion(void){
if(internal::packet_traits<Scalar>::Vectorizable)
VERIFY_RAISES_ASSERT((MQuaternionA(array3unaligned)));
#endif
+
+ VERIFY_IS_APPROX(mq1 * (mq1.inverse() * v1), v1);
+ VERIFY_IS_APPROX(mq1 * (mq1.conjugate() * v1), v1);
+
+ VERIFY_IS_APPROX(mcq1 * (mcq1.inverse() * v1), v1);
+ VERIFY_IS_APPROX(mcq1 * (mcq1.conjugate() * v1), v1);
+
+ VERIFY_IS_APPROX(mq3 * (mq3.inverse() * v1), v1);
+ VERIFY_IS_APPROX(mq3 * (mq3.conjugate() * v1), v1);
+
+ VERIFY_IS_APPROX(mcq3 * (mcq3.inverse() * v1), v1);
+ VERIFY_IS_APPROX(mcq3 * (mcq3.conjugate() * v1), v1);
+
+ VERIFY_IS_APPROX(mq1*mq2, q1*q2);
+ VERIFY_IS_APPROX(mq3*mq2, q3*q2);
+ VERIFY_IS_APPROX(mcq1*mq2, q1*q2);
+ VERIFY_IS_APPROX(mcq3*mq2, q3*q2);
}
template<typename Scalar> void quaternionAlignment(void){