19 #define SET_CRT_DEBUG_FIELD(a) \
20 _CrtSetDbgFlag((a) | _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
21 #define CLEAR_CRT_DEBUG_FIELD(a) \
22 _CrtSetDbgFlag(~(a) & _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
24 #define SET_CRT_DEBUG_FIELD(a) ((void) 0)
25 #define CLEAR_CRT_DEBUG_FIELD(a) ((void) 0)
36 const float ooMax = 1.0f / (
float)(RAND_MAX+1);
38 float retValue = ( (
float)rand() * ooMax * (a_max - a_min) + a_min);
40 ASSERT(retValue >= a_min && retValue < a_max);
53 Vec3(
float a_x,
float a_y,
float a_z)
63 return Vec3(
v[0] + a_other.
v[0],
73 const Vec3& a_boxMinB,
const Vec3& a_boxMaxB)
75 for(
int axis=0; axis<3; ++axis)
77 if(a_boxMinA.
v[axis] > a_boxMaxB.
v[axis] ||
78 a_boxMaxA.
v[axis] < a_boxMinB.
v[axis])
118 int main(
int argc,
char* argv[])
120 const int NUM_OBJECTS = 40;
121 const int FRAC_OBJECTS = 4;
122 const float MAX_WORLDSIZE = 10.0f;
123 const float FRAC_WORLDSIZE = MAX_WORLDSIZE / 2;
128 ASSERT( NUM_OBJECTS > FRAC_OBJECTS );
133 memset(thingArray, 0,
sizeof(thingArray));
143 for( index = 0; index < NUM_OBJECTS; ++index )
152 thingArray[counter-1] = newThing;
154 tree.Insert(newThing->
m_min.
v, newThing->
m_max.
v, newThing);
158 printf(
"tree count = %d\n", tree.Count());
160 int numToDelete = NUM_OBJECTS / FRAC_OBJECTS;
161 int numToStep = FRAC_OBJECTS;
164 for( index = 0; index < NUM_OBJECTS; index += numToStep )
170 tree.Remove(curThing->
m_min.
v, curThing->
m_max.
v, curThing);
174 thingArray[index] = NULL;
178 printf(
"tree count = %d\n", tree.Count());
181 for( index = 0; index < numToDelete; ++index )
190 thingArray[counter-1] = newThing;
192 tree.Insert(newThing->
m_min.
v, newThing->
m_max.
v, newThing);
196 printf(
"tree count = %d\n", tree.Count());
198 Vec3 searchMin(0,0,0);
199 Vec3 searchMax(FRAC_WORLDSIZE, FRAC_WORLDSIZE, FRAC_WORLDSIZE);
207 SomeThingTree::Iterator it;
208 for( tree.GetFirst(it); !tree.IsNull(it); tree.GetNext(it) )
220 for( tree.GetFirst(it); !tree.IsNull(it); tree.GetNext(it) )
233 if(SomeThing::s_outstandingAllocs > 0)
235 printf(
"Memory leak!\n");
236 printf(
"s_outstandingAllocs = %d\n", SomeThing::s_outstandingAllocs);
240 printf(
"No memory leaks detected by app\n");
248 SET_CRT_DEBUG_FIELD( _CRTDBG_LEAK_CHECK_DF );
A user type to test with, instead of a simple type such as an 'int'.
bool _cdecl QueryResultCallback(SomeThing *a_data, void *a_context)
A callback function to obtain query results in this implementation.
int m_creationCounter
Just a number for identifying within test program.
float v[3]
3 float components for axes or dimensions
Vec3(float a_x, float a_y, float a_z)
Construct from three elements.
static float RandFloat(float a_min, float a_max)
static int s_outstandingAllocs
Count how many outstanding objects remain.
Simplify handling of 3 dimensional coordinate.
Vec3()
Default constructor.
static bool BoxesIntersect(const Vec3 &a_boxMinA, const Vec3 &a_boxMaxA, const Vec3 &a_boxMinB, const Vec3 &a_boxMaxB)
Vec3 m_max
Minimal bounding rect, values must be known and constant in order to remove from RTree.
Vec3 operator+(const Vec3 &a_other) const
Add two vectors and return result.
int main(int argc, char *argv[])