1
0

Fixed cBoundingBox self-test code-style.

Also made the class name unique and the global variable static, to avoid linkage problems with other self-tests
This commit is contained in:
madmaxoft 2014-02-16 23:30:50 +01:00
parent b90c9936b8
commit b0dbe51210

View File

@ -12,25 +12,25 @@
#if SELF_TEST #if SELF_TEST
/// A simple self-test that is executed on program start, used to verify bbox functionality /** A simple self-test that is executed on program start, used to verify bbox functionality */
class SelfTest static class SelfTest_BoundingBox
{ {
public: public:
SelfTest(void) SelfTest_BoundingBox(void)
{ {
Vector3d Min(1, 1, 1); Vector3d Min(1, 1, 1);
Vector3d Max(2, 2, 2); Vector3d Max(2, 2, 2);
Vector3d LineDefs[] = Vector3d LineDefs[] =
{ {
Vector3d(1.5, 4, 1.5), Vector3d(1.5, 3, 1.5), // Should intersect at 2, face 1 (YP) Vector3d(1.5, 4, 1.5), Vector3d(1.5, 3, 1.5), // Should intersect at 2, face 1 (YP)
Vector3d(1.5, 0, 1.5), Vector3d(1.5, 4, 1.5), // Should intersect at 0.25, face 0 (YM) Vector3d(1.5, 0, 1.5), Vector3d(1.5, 4, 1.5), // Should intersect at 0.25, face 0 (YM)
Vector3d(0, 0, 0), Vector3d(2, 2, 2), // Should intersect at 0.5, face 0, 3 or 5 (anyM) Vector3d(0, 0, 0), Vector3d(2, 2, 2), // Should intersect at 0.5, face 0, 3 or 5 (anyM)
Vector3d(0.999, 0, 1.5), Vector3d(0.999, 4, 1.5), // Should not intersect Vector3d(0.999, 0, 1.5), Vector3d(0.999, 4, 1.5), // Should not intersect
Vector3d(1.999, 0, 1.5), Vector3d(1.999, 4, 1.5), // Should intersect at 0.25, face 0 (YM) Vector3d(1.999, 0, 1.5), Vector3d(1.999, 4, 1.5), // Should intersect at 0.25, face 0 (YM)
Vector3d(2.001, 0, 1.5), Vector3d(2.001, 4, 1.5), // Should not intersect Vector3d(2.001, 0, 1.5), Vector3d(2.001, 4, 1.5), // Should not intersect
} ; } ;
bool Results[] = {true,true,true,false,true,false}; bool Results[] = {true, true, true, false, true, false};
double LineCoeffs[] = {2,0.25,0.5,0,0.25,0}; double LineCoeffs[] = {2, 0.25, 0.5, 0, 0.25, 0};
for (size_t i = 0; i < ARRAYCOUNT(LineDefs) / 2; i++) for (size_t i = 0; i < ARRAYCOUNT(LineDefs) / 2; i++)
{ {
@ -41,7 +41,7 @@ public:
bool res = cBoundingBox::CalcLineIntersection(Min, Max, Line1, Line2, LineCoeff, Face); bool res = cBoundingBox::CalcLineIntersection(Min, Max, Line1, Line2, LineCoeff, Face);
if (res != Results[i]) if (res != Results[i])
{ {
fprintf(stderr,"LineIntersection({%.02f, %.02f, %.02f}, {%.02f, %.02f, %.02f}) -> %d, %.05f, %d\n", fprintf(stderr, "LineIntersection({%.02f, %.02f, %.02f}, {%.02f, %.02f, %.02f}) -> %d, %.05f, %d\n",
Line1.x, Line1.y, Line1.z, Line1.x, Line1.y, Line1.z,
Line2.x, Line2.y, Line2.z, Line2.x, Line2.y, Line2.z,
res ? 1 : 0, LineCoeff, Face res ? 1 : 0, LineCoeff, Face
@ -52,7 +52,7 @@ public:
{ {
if (LineCoeff != LineCoeffs[i]) if (LineCoeff != LineCoeffs[i])
{ {
fprintf(stderr,"LineIntersection({%.02f, %.02f, %.02f}, {%.02f, %.02f, %.02f}) -> %d, %.05f, %d\n", fprintf(stderr, "LineIntersection({%.02f, %.02f, %.02f}, {%.02f, %.02f, %.02f}) -> %d, %.05f, %d\n",
Line1.x, Line1.y, Line1.z, Line1.x, Line1.y, Line1.z,
Line2.x, Line2.y, Line2.z, Line2.x, Line2.y, Line2.z,
res ? 1 : 0, LineCoeff, Face res ? 1 : 0, LineCoeff, Face
@ -61,9 +61,9 @@ public:
} }
} }
} // for i - LineDefs[] } // for i - LineDefs[]
fprintf(stderr,"BoundingBox selftest complete."); fprintf(stderr, "BoundingBox selftest complete.\n");
} }
} Test; } gTest;
#endif #endif