Skip to content

Commit

Permalink
Simplify code from paperjs#971 and activate unit test for it again.
Browse files Browse the repository at this point in the history
  • Loading branch information
lehni committed Feb 14, 2016
1 parent 4c72d98 commit 8d5c922
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 25 deletions.
35 changes: 11 additions & 24 deletions src/path/PathItem.Boolean.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,7 @@ PathItem.inject(new function() {
// Separately count the windings for points on curves.
windLeftOnCurve = 0,
windRightOnCurve = 0,
isOnCurve = false,
// Use the winding at the leftmost intersection to determine
// the orientation of the loop (clockwise / anti-clockwise).
leftIntersVal;
isOnCurve = false;
for (var i = 0; i < length; i++) {
var curve = curves[i],
winding = curve.winding,
Expand All @@ -362,10 +359,8 @@ PathItem.inject(new function() {
// non-horizontal curve for the first curve in the loop.
prevWinding = curve.last.winding;
prevXEnd = curve.last.values[6];
// Reset the on curve flag and the leftmost intersection
// values for each loop.
// Reset the on curve flag for each loop.
isOnCurve = false;
leftIntersVal = null;
}
// Since the curves are monotonic in y direction, we can just
// compare the endpoints of the curve to determine if the ray
Expand Down Expand Up @@ -411,25 +406,17 @@ PathItem.inject(new function() {
isOnCurve = true;
}
}
// If we are at the end of a loop and the point was on a curve of the
// loop, we increment / decrement the on-curve winding numbers as if
// the point was inside the path.
if (i == length - 1 || curves[i + 1].last) {
if (isOnCurve) {
if (leftIntersVal && leftIntersVal[1] < 0) {
windLeftOnCurve -= 1;
windRightOnCurve += 1;
} else {
windLeftOnCurve += 1;
windRightOnCurve -= 1;
}
}
// If we are at the end of a loop and the point was on a curve
// of the loop, we increment / decrement the on-curve winding
// numbers as if the point was inside the path.
if (isOnCurve && (i >= length - 1 || curves[i + 1].last)) {
windLeftOnCurve += 1;
windRightOnCurve -= 1;
}
}
// Use the on-curve windings if no other intersections were
// found or if they canceled each other. On single paths
// this ensures that the overally winding is 1 if the
// point was on a monotonic curve.
// Use the on-curve windings if no other intersections were found or
// if they canceled each other. On single paths this ensures that
// the overall winding is 1 if the point was on a monotonic curve.
if (windLeft === 0 && windRight === 0) {
windLeft = windLeftOnCurve;
windRight = windRightOnCurve;
Expand Down
1 change: 0 additions & 1 deletion test/tests/Path_Boolean.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,6 @@ test('#958', function() {
});

test('#968', function(assert) {
return assert.expect(0);
var p1 = new paper.Path({
segments: [
[352, 280, 0, -26.5, 0, 0],
Expand Down

0 comments on commit 8d5c922

Please sign in to comment.