view test/main.cpp @ 19:4634ca3fc308

Renamed src to test Began refactoring test program to use Google Test framework
author Eris Caffee <discordia@eldalin.com>
date Mon, 15 Sep 2014 01:02:04 -0500
parents
children fbb4ac41da28
line source
1 #include <iostream>
2 #include <iomanip>
3 #include <limits>
4 #include <string>
6 using namespace std;
8 #include "Math.h"
9 using namespace arda::Math;
11 #include "gtest/gtest.h"
13 ////////////////////////////////////////////////////////////////////////////////
14 // Vector2iTest
16 TEST( Vector2iTest, ConstructFromSingleValue ) {
17 Vector2i v2i_0(0);
18 EXPECT_EQ( 0, v2i_0.x ) << "x component is not 0";
19 EXPECT_EQ( 0, v2i_0.y ) << "y component is not 0";
21 Vector2i v2i_1(1);
22 EXPECT_EQ( 1, v2i_1.x ) << "x component is not 1";
23 EXPECT_EQ( 1, v2i_1.y ) << "y component is not 1";
24 }
26 TEST( Vector2iTest, ConstructFromMultipleValue ) {
27 Vector2i v2i(1, 2);
28 EXPECT_EQ( 1, v2i.x ) << "x component is not 1";
29 EXPECT_EQ( 2, v2i.y ) << "y component is not 2";
30 }
32 TEST( Vector2iTest, ConstructFromVector ) {
33 Vector2i v2i_1(1, 2);
35 Vector2i v2i_2(v2i_1);
36 EXPECT_EQ( 1, v2i_2.x ) << "x component is not 1";
37 EXPECT_EQ( 2, v2i_2.y ) << "y component is not 2";
38 }
40 ////////////////////////////////////////////////////////////////////////////////
41 // Vector3fTest
43 TEST( Vector3fTest, ConstructFromSingleValue ) {
44 Vector3f v3f_0(0.0);
45 EXPECT_EQ( 0.0, v3f_0.x ) << "x component is not 0.0";
46 EXPECT_EQ( 0.0, v3f_0.y ) << "y component is not 0.0";
47 EXPECT_EQ( 0.0, v3f_0.z ) << "z component is not 0.0";
49 Vector3f v3f_1(1.0);
50 EXPECT_EQ( 1.0, v3f_1.x ) << "x component is not 1.0";
51 EXPECT_EQ( 1.0, v3f_1.y ) << "y component is not 1.0";
52 EXPECT_EQ( 1.0, v3f_1.y ) << "z component is not 1.0";
53 }
55 TEST( Vector3fTest, ConstructFromMultipleValue ) {
56 Vector3f v3f(1.0, 2.0, 3.0);
57 EXPECT_EQ( 1.0, v3f.x ) << "x component is not 1.0";
58 EXPECT_EQ( 2.0, v3f.y ) << "y component is not 2.0";
59 EXPECT_EQ( 3.0, v3f.z ) << "z component is not 3.0";
60 }
62 TEST( Vector3fTest, ConstructFromVector ) {
63 Vector3f v3f_1 (1.0, 2.0, 3.0);
65 Vector3f v3f (v3f_1);
66 EXPECT_EQ( 1.0, v3f.x ) << "x component is not 1.0";
67 EXPECT_EQ( 2.0, v3f.y ) << "y component is not 2.0";
68 EXPECT_EQ( 3.0, v3f.z ) << "z component is not 3.0";
69 }
72 ////////////////////////////////////////////////////////////////////////////////
73 // Vector4dTest
75 TEST( Vector4dTest, ConstructFromSingleValue ) {
76 Vector4d v4d_0(0.0);
77 EXPECT_EQ( 0.0, v4d_0.x ) << "x component is not 0.0";
78 EXPECT_EQ( 0.0, v4d_0.y ) << "y component is not 0.0";
79 EXPECT_EQ( 0.0, v4d_0.z ) << "z component is not 0.0";
80 EXPECT_EQ( 0.0, v4d_0.w ) << "w component is not 0.0";
82 Vector4d v4d_1(1.0);
83 EXPECT_EQ( 1.0, v4d_1.x ) << "x component is not 1.0";
84 EXPECT_EQ( 1.0, v4d_1.y ) << "y component is not 1.0";
85 EXPECT_EQ( 1.0, v4d_1.z ) << "z component is not 1.0";
86 EXPECT_EQ( 1.0, v4d_1.w ) << "w component is not 1.0";
87 }
89 TEST( Vector4dTest, ConstructFromMultipleValue ) {
90 Vector4d v4d_1(1.0, 2.0, 3.0, 4.0);
92 Vector4d v4d (v4d_1);
93 EXPECT_EQ( 1.0, v4d.x ) << "x component is not 1.0";
94 EXPECT_EQ( 2.0, v4d.y ) << "y component is not 2.0";
95 EXPECT_EQ( 3.0, v4d.z ) << "z component is not 3.0";
96 EXPECT_EQ( 4.0, v4d.w ) << "w component is not 4.0";
97 }
99 TEST( Vector4dTest, ConstructFromVector ) {
100 Vector4d v4d_1 (1.0, 2.0, 3.0, 4.0);
102 Vector4d v4d (v4d_1);
103 EXPECT_EQ( 1.0, v4d.x ) << "x component is not 1.0";
104 EXPECT_EQ( 2.0, v4d.y ) << "y component is not 2.0";
105 EXPECT_EQ( 3.0, v4d.z ) << "z component is not 3.0";
106 EXPECT_EQ( 4.0, v4d.w ) << "w component is not 4.0";
107 }
112 int main(int argc, char **argv) {
113 ::testing::InitGoogleTest(&argc, argv);
114 return RUN_ALL_TESTS();
115 }
118 #ifdef NOTHING
120 ////////////////////////////////////////////////////////////////////////////////
121 void test_vector(void)
122 {
123 string s1, s2;
126 {
127 cout << "===============================================================" << endl <<
128 "Testing Vector array indexing" << endl;
129 Vector2i v2i(1,2);
130 Vector3f v3f(1.1f, 2.2f, 3.3f);
131 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
133 cout << setw(40) << "v2i: " << v2i[0] << ", " << v2i[1] << endl;
134 cout << setw(40) << "v3f: " << v3f[0] << ", " << v3f[1] << ", " << v3f[2] << endl;
135 cout << setw(40) << "v4d: " << v4d[0] << ", " << v4d[1] << ", " << v4d[2] << ", " << v4d[3] << endl;
136 }
138 {
139 cout << "===============================================================" << endl <<
140 "Testing Vector assignment" << endl;
141 Vector2i v2i(1,2);
142 Vector3f v3f(1.1f, 2.2f, 3.3f);
143 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
144 Vector2i v2i_2(0);
145 Vector3f v3f_2(0);
146 Vector4d v4d_2(0);
148 cout << "Before assignment" << endl;
149 cout << setw(40) << "v2i: " << v2i.to_string() << endl;
150 cout << setw(40) << "v3f: " << v3f.to_string() << endl;
151 cout << setw(40) << "v4d: " << v4d.to_string() << endl;
152 cout << setw(40) << "v2i_2: " << v2i_2.to_string() << endl;
153 cout << setw(40) << "v3f_2: " << v3f_2.to_string() << endl;
154 cout << setw(40) << "v4d_2: " << v4d_2.to_string() << endl;
156 v2i_2 = v2i;
157 v3f_2 = v3f;
158 v4d_2 = v4d;
159 cout << "After assignment by =" << endl;
160 cout << setw(40) << "v2i_2: " << v2i_2.to_string() << endl;
161 cout << setw(40) << "v3f_2: " << v3f_2.to_string() << endl;
162 cout << setw(40) << "v4d_2: " << v4d_2.to_string() << endl;
164 v2i_2.assign(1, 1);
165 v3f_2.assign(2.2, 2.2, 2.2);
166 v4d_2.assign(3.3, 3.3, 3.3, 3.3);
167 cout << "After assignment by assign()" << endl;
168 cout << setw(40) << "v2i_2: " << v2i_2.to_string() << endl;
169 cout << setw(40) << "v3f_2: " << v3f_2.to_string() << endl;
170 cout << setw(40) << "v4d_2: " << v4d_2.to_string() << endl;
171 }
173 {
174 cout << "===============================================================" << endl <<
175 "Testing Vector comparison" << endl;
176 Vector2i v2i(1,2);
177 Vector3f v3f(1.1f, 2.2f, 3.3f);
178 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
179 Vector2i v2i_2(1,2);
180 Vector3f v3f_2(1.1f, 2.2f, 3.3f);
181 Vector4d v4d_2(1.1, 2.2, 3.3, 4.4);
182 Vector2i v2i_3(0);
183 Vector3f v3f_3(0);
184 Vector4d v4d_3(0);
186 cout << setw(40) << "v2i: " << v2i.to_string() << endl;
187 cout << setw(40) << "v3f: " << v3f.to_string() << endl;
188 cout << setw(40) << "v4d: " << v4d.to_string() << endl;
189 cout << setw(40) << "v2i_2: " << v2i_2.to_string() << endl;
190 cout << setw(40) << "v3f_2: " << v3f_2.to_string() << endl;
191 cout << setw(40) << "v4d_2: " << v4d_2.to_string() << endl;
192 cout << setw(40) << "v2i_3: " << v2i_3.to_string() << endl;
193 cout << setw(40) << "v3f_3: " << v3f_3.to_string() << endl;
194 cout << setw(40) << "v4d_3: " << v4d_3.to_string() << endl;
195 cout << boolalpha;
196 cout << setw(40) << "v2i == v2i_2: " << (v2i == v2i_2) << endl;
197 cout << setw(40) << "v2i == v2i_3: " << (v2i == v2i_3) << endl;
198 cout << setw(40) << "v2i != v2i_2: " << (v2i != v2i_2) << endl;
199 cout << setw(40) << "v2i != v2i_3: " << (v2i != v2i_3) << endl;
200 cout << setw(40) << "v3f == v3f_2: " << (v3f == v3f_2) << endl;
201 cout << setw(40) << "v3f == v3f_3: " << (v3f == v3f_3) << endl;
202 cout << setw(40) << "v3f != v3f_2: " << (v3f != v3f_2) << endl;
203 cout << setw(40) << "v3f != v3f_3: " << (v3f != v3f_3) << endl;
204 cout << setw(40) << "v4d == v4d_2: " << (v4d == v4d_2) << endl;
205 cout << setw(40) << "v4d == v4d_3: " << (v4d == v4d_3) << endl;
206 cout << setw(40) << "v4d != v4d_2: " << (v4d != v4d_2) << endl;
207 cout << setw(40) << "v4d != v4d_3: " << (v4d != v4d_3) << endl;
208 }
210 {
211 cout << "===============================================================" << endl <<
212 "Testing Vector addition" << endl;
213 Vector2i v2i(1,2);
214 Vector3f v3f(1.1f, 2.2f, 3.3f);
215 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
216 Vector2i v2i_2(3,4);
217 Vector3f v3f_2(4.4, 5.5, 6.6);
218 Vector4d v4d_2(5.5, 6.6, 7.7, 8.8);
219 Vector2i v2i_3(0);
220 Vector3f v3f_3(0);
221 Vector4d v4d_3(0);
223 cout << setw(40) << "v2i: " << v2i.to_string() << endl;
224 cout << setw(40) << "v3f: " << v3f.to_string() << endl;
225 cout << setw(40) << "v4d: " << v4d.to_string() << endl;
226 cout << setw(40) << "v2i_2: " << v2i_2.to_string() << endl;
227 cout << setw(40) << "v3f_2: " << v3f_2.to_string() << endl;
228 cout << setw(40) << "v4d_2: " << v4d_2.to_string() << endl;
229 v2i_3 = v2i + v2i_2;
230 v3f_3 = v3f + v3f_2;
231 v4d_3 = v4d + v4d_2;
232 cout << setw(40) << "v2i_3 = v2i + v2i_2: " << v2i_3.to_string() << endl;
233 cout << setw(40) << "v3f_3 = v3f + v3f_2: " << v3f_3.to_string() << endl;
234 cout << setw(40) << "v4d_3 = v4d + v4d_2: " << v4d_3.to_string() << endl;
235 v2i_3 += v2i_2;
236 v3f_3 += v3f_2;
237 v4d_3 += v4d_3;
238 cout << setw(40) << "v2i_3 += v2i_2: " << v2i_3.to_string() << endl;
239 cout << setw(40) << "v3f_3 += v3f_2: " << v3f_3.to_string() << endl;
240 cout << setw(40) << "v4d_3 += v4d_3: " << v4d_3.to_string() << endl;
241 }
243 {
244 cout << "===============================================================" << endl <<
245 "Testing Vector subtraction" << endl;
246 Vector2i v2i(1,2);
247 Vector3f v3f(1.1f, 2.2f, 3.3f);
248 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
249 Vector2i v2i_2(3,4);
250 Vector3f v3f_2(4.4, 5.5, 6.6);
251 Vector4d v4d_2(5.5, 6.6, 7.7, 8.8);
252 Vector2i v2i_3(0);
253 Vector3f v3f_3(0);
254 Vector4d v4d_3(0);
256 cout << setw(40) << "v2i: " << v2i.to_string() << endl;
257 cout << setw(40) << "v3f: " << v3f.to_string() << endl;
258 cout << setw(40) << "v4d: " << v4d.to_string() << endl;
259 cout << setw(40) << "v2i_2: " << v2i_2.to_string() << endl;
260 cout << setw(40) << "v3f_2: " << v3f_2.to_string() << endl;
261 cout << setw(40) << "v4d_2: " << v4d_2.to_string() << endl;
262 v2i_3 = v2i - v2i_2;
263 v3f_3 = v3f - v3f_2;
264 v4d_3 = v4d - v4d_2;
265 cout << setw(40) << "v2i_3 = v2i - v2i_2: " << v2i_3.to_string() << endl;
266 cout << setw(40) << "v3f_3 = v3f - v3f_2: " << v3f_3.to_string() << endl;
267 cout << setw(40) << "v4d_3 = v4d - v4d_2: " << v4d_3.to_string() << endl;
268 v2i_3 -= v2i_2;
269 v3f_3 -= v3f_2;
270 v4d_3 -= v4d_3;
271 cout << setw(40) << "v2i_3 -= v2i_2: " << v2i_3.to_string() << endl;
272 cout << setw(40) << "v3f_3 -= v3f_2: " << v3f_3.to_string() << endl;
273 cout << setw(40) << "v4d_3 -= v4d_3: " << v4d_3.to_string() << endl;
274 }
276 {
277 cout << "===============================================================" << endl <<
278 "Testing Vector scalar multiplication" << endl;
279 Vector2i v2i(1,2);
280 Vector3f v3f(1.1f, 2.2f, 3.3f);
281 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
282 Vector2i v2i_2(0);
283 Vector3f v3f_2(0);
284 Vector4d v4d_2(0);
285 int i = 2;
286 float f = 2.f;
287 double d = 2.0;
289 cout << setw(40) << "i: " << i << endl;
290 cout << setw(40) << "f: " << f << endl;
291 cout << setw(40) << "d: " << d << endl;
292 cout << setw(40) << "v2i: " << v2i.to_string() << endl;
293 cout << setw(40) << "v3f: " << v3f.to_string() << endl;
294 cout << setw(40) << "v4d: " << v4d.to_string() << endl;
295 cout << setw(40) << "v2i_2: " << v2i_2.to_string() << endl;
296 cout << setw(40) << "v3f_2: " << v3f_2.to_string() << endl;
297 cout << setw(40) << "v4d_2: " << v4d_2.to_string() << endl;
298 v2i_2 = v2i * i;
299 v3f_2 = v3f * f;
300 v4d_2 = v4d * d;
301 cout << setw(40) << "v2i_2 = v2i * i: " << v2i_2.to_string() << endl;
302 cout << setw(40) << "v3f_2 = v3f * f: " << v3f_2.to_string() << endl;
303 cout << setw(40) << "v4d_2 = v4d * d: " << v4d_2.to_string() << endl;
304 v2i_2 *= i;
305 v3f_2 *= f;
306 v4d_2 *= d;
307 cout << setw(40) << "v2i_2 *= i: " << v2i_2.to_string() << endl;
308 cout << setw(40) << "v3f_2 *= f: " << v3f_2.to_string() << endl;
309 cout << setw(40) << "v4d_2 *= d: " << v4d_2.to_string() << endl;
310 }
312 {
313 cout << "===============================================================" << endl <<
314 "Testing Vector scalar division" << endl;
315 Vector2i v2i(1,2);
316 Vector3f v3f(1.1f, 2.2f, 3.3f);
317 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
318 Vector2i v2i_2(0);
319 Vector3f v3f_2(0);
320 Vector4d v4d_2(0);
321 int i = 2;
322 float f = 2.f;
323 double d = 2.0;
325 cout << setw(40) << "v2i: " << v2i.to_string() << endl;
326 cout << setw(40) << "v3f: " << v3f.to_string() << endl;
327 cout << setw(40) << "v4d: " << v4d.to_string() << endl;
328 cout << setw(40) << "v2i_2: " << v2i_2.to_string() << endl;
329 cout << setw(40) << "v3f_2: " << v3f_2.to_string() << endl;
330 cout << setw(40) << "v4d_2: " << v4d_2.to_string() << endl;
331 v2i_2 = v2i / i;
332 v3f_2 = v3f / f;
333 v4d_2 = v4d / d;
334 cout << setw(40) << "v2i_2 = v2i / i: " << v2i_2.to_string() << endl;
335 cout << setw(40) << "v3f_2 = v3f / f: " << v3f_2.to_string() << endl;
336 cout << setw(40) << "v4d_2 = v4d / d: " << v4d_2.to_string() << endl;
337 v2i_2 /= i;
338 v3f_2 /= f;
339 v4d_2 /= d;
340 cout << setw(40) << "v2i_2 /= i: " << v2i_2.to_string() << endl;
341 cout << setw(40) << "v3f_2 /= f: " << v3f_2.to_string() << endl;
342 cout << setw(40) << "v4d_2 /= d: " << v4d_2.to_string() << endl;
343 }
345 {
346 cout << "===============================================================" << endl <<
347 "Testing Vector cross product" << endl;
348 Vector3f v3f(1.1f, 2.2f, 3.3f);
349 Vector3f v3f_2(4.4, 5.5, 6.6);
350 Vector3f v3f_3(0);
351 Vector3f v3f_4(0);
352 cout << setw(40) << "v3f: " << v3f.to_string() << endl;
353 cout << setw(40) << "v3f_2: " << v3f_2.to_string() << endl;
354 cout << setw(40) << "v3f_3: " << v3f_3.to_string() << endl;
355 v3f.cross(v3f_2, v3f_3);
356 cout << setw(40) << "v3f.cross(v3f_2, v3f_3): " << v3f_3.to_string() << endl;
357 v3f_4 = 2.0 * v3f.cross(v3f_2);
358 cout << setw(40) << "2.0 * v3f.cross(v3f_2,): " << v3f_4.to_string() << endl;
359 v3f_4.assign(0,0,0);
360 v3f.cross(v3f_2, v3f_4);
361 cout << setw(40) << "v3f.cross(v3f_2, v3f_4): " << v3f_4.to_string() << endl;
362 }
364 {
365 cout << "===============================================================" << endl <<
366 "Testing Vector dot product" << endl;
367 Vector2i v2i(1, 2);
368 Vector2i v2i_2(3, 4);
369 Vector3f v3f(1.1f, 2.2f, 3.3f);
370 Vector3f v3f_2(4.4, 5.5, 6.6);
371 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
372 Vector4d v4d_2(5.5, 6.6, 7.7, 8.8);
373 int i;
374 float f;
375 double d;
376 cout << setw(40) << "v2i: " << v2i.to_string() << endl;
377 cout << setw(40) << "v2i_2: " << v2i_2.to_string() << endl;
378 cout << setw(40) << "v3f: " << v3f.to_string() << endl;
379 cout << setw(40) << "v3f_2: " << v3f_2.to_string() << endl;
380 cout << setw(40) << "v4d: " << v4d.to_string() << endl;
381 cout << setw(40) << "v4d_2: " << v4d_2.to_string() << endl;
382 i = v2i.dot(v2i_2);
383 cout << setw(40) << "i = v2i.dot(v2i_2): " << i << endl;
384 f = v3f.dot(v3f_2);
385 cout << setw(40) << "f = v3f.dot(v3f_2): " << f << endl;
386 d = v4d.dot(v4d_2);
387 cout << setw(40) << "d = v4d.dot(v4d_2): " << d << endl;
388 }
390 {
391 cout << "===============================================================" << endl <<
392 "Testing Vector length" << endl;
393 Vector2i v2i(1, 2);
394 Vector3f v3f(1.1f, 2.2f, 3.3f);
395 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
396 cout << setw(40) << "v2i: " << v2i.to_string() << endl;
397 cout << setw(40) << "v3f: " << v3f.to_string() << endl;
398 cout << setw(40) << "v4d: " << v4d.to_string() << endl;
399 cout << setw(40) << "v2i.length(): " << v2i.length() << endl;
400 cout << setw(40) << "v3f.length(): " << v3f.length() << endl;
401 cout << setw(40) << "v4d.length(): " << v4d.length() << endl;
402 }
404 {
405 cout << "===============================================================" << endl <<
406 "Testing Vector normalize" << endl;
407 Vector2f v2f(1.1, 2.2);
408 Vector3f v3f(1.1f, 2.2f, 3.3f);
409 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
410 cout << setw(40) << "v2f: " << v2f.to_string() << endl;
411 cout << setw(40) << "v3f: " << v3f.to_string() << endl;
412 cout << setw(40) << "v4d: " << v4d.to_string() << endl;
413 v2f.normalize();
414 cout << setw(40) << "v2f.normalize() " << v2f.to_string() << endl;
415 v3f.normalize();
416 cout << setw(40) << "v3f.normalize() " << v3f.to_string() << endl;
417 v4d.normalize();
418 cout << setw(40) << "v4d.normalize() " << v4d.to_string() << endl;
419 cout << setw(40) << "v2f.length(): " << v2f.length() << endl;
420 cout << setw(40) << "v3f.length(): " << v3f.length() << endl;
421 cout << setw(40) << "v4d.length(): " << v4d.length() << endl;
422 }
424 {
425 cout << "===============================================================" << endl <<
426 "Testing Vector get_angle" << endl;
427 Vector2i v2i(1, 2);
428 Vector2i v2i_2(3, 4);
429 Vector3f v3f(1.1f, 2.2f, 3.3f);
430 Vector3f v3f_2(4.4, 5.5, 6.6);
431 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
432 Vector4d v4d_2(5.5, 6.6, 7.7, 8.8);
433 double d;
434 cout << setw(40) << "v2i: " << v2i.to_string() << endl;
435 cout << setw(40) << "v2i_2: " << v2i_2.to_string() << endl;
436 cout << setw(40) << "v3f: " << v3f.to_string() << endl;
437 cout << setw(40) << "v3f_2: " << v3f_2.to_string() << endl;
438 cout << setw(40) << "v4d: " << v4d.to_string() << endl;
439 cout << setw(40) << "v4d_2: " << v4d_2.to_string() << endl;
440 d = v2i.get_angle(v2i_2);
441 cout << setw(40) << "d = v2i.get_angle(v2i_2): " << d << endl;
442 d = v3f.get_angle(v3f_2);
443 cout << setw(40) << "d = v3f.get_angle(v3f_2): " << d << endl;
444 d = v4d.get_angle(v4d_2);
445 cout << setw(40) << "d = v4d.get_angle(v4d_2): " << d << endl;
446 }
448 {
449 cout << "===============================================================" << endl <<
450 "Testing Vector get_anglen" << endl;
451 Vector2f v2f(1.1, 2.2);
452 Vector2f v2f_2(3.3, 4.4);
453 Vector3f v3f(1.1f, 2.2f, 3.3f);
454 Vector3f v3f_2(4.4, 5.5, 6.6);
455 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
456 Vector4d v4d_2(5.5, 6.6, 7.7, 8.8);
457 double d;
458 v2f.normalize();
459 v2f_2.normalize();
460 v3f.normalize();
461 v3f_2.normalize();
462 v4d.normalize();
463 v4d_2.normalize();
464 cout << setw(40) << "v2f: " << v2f.to_string() << endl;
465 cout << setw(40) << "v2f_2: " << v2f_2.to_string() << endl;
466 cout << setw(40) << "v3f: " << v3f.to_string() << endl;
467 cout << setw(40) << "v3f_2: " << v3f_2.to_string() << endl;
468 cout << setw(40) << "v4d: " << v4d.to_string() << endl;
469 cout << setw(40) << "v4d_2: " << v4d_2.to_string() << endl;
470 d = v2f.get_anglen(v2f_2);
471 cout << setw(40) << "d = v2f.get_anglen(v2f_2): " << d << endl;
472 d = v3f.get_anglen(v3f_2);
473 cout << setw(40) << "d = v3f.get_anglen(v3f_2): " << d << endl;
474 d = v4d.get_anglen(v4d_2);
475 cout << setw(40) << "d = v4d.get_anglen(v4d_2): " << d << endl;
476 }
478 {
479 cout << "===============================================================" << endl <<
480 "Testing Vector get_proj" << endl;
481 Vector2f v2f(1.1, 2.2);
482 Vector2f v2f_2(3.3, 4.4);
483 Vector2f v2f_3(0);
484 Vector3f v3f(1.1f, 2.2f, 3.3f);
485 Vector3f v3f_2(4.4, 5.5, 6.6);
486 Vector3f v3f_3(0);
487 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
488 Vector4d v4d_2(5.5, 6.6, 7.7, 8.8);
489 Vector4d v4d_3(0);
490 cout << setw(40) << "v2f: " << v2f.to_string() << endl;
491 cout << setw(40) << "v2f_2: " << v2f_2.to_string() << endl;
492 cout << setw(40) << "v3f: " << v3f.to_string() << endl;
493 cout << setw(40) << "v3f_2: " << v3f_2.to_string() << endl;
494 cout << setw(40) << "v4d: " << v4d.to_string() << endl;
495 cout << setw(40) << "v4d_2: " << v4d_2.to_string() << endl;
496 v2f_3 = v2f.proj(v2f_2);
497 cout << setw(40) << "v2f_3 = v2f.proj(v3f_2): " << v2f_3.to_string() << endl;
498 v3f_3 = v3f.proj(v3f_2);
499 cout << setw(40) << "v3f_3 = v3f.proj(v3f_2): " << v3f_3.to_string() << endl;
500 v4d_3 = v4d.proj(v4d_2);
501 cout << setw(40) << "v4d_3 = v4d.proj(v4d_2): " << v4d_3.to_string() << endl;
502 v2f_3.assign(0,0);
503 v3f_3.assign(0,0,0);
504 v4d_3.assign(0,0,0,0);
505 v2f.proj(v2f_2, v2f_3);
506 cout << setw(40) << "v2f.proj(v2f_2, v2f_3): " << v2f_3.to_string() << endl;
507 v3f.proj(v3f_2, v3f_3);
508 cout << setw(40) << "v3f.proj(v3f_2, v3f_3): " << v3f_3.to_string() << endl;
509 v4d.proj(v4d_2, v4d_3);
510 cout << setw(40) << "v4d.proj(v4d_2, v4d_3): " << v4d_3.to_string() << endl;
511 }
513 }
515 ////////////////////////////////////////////////////////////////////////////////
516 void test_matrix(void)
517 {
518 string s1, s2;
520 {
521 cout << "===============================================================" << endl <<
522 "Testing Maxtrix constructors" << endl;
523 Matrix22i m22i_1(0);
524 Matrix22i m22i_2(1);
525 Matrix22i m22i_3(1, 2, 3, 4);
526 Matrix22i m22i_4(m22i_3);
528 cout << setw(40) << "m22i_1: " << m22i_1.to_string() << endl;
529 cout << setw(40) << "m22i_2: " << m22i_2.to_string() << endl;
530 cout << setw(40) << "m22i_3: " << m22i_3.to_string() << endl;
531 cout << setw(40) << "m22i_4: " << m22i_4.to_string() << endl;
533 Matrix33f m33f_1(0.0f);
534 Matrix33f m33f_2(1.1f);
535 Matrix33f m33f_3(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
536 Matrix33f m33f_4(m33f_3);
538 cout << setw(40) << "m33f_1: " << m33f_1.to_string() << endl;
539 cout << setw(40) << "m33f_2: " << m33f_2.to_string() << endl;
540 cout << setw(40) << "m33f_3: " << m33f_3.to_string() << endl;
541 cout << setw(40) << "m33f_4: " << m33f_4.to_string() << endl;
543 Matrix44d m44d_1(0.0);
544 Matrix44d m44d_2(1.1);
545 Matrix44d m44d_3(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11,
546 12.12, 13.13, 14.14, 15.15, 16.16);
547 Matrix44d m44d_4(m44d_3);
549 cout << setw(40) << "m44d_1: " << m44d_1.to_string() << endl;
550 cout << setw(40) << "m44d_2: " << m44d_2.to_string() << endl;
551 cout << setw(40) << "m44d_3: " << m44d_3.to_string() << endl;
552 cout << setw(40) << "m44d_4: " << m44d_4.to_string() << endl;
553 }
555 {
556 cout << "===============================================================" << endl <<
557 "Testing Maxtrix array indexing" << endl;
558 Matrix22i m22i(1, 2, 3, 4);
560 cout << setw(40) << "m22i: " << m22i[0] << " " << m22i[1] << " " << m22i[2] << " " << m22i[3] << " "<< endl;
562 Matrix33f m33f(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
564 cout << setw(40) << "m33f: " << m33f[0] << " " << m33f[1] << " " << m33f[2] << " " << m33f[3] << " " << m33f[4] << " " << m33f[5] << " " << m33f[6] << " " << m33f[7] << " " << m33f[8] << endl;
566 Matrix44d m44d(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11,
567 12.12, 13.13, 14.14, 15.15, 16.16);
569 cout << setw(40) << "m44d: " << m44d[0] << " " << m44d[1] << " " << m44d[2] << " " << m44d[3] << " " << m44d[4] << " " << m44d[5] << " " << m44d[6] << " " << m44d[7] << " " << m44d[8] << " " << m44d[9] << " " << m44d[10] << " " << m44d[11] << " " << m44d[12] << " " << m44d[13] << " " << m44d[14] << " " << m44d[15] << endl;
570 }
572 {
573 cout << "===============================================================" << endl <<
574 "Testing Maxtrix assignment" << endl;
575 Matrix22i m22i_1(1, 2, 3, 4);
576 Matrix22i m22i_2(5, 6, 7, 8);
578 cout << setw(40) << "m22i_1: " << m22i_1.to_string() << endl;
579 cout << setw(40) << "m22i_2: " << m22i_2.to_string() << endl;
581 m22i_2 = m22i_1;
582 cout << setw(40) << "m22i_2 = m22i_1: " << m22i_2.to_string() << endl;
584 m22i_2.assign(9, 10, 11, 12);
585 cout << setw(40) << "m22i_2.assign(9, 10, 11, 12): "
586 << m22i_2.to_string() << endl;
588 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
589 Matrix33f m33f_2(10.10f, 11.11f, 12.12f, 13.13f, 14.14f, 15.15f, 16.16f, 17.17f, 18.18f);
591 cout << setw(40) << "m33f_1: " << m33f_1.to_string() << endl;
592 cout << setw(40) << "m33f_2: " << m33f_2.to_string() << endl;
594 m33f_2 = m33f_1;
595 cout << setw(40) << "m33f_2 = m33f_1: " << m33f_2.to_string() << endl;
597 m33f_2.assign(19.19f, 20.20f, 21.21f, 22.22f, 23.23f, 24.24f, 25.25f, 26.26f, 27.27f);
598 cout << setw(40) << "m33f_2.assign(19.19f, 20.20f, ... , 27.27f): "
599 << m33f_2.to_string() << endl;
601 Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11,
602 12.12, 13.13, 14.14, 15.15, 16.16);
603 Matrix44d m44d_2(16.16, 17.17, 18.18, 19.19,
604 20.20, 21.21, 22.22, 23.23,
605 24.24, 25.25, 26.26, 27.27,
606 28.28, 29.29, 30.30, 31.31);
608 cout << setw(40) << "m44d_1: " << m44d_1.to_string() << endl;
609 cout << setw(40) << "m44d_2: " << m44d_2.to_string() << endl;
611 m44d_2 = m44d_1;
612 cout << setw(40) << "m44d_2 = m44d_1: " << m44d_2.to_string() << endl;
614 m44d_2.assign(32.32, 33.33, 34.34, 35.35,
615 36.36, 37.37, 38.38, 39.39,
616 40.40, 41.41, 42.42, 43.43,
617 44.44, 45.45, 46.46, 47.47);
618 cout << setw(40) << "m44d_2.assign(32.32, 33.33, ... , 47.47): "
619 << m44d_2.to_string() << endl;
620 }
622 {
623 cout << "===============================================================" << endl <<
624 "Testing Maxtrix comparison" << endl;
625 Matrix22i m22i_1(1, 2, 3, 4);
626 Matrix22i m22i_2(1, 2, 3, 4);
627 Matrix22i m22i_3(0);
629 cout << setw(40) << "m22i_1: " << m22i_1.to_string() << endl;
630 cout << setw(40) << "m22i_2: " << m22i_2.to_string() << endl;
631 cout << setw(40) << "m22i_3: " << m22i_3.to_string() << endl;
632 cout << boolalpha;
633 cout << setw(40) << "m22i_1 == m22i_2: " << (m22i_1 == m22i_2) << endl;
634 cout << setw(40) << "m22i_1 == m22i_3: " << (m22i_2 == m22i_3) << endl;
635 cout << setw(40) << "m22i_1 != m22i_2: " << (m22i_1 != m22i_2) << endl;
636 cout << setw(40) << "m22i_1 != m22i_3: " << (m22i_2 != m22i_3) << endl;
638 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
639 Matrix33f m33f_2(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
640 Matrix33f m33f_3(0.0f);
642 cout << setw(40) << "m33f_1: " << m33f_1.to_string() << endl;
643 cout << setw(40) << "m33f_2: " << m33f_2.to_string() << endl;
644 cout << setw(40) << "m33f_3: " << m33f_3.to_string() << endl;
645 cout << boolalpha;
646 cout << setw(40) << "m33f_1 == m33f_2: " << (m33f_1 == m33f_2) << endl;
647 cout << setw(40) << "m33f_1 == m33f_3: " << (m33f_2 == m33f_3) << endl;
648 cout << setw(40) << "m33f_1 != m33f_2: " << (m33f_1 != m33f_2) << endl;
649 cout << setw(40) << "m33f_1 != m33f_3: " << (m33f_2 != m33f_3) << endl;
651 Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11,
652 12.12, 13.13, 14.14, 15.15, 16.16);
653 Matrix44d m44d_2(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11,
654 12.12, 13.13, 14.14, 15.15, 16.16);
655 Matrix44d m44d_3(0.0);
657 cout << setw(40) << "m44d_1: " << m44d_1.to_string() << endl;
658 cout << setw(40) << "m44d_2: " << m44d_2.to_string() << endl;
659 cout << setw(40) << "m44d_3: " << m44d_3.to_string() << endl;
660 cout << boolalpha;
661 cout << setw(40) << "m44d_1 == m44d_2: " << (m44d_1 == m44d_2) << endl;
662 cout << setw(40) << "m44d_1 == m44d_3: " << (m44d_2 == m44d_3) << endl;
663 cout << setw(40) << "m44d_1 != m44d_2: " << (m44d_1 != m44d_2) << endl;
664 cout << setw(40) << "m44d_1 != m44d_3: " << (m44d_2 != m44d_3) << endl;
665 }
667 {
668 cout << "===============================================================" << endl <<
669 "Testing Maxtrix addition" << endl;
670 Matrix22i m22i_1(1, 2, 3, 4);
671 Matrix22i m22i_2(5, 6, 7, 8);
672 Matrix22i m22i_3(0);
674 cout << setw(40) << "m22i_1: " << m22i_1.to_string() << endl;
675 cout << setw(40) << "m22i_2: " << m22i_2.to_string() << endl;
676 cout << setw(40) << "m22i_3: " << m22i_3.to_string() << endl;
677 m22i_3 = m22i_1 + m22i_2;
678 cout << setw(40) << "m22i_3 = m22i_1 + m22i_2: " << m22i_3.to_string() << endl;
680 m22i_3 += m22i_1;
681 cout << setw(40) << "m22i_3 += m22i_1: " << m22i_3.to_string() << endl;
683 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
684 Matrix33f m33f_2(10.10f, 11.11f, 12.12f, 13.13f, 14.14f, 15.15f, 16.16f, 17.17f, 18.18f);
685 Matrix33f m33f_3(0.0f);
687 cout << setw(40) << "m33f_1: " << m33f_1.to_string() << endl;
688 cout << setw(40) << "m33f_2: " << m33f_2.to_string() << endl;
689 cout << setw(40) << "m33f_3: " << m33f_3.to_string() << endl;
690 m33f_3 = m33f_1 + m33f_2;
691 cout << setw(40) << "m33f_3 = m33f_1 + m33f_2: " << m33f_3.to_string() << endl;
693 m33f_3 += m33f_1;
694 cout << setw(40) << "m33f_3 += m33f_1: " << m33f_3.to_string() << endl;
696 Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11,
697 12.12, 13.13, 14.14, 15.15, 16.16);
698 Matrix44d m44d_2(16.16, 17.17, 18.18, 19.19,
699 20.20, 21.21, 22.22, 23.23,
700 24.24, 25.25, 26.26, 27.27,
701 28.28, 29.29, 30.30, 31.31);
702 Matrix44d m44d_3(0.0);
704 cout << setw(40) << "m44d_1: " << m44d_1.to_string() << endl;
705 cout << setw(40) << "m44d_2: " << m44d_2.to_string() << endl;
706 cout << setw(40) << "m44d_3: " << m44d_3.to_string() << endl;
707 m44d_3 = m44d_1 + m44d_2;
708 cout << setw(40) << "m44d_3 = m44d_1 + m44d_2: " << m44d_3.to_string() << endl;
710 m44d_3 += m44d_1;
711 cout << setw(40) << "m44d_3 += m44d_1: " << m44d_3.to_string() << endl;
712 }
714 {
715 cout << "===============================================================" << endl <<
716 "Testing Maxtrix subtraction" << endl;
717 Matrix22i m22i_1(1, 2, 3, 4);
718 Matrix22i m22i_2(5, 6, 7, 8);
719 Matrix22i m22i_3(0);
721 cout << setw(40) << "m22i_1: " << m22i_1.to_string() << endl;
722 cout << setw(40) << "m22i_2: " << m22i_2.to_string() << endl;
723 cout << setw(40) << "m22i_3: " << m22i_3.to_string() << endl;
724 m22i_3 = m22i_1 - m22i_2;
725 cout << setw(40) << "m22i_3 = m22i_1 - m22i_2: " << m22i_3.to_string() << endl;
727 m22i_3 -= m22i_1;
728 cout << setw(40) << "m22i_3 -= m22i_1: " << m22i_3.to_string() << endl;
730 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
731 Matrix33f m33f_2(10.10f, 11.11f, 12.12f, 13.13f, 14.14f, 15.15f, 16.16f, 17.17f, 18.18f);
732 Matrix33f m33f_3(0.0f);
734 cout << setw(40) << "m33f_1: " << m33f_1.to_string() << endl;
735 cout << setw(40) << "m33f_2: " << m33f_2.to_string() << endl;
736 cout << setw(40) << "m33f_3: " << m33f_3.to_string() << endl;
737 m33f_3 = m33f_1 - m33f_2;
738 cout << setw(40) << "m33f_3 = m33f_1 - m33f_2: " << m33f_3.to_string() << endl;
740 m33f_3 -= m33f_1;
741 cout << setw(40) << "m33f_3 -= m33f_1: " << m33f_3.to_string() << endl;
743 Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11,
744 12.12, 13.13, 14.14, 15.15, 16.16);
745 Matrix44d m44d_2(16.16, 17.17, 18.18, 19.19,
746 20.20, 21.21, 22.22, 23.23,
747 24.24, 25.25, 26.26, 27.27,
748 28.28, 29.29, 30.30, 31.31);
749 Matrix44d m44d_3(0.0);
751 cout << setw(40) << "m44d_1: " << m44d_1.to_string() << endl;
752 cout << setw(40) << "m44d_2: " << m44d_2.to_string() << endl;
753 cout << setw(40) << "m44d_3: " << m44d_3.to_string() << endl;
754 m44d_3 = m44d_1 - m44d_2;
755 cout << setw(40) << "m44d_3 = m44d_1 - m44d_2: " << m44d_3.to_string() << endl;
757 m44d_3 -= m44d_1;
758 cout << setw(40) << "m44d_3 -= m44d_1: " << m44d_3.to_string() << endl;
759 }
761 {
762 cout << "===============================================================" << endl <<
763 "Testing Matrix scalar multiplication" << endl;
764 Matrix22i m22i_1(1, 2, 3, 4);
765 Matrix22i m22i_2(0);
766 int i = 2;
768 cout << setw(40) << "i: " << i << endl;
769 cout << setw(40) << "m22i_1: " << m22i_1.to_string() << endl;
770 cout << setw(40) << "m22i_2: " << m22i_2.to_string() << endl;
771 m22i_2 = m22i_1 *i;
772 cout << setw(40) << "m22i_2 = m22i_1 * i: " << m22i_2.to_string() << endl;
773 m22i_2 = i * m22i_1;
774 cout << setw(40) << "m22i_2 = i * m22i_1: " << m22i_2.to_string() << endl;
775 m22i_2 *= i;
776 cout << setw(40) << "m22i_2 *= i: " << m22i_2.to_string() << endl;
778 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
779 Matrix33f m33f_2(0.0f);
780 float f = 2.0f;
782 cout << setw(40) << "f: " << f << endl;
783 cout << setw(40) << "m33f_1: " << m33f_1.to_string() << endl;
784 cout << setw(40) << "m33f_2: " << m33f_2.to_string() << endl;
785 m33f_2 = m33f_1 * f;
786 cout << setw(40) << "m33f_2 = m33f_1 * f: " << m33f_2.to_string() << endl;
787 m33f_2 = f * m33f_1;
788 cout << setw(40) << "m33f_2 = f * m33f_1: " << m33f_2.to_string() << endl;
789 m33f_2 *= f;
790 cout << setw(40) << "m33f_2 *= f: " << m33f_2.to_string() << endl;
792 Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11,
793 12.12, 13.13, 14.14, 15.15, 16.16);
794 Matrix44d m44d_2(0.0);
795 double d = 2.0f;
797 cout << setw(40) << "d: " << d << endl;
798 cout << setw(40) << "m44d_1: " << m44d_1.to_string() << endl;
799 cout << setw(40) << "m44d_2: " << m44d_2.to_string() << endl;
800 m44d_2 = m44d_1 * d;
801 cout << setw(40) << "m44d_2 = m44d_1 * d: " << m44d_2.to_string() << endl;
802 m44d_2 = d * m44d_1;
803 cout << setw(40) << "m44d_2 = d * m44d_1: " << m44d_2.to_string() << endl;
804 m44d_2 *= d;
805 cout << setw(40) << "m44d_2 *= d: " << m44d_2.to_string() << endl;
806 }
808 {
809 cout << "===============================================================" << endl <<
810 "Testing Matrix scalar division" << endl;
811 Matrix22i m22i_1(1, 2, 3, 4);
812 Matrix22i m22i_2(0);
813 int i = 2;
815 cout << setw(40) << "i: " << i << endl;
816 cout << setw(40) << "m22i_1: " << m22i_1.to_string() << endl;
817 cout << setw(40) << "m22i_2: " << m22i_2.to_string() << endl;
818 m22i_2 = m22i_1 / i;
819 cout << setw(40) << "m22i_2 = m22i_1 / i: " << m22i_2.to_string() << endl;
820 m22i_1 /= i;
821 cout << setw(40) << "m22i_1 /= i: " << m22i_2.to_string() << endl;
823 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
824 Matrix33f m33f_2(0.0f);
825 float f = 2.0f;
827 cout << setw(40) << "f: " << f << endl;
828 cout << setw(40) << "m33f_1: " << m33f_1.to_string() << endl;
829 cout << setw(40) << "m33f_2: " << m33f_2.to_string() << endl;
830 m33f_2 = m33f_1 / f;
831 cout << setw(40) << "m33f_2 = m33f_1 / f: " << m33f_2.to_string() << endl;
832 m33f_1 /= f;
833 cout << setw(40) << "m33f_1 /= f: " << m33f_2.to_string() << endl;
835 Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11,
836 12.12, 13.13, 14.14, 15.15, 16.16);
837 Matrix44d m44d_2(0.0);
838 double d = 2.0f;
840 cout << setw(40) << "d: " << d << endl;
841 cout << setw(40) << "m44d_1: " << m44d_1.to_string() << endl;
842 cout << setw(40) << "m44d_2: " << m44d_2.to_string() << endl;
843 m44d_2 = m44d_1 / d;
844 cout << setw(40) << "m44d_2 = m44d_1 / d: " << m44d_2.to_string() << endl;
845 m44d_1 /= d;
846 cout << setw(40) << "m44d_1 /= d: " << m44d_2.to_string() << endl;
847 }
849 {
850 cout << "===============================================================" << endl <<
851 "Testing Maxtrix multiplication" << endl;
852 Matrix22i m22i_1(1, 2, 3, 4);
853 Matrix22i m22i_2(5, 6, 7, 8);
854 Matrix22i m22i_3(0);
856 cout << setw(40) << "m22i_1: " << m22i_1.to_string() << endl;
857 cout << setw(40) << "m22i_2: " << m22i_2.to_string() << endl;
858 cout << setw(40) << "m22i_3: " << m22i_3.to_string() << endl;
859 m22i_3 = m22i_1 * m22i_2;
860 cout << setw(40) << "m22i_3 = m22i_1 * m22i_2: " << m22i_3.to_string() << endl;
862 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
863 Matrix33f m33f_2(10.10f, 11.11f, 12.12f, 13.13f, 14.14f, 15.15f, 16.16f, 17.17f, 18.18f);
864 Matrix33f m33f_3(0.0f);
866 cout << setw(40) << "m33f_1: " << m33f_1.to_string() << endl;
867 cout << setw(40) << "m33f_2: " << m33f_2.to_string() << endl;
868 cout << setw(40) << "m33f_3: " << m33f_3.to_string() << endl;
869 m33f_3 = m33f_1 * m33f_2;
870 cout << setw(40) << "m33f_3 = m33f_1 * m33f_2: " << m33f_3.to_string() << endl;
872 Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11,
873 12.12, 13.13, 14.14, 15.15, 16.16);
874 Matrix44d m44d_2(16.16, 17.17, 18.18, 19.19,
875 20.20, 21.21, 22.22, 23.23,
876 24.24, 25.25, 26.26, 27.27,
877 28.28, 29.29, 30.30, 31.31);
878 Matrix44d m44d_3(0.0);
880 cout << setw(40) << "m44d_1: " << m44d_1.to_string() << endl;
881 cout << setw(40) << "m44d_2: " << m44d_2.to_string() << endl;
882 cout << setw(40) << "m44d_3: " << m44d_3.to_string() << endl;
883 m44d_3 = m44d_1 * m44d_2;
884 cout << setw(40) << "m44d_3 = m44d_1 * m44d_2: " << m44d_3.to_string() << endl;
885 }
887 {
888 cout << "===============================================================" << endl <<
889 "Testing Maxtrix det" << endl;
890 Matrix22i m22i_1(1, 2, 3, 4);
891 double d;
893 cout << setw(40) << "m22i_1: " << m22i_1.to_string() << endl;
894 d = det(m22i_1);
895 cout << setw(40) << "d = det(m22i_1): " << d << endl;
897 // Note: singular matrix. The real determinant is exactly zero.
898 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
900 cout << setw(40) << "m33f_1: " << m33f_1.to_string() << endl;
901 d = det(m33f_1);
902 cout << setw(40) << "d = det(m33f_1): " << d << endl;
904 // Note: singular matrix. The real determinant is exactly zero.
905 Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11,
906 12.12, 13.13, 14.14, 15.15, 16.16);
908 cout << setw(40) << "m44d_1: " << m44d_1.to_string() << endl;
909 d = det(m44d_1);
910 cout << setw(40) << "d = det(m44d_1): " << d << endl;
912 }
914 {
915 cout << "===============================================================" << endl <<
916 "Testing Maxtrix transpose" << endl;
917 Matrix22i m22i_1(1, 2, 3, 4);
918 Matrix22i m22i_2;
920 cout << setw(40) << "m22i_1: " << m22i_1.to_string() << endl;
921 m22i_2 = transpose(m22i_1);
922 cout << setw(40) << "m22i_2 = transpose(m22i_1): " << m22i_2.to_string() << endl;
924 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
925 Matrix33f m33f_2(0.0f);
927 cout << setw(40) << "m33f_1: " << m33f_1.to_string() << endl;
928 m33f_2 = transpose(m33f_1);
929 cout << setw(40) << "m33f_2 = transpose(m33f_1): " << m33f_2.to_string() << endl;
931 Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11,
932 12.12, 13.13, 14.14, 15.15, 16.16);
933 Matrix44d m44d_2(0.0);
935 cout << setw(40) << "m44d_1: " << m44d_1.to_string() << endl;
936 m44d_2 = transpose(m44d_1);
937 cout << setw(40) << "m44d_2 = transpose(m44d_1): " << m44d_2.to_string() << endl;
938 }
940 {
941 cout << "===============================================================" << endl <<
942 "Testing Maxtrix setidentity" << endl;
943 Matrix22i m22i_1(1, 2, 3, 4);
945 cout << setw(40) << "m22i_1: " << m22i_1.to_string() << endl;
946 m22i_1.setidentity();
947 cout << setw(40) << "m22i_1.setidentity(): " << m22i_1.to_string() << endl;
949 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
951 cout << setw(40) << "m33f_1: " << m33f_1.to_string() << endl;
952 m33f_1.setidentity();
953 cout << setw(40) << "m33f_1.setidentity(): " << m33f_1.to_string() << endl;
955 Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11,
956 12.12, 13.13, 14.14, 15.15, 16.16);
958 cout << setw(40) << "m44d_1: " << m44d_1.to_string() << endl;
959 m44d_1.setidentity();
960 cout << setw(40) << "m44d_1.setidentity(): " << m44d_1.to_string() << endl;
961 }
963 {
964 cout << "===============================================================" << endl <<
965 "Testing Matrix getrow() and getcol()" << endl;
966 Matrix22i m22i_1(1, 2, 3, 4);
967 Vector2i v2i_1(0);
969 cout << setw(40) << "m22i_1: " << m22i_1.to_string() << endl;
970 v2i_1 = m22i_1.getrow(0);
971 cout << setw(40) << "v2i_1 = m22i_1.getrow(0): " << v2i_1.to_string() << endl;
972 v2i_1 = m22i_1.getrow(1);
973 cout << setw(40) << "v2i_1 = m22i_1.getrow(1): " << v2i_1.to_string() << endl;
974 v2i_1 = m22i_1.getcol(0);
975 cout << setw(40) << "v2i_1 = m22i_1.getcol(0): " << v2i_1.to_string() << endl;
976 v2i_1 = m22i_1.getcol(1);
977 cout << setw(40) << "v2i_1 = m22i_1.getcol(1): " << v2i_1.to_string() << endl;
979 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
980 Vector3f v3f_1(0);
982 cout << setw(40) << "m33f_1: " << m33f_1.to_string() << endl;
983 v3f_1 = m33f_1.getrow(0);
984 cout << setw(40) << "v3f_1 = m33f_1.getrow(0): " << v3f_1.to_string() << endl;
985 v3f_1 = m33f_1.getrow(1);
986 cout << setw(40) << "v3f_1 = m33f_1.getrow(1): " << v3f_1.to_string() << endl;
987 v3f_1 = m33f_1.getrow(2);
988 cout << setw(40) << "v3f_1 = m33f_1.getrow(2): " << v3f_1.to_string() << endl;
989 v3f_1 = m33f_1.getcol(0);
990 cout << setw(40) << "v3f_1 = m33f_1.getcol(0): " << v3f_1.to_string() << endl;
991 v3f_1 = m33f_1.getcol(1);
992 cout << setw(40) << "v3f_1 = m33f_1.getcol(1): " << v3f_1.to_string() << endl;
993 v3f_1 = m33f_1.getcol(2);
994 cout << setw(40) << "v3f_1 = m33f_1.getcol(2): " << v3f_1.to_string() << endl;
996 Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11,
997 12.12, 13.13, 14.14, 15.15, 16.16);
998 Vector4d v4d_1(0);
1000 cout << setw(40) << "m44d_1: " << m44d_1.to_string() << endl;
1001 v4d_1 = m44d_1.getrow(0);
1002 cout << setw(40) << "v4d_1 = m44d_1.getrow(0): " << v4d_1.to_string() << endl;
1003 v4d_1 = m44d_1.getrow(1);
1004 cout << setw(40) << "v4d_1 = m44d_1.getrow(1): " << v4d_1.to_string() << endl;
1005 v4d_1 = m44d_1.getrow(2);
1006 cout << setw(40) << "v4d_1 = m44d_1.getrow(2): " << v4d_1.to_string() << endl;
1007 v4d_1 = m44d_1.getrow(3);
1008 cout << setw(40) << "v4d_1 = m44d_1.getrow(3): " << v4d_1.to_string() << endl;
1010 v4d_1 = m44d_1.getcol(0);
1011 cout << setw(40) << "v4d_1 = m44d_1.getcol(0): " << v4d_1.to_string() << endl;
1012 v4d_1 = m44d_1.getcol(1);
1013 cout << setw(40) << "v4d_1 = m44d_1.getcol(1): " << v4d_1.to_string() << endl;
1014 v4d_1 = m44d_1.getcol(2);
1015 cout << setw(40) << "v4d_1 = m44d_1.getcol(2): " << v4d_1.to_string() << endl;
1016 v4d_1 = m44d_1.getcol(3);
1017 cout << setw(40) << "v4d_1 = m44d_1.getcol(3): " << v4d_1.to_string() << endl;
1021 cout << "===============================================================" << endl <<
1022 "Testing Matrix setrow() and setcol()" << endl;
1023 Matrix22i m22i_1;
1024 Vector2i v2i_1(2, 3);
1026 m22i_1.setidentity();
1027 cout << setw(40) << "m22i_1: " << m22i_1.to_string() << endl;
1028 m22i_1.setrow(0, v2i_1);
1029 cout << setw(40) << "m22i_1.setrow(0, v2i_1): " << m22i_1.to_string() << endl;
1031 m22i_1.setidentity();
1032 m22i_1.setrow(1, v2i_1);
1033 cout << setw(40) << "m22i_1.setrow(1, v2i_1): " << m22i_1.to_string() << endl;
1035 m22i_1.setidentity();
1036 m22i_1.setrow(1, 4, 5);
1037 cout << setw(40) << "m22i_1.setrow(1, 4, 5): " << m22i_1.to_string() << endl;
1039 m22i_1.setidentity();
1040 m22i_1.setcol(0, v2i_1);
1041 cout << setw(40) << "m22i_1.setcol(0, v2i_1): " << m22i_1.to_string() << endl;
1043 m22i_1.setidentity();
1044 m22i_1.setcol(1, v2i_1);
1045 cout << setw(40) << "m22i_1.setcol(1, v2i_1): " << m22i_1.to_string() << endl;
1047 m22i_1.setidentity();
1048 m22i_1.setcol(1, 4, 5);
1049 cout << setw(40) << "m22i_1.setcol(1, 4, 5): " << m22i_1.to_string() << endl;
1051 Matrix33f m33f_1;
1052 Vector3f v3f_1(0);
1054 m33f_1.setidentity();
1055 cout << setw(40) << "m33f_1: " << m33f_1.to_string() << endl;
1056 m33f_1.setrow(0, v3f_1);
1057 cout << setw(40) << "m33f_1.setrow(0, v3f_1): " << m33f_1.to_string() << endl;
1059 m33f_1.setidentity();
1060 m33f_1.setrow(1, v3f_1);
1061 cout << setw(40) << "m33f_1.setrow(1, v3f_1): " << m33f_1.to_string() << endl;
1063 m33f_1.setidentity();
1064 m33f_1.setrow(1, 2.2f, 3.3f, 4.4f);
1065 cout << setw(40) << "m33f_1.setrow(1, 2.2f, 3.3f, 4.4f): "
1066 << m33f_1.to_string() << endl;
1068 m33f_1.setidentity();
1069 m33f_1.setcol(0, v3f_1);
1070 cout << setw(40) << "m33f_1.setcol(0, v3f_1): " << m33f_1.to_string() << endl;
1072 m33f_1.setidentity();
1073 m33f_1.setcol(1, v3f_1);
1074 cout << setw(40) << "m33f_1.setcol(1, v3f_1): " << m33f_1.to_string() << endl;
1076 m33f_1.setidentity();
1077 m33f_1.setcol(1, 2.2f, 3.3f, 4.4f);
1078 cout << setw(40) << "m33f_1.setcol(1, 2.2f, 3.3f, 4.4f: "
1079 << m33f_1.to_string() << endl;
1081 Matrix44d m44d_1;
1082 Vector4d v4d_1(0);
1084 m44d_1.setidentity();
1085 cout << setw(40) << "m44d_1: " << m44d_1.to_string() << endl;
1086 m44d_1.setrow(0, v4d_1);
1087 cout << setw(40) << "m44d_1.setrow(0, v4d_1): " << m44d_1.to_string() << endl;
1089 m44d_1.setidentity();
1090 m44d_1.setrow(1, v4d_1);
1091 cout << setw(40) << "m44d_1.setrow(1, v4d_1): " << m44d_1.to_string() << endl;
1093 m44d_1.setidentity();
1094 m44d_1.setrow(1, 2.2, 3.3, 4.4, 5.5);
1095 cout << setw(40) << "m44d_1.setrow(1, 2.2, 3.3, 4.4, 5.5): "
1096 << m44d_1.to_string() << endl;
1098 m44d_1.setidentity();
1099 m44d_1.setcol(0, v4d_1);
1100 cout << setw(40) << "m44d_1.setcol(0, v4d_1): " << m44d_1.to_string() << endl;
1102 m44d_1.setidentity();
1103 m44d_1.setcol(1, v4d_1);
1104 cout << setw(40) << "m44d_1.setcol(1, v4d_1): " << m44d_1.to_string() << endl;
1106 m44d_1.setidentity();
1107 m44d_1.setcol(1, 2.2, 3.3, 4.4, 5.5);
1108 cout << setw(40) << "m44d_1.setcol(1, 2.2, 3.3, 4.4, 5.5: "
1109 << m44d_1.to_string() << endl;
1113 ////////////////////////////////////////////////////////////////////////////////
1114 void test_all(void)
1116 test_vector();
1117 test_matrix();
1120 ////////////////////////////////////////////////////////////////////////////////
1121 void show_menu(void)
1123 cout << endl << endl
1124 << "Test what?" << endl
1125 << "0) All" << endl << endl
1126 << "1) Vector" << endl
1127 << "2) Matrix" << endl
1128 << endl
1129 << "99 Quit" << endl;
1132 ////////////////////////////////////////////////////////////////////////////////
1133 int main (int argc, char * argv[])
1135 int retval = 0;
1137 test_all();
1138 return 0;
1140 try
1142 int choice = -1;
1144 while (choice != 99)
1146 show_menu();
1147 cin >> choice;
1148 if(!cin)
1150 cin.clear();
1151 cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
1153 if (choice != 99)
1155 switch (choice)
1157 case 0:
1158 test_all();
1159 break;
1160 case 1:
1161 test_vector();
1162 break;
1163 case 2:
1164 test_matrix();
1165 break;
1166 default:
1167 cout << "Unrecognized choice. Please try again." << endl;
1169 choice = -1;
1173 catch (const std::exception & error)
1175 string e = "Caught exception: ";
1176 e += error.what();
1177 cerr << e << endl;
1178 retval = 1;
1181 return retval;;
1185 #endif