1
// Copyright (C) 2008-2011 Colin MacDonald
2
// No rights reserved: this software is in the public domain.
9
// These tests are also only called for f32 and f64, due to conversion problems
10
// in the respective methods.
12
static bool checkCollisions()
14
aabbox3d<T> one(0,0,0,4,4,4);
15
aabbox3d<T> two(2,2,2,4,4,4);
17
if (two.getInterpolated(one, 1) != two)
19
logTestString("aabbox3d<T> interpolation wrong on 1\n");
22
if (two.getInterpolated(one, 0) != one)
24
logTestString("aabbox3d<T> interpolation wrong on 0\n");
27
aabbox3d<T> three(two.getInterpolated(one, 0.5f));
30
logTestString("aabbox3d<T> interpolation wrong on 0.5 (right)\n");
35
logTestString("aabbox3d<T> interpolation wrong on 0.5 (left)\n");
38
three.reset(aabbox3d<T>(2,2,2,5,5,5));
39
if (!two.isFullInside(one))
41
logTestString("small aabbox3d<T> is not fully inside\n");
44
if (three.isFullInside(one))
46
logTestString("large aabbox3d<T> is fully inside\n");
50
if (!two.intersectsWithBox(one))
52
logTestString("small aabbox3d<T> does not intersect\n");
55
if (!three.intersectsWithBox(one))
57
logTestString("large aabbox3d<T> does not intersect\n");
61
core::line3d<T> line(-2,-2,-2,2,2,2);
62
if (!one.intersectsWithLine(line))
64
logTestString("aabbox3d<T> does not intersect with line(1)\n");
68
if (!one.intersectsWithLine(line))
70
logTestString("aabbox3d<T> does not intersect with line(2)\n");
74
if (one.intersectsWithLine(line))
76
logTestString("aabbox3d<T> does intersect with line(3)\n");
83
static bool checkPoints()
85
aabbox3d<T> one(-1,-2,-3,2,2,2);
87
if (!one.isPointInside(core::vector3d<T>(-1,-2,-3)))
89
logTestString("isPointInside failed with min vertex\n");
92
if (!one.isPointInside(core::vector3d<T>(-1,2,-3)))
94
logTestString("isPointInside failed with other min vertex\n");
97
if (!one.isPointInside(core::vector3d<T>(2,-2,2)))
99
logTestString("isPointInside failed with other max vertex\n");
102
if (!one.isPointInside(core::vector3d<T>(2,2,2)))
104
logTestString("isPointInside failed with max vertex\n");
107
if (!one.isPointInside(core::vector3d<T>(0,0,0)))
109
logTestString("isPointInside failed with origin\n");
112
if (!one.isPointInside(core::vector3d<T>((T)1.2,-1,1)))
114
logTestString("isPointInside failed with random point inside\n");
117
if (one.isPointInside(core::vector3d<T>(-2,-2,-3)))
119
logTestString("isPointInside failed near min vertex\n");
122
if (one.isPointInside(core::vector3d<T>(2,3,2)))
124
logTestString("isPointInside failed near max vertex\n");
127
if (one.isPointInside(core::vector3d<T>(3,0,0)))
129
logTestString("isPointInside failed near origin\n");
132
if (one.isPointInside(core::vector3d<T>((T)10.2,-1,1)))
134
logTestString("isPointInside failed with random point outside\n");
137
if (one.isPointTotalInside(core::vector3d<T>(-1,-2,-3)))
139
logTestString("isPointTotalInside failed with min vertex\n");
142
if (one.isPointTotalInside(core::vector3d<T>(-1,2,-3)))
144
logTestString("isPointTotalInside failed with other min vertex\n");
147
if (one.isPointTotalInside(core::vector3d<T>(2,-2,2)))
149
logTestString("isPointTotalInside failed with other max vertex\n");
152
if (one.isPointTotalInside(core::vector3d<T>(2,2,2)))
154
logTestString("isPointTotalInside failed with max vertex\n");
157
if (!one.isPointTotalInside(core::vector3d<T>(0,0,0)))
159
logTestString("isPointTotalInside failed with origin\n");
162
if (!one.isPointTotalInside(core::vector3d<T>((T)1.2,-1,1)))
164
logTestString("isPointTotalInside failed with random point inside\n");
167
if (one.isPointTotalInside(core::vector3d<T>((T)10.2,-1,1)))
169
logTestString("isPointTotalInside failed with random point outside\n");
173
core::plane3d<T> plane(core::vector3d<T>(0,0,-1), -10);
174
if (one.classifyPlaneRelation(plane) != core::ISREL3D_BACK)
176
logTestString("box not behind\n");
180
if (one.classifyPlaneRelation(plane) != core::ISREL3D_CLIPPED)
182
logTestString("box not clipped\n");
186
if (one.classifyPlaneRelation(plane) != core::ISREL3D_FRONT)
188
logTestString("box not in front\n");
195
static bool doTests()
198
aabbox3d<T> one(-1,-1,-1,1,1,1);
201
logTestString("default aabbox3d<T> wrong, or comparison failed\n");
204
if (empty.getCenter() != core::vector3d<T>(0,0,0))
206
logTestString("default aabbox3d<T> has wrong Center\n");
209
if (empty.getExtent() != core::vector3d<T>(2,2,2))
211
logTestString("default aabbox3d<T> has wrong Extent\n");
216
logTestString("default aabbox3d<T> is empty\n");
219
if (empty.getVolume() != 8)
221
logTestString("default aabbox3d<T> has wrong volume\n");
224
if (empty.getArea() != 24)
226
logTestString("default aabbox3d<T> has wrong area\n");
229
aabbox3d<T> two(core::vector3d<T>(-1,-1,-1),core::vector3d<T>(2,2,2));
232
logTestString("empty aabbox3d<T> too large, or comparison failed\n");
235
if (two.getCenter() != core::vector3d<T>((T)0.5,(T)0.5,(T)0.5))
237
logTestString("extended aabbox3d<T> has wrong Center\n");
240
if (two.getExtent() != core::vector3d<T>(3,3,3))
242
logTestString("extended aabbox3d<T> has wrong Extent\n");
247
logTestString("extended aabbox3d<T> is empty\n");
250
if (two.getVolume() != 27)
252
logTestString("extended aabbox3d<T> has wrong volume\n");
255
if (two.getArea() != 54)
257
logTestString("extended aabbox3d<T> has wrong area\n");
263
logTestString("reset failed, or comparison failed\n");
266
if (one.getCenter() != core::vector3d<T>(1,1,1))
268
logTestString("singular aabbox3d<T> has wrong Center\n");
271
if (one.getExtent() != core::vector3d<T>(0,0,0))
273
logTestString("singular aabbox3d<T> has Extent\n");
278
logTestString("empty aabbox3d<T> is not empty\n");
281
if (one.getVolume() != 0)
283
logTestString("empty aabbox3d<T> has wrong volume\n");
286
if (one.getArea() != 0)
288
logTestString("empty aabbox3d<T> has wrong area\n");
291
one.addInternalPoint(core::vector3d<T>(-1,-1,-1));
294
logTestString("addInternalPoint failed, creating default bbox\n");
301
logTestString("reset with bbox failed, creating default bbox\n");
304
one.addInternalPoint(core::vector3d<T>(2,2,2));
307
logTestString("addInternalPoint for aabbox3d<T> failed.\n");
310
one.addInternalBox(empty);
313
logTestString("addInternalBox with smaller box failed.\n");
316
one.addInternalBox(two);
319
logTestString("addInternalBox with same box failed.\n");
322
one.addInternalPoint(-1,-2,-3);
323
two.addInternalPoint(-1,-2,-3);
324
empty.addInternalBox(one);
327
logTestString("addInternalBox with larger box failed\n");
330
if (one.getCenter() != core::vector3d<T>((T)0.5,0,(T)-0.5))
332
logTestString("large aabbox3d<T> has wrong Center\n");
335
if (one.getExtent() != core::vector3d<T>(3,4,5))
337
logTestString("large aabbox3d<T> has wrong Extent\n");
342
logTestString("large aabbox3d<T> is empty\n");
345
if (one.getVolume() != 60)
347
logTestString("large aabbox3d<T> has wrong volume\n");
350
if (one.getArea() != 94)
352
logTestString("large aabbox3d<T> has wrong area\n");
355
if (!checkPoints<T>())
361
/** Test the functionality of aabbox3d<T>. */
362
bool testaabbox3d(void)
364
bool f32Success = doTests<f32>();
365
f32Success &= checkCollisions<f32>();
367
logTestString("aabbox3d<f32> tests passed\n\n");
369
logTestString("\n*** aabbox3d<f32> tests failed ***\n\n");
371
bool f64Success = doTests<f64>();
372
f64Success &= checkCollisions<f64>();
374
logTestString("aabbox3d<f64> tests passed\n\n");
376
logTestString("\n*** aabbox3d<f64> tests failed ***\n\n");
378
bool s32Success = doTests<s32>();
380
logTestString("aabbox3d<s32> tests passed\n\n");
382
logTestString("\n*** aabbox3d<s32> tests failed ***\n\n");
384
return f32Success && f64Success && s32Success;