math test reviewed
This commit is contained in:
parent
72117b5314
commit
ff710a24c7
@ -5,14 +5,17 @@
|
|||||||
// James Turk (jpt2433@rit.edu)
|
// James Turk (jpt2433@rit.edu)
|
||||||
//
|
//
|
||||||
// Version:
|
// Version:
|
||||||
// $Id: math_test.cpp,v 1.3 2005/07/17 02:40:39 cozman Exp $
|
// $Id: math_test.cpp,v 1.4 2005/07/20 01:47:15 cozman Exp $
|
||||||
|
|
||||||
// Tests almost everything within photon::math
|
// Tests almost everything within photon::math (example run at bottom of file)
|
||||||
// Doesn't test:
|
// Doesn't test:
|
||||||
// -Circle-Rectangle intersection: hard to test without graphics
|
// -Circle-Rectangle intersection: hard to test without graphics
|
||||||
// -Accessors: so many of them, simple to detect problems, possibly add later
|
// -Accessors: so many of them, simple to detect problems, possibly add later
|
||||||
// -Rect: coming soon
|
//
|
||||||
// -Vector2: coming soon
|
// example checks should always contain a positive check followed by a negative
|
||||||
|
// ex:
|
||||||
|
// a contains origin
|
||||||
|
// b doesn't contain origin
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
@ -20,10 +23,6 @@
|
|||||||
using namespace photon;
|
using namespace photon;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
// example checks should always contain a positive check followed by a negative
|
|
||||||
// ex:
|
|
||||||
// a contains origin
|
|
||||||
// b doesn't contain origin
|
|
||||||
|
|
||||||
void testGeneral()
|
void testGeneral()
|
||||||
{
|
{
|
||||||
@ -169,3 +168,82 @@ int main()
|
|||||||
testRect();
|
testRect();
|
||||||
testVector2();
|
testVector2();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Example run (values may vary slightly):
|
||||||
|
// --General Math-------------------------------------------------
|
||||||
|
// PI = 3.141592654
|
||||||
|
// clamp(2.5, 0, 5) = 2.5
|
||||||
|
// clamp(-1, 0, 5) = 0
|
||||||
|
// clamp(1000, 0, 5) = 5
|
||||||
|
// scalarCompare(3.0, 3.0000001) are equal
|
||||||
|
// scalarCompare(3.0, 3.1) are not equal
|
||||||
|
// PI/6 radians = 30 degrees
|
||||||
|
// 45 degrees = 0.785 radians
|
||||||
|
//
|
||||||
|
// --Circles------------------------------------------------------
|
||||||
|
// a: Circle { Center: (0,0) Radius: 1 }
|
||||||
|
// b: Circle { Center: (10,10) Radius: 25 }
|
||||||
|
// c: Circle { Center: (-10,-10) Radius: 1 }
|
||||||
|
// a == a
|
||||||
|
// a != b
|
||||||
|
// Moving a to 100,100: a: Circle { Center: (100,100) Radius: 1 }
|
||||||
|
// Moving a by -100,-100: a: Circle { Center: (0,0) Radius: 1 }
|
||||||
|
// Resizing a's radius to 2: a: Circle { Center: (0,0) Radius: 2 }
|
||||||
|
// Resizing a's radius by -3 (can't have negative radius): a: Circle
|
||||||
|
// { Center: (0,0) Radius: 0 }
|
||||||
|
// Resizing a's radius by +3: a: Circle { Center: (0,0) Radius: 3 }
|
||||||
|
// a and b intersect.
|
||||||
|
// a and c do not intersect.
|
||||||
|
// a contains (0,0).
|
||||||
|
// c doesn't contain (0,0).
|
||||||
|
//
|
||||||
|
// --Rects--------------------------------------------------------
|
||||||
|
// a: Rect { Top left: (-4,-4) Width: 4 Height: 4 }
|
||||||
|
// b: Rect { Top left: (-4,-4) Width: 10 Height: 10 }
|
||||||
|
// c: Rect { Top left: (-4,-4) Width: 4 Height: 4 }
|
||||||
|
// d: Rect { Top left: (-3,-3) Width: 1 Height: 1 }
|
||||||
|
// a == a
|
||||||
|
// a != b
|
||||||
|
// Moving a to 0,0: a: Rect { Top left: (0,0) Width: 4 Height: 4 }
|
||||||
|
// Moving a by 4,4: a: Rect { Top left: (4,4) Width: 4 Height: 4 }
|
||||||
|
// Resizing a to 8x8: a: Rect { Top left: (4,4) Width: 8 Height: 8 }
|
||||||
|
// Resizing a by 2 in each direction: a:
|
||||||
|
// Rect { Top left: (4,4) Width: 10 Height: 10 }
|
||||||
|
// a and b intersect.
|
||||||
|
// a and c do not intersect.
|
||||||
|
// c contains d
|
||||||
|
// d doesn't contain c
|
||||||
|
// c contains (0,0).
|
||||||
|
// d doesn't contain (0,0).
|
||||||
|
// a.calcIntersection(b) = Rect { Top left: (4,4) Width: 2 Height: 2 }
|
||||||
|
// a.calcIntersection(a) = Rect { Top left: (4,4) Width: 10 Height: 10 }
|
||||||
|
// a.calcIntersection(c) = Rect { Top left: (0,0) Width: 0 Height: 0 }
|
||||||
|
//
|
||||||
|
// --Vector2------------------------------------------------------
|
||||||
|
// a: (0,0)
|
||||||
|
// b: (1,2)
|
||||||
|
// Setting a to [5,5]: a: (5,5)
|
||||||
|
// Setting a to 5 units long at 45 degrees: a: (3.54,-3.54)
|
||||||
|
// Setting a to 5 units long at pi radians: a: (-5,-6.12e-16)
|
||||||
|
// Normalizing a: a: (-1,-1.22e-16)
|
||||||
|
// a == a
|
||||||
|
// a != b
|
||||||
|
// -a = (1,1.22e-16)
|
||||||
|
// a.b = -1
|
||||||
|
// a+b = (0,2)
|
||||||
|
// a-b = (-2,-2)
|
||||||
|
// 2*a = (-2,-2.45e-16)
|
||||||
|
// a/2 = (-0.5,-6.12e-17)
|
||||||
|
// a += b: (0,2)
|
||||||
|
// a -= b: (-1,-2.22e-16)
|
||||||
|
// |a| = 1
|
||||||
|
// |b| = 2.24
|
||||||
|
// angle of a (deg) = -180
|
||||||
|
// angle of b (deg) = 63.4
|
||||||
|
// angle of a (rad) = -3.14
|
||||||
|
// angle of b (rad) = 1.11
|
||||||
|
// normal of a: (-1,-2.22e-16)
|
||||||
|
// normal of b: (0.447,0.894)
|
||||||
|
// angle between a and b (deg): 117
|
||||||
|
// angle between a and b (rad): 2.03
|
||||||
|
// distance between a and b: 2.83
|
||||||
|
Loading…
Reference in New Issue
Block a user