view test/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 fbb4ac41da28
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 #include "gtest/gtest.h"
13 ////////////////////////////////////////////////////////////////////////////////
14 // Vector2 floating point
16 typedef ::testing::Types<int, float, double> MyTypes;
18 template <typename T>
19 class VectorTest : public ::testing::Test {
20 public:
21 static T x;
22 static T y;
23 static T z;
24 static T w;
26 virtual void SetUp() {
27 }
29 };
31 TYPED_TEST_CASE( VectorTest, MyTypes );
33 TYPED_TEST( VectorTest, ConstructFromSingleValue ) {
34 TypeParam zero = (TypeParam ) 0;
35 TypeParam one = (TypeParam ) 1;
37 Vector2<TypeParam> v2_zero( zero );
38 EXPECT_FLOAT_EQ( zero, v2_zero.x ) << "x component is not " << zero;
39 EXPECT_FLOAT_EQ( zero, v2_zero.y ) << "y component is not " << zero;
41 Vector2<TypeParam> v2_one( one );
42 EXPECT_FLOAT_EQ( one, v2_one.x ) << "x component is not " << one;
43 EXPECT_FLOAT_EQ( one, v2_one.y ) << "y component is not " << one;
45 Vector3<TypeParam> v3_zero( zero );
46 EXPECT_FLOAT_EQ( zero, v3_zero.x ) << "x component is not " << zero;
47 EXPECT_FLOAT_EQ( zero, v3_zero.y ) << "y component is not " << zero;
48 EXPECT_FLOAT_EQ( zero, v3_zero.z ) << "z component is not " << zero;
50 Vector3<TypeParam> v3_one( one );
51 EXPECT_FLOAT_EQ( one, v3_one.x ) << "x component is not " << one;
52 EXPECT_FLOAT_EQ( one, v3_one.y ) << "y component is not " << one;
53 EXPECT_FLOAT_EQ( one, v3_one.z ) << "z component is not " << one;
55 Vector4<TypeParam> v4_zero( zero );
56 EXPECT_FLOAT_EQ( zero, v4_zero.x ) << "x component is not " << zero;
57 EXPECT_FLOAT_EQ( zero, v4_zero.y ) << "y component is not " << zero;
58 EXPECT_FLOAT_EQ( zero, v4_zero.z ) << "z component is not " << zero;
59 EXPECT_FLOAT_EQ( zero, v4_zero.w ) << "w component is not " << zero;
61 Vector4<TypeParam> v4_one( one );
62 EXPECT_FLOAT_EQ( one, v4_one.x ) << "x component is not " << one;
63 EXPECT_FLOAT_EQ( one, v4_one.y ) << "y component is not " << one;
64 EXPECT_FLOAT_EQ( one, v4_one.z ) << "z component is not " << one;
65 EXPECT_FLOAT_EQ( one, v4_one.w ) << "w component is not " << one;
67 }
69 TYPED_TEST( VectorTest, ConstructFromMultipleValues ) {
70 TypeParam x = (TypeParam ) 1.1;
71 TypeParam y = (TypeParam ) 2.2;
72 TypeParam z = (TypeParam ) 3.3;
73 TypeParam w = (TypeParam ) 4.4;
75 Vector2<TypeParam> v2( x, y );
76 EXPECT_FLOAT_EQ( x, v2.x ) << "x component is not " << x;
77 EXPECT_FLOAT_EQ( y, v2.y ) << "y component is not " << y;
79 Vector3<TypeParam> v3( x, y, z );
80 EXPECT_FLOAT_EQ( x, v3.x ) << "x component is not " << x;
81 EXPECT_FLOAT_EQ( y, v3.y ) << "y component is not " << y;
82 EXPECT_FLOAT_EQ( z, v3.z ) << "z component is not " << z;
84 Vector4<TypeParam> v4( x, y, z, w );
85 EXPECT_FLOAT_EQ( x, v4.x ) << "x component is not " << x;
86 EXPECT_FLOAT_EQ( y, v4.y ) << "y component is not " << y;
87 EXPECT_FLOAT_EQ( z, v4.z ) << "z component is not " << z;
88 EXPECT_FLOAT_EQ( w, v4.w ) << "w component is not " << w;
89 }
91 TYPED_TEST( VectorTest, ConstructFromVector ) {
92 TypeParam x = (TypeParam ) 1.1;
93 TypeParam y = (TypeParam ) 2.2;
94 TypeParam z = (TypeParam ) 3.3;
95 TypeParam w = (TypeParam ) 4.4;
97 Vector2<TypeParam> v2_1( x, y );
98 Vector2<TypeParam> v2_2( v2_1 );
99 EXPECT_FLOAT_EQ( v2_1.x, v2_2.x ) << "x component is not " << v2_1.x;
100 EXPECT_FLOAT_EQ( v2_1.y, v2_2.y ) << "y component is not " << v2_1.y;
102 Vector3<TypeParam> v3_1( x, y, z );
103 Vector3<TypeParam> v3_2( v3_1 );
104 EXPECT_FLOAT_EQ( v3_1.x, v3_2.x ) << "x component is not " << v3_1.x;
105 EXPECT_FLOAT_EQ( v3_1.y, v3_2.y ) << "y component is not " << v3_1.y;
106 EXPECT_FLOAT_EQ( v3_1.z, v3_2.z ) << "z component is not " << v3_1.z;
108 Vector4<TypeParam> v4_2_1( x, y, z, w );
109 Vector4<TypeParam> v2( v4_2_1 );
110 EXPECT_FLOAT_EQ( v4_2_1.x, v2.x ) << "x component is not " << v4_2_1.x;
111 EXPECT_FLOAT_EQ( v4_2_1.y, v2.y ) << "y component is not " << v4_2_1.y;
112 EXPECT_FLOAT_EQ( v4_2_1.z, v2.z ) << "z component is not " << v4_2_1.z;
113 EXPECT_FLOAT_EQ( v4_2_1.w, v2.w ) << "w component is not " << v4_2_1.w;
115 }
117 TYPED_TEST( VectorTest, Indexing ) {
118 TypeParam x = (TypeParam ) 1.1;
119 TypeParam y = (TypeParam ) 2.2;
120 TypeParam z = (TypeParam ) 3.3;
121 TypeParam w = (TypeParam ) 4.4;
123 Vector2<TypeParam> v2( x, y);
124 ASSERT_EQ( x, v2.x ) << "x component is not " << x;
125 ASSERT_EQ( y, v2.y ) << "y component is not " << y;
127 Vector3<TypeParam> v3( x, y, z);
128 ASSERT_FLOAT_EQ( x, v3.x ) << "x component is not " << x;
129 ASSERT_FLOAT_EQ( y, v3.y ) << "y component is not " << y;
130 ASSERT_FLOAT_EQ( z, v3.z ) << "z component is not " << z;
132 Vector4<TypeParam> v4( x, y, z, w);
133 ASSERT_FLOAT_EQ( x, v4.x ) << "x component is not " << x;
134 ASSERT_FLOAT_EQ( y, v4.y ) << "y component is not " << y;
135 ASSERT_FLOAT_EQ( z, v4.z ) << "z component is not " << z;
136 ASSERT_FLOAT_EQ( w, v4.w ) << "w component is not " << w;
138 }
140 ////////////////////////////////////////////////////////////////////////////////
142 int main(int argc, char **argv) {
143 ::testing::InitGoogleTest(&argc, argv);
144 return RUN_ALL_TESTS();
145 }
148 #ifdef NOTHING
150 ////////////////////////////////////////////////////////////////////////////////
151 void test_vector(void)
152 {
153 string s1, s2;
156 {
157 cout << "===============================================================" << endl <<
158 "Testing Vector assignment" << endl;
159 Vector2i v2i(1,2);
160 Vector3f v3f(1.1f, 2.2f, 3.3f);
161 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
162 Vector2i v2i_2(0);
163 Vector3f v3f_2(0);
164 Vector4d v4d_2(0);
166 cout << "Before assignment" << endl;
167 cout << setw(40) << "v2i: " << v2i.to_string() << endl;
168 cout << setw(40) << "v3f: " << v3f.to_string() << endl;
169 cout << setw(40) << "v4d: " << v4d.to_string() << endl;
170 cout << setw(40) << "v2i_2: " << v2i_2.to_string() << endl;
171 cout << setw(40) << "v3f_2: " << v3f_2.to_string() << endl;
172 cout << setw(40) << "v4d_2: " << v4d_2.to_string() << endl;
174 v2i_2 = v2i;
175 v3f_2 = v3f;
176 v4d_2 = v4d;
177 cout << "After assignment by =" << endl;
178 cout << setw(40) << "v2i_2: " << v2i_2.to_string() << endl;
179 cout << setw(40) << "v3f_2: " << v3f_2.to_string() << endl;
180 cout << setw(40) << "v4d_2: " << v4d_2.to_string() << endl;
182 v2i_2.assign(1, 1);
183 v3f_2.assign(2.2, 2.2, 2.2);
184 v4d_2.assign(3.3, 3.3, 3.3, 3.3);
185 cout << "After assignment by assign()" << endl;
186 cout << setw(40) << "v2i_2: " << v2i_2.to_string() << endl;
187 cout << setw(40) << "v3f_2: " << v3f_2.to_string() << endl;
188 cout << setw(40) << "v4d_2: " << v4d_2.to_string() << endl;
189 }
191 {
192 cout << "===============================================================" << endl <<
193 "Testing Vector comparison" << endl;
194 Vector2i v2i(1,2);
195 Vector3f v3f(1.1f, 2.2f, 3.3f);
196 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
197 Vector2i v2i_2(1,2);
198 Vector3f v3f_2(1.1f, 2.2f, 3.3f);
199 Vector4d v4d_2(1.1, 2.2, 3.3, 4.4);
200 Vector2i v2i_3(0);
201 Vector3f v3f_3(0);
202 Vector4d v4d_3(0);
204 cout << setw(40) << "v2i: " << v2i.to_string() << endl;
205 cout << setw(40) << "v3f: " << v3f.to_string() << endl;
206 cout << setw(40) << "v4d: " << v4d.to_string() << endl;
207 cout << setw(40) << "v2i_2: " << v2i_2.to_string() << endl;
208 cout << setw(40) << "v3f_2: " << v3f_2.to_string() << endl;
209 cout << setw(40) << "v4d_2: " << v4d_2.to_string() << endl;
210 cout << setw(40) << "v2i_3: " << v2i_3.to_string() << endl;
211 cout << setw(40) << "v3f_3: " << v3f_3.to_string() << endl;
212 cout << setw(40) << "v4d_3: " << v4d_3.to_string() << endl;
213 cout << boolalpha;
214 cout << setw(40) << "v2i == v2i_2: " << (v2i == v2i_2) << endl;
215 cout << setw(40) << "v2i == v2i_3: " << (v2i == v2i_3) << endl;
216 cout << setw(40) << "v2i != v2i_2: " << (v2i != v2i_2) << endl;
217 cout << setw(40) << "v2i != v2i_3: " << (v2i != v2i_3) << endl;
218 cout << setw(40) << "v3f == v3f_2: " << (v3f == v3f_2) << endl;
219 cout << setw(40) << "v3f == v3f_3: " << (v3f == v3f_3) << endl;
220 cout << setw(40) << "v3f != v3f_2: " << (v3f != v3f_2) << endl;
221 cout << setw(40) << "v3f != v3f_3: " << (v3f != v3f_3) << endl;
222 cout << setw(40) << "v4d == v4d_2: " << (v4d == v4d_2) << endl;
223 cout << setw(40) << "v4d == v4d_3: " << (v4d == v4d_3) << endl;
224 cout << setw(40) << "v4d != v4d_2: " << (v4d != v4d_2) << endl;
225 cout << setw(40) << "v4d != v4d_3: " << (v4d != v4d_3) << endl;
226 }
228 {
229 cout << "===============================================================" << endl <<
230 "Testing Vector addition" << endl;
231 Vector2i v2i(1,2);
232 Vector3f v3f(1.1f, 2.2f, 3.3f);
233 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
234 Vector2i v2i_2(3,4);
235 Vector3f v3f_2(4.4, 5.5, 6.6);
236 Vector4d v4d_2(5.5, 6.6, 7.7, 8.8);
237 Vector2i v2i_3(0);
238 Vector3f v3f_3(0);
239 Vector4d v4d_3(0);
241 cout << setw(40) << "v2i: " << v2i.to_string() << endl;
242 cout << setw(40) << "v3f: " << v3f.to_string() << endl;
243 cout << setw(40) << "v4d: " << v4d.to_string() << endl;
244 cout << setw(40) << "v2i_2: " << v2i_2.to_string() << endl;
245 cout << setw(40) << "v3f_2: " << v3f_2.to_string() << endl;
246 cout << setw(40) << "v4d_2: " << v4d_2.to_string() << endl;
247 v2i_3 = v2i + v2i_2;
248 v3f_3 = v3f + v3f_2;
249 v4d_3 = v4d + v4d_2;
250 cout << setw(40) << "v2i_3 = v2i + v2i_2: " << v2i_3.to_string() << endl;
251 cout << setw(40) << "v3f_3 = v3f + v3f_2: " << v3f_3.to_string() << endl;
252 cout << setw(40) << "v4d_3 = v4d + v4d_2: " << v4d_3.to_string() << endl;
253 v2i_3 += v2i_2;
254 v3f_3 += v3f_2;
255 v4d_3 += v4d_3;
256 cout << setw(40) << "v2i_3 += v2i_2: " << v2i_3.to_string() << endl;
257 cout << setw(40) << "v3f_3 += v3f_2: " << v3f_3.to_string() << endl;
258 cout << setw(40) << "v4d_3 += v4d_3: " << v4d_3.to_string() << endl;
259 }
261 {
262 cout << "===============================================================" << endl <<
263 "Testing Vector subtraction" << endl;
264 Vector2i v2i(1,2);
265 Vector3f v3f(1.1f, 2.2f, 3.3f);
266 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
267 Vector2i v2i_2(3,4);
268 Vector3f v3f_2(4.4, 5.5, 6.6);
269 Vector4d v4d_2(5.5, 6.6, 7.7, 8.8);
270 Vector2i v2i_3(0);
271 Vector3f v3f_3(0);
272 Vector4d v4d_3(0);
274 cout << setw(40) << "v2i: " << v2i.to_string() << endl;
275 cout << setw(40) << "v3f: " << v3f.to_string() << endl;
276 cout << setw(40) << "v4d: " << v4d.to_string() << endl;
277 cout << setw(40) << "v2i_2: " << v2i_2.to_string() << endl;
278 cout << setw(40) << "v3f_2: " << v3f_2.to_string() << endl;
279 cout << setw(40) << "v4d_2: " << v4d_2.to_string() << endl;
280 v2i_3 = v2i - v2i_2;
281 v3f_3 = v3f - v3f_2;
282 v4d_3 = v4d - v4d_2;
283 cout << setw(40) << "v2i_3 = v2i - v2i_2: " << v2i_3.to_string() << endl;
284 cout << setw(40) << "v3f_3 = v3f - v3f_2: " << v3f_3.to_string() << endl;
285 cout << setw(40) << "v4d_3 = v4d - v4d_2: " << v4d_3.to_string() << endl;
286 v2i_3 -= v2i_2;
287 v3f_3 -= v3f_2;
288 v4d_3 -= v4d_3;
289 cout << setw(40) << "v2i_3 -= v2i_2: " << v2i_3.to_string() << endl;
290 cout << setw(40) << "v3f_3 -= v3f_2: " << v3f_3.to_string() << endl;
291 cout << setw(40) << "v4d_3 -= v4d_3: " << v4d_3.to_string() << endl;
292 }
294 {
295 cout << "===============================================================" << endl <<
296 "Testing Vector scalar multiplication" << endl;
297 Vector2i v2i(1,2);
298 Vector3f v3f(1.1f, 2.2f, 3.3f);
299 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
300 Vector2i v2i_2(0);
301 Vector3f v3f_2(0);
302 Vector4d v4d_2(0);
303 int i = 2;
304 float f = 2.f;
305 double d = 2.0;
307 cout << setw(40) << "i: " << i << endl;
308 cout << setw(40) << "f: " << f << endl;
309 cout << setw(40) << "d: " << d << endl;
310 cout << setw(40) << "v2i: " << v2i.to_string() << endl;
311 cout << setw(40) << "v3f: " << v3f.to_string() << endl;
312 cout << setw(40) << "v4d: " << v4d.to_string() << endl;
313 cout << setw(40) << "v2i_2: " << v2i_2.to_string() << endl;
314 cout << setw(40) << "v3f_2: " << v3f_2.to_string() << endl;
315 cout << setw(40) << "v4d_2: " << v4d_2.to_string() << endl;
316 v2i_2 = v2i * i;
317 v3f_2 = v3f * f;
318 v4d_2 = v4d * d;
319 cout << setw(40) << "v2i_2 = v2i * i: " << v2i_2.to_string() << endl;
320 cout << setw(40) << "v3f_2 = v3f * f: " << v3f_2.to_string() << endl;
321 cout << setw(40) << "v4d_2 = v4d * d: " << v4d_2.to_string() << endl;
322 v2i_2 *= i;
323 v3f_2 *= f;
324 v4d_2 *= d;
325 cout << setw(40) << "v2i_2 *= i: " << v2i_2.to_string() << endl;
326 cout << setw(40) << "v3f_2 *= f: " << v3f_2.to_string() << endl;
327 cout << setw(40) << "v4d_2 *= d: " << v4d_2.to_string() << endl;
328 }
330 {
331 cout << "===============================================================" << endl <<
332 "Testing Vector scalar division" << endl;
333 Vector2i v2i(1,2);
334 Vector3f v3f(1.1f, 2.2f, 3.3f);
335 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
336 Vector2i v2i_2(0);
337 Vector3f v3f_2(0);
338 Vector4d v4d_2(0);
339 int i = 2;
340 float f = 2.f;
341 double d = 2.0;
343 cout << setw(40) << "v2i: " << v2i.to_string() << endl;
344 cout << setw(40) << "v3f: " << v3f.to_string() << endl;
345 cout << setw(40) << "v4d: " << v4d.to_string() << endl;
346 cout << setw(40) << "v2i_2: " << v2i_2.to_string() << endl;
347 cout << setw(40) << "v3f_2: " << v3f_2.to_string() << endl;
348 cout << setw(40) << "v4d_2: " << v4d_2.to_string() << endl;
349 v2i_2 = v2i / i;
350 v3f_2 = v3f / f;
351 v4d_2 = v4d / d;
352 cout << setw(40) << "v2i_2 = v2i / i: " << v2i_2.to_string() << endl;
353 cout << setw(40) << "v3f_2 = v3f / f: " << v3f_2.to_string() << endl;
354 cout << setw(40) << "v4d_2 = v4d / d: " << v4d_2.to_string() << endl;
355 v2i_2 /= i;
356 v3f_2 /= f;
357 v4d_2 /= d;
358 cout << setw(40) << "v2i_2 /= i: " << v2i_2.to_string() << endl;
359 cout << setw(40) << "v3f_2 /= f: " << v3f_2.to_string() << endl;
360 cout << setw(40) << "v4d_2 /= d: " << v4d_2.to_string() << endl;
361 }
363 {
364 cout << "===============================================================" << endl <<
365 "Testing Vector cross product" << endl;
366 Vector3f v3f(1.1f, 2.2f, 3.3f);
367 Vector3f v3f_2(4.4, 5.5, 6.6);
368 Vector3f v3f_3(0);
369 Vector3f v3f_4(0);
370 cout << setw(40) << "v3f: " << v3f.to_string() << endl;
371 cout << setw(40) << "v3f_2: " << v3f_2.to_string() << endl;
372 cout << setw(40) << "v3f_3: " << v3f_3.to_string() << endl;
373 v3f.cross(v3f_2, v3f_3);
374 cout << setw(40) << "v3f.cross(v3f_2, v3f_3): " << v3f_3.to_string() << endl;
375 v3f_4 = 2.0 * v3f.cross(v3f_2);
376 cout << setw(40) << "2.0 * v3f.cross(v3f_2,): " << v3f_4.to_string() << endl;
377 v3f_4.assign(0,0,0);
378 v3f.cross(v3f_2, v3f_4);
379 cout << setw(40) << "v3f.cross(v3f_2, v3f_4): " << v3f_4.to_string() << endl;
380 }
382 {
383 cout << "===============================================================" << endl <<
384 "Testing Vector dot product" << endl;
385 Vector2i v2i(1, 2);
386 Vector2i v2i_2(3, 4);
387 Vector3f v3f(1.1f, 2.2f, 3.3f);
388 Vector3f v3f_2(4.4, 5.5, 6.6);
389 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
390 Vector4d v4d_2(5.5, 6.6, 7.7, 8.8);
391 int i;
392 float f;
393 double d;
394 cout << setw(40) << "v2i: " << v2i.to_string() << endl;
395 cout << setw(40) << "v2i_2: " << v2i_2.to_string() << endl;
396 cout << setw(40) << "v3f: " << v3f.to_string() << endl;
397 cout << setw(40) << "v3f_2: " << v3f_2.to_string() << endl;
398 cout << setw(40) << "v4d: " << v4d.to_string() << endl;
399 cout << setw(40) << "v4d_2: " << v4d_2.to_string() << endl;
400 i = v2i.dot(v2i_2);
401 cout << setw(40) << "i = v2i.dot(v2i_2): " << i << endl;
402 f = v3f.dot(v3f_2);
403 cout << setw(40) << "f = v3f.dot(v3f_2): " << f << endl;
404 d = v4d.dot(v4d_2);
405 cout << setw(40) << "d = v4d.dot(v4d_2): " << d << endl;
406 }
408 {
409 cout << "===============================================================" << endl <<
410 "Testing Vector length" << endl;
411 Vector2i v2i(1, 2);
412 Vector3f v3f(1.1f, 2.2f, 3.3f);
413 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
414 cout << setw(40) << "v2i: " << v2i.to_string() << endl;
415 cout << setw(40) << "v3f: " << v3f.to_string() << endl;
416 cout << setw(40) << "v4d: " << v4d.to_string() << endl;
417 cout << setw(40) << "v2i.length(): " << v2i.length() << endl;
418 cout << setw(40) << "v3f.length(): " << v3f.length() << endl;
419 cout << setw(40) << "v4d.length(): " << v4d.length() << endl;
420 }
422 {
423 cout << "===============================================================" << endl <<
424 "Testing Vector normalize" << endl;
425 Vector2f v2f(1.1, 2.2);
426 Vector3f v3f(1.1f, 2.2f, 3.3f);
427 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
428 cout << setw(40) << "v2f: " << v2f.to_string() << endl;
429 cout << setw(40) << "v3f: " << v3f.to_string() << endl;
430 cout << setw(40) << "v4d: " << v4d.to_string() << endl;
431 v2f.normalize();
432 cout << setw(40) << "v2f.normalize() " << v2f.to_string() << endl;
433 v3f.normalize();
434 cout << setw(40) << "v3f.normalize() " << v3f.to_string() << endl;
435 v4d.normalize();
436 cout << setw(40) << "v4d.normalize() " << v4d.to_string() << endl;
437 cout << setw(40) << "v2f.length(): " << v2f.length() << endl;
438 cout << setw(40) << "v3f.length(): " << v3f.length() << endl;
439 cout << setw(40) << "v4d.length(): " << v4d.length() << endl;
440 }
442 {
443 cout << "===============================================================" << endl <<
444 "Testing Vector get_angle" << endl;
445 Vector2i v2i(1, 2);
446 Vector2i v2i_2(3, 4);
447 Vector3f v3f(1.1f, 2.2f, 3.3f);
448 Vector3f v3f_2(4.4, 5.5, 6.6);
449 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
450 Vector4d v4d_2(5.5, 6.6, 7.7, 8.8);
451 double d;
452 cout << setw(40) << "v2i: " << v2i.to_string() << endl;
453 cout << setw(40) << "v2i_2: " << v2i_2.to_string() << endl;
454 cout << setw(40) << "v3f: " << v3f.to_string() << endl;
455 cout << setw(40) << "v3f_2: " << v3f_2.to_string() << endl;
456 cout << setw(40) << "v4d: " << v4d.to_string() << endl;
457 cout << setw(40) << "v4d_2: " << v4d_2.to_string() << endl;
458 d = v2i.get_angle(v2i_2);
459 cout << setw(40) << "d = v2i.get_angle(v2i_2): " << d << endl;
460 d = v3f.get_angle(v3f_2);
461 cout << setw(40) << "d = v3f.get_angle(v3f_2): " << d << endl;
462 d = v4d.get_angle(v4d_2);
463 cout << setw(40) << "d = v4d.get_angle(v4d_2): " << d << endl;
464 }
466 {
467 cout << "===============================================================" << endl <<
468 "Testing Vector get_anglen" << endl;
469 Vector2f v2f(1.1, 2.2);
470 Vector2f v2f_2(3.3, 4.4);
471 Vector3f v3f(1.1f, 2.2f, 3.3f);
472 Vector3f v3f_2(4.4, 5.5, 6.6);
473 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
474 Vector4d v4d_2(5.5, 6.6, 7.7, 8.8);
475 double d;
476 v2f.normalize();
477 v2f_2.normalize();
478 v3f.normalize();
479 v3f_2.normalize();
480 v4d.normalize();
481 v4d_2.normalize();
482 cout << setw(40) << "v2f: " << v2f.to_string() << endl;
483 cout << setw(40) << "v2f_2: " << v2f_2.to_string() << endl;
484 cout << setw(40) << "v3f: " << v3f.to_string() << endl;
485 cout << setw(40) << "v3f_2: " << v3f_2.to_string() << endl;
486 cout << setw(40) << "v4d: " << v4d.to_string() << endl;
487 cout << setw(40) << "v4d_2: " << v4d_2.to_string() << endl;
488 d = v2f.get_anglen(v2f_2);
489 cout << setw(40) << "d = v2f.get_anglen(v2f_2): " << d << endl;
490 d = v3f.get_anglen(v3f_2);
491 cout << setw(40) << "d = v3f.get_anglen(v3f_2): " << d << endl;
492 d = v4d.get_anglen(v4d_2);
493 cout << setw(40) << "d = v4d.get_anglen(v4d_2): " << d << endl;
494 }
496 {
497 cout << "===============================================================" << endl <<
498 "Testing Vector get_proj" << endl;
499 Vector2f v2f(1.1, 2.2);
500 Vector2f v2f_2(3.3, 4.4);
501 Vector2f v2f_3(0);
502 Vector3f v3f(1.1f, 2.2f, 3.3f);
503 Vector3f v3f_2(4.4, 5.5, 6.6);
504 Vector3f v3f_3(0);
505 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
506 Vector4d v4d_2(5.5, 6.6, 7.7, 8.8);
507 Vector4d v4d_3(0);
508 cout << setw(40) << "v2f: " << v2f.to_string() << endl;
509 cout << setw(40) << "v2f_2: " << v2f_2.to_string() << endl;
510 cout << setw(40) << "v3f: " << v3f.to_string() << endl;
511 cout << setw(40) << "v3f_2: " << v3f_2.to_string() << endl;
512 cout << setw(40) << "v4d: " << v4d.to_string() << endl;
513 cout << setw(40) << "v4d_2: " << v4d_2.to_string() << endl;
514 v2f_3 = v2f.proj(v2f_2);
515 cout << setw(40) << "v2f_3 = v2f.proj(v3f_2): " << v2f_3.to_string() << endl;
516 v3f_3 = v3f.proj(v3f_2);
517 cout << setw(40) << "v3f_3 = v3f.proj(v3f_2): " << v3f_3.to_string() << endl;
518 v4d_3 = v4d.proj(v4d_2);
519 cout << setw(40) << "v4d_3 = v4d.proj(v4d_2): " << v4d_3.to_string() << endl;
520 v2f_3.assign(0,0);
521 v3f_3.assign(0,0,0);
522 v4d_3.assign(0,0,0,0);
523 v2f.proj(v2f_2, v2f_3);
524 cout << setw(40) << "v2f.proj(v2f_2, v2f_3): " << v2f_3.to_string() << endl;
525 v3f.proj(v3f_2, v3f_3);
526 cout << setw(40) << "v3f.proj(v3f_2, v3f_3): " << v3f_3.to_string() << endl;
527 v4d.proj(v4d_2, v4d_3);
528 cout << setw(40) << "v4d.proj(v4d_2, v4d_3): " << v4d_3.to_string() << endl;
529 }
531 }
533 ////////////////////////////////////////////////////////////////////////////////
534 void test_matrix(void)
535 {
536 string s1, s2;
538 {
539 cout << "===============================================================" << endl <<
540 "Testing Maxtrix constructors" << endl;
541 Matrix22i m22i_1(0);
542 Matrix22i m22i_2(1);
543 Matrix22i m22i_3(1, 2, 3, 4);
544 Matrix22i m22i_4(m22i_3);
546 cout << setw(40) << "m22i_1: " << m22i_1.to_string() << endl;
547 cout << setw(40) << "m22i_2: " << m22i_2.to_string() << endl;
548 cout << setw(40) << "m22i_3: " << m22i_3.to_string() << endl;
549 cout << setw(40) << "m22i_4: " << m22i_4.to_string() << endl;
551 Matrix33f m33f_1(0.0f);
552 Matrix33f m33f_2(1.1f);
553 Matrix33f m33f_3(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
554 Matrix33f m33f_4(m33f_3);
556 cout << setw(40) << "m33f_1: " << m33f_1.to_string() << endl;
557 cout << setw(40) << "m33f_2: " << m33f_2.to_string() << endl;
558 cout << setw(40) << "m33f_3: " << m33f_3.to_string() << endl;
559 cout << setw(40) << "m33f_4: " << m33f_4.to_string() << endl;
561 Matrix44d m44d_1(0.0);
562 Matrix44d m44d_2(1.1);
563 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,
564 12.12, 13.13, 14.14, 15.15, 16.16);
565 Matrix44d m44d_4(m44d_3);
567 cout << setw(40) << "m44d_1: " << m44d_1.to_string() << endl;
568 cout << setw(40) << "m44d_2: " << m44d_2.to_string() << endl;
569 cout << setw(40) << "m44d_3: " << m44d_3.to_string() << endl;
570 cout << setw(40) << "m44d_4: " << m44d_4.to_string() << endl;
571 }
573 {
574 cout << "===============================================================" << endl <<
575 "Testing Maxtrix array indexing" << endl;
576 Matrix22i m22i(1, 2, 3, 4);
578 cout << setw(40) << "m22i: " << m22i[0] << " " << m22i[1] << " " << m22i[2] << " " << m22i[3] << " "<< endl;
580 Matrix33f m33f(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
582 cout << setw(40) << "m33f: " << m33f[0] << " " << m33f[1] << " " << m33f[2] << " " << m33f[3] << " " << m33f[4] << " " << m33f[5] << " " << m33f[6] << " " << m33f[7] << " " << m33f[8] << endl;
584 Matrix44d m44d(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11,
585 12.12, 13.13, 14.14, 15.15, 16.16);
587 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;
588 }
590 {
591 cout << "===============================================================" << endl <<
592 "Testing Maxtrix assignment" << endl;
593 Matrix22i m22i_1(1, 2, 3, 4);
594 Matrix22i m22i_2(5, 6, 7, 8);
596 cout << setw(40) << "m22i_1: " << m22i_1.to_string() << endl;
597 cout << setw(40) << "m22i_2: " << m22i_2.to_string() << endl;
599 m22i_2 = m22i_1;
600 cout << setw(40) << "m22i_2 = m22i_1: " << m22i_2.to_string() << endl;
602 m22i_2.assign(9, 10, 11, 12);
603 cout << setw(40) << "m22i_2.assign(9, 10, 11, 12): "
604 << m22i_2.to_string() << endl;
606 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
607 Matrix33f m33f_2(10.10f, 11.11f, 12.12f, 13.13f, 14.14f, 15.15f, 16.16f, 17.17f, 18.18f);
609 cout << setw(40) << "m33f_1: " << m33f_1.to_string() << endl;
610 cout << setw(40) << "m33f_2: " << m33f_2.to_string() << endl;
612 m33f_2 = m33f_1;
613 cout << setw(40) << "m33f_2 = m33f_1: " << m33f_2.to_string() << endl;
615 m33f_2.assign(19.19f, 20.20f, 21.21f, 22.22f, 23.23f, 24.24f, 25.25f, 26.26f, 27.27f);
616 cout << setw(40) << "m33f_2.assign(19.19f, 20.20f, ... , 27.27f): "
617 << m33f_2.to_string() << endl;
619 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,
620 12.12, 13.13, 14.14, 15.15, 16.16);
621 Matrix44d m44d_2(16.16, 17.17, 18.18, 19.19,
622 20.20, 21.21, 22.22, 23.23,
623 24.24, 25.25, 26.26, 27.27,
624 28.28, 29.29, 30.30, 31.31);
626 cout << setw(40) << "m44d_1: " << m44d_1.to_string() << endl;
627 cout << setw(40) << "m44d_2: " << m44d_2.to_string() << endl;
629 m44d_2 = m44d_1;
630 cout << setw(40) << "m44d_2 = m44d_1: " << m44d_2.to_string() << endl;
632 m44d_2.assign(32.32, 33.33, 34.34, 35.35,
633 36.36, 37.37, 38.38, 39.39,
634 40.40, 41.41, 42.42, 43.43,
635 44.44, 45.45, 46.46, 47.47);
636 cout << setw(40) << "m44d_2.assign(32.32, 33.33, ... , 47.47): "
637 << m44d_2.to_string() << endl;
638 }
640 {
641 cout << "===============================================================" << endl <<
642 "Testing Maxtrix comparison" << endl;
643 Matrix22i m22i_1(1, 2, 3, 4);
644 Matrix22i m22i_2(1, 2, 3, 4);
645 Matrix22i m22i_3(0);
647 cout << setw(40) << "m22i_1: " << m22i_1.to_string() << endl;
648 cout << setw(40) << "m22i_2: " << m22i_2.to_string() << endl;
649 cout << setw(40) << "m22i_3: " << m22i_3.to_string() << endl;
650 cout << boolalpha;
651 cout << setw(40) << "m22i_1 == m22i_2: " << (m22i_1 == m22i_2) << endl;
652 cout << setw(40) << "m22i_1 == m22i_3: " << (m22i_2 == m22i_3) << endl;
653 cout << setw(40) << "m22i_1 != m22i_2: " << (m22i_1 != m22i_2) << endl;
654 cout << setw(40) << "m22i_1 != m22i_3: " << (m22i_2 != m22i_3) << endl;
656 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
657 Matrix33f m33f_2(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
658 Matrix33f m33f_3(0.0f);
660 cout << setw(40) << "m33f_1: " << m33f_1.to_string() << endl;
661 cout << setw(40) << "m33f_2: " << m33f_2.to_string() << endl;
662 cout << setw(40) << "m33f_3: " << m33f_3.to_string() << endl;
663 cout << boolalpha;
664 cout << setw(40) << "m33f_1 == m33f_2: " << (m33f_1 == m33f_2) << endl;
665 cout << setw(40) << "m33f_1 == m33f_3: " << (m33f_2 == m33f_3) << endl;
666 cout << setw(40) << "m33f_1 != m33f_2: " << (m33f_1 != m33f_2) << endl;
667 cout << setw(40) << "m33f_1 != m33f_3: " << (m33f_2 != m33f_3) << endl;
669 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,
670 12.12, 13.13, 14.14, 15.15, 16.16);
671 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,
672 12.12, 13.13, 14.14, 15.15, 16.16);
673 Matrix44d m44d_3(0.0);
675 cout << setw(40) << "m44d_1: " << m44d_1.to_string() << endl;
676 cout << setw(40) << "m44d_2: " << m44d_2.to_string() << endl;
677 cout << setw(40) << "m44d_3: " << m44d_3.to_string() << endl;
678 cout << boolalpha;
679 cout << setw(40) << "m44d_1 == m44d_2: " << (m44d_1 == m44d_2) << endl;
680 cout << setw(40) << "m44d_1 == m44d_3: " << (m44d_2 == m44d_3) << endl;
681 cout << setw(40) << "m44d_1 != m44d_2: " << (m44d_1 != m44d_2) << endl;
682 cout << setw(40) << "m44d_1 != m44d_3: " << (m44d_2 != m44d_3) << endl;
683 }
685 {
686 cout << "===============================================================" << endl <<
687 "Testing Maxtrix addition" << endl;
688 Matrix22i m22i_1(1, 2, 3, 4);
689 Matrix22i m22i_2(5, 6, 7, 8);
690 Matrix22i m22i_3(0);
692 cout << setw(40) << "m22i_1: " << m22i_1.to_string() << endl;
693 cout << setw(40) << "m22i_2: " << m22i_2.to_string() << endl;
694 cout << setw(40) << "m22i_3: " << m22i_3.to_string() << endl;
695 m22i_3 = m22i_1 + m22i_2;
696 cout << setw(40) << "m22i_3 = m22i_1 + m22i_2: " << m22i_3.to_string() << endl;
698 m22i_3 += m22i_1;
699 cout << setw(40) << "m22i_3 += m22i_1: " << m22i_3.to_string() << endl;
701 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
702 Matrix33f m33f_2(10.10f, 11.11f, 12.12f, 13.13f, 14.14f, 15.15f, 16.16f, 17.17f, 18.18f);
703 Matrix33f m33f_3(0.0f);
705 cout << setw(40) << "m33f_1: " << m33f_1.to_string() << endl;
706 cout << setw(40) << "m33f_2: " << m33f_2.to_string() << endl;
707 cout << setw(40) << "m33f_3: " << m33f_3.to_string() << endl;
708 m33f_3 = m33f_1 + m33f_2;
709 cout << setw(40) << "m33f_3 = m33f_1 + m33f_2: " << m33f_3.to_string() << endl;
711 m33f_3 += m33f_1;
712 cout << setw(40) << "m33f_3 += m33f_1: " << m33f_3.to_string() << endl;
714 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,
715 12.12, 13.13, 14.14, 15.15, 16.16);
716 Matrix44d m44d_2(16.16, 17.17, 18.18, 19.19,
717 20.20, 21.21, 22.22, 23.23,
718 24.24, 25.25, 26.26, 27.27,
719 28.28, 29.29, 30.30, 31.31);
720 Matrix44d m44d_3(0.0);
722 cout << setw(40) << "m44d_1: " << m44d_1.to_string() << endl;
723 cout << setw(40) << "m44d_2: " << m44d_2.to_string() << endl;
724 cout << setw(40) << "m44d_3: " << m44d_3.to_string() << endl;
725 m44d_3 = m44d_1 + m44d_2;
726 cout << setw(40) << "m44d_3 = m44d_1 + m44d_2: " << m44d_3.to_string() << endl;
728 m44d_3 += m44d_1;
729 cout << setw(40) << "m44d_3 += m44d_1: " << m44d_3.to_string() << endl;
730 }
732 {
733 cout << "===============================================================" << endl <<
734 "Testing Maxtrix subtraction" << endl;
735 Matrix22i m22i_1(1, 2, 3, 4);
736 Matrix22i m22i_2(5, 6, 7, 8);
737 Matrix22i m22i_3(0);
739 cout << setw(40) << "m22i_1: " << m22i_1.to_string() << endl;
740 cout << setw(40) << "m22i_2: " << m22i_2.to_string() << endl;
741 cout << setw(40) << "m22i_3: " << m22i_3.to_string() << endl;
742 m22i_3 = m22i_1 - m22i_2;
743 cout << setw(40) << "m22i_3 = m22i_1 - m22i_2: " << m22i_3.to_string() << endl;
745 m22i_3 -= m22i_1;
746 cout << setw(40) << "m22i_3 -= m22i_1: " << m22i_3.to_string() << endl;
748 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
749 Matrix33f m33f_2(10.10f, 11.11f, 12.12f, 13.13f, 14.14f, 15.15f, 16.16f, 17.17f, 18.18f);
750 Matrix33f m33f_3(0.0f);
752 cout << setw(40) << "m33f_1: " << m33f_1.to_string() << endl;
753 cout << setw(40) << "m33f_2: " << m33f_2.to_string() << endl;
754 cout << setw(40) << "m33f_3: " << m33f_3.to_string() << endl;
755 m33f_3 = m33f_1 - m33f_2;
756 cout << setw(40) << "m33f_3 = m33f_1 - m33f_2: " << m33f_3.to_string() << endl;
758 m33f_3 -= m33f_1;
759 cout << setw(40) << "m33f_3 -= m33f_1: " << m33f_3.to_string() << endl;
761 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,
762 12.12, 13.13, 14.14, 15.15, 16.16);
763 Matrix44d m44d_2(16.16, 17.17, 18.18, 19.19,
764 20.20, 21.21, 22.22, 23.23,
765 24.24, 25.25, 26.26, 27.27,
766 28.28, 29.29, 30.30, 31.31);
767 Matrix44d m44d_3(0.0);
769 cout << setw(40) << "m44d_1: " << m44d_1.to_string() << endl;
770 cout << setw(40) << "m44d_2: " << m44d_2.to_string() << endl;
771 cout << setw(40) << "m44d_3: " << m44d_3.to_string() << endl;
772 m44d_3 = m44d_1 - m44d_2;
773 cout << setw(40) << "m44d_3 = m44d_1 - m44d_2: " << m44d_3.to_string() << endl;
775 m44d_3 -= m44d_1;
776 cout << setw(40) << "m44d_3 -= m44d_1: " << m44d_3.to_string() << endl;
777 }
779 {
780 cout << "===============================================================" << endl <<
781 "Testing Matrix scalar multiplication" << endl;
782 Matrix22i m22i_1(1, 2, 3, 4);
783 Matrix22i m22i_2(0);
784 int i = 2;
786 cout << setw(40) << "i: " << i << endl;
787 cout << setw(40) << "m22i_1: " << m22i_1.to_string() << endl;
788 cout << setw(40) << "m22i_2: " << m22i_2.to_string() << endl;
789 m22i_2 = m22i_1 *i;
790 cout << setw(40) << "m22i_2 = m22i_1 * i: " << m22i_2.to_string() << endl;
791 m22i_2 = i * m22i_1;
792 cout << setw(40) << "m22i_2 = i * m22i_1: " << m22i_2.to_string() << endl;
793 m22i_2 *= i;
794 cout << setw(40) << "m22i_2 *= i: " << m22i_2.to_string() << endl;
796 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
797 Matrix33f m33f_2(0.0f);
798 float f = 2.0f;
800 cout << setw(40) << "f: " << f << endl;
801 cout << setw(40) << "m33f_1: " << m33f_1.to_string() << endl;
802 cout << setw(40) << "m33f_2: " << m33f_2.to_string() << endl;
803 m33f_2 = m33f_1 * f;
804 cout << setw(40) << "m33f_2 = m33f_1 * f: " << m33f_2.to_string() << endl;
805 m33f_2 = f * m33f_1;
806 cout << setw(40) << "m33f_2 = f * m33f_1: " << m33f_2.to_string() << endl;
807 m33f_2 *= f;
808 cout << setw(40) << "m33f_2 *= f: " << m33f_2.to_string() << endl;
810 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,
811 12.12, 13.13, 14.14, 15.15, 16.16);
812 Matrix44d m44d_2(0.0);
813 double d = 2.0f;
815 cout << setw(40) << "d: " << d << endl;
816 cout << setw(40) << "m44d_1: " << m44d_1.to_string() << endl;
817 cout << setw(40) << "m44d_2: " << m44d_2.to_string() << endl;
818 m44d_2 = m44d_1 * d;
819 cout << setw(40) << "m44d_2 = m44d_1 * d: " << m44d_2.to_string() << endl;
820 m44d_2 = d * m44d_1;
821 cout << setw(40) << "m44d_2 = d * m44d_1: " << m44d_2.to_string() << endl;
822 m44d_2 *= d;
823 cout << setw(40) << "m44d_2 *= d: " << m44d_2.to_string() << endl;
824 }
826 {
827 cout << "===============================================================" << endl <<
828 "Testing Matrix scalar division" << endl;
829 Matrix22i m22i_1(1, 2, 3, 4);
830 Matrix22i m22i_2(0);
831 int i = 2;
833 cout << setw(40) << "i: " << i << endl;
834 cout << setw(40) << "m22i_1: " << m22i_1.to_string() << endl;
835 cout << setw(40) << "m22i_2: " << m22i_2.to_string() << endl;
836 m22i_2 = m22i_1 / i;
837 cout << setw(40) << "m22i_2 = m22i_1 / i: " << m22i_2.to_string() << endl;
838 m22i_1 /= i;
839 cout << setw(40) << "m22i_1 /= i: " << m22i_2.to_string() << endl;
841 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
842 Matrix33f m33f_2(0.0f);
843 float f = 2.0f;
845 cout << setw(40) << "f: " << f << endl;
846 cout << setw(40) << "m33f_1: " << m33f_1.to_string() << endl;
847 cout << setw(40) << "m33f_2: " << m33f_2.to_string() << endl;
848 m33f_2 = m33f_1 / f;
849 cout << setw(40) << "m33f_2 = m33f_1 / f: " << m33f_2.to_string() << endl;
850 m33f_1 /= f;
851 cout << setw(40) << "m33f_1 /= f: " << m33f_2.to_string() << endl;
853 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,
854 12.12, 13.13, 14.14, 15.15, 16.16);
855 Matrix44d m44d_2(0.0);
856 double d = 2.0f;
858 cout << setw(40) << "d: " << d << endl;
859 cout << setw(40) << "m44d_1: " << m44d_1.to_string() << endl;
860 cout << setw(40) << "m44d_2: " << m44d_2.to_string() << endl;
861 m44d_2 = m44d_1 / d;
862 cout << setw(40) << "m44d_2 = m44d_1 / d: " << m44d_2.to_string() << endl;
863 m44d_1 /= d;
864 cout << setw(40) << "m44d_1 /= d: " << m44d_2.to_string() << endl;
865 }
867 {
868 cout << "===============================================================" << endl <<
869 "Testing Maxtrix multiplication" << endl;
870 Matrix22i m22i_1(1, 2, 3, 4);
871 Matrix22i m22i_2(5, 6, 7, 8);
872 Matrix22i m22i_3(0);
874 cout << setw(40) << "m22i_1: " << m22i_1.to_string() << endl;
875 cout << setw(40) << "m22i_2: " << m22i_2.to_string() << endl;
876 cout << setw(40) << "m22i_3: " << m22i_3.to_string() << endl;
877 m22i_3 = m22i_1 * m22i_2;
878 cout << setw(40) << "m22i_3 = m22i_1 * m22i_2: " << m22i_3.to_string() << endl;
880 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
881 Matrix33f m33f_2(10.10f, 11.11f, 12.12f, 13.13f, 14.14f, 15.15f, 16.16f, 17.17f, 18.18f);
882 Matrix33f m33f_3(0.0f);
884 cout << setw(40) << "m33f_1: " << m33f_1.to_string() << endl;
885 cout << setw(40) << "m33f_2: " << m33f_2.to_string() << endl;
886 cout << setw(40) << "m33f_3: " << m33f_3.to_string() << endl;
887 m33f_3 = m33f_1 * m33f_2;
888 cout << setw(40) << "m33f_3 = m33f_1 * m33f_2: " << m33f_3.to_string() << endl;
890 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,
891 12.12, 13.13, 14.14, 15.15, 16.16);
892 Matrix44d m44d_2(16.16, 17.17, 18.18, 19.19,
893 20.20, 21.21, 22.22, 23.23,
894 24.24, 25.25, 26.26, 27.27,
895 28.28, 29.29, 30.30, 31.31);
896 Matrix44d m44d_3(0.0);
898 cout << setw(40) << "m44d_1: " << m44d_1.to_string() << endl;
899 cout << setw(40) << "m44d_2: " << m44d_2.to_string() << endl;
900 cout << setw(40) << "m44d_3: " << m44d_3.to_string() << endl;
901 m44d_3 = m44d_1 * m44d_2;
902 cout << setw(40) << "m44d_3 = m44d_1 * m44d_2: " << m44d_3.to_string() << endl;
903 }
905 {
906 cout << "===============================================================" << endl <<
907 "Testing Maxtrix det" << endl;
908 Matrix22i m22i_1(1, 2, 3, 4);
909 double d;
911 cout << setw(40) << "m22i_1: " << m22i_1.to_string() << endl;
912 d = det(m22i_1);
913 cout << setw(40) << "d = det(m22i_1): " << d << endl;
915 // Note: singular matrix. The real determinant is exactly zero.
916 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
918 cout << setw(40) << "m33f_1: " << m33f_1.to_string() << endl;
919 d = det(m33f_1);
920 cout << setw(40) << "d = det(m33f_1): " << d << endl;
922 // Note: singular matrix. The real determinant is exactly zero.
923 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,
924 12.12, 13.13, 14.14, 15.15, 16.16);
926 cout << setw(40) << "m44d_1: " << m44d_1.to_string() << endl;
927 d = det(m44d_1);
928 cout << setw(40) << "d = det(m44d_1): " << d << endl;
930 }
932 {
933 cout << "===============================================================" << endl <<
934 "Testing Maxtrix transpose" << endl;
935 Matrix22i m22i_1(1, 2, 3, 4);
936 Matrix22i m22i_2;
938 cout << setw(40) << "m22i_1: " << m22i_1.to_string() << endl;
939 m22i_2 = transpose(m22i_1);
940 cout << setw(40) << "m22i_2 = transpose(m22i_1): " << m22i_2.to_string() << endl;
942 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
943 Matrix33f m33f_2(0.0f);
945 cout << setw(40) << "m33f_1: " << m33f_1.to_string() << endl;
946 m33f_2 = transpose(m33f_1);
947 cout << setw(40) << "m33f_2 = transpose(m33f_1): " << m33f_2.to_string() << endl;
949 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,
950 12.12, 13.13, 14.14, 15.15, 16.16);
951 Matrix44d m44d_2(0.0);
953 cout << setw(40) << "m44d_1: " << m44d_1.to_string() << endl;
954 m44d_2 = transpose(m44d_1);
955 cout << setw(40) << "m44d_2 = transpose(m44d_1): " << m44d_2.to_string() << endl;
956 }
958 {
959 cout << "===============================================================" << endl <<
960 "Testing Maxtrix setidentity" << endl;
961 Matrix22i m22i_1(1, 2, 3, 4);
963 cout << setw(40) << "m22i_1: " << m22i_1.to_string() << endl;
964 m22i_1.setidentity();
965 cout << setw(40) << "m22i_1.setidentity(): " << m22i_1.to_string() << endl;
967 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
969 cout << setw(40) << "m33f_1: " << m33f_1.to_string() << endl;
970 m33f_1.setidentity();
971 cout << setw(40) << "m33f_1.setidentity(): " << m33f_1.to_string() << endl;
973 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,
974 12.12, 13.13, 14.14, 15.15, 16.16);
976 cout << setw(40) << "m44d_1: " << m44d_1.to_string() << endl;
977 m44d_1.setidentity();
978 cout << setw(40) << "m44d_1.setidentity(): " << m44d_1.to_string() << endl;
979 }
981 {
982 cout << "===============================================================" << endl <<
983 "Testing Matrix getrow() and getcol()" << endl;
984 Matrix22i m22i_1(1, 2, 3, 4);
985 Vector2i v2i_1(0);
987 cout << setw(40) << "m22i_1: " << m22i_1.to_string() << endl;
988 v2i_1 = m22i_1.getrow(0);
989 cout << setw(40) << "v2i_1 = m22i_1.getrow(0): " << v2i_1.to_string() << endl;
990 v2i_1 = m22i_1.getrow(1);
991 cout << setw(40) << "v2i_1 = m22i_1.getrow(1): " << v2i_1.to_string() << endl;
992 v2i_1 = m22i_1.getcol(0);
993 cout << setw(40) << "v2i_1 = m22i_1.getcol(0): " << v2i_1.to_string() << endl;
994 v2i_1 = m22i_1.getcol(1);
995 cout << setw(40) << "v2i_1 = m22i_1.getcol(1): " << v2i_1.to_string() << endl;
997 Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f);
998 Vector3f v3f_1(0);
1000 cout << setw(40) << "m33f_1: " << m33f_1.to_string() << endl;
1001 v3f_1 = m33f_1.getrow(0);
1002 cout << setw(40) << "v3f_1 = m33f_1.getrow(0): " << v3f_1.to_string() << endl;
1003 v3f_1 = m33f_1.getrow(1);
1004 cout << setw(40) << "v3f_1 = m33f_1.getrow(1): " << v3f_1.to_string() << endl;
1005 v3f_1 = m33f_1.getrow(2);
1006 cout << setw(40) << "v3f_1 = m33f_1.getrow(2): " << v3f_1.to_string() << endl;
1007 v3f_1 = m33f_1.getcol(0);
1008 cout << setw(40) << "v3f_1 = m33f_1.getcol(0): " << v3f_1.to_string() << endl;
1009 v3f_1 = m33f_1.getcol(1);
1010 cout << setw(40) << "v3f_1 = m33f_1.getcol(1): " << v3f_1.to_string() << endl;
1011 v3f_1 = m33f_1.getcol(2);
1012 cout << setw(40) << "v3f_1 = m33f_1.getcol(2): " << v3f_1.to_string() << endl;
1014 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,
1015 12.12, 13.13, 14.14, 15.15, 16.16);
1016 Vector4d v4d_1(0);
1018 cout << setw(40) << "m44d_1: " << m44d_1.to_string() << endl;
1019 v4d_1 = m44d_1.getrow(0);
1020 cout << setw(40) << "v4d_1 = m44d_1.getrow(0): " << v4d_1.to_string() << endl;
1021 v4d_1 = m44d_1.getrow(1);
1022 cout << setw(40) << "v4d_1 = m44d_1.getrow(1): " << v4d_1.to_string() << endl;
1023 v4d_1 = m44d_1.getrow(2);
1024 cout << setw(40) << "v4d_1 = m44d_1.getrow(2): " << v4d_1.to_string() << endl;
1025 v4d_1 = m44d_1.getrow(3);
1026 cout << setw(40) << "v4d_1 = m44d_1.getrow(3): " << v4d_1.to_string() << endl;
1028 v4d_1 = m44d_1.getcol(0);
1029 cout << setw(40) << "v4d_1 = m44d_1.getcol(0): " << v4d_1.to_string() << endl;
1030 v4d_1 = m44d_1.getcol(1);
1031 cout << setw(40) << "v4d_1 = m44d_1.getcol(1): " << v4d_1.to_string() << endl;
1032 v4d_1 = m44d_1.getcol(2);
1033 cout << setw(40) << "v4d_1 = m44d_1.getcol(2): " << v4d_1.to_string() << endl;
1034 v4d_1 = m44d_1.getcol(3);
1035 cout << setw(40) << "v4d_1 = m44d_1.getcol(3): " << v4d_1.to_string() << endl;
1039 cout << "===============================================================" << endl <<
1040 "Testing Matrix setrow() and setcol()" << endl;
1041 Matrix22i m22i_1;
1042 Vector2i v2i_1(2, 3);
1044 m22i_1.setidentity();
1045 cout << setw(40) << "m22i_1: " << m22i_1.to_string() << endl;
1046 m22i_1.setrow(0, v2i_1);
1047 cout << setw(40) << "m22i_1.setrow(0, v2i_1): " << m22i_1.to_string() << endl;
1049 m22i_1.setidentity();
1050 m22i_1.setrow(1, v2i_1);
1051 cout << setw(40) << "m22i_1.setrow(1, v2i_1): " << m22i_1.to_string() << endl;
1053 m22i_1.setidentity();
1054 m22i_1.setrow(1, 4, 5);
1055 cout << setw(40) << "m22i_1.setrow(1, 4, 5): " << m22i_1.to_string() << endl;
1057 m22i_1.setidentity();
1058 m22i_1.setcol(0, v2i_1);
1059 cout << setw(40) << "m22i_1.setcol(0, v2i_1): " << m22i_1.to_string() << endl;
1061 m22i_1.setidentity();
1062 m22i_1.setcol(1, v2i_1);
1063 cout << setw(40) << "m22i_1.setcol(1, v2i_1): " << m22i_1.to_string() << endl;
1065 m22i_1.setidentity();
1066 m22i_1.setcol(1, 4, 5);
1067 cout << setw(40) << "m22i_1.setcol(1, 4, 5): " << m22i_1.to_string() << endl;
1069 Matrix33f m33f_1;
1070 Vector3f v3f_1(0);
1072 m33f_1.setidentity();
1073 cout << setw(40) << "m33f_1: " << m33f_1.to_string() << endl;
1074 m33f_1.setrow(0, v3f_1);
1075 cout << setw(40) << "m33f_1.setrow(0, v3f_1): " << m33f_1.to_string() << endl;
1077 m33f_1.setidentity();
1078 m33f_1.setrow(1, v3f_1);
1079 cout << setw(40) << "m33f_1.setrow(1, v3f_1): " << m33f_1.to_string() << endl;
1081 m33f_1.setidentity();
1082 m33f_1.setrow(1, 2.2f, 3.3f, 4.4f);
1083 cout << setw(40) << "m33f_1.setrow(1, 2.2f, 3.3f, 4.4f): "
1084 << m33f_1.to_string() << endl;
1086 m33f_1.setidentity();
1087 m33f_1.setcol(0, v3f_1);
1088 cout << setw(40) << "m33f_1.setcol(0, v3f_1): " << m33f_1.to_string() << endl;
1090 m33f_1.setidentity();
1091 m33f_1.setcol(1, v3f_1);
1092 cout << setw(40) << "m33f_1.setcol(1, v3f_1): " << m33f_1.to_string() << endl;
1094 m33f_1.setidentity();
1095 m33f_1.setcol(1, 2.2f, 3.3f, 4.4f);
1096 cout << setw(40) << "m33f_1.setcol(1, 2.2f, 3.3f, 4.4f: "
1097 << m33f_1.to_string() << endl;
1099 Matrix44d m44d_1;
1100 Vector4d v4d_1(0);
1102 m44d_1.setidentity();
1103 cout << setw(40) << "m44d_1: " << m44d_1.to_string() << endl;
1104 m44d_1.setrow(0, v4d_1);
1105 cout << setw(40) << "m44d_1.setrow(0, v4d_1): " << m44d_1.to_string() << endl;
1107 m44d_1.setidentity();
1108 m44d_1.setrow(1, v4d_1);
1109 cout << setw(40) << "m44d_1.setrow(1, v4d_1): " << m44d_1.to_string() << endl;
1111 m44d_1.setidentity();
1112 m44d_1.setrow(1, 2.2, 3.3, 4.4, 5.5);
1113 cout << setw(40) << "m44d_1.setrow(1, 2.2, 3.3, 4.4, 5.5): "
1114 << m44d_1.to_string() << endl;
1116 m44d_1.setidentity();
1117 m44d_1.setcol(0, v4d_1);
1118 cout << setw(40) << "m44d_1.setcol(0, v4d_1): " << m44d_1.to_string() << endl;
1120 m44d_1.setidentity();
1121 m44d_1.setcol(1, v4d_1);
1122 cout << setw(40) << "m44d_1.setcol(1, v4d_1): " << m44d_1.to_string() << endl;
1124 m44d_1.setidentity();
1125 m44d_1.setcol(1, 2.2, 3.3, 4.4, 5.5);
1126 cout << setw(40) << "m44d_1.setcol(1, 2.2, 3.3, 4.4, 5.5: "
1127 << m44d_1.to_string() << endl;
1131 ////////////////////////////////////////////////////////////////////////////////
1132 void test_all(void)
1134 test_vector();
1135 test_matrix();
1138 ////////////////////////////////////////////////////////////////////////////////
1139 void show_menu(void)
1141 cout << endl << endl
1142 << "Test what?" << endl
1143 << "0) All" << endl << endl
1144 << "1) Vector" << endl
1145 << "2) Matrix" << endl
1146 << endl
1147 << "99 Quit" << endl;
1150 ////////////////////////////////////////////////////////////////////////////////
1151 int main (int argc, char * argv[])
1153 int retval = 0;
1155 test_all();
1156 return 0;
1158 try
1160 int choice = -1;
1162 while (choice != 99)
1164 show_menu();
1165 cin >> choice;
1166 if(!cin)
1168 cin.clear();
1169 cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
1171 if (choice != 99)
1173 switch (choice)
1175 case 0:
1176 test_all();
1177 break;
1178 case 1:
1179 test_vector();
1180 break;
1181 case 2:
1182 test_matrix();
1183 break;
1184 default:
1185 cout << "Unrecognized choice. Please try again." << endl;
1187 choice = -1;
1191 catch (const std::exception & error)
1193 string e = "Caught exception: ";
1194 e += error.what();
1195 cerr << e << endl;
1196 retval = 1;
1199 return retval;;
1203 #endif