Minor clean up in Curve.filterIntersections().

This commit is contained in:
Jürg Lehni 2015-01-04 17:47:41 +01:00
parent f0d28d7529
commit 1239eb55ec

View file

@ -1408,11 +1408,11 @@ new function() { // Scope for methods that require numerical integration
}, },
filterIntersections: function(locations, _expand) { filterIntersections: function(locations, _expand) {
var max = locations.length - 1, var last = locations.length - 1,
tMax = 1 - /*#=*/Numerical.TOLERANCE; tMax = 1 - /*#=*/Numerical.TOLERANCE;
// Merge intersections very close to the end of a curve to the // Merge intersections very close to the end of a curve to the
// beginning of the next curve. // beginning of the next curve.
for (var i = max; i >= 0; i--) { for (var i = last; i >= 0; i--) {
var loc = locations[i], var loc = locations[i],
next = loc._curve.getNext(), next = loc._curve.getNext(),
next2 = loc._curve2.getNext(); next2 = loc._curve2.getNext();
@ -1439,18 +1439,18 @@ new function() { // Scope for methods that require numerical integration
: path1._id - path2._id; : path1._id - path2._id;
} }
if (max > 0) { if (last > 0) {
locations.sort(compare); locations.sort(compare);
// Filter out duplicate locations // Filter out duplicate locations.
for (var i = max; i >= 1; i--) { for (var i = last; i > 0; i--) {
if (locations[i].equals(locations[i === 0 ? max : i - 1])) { if (locations[i].equals(locations[i - 1])) {
locations.splice(i, 1); locations.splice(i, 1);
max--; last--;
} }
} }
} }
if (_expand) { if (_expand) {
for (var i = max; i >= 0; i--) for (var i = last; i >= 0; i--)
locations.push(locations[i].getIntersection()); locations.push(locations[i].getIntersection());
locations.sort(compare); locations.sort(compare);
} }