view src/main.cpp @ 22:b3e035767eb0

WIP - Conversion to new test suite started, but not yet complete.
author Eris Caffee <discordia@eldalin.com>
date Thu, 11 Jun 2015 08:18:59 -0500
parents
children
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 ////////////////////////////////////////////////////////////////////////////////
12 void test_vector(void)
13 {
14 string s1, s2;
16 {
17 cout << "===============================================================" << endl <<
18 "Testing Vector constructors" << endl;
19 Vector2i v2i_1(0);
20 Vector2i v2i_2(1);
21 Vector2i v2i_3(1, 2);
22 Vector2i v2i_4(v2i_3);
24 cout << setw(40) << "v2i_1: " << v2i_1.to_string(s1) << endl;
25 cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl;
26 cout << setw(40) << "v2i_3: " << v2i_3.to_string(s1) << endl;
27 cout << setw(40) << "v2i_4: " << v2i_4.to_string(s1) << endl;
29 Vector3f v3f_1(0);
30 Vector3f v3f_2(1);
31 Vector3f v3f_3(1, 2, 3);
32 Vector3f v3f_4(v3f_3);
34 cout << setw(40) << "v3f_1: " << v3f_1.to_string(s1) << endl;
35 cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl;
36 cout << setw(40) << "v3f_3: " << v3f_3.to_string(s1) << endl;
37 cout << setw(40) << "v3f_4: " << v3f_4.to_string(s1) << endl;
39 Vector4d v4d_1(0);
40 Vector4d v4d_2(1);
41 Vector4d v4d_3(1, 2, 3, 4);
42 Vector4d v4d_4(v4d_3);
44 cout << setw(40) << "v4d_1: " << v4d_1.to_string(s1) << endl;
45 cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl;
46 cout << setw(40) << "v4d_3: " << v4d_3.to_string(s1) << endl;
47 cout << setw(40) << "v4d_4: " << v4d_4.to_string(s1) << endl;
48 }
50 {
51 cout << "===============================================================" << endl <<
52 "Testing Vector array indexing" << endl;
53 Vector2i v2i(1,2);
54 Vector3f v3f(1.1f, 2.2f, 3.3f);
55 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
57 cout << setw(40) << "v2i: " << v2i[0] << ", " << v2i[1] << endl;
58 cout << setw(40) << "v3f: " << v3f[0] << ", " << v3f[1] << ", " << v3f[2] << endl;
59 cout << setw(40) << "v4d: " << v4d[0] << ", " << v4d[1] << ", " << v4d[2] << ", " << v4d[3] << endl;
60 }
62 {
63 cout << "===============================================================" << endl <<
64 "Testing Vector assignment" << endl;
65 Vector2i v2i(1,2);
66 Vector3f v3f(1.1f, 2.2f, 3.3f);
67 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
68 Vector2i v2i_2(0);
69 Vector3f v3f_2(0);
70 Vector4d v4d_2(0);
72 cout << "Before assignment" << endl;
73 cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl;
74 cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl;
75 cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl;
76 cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl;
77 cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl;
78 cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl;
80 v2i_2 = v2i;
81 v3f_2 = v3f;
82 v4d_2 = v4d;
83 cout << "After assignment by =" << endl;
84 cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl;
85 cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl;
86 cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl;
88 v2i_2.assign(1, 1);
89 v3f_2.assign(2.2, 2.2, 2.2);
90 v4d_2.assign(3.3, 3.3, 3.3, 3.3);
91 cout << "After assignment by assign()" << endl;
92 cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl;
93 cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl;
94 cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl;
95 }
97 {
98 cout << "===============================================================" << endl <<
99 "Testing Vector comparison" << endl;
100 Vector2i v2i(1,2);
101 Vector3f v3f(1.1f, 2.2f, 3.3f);
102 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
103 Vector2i v2i_2(1,2);
104 Vector3f v3f_2(1.1f, 2.2f, 3.3f);
105 Vector4d v4d_2(1.1, 2.2, 3.3, 4.4);
106 Vector2i v2i_3(0);
107 Vector3f v3f_3(0);
108 Vector4d v4d_3(0);
110 cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl;
111 cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl;
112 cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl;
113 cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl;
114 cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl;
115 cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl;
116 cout << setw(40) << "v2i_3: " << v2i_3.to_string(s1) << endl;
117 cout << setw(40) << "v3f_3: " << v3f_3.to_string(s1) << endl;
118 cout << setw(40) << "v4d_3: " << v4d_3.to_string(s1) << endl;
119 cout << boolalpha;
120 cout << setw(40) << "v2i == v2i_2: " << (v2i == v2i_2) << endl;
121 cout << setw(40) << "v2i == v2i_3: " << (v2i == v2i_3) << endl;
122 cout << setw(40) << "v2i != v2i_2: " << (v2i != v2i_2) << endl;
123 cout << setw(40) << "v2i != v2i_3: " << (v2i != v2i_3) << endl;
124 cout << setw(40) << "v3f == v3f_2: " << (v3f == v3f_2) << endl;
125 cout << setw(40) << "v3f == v3f_3: " << (v3f == v3f_3) << endl;
126 cout << setw(40) << "v3f != v3f_2: " << (v3f != v3f_2) << endl;
127 cout << setw(40) << "v3f != v3f_3: " << (v3f != v3f_3) << endl;
128 cout << setw(40) << "v4d == v4d_2: " << (v4d == v4d_2) << endl;
129 cout << setw(40) << "v4d == v4d_3: " << (v4d == v4d_3) << endl;
130 cout << setw(40) << "v4d != v4d_2: " << (v4d != v4d_2) << endl;
131 cout << setw(40) << "v4d != v4d_3: " << (v4d != v4d_3) << endl;
132 }
134 {
135 cout << "===============================================================" << endl <<
136 "Testing Vector addition" << endl;
137 Vector2i v2i(1,2);
138 Vector3f v3f(1.1f, 2.2f, 3.3f);
139 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
140 Vector2i v2i_2(3,4);
141 Vector3f v3f_2(4.4, 5.5, 6.6);
142 Vector4d v4d_2(5.5, 6.6, 7.7, 8.8);
143 Vector2i v2i_3(0);
144 Vector3f v3f_3(0);
145 Vector4d v4d_3(0);
147 cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl;
148 cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl;
149 cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl;
150 cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl;
151 cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl;
152 cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl;
153 v2i_3 = v2i + v2i_2;
154 v3f_3 = v3f + v3f_2;
155 v4d_3 = v4d + v4d_2;
156 cout << setw(40) << "v2i_3 = v2i + v2i_2: " << v2i_3.to_string(s1) << endl;
157 cout << setw(40) << "v3f_3 = v3f + v3f_2: " << v3f_3.to_string(s1) << endl;
158 cout << setw(40) << "v4d_3 = v4d + v4d_2: " << v4d_3.to_string(s1) << endl;
159 v2i_3 += v2i_2;
160 v3f_3 += v3f_2;
161 v4d_3 += v4d_3;
162 cout << setw(40) << "v2i_3 += v2i_2: " << v2i_3.to_string(s1) << endl;
163 cout << setw(40) << "v3f_3 += v3f_2: " << v3f_3.to_string(s1) << endl;
164 cout << setw(40) << "v4d_3 += v4d_3: " << v4d_3.to_string(s1) << endl;
165 }
167 {
168 cout << "===============================================================" << endl <<
169 "Testing Vector subtraction" << endl;
170 Vector2i v2i(1,2);
171 Vector3f v3f(1.1f, 2.2f, 3.3f);
172 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
173 Vector2i v2i_2(3,4);
174 Vector3f v3f_2(4.4, 5.5, 6.6);
175 Vector4d v4d_2(5.5, 6.6, 7.7, 8.8);
176 Vector2i v2i_3(0);
177 Vector3f v3f_3(0);
178 Vector4d v4d_3(0);
180 cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl;
181 cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl;
182 cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl;
183 cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl;
184 cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl;
185 cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl;
186 v2i_3 = v2i - v2i_2;
187 v3f_3 = v3f - v3f_2;
188 v4d_3 = v4d - v4d_2;
189 cout << setw(40) << "v2i_3 = v2i - v2i_2: " << v2i_3.to_string(s1) << endl;
190 cout << setw(40) << "v3f_3 = v3f - v3f_2: " << v3f_3.to_string(s1) << endl;
191 cout << setw(40) << "v4d_3 = v4d - v4d_2: " << v4d_3.to_string(s1) << endl;
192 v2i_3 -= v2i_2;
193 v3f_3 -= v3f_2;
194 v4d_3 -= v4d_3;
195 cout << setw(40) << "v2i_3 -= v2i_2: " << v2i_3.to_string(s1) << endl;
196 cout << setw(40) << "v3f_3 -= v3f_2: " << v3f_3.to_string(s1) << endl;
197 cout << setw(40) << "v4d_3 -= v4d_3: " << v4d_3.to_string(s1) << endl;
198 }
200 {
201 cout << "===============================================================" << endl <<
202 "Testing Vector scalar multiplication" << endl;
203 Vector2i v2i(1,2);
204 Vector3f v3f(1.1f, 2.2f, 3.3f);
205 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
206 Vector2i v2i_2(0);
207 Vector3f v3f_2(0);
208 Vector4d v4d_2(0);
209 int i = 2;
210 float f = 2.f;
211 double d = 2.0;
213 cout << setw(40) << "i: " << i << endl;
214 cout << setw(40) << "f: " << f << endl;
215 cout << setw(40) << "d: " << d << endl;
216 cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl;
217 cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl;
218 cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl;
219 cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl;
220 cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl;
221 cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl;
222 v2i_2 = v2i * i;
223 v3f_2 = v3f * f;
224 v4d_2 = v4d * d;
225 cout << setw(40) << "v2i_2 = v2i * i: " << v2i_2.to_string(s1) << endl;
226 cout << setw(40) << "v3f_2 = v3f * f: " << v3f_2.to_string(s1) << endl;
227 cout << setw(40) << "v4d_2 = v4d * d: " << v4d_2.to_string(s1) << endl;
228 v2i_2 *= i;
229 v3f_2 *= f;
230 v4d_2 *= d;
231 cout << setw(40) << "v2i_2 *= i: " << v2i_2.to_string(s1) << endl;
232 cout << setw(40) << "v3f_2 *= f: " << v3f_2.to_string(s1) << endl;
233 cout << setw(40) << "v4d_2 *= d: " << v4d_2.to_string(s1) << endl;
234 }
236 {
237 cout << "===============================================================" << endl <<
238 "Testing Vector scalar division" << endl;
239 Vector2i v2i(1,2);
240 Vector3f v3f(1.1f, 2.2f, 3.3f);
241 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
242 Vector2i v2i_2(0);
243 Vector3f v3f_2(0);
244 Vector4d v4d_2(0);
245 int i = 2;
246 float f = 2.f;
247 double d = 2.0;
249 cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl;
250 cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl;
251 cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl;
252 cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl;
253 cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl;
254 cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl;
255 v2i_2 = v2i / i;
256 v3f_2 = v3f / f;
257 v4d_2 = v4d / d;
258 cout << setw(40) << "v2i_2 = v2i / i: " << v2i_2.to_string(s1) << endl;
259 cout << setw(40) << "v3f_2 = v3f / f: " << v3f_2.to_string(s1) << endl;
260 cout << setw(40) << "v4d_2 = v4d / d: " << v4d_2.to_string(s1) << endl;
261 v2i_2 /= i;
262 v3f_2 /= f;
263 v4d_2 /= d;
264 cout << setw(40) << "v2i_2 /= i: " << v2i_2.to_string(s1) << endl;
265 cout << setw(40) << "v3f_2 /= f: " << v3f_2.to_string(s1) << endl;
266 cout << setw(40) << "v4d_2 /= d: " << v4d_2.to_string(s1) << endl;
267 }
269 {
270 cout << "===============================================================" << endl <<
271 "Testing Vector cross product" << endl;
272 Vector3f v3f(1.1f, 2.2f, 3.3f);
273 Vector3f v3f_2(4.4, 5.5, 6.6);
274 Vector3f v3f_3(0);
275 Vector3f v3f_4(0);
276 cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl;
277 cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl;
278 cout << setw(40) << "v3f_3: " << v3f_3.to_string(s1) << endl;
279 v3f.cross(v3f_2, v3f_3);
280 cout << setw(40) << "v3f.cross(v3f_2, v3f_3): " << v3f_3.to_string(s1) << endl;
281 v3f_4 = 2.0 * v3f.cross(v3f_2);
282 cout << setw(40) << "2.0 * v3f.cross(v3f_2,): " << v3f_4.to_string(s1) << endl;
283 v3f_4.assign(0,0,0);
284 v3f.cross(v3f_2, v3f_4);
285 cout << setw(40) << "v3f.cross(v3f_2, v3f_4): " << v3f_4.to_string(s1) << endl;
286 }
288 {
289 cout << "===============================================================" << endl <<
290 "Testing Vector dot product" << endl;
291 Vector2i v2i(1, 2);
292 Vector2i v2i_2(3, 4);
293 Vector3f v3f(1.1f, 2.2f, 3.3f);
294 Vector3f v3f_2(4.4, 5.5, 6.6);
295 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
296 Vector4d v4d_2(5.5, 6.6, 7.7, 8.8);
297 int i;
298 float f;
299 double d;
300 cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl;
301 cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl;
302 cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl;
303 cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl;
304 cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl;
305 cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl;
306 i = v2i.dot(v2i_2);
307 cout << setw(40) << "i = v2i.dot(v2i_2): " << i << endl;
308 f = v3f.dot(v3f_2);
309 cout << setw(40) << "f = v3f.dot(v3f_2): " << f << endl;
310 d = v4d.dot(v4d_2);
311 cout << setw(40) << "d = v4d.dot(v4d_2): " << d << endl;
312 }
314 {
315 cout << "===============================================================" << endl <<
316 "Testing Vector length" << endl;
317 Vector2i v2i(1, 2);
318 Vector3f v3f(1.1f, 2.2f, 3.3f);
319 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
320 cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl;
321 cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl;
322 cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl;
323 cout << setw(40) << "v2i.length(): " << v2i.length() << endl;
324 cout << setw(40) << "v3f.length(): " << v3f.length() << endl;
325 cout << setw(40) << "v4d.length(): " << v4d.length() << endl;
326 }
328 {
329 cout << "===============================================================" << endl <<
330 "Testing Vector normalize" << endl;
331 Vector2f v2f(1.1, 2.2);
332 Vector3f v3f(1.1f, 2.2f, 3.3f);
333 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
334 cout << setw(40) << "v2f: " << v2f.to_string(s1) << endl;
335 cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl;
336 cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl;
337 v2f.normalize();
338 cout << setw(40) << "v2f.normalize() " << v2f.to_string(s1) << endl;
339 v3f.normalize();
340 cout << setw(40) << "v3f.normalize() " << v3f.to_string(s1) << endl;
341 v4d.normalize();
342 cout << setw(40) << "v4d.normalize() " << v4d.to_string(s1) << endl;
343 cout << setw(40) << "v2f.length(): " << v2f.length() << endl;
344 cout << setw(40) << "v3f.length(): " << v3f.length() << endl;
345 cout << setw(40) << "v4d.length(): " << v4d.length() << endl;
346 }
348 {
349 cout << "===============================================================" << endl <<
350 "Testing Vector get_angle" << endl;
351 Vector2i v2i(1, 2);
352 Vector2i v2i_2(3, 4);
353 Vector3f v3f(1.1f, 2.2f, 3.3f);
354 Vector3f v3f_2(4.4, 5.5, 6.6);
355 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
356 Vector4d v4d_2(5.5, 6.6, 7.7, 8.8);
357 double d;
358 cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl;
359 cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl;
360 cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl;
361 cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl;
362 cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl;
363 cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl;
364 d = v2i.get_angle(v2i_2);
365 cout << setw(40) << "d = v2i.get_angle(v2i_2): " << d << endl;
366 d = v3f.get_angle(v3f_2);
367 cout << setw(40) << "d = v3f.get_angle(v3f_2): " << d << endl;
368 d = v4d.get_angle(v4d_2);
369 cout << setw(40) << "d = v4d.get_angle(v4d_2): " << d << endl;
370 }
372 {
373 cout << "===============================================================" << endl <<
374 "Testing Vector get_anglen" << endl;
375 Vector2f v2f(1.1, 2.2);
376 Vector2f v2f_2(3.3, 4.4);
377 Vector3f v3f(1.1f, 2.2f, 3.3f);
378 Vector3f v3f_2(4.4, 5.5, 6.6);
379 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
380 Vector4d v4d_2(5.5, 6.6, 7.7, 8.8);
381 double d;
382 v2f.normalize();
383 v2f_2.normalize();
384 v3f.normalize();
385 v3f_2.normalize();
386 v4d.normalize();
387 v4d_2.normalize();
388 cout << setw(40) << "v2f: " << v2f.to_string(s1) << endl;
389 cout << setw(40) << "v2f_2: " << v2f_2.to_string(s1) << endl;
390 cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl;
391 cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl;
392 cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl;
393 cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl;
394 d = v2f.get_anglen(v2f_2);
395 cout << setw(40) << "d = v2f.get_anglen(v2f_2): " << d << endl;
396 d = v3f.get_anglen(v3f_2);
397 cout << setw(40) << "d = v3f.get_anglen(v3f_2): " << d << endl;
398 d = v4d.get_anglen(v4d_2);
399 cout << setw(40) << "d = v4d.get_anglen(v4d_2): " << d << endl;
400 }
402 {
403 cout << "===============================================================" << endl <<
404 "Testing Vector get_proj" << endl;
405 Vector2f v2f(1.1, 2.2);
406 Vector2f v2f_2(3.3, 4.4);
407 Vector2f v2f_3(0);
408 Vector3f v3f(1.1f, 2.2f, 3.3f);
409 Vector3f v3f_2(4.4, 5.5, 6.6);
410 Vector3f v3f_3(0);
411 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
412 Vector4d v4d_2(5.5, 6.6, 7.7, 8.8);
413 Vector4d v4d_3(0);
414 cout << setw(40) << "v2f: " << v2f.to_string(s1) << endl;
415 cout << setw(40) << "v2f_2: " << v2f_2.to_string(s1) << endl;
416 cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl;
417 cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl;
418 cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl;
419 cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl;
420 v2f_3 = v2f.proj(v2f_2);
421 cout << setw(40) << "v2f_3 = v2f.proj(v3f_2): " << v2f_3.to_string(s1) << endl;
422 v3f_3 = v3f.proj(v3f_2);
423 cout << setw(40) << "v3f_3 = v3f.proj(v3f_2): " << v3f_3.to_string(s1) << endl;
424 v4d_3 = v4d.proj(v4d_2);
425 cout << setw(40) << "v4d_3 = v4d.proj(v4d_2): " << v4d_3.to_string(s1) << endl;
426 v2f_3.assign(0,0);
427 v3f_3.assign(0,0,0);
428 v4d_3.assign(0,0,0,0);
429 v2f.proj(v2f_2, v2f_3);
430 cout << setw(40) << "v2f.proj(v2f_2, v2f_3): " << v2f_3.to_string(s1) << endl;
431 v3f.proj(v3f_2, v3f_3);
432 cout << setw(40) << "v3f.proj(v3f_2, v3f_3): " << v3f_3.to_string(s1) << endl;
433 v4d.proj(v4d_2, v4d_3);
434 cout << setw(40) << "v4d.proj(v4d_2, v4d_3): " << v4d_3.to_string(s1) << endl;
435 }
437 }
439 ////////////////////////////////////////////////////////////////////////////////
440 void test_matrix(void)
441 {
442 string s1, s2;
444 {
445 cout << "===============================================================" << endl <<
446 "Testing Maxtrix constructors" << endl;
447 Matrix22i m22i_1(0);
448 Matrix22i m22i_2(1);
449 Matrix22i m22i_3(1, 2, 3, 4);
450 Matrix22i m22i_4(m22i_3);
452 cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl;
453 cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl;
454 cout << setw(40) << "m22i_3: " << m22i_3.to_string(s1) << endl;
455 cout << setw(40) << "m22i_4: " << m22i_4.to_string(s1) << endl;
457 Matrix33f m33f_1(0.0f);
458 Matrix33f m33f_2(1.1f);
459 Matrix33f m33f_3(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
460 Matrix33f m33f_4(m33f_3);
462 cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl;
463 cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl;
464 cout << setw(40) << "m33f_3: " << m33f_3.to_string(s1) << endl;
465 cout << setw(40) << "m33f_4: " << m33f_4.to_string(s1) << endl;
467 Matrix44d m44d_1(0.0);
468 Matrix44d m44d_2(1.1);
469 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,
470 12.12, 13.13, 14.14, 15.15, 16.16);
471 Matrix44d m44d_4(m44d_3);
473 cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl;
474 cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl;
475 cout << setw(40) << "m44d_3: " << m44d_3.to_string(s1) << endl;
476 cout << setw(40) << "m44d_4: " << m44d_4.to_string(s1) << endl;
477 }
479 {
480 cout << "===============================================================" << endl <<
481 "Testing Maxtrix array indexing" << endl;
482 Matrix22i m22i(1, 2, 3, 4);
484 cout << setw(40) << "m22i: " << m22i[0] << " " << m22i[1] << " " << m22i[2] << " " << m22i[3] << " "<< endl;
486 Matrix33f m33f(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
488 cout << setw(40) << "m33f: " << m33f[0] << " " << m33f[1] << " " << m33f[2] << " " << m33f[3] << " " << m33f[4] << " " << m33f[5] << " " << m33f[6] << " " << m33f[7] << " " << m33f[8] << endl;
490 Matrix44d m44d(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11,
491 12.12, 13.13, 14.14, 15.15, 16.16);
493 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;
494 }
496 {
497 cout << "===============================================================" << endl <<
498 "Testing Maxtrix assignment" << endl;
499 Matrix22i m22i_1(1, 2, 3, 4);
500 Matrix22i m22i_2(5, 6, 7, 8);
502 cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl;
503 cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl;
505 m22i_2 = m22i_1;
506 cout << setw(40) << "m22i_2 = m22i_1: " << m22i_2.to_string(s1) << endl;
508 m22i_2.assign(9, 10, 11, 12);
509 cout << setw(40) << "m22i_2.assign(9, 10, 11, 12): "
510 << m22i_2.to_string(s1) << endl;
512 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
513 Matrix33f m33f_2(10.10f, 11.11f, 12.12f, 13.13f, 14.14f, 15.15f, 16.16f, 17.17f, 18.18f);
515 cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl;
516 cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl;
518 m33f_2 = m33f_1;
519 cout << setw(40) << "m33f_2 = m33f_1: " << m33f_2.to_string(s1) << endl;
521 m33f_2.assign(19.19f, 20.20f, 21.21f, 22.22f, 23.23f, 24.24f, 25.25f, 26.26f, 27.27f);
522 cout << setw(40) << "m33f_2.assign(19.19f, 20.20f, ... , 27.27f): "
523 << m33f_2.to_string(s1) << endl;
525 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,
526 12.12, 13.13, 14.14, 15.15, 16.16);
527 Matrix44d m44d_2(16.16, 17.17, 18.18, 19.19,
528 20.20, 21.21, 22.22, 23.23,
529 24.24, 25.25, 26.26, 27.27,
530 28.28, 29.29, 30.30, 31.31);
532 cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl;
533 cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl;
535 m44d_2 = m44d_1;
536 cout << setw(40) << "m44d_2 = m44d_1: " << m44d_2.to_string(s1) << endl;
538 m44d_2.assign(32.32, 33.33, 34.34, 35.35,
539 36.36, 37.37, 38.38, 39.39,
540 40.40, 41.41, 42.42, 43.43,
541 44.44, 45.45, 46.46, 47.47);
542 cout << setw(40) << "m44d_2.assign(32.32, 33.33, ... , 47.47): "
543 << m44d_2.to_string(s1) << endl;
544 }
546 {
547 cout << "===============================================================" << endl <<
548 "Testing Maxtrix comparison" << endl;
549 Matrix22i m22i_1(1, 2, 3, 4);
550 Matrix22i m22i_2(1, 2, 3, 4);
551 Matrix22i m22i_3(0);
553 cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl;
554 cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl;
555 cout << setw(40) << "m22i_3: " << m22i_3.to_string(s1) << endl;
556 cout << boolalpha;
557 cout << setw(40) << "m22i_1 == m22i_2: " << (m22i_1 == m22i_2) << endl;
558 cout << setw(40) << "m22i_1 == m22i_3: " << (m22i_2 == m22i_3) << endl;
559 cout << setw(40) << "m22i_1 != m22i_2: " << (m22i_1 != m22i_2) << endl;
560 cout << setw(40) << "m22i_1 != m22i_3: " << (m22i_2 != m22i_3) << endl;
562 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
563 Matrix33f m33f_2(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
564 Matrix33f m33f_3(0.0f);
566 cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl;
567 cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl;
568 cout << setw(40) << "m33f_3: " << m33f_3.to_string(s1) << endl;
569 cout << boolalpha;
570 cout << setw(40) << "m33f_1 == m33f_2: " << (m33f_1 == m33f_2) << endl;
571 cout << setw(40) << "m33f_1 == m33f_3: " << (m33f_2 == m33f_3) << endl;
572 cout << setw(40) << "m33f_1 != m33f_2: " << (m33f_1 != m33f_2) << endl;
573 cout << setw(40) << "m33f_1 != m33f_3: " << (m33f_2 != m33f_3) << endl;
575 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,
576 12.12, 13.13, 14.14, 15.15, 16.16);
577 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,
578 12.12, 13.13, 14.14, 15.15, 16.16);
579 Matrix44d m44d_3(0.0);
581 cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl;
582 cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl;
583 cout << setw(40) << "m44d_3: " << m44d_3.to_string(s1) << endl;
584 cout << boolalpha;
585 cout << setw(40) << "m44d_1 == m44d_2: " << (m44d_1 == m44d_2) << endl;
586 cout << setw(40) << "m44d_1 == m44d_3: " << (m44d_2 == m44d_3) << endl;
587 cout << setw(40) << "m44d_1 != m44d_2: " << (m44d_1 != m44d_2) << endl;
588 cout << setw(40) << "m44d_1 != m44d_3: " << (m44d_2 != m44d_3) << endl;
589 }
591 {
592 cout << "===============================================================" << endl <<
593 "Testing Maxtrix addition" << endl;
594 Matrix22i m22i_1(1, 2, 3, 4);
595 Matrix22i m22i_2(5, 6, 7, 8);
596 Matrix22i m22i_3(0);
598 cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl;
599 cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl;
600 cout << setw(40) << "m22i_3: " << m22i_3.to_string(s1) << endl;
601 m22i_3 = m22i_1 + m22i_2;
602 cout << setw(40) << "m22i_3 = m22i_1 + m22i_2: " << m22i_3.to_string(s1) << endl;
604 m22i_3 += m22i_1;
605 cout << setw(40) << "m22i_3 += m22i_1: " << m22i_3.to_string(s1) << endl;
607 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
608 Matrix33f m33f_2(10.10f, 11.11f, 12.12f, 13.13f, 14.14f, 15.15f, 16.16f, 17.17f, 18.18f);
609 Matrix33f m33f_3(0.0f);
611 cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl;
612 cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl;
613 cout << setw(40) << "m33f_3: " << m33f_3.to_string(s1) << endl;
614 m33f_3 = m33f_1 + m33f_2;
615 cout << setw(40) << "m33f_3 = m33f_1 + m33f_2: " << m33f_3.to_string(s1) << endl;
617 m33f_3 += m33f_1;
618 cout << setw(40) << "m33f_3 += m33f_1: " << m33f_3.to_string(s1) << endl;
620 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,
621 12.12, 13.13, 14.14, 15.15, 16.16);
622 Matrix44d m44d_2(16.16, 17.17, 18.18, 19.19,
623 20.20, 21.21, 22.22, 23.23,
624 24.24, 25.25, 26.26, 27.27,
625 28.28, 29.29, 30.30, 31.31);
626 Matrix44d m44d_3(0.0);
628 cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl;
629 cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl;
630 cout << setw(40) << "m44d_3: " << m44d_3.to_string(s1) << endl;
631 m44d_3 = m44d_1 + m44d_2;
632 cout << setw(40) << "m44d_3 = m44d_1 + m44d_2: " << m44d_3.to_string(s1) << endl;
634 m44d_3 += m44d_1;
635 cout << setw(40) << "m44d_3 += m44d_1: " << m44d_3.to_string(s1) << endl;
636 }
638 {
639 cout << "===============================================================" << endl <<
640 "Testing Maxtrix subtraction" << endl;
641 Matrix22i m22i_1(1, 2, 3, 4);
642 Matrix22i m22i_2(5, 6, 7, 8);
643 Matrix22i m22i_3(0);
645 cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl;
646 cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl;
647 cout << setw(40) << "m22i_3: " << m22i_3.to_string(s1) << endl;
648 m22i_3 = m22i_1 - m22i_2;
649 cout << setw(40) << "m22i_3 = m22i_1 - m22i_2: " << m22i_3.to_string(s1) << endl;
651 m22i_3 -= m22i_1;
652 cout << setw(40) << "m22i_3 -= m22i_1: " << m22i_3.to_string(s1) << endl;
654 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
655 Matrix33f m33f_2(10.10f, 11.11f, 12.12f, 13.13f, 14.14f, 15.15f, 16.16f, 17.17f, 18.18f);
656 Matrix33f m33f_3(0.0f);
658 cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl;
659 cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl;
660 cout << setw(40) << "m33f_3: " << m33f_3.to_string(s1) << endl;
661 m33f_3 = m33f_1 - m33f_2;
662 cout << setw(40) << "m33f_3 = m33f_1 - m33f_2: " << m33f_3.to_string(s1) << endl;
664 m33f_3 -= m33f_1;
665 cout << setw(40) << "m33f_3 -= m33f_1: " << m33f_3.to_string(s1) << endl;
667 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,
668 12.12, 13.13, 14.14, 15.15, 16.16);
669 Matrix44d m44d_2(16.16, 17.17, 18.18, 19.19,
670 20.20, 21.21, 22.22, 23.23,
671 24.24, 25.25, 26.26, 27.27,
672 28.28, 29.29, 30.30, 31.31);
673 Matrix44d m44d_3(0.0);
675 cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl;
676 cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl;
677 cout << setw(40) << "m44d_3: " << m44d_3.to_string(s1) << endl;
678 m44d_3 = m44d_1 - m44d_2;
679 cout << setw(40) << "m44d_3 = m44d_1 - m44d_2: " << m44d_3.to_string(s1) << endl;
681 m44d_3 -= m44d_1;
682 cout << setw(40) << "m44d_3 -= m44d_1: " << m44d_3.to_string(s1) << endl;
683 }
685 {
686 cout << "===============================================================" << endl <<
687 "Testing Matrix scalar multiplication" << endl;
688 Matrix22i m22i_1(1, 2, 3, 4);
689 Matrix22i m22i_2(0);
690 int i = 2;
692 cout << setw(40) << "i: " << i << endl;
693 cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl;
694 cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl;
695 m22i_2 = m22i_1 *i;
696 cout << setw(40) << "m22i_2 = m22i_1 * i: " << m22i_2.to_string(s1) << endl;
697 m22i_2 = i * m22i_1;
698 cout << setw(40) << "m22i_2 = i * m22i_1: " << m22i_2.to_string(s1) << endl;
699 m22i_2 *= i;
700 cout << setw(40) << "m22i_2 *= i: " << m22i_2.to_string(s1) << endl;
702 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
703 Matrix33f m33f_2(0.0f);
704 float f = 2.0f;
706 cout << setw(40) << "f: " << f << endl;
707 cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl;
708 cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl;
709 m33f_2 = m33f_1 * f;
710 cout << setw(40) << "m33f_2 = m33f_1 * f: " << m33f_2.to_string(s1) << endl;
711 m33f_2 = f * m33f_1;
712 cout << setw(40) << "m33f_2 = f * m33f_1: " << m33f_2.to_string(s1) << endl;
713 m33f_2 *= f;
714 cout << setw(40) << "m33f_2 *= f: " << m33f_2.to_string(s1) << endl;
716 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,
717 12.12, 13.13, 14.14, 15.15, 16.16);
718 Matrix44d m44d_2(0.0);
719 double d = 2.0f;
721 cout << setw(40) << "d: " << d << endl;
722 cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl;
723 cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl;
724 m44d_2 = m44d_1 * d;
725 cout << setw(40) << "m44d_2 = m44d_1 * d: " << m44d_2.to_string(s1) << endl;
726 m44d_2 = d * m44d_1;
727 cout << setw(40) << "m44d_2 = d * m44d_1: " << m44d_2.to_string(s1) << endl;
728 m44d_2 *= d;
729 cout << setw(40) << "m44d_2 *= d: " << m44d_2.to_string(s1) << endl;
730 }
732 {
733 cout << "===============================================================" << endl <<
734 "Testing Matrix scalar division" << endl;
735 Matrix22i m22i_1(1, 2, 3, 4);
736 Matrix22i m22i_2(0);
737 int i = 2;
739 cout << setw(40) << "i: " << i << endl;
740 cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl;
741 cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl;
742 m22i_2 = m22i_1 / i;
743 cout << setw(40) << "m22i_2 = m22i_1 / i: " << m22i_2.to_string(s1) << endl;
744 m22i_1 /= i;
745 cout << setw(40) << "m22i_1 /= i: " << m22i_2.to_string(s1) << endl;
747 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
748 Matrix33f m33f_2(0.0f);
749 float f = 2.0f;
751 cout << setw(40) << "f: " << f << endl;
752 cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl;
753 cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl;
754 m33f_2 = m33f_1 / f;
755 cout << setw(40) << "m33f_2 = m33f_1 / f: " << m33f_2.to_string(s1) << endl;
756 m33f_1 /= f;
757 cout << setw(40) << "m33f_1 /= f: " << m33f_2.to_string(s1) << endl;
759 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,
760 12.12, 13.13, 14.14, 15.15, 16.16);
761 Matrix44d m44d_2(0.0);
762 double d = 2.0f;
764 cout << setw(40) << "d: " << d << endl;
765 cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl;
766 cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl;
767 m44d_2 = m44d_1 / d;
768 cout << setw(40) << "m44d_2 = m44d_1 / d: " << m44d_2.to_string(s1) << endl;
769 m44d_1 /= d;
770 cout << setw(40) << "m44d_1 /= d: " << m44d_2.to_string(s1) << endl;
771 }
773 {
774 cout << "===============================================================" << endl <<
775 "Testing Maxtrix multiplication" << endl;
776 Matrix22i m22i_1(1, 2, 3, 4);
777 Matrix22i m22i_2(5, 6, 7, 8);
778 Matrix22i m22i_3(0);
780 cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl;
781 cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl;
782 cout << setw(40) << "m22i_3: " << m22i_3.to_string(s1) << endl;
783 m22i_3 = m22i_1 * m22i_2;
784 cout << setw(40) << "m22i_3 = m22i_1 * m22i_2: " << m22i_3.to_string(s1) << endl;
786 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
787 Matrix33f m33f_2(10.10f, 11.11f, 12.12f, 13.13f, 14.14f, 15.15f, 16.16f, 17.17f, 18.18f);
788 Matrix33f m33f_3(0.0f);
790 cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl;
791 cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl;
792 cout << setw(40) << "m33f_3: " << m33f_3.to_string(s1) << endl;
793 m33f_3 = m33f_1 * m33f_2;
794 cout << setw(40) << "m33f_3 = m33f_1 * m33f_2: " << m33f_3.to_string(s1) << endl;
796 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,
797 12.12, 13.13, 14.14, 15.15, 16.16);
798 Matrix44d m44d_2(16.16, 17.17, 18.18, 19.19,
799 20.20, 21.21, 22.22, 23.23,
800 24.24, 25.25, 26.26, 27.27,
801 28.28, 29.29, 30.30, 31.31);
802 Matrix44d m44d_3(0.0);
804 cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl;
805 cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl;
806 cout << setw(40) << "m44d_3: " << m44d_3.to_string(s1) << endl;
807 m44d_3 = m44d_1 * m44d_2;
808 cout << setw(40) << "m44d_3 = m44d_1 * m44d_2: " << m44d_3.to_string(s1) << endl;
809 }
811 {
812 cout << "===============================================================" << endl <<
813 "Testing Maxtrix det" << endl;
814 Matrix22i m22i_1(1, 2, 3, 4);
815 double d;
817 cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl;
818 d = det(m22i_1);
819 cout << setw(40) << "d = det(m22i_1): " << d << endl;
821 // Note: singular matrix. The real determinant is exactly zero.
822 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
824 cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl;
825 d = det(m33f_1);
826 cout << setw(40) << "d = det(m33f_1): " << d << endl;
828 // Note: singular matrix. The real determinant is exactly zero.
829 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,
830 12.12, 13.13, 14.14, 15.15, 16.16);
832 cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl;
833 d = det(m44d_1);
834 cout << setw(40) << "d = det(m44d_1): " << d << endl;
836 }
838 {
839 cout << "===============================================================" << endl <<
840 "Testing Maxtrix transpose" << endl;
841 Matrix22i m22i_1(1, 2, 3, 4);
842 Matrix22i m22i_2;
844 cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl;
845 m22i_2 = transpose(m22i_1);
846 cout << setw(40) << "m22i_2 = transpose(m22i_1): " << m22i_2.to_string(s1) << endl;
848 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
849 Matrix33f m33f_2(0.0f);
851 cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl;
852 m33f_2 = transpose(m33f_1);
853 cout << setw(40) << "m33f_2 = transpose(m33f_1): " << m33f_2.to_string(s1) << endl;
855 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,
856 12.12, 13.13, 14.14, 15.15, 16.16);
857 Matrix44d m44d_2(0.0);
859 cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl;
860 m44d_2 = transpose(m44d_1);
861 cout << setw(40) << "m44d_2 = transpose(m44d_1): " << m44d_2.to_string(s1) << endl;
862 }
864 {
865 cout << "===============================================================" << endl <<
866 "Testing Maxtrix setidentity" << endl;
867 Matrix22i m22i_1(1, 2, 3, 4);
869 cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl;
870 m22i_1.setidentity();
871 cout << setw(40) << "m22i_1.setidentity(): " << m22i_1.to_string(s1) << endl;
873 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
875 cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl;
876 m33f_1.setidentity();
877 cout << setw(40) << "m33f_1.setidentity(): " << m33f_1.to_string(s1) << endl;
879 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,
880 12.12, 13.13, 14.14, 15.15, 16.16);
882 cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl;
883 m44d_1.setidentity();
884 cout << setw(40) << "m44d_1.setidentity(): " << m44d_1.to_string(s1) << endl;
885 }
887 {
888 cout << "===============================================================" << endl <<
889 "Testing Matrix getrow() and getcol()" << endl;
890 Matrix22i m22i_1(1, 2, 3, 4);
891 Vector2i v2i_1(0);
893 cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl;
894 v2i_1 = m22i_1.getrow(0);
895 cout << setw(40) << "v2i_1 = m22i_1.getrow(0): " << v2i_1.to_string(s1) << endl;
896 v2i_1 = m22i_1.getrow(1);
897 cout << setw(40) << "v2i_1 = m22i_1.getrow(1): " << v2i_1.to_string(s1) << endl;
898 v2i_1 = m22i_1.getcol(0);
899 cout << setw(40) << "v2i_1 = m22i_1.getcol(0): " << v2i_1.to_string(s1) << endl;
900 v2i_1 = m22i_1.getcol(1);
901 cout << setw(40) << "v2i_1 = m22i_1.getcol(1): " << v2i_1.to_string(s1) << endl;
903 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
904 Vector3f v3f_1(0);
906 cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl;
907 v3f_1 = m33f_1.getrow(0);
908 cout << setw(40) << "v3f_1 = m33f_1.getrow(0): " << v3f_1.to_string(s1) << endl;
909 v3f_1 = m33f_1.getrow(1);
910 cout << setw(40) << "v3f_1 = m33f_1.getrow(1): " << v3f_1.to_string(s1) << endl;
911 v3f_1 = m33f_1.getrow(2);
912 cout << setw(40) << "v3f_1 = m33f_1.getrow(2): " << v3f_1.to_string(s1) << endl;
913 v3f_1 = m33f_1.getcol(0);
914 cout << setw(40) << "v3f_1 = m33f_1.getcol(0): " << v3f_1.to_string(s1) << endl;
915 v3f_1 = m33f_1.getcol(1);
916 cout << setw(40) << "v3f_1 = m33f_1.getcol(1): " << v3f_1.to_string(s1) << endl;
917 v3f_1 = m33f_1.getcol(2);
918 cout << setw(40) << "v3f_1 = m33f_1.getcol(2): " << v3f_1.to_string(s1) << endl;
920 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,
921 12.12, 13.13, 14.14, 15.15, 16.16);
922 Vector4d v4d_1(0);
924 cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl;
925 v4d_1 = m44d_1.getrow(0);
926 cout << setw(40) << "v4d_1 = m44d_1.getrow(0): " << v4d_1.to_string(s1) << endl;
927 v4d_1 = m44d_1.getrow(1);
928 cout << setw(40) << "v4d_1 = m44d_1.getrow(1): " << v4d_1.to_string(s1) << endl;
929 v4d_1 = m44d_1.getrow(2);
930 cout << setw(40) << "v4d_1 = m44d_1.getrow(2): " << v4d_1.to_string(s1) << endl;
931 v4d_1 = m44d_1.getrow(3);
932 cout << setw(40) << "v4d_1 = m44d_1.getrow(3): " << v4d_1.to_string(s1) << endl;
934 v4d_1 = m44d_1.getcol(0);
935 cout << setw(40) << "v4d_1 = m44d_1.getcol(0): " << v4d_1.to_string(s1) << endl;
936 v4d_1 = m44d_1.getcol(1);
937 cout << setw(40) << "v4d_1 = m44d_1.getcol(1): " << v4d_1.to_string(s1) << endl;
938 v4d_1 = m44d_1.getcol(2);
939 cout << setw(40) << "v4d_1 = m44d_1.getcol(2): " << v4d_1.to_string(s1) << endl;
940 v4d_1 = m44d_1.getcol(3);
941 cout << setw(40) << "v4d_1 = m44d_1.getcol(3): " << v4d_1.to_string(s1) << endl;
942 }
944 {
945 cout << "===============================================================" << endl <<
946 "Testing Matrix setrow() and setcol()" << endl;
947 Matrix22i m22i_1;
948 Vector2i v2i_1(2, 3);
950 m22i_1.setidentity();
951 cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl;
952 m22i_1.setrow(0, v2i_1);
953 cout << setw(40) << "m22i_1.setrow(0, v2i_1): " << m22i_1.to_string(s1) << endl;
955 m22i_1.setidentity();
956 m22i_1.setrow(1, v2i_1);
957 cout << setw(40) << "m22i_1.setrow(1, v2i_1): " << m22i_1.to_string(s1) << endl;
959 m22i_1.setidentity();
960 m22i_1.setrow(1, 4, 5);
961 cout << setw(40) << "m22i_1.setrow(1, 4, 5): " << m22i_1.to_string(s1) << endl;
963 m22i_1.setidentity();
964 m22i_1.setcol(0, v2i_1);
965 cout << setw(40) << "m22i_1.setcol(0, v2i_1): " << m22i_1.to_string(s1) << endl;
967 m22i_1.setidentity();
968 m22i_1.setcol(1, v2i_1);
969 cout << setw(40) << "m22i_1.setcol(1, v2i_1): " << m22i_1.to_string(s1) << endl;
971 m22i_1.setidentity();
972 m22i_1.setcol(1, 4, 5);
973 cout << setw(40) << "m22i_1.setcol(1, 4, 5): " << m22i_1.to_string(s1) << endl;
975 Matrix33f m33f_1;
976 Vector3f v3f_1(0);
978 m33f_1.setidentity();
979 cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl;
980 m33f_1.setrow(0, v3f_1);
981 cout << setw(40) << "m33f_1.setrow(0, v3f_1): " << m33f_1.to_string(s1) << endl;
983 m33f_1.setidentity();
984 m33f_1.setrow(1, v3f_1);
985 cout << setw(40) << "m33f_1.setrow(1, v3f_1): " << m33f_1.to_string(s1) << endl;
987 m33f_1.setidentity();
988 m33f_1.setrow(1, 2.2f, 3.3f, 4.4f);
989 cout << setw(40) << "m33f_1.setrow(1, 2.2f, 3.3f, 4.4f): "
990 << m33f_1.to_string(s1) << endl;
992 m33f_1.setidentity();
993 m33f_1.setcol(0, v3f_1);
994 cout << setw(40) << "m33f_1.setcol(0, v3f_1): " << m33f_1.to_string(s1) << endl;
996 m33f_1.setidentity();
997 m33f_1.setcol(1, v3f_1);
998 cout << setw(40) << "m33f_1.setcol(1, v3f_1): " << m33f_1.to_string(s1) << endl;
1000 m33f_1.setidentity();
1001 m33f_1.setcol(1, 2.2f, 3.3f, 4.4f);
1002 cout << setw(40) << "m33f_1.setcol(1, 2.2f, 3.3f, 4.4f: "
1003 << m33f_1.to_string(s1) << endl;
1005 Matrix44d m44d_1;
1006 Vector4d v4d_1(0);
1008 m44d_1.setidentity();
1009 cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl;
1010 m44d_1.setrow(0, v4d_1);
1011 cout << setw(40) << "m44d_1.setrow(0, v4d_1): " << m44d_1.to_string(s1) << endl;
1013 m44d_1.setidentity();
1014 m44d_1.setrow(1, v4d_1);
1015 cout << setw(40) << "m44d_1.setrow(1, v4d_1): " << m44d_1.to_string(s1) << endl;
1017 m44d_1.setidentity();
1018 m44d_1.setrow(1, 2.2, 3.3, 4.4, 5.5);
1019 cout << setw(40) << "m44d_1.setrow(1, 2.2, 3.3, 4.4, 5.5): "
1020 << m44d_1.to_string(s1) << endl;
1022 m44d_1.setidentity();
1023 m44d_1.setcol(0, v4d_1);
1024 cout << setw(40) << "m44d_1.setcol(0, v4d_1): " << m44d_1.to_string(s1) << endl;
1026 m44d_1.setidentity();
1027 m44d_1.setcol(1, v4d_1);
1028 cout << setw(40) << "m44d_1.setcol(1, v4d_1): " << m44d_1.to_string(s1) << endl;
1030 m44d_1.setidentity();
1031 m44d_1.setcol(1, 2.2, 3.3, 4.4, 5.5);
1032 cout << setw(40) << "m44d_1.setcol(1, 2.2, 3.3, 4.4, 5.5: "
1033 << m44d_1.to_string(s1) << endl;
1037 ////////////////////////////////////////////////////////////////////////////////
1038 void test_all(void)
1040 test_vector();
1041 test_matrix();
1044 ////////////////////////////////////////////////////////////////////////////////
1045 void show_menu(void)
1047 cout << endl << endl
1048 << "Test what?" << endl
1049 << "0) All" << endl << endl
1050 << "1) Vector" << endl
1051 << "2) Matrix" << endl
1052 << endl
1053 << "99 Quit" << endl;
1056 ////////////////////////////////////////////////////////////////////////////////
1057 int main (int argc, char * argv[])
1059 int retval = 0;
1061 test_all();
1062 return 0;
1064 try
1066 int choice = -1;
1068 while (choice != 99)
1070 show_menu();
1071 cin >> choice;
1072 if(!cin)
1074 cin.clear();
1075 cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
1077 if (choice != 99)
1079 switch (choice)
1081 case 0:
1082 test_all();
1083 break;
1084 case 1:
1085 test_vector();
1086 break;
1087 case 2:
1088 test_matrix();
1089 break;
1090 default:
1091 cout << "Unrecognized choice. Please try again." << endl;
1093 choice = -1;
1097 catch (const std::exception & error)
1099 string e = "Caught exception: ";
1100 e += error.what();
1101 cerr << e << endl;
1102 retval = 1;
1105 return retval;;