]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/qvm/test/rot_mat_test.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / qvm / test / rot_mat_test.cpp
CommitLineData
92f5a8d4
TL
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/mat_operations.hpp>
7#include <boost/qvm/mat.hpp>
8#include "test_qvm_matrix.hpp"
9#include "test_qvm_vector.hpp"
10#include "gold.hpp"
11
12namespace
13 {
14 template <int D>
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::matrix<M1,D,D> const m1=rot_mat<D>(axis,r);
23 test_qvm::rotation_x(m1.b,r);
24 BOOST_QVM_TEST_EQ(m1.a,m1.b);
25 test_qvm::matrix<M1,D,D> m2(42,1);
26 set_rot(m2,axis,r);
27 test_qvm::rotation_x(m2.b,r);
28 BOOST_QVM_TEST_EQ(m2.a,m2.b);
29 test_qvm::matrix<M1,D,D> m3(42,1);
30 test_qvm::matrix<M1,D,D> m4(42,1);
31 rotate(m3,axis,r);
32 m3 = m3*m1;
33 BOOST_QVM_TEST_EQ(m3.a,m3.a);
34 }
35 }
36
37 template <int D>
38 void
39 test_y()
40 {
41 using namespace boost::qvm;
42 test_qvm::vector<V1,3> axis; axis.a[1]=1;
43 for( float r=0; r<6.28f; r+=0.5f )
44 {
45 test_qvm::matrix<M1,D,D> m1=rot_mat<D>(axis,r);
46 test_qvm::rotation_y(m1.b,r);
47 BOOST_QVM_TEST_EQ(m1.a,m1.b);
48 test_qvm::matrix<M1,D,D> m2(42,1);
49 set_rot(m2,axis,r);
50 test_qvm::rotation_y(m2.b,r);
51 BOOST_QVM_TEST_EQ(m2.a,m2.b);
52 test_qvm::matrix<M1,D,D> m3(42,1);
53 test_qvm::matrix<M1,D,D> m4(42,1);
54 rotate(m3,axis,r);
55 m3 = m3*m1;
56 BOOST_QVM_TEST_EQ(m3.a,m3.a);
57 }
58 }
59
60 template <int D>
61 void
62 test_z()
63 {
64 using namespace boost::qvm;
65 test_qvm::vector<V1,3> axis; axis.a[2]=1;
66 for( float r=0; r<6.28f; r+=0.5f )
67 {
68 test_qvm::matrix<M1,D,D> m1=rot_mat<D>(axis,r);
69 test_qvm::rotation_z(m1.b,r);
70 BOOST_QVM_TEST_EQ(m1.a,m1.b);
71 test_qvm::matrix<M1,D,D> m2(42,1);
72 set_rot(m2,axis,r);
73 test_qvm::rotation_z(m2.b,r);
74 BOOST_QVM_TEST_EQ(m2.a,m2.b);
75 test_qvm::matrix<M1,D,D> m3(42,1);
76 test_qvm::matrix<M1,D,D> m4(42,1);
77 rotate(m3,axis,r);
78 m3 = m3*m1;
79 BOOST_QVM_TEST_EQ(m3.a,m3.a);
80 }
81 }
82
83 template <int D>
84 void
85 test_xzy()
86 {
87 using namespace boost::qvm;
88 for( float x1=0; x1<6.28f; x1+=0.5f )
89 for( float z2=0; z2<6.28f; z2+=0.5f )
90 for( float y3=0; y3<6.28f; y3+=0.5f )
91 {
92 mat<float,D,D> const m2 = rotx_mat<D>(x1) * rotz_mat<D>(z2) * roty_mat<D>(y3);
93 {
94 mat<float,D,D> m1 = rot_mat_xzy<D>(x1,z2,y3);
95 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
96 }
97 {
98 mat<float,D,D> m1; set_rot_xzy(m1,x1,z2,y3);
99 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
100 }
101 {
102 mat<float,D,D> m1 = identity_mat<float,D>(); rotate_xzy(m1,x1,z2,y3);
103 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
104 }
105 }
106 }
107
108 template <int D>
109 void
110 test_xyz()
111 {
112 using namespace boost::qvm;
113 for( float x1=0; x1<6.28f; x1+=0.5f )
114 for( float y2=0; y2<6.28f; y2+=0.5f )
115 for( float z3=0; z3<6.28f; z3+=0.5f )
116 {
117 mat<float,D,D> const m2 = rotx_mat<D>(x1) * roty_mat<D>(y2) * rotz_mat<D>(z3);
118 {
119 mat<float,D,D> m1 = rot_mat_xyz<D>(x1,y2,z3);
120 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
121 }
122 {
123 mat<float,D,D> m1; set_rot_xyz(m1,x1,y2,z3);
124 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
125 }
126 {
127 mat<float,D,D> m1 = identity_mat<float,D>(); rotate_xyz(m1,x1,y2,z3);
128 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
129 }
130 }
131 }
132
133 template <int D>
134 void
135 test_yxz()
136 {
137 using namespace boost::qvm;
138 for( float y1=0; y1<6.28f; y1+=0.5f )
139 for( float x2=0; x2<6.28f; x2+=0.5f )
140 for( float z3=0; z3<6.28f; z3+=0.5f )
141 {
142 mat<float,D,D> const m2 = roty_mat<D>(y1) * rotx_mat<D>(x2) * rotz_mat<D>(z3);
143 {
144 mat<float,D,D> m1 = rot_mat_yxz<D>(y1,x2,z3);
145 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
146 }
147 {
148 mat<float,D,D> m1; set_rot_yxz(m1,y1,x2,z3);
149 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
150 }
151 {
152 mat<float,D,D> m1 = identity_mat<float,D>(); rotate_yxz(m1,y1,x2,z3);
153 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
154 }
155 }
156 }
157
158 template <int D>
159 void
160 test_yzx()
161 {
162 using namespace boost::qvm;
163 for( float y1=0; y1<6.28f; y1+=0.5f )
164 for( float z2=0; z2<6.28f; z2+=0.5f )
165 for( float x3=0; x3<6.28f; x3+=0.5f )
166 {
167 mat<float,D,D> const m2 = roty_mat<D>(y1) * rotz_mat<D>(z2) * rotx_mat<D>(x3);
168 {
169 mat<float,D,D> m1 = rot_mat_yzx<D>(y1,z2,x3);
170 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
171 }
172 {
173 mat<float,D,D> m1; set_rot_yzx(m1,y1,z2,x3);
174 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
175 }
176 {
177 mat<float,D,D> m1 = identity_mat<float,D>(); rotate_yzx(m1,y1,z2,x3);
178 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
179 }
180 }
181 }
182
183 template <int D>
184 void
185 test_zyx()
186 {
187 using namespace boost::qvm;
188 for( float z1=0; z1<6.28f; z1+=0.5f )
189 for( float y2=0; y2<6.28f; y2+=0.5f )
190 for( float x3=0; x3<6.28f; x3+=0.5f )
191 {
192 mat<float,D,D> const m2 = rotz_mat<D>(z1) * roty_mat<D>(y2) * rotx_mat<D>(x3);
193 {
194 mat<float,D,D> m1 = rot_mat_zyx<D>(z1,y2,x3);
195 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
196 }
197 {
198 mat<float,D,D> m1; set_rot_zyx(m1,z1,y2,x3);
199 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
200 }
201 {
202 mat<float,D,D> m1 = identity_mat<float,D>(); rotate_zyx(m1,z1,y2,x3);
203 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
204 }
205 }
206 }
207
208 template <int D>
209 void
210 test_zxy()
211 {
212 using namespace boost::qvm;
213 for( float z1=0; z1<6.28f; z1+=0.5f )
214 for( float x2=0; x2<6.28f; x2+=0.5f )
215 for( float y3=0; y3<6.28f; y3+=0.5f )
216 {
217 mat<float,D,D> const m2 = rotz_mat<D>(z1) * rotx_mat<D>(x2) * roty_mat<D>(y3);
218 {
219 mat<float,D,D> m1 = rot_mat_zxy<D>(z1,x2,y3);
220 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
221 }
222 {
223 mat<float,D,D> m1; set_rot_zxy(m1,z1,x2,y3);
224 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
225 }
226 {
227 mat<float,D,D> m1 = identity_mat<float,D>(); rotate_zxy(m1,z1,x2,y3);
228 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
229 }
230 }
231 }
232
233 template <int D>
234 void
235 test_xzx()
236 {
237 using namespace boost::qvm;
238 for( float x1=0; x1<6.28f; x1+=0.5f )
239 for( float z2=0; z2<6.28f; z2+=0.5f )
240 for( float x3=0; x3<6.28f; x3+=0.5f )
241 {
242 mat<float,D,D> const m2 = rotx_mat<D>(x1) * rotz_mat<D>(z2) * rotx_mat<D>(x3);
243 {
244 mat<float,D,D> m1 = rot_mat_xzx<D>(x1,z2,x3);
245 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
246 }
247 {
248 mat<float,D,D> m1; set_rot_xzx(m1,x1,z2,x3);
249 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
250 }
251 {
252 mat<float,D,D> m1 = identity_mat<float,D>(); rotate_xzx(m1,x1,z2,x3);
253 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
254 }
255 }
256 }
257
258 template <int D>
259 void
260 test_xyx()
261 {
262 using namespace boost::qvm;
263 for( float x1=0; x1<6.28f; x1+=0.5f )
264 for( float y2=0; y2<6.28f; y2+=0.5f )
265 for( float x3=0; x3<6.28f; x3+=0.5f )
266 {
267 mat<float,D,D> const m2 = rotx_mat<D>(x1) * roty_mat<D>(y2) * rotx_mat<D>(x3);
268 {
269 mat<float,D,D> m1 = rot_mat_xyx<D>(x1,y2,x3);
270 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
271 }
272 {
273 mat<float,D,D> m1; set_rot_xyx(m1,x1,y2,x3);
274 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
275 }
276 {
277 mat<float,D,D> m1 = identity_mat<float,D>(); rotate_xyx(m1,x1,y2,x3);
278 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
279 }
280 }
281 }
282
283 template <int D>
284 void
285 test_yxy()
286 {
287 using namespace boost::qvm;
288 for( float y1=0; y1<6.28f; y1+=0.5f )
289 for( float x2=0; x2<6.28f; x2+=0.5f )
290 for( float y3=0; y3<6.28f; y3+=0.5f )
291 {
292 mat<float,D,D> const m2 = roty_mat<D>(y1) * rotx_mat<D>(x2) * roty_mat<D>(y3);
293 {
294 mat<float,D,D> m1 = rot_mat_yxy<D>(y1,x2,y3);
295 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
296 }
297 {
298 mat<float,D,D> m1; set_rot_yxy(m1,y1,x2,y3);
299 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
300 }
301 {
302 mat<float,D,D> m1 = identity_mat<float,D>(); rotate_yxy(m1,y1,x2,y3);
303 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
304 }
305 }
306 }
307
308 template <int D>
309 void
310 test_yzy()
311 {
312 using namespace boost::qvm;
313 for( float y1=0; y1<6.28f; y1+=0.5f )
314 for( float z2=0; z2<6.28f; z2+=0.5f )
315 for( float y3=0; y3<6.28f; y3+=0.5f )
316 {
317 mat<float,D,D> const m2 = roty_mat<D>(y1) * rotz_mat<D>(z2) * roty_mat<D>(y3);
318 {
319 mat<float,D,D> m1 = rot_mat_yzy<D>(y1,z2,y3);
320 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
321 }
322 {
323 mat<float,D,D> m1; set_rot_yzy(m1,y1,z2,y3);
324 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
325 }
326 {
327 mat<float,D,D> m1 = identity_mat<float,D>(); rotate_yzy(m1,y1,z2,y3);
328 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
329 }
330 }
331 }
332
333 template <int D>
334 void
335 test_zyz()
336 {
337 using namespace boost::qvm;
338 for( float z1=0; z1<6.28f; z1+=0.5f )
339 for( float y2=0; y2<6.28f; y2+=0.5f )
340 for( float z3=0; z3<6.28f; z3+=0.5f )
341 {
342 mat<float,D,D> const m2 = rotz_mat<D>(z1) * roty_mat<D>(y2) * rotz_mat<D>(z3);
343 {
344 mat<float,D,D> m1 = rot_mat_zyz<D>(z1,y2,z3);
345 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
346 }
347 {
348 mat<float,D,D> m1; set_rot_zyz(m1,z1,y2,z3);
349 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
350 }
351 {
352 mat<float,D,D> m1 = identity_mat<float,D>(); rotate_zyz(m1,z1,y2,z3);
353 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
354 }
355 }
356 }
357
358 template <int D>
359 void
360 test_zxz()
361 {
362 using namespace boost::qvm;
363 for( float z1=0; z1<6.28f; z1+=0.5f )
364 for( float x2=0; x2<6.28f; x2+=0.5f )
365 for( float z3=0; z3<6.28f; z3+=0.5f )
366 {
367 mat<float,D,D> const m2 = rotz_mat<D>(z1) * rotx_mat<D>(x2) * rotz_mat<D>(z3);
368 {
369 mat<float,D,D> m1 = rot_mat_zxz<D>(z1,x2,z3);
370 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
371 }
372 {
373 mat<float,D,D> m1; set_rot_zxz(m1,z1,x2,z3);
374 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
375 }
376 {
377 mat<float,D,D> m1 = identity_mat<float,D>(); rotate_zxz(m1,z1,x2,z3);
378 BOOST_QVM_TEST_CLOSE(m1.a,m2.a,0.0002f);
379 }
380 }
381 }
382 }
383
384int
385main()
386 {
387 test_x<3>();
388 test_y<3>();
389 test_z<3>();
390 test_xzy<3>();
391 test_xyz<3>();
392 test_yxz<3>();
393 test_yzx<3>();
394 test_zyx<3>();
395 test_zxy<3>();
396 test_xzx<3>();
397 test_xyx<3>();
398 test_yxy<3>();
399 test_yzy<3>();
400 test_zyz<3>();
401 test_zxz<3>();
402 test_x<4>();
403 test_y<4>();
404 test_z<4>();
405 test_xzy<4>();
406 test_xyz<4>();
407 test_yxz<4>();
408 test_yzx<4>();
409 test_zyx<4>();
410 test_zxy<4>();
411 test_xzx<4>();
412 test_xyx<4>();
413 test_yxy<4>();
414 test_yzy<4>();
415 test_zyz<4>();
416 test_zxz<4>();
417 test_x<5>();
418 test_y<5>();
419 test_z<5>();
420 test_xzy<5>();
421 test_xyz<5>();
422 test_yxz<5>();
423 test_yzx<5>();
424 test_zyx<5>();
425 test_zxy<5>();
426 test_xzx<5>();
427 test_xyx<5>();
428 test_yxy<5>();
429 test_yzy<5>();
430 test_zyz<5>();
431 test_zxz<5>();
432 return boost::report_errors();
433 }