Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefix assume & assert definitions to prevent name clashes #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions src/Algorithm/GJK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ vec UpdateSimplex(vec *s, int &n)
float d0 = s[0].DistanceSq(vec::zero);
float d1 = s[1].DistanceSq(vec::zero);
float d2 = LineSegment(s[0], s[1]).DistanceSq(vec::zero);
assert2(d2 <= d0, d2, d0);
assert2(d2 <= d1, d2, d1);
mgl_assert2(d2 <= d0, d2, d0);
mgl_assert2(d2 <= d1, d2, d1);
// Cannot be in case 0: the step 0 -> 1 must have been toward the zero direction:
assert(Dot(s[1]-s[0], -s[0]) >= 0.f);
mgl_assert(Dot(s[1]-s[0], -s[0]) >= 0.f);
// Cannot be in case 1: the zero direction cannot be in the voronoi region of vertex s[1].
assert(Dot(s[1]-s[0], -s[1]) <= 0.f);
mgl_assert(Dot(s[1]-s[0], -s[1]) <= 0.f);
#endif

vec d01 = s[1] - s[0];
Expand Down Expand Up @@ -105,10 +105,10 @@ vec UpdateSimplex(vec *s, int &n)
minDistIndex = i;
}

assert4(isContainedInTriangle || dist <= d[0] + 1e-4f, d[0], dist, isContainedInTriangle, minDistIndex);
assert4(isContainedInTriangle || dist <= d[1] + 1e-4f, d[1], dist, isContainedInTriangle, minDistIndex);
assert4(isContainedInTriangle || dist <= d[2] + 1e-4f, d[2], dist, isContainedInTriangle, minDistIndex);
assert4(isContainedInTriangle || dist <= d[3] + 1e-4f, d[3], dist, isContainedInTriangle, minDistIndex);
mgl_assert4(isContainedInTriangle || dist <= d[0] + 1e-4f, d[0], dist, isContainedInTriangle, minDistIndex);
mgl_assert4(isContainedInTriangle || dist <= d[1] + 1e-4f, d[1], dist, isContainedInTriangle, minDistIndex);
mgl_assert4(isContainedInTriangle || dist <= d[2] + 1e-4f, d[2], dist, isContainedInTriangle, minDistIndex);
mgl_assert4(isContainedInTriangle || dist <= d[3] + 1e-4f, d[3], dist, isContainedInTriangle, minDistIndex);
#endif
vec d12 = s[2]-s[1];
vec d02 = s[2]-s[0];
Expand All @@ -120,7 +120,7 @@ vec UpdateSimplex(vec *s, int &n)
{
// Case 4: Edge 1->2 is closest.
#ifdef MATH_ASSERT_CORRECTNESS
assert4(d[4] <= dist + 1e-3f * Max(1.f, d[4], dist), d[4], dist, isContainedInTriangle, minDistIndex);
mgl_assert4(d[4] <= dist + 1e-3f * Max(1.f, d[4], dist), d[4], dist, isContainedInTriangle, minDistIndex);
#endif
vec newDir = Cross(d12, Cross(d12, s[1]));
s[0] = s[1];
Expand All @@ -134,7 +134,7 @@ vec UpdateSimplex(vec *s, int &n)
{
// Case 5: Edge 0->2 is closest.
#ifdef MATH_ASSERT_CORRECTNESS
assert4(d[5] <= dist + 1e-3f * Max(1.f, d[5], dist), d[5], dist, isContainedInTriangle, minDistIndex);
mgl_assert4(d[5] <= dist + 1e-3f * Max(1.f, d[5], dist), d[5], dist, isContainedInTriangle, minDistIndex);
#endif
vec newDir = Cross(d02, Cross(d02, s[0]));
s[1] = s[2];
Expand All @@ -143,7 +143,7 @@ vec UpdateSimplex(vec *s, int &n)
}
// Cases 6)-8):
#ifdef MATH_ASSERT_CORRECTNESS
assert4(d[6] <= dist + 1e-3f * Max(1.f, d[6], dist), d[6], dist, isContainedInTriangle, minDistIndex);
mgl_assert4(d[6] <= dist + 1e-3f * Max(1.f, d[6], dist), d[6], dist, isContainedInTriangle, minDistIndex);
#endif
float scaledSignedDistToTriangle = triNormal.Dot(s[2]);
float distSq = scaledSignedDistToTriangle*scaledSignedDistToTriangle;
Expand Down Expand Up @@ -216,7 +216,7 @@ vec UpdateSimplex(vec *s, int &n)
vec Tri023Normal = Cross(s[3]-s[0], s[2]-s[0]);
vec Tri123Normal = Cross(s[2]-s[1], s[3]-s[1]);
vec Tri012Normal = Cross(s[2] - s[0], s[1] - s[0]);
assert(Dot(Tri012Normal, s[3] - s[0]) <= 0.f);
mgl_assert(Dot(Tri012Normal, s[3] - s[0]) <= 0.f);
float InTri012 = Dot(-s[0], Tri012Normal);
float InTri013 = Dot(-s[3], Tri013Normal);
float InTri023 = Dot(-s[3], Tri023Normal);
Expand All @@ -232,13 +232,13 @@ vec UpdateSimplex(vec *s, int &n)
dist = d[i];
minDistIndex = i;
}
assert4(insideSimplex || dist <= d[0] + 1e-4 * Max(1.0, d[0], dist), d[0], dist, insideSimplex, minDistIndex);
assert4(insideSimplex || dist <= d[1] + 1e-4 * Max(1.0, d[1], dist), d[1], dist, insideSimplex, minDistIndex);
assert4(insideSimplex || dist <= d[2] + 1e-4 * Max(1.0, d[2], dist), d[2], dist, insideSimplex, minDistIndex);
assert4(insideSimplex || dist <= d[4] + 1e-4 * Max(1.0, d[4], dist), d[4], dist, insideSimplex, minDistIndex);
assert4(insideSimplex || dist <= d[5] + 1e-4 * Max(1.0, d[5], dist), d[5], dist, insideSimplex, minDistIndex);
assert4(insideSimplex || dist <= d[7] + 1e-4 * Max(1.0, d[7], dist), d[7], dist, insideSimplex, minDistIndex);
assert4(insideSimplex || dist <= d[10] + 1e-4 * Max(1.0, d[10], dist), d[10], dist, insideSimplex, minDistIndex);
mgl_assert4(insideSimplex || dist <= d[0] + 1e-4 * Max(1.0, d[0], dist), d[0], dist, insideSimplex, minDistIndex);
mgl_assert4(insideSimplex || dist <= d[1] + 1e-4 * Max(1.0, d[1], dist), d[1], dist, insideSimplex, minDistIndex);
mgl_assert4(insideSimplex || dist <= d[2] + 1e-4 * Max(1.0, d[2], dist), d[2], dist, insideSimplex, minDistIndex);
mgl_assert4(insideSimplex || dist <= d[4] + 1e-4 * Max(1.0, d[4], dist), d[4], dist, insideSimplex, minDistIndex);
mgl_assert4(insideSimplex || dist <= d[5] + 1e-4 * Max(1.0, d[5], dist), d[5], dist, insideSimplex, minDistIndex);
mgl_assert4(insideSimplex || dist <= d[7] + 1e-4 * Max(1.0, d[7], dist), d[7], dist, insideSimplex, minDistIndex);
mgl_assert4(insideSimplex || dist <= d[10] + 1e-4 * Max(1.0, d[10], dist), d[10], dist, insideSimplex, minDistIndex);
#endif

