Subversion Repositories gelsvn

Rev

Rev 20 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 20 Rev 35
Line 1... Line 1...
1
#include <iostream>
1
#include <iostream>
-
 
2
#include <cmath>
-
 
3
#include <ctime>
-
 
4
#include <cstdlib>
-
 
5
#include <climits>
2
 
6
 
-
 
7
#include "CGLA/Vec2d.h"
3
#include "CGLA/Vec2f.h"
8
#include "CGLA/Vec2f.h"
4
#include "CGLA/Vec2i.h"
9
#include "CGLA/Vec2i.h"
5
#include "CGLA/Vec3i.h"
10
#include "CGLA/Vec3i.h"
6
#include "CGLA/Vec3f.h"
11
#include "CGLA/Vec3f.h" 
7
#include "CGLA/Vec3d.h"
12
#include "CGLA/Vec3d.h" 
-
 
13
#include "CGLA/Vec3Hf.h" // next
8
#include "CGLA/Vec3Hf.h"
14
#include "CGLA/Vec3uc.h"
-
 
15
#include "CGLA/Vec3usi.h"
-
 
16
#include "CGLA/Vec4f.h"
-
 
17
#include "CGLA/Vec4d.h"
-
 
18
#include "CGLA/Vec4uc.h"
-
 
19
#include "CGLA/Quaternion.h"
9
#include "Timer.h"
20
#include "Timer.h"
10
 
21
 
11
using namespace std;
22
using namespace std;
12
using namespace CGLA;
23
using namespace CGLA;
13
 
24
 
-
 
25
namespace
-
 
26
{
-
 
27
  // To find a pseudo-random number in the interval [0,1[
-
 
28
  double my_random()
-
 
29
  {
-
 
30
    return rand()/(static_cast<double>(RAND_MAX) + 1.0);
-
 
31
  }
-
 
32
}
14
 
33
 
