From c04aa735ff82377395669bfee30a90aa60c07d5f Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Fri, 12 Jul 2024 21:39:45 +0200 Subject: [PATCH] Recast: code deduplication Use new function introduced in commit 2f9776d495f6a5c7bedccc3566b81d41d28e09f6. --- .../Detour/Source/DetourNavMeshQuery.cpp | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/thirdparty/recast/Detour/Source/DetourNavMeshQuery.cpp b/src/thirdparty/recast/Detour/Source/DetourNavMeshQuery.cpp index 6c616207..f24a0464 100644 --- a/src/thirdparty/recast/Detour/Source/DetourNavMeshQuery.cpp +++ b/src/thirdparty/recast/Detour/Source/DetourNavMeshQuery.cpp @@ -263,14 +263,7 @@ dtStatus dtNavMeshQuery::findRandomPoint(const dtQueryFilter* filter, float (*fr continue; // Calc area of the polygon. - float polyArea = 0.0f; - for (int j = 2; j < p->vertCount; ++j) - { - const float* va = &tile->verts[p->verts[0]*3]; - const float* vb = &tile->verts[p->verts[j]*3]; - const float* vc = &tile->verts[p->verts[j-1]*3]; - polyArea += dtTriArea2D(va,vb,vc); - } + const float polyArea = dtCalcPolyArea(p, tile->verts); // Choose random polygon weighted by area, using reservoir sampling. areaSum += polyArea; @@ -371,14 +364,8 @@ dtStatus dtNavMeshQuery::findRandomPointAroundCircle(dtPolyRef startRef, const f if (bestPoly->getType() == DT_POLYTYPE_GROUND) { // Calc area of the polygon. - float polyArea = 0.0f; - for (int j = 2; j < bestPoly->vertCount; ++j) - { - const float* va = &bestTile->verts[bestPoly->verts[0]*3]; - const float* vb = &bestTile->verts[bestPoly->verts[j]*3]; - const float* vc = &bestTile->verts[bestPoly->verts[j-1]*3]; - polyArea += dtTriArea2D(va,vb,vc); - } + const float polyArea = dtCalcPolyArea(bestPoly, bestTile->verts); + // Choose random polygon weighted by area, using reservoir sampling. areaSum += polyArea; const float u = frand();