summaryrefslogtreecommitdiffstats
path: root/src/BoundingBox.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/BoundingBox.cpp')
-rw-r--r--src/BoundingBox.cpp52
1 files changed, 35 insertions, 17 deletions
diff --git a/src/BoundingBox.cpp b/src/BoundingBox.cpp
index d0943d42a..482f9923f 100644
--- a/src/BoundingBox.cpp
+++ b/src/BoundingBox.cpp
@@ -1,4 +1,3 @@
-
// BoundingBox.cpp
// Implements the cBoundingBox class representing an axis-aligned bounding box with floatingpoint coords
@@ -11,41 +10,60 @@
-#if 0
+#ifdef SELF_TEST
-/// A simple self-test that is executed on program start, used to verify bbox functionality
-class SelfTest
+/** A simple self-test that is executed on program start, used to verify bbox functionality */
+static class SelfTest_BoundingBox
{
public:
- SelfTest(void)
+ SelfTest_BoundingBox(void)
{
Vector3d Min(1, 1, 1);
Vector3d Max(2, 2, 2);
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(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(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
} ;
+ bool Results[] = {true, true, true, false, true, false};
+ double LineCoeffs[] = {2, 0.25, 0.5, 0, 0.25, 0};
+
for (size_t i = 0; i < ARRAYCOUNT(LineDefs) / 2; i++)
{
double LineCoeff;
- char Face;
+ eBlockFace Face;
Vector3d Line1 = LineDefs[2 * i];
Vector3d Line2 = LineDefs[2 * i + 1];
bool res = cBoundingBox::CalcLineIntersection(Min, Max, Line1, Line2, LineCoeff, Face);
- printf("LineIntersection({%.02f, %.02f, %.02f}, {%.02f, %.02f, %.02f}) -> %d, %.05f, %d\n",
- Line1.x, Line1.y, Line1.z,
- Line2.x, Line2.y, Line2.z,
- res ? 1 : 0, LineCoeff, Face
- );
+ if (res != Results[i])
+ {
+ fprintf(stderr, "LineIntersection({%.02f, %.02f, %.02f}, {%.02f, %.02f, %.02f}) -> %d, %.05f, %d\n",
+ Line1.x, Line1.y, Line1.z,
+ Line2.x, Line2.y, Line2.z,
+ res ? 1 : 0, LineCoeff, Face
+ );
+ abort();
+ }
+ if (res)
+ {
+ if (LineCoeff != LineCoeffs[i])
+ {
+ fprintf(stderr, "LineIntersection({%.02f, %.02f, %.02f}, {%.02f, %.02f, %.02f}) -> %d, %.05f, %d\n",
+ Line1.x, Line1.y, Line1.z,
+ Line2.x, Line2.y, Line2.z,
+ res ? 1 : 0, LineCoeff, Face
+ );
+ abort();
+ }
+ }
} // for i - LineDefs[]
- printf("BoundingBox selftest complete.");
+ fprintf(stderr, "BoundingBox selftest complete.\n");
}
-} Test;
+} gTest;
#endif
@@ -228,7 +246,7 @@ bool cBoundingBox::IsInside(const Vector3d & a_Min, const Vector3d & a_Max, doub
-bool cBoundingBox::CalcLineIntersection(const Vector3d & a_Line1, const Vector3d & a_Line2, double & a_LineCoeff, char & a_Face)
+bool cBoundingBox::CalcLineIntersection(const Vector3d & a_Line1, const Vector3d & a_Line2, double & a_LineCoeff, eBlockFace & a_Face)
{
return CalcLineIntersection(m_Min, m_Max, a_Line1, a_Line2, a_LineCoeff, a_Face);
}
@@ -237,7 +255,7 @@ bool cBoundingBox::CalcLineIntersection(const Vector3d & a_Line1, const Vector3d
-bool cBoundingBox::CalcLineIntersection(const Vector3d & a_Min, const Vector3d & a_Max, const Vector3d & a_Line1, const Vector3d & a_Line2, double & a_LineCoeff, char & a_Face)
+bool cBoundingBox::CalcLineIntersection(const Vector3d & a_Min, const Vector3d & a_Max, const Vector3d & a_Line1, const Vector3d & a_Line2, double & a_LineCoeff, eBlockFace & a_Face)
{
if (IsInside(a_Min, a_Max, a_Line1))
{
@@ -247,7 +265,7 @@ bool cBoundingBox::CalcLineIntersection(const Vector3d & a_Min, const Vector3d &
return true;
}
- char Face = BLOCK_FACE_NONE;
+ eBlockFace Face = BLOCK_FACE_NONE;
double Coeff = Vector3d::NO_INTERSECTION;
// Check each individual bbox face for intersection with the line, remember the one with the lowest coeff