Skip to content

Commit

Permalink
Merge pull request #1512 from VisActor/fix/simplify
Browse files Browse the repository at this point in the history
fix: 注释掉点优化中的Ramer-Douglas-Peucker算法
  • Loading branch information
neuqzxy authored Oct 30, 2024
2 parents f425014 + 2adef9c commit 7266724
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vrender-core",
"comment": "fix: annotate the Ramer Douglas Peucker algorithm in point optimization",
"type": "none"
}
],
"packageName": "@visactor/vrender-core"
}
6 changes: 4 additions & 2 deletions packages/vrender-core/src/common/simplify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,14 @@ function simplifyDPStep(
nextIdx = i;
}
}

if (maxSqDist > sqTolerance) {
if (nextIdx - startIdx > 2) {
simplifyDPStep(points, startIdx, nextIdx, sqTolerance, simplified);
}
simplified.push(points[nextIdx], points[nextIdx + 1]);
if (endIdx - nextIdx > 2) {
simplifyDPStep(points, nextIdx, endIdx, sqTolerance, simplified);
simplifyDPStep(points, nextIdx + 1, endIdx, sqTolerance, simplified);
}
}
}
Expand All @@ -88,6 +89,7 @@ export function flatten_simplify(points: IPointLike[], tolerance: number, highes
}
const sqTolerance = tolerance !== undefined ? tolerance * tolerance : 1;
points = highestQuality ? points : simplifyRadialDist(points, sqTolerance);
points = simplifyDouglasPeucker(points, sqTolerance);
// 暂时屏蔽 Douglas-Peucker 算法, 因为在极端情况下不会有点被删除, 导致性能问题
// points = simplifyDouglasPeucker(points, sqTolerance);
return points;
}

0 comments on commit 7266724

Please sign in to comment.