Rev 18 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#include <iostream>
#include "CGLA/Vec2f.h"
#include "CGLA/Vec2i.h"
#include "CGLA/Vec3i.h"
#include "CGLA/Vec3f.h"
#include "CGLA/Vec3d.h"
#include "CGLA/Vec3Hf.h"
#include "Timer.h"
using namespace std;
using namespace CGLA;
/* This is a non-exhaustive test program for CGLA */
main()
{
// Test that the right cross products get called;
{
Vec2f a2(1,0),b2(0,1),c2;
Vec3f af(1,0,0),bf(0,1,0),cf;
Vec3d ad(1,0,0),bd(0,1,0),cd;
Vec3i ai(1,0,0),bi(0,1,0),ci;
float x = cross(a2, b2);
cross(a2-b2, a2-b2);
cf = cross(af, bf);
ci = cross(ai, bi);
assert(x == 1.0f);
assert(cf == Vec3f(0,0,1));
assert(ci == Vec3i(0,0,1));
cout << " x (should be 1) " << x << endl;
cout << " cf (should be 0,0,1) " << cf << endl;
cout << " ci (should be 0,0,1) " << ci << endl;
}
{
Vec3f af(1,0,0);
Vec3f df,ef;
orthogonal(af, df, ef);
assert(df == Vec3f(0,1,0));
assert(ef == Vec3f(0,0,1));
cout << " df ef (should be 010 and 001) " << df << ef << endl;
Vec3d ad(1,0,0);
Vec3d dd,ed;
orthogonal(ad, dd, ed);
assert(dd == Vec3d(0,1,0));
assert(ed == Vec3d(0,0,1));
cout << " dd ed (should be 010 and 001) " << dd << ed << endl;
}
{
Vec3f af(1,3,2);
cout << "max_element af (should be 3): " << af.max_coord() << endl;
cout << "min_element af (should be 1): " << af.min_coord() << endl;
Vec3f bf(2,1,3);
cout << "v_max af bf (should be 233): " << v_max(af, bf) << endl;
cout << "v_min af bf (should be 112): " << v_min(af, bf) << endl;
Vec3f cf(2,2,2);
cout << "cf==3 (should be 0): " << (cf == 3) << endl;
cout << "cf==2 (should be 1): " << (cf == 2) << endl;
Timer t;
float d;
t.start();
for(int i = 0; i < 10000000; ++i)
{
cf = cross(af, bf);
d = dot(af, bf);
}
t.stop();
cout << "Time 10,000,000 af cross bf" << endl
<< " + 10,000,000 af dot bf: " << t.get_time() << endl;
cout << "Results: " << cf << " " << d;
}
}