]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/qvm/test/rot_quat_test.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / qvm / test / rot_quat_test.cpp
1 //Copyright (c) 2008-2016 Emil Dotchevski and Reverge Studios, Inc.
2
3 //Distributed under the Boost Software License, Version 1.0. (See accompanying
4 //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 #include <boost/qvm/quat_operations.hpp>
7 #include <boost/qvm/mat_operations.hpp>
8 #include "test_qvm_matrix.hpp"
9 #include "test_qvm_quaternion.hpp"
10 #include "test_qvm_vector.hpp"
11 #include "gold.hpp"
12
13 namespace
14 {
15 void
16 test_x()
17 {
18 using namespace boost::qvm;
19 test_qvm::vector<V1,3> axis; axis.a[0]=1;
20 for( float r=0; r<6.28f; r+=0.5f )
21 {
22 test_qvm::quaternion<Q1> q1=rot_quat(axis,r);
23 test_qvm::matrix<M1,3,3> x1=convert_to< test_qvm::matrix<M1,3,3> >(q1);
24 test_qvm::rotation_x(x1.b,r);
25 BOOST_QVM_TEST_CLOSE(x1.a,x1.b,0.000001f);
26 test_qvm::quaternion<Q2> q2(42,1);
27 set_rot(q2,axis,r);
28 test_qvm::matrix<M2,3,3> x2=convert_to< test_qvm::matrix<M2,3,3> >(q2);
29 test_qvm::rotation_x(x2.b,r);
30 BOOST_QVM_TEST_CLOSE(x2.a,x2.b,0.000001f);
31 test_qvm::quaternion<Q1> q3(42,1);
32 test_qvm::quaternion<Q1> q4(42,1);
33 rotate(q3,axis,r);
34 q3 = q3*q1;
35 BOOST_QVM_TEST_EQ(q3.a,q3.a);
36 }
37 }
38
39 void
40 test_y()
41 {
42 using namespace boost::qvm;
43 test_qvm::vector<V1,3> axis; axis.a[1]=1;
44 for( float r=0; r<6.28f; r+=0.5f )
45 {
46 test_qvm::quaternion<Q1> q1=rot_quat(axis,r);
47 test_qvm::matrix<M1,3,3> x1=convert_to< test_qvm::matrix<M1,3,3> >(q1);
48 test_qvm::rotation_y(x1.b,r);
49 BOOST_QVM_TEST_CLOSE(x1.a,x1.b,0.000001f);
50 test_qvm::quaternion<Q2> q2(42,1);
51 set_rot(q2,axis,r);
52 test_qvm::matrix<M2,3,3> x2=convert_to< test_qvm::matrix<M2,3,3> >(q2);
53 test_qvm::rotation_y(x2.b,r);
54 BOOST_QVM_TEST_CLOSE(x2.a,x2.b,0.000001f);
55 test_qvm::quaternion<Q1> q3(42,1);
56 test_qvm::quaternion<Q1> q4(42,1);
57 rotate(q3,axis,r);
58 q3 = q3*q1;
59 BOOST_QVM_TEST_EQ(q3.a,q3.a);
60 }
61 }
62
63 void
64 test_z()
65 {
66 using namespace boost::qvm;
67 test_qvm::vector<V1,3> axis; axis.a[2]=1;
68 for( float r=0; r<6.28f; r+=0.5f )
69 {
70 test_qvm::quaternion<Q1> q1=rot_quat(axis,r);
71 test_qvm::matrix<M1,3,3> x1=convert_to< test_qvm::matrix<M1,3,3> >(q1);
72 test_qvm::rotation_z(x1.b,r);
73 BOOST_QVM_TEST_CLOSE(x1.a,x1.b,0.000001f);
74 test_qvm::quaternion<Q2> q2(42,1);
75 set_rot(q2,axis,r);
76 test_qvm::matrix<M2,3,3> x2=convert_to< test_qvm::matrix<M2,3,3> >(q2);
77 test_qvm::rotation_z(x2.b,r);
78 BOOST_QVM_TEST_CLOSE(x2.a,x2.b,0.000001f);
79 test_qvm::quaternion<Q1> q3(42,1);
80 test_qvm::quaternion<Q1> q4(42,1);
81 rotate(q3,axis,r);
82 q3 = q3*q1;
83 BOOST_QVM_TEST_EQ(q3.a,q3.a);
84 }
85 }
86 }
87
88 int
89 main()
90 {
91 test_x();
92 test_y();
93 test_z();
94 return boost::report_errors();
95 }