From f170e2b6f3f5804562cd3c73602368e38d6d2085 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Thu, 18 Jul 2024 19:00:53 +0200 Subject: [PATCH] Recast: remove all duplicate epsilon definitions Make a constant in the math library. --- src/naveditor/ChunkyTriMesh.cpp | 5 ++--- src/naveditor/CrowdTool.cpp | 4 +--- src/naveditor/Editor_TempObstacles.cpp | 4 +--- src/naveditor/InputGeom.cpp | 4 +--- .../recast/DetourCrowd/Source/DetourObstacleAvoidance.cpp | 2 +- src/thirdparty/recast/Recast/Source/RecastArea.cpp | 6 +++--- src/thirdparty/recast/Recast/Source/RecastMeshDetail.cpp | 5 ++--- src/thirdparty/recast/Shared/Include/SharedMath.h | 3 +++ src/thirdparty/recast/Shared/Source/SharedCommon.cpp | 5 ++--- 9 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/naveditor/ChunkyTriMesh.cpp b/src/naveditor/ChunkyTriMesh.cpp index 2c0946e6..84fd2ec3 100644 --- a/src/naveditor/ChunkyTriMesh.cpp +++ b/src/naveditor/ChunkyTriMesh.cpp @@ -16,6 +16,7 @@ // 3. This notice may not be removed or altered from any source distribution. // +#include "Shared/Include/SharedMath.h" #include "NavEditor/Include/ChunkyTriMesh.h" struct BoundsItem @@ -280,8 +281,6 @@ int rcGetChunksOverlappingRect(const rcChunkyTriMesh * cm, float bmin[2], float static bool checkOverlapSegment(const float p[2], const float q[2], const float bmin[2], const float bmax[2]) { - static const float EPSILON = 1e-6f; - float tmin = 0; float tmax = 1; float d[2]; @@ -290,7 +289,7 @@ static bool checkOverlapSegment(const float p[2], const float q[2], for (int i = 0; i < 2; i++) { - if (fabsf(d[i]) < EPSILON) + if (fabsf(d[i]) < RD_EPS) { // Ray is parallel to slab. No hit if origin not within slab if (p[i] < bmin[i] || p[i] > bmax[i]) diff --git a/src/naveditor/CrowdTool.cpp b/src/naveditor/CrowdTool.cpp index f2de2a7c..7ac9a1ff 100644 --- a/src/naveditor/CrowdTool.cpp +++ b/src/naveditor/CrowdTool.cpp @@ -31,8 +31,6 @@ static bool isectSegAABB(const float* sp, const float* sq, const float* amin, const float* amax, float& tmin, float& tmax) { - static const float EPS = 1e-6f; - float d[3]; rdVsub(d, sq, sp); tmin = 0; // set to -FLT_MAX to get first hit on line @@ -41,7 +39,7 @@ static bool isectSegAABB(const float* sp, const float* sq, // For all three slabs for (int i = 0; i < 3; i++) { - if (fabsf(d[i]) < EPS) + if (fabsf(d[i]) < RD_EPS) { // Ray is parallel to slab. No hit if origin not within slab if (sp[i] < amin[i] || sp[i] > amax[i]) diff --git a/src/naveditor/Editor_TempObstacles.cpp b/src/naveditor/Editor_TempObstacles.cpp index 06870eaf..4e01d73f 100644 --- a/src/naveditor/Editor_TempObstacles.cpp +++ b/src/naveditor/Editor_TempObstacles.cpp @@ -42,8 +42,6 @@ static bool isectSegAABB(const float* sp, const float* sq, const float* amin, const float* amax, float& tmin, float& tmax) { - static const float EPS = 1e-6f; - float d[3]; rdVsub(d, sq, sp); tmin = 0; // set to -FLT_MAX to get first hit on line @@ -52,7 +50,7 @@ static bool isectSegAABB(const float* sp, const float* sq, // For all three slabs for (int i = 0; i < 3; i++) { - if (fabsf(d[i]) < EPS) + if (fabsf(d[i]) < RD_EPS) { // Ray is parallel to slab. No hit if origin not within slab if (sp[i] < amin[i] || sp[i] > amax[i]) diff --git a/src/naveditor/InputGeom.cpp b/src/naveditor/InputGeom.cpp index 84fb50c2..31a582d7 100644 --- a/src/naveditor/InputGeom.cpp +++ b/src/naveditor/InputGeom.cpp @@ -459,8 +459,6 @@ static bool isectSegAABB(const float* sp, const float* sq, const float* amin, const float* amax, float& tmin, float& tmax) { - static const float EPS = 1e-6f; - float d[3]; d[0] = sq[0] - sp[0]; d[1] = sq[1] - sp[1]; @@ -470,7 +468,7 @@ static bool isectSegAABB(const float* sp, const float* sq, for (int i = 0; i < 3; i++) { - if (fabsf(d[i]) < EPS) + if (rdMathFabsf(d[i]) < RD_EPS) { if (sp[i] < amin[i] || sp[i] > amax[i]) return false; diff --git a/src/thirdparty/recast/DetourCrowd/Source/DetourObstacleAvoidance.cpp b/src/thirdparty/recast/DetourCrowd/Source/DetourObstacleAvoidance.cpp index b5af51dc..40929b4b 100644 --- a/src/thirdparty/recast/DetourCrowd/Source/DetourObstacleAvoidance.cpp +++ b/src/thirdparty/recast/DetourCrowd/Source/DetourObstacleAvoidance.cpp @@ -53,7 +53,7 @@ static int isectRaySeg(const float* ap, const float* u, rdVsub(v,bq,bp); rdVsub(w,ap,bp); float d = rdVperp2D(u,v); - if (rdMathFabsf(d) < 1e-6f) return 0; + if (rdMathFabsf(d) < RD_EPS) return 0; d = 1.0f/d; t = rdVperp2D(v,w) * d; if (t < 0 || t > 1) return 0; diff --git a/src/thirdparty/recast/Recast/Source/RecastArea.cpp b/src/thirdparty/recast/Recast/Source/RecastArea.cpp index fbf4f2a0..bffed99f 100644 --- a/src/thirdparty/recast/Recast/Source/RecastArea.cpp +++ b/src/thirdparty/recast/Recast/Source/RecastArea.cpp @@ -455,7 +455,7 @@ int rcOffsetPoly(const float* verts, const int nverts, const float offset, float dx0 = vb[0] - va[0]; float dy0 = vb[1] - va[1]; float d0 = dx0*dx0 + dy0*dy0; - if (d0 > 1e-6f) + if (d0 > RD_EPS) { d0 = 1.0f/rdMathSqrtf(d0); dx0 *= d0; @@ -464,7 +464,7 @@ int rcOffsetPoly(const float* verts, const int nverts, const float offset, float dx1 = vc[0] - vb[0]; float dy1 = vc[1] - vb[1]; float d1 = dx1*dx1 + dy1*dy1; - if (d1 > 1e-6f) + if (d1 > RD_EPS) { d1 = 1.0f/rdMathSqrtf(d1); dx1 *= d1; @@ -479,7 +479,7 @@ int rcOffsetPoly(const float* verts, const int nverts, const float offset, float dmy = (dly0 + dly1) * 0.5f; float dmr2 = dmx*dmx + dmy*dmy; bool bevel = dmr2 * MITER_LIMIT*MITER_LIMIT < 1.0f; - if (dmr2 > 1e-6f) + if (dmr2 > RD_EPS) { const float scale = 1.0f / dmr2; dmx *= scale; diff --git a/src/thirdparty/recast/Recast/Source/RecastMeshDetail.cpp b/src/thirdparty/recast/Recast/Source/RecastMeshDetail.cpp index de052b1c..4343dc4d 100644 --- a/src/thirdparty/recast/Recast/Source/RecastMeshDetail.cpp +++ b/src/thirdparty/recast/Recast/Source/RecastMeshDetail.cpp @@ -43,7 +43,6 @@ inline float vcross2(const float* p1, const float* p2, const float* p3) static bool circumCircle(const float* p1, const float* p2, const float* p3, float* c, float& r) { - static const float EPS = 1e-6f; // Calculate the circle relative to p1, to avoid some precision issues. const float v1[3] = {0,0,0}; float v2[3], v3[3]; @@ -51,7 +50,7 @@ static bool circumCircle(const float* p1, const float* p2, const float* p3, rdVsub(v3, p3,p1); const float cp = vcross2(v1, v2, v3); - if (rdMathFabsf(cp) > EPS) + if (rdMathFabsf(cp) > RD_EPS) { const float v1Sq = rdVdot2D(v1,v1); const float v2Sq = rdVdot2D(v2,v2); @@ -793,7 +792,7 @@ static bool buildPolyDetail(rcContext* ctx, const float* in, const int nin, bool swapped = false; // Make sure the segments are always handled in same order // using lexological sort or else there will be seams. - if (rdMathFabsf(vj[0]-vi[0]) < 1e-6f) + if (rdMathFabsf(vj[0]-vi[0]) < RD_EPS) { if (vj[1] > vi[1]) { diff --git a/src/thirdparty/recast/Shared/Include/SharedMath.h b/src/thirdparty/recast/Shared/Include/SharedMath.h index b60bfd2c..4c96d3e9 100644 --- a/src/thirdparty/recast/Shared/Include/SharedMath.h +++ b/src/thirdparty/recast/Shared/Include/SharedMath.h @@ -12,6 +12,9 @@ Members in this module are wrappers around the standard math library /// The value of PI used by Recast & Detour. static const float RD_PI = 3.14159265f; +/// The value of Epsilon used by Recast & Detour. +static const float RD_EPS = 1e-6f; + inline float rdMathFabsf(float x) { return fabsf(x); } inline float rdMathSqrtf(float x) { return sqrtf(x); } inline float rdMathFloorf(float x) { return floorf(x); } diff --git a/src/thirdparty/recast/Shared/Source/SharedCommon.cpp b/src/thirdparty/recast/Shared/Source/SharedCommon.cpp index 8ec94f09..1b11c2b7 100644 --- a/src/thirdparty/recast/Shared/Source/SharedCommon.cpp +++ b/src/thirdparty/recast/Shared/Source/SharedCommon.cpp @@ -203,7 +203,6 @@ void rdCalcPolyCenter(float* tc, const unsigned short* idx, int nidx, const floa bool rdClosestHeightPointTriangle(const float* p, const float* a, const float* b, const float* c, float& h) { - const float EPS = 1e-6f; float v0[3], v1[3], v2[3]; rdVsub(v0, c, a); @@ -212,7 +211,7 @@ bool rdClosestHeightPointTriangle(const float* p, const float* a, const float* b // Compute scaled barycentric coordinates float denom = v0[0] * v1[1] - v0[1] * v1[0]; - if (rdMathFabsf(denom) < EPS) + if (rdMathFabsf(denom) < RD_EPS) return false; float u = v1[1] * v2[0] - v1[0] * v2[1]; @@ -377,7 +376,7 @@ bool rdIntersectSegSeg2D(const float* ap, const float* aq, rdVsub(v,bq,bp); rdVsub(w,ap,bp); float d = rdVperp2D(u,v); - if (rdMathFabsf(d) < 1e-6f) return false; + if (rdMathFabsf(d) < RD_EPS) return false; s = rdVperp2D(v,w) / d; t = rdVperp2D(u,w) / d; return true;