vec d01 = s[1] - s[0];
Expand All @@ -253,8 +253,8 @@ vec UpdateSimplex(vec *s, int &n)
float4d D03 = POINT_TO_FLOAT4(s[3]) - POINT_TO_FLOAT4(s[0]);
float4d tri013NormalD = D01.Cross(D03);
float4d tri023NormalD = D03.Cross(D02);
assert3(tri013NormalD.Dot(D02) <= 0.f, tri013NormalD, D02, tri013NormalD.Dot(D02));
assert3(tri023NormalD.Dot(D01) <= 0.f, tri023NormalD, D01, tri023NormalD.Dot(D01));
mgl_assert3(tri013NormalD.Dot(D02) <= 0.f, tri013NormalD, D02, tri013NormalD.Dot(D02));
mgl_assert3(tri023NormalD.Dot(D01) <= 0.f, tri023NormalD, D01, tri023NormalD.Dot(D01));
#endif

vec e03_1 = Cross(tri013Normal, d03); // The normal of edge 0->3 on triangle 013.
Expand All @@ -265,7 +265,7 @@ vec UpdateSimplex(vec *s, int &n)
{
// Case 6) Edge 0->3 is closest. Simplex degenerates to a line segment.
#ifdef MATH_ASSERT_CORRECTNESS
assert4(!insideSimplex && d[6] <= dist + 1e-3f * Max(1.0, d[6], dist), d[6], dist, insideSimplex, minDistIndex);
mgl_assert4(!insideSimplex && d[6] <= dist + 1e-3f * Max(1.0, d[6], dist), d[6], dist, insideSimplex, minDistIndex);
#endif
vec newDir = Cross(d03, Cross(d03, s[3]));
s[1] = s[3];
Expand All @@ -276,7 +276,7 @@ vec UpdateSimplex(vec *s, int &n)
vec d12 = s[2] - s[1];
vec d13 = s[3] - s[1];
vec tri123Normal = Cross(d12, d13);
assert(Dot(tri123Normal, -d02) <= 0.f);
mgl_assert(Dot(tri123Normal, -d02) <= 0.f);
vec e13_0 = Cross(d13, tri013Normal);
vec e13_2 = Cross(tri123Normal, d13);
float inE13_0 = Dot(e13_0, s[3]);
Expand All @@ -285,7 +285,7 @@ vec UpdateSimplex(vec *s, int &n)
{
// Case 8) Edge 1->3 is closest. Simplex degenerates to a line segment.
#ifdef MATH_ASSERT_CORRECTNESS
assert4(!insideSimplex && d[8] <= dist + 1e-3f * Max(1.0, d[8], dist), d[8], dist, insideSimplex, minDistIndex);
mgl_assert4(!insideSimplex && d[8] <= dist + 1e-3f * Max(1.0, d[8], dist), d[8], dist, insideSimplex, minDistIndex);
#endif
vec newDir = Cross(d13, Cross(d13, s[3]));
s[0] = s[1];
Expand All @@ -303,7 +303,7 @@ vec UpdateSimplex(vec *s, int &n)
{
// Case 9) Edge 2->3 is closest. Simplex degenerates to a line segment.
#ifdef MATH_ASSERT_CORRECTNESS
assert4(!insideSimplex && d[9] <= dist + 1e-3f * Max(1.0, d[9], dist), d[9], dist, insideSimplex, minDistIndex);
mgl_assert4(!insideSimplex && d[9] <= dist + 1e-3f * Max(1.0, d[9], dist), d[9], dist, insideSimplex, minDistIndex);
#endif
vec newDir = Cross(d23, Cross(d23, s[3]));
s[0] = s[2];
Expand All @@ -317,7 +317,7 @@ vec UpdateSimplex(vec *s, int &n)
{
// Case 11) Triangle 0->1->3 is closest.
#ifdef MATH_ASSERT_CORRECTNESS
assert4(!insideSimplex && d[11] <= dist + 1e-3f * Max(1.0, d[11], dist), d[11], dist, insideSimplex, minDistIndex);
mgl_assert4(!insideSimplex && d[11] <= dist + 1e-3f * Max(1.0, d[11], dist), d[11], dist, insideSimplex, minDistIndex);
#endif
s[2] = s[3];
n = 3;
Expand All @@ -328,7 +328,7 @@ vec UpdateSimplex(vec *s, int &n)
{
// Case 12) Triangle 0->2->3 is closest.
#ifdef MATH_ASSERT_CORRECTNESS
assert4(!insideSimplex && d[12] <= dist + 1e-3f * Max(1.0, d[12], dist), d[12], dist, insideSimplex, minDistIndex);
mgl_assert4(!insideSimplex && d[12] <= dist + 1e-3f * Max(1.0, d[12], dist), d[12], dist, insideSimplex, minDistIndex);
#endif
s[1] = s[0];
s[0] = s[2];
Expand All @@ -341,7 +341,7 @@ vec UpdateSimplex(vec *s, int &n)
{
// Case 13) Triangle 1->2->3 is closest.
#ifdef MATH_ASSERT_CORRECTNESS
assert4(!insideSimplex && d[13] <= dist + 1e-3f * Max(1.0, d[13], dist), d[13], dist, insideSimplex, minDistIndex);
mgl_assert4(!insideSimplex && d[13] <= dist + 1e-3f * Max(1.0, d[13], dist), d[13], dist, insideSimplex, minDistIndex);
#endif
s[0] = s[1];
s[1] = s[2];
Expand Down
8 changes: 4 additions & 4 deletions src/Algorithm/GJK.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,23 @@ bool GJKIntersect(const A &a, const B &b)
float maxS, minS;
vec newSupport = SUPPORT(d, minS, maxS);
#ifdef MATH_VEC_IS_FLOAT4
assume(newSupport.w == 0.f);
mgl_assume(newSupport.w == 0.f);
#endif
// If the most extreme point in that search direction did not walk past the origin, then the origin cannot be contained in the Minkowski
// convex shape, and the two convex objects a and b do not share a common point - no intersection!
if (minS + maxS < 0.f)
return false;
// Add the newly evaluated point to the search simplex.
assert(n < 4);
mgl_assert(n < 4);
support[n++] = newSupport;
// Examine the current simplex, prune a redundant part of it, and produce the next search direction.
d = UpdateSimplex(support, n);
if (n == 0) // Was the origin contained in the current simplex? If so, then the convex shapes a and b do share a common point - intersection!
return true;
}
assume(false && "GJK intersection test did not converge to a result!");
mgl_assume(false && "GJK intersection test did not converge to a result!");
// TODO: enable
//assume2(false && "GJK intersection test did not converge to a result!", a.SerializeToString(), b.SerializeToString());
//mgl_assume2(false && "GJK intersection test did not converge to a result!", a.SerializeToString(), b.SerializeToString());
return false; // Report no intersection.
}

Expand Down
26 changes: 13 additions & 13 deletions src/Algorithm/GJK2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ MATH_BEGIN_NAMESPACE
@return The new search direction vector. */
vec2d UpdateSimplex2D(vec2d *s, int &n)
{
assert1(n == 2 || n == 3, n);
mgl_assert1(n == 2 || n == 3, n);

if (n == 2)
{
Expand All @@ -50,12 +50,12 @@ vec2d UpdateSimplex2D(vec2d *s, int &n)
float d0 = s[0].DistanceSq(vec2d::zero);
float d1 = s[1].DistanceSq(vec2d::zero);
float d2 = LineSegment2D(s[0], s[1]).DistanceSq(vec2d::zero);
assert2(d2 <= d0, d2, d0);
assert2(d2 <= d1, d2, d1);
mgl_assert2(d2 <= d0, d2, d0);
mgl_assert2(d2 <= d1, d2, d1);
// Cannot be in case 0: the step 0 -> 1 must have been toward the zero direction:
assert(Dot(s[1]-s[0], -s[0]) >= 0.f);
mgl_assert(Dot(s[1]-s[0], -s[0]) >= 0.f);
// Cannot be in case 1: the zero direction cannot be in the voronoi region of vertex s[1].
assert(Dot(s[1]-s[0], -s[1]) <= 0.f);
mgl_assert(Dot(s[1]-s[0], -s[1]) <= 0.f);
#endif

vec2d d01 = s[1] - s[0];
Expand All @@ -73,7 +73,7 @@ vec2d UpdateSimplex2D(vec2d *s, int &n)
}
else
{
assert(n == 3);
mgl_assert(n == 3);
// Seven voronoi regions:
// 0) closest to vertex s[0].
// 1) closest to vertex s[1].
Expand Down Expand Up @@ -109,10 +109,10 @@ vec2d UpdateSimplex2D(vec2d *s, int &n)
minDistIndex = i;
}

assert4(isContainedInTriangle || dist <= d[0] + 1e-4f, d[0], dist, isContainedInTriangle, minDistIndex);
assert4(isContainedInTriangle || dist <= d[1] + 1e-4f, d[1], dist, isContainedInTriangle, minDistIndex);
assert4(isContainedInTriangle || dist <= d[2] + 1e-4f, d[2], dist, isContainedInTriangle, minDistIndex);
assert4(isContainedInTriangle || dist <= d[3] + 1e-4f, d[3], dist, isContainedInTriangle, minDistIndex);
mgl_assert4(isContainedInTriangle || dist <= d[0] + 1e-4f, d[0], dist, isContainedInTriangle, minDistIndex);
mgl_assert4(isContainedInTriangle || dist <= d[1] + 1e-4f, d[1], dist, isContainedInTriangle, minDistIndex);
mgl_assert4(isContainedInTriangle || dist <= d[2] + 1e-4f, d[2], dist, isContainedInTriangle, minDistIndex);
mgl_assert4(isContainedInTriangle || dist <= d[3] + 1e-4f, d[3], dist, isContainedInTriangle, minDistIndex);
#endif
vec2d d12 = s[2]-s[1];
vec2d d02 = s[2]-s[0];
Expand All @@ -124,7 +124,7 @@ vec2d UpdateSimplex2D(vec2d *s, int &n)
{
// Case 4: Edge 1->2 is closest.
#ifdef MATH_ASSERT_CORRECTNESS
assert4(d[4] <= dist + 1e-3f * Max(1.f, d[4], dist), d[4], dist, isContainedInTriangle, minDistIndex);
mgl_assert4(d[4] <= dist + 1e-3f * Max(1.f, d[4], dist), d[4], dist, isContainedInTriangle, minDistIndex);
#endif
vec2d newDir = e12;
s[0] = s[1];
Expand All @@ -139,7 +139,7 @@ vec2d UpdateSimplex2D(vec2d *s, int &n)
{
// Case 5: Edge 0->2 is closest.
#ifdef MATH_ASSERT_CORRECTNESS
assert4(d[5] <= dist + 1e-3f * Max(1.f, d[5], dist), d[5], dist, isContainedInTriangle, minDistIndex);
mgl_assert4(d[5] <= dist + 1e-3f * Max(1.f, d[5], dist), d[5], dist, isContainedInTriangle, minDistIndex);
#endif
vec2d newDir = e02;
s[1] = s[2];
Expand All @@ -148,7 +148,7 @@ vec2d UpdateSimplex2D(vec2d *s, int &n)
}
// Case 6) The origin lies directly inside the triangle. For robustness, terminate the search here immediately with success.
#ifdef MATH_ASSERT_CORRECTNESS
assert4(d[6] <= dist + 1e-3f * Max(1.f, d[6], dist), d[6], dist, isContainedInTriangle, minDistIndex);
mgl_assert4(d[6] <= dist + 1e-3f * Max(1.f, d[6], dist), d[6], dist, isContainedInTriangle, minDistIndex);
#endif
n = 0;
return vec2d::zero;
Expand Down
10 changes: 5 additions & 5 deletions src/Algorithm/GJK2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,24 @@ bool GJKIntersect2D(const A &a, const B &b)
float maxS, minS;
vec2d newSupport = SUPPORT2D(d, minS, maxS);
#ifdef MATH_VEC_IS_FLOAT4
assume(newSupport.z == 0.f);
assume(newSupport.w == 0.f);
mgl_assume(newSupport.z == 0.f);
mgl_assume(newSupport.w == 0.f);
#endif
// If the most extreme point in that search direction did not walk past the origin, then the origin cannot be contained in the Minkowski
// convex shape, and the two convex objects a and b do not share a common point - no intersection!
if (minS + maxS < 0.f)
return false;
// Add the newly evaluated point to the search simplex.
assert(n < 3);
mgl_assert(n < 3);
support[n++] = newSupport;
// Examine the current simplex, prune a redundant part of it, and produce the next search direction.
d = UpdateSimplex2D(support, n);
if (n == 0) // Was the origin contained in the current simplex? If so, then the convex shapes a and b do share a common point - intersection!
return true;
}
assume(false && "GJK2D intersection test did not converge to a result!");
mgl_assume(false && "GJK2D intersection test did not converge to a result!");
// TODO: enable this on Polygon2DRef
// assume2(false && "GJK2D intersection test did not converge to a result!", a.SerializeToString(), b.SerializeToString());
// mgl_assume2(false && "GJK2D intersection test did not converge to a result!", a.SerializeToString(), b.SerializeToString());
return false; // Report no intersection.
}

Expand Down
Loading