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

source code of boost/libs/qvm/test/rot_mat_test.cpp