diff --git a/src/thirdparty/recast/Shared/Include/SharedCommon.h b/src/thirdparty/recast/Shared/Include/SharedCommon.h index 0b9fbba3..72f20165 100644 --- a/src/thirdparty/recast/Shared/Include/SharedCommon.h +++ b/src/thirdparty/recast/Shared/Include/SharedCommon.h @@ -433,6 +433,7 @@ bool rdIntersectSegSeg2D(const float* ap, const float* aq, float rdDistancePtLine2d(const float* pt, const float* p, const float* q); unsigned char rdClassifyPointOutsideBounds(const float* pt, const float* bmin, const float* bmax); +unsigned char rdClassifyPointInsideBounds(const float* pt, const float* bmin, const float* bmax); /// Determines if the specified point is inside the convex polygon on the xy-plane. /// @param[in] pt The point to check. [(x, y, z)] diff --git a/src/thirdparty/recast/Shared/Source/SharedCommon.cpp b/src/thirdparty/recast/Shared/Source/SharedCommon.cpp index 87211900..418256f7 100644 --- a/src/thirdparty/recast/Shared/Source/SharedCommon.cpp +++ b/src/thirdparty/recast/Shared/Source/SharedCommon.cpp @@ -436,3 +436,51 @@ unsigned char rdClassifyPointOutsideBounds(const float* pt, const float* bmin, c return 0xff; } + +unsigned char rdClassifyPointInsideBounds(const float* pt, const float* bmin, const float* bmax) +{ + const float distXP = rdMathFabsf(pt[0]-bmax[0]); + const float distXM = rdMathFabsf(pt[0]-bmin[0]); + const float distZP = rdMathFabsf(pt[1]-bmax[1]); + const float distZM = rdMathFabsf(pt[1]-bmin[1]); + + unsigned char outcode = XP; + float minDist = distXP; + + // Determine closest. + if (distZP < minDist) + { + minDist = distZP; + outcode = ZP; + } + if (distXM < minDist) + { + minDist = distXM; + outcode = XM; + } + if (distZM < minDist) + { + minDist = distZM; + outcode = ZM; + } + + // Diagonal cases. + if (rdMathFabsf(distXP-minDist) < RD_EPS && outcode != XP) outcode |= XP; + if (rdMathFabsf(distXM-minDist) < RD_EPS && outcode != XM) outcode |= XM; + if (rdMathFabsf(distZP-minDist) < RD_EPS && outcode != ZP) outcode |= ZP; + if (rdMathFabsf(distZM-minDist) < RD_EPS && outcode != ZM) outcode |= ZM; + + switch (outcode) + { + case XP: return 0; + case XP|ZP: return 1; + case ZP: return 2; + case XM|ZP: return 3; + case XM: return 4; + case XM|ZM: return 5; + case ZM: return 6; + case XP|ZM: return 7; + } + + return 0xff; +}