GCC Code Coverage Report


Directory: ./
File: unittest/rotation.cpp
Date: 2024-08-27 18:20:05
Exec Total Coverage
Lines: 0 26 0.0%
Branches: 0 246 0.0%

Line Branch Exec Source
1 //
2 // Copyright (c) 2019-2020 INRIA
3 //
4
5 #include <iostream>
6
7 #include <pinocchio/math/rotation.hpp>
8 #include <pinocchio/math/sincos.hpp>
9 #include <Eigen/Geometry>
10
11 #include <boost/variant.hpp> // to avoid C99 warnings
12
13 #include <boost/test/unit_test.hpp>
14 #include <boost/utility/binary.hpp>
15
16 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
17
18 BOOST_AUTO_TEST_CASE(test_toRotationMatrix)
19 {
20 using namespace pinocchio;
21 #ifndef NDEBUG
22 const int max_tests = 1e5;
23 #else
24 const int max_tests = 1e2;
25 #endif
26 for (int k = 0; k < max_tests; ++k)
27 {
28 const double theta = std::rand();
29 double cos_value, sin_value;
30
31 pinocchio::SINCOS(theta, &sin_value, &cos_value);
32 const Eigen::Vector3d axis(Eigen::Vector3d::Random().normalized());
33
34 Eigen::Matrix3d rot;
35 toRotationMatrix(axis, cos_value, sin_value, rot);
36 Eigen::Matrix3d rot2;
37 toRotationMatrix(axis, theta, rot2);
38
39 const Eigen::Matrix3d rot_ref = Eigen::AngleAxisd(theta, axis).toRotationMatrix();
40
41 BOOST_CHECK(rot.isApprox(rot_ref));
42 BOOST_CHECK(rot2.isApprox(rot_ref));
43 }
44 }
45
46 BOOST_AUTO_TEST_CASE(test_orthogonal_projection)
47 {
48 using namespace pinocchio;
49 #ifndef NDEBUG
50 const int max_tests = 1e5;
51 #else
52 const int max_tests = 1e2;
53 #endif
54
55 typedef Eigen::Vector4d Vector4;
56 typedef Eigen::Quaterniond Quaternion;
57 typedef Eigen::Matrix3d Matrix3;
58
59 for (int k = 0; k < max_tests; ++k)
60 {
61 const Vector4 vec4 = Vector4::Random();
62 const Quaternion quat(vec4.normalized());
63
64 const Matrix3 rot = quat.toRotationMatrix();
65
66 Matrix3 rot_proj = orthogonalProjection(rot);
67 BOOST_CHECK(rot.isApprox(rot_proj));
68 }
69
70 for (int k = 0; k < max_tests; ++k)
71 {
72 const Matrix3 mat = Matrix3::Random();
73
74 Matrix3 rot_proj = orthogonalProjection(mat);
75 BOOST_CHECK((rot_proj.transpose() * rot_proj).isIdentity());
76 BOOST_CHECK(fabs(rot_proj.determinant() - 1.) <= Eigen::NumTraits<double>::dummy_precision());
77 }
78 }
79
80 BOOST_AUTO_TEST_SUITE_END()
81