Subversion Repositories gelsvn

Rev

Rev 18 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 bj 1
#include <iostream>
2
 
3
#include "CGLA/Vec2f.h"
4
#include "CGLA/Vec2i.h"
5
#include "CGLA/Vec3i.h"
6
#include "CGLA/Vec3f.h"
7
#include "CGLA/Vec3d.h"
8
#include "CGLA/Vec3Hf.h"
20 jrf 9
#include "Timer.h"
2 bj 10
 
11
using namespace std;
12
using namespace CGLA;
13
 
14
 
15
/* This is a non-exhaustive test program for CGLA */
16
main()
17
{
18
	// Test that the right cross products get called;
19
 
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
	}
20 jrf 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;
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
	}
2 bj 78
}