15
/* This is a non-exhaustive test program for CGLA */
34
/* This is a non-exhaustive test program for CGLA */
16
main()
35
int main()
17
{
36
{
-
 
37
  int success = 0;
-
 
38
  Timer t;
-
 
39
 
-
 
40
  srand(time(0));
-
 
41
 
-
 
42
  t.start();
-
 
43
 
-
 
44
  ////////////////////////////////////////////////
-
 
45
  //                V e c 2 d
-
 
46
  ////////////////////////////////////////////////
-
 
47
 
-
 
48
  // Constructors
-
 
49
 
-
 
50
  {
-
 
51
    Vec2d x1;
-
 
52
    success += _isnan(x1[0]) && _isnan(x1[1]);
-
 
53
 
-
 
54
    double xi1 = my_random(), xi2 = my_random();
-
 
55
    Vec2d x2(xi1, xi2);
-
 
56
    success += x2[0] == xi1 && x2[1] == xi2;
-
 
57
 
-
 
58
    int xii1 = rand(), xii2 = rand();
-
 
59
    Vec2i i1(xii1, xii2);
-
 
60
    Vec2d x3(i1);
-
 
61
    success += x3[0] == xii1 && x3[1] == xii2;
-
 
62
 
-
 
63
    float xiii1 = my_random(), xiii2 = my_random();
-
 
64
    Vec2f f1(xiii1, xiii2);
-
 
65
    Vec2d x4(f1);
-
 
66
    success += x4[0] == xiii1 && x4[1] == xiii2;
-
 
67
 
-
 
68
    double xiiii = my_random();
-
 
69
    Vec2d x5(xiiii);
-
 
70
    success += x5[0] == xiiii && x5[1] == xiiii;
-
 
71
  }
-
 
72
  if(success != 5)
-
 
73
  {
-
 
74
    cout << "Failure in test of Vec2d Constructors";
-
 
75
    return 1;
-
 
76
  }
-
 
77
  success = 0;
-
 
78
 
-
 
79
  // Data manipulation
-
 
80
 
-
 
81
  {
-
 
82
    Vec2d x1;    
-
 
83
 
-
 
84
    success += x1.get_dim() == 2;
-
 
85
 
-
 
86
    double xi1 = my_random(), xi2 = my_random();
-
 
87
    x1.set(xi1, xi2);
-
 
88
    success += x1[0] == xi1 && x1[1] == xi2;
-
 
89
 
-
 
90
    success += x1.get() == &x1[0];
-
 
91
 
-
 
92
    double temp = BIG;
-
 
93
    for(int i = 0; i < x1.get_dim(); ++i)
-
 
94
      if(x1[i] < temp)
-
 
95
	temp = x1[i];
-
 
96
    success += temp == x1.min_coord();
-
 
97
 
-
 
98
    temp = -BIG;
-
 
99
    for(int i = 0; i < x1.get_dim(); ++i)
-
 
100
      if(x1[i] > temp)
-
 
101
	temp = x1[i];
-
 
102
    success += temp == x1.max_coord();
-
 
103
  }
-
 
104
  if(success != 5)
-
 
105
  {
-
 
106
    cout << "Failure in test of Vec2d Data manipulation";
-
 
107
    return 1;
-
 
108
  }
-
 
109
  success = 0;
-
 
110
 
-
 
111
  // Comparison operators
-
 
112
 
-
 
113
  {
-
 
114
    double xi1 = my_random(), xi2 = my_random();
-
 
115
    while(xi1 == xi2)
-
 
116
    {
-
 
117
      xi1 = my_random();
-
 
118
      xi2 = my_random();
-
 
119
    }
-
 
120
 
-
 
121
    Vec2d x1(xi1, xi2), x2(xi1, xi2), x3(xi1), x4(xi2);    
-
 
122
    success += x1 == x2;
-
 
123
    success += !(x1 == x3);
-
 
124
    success += x3 == xi1;
-
 
125
    success += !(x3 == xi2);
-
 
126
    success += x1 != x3;
-
 
127
    success += !(x1 != x2);
-
 
128
 
-
 
129
    if(xi1 < xi2)
-
 
130
    {
-
 
131
      success += x3.all_l(x4);
-
 
132
      success += !(x3.all_l(x2));
-
 
133
      success += x3.all_le(x2);
-
 
134
      success += !(x4.all_le(x3));
-
 
135
      success += x4.all_g(x3);
-
 
136
      success += !(x4.all_g(x2));
-
 
137
      success += x4.all_ge(x2);
-
 
138
      success += !(x3.all_ge(x4));
-
 
139
    }
-
 
140
    else 
-
 
141
    {
-
 
142
      success += x4.all_l(x3);
-
 
143
      success += !(x4.all_l(x2));
-
 
144
      success += x4.all_le(x2);
-
 
145
      success += !(x3.all_le(x4));
-
 
146
      success += x3.all_g(x4);
-
 
147
      success += !(x3.all_g(x2));
-
 
148
      success += x3.all_ge(x2);
-
 
149
      success += !(x4.all_ge(x3));
-
 
150
    }
-
 
151
  }
-
 
152
  if(success != 14)
-
 
153
  {
-
 
154
    cout << "Failure in test of Vec2d Comparison operators";
-
 
155
    return 1;
-
 
156
  }
-
 
157
  success = 0;
-
 
158
  
-
 
159
  // Assignment operators
-
 
160
 
-
 
161
  {
-
 
162
    double xi1 = my_random(), xi2 = my_random();
-
 
163
    Vec2d x1(xi1, xi2);
-
 
164
    double xi3 = my_random();
-
 
165
    x1 *= xi3;
-
 
166
    success += x1[0] == xi1*xi3 && x1[1] == xi2*xi3;
-
 
167
 
-
 
168
    while(xi3 == 0)
-
 
169
      xi3 = my_random();
-
 
170
    x1 = Vec2d(xi1, xi2);
-
 
171
    x1 /= xi3;
-
 
172
    success += abs(x1[0] - xi1/xi3) < 1.0e-15 && abs(x1[1] - xi2/xi3) < 1.0e-15;
-
 
173
 
-
 
174
    x1 = Vec2d(xi1, xi2);
-
 
175
    x1 += xi3;
-
 
176
    success += x1[0] == xi1 + xi3 && x1[1] == xi2 + xi3;
-
 
177
 
-
 
178
    x1 = Vec2d(xi1, xi2);
-
 
179
    x1 -= xi3;
-
 
180
    success += x1[0] == xi1 - xi3 && x1[1] == xi2 - xi3;
-
 
181
 
-
 
182
    double xii1 = my_random(), xii2 = my_random();
-
 
183
    Vec2d x2(xii1, xii2);
-
 
184
    x1 = Vec2d(xi1, xi2);
-
 
185
    x2 *= x1;
-
 
186
    success += x2[0] == xi1*xii1 && x2[1] == xi2*xii2;
-
 
187
 
-
 
188
    while(xi1 == 0)
-
 
189
      xi1 = my_random();
-
 
190
    while(xi2 == 0)
-
 
191
      xi2 = my_random();
-
 
192
    x1 = Vec2d(xi1, xi2);
-
 
193
    x2 = Vec2d(xii1, xii2);
-
 
194
    x2 /= x1;
-
 
195
    success += abs(x2[0] - xii1/xi1) < 1.0e-15 && abs(x2[1] - xii2/xi2) < 1.0e-15;
-
 
196
 
-
 
197
    x2 = Vec2d(xii1, xii2);
-
 
198
    x2 += x1;
-
 
199
    success += x2[0] == xii1 + xi1 && x2[1] == xii2 + xi2;
-
 
200
    
-
 
201
    x2 = Vec2d(xii1, xii2);
-
 
202
    x2 -= x1;
-
 
203
    success += x2[0] == xii1 - xi1 && x2[1] == xii2 - xi2;    
-
 
204
  }
-
 
205
  if(success != 8)
-
 
206
  {
-
 
207
    cout << "Failure in test of Vec2d Assignment operators";
-
 
208
    return 1;
-
 
209
  }
-
 
210
  success = 0;
-
 
211
 
-
 
212
  // Unary operators
-
 
213
 
-
 
214
  {
-
 
215
    double xi1 = my_random(), xi2 = my_random();
-
 
216
    Vec2d x1 = -Vec2d(xi1, xi2);    
-
 
217
    success += x1[0] == -xi1 && x1[1] == -xi2;
-
 
218
  }
-
 
219
  if(success != 1)
-
 
220
  {
-
 
221
    cout << "Failure in test of Vec2d Unary operators";
-
 
222
    return 1;
-
 
223
  }
-
 
224
  success = 0;
-
 
225
 
-
 
226
  // Binary operators
-
 
227
 
-
 
228
  {
-
 
229
    double xi1 = my_random(), xi2 = my_random();
-
 
230
    Vec2d x1(xi1, xi2);
-
 
231
    double xii1 = my_random(), xii2 = my_random();
-
 
232
    while(xii1 == 0)
-
 
233
      xii1 = my_random();
-
 
234
    while(xii2 == 0)
-
 
235
      xii2 = my_random();
-
 
236
    Vec2d x2(xii1, xii2);
-
 
237
    Vec2d x3 = x1*x2;
-
 
238
    success += x3[0] == xi1*xii1 && x3[1] == xi2*xii2;
-
 
239
    
-
 
240
    x3 = x1 + x2;
-
 
241
    success += x3[0] == xi1 + xii1 && x3[1] == xi2 + xii2;
-
 
242
 
-
 
243
    x3 = x1 - x2;
-
 
244
    success += x3[0] == xi1 - xii1 && x3[1] == xi2 - xii2;
-
 
245
    
-
 
246
    x3 = x1/x2;
-
 
247
    success += abs(x3[0] - xi1/xii1) < 1.0e-15 && abs(x3[1] - xi2/xii2) < 1.0e-15;
-
 
248
 
-
 
249
    double xi3 = my_random();
-
 
250
    x3 = x1*xi3;
-
 
251
    success += x3[0] == xi1*xi3 && x3[1] == xi2*xi3;
-
 
252
    
-
 
253
    x3 = xi3*x1;
-
 
254
    success += x3[0] == xi1*xi3 && x3[1] == xi2*xi3;
-
 
255
 
-
 
256
    float xi4 = my_random();
-
 
257
    x3 = xi4*x1;
-
 
258
    success += x3[0] == xi1*xi4 && x3[1] == xi2*xi4;
-
 
259
    
-
 
260
    x3 = x1*xi4;
-
 
261
    success += x3[0] == xi1*xi4 && x3[1] == xi2*xi4;
-
 
262
 
-
 
263
    int xi5 = rand();
-
 
264
    x3 = xi5*x1;
-
 
265
    success += x3[0] == xi1*xi5 && x3[1] == xi2*xi5;
-
 
266
    
-
 
267
    x3 = x1*xi5;
-
 
268
    success += x3[0] == xi1*xi5 && x3[1] == xi2*xi5;
-
 
269
 
-
 
270
    while(xi3 == 0)
-
 
271
      xi3 = my_random();
-
 
272
    x3 = x1/xi3;
-
 
273
    success += abs(x3[0] - xi1/xi3) < 1.0e-15 && abs(x3[1] - xi2/xi3) < 1.0e-15;
-
 
274
  } 
-
 
275
  if(success != 11)
-
 
276
  {
-
 
277
    cout << "Failure in test of Vec2d Binary operators";
-
 
278
    return 1;
-
 
279
  }
-
 
280
  success = 0;
-
 
281
 
-
 
282
  // Vector operations
-
 
283
 
-
 
284
  {
-
 
285
    double xi1 = my_random(), xi2 = my_random();
-
 
286
    Vec2d x1(xi1, xi2);
-
 
287
    double xii1 = my_random(), xii2 = my_random();
-
 
288
    Vec2d x2(xii1, xii2);
-
 
289
    double x = dot(x1, x2);
-
 
290
    success += x == xi1*xii1 + xi2*xii2;
-
 
291
 
-
 
292
    x = sqr_length(x1);
-
 
293
    success += x == xi1*xi1 + xi2*xi2;
-
 
294
 
-
 
295
    Vec2d x3 = v_min(x1, x2);
-
 
296
    success += x3[0] == (xi1 < xii1 ? xi1 : xii1) && x3[1] == (xi2 < xii2 ? xi2 : xii2);
-
 
297
 
-
 
298
    x3 = v_max(x1, x2);
-
 
299
    success += x3[0] == (xi1 > xii1 ? xi1 : xii1) && x3[1] == (xi2 > xii2 ? xi2 : xii2);
-
 
300
 
-
 
301
    x = x2.length();
-
 
302
    success += abs(x - sqrt(xii1*xii1 + xii2*xii2)) < 1.0e-15;
-
 
303
 
-
 
304
    x = length(x2);
-
 
305
    success += abs(x - sqrt(xii1*xii1 + xii2*xii2)) < 1.0e-15;
-
 
306
 
-
 
307
    while(sqr_length(x1) == 0.0)
-
 
308
    {
-
 
309
      xi1 = my_random();
-
 
310
      xi2 = my_random();      
-
 
311
      x1 = Vec2d(xi1, xi2);
-
 
312
    }
-
 
313
    x3 = normalize(x1);
-
 
314
    success += abs(x3[0] - xi1/sqrt(xi1*xi1 + xi2*xi2)) < 1.0e-15 
-
 
315
               && abs(x3[1] - xi2/sqrt(xi1*xi1 + xi2*xi2)) < 1.0e-15;
-
 
316
 
-
 
317
    x1.normalize();
-
 
318
    success += abs(x1[0] - xi1/sqrt(xi1*xi1 + xi2*xi2)) < 1.0e-15 
-
 
319
               && abs(x1[1] - xi2/sqrt(xi1*xi1 + xi2*xi2)) < 1.0e-15;
-
 
320
    
-
 
321
    x3 = orthogonal(x2);
-
 
322
    success += dot(x2, x3) == 0;
-
 
323
 
-
 
324
    x1 = Vec2d(xi1, xi2);
-
 
325
    x = cross(x1, x2);
-
 
326
    success += x == xi1*xii2 - xi2*xii1;
-
 
327
 
-
 
328
    while(x == 0)
-
 
329
    {
-
 
330
      xi1 = my_random();
-
 
331
      xi2 = my_random();
-
 
332
      x1 = Vec2d(xi1, xi2);
-
 
333
      x = cross(x1, x2);      
-
 
334
    }
-
 
335
    double xiii1 = my_random(), xiii2 = my_random();
-
 
336
    x3 = Vec2d(xiii1, xiii2);
-
 
337
    double y, z;
-
 
338
    linear_combine(x1, x2, x3, y, z);
-
 
339
    success += abs(y - (xii2*xiii1 - xii1*xiii2)/x) < 1.0e-15
-
 
340
               && abs(z - (xi1*xiii2 - xi2*xiii1)/x) < 1.0e-15;
-
 
341
  }
-
 
342
  if(success != 11)
-
 
343
  {
-
 
344
    cout << "Failure in test of Vec2d Vector operations";
-
 
345
    return 1;
-
 
346
  }
-
 
347
  success = 0;
-
 
348
  
-
 
349
  ////////////////////////////////////////////////
-
 
350
  //                V e c 2 f
-
 
351
  ////////////////////////////////////////////////
-
 
352
 
-
 
353
  // Constructors
-
 
354
 
-
 
355
  {
-
 
356
    Vec2f x1;
-
 
357
    success += _isnan(x1[0]) && _isnan(x1[1]);
-
 
358
 
-
 
359
    float xi1 = my_random(), xi2 = my_random();
-
 
360
    Vec2f x2(xi1, xi2);
-
 
361
    success += x2[0] == xi1 && x2[1] == xi2;
-
 
362
 
-
 
363
    int xii1 = rand(), xii2 = rand();
-
 
364
    Vec2i i1(xii1, xii2);
-
 
365
    Vec2f x3(i1);
-
 
366
    success += x3[0] == xii1 && x3[1] == xii2;
-
 
367
 
-
 
368
    double xiii1 = my_random(), xiii2 = my_random();
-
 
369
    Vec2d d1(xiii1, xiii2);
-
 
370
    Vec2f x4(d1);
-
 
371
    success += x4[0] == xiii1 && x4[1] == xiii2;
-
 
372
 
-
 
373
    float xiiii = my_random();
-
 
374
    Vec2f x5(xiiii);
-
 
375
    success += x5[0] == xiiii && x5[1] == xiiii;
-
 
376
  }
-
 
377
  if(success != 5)
-
 
378
  {
-
 
379
    cout << "Failure in test of Vec2f Constructors";
-
 
380
    return 1;
-
 
381
  }
-
 
382
  success = 0;
-
 
383
 
-
 
384
  // Data manipulation
-
 
385
 
-
 
386
  {
-
 
387
    Vec2f x1;    
-
 
388
 
-
 
389
    success += x1.get_dim() == 2;
-
 
390
 
-
 
391
    float xi1 = my_random(), xi2 = my_random();
-
 
392
    x1.set(xi1, xi2);
-
 
393
    success += x1[0] == xi1 && x1[1] == xi2;
-
 
394
 
-
 
395
    success += x1.get() == &x1[0];
-
 
396
 
-
 
397
    float temp = BIG;
-
 
398
    for(int i = 0; i < x1.get_dim(); ++i)
-
 
399
      if(x1[i] < temp)
-
 
400
	temp = x1[i];
-
 
401
    success += temp == x1.min_coord();
-
 
402
 
-
 
403
    temp = -BIG;
-
 
404
    for(int i = 0; i < x1.get_dim(); ++i)
-
 
405
      if(x1[i] > temp)
-
 
406
	temp = x1[i];
-
 
407
    success += temp == x1.max_coord();
-
 
408
  }
-
 
409
  if(success != 5)
-
 
410
  {
-
 
411
    cout << "Failure in test of Vec2f Data manipulation";
-
 
412
    return 1;
-
 
413
  }
-
 
414
  success = 0;
-
 
415
 
-
 
416
  // Comparison operators
-
 
417
 
-
 
418
  {
-
 
419
    float xi1 = my_random(), xi2 = my_random();
-
 
420
    while(xi1 == xi2)
-
 
421
    {
-
 
422
      xi1 = my_random();
-
 
423
      xi2 = my_random();
-
 
424
    }
-
 
425
 
-
 
426
    Vec2f x1(xi1, xi2), x2(xi1, xi2), x3(xi1), x4(xi2);    
-
 
427
    success += x1 == x2;
-
 
428
    success += !(x1 == x3);
-
 
429
    success += x3 == xi1;
-
 
430
    success += !(x3 == xi2);
-
 
431
    success += x1 != x3;
-
 
432
    success += !(x1 != x2);
-
 
433
 
-
 
434
    if(xi1 < xi2)
-
 
435
    {
-
 
436
      success += x3.all_l(x4);
-
 
437
      success += !(x3.all_l(x2));
-
 
438
      success += x3.all_le(x2);
-
 
439
      success += !(x4.all_le(x3));
-
 
440
      success += x4.all_g(x3);
-
 
441
      success += !(x4.all_g(x2));
-
 
442
      success += x4.all_ge(x2);
-
 
443
      success += !(x3.all_ge(x4));
-
 
444
    }
-
 
445
    else 
-
 
446
    {
-
 
447
      success += x4.all_l(x3);
-
 
448
      success += !(x4.all_l(x2));
-
 
449
      success += x4.all_le(x2);
-
 
450
      success += !(x3.all_le(x4));
-
 
451
      success += x3.all_g(x4);
-
 
452
      success += !(x3.all_g(x2));
-
 
453
      success += x3.all_ge(x2);
-
 
454
      success += !(x4.all_ge(x3));
-
 
455
    }
-
 
456
  }
-
 
457
  if(success != 14)
-
 
458
  {
-
 
459
    cout << "Failure in test of Vec2f Comparison operators";
-
 
460
    return 1;
-
 
461
  }
-
 
462
  success = 0;
-
 
463
  
-
 
464
  // Assignment operators
-
 
465
 
-
 
466
  {
-
 
467
    float xi1 = my_random(), xi2 = my_random();
-
 
468
    Vec2f x1(xi1, xi2);
-
 
469
    float xi3 = my_random();
-
 
470
    x1 *= xi3;
-
 
471
    success += abs(x1[0] - xi1*xi3) < 1.0e-15 && abs(x1[1] - xi2*xi3) < 1.0e-15;
-
 
472
 
-
 
473
    while(xi3 == 0)
-
 
474
      xi3 = my_random();
-
 
475
    x1 = Vec2f(xi1, xi2);
-
 
476
    x1 /= xi3;
-
 
477
    success += abs(x1[0] - xi1/xi3) < 1.0e-15 && abs(x1[1] - xi2/xi3) < 1.0e-15;
-
 
478
 
-
 
479
    x1 = Vec2f(xi1, xi2);
-
 
480
    x1 += xi3;
-
 
481
    success += x1[0] == xi1 + xi3 && x1[1] == xi2 + xi3;
-
 
482
 
-
 
483
    x1 = Vec2f(xi1, xi2);
-
 
484
    x1 -= xi3;
-
 
485
    success += x1[0] == xi1 - xi3 && x1[1] == xi2 - xi3;
-
 
486
 
-
 
487
    float xii1 = my_random(), xii2 = my_random();
-
 
488
    Vec2f x2(xii1, xii2);
-
 
489
    x1 = Vec2f(xi1, xi2);
-
 
490
    x2 *= x1;
-
 
491
    success += abs(x2[0] - xi1*xii1) < 1.0e-15 && abs(x2[1] - xi2*xii2) < 1.0e-15;
-
 
492
 
-
 
493
    while(xi1 == 0)
-
 
494
      xi1 = my_random();
-
 
495
    while(xi2 == 0)
-
 
496
      xi2 = my_random();
-
 
497
    x1 = Vec2f(xi1, xi2);
-
 
498
    x2 = Vec2f(xii1, xii2);
-
 
499
    x2 /= x1;
-
 
500
    success += abs(x2[0] - xii1/xi1) < 1.0e-15 && abs(x2[1] - xii2/xi2) < 1.0e-15;
-
 
501
 
-
 
502
    x2 = Vec2f(xii1, xii2);
-
 
503
    x2 += x1;
-
 
504
    success += x2[0] == xii1 + xi1 && x2[1] == xii2 + xi2;
-
 
505
    
-
 
506
    x2 = Vec2f(xii1, xii2);
-
 
507
    x2 -= x1;
-
 
508
    success += x2[0] == xii1 - xi1 && x2[1] == xii2 - xi2;    
-
 
509
  }
-
 
510
  if(success != 8)
-
 
511
  {
-
 
512
    cout << "Failure in test of Vec2f Assignment operators";
-
 
513
    return 1;
-
 
514
  }
-
 
515
  success = 0;
-
 
516
 
-
 
517
  // Unary operators
-
 
518
 
-
 
519
  {
-
 
520
    float xi1 = my_random(), xi2 = my_random();
-
 
521
    Vec2f x1 = -Vec2f(xi1, xi2);    
-
 
522
    success += x1[0] == -xi1 && x1[1] == -xi2;
-
 
523
  }
-
 
524
  if(success != 1)
-
 
525
  {
-
 
526
    cout << "Failure in test of Vec2f Unary operators";
-
 
527
    return 1;
-
 
528
  }
-
 
529
  success = 0;
-
 
530
 
-
 
531
  // Binary operators
-
 
532
 
-
 
533
  {
-
 
534
    float xi1 = my_random(), xi2 = my_random();
-
 
535
    Vec2f x1(xi1, xi2);
-
 
536
    float xii1 = my_random(), xii2 = my_random();
-
 
537
    while(xii1 == 0)
-
 
538
      xii1 = my_random();
-
 
539
    while(xii2 == 0)
-
 
540
      xii2 = my_random();
-
 
541
    Vec2f x2(xii1, xii2);
-
 
542
    Vec2f x3 = x1*x2;
-
 
543
    success += abs(x3[0] - xi1*xii1) < 1.0e-15 && abs(x3[1] - xi2*xii2) < 1.0e-15;
-
 
544
    
-
 
545
    x3 = x1 + x2;
-
 
546
    success += x3[0] == xi1 + xii1 && x3[1] == xi2 + xii2;
-
 
547
 
-
 
548
    x3 = x1 - x2;
-
 
549
    success += x3[0] == xi1 - xii1 && x3[1] == xi2 - xii2;
-
 
550
    
-
 
551
    x3 = x1/x2;
-
 
552
    success += abs(x3[0] - xi1/xii1) < 1.0e-15 && abs(x3[1] - xi2/xii2) < 1.0e-15;
-
 
553
 
-
 
554
    float xi3 = my_random();
-
 
555
    x3 = x1*xi3;
-
 
556
    success += abs(x3[0] - xi1*xi3) < 1.0e-15 && abs(x3[1] - xi2*xi3) < 1.0e-15;
-
 
557
    
-
 
558
    x3 = xi3*x1;
-
 
559
    success += abs(x3[0] - xi1*xi3) < 1.0e-15 && abs(x3[1] - xi2*xi3) < 1.0e-15;
-
 
560
 
-
 
561
    float xi4 = my_random();
-
 
562
    x3 = xi4*x1;
-
 
563
    success += abs(x3[0] - xi1*xi4) < 1-0e-15 && abs(x3[1] - xi2*xi4) < 1.0e-15;
-
 
564
    
-
 
565
    x3 = x1*xi4;
-
 
566
    success += abs(x3[0] - xi1*xi4) < 1-0e-15 && abs(x3[1] - xi2*xi4) < 1.0e-15;
-
 
567
 
-
 
568
    int xi5 = rand();
-
 
569
    x3 = xi5*x1;
-
 
570
    success += abs(x3[0] - xi1*xi5) < 1.0e-15 && abs(x3[1] - xi2*xi5) < 1.0e-15;
-
 
571
 
-
 
572
    x3 = x1*xi5;
-
 
573
    success += abs(x3[0] - xi1*xi5) < 1.0e-15 && abs(x3[1] - xi2*xi5) < 1.0e-15;
-
 
574
    
-
 
575
    while(xi3 == 0)
-
 
576
      xi3 = my_random();
-
 
577
    x3 = x1/xi3;
-
 
578
    success += abs(x3[0] - xi1/xi3) < 1.0e-15 && abs(x3[1] - xi2/xi3) < 1.0e-15;
-
 
579
  } 
-
 
580
  if(success != 11)
-
 
581
  {
-
 
582
    cout << "Failure in test of Vec2f Binary operators";
-
 
583
    return 1;
-
 
584
  }
-
 
585
  success = 0;
-
 
586
 
-
 
587
  // Vector operations
-
 
588
 
-
 
589
  {
-
 
590
    float xi1 = my_random(), xi2 = my_random();
-
 
591
    Vec2f x1(xi1, xi2);
-
 
592
    float xii1 = my_random(), xii2 = my_random();
-
 
593
    Vec2f x2(xii1, xii2);
-
 
594
    float x = dot(x1, x2);
-
 
595
    success += (x - xi1*xii1 - xi2*xii2) < 1.0e-7;
-
 
596
 
-
 
597
    x = sqr_length(x1);
-
 
598
    success += abs(x - xi1*xi1 - xi2*xi2) < 1.0e-15;
-
 
599
 
-
 
600
    Vec2f x3 = v_min(x1, x2);
-
 
601
    success += x3[0] == (xi1 < xii1 ? xi1 : xii1) && x3[1] == (xi2 < xii2 ? xi2 : xii2);
-
 
602
 
-
 
603
    x3 = v_max(x1, x2);
-
 
604
    success += x3[0] == (xi1 > xii1 ? xi1 : xii1) && x3[1] == (xi2 > xii2 ? xi2 : xii2);
-
 
605
 
-
 
606
    x = x2.length();
-
 
607
    success += abs(x - sqrt(xii1*xii1 + xii2*xii2)) < 1.0e-15;
-
 
608
 
-
 
609
    x = length(x2);
-
 
610
    success += abs(x - sqrt(xii1*xii1 + xii2*xii2)) < 1.0e-15;
-
 
611
 
-
 
612
    while(sqr_length(x1) == 0.0)
-
 
613
    {
-
 
614
      xi1 = my_random();
-
 
615
      xi2 = my_random();      
-
 
616
      x1 = Vec2f(xi1, xi2);
-
 
617
    }
-
 
618
    x3 = normalize(x1);
-
 
619
    success += abs(x3[0] - xi1/sqrt(xi1*xi1 + xi2*xi2)) < 1.0e-15 
-
 
620
               && abs(x3[1] - xi2/sqrt(xi1*xi1 + xi2*xi2)) < 1.0e-15;
-
 
621
 
-
 
622
    x1.normalize();
-
 
623
    success += abs(x1[0] - xi1/sqrt(xi1*xi1 + xi2*xi2)) < 1.0e-15 
-
 
624
               && abs(x1[1] - xi2/sqrt(xi1*xi1 + xi2*xi2)) < 1.0e-15;
-
 
625
    
-
 
626
    x3 = orthogonal(x2);
-
 
627
    success += abs(dot(x2, x3)) < 1.0e-15;
-
 
628
 
-
 
629
    x1 = Vec2f(xi1, xi2);
-
 
630
    x = cross(x1, x2);
-
 
631
    success += abs(x - xi1*xii2 + xi2*xii1) < 1.0e-15;
-
 
632
 
-
 
633
    while(x == 0)
-
 
634
    {
-
 
635
      xi1 = my_random();
-
 
636
      xi2 = my_random();
-
 
637
      x1 = Vec2f(xi1, xi2);
-
 
638
      x = cross(x1, x2);      
-
 
639
    }
-
 
640
    float xiii1 = my_random(), xiii2 = my_random();
-
 
641
    x3 = Vec2f(xiii1, xiii2);
-
 
642
    float y, z;
-
 
643
    linear_combine(x1, x2, x3, y, z);
-
 
644
    success += abs(y - (xii2*xiii1 - xii1*xiii2)/x) < 1.0e-15
-
 
645
               && abs(z - (xi1*xiii2 - xi2*xiii1)/x) < 1.0e-15;
-
 
646
  }
-
 
647
  if(success != 11)
-
 
648
  {
-
 
649
    cout << "Failure in test of Vec2f Vector operations";
-
 
650
    return 1;
-
 
651
  }
-
 
652
  success = 0;
-
 
653
 
-
 
654
  ////////////////////////////////////////////////
-
 
655
  //                V e c 2 i
-
 
656
  ////////////////////////////////////////////////
-
 
657
 
-
 
658
  // Constructors
-
 
659
 
-
 
660
  {
-
 
661
/* Vec2i default initialization ?
-
 
662
 *
-
 
663
    Vec2i x1;
-
 
664
    success += _isnan(x1[0]) && _isnan(x1[1]);
-
 
665
*/
-
 
666
 
-
 
667
    int xi1 = rand(), xi2 = rand();
-
 
668
    Vec2i x2(xi1, xi2);
-
 
669
    success += x2[0] == xi1 && x2[1] == xi2;
-
 
670
 
-
 
671
/* Constuctor non-existent !
-
 
672
 *
-
 
673
    int xii1 = my_random(), xii2 = my_random();
-
 
674
    Vec2d d1(xii1, xii2);
-
 
675
    Vec2i x3(i1);
-
 
676
    success += x3[0] == xii1 && x3[1] == xii2;
-
 
677
*/
-
 
678
 
-
 
679
    float xiii1 = my_random(), xiii2 = my_random();
-
 
680
    Vec2f f1(xiii1, xiii2);
-
 
681
    Vec2i x4(f1);
-
 
682
    success += x4[0] == static_cast<int>(xiii1) && x4[1] == static_cast<int>(xiii2);
-
 
683
 
-
 
684
/* Constuctor non-existent !
-
 
685
 *
-
 
686
    int xiiii = rand();
-
 
687
    Vec2i x5(xiiii);
-
 
688
    success += x5[0] == xiiii && x5[1] == xiiii;
-
 
689
*/
-
 
690
  }
-
 
691
  if(success != 2)
-
 
692
  {
-
 
693
    cout << "Failure in test of Vec2i Constructors";
-
 
694
    return 1;
-
 
695
  }
-
 
696
  success = 0;
-
 
697
 
-
 
698
  // Data manipulation
-
 
699
 
-
 
700
  {
-
 
701
    Vec2i x1;    
-
 
702
 
-
 
703
    success += x1.get_dim() == 2;
-
 
704
 
-
 
705
    int xi1 = rand(), xi2 = rand();
-
 
706
    x1.set(xi1, xi2);
-
 
707
    success += x1[0] == xi1 && x1[1] == xi2;
-
 
708
 
-
 
709
    success += x1.get() == &x1[0];
-
 
710
 
-
 
711
    int temp = INT_MAX;
-
 
712
    for(int i = 0; i < x1.get_dim(); ++i)
-
 
713
      if(x1[i] < temp)
-
 
714
	temp = x1[i];
-
 
715
    success += temp == x1.min_coord();
-
 
716
 
-
 
717
    temp = -INT_MAX;
-
 
718
    for(int i = 0; i < x1.get_dim(); ++i)
-
 
719
      if(x1[i] > temp)
-
 
720
	temp = x1[i];
-
 
721
    success += temp == x1.max_coord();
-
 
722
  }
-
 
723
  if(success != 5)
-
 
724
  {
-
 
725
    cout << "Failure in test of Vec2i Data manipulation";
-
 
726
    return 1;
-
 
727
  }
-
 
728
  success = 0;
-
 
729
 
-
 
730
  // Comparison operators
-
 
731
 
-
 
732
  {
-
 
733
    int xi1 = rand(), xi2 = rand();
-
 
734
    while(xi1 == xi2)
-
 
735
    {
-
 
736
      xi1 = rand();
-
 
737
      xi2 = rand();
-
 
738
    }
-
 
739
 
-
 
740
    Vec2i x1(xi1, xi2), x2(xi1, xi2), x3(xi1, xi1), x4(xi2, xi2);    
-
 
741
    success += x1 == x2;
-
 
742
    success += !(x1 == x3);
-
 
743
    success += x3 == xi1;
-
 
744
    success += !(x3 == xi2);
-
 
745
    success += x1 != x3;
-
 
746
    success += !(x1 != x2);
-
 
747
 
-
 
748
    if(xi1 < xi2)
-
 
749
    {
-
 
750
      success += x3.all_l(x4);
-
 
751
      success += !(x3.all_l(x2));
-
 
752
      success += x3.all_le(x2);
-
 
753
      success += !(x4.all_le(x3));
-
 
754
      success += x4.all_g(x3);
-
 
755
      success += !(x4.all_g(x2));
-
 
756
      success += x4.all_ge(x2);
-
 
757
      success += !(x3.all_ge(x4));
-
 
758
    }
-
 
759
    else 
-
 
760
    {
-
 
761
      success += x4.all_l(x3);
-
 
762
      success += !(x4.all_l(x2));
-
 
763
      success += x4.all_le(x2);
-
 
764
      success += !(x3.all_le(x4));
-
 
765
      success += x3.all_g(x4);
-
 
766
      success += !(x3.all_g(x2));
-
 
767
      success += x3.all_ge(x2);
-
 
768
      success += !(x4.all_ge(x3));
-
 
769
    }
-
 
770
  }
-
 
771
  if(success != 14)
-
 
772
  {
-
 
773
    cout << "Failure in test of Vec2i Comparison operators";
-
 
774
    return 1;
-
 
775
  }
-
 
776
  success = 0;
-
 
777
  
-
 
778
  // Assignment operators
-
 
779
 
-
 
780
  {
-
 
781
    int xi1 = rand(), xi2 = rand();
-
 
782
    Vec2i x1(xi1, xi2);
-
 
783
    int xi3 = rand();
-
 
784
    x1 *= xi3;
-
 
785
    success += x1[0] == xi1*xi3 && x1[1] == xi2*xi3;
-
 
786
 
-
 
787
    while(xi3 == 0)
-
 
788
      xi3 = rand();
-
 
789
    x1 = Vec2i(xi1, xi2);
-
 
790
    x1 /= xi3;
-
 
791
    success += x1[0] == xi1/xi3 && x1[1] == xi2/xi3;
-
 
792
 
-
 
793
    x1 = Vec2i(xi1, xi2);
-
 
794
    x1 += xi3;
-
 
795
    success += x1[0] == xi1 + xi3 && x1[1] == xi2 + xi3;
-
 
796
 
-
 
797
    x1 = Vec2i(xi1, xi2);
-
 
798
    x1 -= xi3;
-
 
799
    success += x1[0] == xi1 - xi3 && x1[1] == xi2 - xi3;
-
 
800
 
-
 
801
    int xii1 = rand(), xii2 = rand();
-
 
802
    Vec2i x2(xii1, xii2);
-
 
803
    x1 = Vec2i(xi1, xi2);
-
 
804
    x2 *= x1;
-
 
805
    success += x2[0] == xi1*xii1 && x2[1] == xi2*xii2;
-
 
806
 
-
 
807
    while(xi1 == 0)
-
 
808
      xi1 = rand();
-
 
809
    while(xi2 == 0)
-
 
810
      xi2 = rand();
-
 
811
    x1 = Vec2i(xi1, xi2);
-
 
812
    x2 = Vec2i(xii1, xii2);
-
 
813
    x2 /= x1;
-
 
814
    success += x2[0] == xii1/xi1 && x2[1] == xii2/xi2;
-
 
815
 
-
 
816
    x2 = Vec2i(xii1, xii2);
-
 
817
    x2 += x1;
-
 
818
    success += x2[0] == xii1 + xi1 && x2[1] == xii2 + xi2;
-
 
819
    
-
 
820
    x2 = Vec2i(xii1, xii2);
-
 
821
    x2 -= x1;
-
 
822
    success += x2[0] == xii1 - xi1 && x2[1] == xii2 - xi2;    
-
 
823
  }
-
 
824
  if(success != 8)
-
 
825
  {
-
 
826
    cout << "Failure in test of Vec2i Assignment operators";
-
 
827
    return 1;
-
 
828
  }
-
 
829
  success = 0;
-
 
830
 
-
 
831
  // Unary operators
-
 
832
 
-
 
833
  {
-
 
834
    int xi1 = rand(), xi2 = rand();
-
 
835
    Vec2i x1 = -Vec2i(xi1, xi2);    
-
 
836
    success += x1[0] == -xi1 && x1[1] == -xi2;
-
 
837
  }
-
 
838
  if(success != 1)
-
 
839
  {
-
 
840
    cout << "Failure in test of Vec2i Unary operators";
-
 
841
    return 1;
-
 
842
  }
-
 
843
  success = 0;
-
 
844
 
-
 
845
  // Binary operators
-
 
846
 
-
 
847
  {
-
 
848
    int xi1 = rand(), xi2 = rand();
-
 
849
    Vec2i x1(xi1, xi2);
-
 
850
    int xii1 = rand(), xii2 = rand();
-
 
851
    while(xii1 == 0)
-
 
852
      xii1 = rand();
-
 
853
    while(xii2 == 0)
-
 
854
      xii2 = rand();
-
 
855
    Vec2i x2(xii1, xii2);
-
 
856
    Vec2i x3 = x1*x2;
-
 
857
    success += x3[0] == xi1*xii1 && x3[1] == xi2*xii2;
-
 
858
    
-
 
859
    x3 = x1 + x2;
-
 
860
    success += x3[0] == xi1 + xii1 && x3[1] == xi2 + xii2;
-
 
861
 
-
 
862
    x3 = x1 - x2;
-
 
863
    success += x3[0] == xi1 - xii1 && x3[1] == xi2 - xii2;
-
 
864
    
-
 
865
    x3 = x1/x2;
-
 
866
    success += x3[0] == xi1/xii1 && x3[1] == xi2/xii2;
-
 
867
 
-
 
868
    int xi3 = rand();
-
 
869
    x3 = x1*xi3;
-
 
870
    success += x3[0] == xi1*xi3 && x3[1] == xi2*xi3;
-
 
871
    
-
 
872
    x3 = xi3*x1;
-
 
873
    success += x3[0] == xi1*xi3 && x3[1] == xi2*xi3;
-
 
874
 
-
 
875
    float xi4 = INT_MAX*my_random();
-
 
876
    x3 = xi4*x1;
-
 
877
    success += x3[0] == xi1*static_cast<int>(xi4) && x3[1] == xi2*static_cast<int>(xi4);
-
 
878
    
-
 
879
    x3 = x1*xi4;
-
 
880
    success += x3[0] == xi1*static_cast<int>(xi4) && x3[1] == xi2*static_cast<int>(xi4);
-
 
881
 
-
 
882
    double xi5 = INT_MAX*my_random();
-
 
883
    x3 = xi5*x1;
-
 
884
    success += x3[0] == xi1*static_cast<int>(xi5) && x3[1] == xi2*static_cast<int>(xi5);
-
 
885
    
-
 
886
    x3 = x1*xi5;
-
 
887
    success += x3[0] == xi1*static_cast<int>(xi5) && x3[1] == xi2*static_cast<int>(xi5);
-
 
888
 
-
 
889
    while(xi3 == 0)
-
 
890
      xi3 = rand();
-
 
891
    x3 = x1/xi3;
-
 
892
    success += x3[0] == xi1/xi3 && x3[1] == xi2/xi3;
-
 
893
  } 
-
 
894
  if(success != 11)
-
 
895
  {
-
 
896
    cout << "Failure in test of Vec2i Binary operators";
-
 
897
    return 1;
-
 
898
  }
-
 
899
  success = 0;
-
 
900
 
-
 
901
  // Vector operations
-
 
902
 
-
 
903
  {
-
 
904
    int xi1 = rand(), xi2 = rand();
-
 
905
    Vec2i x1(xi1, xi2);
-
 
906
    int xii1 = rand(), xii2 = rand();
-
 
907
    Vec2i x2(xii1, xii2);
-
 
908
    int x = dot(x1, x2);
-
 
909
    success += x == xi1*xii1 + xi2*xii2;
-
 
910
 
-
 
911
    x = sqr_length(x1);
-
 
912
    success += x == xi1*xi1 + xi2*xi2;
-
 
913
 
-
 
914
    Vec2i x3 = v_min(x1, x2);
-
 
915
    success += x3[0] == (xi1 < xii1 ? xi1 : xii1) && x3[1] == (xi2 < xii2 ? xi2 : xii2);
-
 
916
 
-
 
917
    x3 = v_max(x1, x2);
-
 
918
    success += x3[0] == (xi1 > xii1 ? xi1 : xii1) && x3[1] == (xi2 > xii2 ? xi2 : xii2);
-
 
919
  }
-
 
920
  if(success != 4)
-
 
921
  {
-
 
922
    cout << "Failure in test of Vec2i Vector operations";
-
 
923
    return 1;
-
 
924
  }
-
 
925
  success = 0;
-
 
926
 
-
 
927
  ////////////////////////////////////////////////
-
 
928
  //                V e c 3 i
-
 
929
  ////////////////////////////////////////////////
-
 
930
 
-
 
931
  // Constructors
-
 
932
 
-
 
933
  {
-
 
934
/* Vec3i default initialization ?
-
 
935
 *
-
 
936
    Vec3i x1;
-
 
937
    success += _isnan(x1[0]) && _isnan(x1[1]) && _isnan(x1[2]);
-
 
938
*/
-
 
939
 
-
 
940
    int xi1 = rand(), xi2 = rand(), xi3 = rand();
-
 
941
    Vec3i x2(xi1, xi2, xi3);
-
 
942
    success += x2[0] == xi1 && x2[1] == xi2 && x2[2] == xi3;
-
 
943
 
-
 
944
    int xiiii = rand();
-
 
945
    Vec3i x3(xiiii);
-
 
946
    success += x3[0] == xiiii && x3[1] == xiiii && x3[2] == xiiii;
-
 
947
 
-
 
948
/* Constuctor non-existent !
-
 
949
 *
-
 
950
    int xii1 = my_random(), xii2 = my_random(), xii3 = my_random();
-
 
951
    Vec3d d1(xii1, xii2, xii3);
-
 
952
    Vec3i x4(d1);
-
 
953
    success += x4[0] == xii1 && x4[1] == xii2 && x4[2] == xii3;
-
 
954
*/
-
 
955
 
-
 
956
    float xiii1 = my_random(), xiii2 = my_random(), xiii3 = my_random();
-
 
957
    Vec3f f1(xiii1, xiii2, xiii3);
-
 
958
    Vec3i x5(f1);
-
 
959
    success += x5[0] == static_cast<int>(xiii1) 
-
 
960
               && x5[1] == static_cast<int>(xiii2)
-
 
961
               && x5[2] == static_cast<int>(xiii3);
-
 
962
 
-
 
963
    unsigned char xiiii1 = 256*my_random(), 
-
 
964
                  xiiii2 = 256*my_random(), 
-
 
965
                  xiiii3 = 256*my_random();
-
 
966
    Vec3uc uc1(xiiii1, xiiii2, xiiii3);
-
 
967
    Vec3i x6(uc1);
-
 
968
    success += x6[0] == xiiii1 && x6[1] == xiiii2 && x6[2] == xiiii3;
-
 
969
 
-
 
970
    unsigned short int xiiv1 = USHRT_MAX*my_random(),
-
 
971
                       xiiv2 = USHRT_MAX*my_random(),
-
 
972
                       xiiv3 = USHRT_MAX*my_random();
-
 
973
    Vec3usi usi1(xiiv1, xiiv2, xiiv3);
-
 
974
    Vec3i x7(usi1);
-
 
975
    success += x7[0] == xiiv1 && x7[1] == xiiv2 && x7[2] == xiiv3;
-
 
976
  }
-
 
977
  if(success != 5)
-
 
978
  {
-
 
979
    cout << "Failure in test of Vec3i Constructors";
-
 
980
    return 1;
-
 
981
  }
-
 
982
  success = 0;
-
 
983
 
-
 
984
  // Data manipulation
-
 
985
 
-
 
986
  {
-
 
987
    Vec3i x1;    
-
 
988
 
-
 
989
    success += x1.get_dim() == 3;
-
 
990
 
-
 
991
    int xi1 = rand(), xi2 = rand(), xi3 = rand();
-
 
992
    x1.set(xi1, xi2, xi3);
-
 
993
    success += x1[0] == xi1 && x1[1] == xi2 && x1[2] == xi3;
-
 
994
 
-
 
995
    success += x1.get() == &x1[0];
-
 
996
 
-
 
997
    int temp = INT_MAX;
-
 
998
    for(int i = 0; i < x1.get_dim(); ++i)
-
 
999
      if(x1[i] < temp)
-
 
1000
	temp = x1[i];
-
 
1001
    success += temp == x1.min_coord();
-
 
1002
 
-
 
1003
    temp = -INT_MAX;
-
 
1004
    for(int i = 0; i < x1.get_dim(); ++i)
-
 
1005
      if(x1[i] > temp)
-
 
1006
	temp = x1[i];
-
 
1007
    success += temp == x1.max_coord();
-
 
1008
  }
-
 
1009
  if(success != 5)
-
 
1010
  {
-
 
1011
    cout << "Failure in test of Vec3i Data manipulation";
-
 
1012
    return 1;
-
 
1013
  }
-
 
1014
  success = 0;
-
 
1015
 
-
 
1016
  // Comparison operators
-
 
1017
 
-
 
1018
  {
-
 
1019
    int xi1 = rand(), xi2 = rand(), xi3 = rand();
-
 
1020
    while(xi1 >= xi2)
-
 
1021
    {
-
 
1022
      xi1 = rand();
-
 
1023
      xi2 = rand();
-
 
1024
    }
-
 
1025
    while(xi3 <= xi2)
-
 
1026
      xi3 = rand();
-
 
1027
 
-
 
1028
    Vec3i x1(xi1, xi2, xi3), x2(xi1, xi2, xi3), 
-
 
1029
          x3(xi1, xi1, xi1), x4(xi2, xi2, xi2), x5(xi3, xi3, xi3);    
-
 
1030
    success += x1 == x2;
-
 
1031
    success += !(x1 == x3);
-
 
1032
    success += x3 == xi1;
-
 
1033
    success += !(x3 == xi2);
-
 
1034
    success += x1 != x3;
-
 
1035
    success += !(x1 != x2);
-
 
1036
    success += x3.all_l(x4);
-
 
1037
    success += !(x3.all_l(x2));
-
 
1038
    success += x3.all_le(x2);
-
 
1039
    success += !(x4.all_le(x2));
-
 
1040
    success += x4.all_g(x3);
-
 
1041
    success += !(x4.all_g(x2));
-
 
1042
    success += x5.all_ge(x2);
-
 
1043
    success += !(x4.all_ge(x2));
-
 
1044
  }
-
 
1045
  if(success != 14)
-
 
1046
  {
-
 
1047
    cout << "Failure in test of Vec3i Comparison operators";
-
 
1048
    return 1;
-
 
1049
  }
-
 
1050
  success = 0;
-
 
1051
  
-
 
1052
  // Assignment operators
-
 
1053
 
-
 
1054
  {
-
 
1055
    int xi1 = rand(), xi2 = rand(), xi3 = rand();
-
 
1056
    Vec3i x1(xi1, xi2, xi3);
-
 
1057
    int xii = rand();
-
 
1058
    x1 *= xii;
-
 
1059
    success += x1[0] == xi1*xii && x1[1] == xi2*xii && x1[2] == xi3*xii;
-
 
1060
 
-
 
1061
    while(xii == 0)
-
 
1062
      xii = rand();
-
 
1063
    x1 = Vec3i(xi1, xi2, xi3);
-
 
1064
    x1 /= xii;
-
 
1065
    success += x1[0] == xi1/xii && x1[1] == xi2/xii && x1[2] == xi3/xii;
-
 
1066
 
-
 
1067
    x1 = Vec3i(xi1, xi2, xi3);
-
 
1068
    x1 += xii;
-
 
1069
    success += x1[0] == xi1 + xii && x1[1] == xi2 + xii && x1[2] == xi3 + xii;
-
 
1070
 
-
 
1071
    x1 = Vec3i(xi1, xi2, xi3);
-
 
1072
    x1 -= xii;
-
 
1073
    success += x1[0] == xi1 - xii && x1[1] == xi2 - xii && x1[2] == xi3 - xii;
-
 
1074
 
-
 
1075
    int xii1 = rand(), xii2 = rand(), xii3 = rand();
-
 
1076
    Vec3i x2(xii1, xii2, xii3);
-
 
1077
    x1 = Vec3i(xi1, xi2, xi3);
-
 
1078
    x2 *= x1;
-
 
1079
    success += x2[0] == xi1*xii1 && x2[1] == xi2*xii2 && x2[2] == xi3*xii3;
-
 
1080
 
-
 
1081
    while(xi1 == 0)
-
 
1082
      xi1 = rand();
-
 
1083
    while(xi2 == 0)
-
 
1084
      xi2 = rand();
-
 
1085
    while(xi3 == 0)
-
 
1086
      xi3 = rand();
-
 
1087
    x1 = Vec3i(xi1, xi2, xi3);
-
 
1088
    x2 = Vec3i(xii1, xii2, xii3);
-
 
1089
    x2 /= x1;
-
 
1090
    success += x2[0] == xii1/xi1 && x2[1] == xii2/xi2 && x2[2] == xii3/xi3;
-
 
1091
 
-
 
1092
    x2 = Vec3i(xii1, xii2, xii3);
-
 
1093
    x2 += x1;
-
 
1094
    success += x2[0] == xii1 + xi1 && x2[1] == xii2 + xi2 && x2[2] == xii3 + xi3;
-
 
1095
    
-
 
1096
    x2 = Vec3i(xii1, xii2, xii3);
-
 
1097
    x2 -= x1;
-
 
1098
    success += x2[0] == xii1 - xi1 && x2[1] == xii2 - xi2 && x2[2] == xii3 - xi3;    
-
 
1099
  }
-
 
1100
  if(success != 8)
-
 
1101
  {
-
 
1102
    cout << "Failure in test of Vec3i Assignment operators";
-
 
1103
    return 1;
-
 
1104
  }
-
 
1105
  success = 0;
-
 
1106
 
-
 
1107
  // Unary operators
-
 
1108
 
-
 
1109
  {
-
 
1110
    int xi1 = rand(), xi2 = rand(), xi3 = rand();
-
 
1111
    Vec3i x1 = -Vec3i(xi1, xi2, xi3);    
-
 
1112
    success += x1[0] == -xi1 && x1[1] == -xi2 && x1[2] == -xi3;
-
 
1113
  }
-
 
1114
  if(success != 1)
-
 
1115
  {
-
 
1116
    cout << "Failure in test of Vec3i Unary operators";
-
 
1117
    return 1;
-
 
1118
  }
-
 
1119
  success = 0;
-
 
1120
 
-
 
1121
  // Binary operators
-
 
1122
 
-
 
1123
  {
-
 
1124
    int xi1 = rand(), xi2 = rand(), xi3 = rand();
-
 
1125
    Vec3i x1(xi1, xi2, xi3);
-
 
1126
    int xii1 = rand(), xii2 = rand(), xii3 = rand();
-
 
1127
    while(xii1 == 0)
-
 
1128
      xii1 = rand();
-
 
1129
    while(xii2 == 0)
-
 
1130
      xii2 = rand();
-
 
1131
    while(xii3 == 0)
-
 
1132
      xii3 = rand();
-
 
1133
    Vec3i x2(xii1, xii2, xii3);
-
 
1134
    Vec3i x3 = x1*x2;
-
 
1135
    success += x3[0] == xi1*xii1 && x3[1] == xi2*xii2 && x3[2] == xi3*xii3;
-
 
1136
    
-
 
1137
    x3 = x1 + x2;
-
 
1138
    success += x3[0] == xi1 + xii1 && x3[1] == xi2 + xii2 && x3[2] == xi3 + xii3;
-
 
1139
 
-
 
1140
    x3 = x1 - x2;
-
 
1141
    success += x3[0] == xi1 - xii1 && x3[1] == xi2 - xii2 && x3[2] == xi3 - xii3;
-
 
1142
    
-
 
1143
    x3 = x1/x2;
-
 
1144
    success += x3[0] == xi1/xii1 && x3[1] == xi2/xii2 && x3[2] == xi3/xii3;
-
 
1145
 
-
 
1146
    int xii = rand();
-
 
1147
    x3 = x1*xii;
-
 
1148
    success += x3[0] == xi1*xii && x3[1] == xi2*xii && x3[2] == xi3*xii;
-
 
1149
    
-
 
1150
    x3 = xii*x1;
-
 
1151
    success += x3[0] == xi1*xii && x3[1] == xi2*xii && x3[2] == xi3*xii;
-
 
1152
 
-
 
1153
    float xi4 = INT_MAX*my_random();
-
 
1154
    x3 = xi4*x1;
-
 
1155
    success += x3[0] == xi1*static_cast<int>(xi4) 
-
 
1156
               && x3[1] == xi2*static_cast<int>(xi4) 
-
 
1157
               && x3[2] == xi3*static_cast<int>(xi4);
-
 
1158
    
-
 
1159
    x3 = x1*xi4;
-
 
1160
    success += x3[0] == xi1*static_cast<int>(xi4) 
-
 
1161
               && x3[1] == xi2*static_cast<int>(xi4) 
-
 
1162
               && x3[2] == xi3*static_cast<int>(xi4);
-
 
1163
 
-
 
1164
    double xi5 = INT_MAX*my_random();
-
 
1165
    x3 = xi5*x1;
-
 
1166
    success += x3[0] == xi1*static_cast<int>(xi5) 
-
 
1167
               && x3[1] == xi2*static_cast<int>(xi5) 
-
 
1168
               && x3[2] == xi3*static_cast<int>(xi5);
-
 
1169
    
-
 
1170
    x3 = x1*xi5;
-
 
1171
    success += x3[0] == xi1*static_cast<int>(xi5) 
-
 
1172
               && x3[1] == xi2*static_cast<int>(xi5) 
-
 
1173
               && x3[2] == xi3*static_cast<int>(xi5);
-
 
1174
 
-
 
1175
    while(xii == 0)
-
 
1176
      xii = rand();
-
 
1177
    x3 = x1/xii;
-
 
1178
    success += x3[0] == xi1/xii && x3[1] == xi2/xii && x3[2] == xi3/xii;
-
 
1179
  } 
-
 
1180
  if(success != 11)
-
 
1181
  {
-
 
1182
    cout << "Failure in test of Vec3i Binary operators";
-
 
1183
    return 1;
-
 
1184
  }
-
 
1185
  success = 0;
-
 
1186
 
-
 
1187
  // Vector operations
-
 
1188
 
-
 
1189
  {
-
 
1190
    int xi1 = rand(), xi2 = rand(), xi3 = rand();
-
 
1191
    Vec3i x1(xi1, xi2, xi3);
-
 
1192
    int xii1 = rand(), xii2 = rand(), xii3 = rand();
-
 
1193
    Vec3i x2(xii1, xii2, xii3);
-
 
1194
    int x = dot(x1, x2);
-
 
1195
    success += x == xi1*xii1 + xi2*xii2 + xi3*xii3;
-
 
1196
 
-
 
1197
    x = sqr_length(x1);
-
 
1198
    success += x == xi1*xi1 + xi2*xi2 + xi3*xi3;
-
 
1199
 
-
 
1200
    Vec3i x3 = v_min(x1, x2);
-
 
1201
    success += x3[0] == (xi1 < xii1 ? xi1 : xii1) 
-
 
1202
               && x3[1] == (xi2 < xii2 ? xi2 : xii2)
-
 
1203
               && x3[2] == (xi3 < xii3 ? xi3 : xii3);
-
 
1204
 
-
 
1205
    x3 = v_max(x1, x2);
-
 
1206
    success += x3[0] == (xi1 > xii1 ? xi1 : xii1) 
-
 
1207
               && x3[1] == (xi2 > xii2 ? xi2 : xii2)
-
 
1208
               && x3[2] == (xi3 > xii3 ? xi3 : xii3);
-
 
1209
 
-
 
1210
    x3 = cross(x1, x2);
-
 
1211
    success += x3[0] == xi2*xii3 - xi3*xii2
-
 
1212
               && x3[1] == xi3*xii1 - xi1*xii3
-
 
1213
               && x3[2] == xi1*xii2 - xi2*xii1;
-
 
1214
  }
-
 
1215
  if(success != 5)
-
 
1216
  {
-
 
1217
    cout << "Failure in test of Vec3i Vector operations";
-
 
1218
    return 1;
-
 
1219
  }
-
 
1220
  success = 0;
-
 
1221
 
-
 
1222
  ////////////////////////////////////////////////
-
 
1223
  //                V e c 3 f
-
 
1224
  ////////////////////////////////////////////////
-
 
1225
 
-
 
1226
  // Constructors
-
 
1227
 
-
 
1228
  {
-
 
1229
    Vec3f x1;
-
 
1230
    success += _isnan(x1[0]) && _isnan(x1[1]) && _isnan(x1[2]);
-
 
1231
 
-
 
1232
    float xi1 = my_random(), xi2 = my_random(), xi3 = my_random();
-
 
1233
    Vec3f x2(xi1, xi2, xi3);
-
 
1234
    success += x2[0] == xi1 && x2[1] == xi2 && x2[2] == xi3;
-
 
1235
 
-
 
1236
    float xiiii = my_random();
-
 
1237
    Vec3f x3(xiiii);
-
 
1238
    success += x3[0] == xiiii && x3[1] == xiiii && x3[2] == xiiii;
-
 
1239
 
-
 
1240
    double xii1 = my_random(), xii2 = my_random(), xii3 = my_random();
-
 
1241
    Vec3d d1(xii1, xii2, xii3);
-
 
1242
    Vec3f x4(d1);
-
 
1243
    success += x4[0] == xii1 && x4[1] == xii2 && x4[2] == xii3;
-
 
1244
 
-
 
1245
    int xiii1 = rand(), xiii2 = rand(), xiii3 = rand();
-
 
1246
    Vec3i i1(xiii1, xiii2, xiii3);
-
 
1247
    Vec3f x5(i1);
-
 
1248
    success += x5[0] == xiii1 && x5[1] == xiii2 && x5[2] == xiii3;
-
 
1249
 
-
 
1250
    float xiiii1 = my_random(), xiiii2 = my_random(), xiiii3 = my_random();
-
 
1251
    Quaternion q(xiiii1, xiiii2, xiiii3, 1.0);
-
 
1252
    Vec3f x6(q);
-
 
1253
    success += x6[0] == xiiii1 && x6[1] == xiiii2 && x6[2] == xiiii3;
-
 
1254
 
-
 
1255
    unsigned short int xiiv1 = USHRT_MAX*my_random(),
-
 
1256
                       xiiv2 = USHRT_MAX*my_random(),
-
 
1257
                       xiiv3 = USHRT_MAX*my_random();
-
 
1258
    Vec3usi usi1(xiiv1, xiiv2, xiiv3);
-
 
1259
    Vec3f x7(usi1);
-
 
1260
    success += x7[0] == xiiv1 && x7[1] == xiiv2 && x7[2] == xiiv3;
-
 
1261
  }
-
 
1262
  if(success != 7)
-
 
1263
  {
-
 
1264
    cout << "Failure in test of Vec3f Constructors";
-
 
1265
    return 1;
-
 
1266
  }
-
 
1267
  success = 0;
-
 
1268
 
-
 
1269
  // Data manipulation
-
 
1270
 
-
 
1271
  {
-
 
1272
    Vec3f x1;    
-
 
1273
 
-
 
1274
    success += x1.get_dim() == 3;
-
 
1275
 
-
 
1276
    float xi1 = my_random(), xi2 = my_random(), xi3 = my_random();
-
 
1277
    x1.set(xi1, xi2, xi3);
-
 
1278
    success += x1[0] == xi1 && x1[1] == xi2 && x1[2] == xi3;
-
 
1279
 
-
 
1280
    success += x1.get() == &x1[0];
-
 
1281
 
-
 
1282
    float temp = BIG;
-
 
1283
    for(float i = 0; i < x1.get_dim(); ++i)
-
 
1284
      if(x1[i] < temp)
-
 
1285
	temp = x1[i];
-
 
1286
    success += temp == x1.min_coord();
-
 
1287
 
-
 
1288
    temp = -BIG;
-
 
1289
    for(float i = 0; i < x1.get_dim(); ++i)
-
 
1290
      if(x1[i] > temp)
-
 
1291
	temp = x1[i];
-
 
1292
    success += temp == x1.max_coord();
-
 
1293
  }
-
 
1294
  if(success != 5)
-
 
1295
  {
-
 
1296
    cout << "Failure in test of Vec3f Data manipulation";
-
 
1297
    return 1;
-
 
1298
  }
-
 
1299
  success = 0;
-
 
1300
 
-
 
1301
  // Comparison operators
-
 
1302
 
-
 
1303
  {
-
 
1304
    float xi1 = my_random(), xi2 = my_random(), xi3 = my_random();
-
 
1305
    while(xi1 >= xi2)
-
 
1306
    {
-
 
1307
      xi1 = my_random();
-
 
1308
      xi2 = my_random();
-
 
1309
    }
-
 
1310
    while(xi3 <= xi2)
-
 
1311
      xi3 = my_random();
-
 
1312
 
-
 
1313
    Vec3f x1(xi1, xi2, xi3), x2(xi1, xi2, xi3), 
-
 
1314
          x3(xi1, xi1, xi1), x4(xi2, xi2, xi2), x5(xi3, xi3, xi3);    
-
 
1315
    success += x1 == x2;
-
 
1316
    success += !(x1 == x3);
-
 
1317
    success += x3 == xi1;
-
 
1318
    success += !(x3 == xi2);
-
 
1319
    success += x1 != x3;
-
 
1320
    success += !(x1 != x2);
-
 
1321
    success += x3.all_l(x4);
-
 
1322
    success += !(x3.all_l(x2));
-
 
1323
    success += x3.all_le(x2);
-
 
1324
    success += !(x4.all_le(x2));
-
 
1325
    success += x4.all_g(x3);
-
 
1326
    success += !(x4.all_g(x2));
-
 
1327
    success += x5.all_ge(x2);
-
 
1328
    success += !(x4.all_ge(x2));
-
 
1329
  }
-
 
1330
  if(success != 14)
-
 
1331
  {
-
 
1332
    cout << "Failure in test of Vec3f Comparison operators";
-
 
1333
    return 1;
-
 
1334
  }
-
 
1335
  success = 0;
-
 
1336
  
-
 
1337
  // Assignment operators
-
 
1338
 
-
 
1339
  {
-
 
1340
    float xi1 = my_random(), xi2 = my_random(), xi3 = my_random();
-
 
1341
    Vec3f x1(xi1, xi2, xi3);
-
 
1342
    float xii = my_random();
-
 
1343
    x1 *= xii;
-
 
1344
    success += abs(x1[0] - xi1*xii) < 1.0e-15 
-
 
1345
               && abs(x1[1] - xi2*xii) < 1.0e-15 
-
 
1346
               && abs(x1[2] - xi3*xii) < 1.0e-15;
-
 
1347
 
-
 
1348
    while(xii == 0)
-
 
1349
      xii = my_random();
-
 
1350
    x1 = Vec3f(xi1, xi2, xi3);
-
 
1351
    x1 /= xii;
-
 
1352
    success += abs(x1[0] - xi1/xii) < 1.0e-15 
-
 
1353
               && abs(x1[1] - xi2/xii) < 1.0e-15 
-
 
1354
               && abs(x1[2] - xi3/xii) < 1.0e-15;
-
 
1355
 
-
 
1356
    x1 = Vec3f(xi1, xi2, xi3);
-
 
1357
    x1 += xii;
-
 
1358
    success += x1[0] == xi1 + xii && x1[1] == xi2 + xii && x1[2] == xi3 + xii;
-
 
1359
 
-
 
1360
    x1 = Vec3f(xi1, xi2, xi3);
-
 
1361
    x1 -= xii;
-
 
1362
    success += x1[0] == xi1 - xii && x1[1] == xi2 - xii && x1[2] == xi3 - xii;
-
 
1363
 
-
 
1364
    float xii1 = my_random(), xii2 = my_random(), xii3 = my_random();
-
 
1365
    Vec3f x2(xii1, xii2, xii3);
-
 
1366
    x1 = Vec3f(xi1, xi2, xi3);
-
 
1367
    x2 *= x1;
-
 
1368
    success += abs(x2[0] - xi1*xii1) < 1.0e-15 
-
 
1369
               && abs(x2[1] - xi2*xii2) < 1.0e-15 
-
 
1370
               && abs(x2[2] - xi3*xii3) < 1.0e-15;
-
 
1371
 
-
 
1372
    while(xi1 == 0)
-
 
1373
      xi1 = my_random();
-
 
1374
    while(xi2 == 0)
-
 
1375
      xi2 = my_random();
-
 
1376
    while(xi3 == 0)
-
 
1377
      xi3 = my_random();
-
 
1378
    x1 = Vec3f(xi1, xi2, xi3);
-
 
1379
    x2 = Vec3f(xii1, xii2, xii3);
-
 
1380
    x2 /= x1;
-
 
1381
    success += abs(x2[0] - xii1/xi1) < 1.0e-15 
-
 
1382
               && abs(x2[1] - xii2/xi2) < 1.0e-15 
-
 
1383
               && abs(x2[2] - xii3/xi3) < 1.0e-15;
-
 
1384
 
-
 
1385
    x2 = Vec3f(xii1, xii2, xii3);
-
 
1386
    x2 += x1;
-
 
1387
    success += x2[0] == xii1 + xi1 && x2[1] == xii2 + xi2 && x2[2] == xii3 + xi3;
-
 
1388
    
-
 
1389
    x2 = Vec3f(xii1, xii2, xii3);
-
 
1390
    x2 -= x1;
-
 
1391
    success += x2[0] == xii1 - xi1 && x2[1] == xii2 - xi2 && x2[2] == xii3 - xi3;    
-
 
1392
  }
-
 
1393
  if(success != 8)
-
 
1394
  {
-
 
1395
    cout << "Failure in test of Vec3f Assignment operators";
-
 
1396
    return 1;
-
 
1397
  }
-
 
1398
  success = 0;
-
 
1399
 
-
 
1400
  // Unary operators
-
 
1401
 
-
 
1402
  {
-
 
1403
    float xi1 = my_random(), xi2 = my_random(), xi3 = my_random();
-
 
1404
    Vec3f x1 = -Vec3f(xi1, xi2, xi3);    
-
 
1405
    success += x1[0] == -xi1 && x1[1] == -xi2 && x1[2] == -xi3;
-
 
1406
  }
-
 
1407
  if(success != 1)
-
 
1408
  {
-
 
1409
    cout << "Failure in test of Vec3f Unary operators";
-
 
1410
    return 1;
-
 
1411
  }
-
 
1412
  success = 0;
-
 
1413
 
-
 
1414
  // Binary operators
-
 
1415
 
-
 
1416
  {
-
 
1417
    float xi1 = my_random(), xi2 = my_random(), xi3 = my_random();
-
 
1418
    Vec3f x1(xi1, xi2, xi3);
-
 
1419
    float xii1 = my_random(), xii2 = my_random(), xii3 = my_random();
-
 
1420
    while(xii1 == 0)
-
 
1421
      xii1 = my_random();
-
 
1422
    while(xii2 == 0)
-
 
1423
      xii2 = my_random();
-
 
1424
    while(xii3 == 0)
-
 
1425
      xii3 = my_random();
-
 
1426
    Vec3f x2(xii1, xii2, xii3);
-
 
1427
    Vec3f x3 = x1*x2;
-
 
1428
    success += abs(x3[0] - xi1*xii1) < 1.0e-15 
-
 
1429
               && abs(x3[1] - xi2*xii2) < 1.0e-15 
-
 
1430
               && abs(x3[2] - xi3*xii3) < 1.0e-15;
-
 
1431
    
-
 
1432
    x3 = x1 + x2;
-
 
1433
    success += x3[0] == xi1 + xii1 && x3[1] == xi2 + xii2 && x3[2] == xi3 + xii3;
-
 
1434
 
-
 
1435
    x3 = x1 - x2;
-
 
1436
    success += x3[0] == xi1 - xii1 && x3[1] == xi2 - xii2 && x3[2] == xi3 - xii3;
-
 
1437
    
-
 
1438
    x3 = x1/x2;
-
 
1439
    success += abs(x3[0] - xi1/xii1) < 1.0e-15 
-
 
1440
               && abs(x3[1] - xi2/xii2) < 1.0e-15 
-
 
1441
               && abs(x3[2] - xi3/xii3) < 1.0e-15;
-
 
1442
 
-
 
1443
    float xii = my_random();
-
 
1444
    x3 = x1*xii;
-
 
1445
    success += abs(x3[0] - xi1*xii) < 1.0e-15
-
 
1446
               && abs(x3[1] - xi2*xii) < 1.0e-15 
-
 
1447
               && abs(x3[2] - xi3*xii) < 1.0e-15;
-
 
1448
    
-
 
1449
    x3 = xii*x1;
-
 
1450
    success += abs(x3[0] - xi1*xii) < 1.0e-15 
-
 
1451
               && abs(x3[1] - xi2*xii) < 1.0e-15 
-
 
1452
               && abs(x3[2] - xi3*xii) < 1.0e-15;
-
 
1453
 
-
 
1454
    int xi4 = rand();
-
 
1455
    x3 = xi4*x1;
-
 
1456
    success += abs(x3[0] - xi1*xi4) < 1.0e-15 
-
 
1457
               && abs(x3[1] - xi2*xi4) < 1.0e-15 
-
 
1458
               && abs(x3[2] - xi3*xi4) < 1.0e-15;
-
 
1459
    
-
 
1460
    x3 = x1*xi4;
-
 
1461
    success += abs(x3[0] - xi1*xi4) < 1.0e-15 
-
 
1462
               && abs(x3[1] - xi2*xi4) < 1.0e-15 
-
 
1463
               && abs(x3[2] - xi3*xi4) < 1.0e-15;
-
 
1464
 
-
 
1465
    double xi5 = my_random();
-
 
1466
    x3 = xi5*x1;
-
 
1467
    success += abs(x3[0] - xi1*xi5) < 1.0e-15 
-
 
1468
               && abs(x3[1] - xi2*xi5) < 1.0e-15 
-
 
1469
               && abs(x3[2] - xi3*xi5) < 1.0e-15;
-
 
1470
    
-
 
1471
    x3 = x1*xi5;
-
 
1472
    success += abs(x3[0] - xi1*xi5) < 1.0e-15 
-
 
1473
               && abs(x3[1] - xi2*xi5) < 1.0e-15 
-
 
1474
               && abs(x3[2] - xi3*xi5) < 1.0e-15;
-
 
1475
 
-
 
1476
    while(xii == 0)
-
 
1477
      xii = my_random();
-
 
1478
    x3 = x1/xii;
-
 
1479
    success += abs(x3[0] - xi1/xii) < 1.0e-15 
-
 
1480
               && abs(x3[1] - xi2/xii) < 1.0e-15 
-
 
1481
               && abs(x3[2] - xi3/xii) < 1.0e-15;
-
 
1482
  } 
-
 
1483
  if(success != 11)
-
 
1484
  {
-
 
1485
    cout << "Failure in test of Vec3f Binary operators";
-
 
1486
    return 1;
-
 
1487
  }
-
 
1488
  success = 0;
-
 
1489
 
-
 
1490
  // Vector operations
-
 
1491
 
-
 
1492
  {
-
 
1493
    float xi1 = my_random(), xi2 = my_random(), xi3 = my_random();
-
 
1494
    Vec3f x1(xi1, xi2, xi3);
-
 
1495
    float xii1 = my_random(), xii2 = my_random(), xii3 = my_random();
-
 
1496
    Vec3f x2(xii1, xii2, xii3);
-
 
1497
    float x = dot(x1, x2);
-
 
1498
    success += abs(x - xi1*xii1 - xi2*xii2 - xi3*xii3) < 1.0e-15;
-
 
1499
 
-
 
1500
    x = sqr_length(x1);
-
 
1501
    success += abs(x - xi1*xi1 - xi2*xi2 - xi3*xi3) < 1.0e-15;
-
 
1502
 
-
 
1503
    Vec3f x3 = v_min(x1, x2);
-
 
1504
    success += x3[0] == (xi1 < xii1 ? xi1 : xii1) 
-
 
1505
               && x3[1] == (xi2 < xii2 ? xi2 : xii2)
-
 
1506
               && x3[2] == (xi3 < xii3 ? xi3 : xii3);
-
 
1507
 
-
 
1508
    x3 = v_max(x1, x2);
-
 
1509
    success += x3[0] == (xi1 > xii1 ? xi1 : xii1) 
-
 
1510
               && x3[1] == (xi2 > xii2 ? xi2 : xii2)
-
 
1511
               && x3[2] == (xi3 > xii3 ? xi3 : xii3);
-
 
1512
 
-
 
1513
    Vec3f x4;
-
 
1514
    orthogonal(x2, x3, x4);
-
 
1515
    success += abs(dot(x2, x3)) < 1.0e-15;
-
 
1516
 
-
 
1517
    x3 = cross(x1, x2);
-
 
1518
    success += abs(x3[0] - xi2*xii3 + xi3*xii2) < 1.0e-15
-
 
1519
               && abs(x3[1] - xi3*xii1 + xi1*xii3) < 1.0e-15
-
 
1520
               && abs(x3[2] - xi1*xii2 + xi2*xii1) < 1.0e-15;
-
 
1521
 
-
 
1522
    float theta, phi, r;
-
 
1523
    x1.get_spherical(theta, phi, r);
-
 
1524
    success += abs(theta - acos(xi3/sqrt(xi1*xi1 + xi2*xi2 + xi3*xi3))) < 1.0e-15
-
 
1525
               && abs(phi - atan(xi2/xi1)) < 1.0e-15 
-
 
1526
               && abs(r - sqrt(xi1*xi1 + xi2*xi2 + xi3*xi3)) < 1.0e-15;
-
 
1527
 
-
 
1528
    x3.set_spherical(theta, phi, r);
-
 
1529
    success += abs(x3[0] - xi1) < 1.0e-15 
-
 
1530
               && abs(x3[1] - xi2) < 1.0e-15 
-
 
1531
               && abs(x3[2] - xi3) < 1.0e-15;
-
 
1532
  }
-
 
1533
  if(success != 8)
-
 
1534
  {
-
 
1535
    cout << "Failure in test of Vec3f Vector operations";
-
 
1536
    return 1;
-
 
1537
  }
-
 
1538
  success = 0;
-
 
1539
 
-
 
1540
  ////////////////////////////////////////////////
-
 
1541
  //                V e c 3 d
-
 
1542
  ////////////////////////////////////////////////
-
 
1543
 
-
 
1544
  // Constructors
-
 
1545
 
-
 
1546
  {
-
 
1547
    Vec3d x1;
-
 
1548
    success += _isnan(x1[0]) && _isnan(x1[1]) && _isnan(x1[2]);
-
 
1549
 
-
 
1550
    double xi1 = my_random(), xi2 = my_random(), xi3 = my_random();
-
 
1551
    Vec3d x2(xi1, xi2, xi3);
-
 
1552
    success += x2[0] == xi1 && x2[1] == xi2 && x2[2] == xi3;
-
 
1553
 
-
 
1554
    double xiiii = my_random();
-
 
1555
    Vec3d x3(xiiii);
-
 
1556
    success += x3[0] == xiiii && x3[1] == xiiii && x3[2] == xiiii;
-
 
1557
 
-
 
1558
    float xii1 = my_random(), xii2 = my_random(), xii3 = my_random();
-
 
1559
    Vec3f f1(xii1, xii2, xii3);
-
 
1560
    Vec3d x4(f1);
-
 
1561
    success += x4[0] == xii1 && x4[1] == xii2 && x4[2] == xii3;
-
 
1562
 
-
 
1563
    int xiii1 = rand(), xiii2 = rand(), xiii3 = rand();
-
 
1564
    Vec3i i1(xiii1, xiii2, xiii3);
-
 
1565
    Vec3d x5(i1);
-
 
1566
    success += x5[0] == xiii1 && x5[1] == xiii2 && x5[2] == xiii3;
-
 
1567
 
-
 
1568
/* Constructor non-existent !
-
 
1569
 *
-
 
1570
    double xiiii1 = my_random(), xiiii2 = my_random(), xiiii3 = my_random();
-
 
1571
    Quaternion q(xiiii1, xiiii2, xiiii3, 1.0);
-
 
1572
    Vec3d x6(q);
-
 
1573
    success += x6[0] == xiiii1 && x6[1] == xiiii2 && x6[2] == xiiii3;
-
 
1574
 
-
 
1575
    unsigned short int xiiv1 = USHRT_MAX*my_random(),
-
 
1576
                       xiiv2 = USHRT_MAX*my_random(),
-
 
1577
                       xiiv3 = USHRT_MAX*my_random();
-
 
1578
    Vec3usi usi1(xiiv1, xiiv2, xiiv3);
-
 
1579
    Vec3d x7(usi1);
-
 
1580
    success += x7[0] == xiiv1 && x7[1] == xiiv2 && x7[2] == xiiv3;
-
 
1581
*/
-
 
1582
  }
-
 
1583
  if(success != 5)
-
 
1584
  {
-
 
1585
    cout << "Failure in test of Vec3d Constructors";
-
 
1586
    return 1;
-
 
1587
  }
-
 
1588
  success = 0;
-
 
1589
 
-
 
1590
  // Data manipulation
-
 
1591
 
-
 
1592
  {
-
 
1593
    Vec3d x1;    
-
 
1594
 
-
 
1595
    success += x1.get_dim() == 3;
-
 
1596
 
-
 
1597
    double xi1 = my_random(), xi2 = my_random(), xi3 = my_random();
-
 
1598
    x1.set(xi1, xi2, xi3);
-
 
1599
    success += x1[0] == xi1 && x1[1] == xi2 && x1[2] == xi3;
-
 
1600
 
-
 
1601
    success += x1.get() == &x1[0];
-
 
1602
 
-
 
1603
    double temp = BIG;
-
 
1604
    for(double i = 0; i < x1.get_dim(); ++i)
-
 
1605
      if(x1[i] < temp)
-
 
1606
	temp = x1[i];
-
 
1607
    success += temp == x1.min_coord();
-
 
1608
 
-
 
1609
    temp = -BIG;
-
 
1610
    for(double i = 0; i < x1.get_dim(); ++i)
-
 
1611
      if(x1[i] > temp)
-
 
1612
	temp = x1[i];
-
 
1613
    success += temp == x1.max_coord();
-
 
1614
  }
-
 
1615
  if(success != 5)
-
 
1616
  {
-
 
1617
    cout << "Failure in test of Vec3d Data manipulation";
-
 
1618
    return 1;
-
 
1619
  }
-
 
1620
  success = 0;
-
 
1621
 
-
 
1622
  // Comparison operators
-
 
1623
 
-
 
1624
  {
-
 
1625
    double xi1 = my_random(), xi2 = my_random(), xi3 = my_random();
-
 
1626
    while(xi1 >= xi2)
-
 
1627
    {
-
 
1628
      xi1 = my_random();
-
 
1629
      xi2 = my_random();
-
 
1630
    }
-
 
1631
    while(xi3 <= xi2)
-
 
1632
      xi3 = my_random();
-
 
1633
 
-
 
1634
    Vec3d x1(xi1, xi2, xi3), x2(xi1, xi2, xi3), 
-
 
1635
          x3(xi1, xi1, xi1), x4(xi2, xi2, xi2), x5(xi3, xi3, xi3);    
-
 
1636
    success += x1 == x2;
-
 
1637
    success += !(x1 == x3);
-
 
1638
    success += x3 == xi1;
-
 
1639
    success += !(x3 == xi2);
-
 
1640
    success += x1 != x3;
-
 
1641
    success += !(x1 != x2);
-
 
1642
    success += x3.all_l(x4);
-
 
1643
    success += !(x3.all_l(x2));
-
 
1644
    success += x3.all_le(x2);
-
 
1645
    success += !(x4.all_le(x2));
-
 
1646
    success += x4.all_g(x3);
-
 
1647
    success += !(x4.all_g(x2));
-
 
1648
    success += x5.all_ge(x2);
-
 
1649
    success += !(x4.all_ge(x2));
-
 
1650
  }
-
 
1651
  if(success != 14)
-
 
1652
  {
-
 
1653
    cout << "Failure in test of Vec3d Comparison operators";
-
 
1654
    return 1;
-
 
1655
  }
-
 
1656
  success = 0;
-
 
1657
  
-
 
1658
  // Assignment operators
-
 
1659
 
-
 
1660
  {
-
 
1661
    double xi1 = my_random(), xi2 = my_random(), xi3 = my_random();
-
 
1662
    Vec3d x1(xi1, xi2, xi3);
-
 
1663
    double xii = my_random();
-
 
1664
    x1 *= xii;
-
 
1665
    success += abs(x1[0] - xi1*xii) < 1.0e-15 
-
 
1666
               && abs(x1[1] - xi2*xii) < 1.0e-15 
-
 
1667
               && abs(x1[2] - xi3*xii) < 1.0e-15;
-
 
1668
 
-
 
1669
    while(xii == 0)
-
 
1670
      xii = my_random();
-
 
1671
    x1 = Vec3d(xi1, xi2, xi3);
-
 
1672
    x1 /= xii;
-
 
1673
    success += abs(x1[0] - xi1/xii) < 1.0e-15 
-
 
1674
               && abs(x1[1] - xi2/xii) < 1.0e-15 
-
 
1675
               && abs(x1[2] - xi3/xii) < 1.0e-15;
-
 
1676
 
-
 
1677
    x1 = Vec3d(xi1, xi2, xi3);
-
 
1678
    x1 += xii;
-
 
1679
    success += x1[0] == xi1 + xii && x1[1] == xi2 + xii && x1[2] == xi3 + xii;
-
 
1680
 
-
 
1681
    x1 = Vec3d(xi1, xi2, xi3);
-
 
1682
    x1 -= xii;
-
 
1683
    success += x1[0] == xi1 - xii && x1[1] == xi2 - xii && x1[2] == xi3 - xii;
-
 
1684
 
-
 
1685
    double xii1 = my_random(), xii2 = my_random(), xii3 = my_random();
-
 
1686
    Vec3d x2(xii1, xii2, xii3);
-
 
1687
    x1 = Vec3d(xi1, xi2, xi3);
-
 
1688
    x2 *= x1;
-
 
1689
    success += abs(x2[0] - xi1*xii1) < 1.0e-15 
-
 
1690
               && abs(x2[1] - xi2*xii2) < 1.0e-15 
-
 
1691
               && abs(x2[2] - xi3*xii3) < 1.0e-15;
-
 
1692
 
-
 
1693
    while(xi1 == 0)
-
 
1694
      xi1 = my_random();
-
 
1695
    while(xi2 == 0)
-
 
1696
      xi2 = my_random();
-
 
1697
    while(xi3 == 0)
-
 
1698
      xi3 = my_random();
-
 
1699
    x1 = Vec3d(xi1, xi2, xi3);
-
 
1700
    x2 = Vec3d(xii1, xii2, xii3);
-
 
1701
    x2 /= x1;
-
 
1702
    success += abs(x2[0] - xii1/xi1) < 1.0e-15 
-
 
1703
               && abs(x2[1] - xii2/xi2) < 1.0e-15 
-
 
1704
               && abs(x2[2] - xii3/xi3) < 1.0e-15;
-
 
1705
 
-
 
1706
    x2 = Vec3d(xii1, xii2, xii3);
-
 
1707
    x2 += x1;
-
 
1708
    success += x2[0] == xii1 + xi1 && x2[1] == xii2 + xi2 && x2[2] == xii3 + xi3;
-
 
1709
    
-
 
1710
    x2 = Vec3d(xii1, xii2, xii3);
-
 
1711
    x2 -= x1;
-
 
1712
    success += x2[0] == xii1 - xi1 && x2[1] == xii2 - xi2 && x2[2] == xii3 - xi3;    
-
 
1713
  }
-
 
1714
  if(success != 8)
-
 
1715
  {
18
	// Test that the right cross products get called;
1716
    cout << "Failure in test of Vec3d Assignment operators";
-
 
1717
    return 1;
-
 
1718
  }
-
 
1719
  success = 0;
-
 
1720
 
-
 
1721
  // Unary operators
-
 
1722
 
-
 
1723
  {
-
 
1724
    double xi1 = my_random(), xi2 = my_random(), xi3 = my_random();
-
 
1725
    Vec3d x1 = -Vec3d(xi1, xi2, xi3);    
-
 
1726
    success += x1[0] == -xi1 && x1[1] == -xi2 && x1[2] == -xi3;
-
 
1727
  }
-
 
1728
  if(success != 1)
-
 
1729
  {
-
 
1730
    cout << "Failure in test of Vec3d Unary operators";
-
 
1731
    return 1;
-
 
1732
  }
-
 
1733
  success = 0;
-
 
1734
 
-
 
1735
  // Binary operators
-
 
1736
 
-
 
1737
  {
-
 
1738
    double xi1 = my_random(), xi2 = my_random(), xi3 = my_random();
-
 
1739
    Vec3d x1(xi1, xi2, xi3);
-
 
1740
    double xii1 = my_random(), xii2 = my_random(), xii3 = my_random();
-
 
1741
    while(xii1 == 0)
-
 
1742
      xii1 = my_random();
-
 
1743
    while(xii2 == 0)
-
 
1744
      xii2 = my_random();
-
 
1745
    while(xii3 == 0)
-
 
1746
      xii3 = my_random();
-
 
1747
    Vec3d x2(xii1, xii2, xii3);
-
 
1748
    Vec3d x3 = x1*x2;
-
 
1749
    success += abs(x3[0] - xi1*xii1) < 1.0e-15 
-
 
1750
               && abs(x3[1] - xi2*xii2) < 1.0e-15 
-
 
1751
               && abs(x3[2] - xi3*xii3) < 1.0e-15;
-
 
1752
    
-
 
1753
    x3 = x1 + x2;
-
 
1754
    success += x3[0] == xi1 + xii1 && x3[1] == xi2 + xii2 && x3[2] == xi3 + xii3;
-
 
1755
 
-
 
1756
    x3 = x1 - x2;
-
 
1757
    success += x3[0] == xi1 - xii1 && x3[1] == xi2 - xii2 && x3[2] == xi3 - xii3;
-
 
1758
    
-
 
1759
    x3 = x1/x2;
-
 
1760
    success += abs(x3[0] - xi1/xii1) < 1.0e-15 
-
 
1761
               && abs(x3[1] - xi2/xii2) < 1.0e-15 
-
 
1762
               && abs(x3[2] - xi3/xii3) < 1.0e-15;
-
 
1763
 
-
 
1764
    double xii = my_random();
-
 
1765
    x3 = x1*xii;
-
 
1766
    success += abs(x3[0] - xi1*xii) < 1.0e-15
-
 
1767
               && abs(x3[1] - xi2*xii) < 1.0e-15 
-
 
1768
               && abs(x3[2] - xi3*xii) < 1.0e-15;
-
 
1769
    
-
 
1770
    x3 = xii*x1;
-
 
1771
    success += abs(x3[0] - xi1*xii) < 1.0e-15 
-
 
1772
               && abs(x3[1] - xi2*xii) < 1.0e-15 
-
 
1773
               && abs(x3[2] - xi3*xii) < 1.0e-15;
-
 
1774
 
-
 
1775
    int xi4 = rand();
-
 
1776
    x3 = xi4*x1;
-
 
1777
    success += abs(x3[0] - xi1*xi4) < 1.0e-15 
-
 
1778
               && abs(x3[1] - xi2*xi4) < 1.0e-15 
-
 
1779
               && abs(x3[2] - xi3*xi4) < 1.0e-15;
-
 
1780
    
-
 
1781
    x3 = x1*xi4;
-
 
1782
    success += abs(x3[0] - xi1*xi4) < 1.0e-15 
-
 
1783
               && abs(x3[1] - xi2*xi4) < 1.0e-15 
-
 
1784
               && abs(x3[2] - xi3*xi4) < 1.0e-15;
-
 
1785
 
-
 
1786
    float xi5 = my_random();
-
 
1787
    x3 = xi5*x1;
-
 
1788
    success += abs(x3[0] - xi1*xi5) < 1.0e-15 
-
 
1789
               && abs(x3[1] - xi2*xi5) < 1.0e-15 
-
 
1790
               && abs(x3[2] - xi3*xi5) < 1.0e-15;
-
 
1791
    
-
 
1792
    x3 = x1*xi5;
-
 
1793
    success += abs(x3[0] - xi1*xi5) < 1.0e-15 
-
 
1794
               && abs(x3[1] - xi2*xi5) < 1.0e-15 
-
 
1795
               && abs(x3[2] - xi3*xi5) < 1.0e-15;
-
 
1796
 
-
 
1797
    while(xii == 0)
-
 
1798
      xii = my_random();
-
 
1799
    x3 = x1/xii;
-
 
1800
    success += abs(x3[0] - xi1/xii) < 1.0e-15 
-
 
1801
               && abs(x3[1] - xi2/xii) < 1.0e-15 
-
 
1802
               && abs(x3[2] - xi3/xii) < 1.0e-15;
-
 
1803
  } 
-
 
1804
  if(success != 11)
-
 
1805
  {
-
 
1806
    cout << "Failure in test of Vec3d Binary operators";
-
 
1807
    return 1;
-
 
1808
  }
-
 
1809
  success = 0;
-
 
1810
 
-
 
1811
  // Vector operations
-
 
1812
 
-
 
1813
  {
-
 
1814
    double xi1 = my_random(), xi2 = my_random(), xi3 = my_random();
-
 
1815
    Vec3d x1(xi1, xi2, xi3);
-
 
1816
    double xii1 = my_random(), xii2 = my_random(), xii3 = my_random();
-
 
1817
    Vec3d x2(xii1, xii2, xii3);
-
 
1818
    double x = dot(x1, x2);
-
 
1819
    success += abs(x - xi1*xii1 - xi2*xii2 - xi3*xii3) < 1.0e-15;
-
 
1820
 
-
 
1821
    x = sqr_length(x1);
-
 
1822
    success += abs(x - xi1*xi1 - xi2*xi2 - xi3*xi3) < 1.0e-15;
-
 
1823
 
-
 
1824
    Vec3d x3 = v_min(x1, x2);
-
 
1825
    success += x3[0] == (xi1 < xii1 ? xi1 : xii1) 
-
 
1826
               && x3[1] == (xi2 < xii2 ? xi2 : xii2)
-
 
1827
               && x3[2] == (xi3 < xii3 ? xi3 : xii3);
-
 
1828
 
-
 
1829
    x3 = v_max(x1, x2);
-
 
1830
    success += x3[0] == (xi1 > xii1 ? xi1 : xii1) 
-
 
1831
               && x3[1] == (xi2 > xii2 ? xi2 : xii2)
-
 
1832
               && x3[2] == (xi3 > xii3 ? xi3 : xii3);
-
 
1833
 
-
 
1834
    Vec3d x4;
-
 
1835
    orthogonal(x2, x3, x4);
-
 
1836
    success += abs(dot(x2, x3)) < 1.0e-15;
-
 
1837
 
-
 
1838
    x3 = cross(x1, x2);
-
 
1839
    success += abs(x3[0] - xi2*xii3 + xi3*xii2) < 1.0e-15
-
 
1840
               && abs(x3[1] - xi3*xii1 + xi1*xii3) < 1.0e-15
-
 
1841
               && abs(x3[2] - xi1*xii2 + xi2*xii1) < 1.0e-15;
-
 
1842
 
-
 
1843
    double theta, phi, r;
-
 
1844
    x1.get_spherical(theta, phi, r);
-
 
1845
    success += abs(theta - acos(xi3/sqrt(xi1*xi1 + xi2*xi2 + xi3*xi3))) < 1.0e-15
-
 
1846
               && abs(phi - atan(xi2/xi1)) < 1.0e-15 
-
 
1847
               && abs(r - sqrt(xi1*xi1 + xi2*xi2 + xi3*xi3)) < 1.0e-15;
-
 
1848
 
-
 
1849
    x3.set_spherical(theta, phi, r);
-
 
1850
    success += abs(x3[0] - xi1) < 1.0e-15 
-
 
1851
               && abs(x3[1] - xi2) < 1.0e-15 
-
 
1852
               && abs(x3[2] - xi3) < 1.0e-15;
-
 
1853
  }
-
 
1854
  if(success != 8)
-
 
1855
  {
-
 
1856
    cout << "Failure in test of Vec3d Vector operations";
-
 
1857
    return 1;
-
 
1858
  }
-
 
1859
  success = 0;
-
 
1860
 
-
 
1861
  ////////////////////////////////////////////////
-
 
1862
  //              F I N A L I Z E
-
 
1863
  ////////////////////////////////////////////////
-
 
1864
 
-
 
1865
  t.stop();
-
 
1866
 
-
 
1867
  cout << "Performance time: " << t.get_time();
-
 
1868
  cout << endl << "ArithVec and derived vector classes have been tested successfully";
19
 
1869
 
20
	{
-
 
21
		Vec2f a2(1,0),b2(0,1),c2;
-
 
22
		Vec3f af(1,0,0),bf(0,1,0),cf;
-
 
23
		Vec3d ad(1,0,0),bd(0,1,0),cd;
-
 
24
		Vec3i ai(1,0,0),bi(0,1,0),ci;
-
 
25
 
-
 
26
		float x = cross(a2, b2);
-
 
27
		cross(a2-b2, a2-b2);
-
 
28
		cf = cross(af, bf);
-
 
29
		ci = cross(ai, bi);
-
 
30
 
-
 
31
		assert(x == 1.0f);
-
 
32
		assert(cf == Vec3f(0,0,1));
-
 
33
		assert(ci == Vec3i(0,0,1));
-
 
34
		cout << " x (should be 1) " << x << endl;
-
 
35
		cout << " cf (should be 0,0,1) " << cf << endl;
-
 
36
		cout << " ci (should be 0,0,1) " << ci << endl;
-
 
37
	}
-
 
38
 
-
 
39
	{
-
 
40
		Vec3f af(1,0,0);
-
 
41
		Vec3f df,ef;
-
 
42
		orthogonal(af, df, ef);
-
 
43
		assert(df == Vec3f(0,1,0));
-
 
44
		assert(ef == Vec3f(0,0,1));
-
 
45
		cout << " df ef (should be 010 and 001) " << df << ef << endl;
-
 
46
 
-
 
47
		Vec3d ad(1,0,0);
-
 
48
		Vec3d dd,ed;
-
 
49
		orthogonal(ad, dd, ed);
-
 
50
		assert(dd == Vec3d(0,1,0));
-
 
51
		assert(ed == Vec3d(0,0,1));
-
 
52
		cout << " dd ed (should be 010 and 001) " << dd << ed << endl;
-
 
53
	}
-
 
54
	{
-
 
55
	  Vec3f af(1,3,2);
-
 
56
	  cout << "max_element af (should be 3): " << af.max_coord() << endl;
-
 
57
	  cout << "min_element af (should be 1): " << af.min_coord() << endl;
-
 
58
	  Vec3f bf(2,1,3);
-
 
59
	  cout << "v_max af bf (should be 233): " << v_max(af, bf) << endl;
-
 
60
	  cout << "v_min af bf (should be 112): " << v_min(af, bf) << endl;
-
 
61
	  Vec3f cf(2,2,2);
-
 
62
	  cout << "cf==3 (should be 0): " << (cf == 3) << endl;
-
 
63
	  cout << "cf==2 (should be 1): " << (cf == 2) << endl;
-
 
64
	  Timer t;
1870
  return 0;
65
 
-
 
66
	  float d;
-
 
67
	  t.start();
-
 
68
	  for(int i = 0; i < 10000000; ++i)
-
 
69
	  {
-
 
70
	    cf = cross(af, bf);
-
 
71
	    d = dot(af, bf);
-
 
72
	  }
-
 
73
	  t.stop();
-
 
74
	  cout << "Time 10,000,000 af cross bf" << endl
-
 
75
	       << "   + 10,000,000 af dot bf: "   << t.get_time() << endl;
-
 
76
	  cout << "Results: " << cf << " " << d;
-
 
77
	}
-
 
78
}
1871
}