removeDuplicatedPoints method
dynamic
removeDuplicatedPoints(
- dynamic points
Implementation
removeDuplicatedPoints(points) {
// Creates a new array if necessary with duplicated points removed.
// This does not remove duplicated initial and ending points of a closed path.
var dupPoints = false;
for (var i = 1, n = points.length - 1; i < n; i++) {
if (points[i].distanceTo(points[i + 1]) < minDistance) {
dupPoints = true;
break;
}
}
if (!dupPoints) return points;
var newPoints = [];
newPoints.add(points[0]);
for (var i = 1, n = points.length - 1; i < n; i++) {
if (points[i].distanceTo(points[i + 1]) >= minDistance) {
newPoints.add(points[i]);
}
}
newPoints.add(points[points.length - 1]);
return newPoints;
}