diff --git a/src/thirdparty/recast/Shared/Include/SharedCommon.h b/src/thirdparty/recast/Shared/Include/SharedCommon.h index 548754c5..b7328171 100644 --- a/src/thirdparty/recast/Shared/Include/SharedCommon.h +++ b/src/thirdparty/recast/Shared/Include/SharedCommon.h @@ -488,6 +488,15 @@ void rdCalcEdgeNormal2D(const float* dir, const bool inner, float* out); /// @param[out] out The resulting normal. [(x, y)] void rdCalcEdgeNormalPt2D(const float* v1, const float* v2, const bool inner, float* out); +/// @param[in] edgeStart First vert of the polygon edge. [(x, y, z)] +/// @param[in] edgeEnd Second vert of the polygon edge. [(x, y, z)] +/// @param[in] subEdgeStart First vert of the detail edge. [(x, y, z)] +/// @param[in] subEdgeEnd Second vert of the detail edge. [(x, y, z)] +/// @param[out] tmin The normalized distance ratio from polygon edge start to detail edge start. +/// @param[out] tmax The normalized distance ratio from polygon edge start to detail edge end. +bool rdCalcSubEdgeArea2D(const float* edgeStart, const float* edgeEnd, const float* subEdgeStart, + const float* subEdgeEnd, float& tmin, float& tmax); + /// Derives the maximum angle in which an object on an elevated surface can be seen from below. /// @param[in] ledgeSpan The distance between the edge of the object and the edge of the ledge. /// @param[in] objectHeight The height of the object. diff --git a/src/thirdparty/recast/Shared/Source/SharedCommon.cpp b/src/thirdparty/recast/Shared/Source/SharedCommon.cpp index b2f3c6c9..a8821816 100644 --- a/src/thirdparty/recast/Shared/Source/SharedCommon.cpp +++ b/src/thirdparty/recast/Shared/Source/SharedCommon.cpp @@ -432,6 +432,28 @@ void rdCalcEdgeNormalPt2D(const float* v1, const float* v2, const bool invert, f rdCalcEdgeNormal2D(dir, invert, out); } +bool rdCalcSubEdgeArea2D(const float* edgeStart, const float* edgeEnd, const float* subEdgeStart, + const float* subEdgeEnd, float& tmin, float& tmax) +{ + const float edgeLen = rdVdist2D(edgeStart, edgeEnd); + const float subEdgeStartDist = rdVdist2D(edgeStart, subEdgeStart); + const float subEdgeEndDist = rdVdist2D(edgeStart, subEdgeEnd); + + tmin = subEdgeStartDist / edgeLen; + tmax = subEdgeEndDist / edgeLen; + + // note(amos): If the min is larger than the max, we most likely have a + // malformed detail polygon, e.g. a triangle that is flipped causing its + // boundary edge's start vert to be closer to the end vert of the polygon + // when comparing the distances in the same winding order. This can happen + // on more complex geometry or when the error tollerance is raised. Either + // way return false to notify caller that the calculation has failed. + if (tmin > tmax) + return false; + + return true; +} + float rdCalcMaxLOSAngle(const float ledgeSpan, const float objectHeight) { const float angleRad = rdMathAtan2f(objectHeight, ledgeSpan);