From 5d91c09e00accece14e7105864e0d587f1932cc9 Mon Sep 17 00:00:00 2001 From: Mikko Mononen Date: Thu, 8 Jul 2010 14:38:53 +0000 Subject: [PATCH] fix for Issue 94:rcBuildContours fails when small area is marked near tile edge --- Recast/Source/RecastContour.cpp | 43 +++++++++++++++++---------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/Recast/Source/RecastContour.cpp b/Recast/Source/RecastContour.cpp index b356e9c..632c18f 100644 --- a/Recast/Source/RecastContour.cpp +++ b/Recast/Source/RecastContour.cpp @@ -231,17 +231,36 @@ static void simplifyContour(rcIntArray& points, rcIntArray& simplified, const float maxError, const int maxEdgeLen, const int buildFlags) { // Add initial points. - bool noConnections = true; + bool hasConnections = false; for (int i = 0; i < points.size(); i += 4) { if ((points[i+3] & RC_CONTOUR_REG_MASK) != 0) { - noConnections = false; + hasConnections = true; break; } } - if (noConnections) + if (hasConnections) + { + // The contour has some portals to other regions. + // Add a new point to every location where the region changes. + for (int i = 0, ni = points.size()/4; i < ni; ++i) + { + int ii = (i+1) % ni; + const bool differentRegs = (points[i*4+3] & RC_CONTOUR_REG_MASK) != (points[ii*4+3] & RC_CONTOUR_REG_MASK); + const bool areaBorders = (points[i*4+3] & RC_AREA_BORDER) != (points[ii*4+3] & RC_AREA_BORDER); + if (differentRegs || areaBorders) + { + simplified.push(points[i*4+0]); + simplified.push(points[i*4+1]); + simplified.push(points[i*4+2]); + simplified.push(i); + } + } + } + + if (simplified.size() == 0) { // If there is no connections at all, // create some initial points for the simplification process. @@ -284,24 +303,6 @@ static void simplifyContour(rcIntArray& points, rcIntArray& simplified, simplified.push(urz); simplified.push(uri); } - else - { - // The contour has some portals to other regions. - // Add a new point to every location where the region changes. - for (int i = 0, ni = points.size()/4; i < ni; ++i) - { - int ii = (i+1) % ni; - const bool differentRegs = (points[i*4+3] & RC_CONTOUR_REG_MASK) != (points[ii*4+3] & RC_CONTOUR_REG_MASK); - const bool areaBorders = (points[i*4+3] & RC_AREA_BORDER) != (points[ii*4+3] & RC_AREA_BORDER); - if (differentRegs || areaBorders) - { - simplified.push(points[i*4+0]); - simplified.push(points[i*4+1]); - simplified.push(points[i*4+2]); - simplified.push(i); - } - } - } // Add points until all raw points are within // error tolerance to the simplified shape.