Recast: remove all duplicate epsilon definitions

Make a constant in the math library.
This commit is contained in:
Kawe Mazidjatari 2024-07-18 19:00:53 +02:00
parent 5ec7862b71
commit f170e2b6f3
9 changed files with 16 additions and 22 deletions

View File

@ -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])

View File

@ -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])

View File

@ -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])

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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])
{

View File

@ -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); }

View File

@ -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;