From 55909b8bd5d267cdb0338277ba32094d2b0d4544 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Fri, 5 Feb 2016 19:43:48 +0100 Subject: [PATCH] Some code cleanup for winding-fix. --- src/path/PathItem.Boolean.js | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/path/PathItem.Boolean.js b/src/path/PathItem.Boolean.js index a1c48959..343415f2 100644 --- a/src/path/PathItem.Boolean.js +++ b/src/path/PathItem.Boolean.js @@ -380,23 +380,21 @@ PathItem.inject(new function() { ? Curve.getPoint(values, roots[0]).x : null; if (x != null) { - // determine if the point is on the horizontal - // connection between the last non-horizontal curve's - // end point and the current curve's start point - var isOnHorizontal = - (py === yStart && (px - x) * (px - prevXEnd) < 0); - // Test if the point is on the current monocurve + // Test if the point is on the current mono-curve. if (x >= xBefore && x <= xAfter) { isOnCurve = true; - // Count the intersection of the ray with the - // monotonic curve if: - // - the crossing is not the start of the curve - // except if the winding changes. - // - and the point is not on the curve or on the - // horizontal connection between the previous - // curve and the current curve - } else if ((py != yStart || winding !== prevWinding) - && !isOnHorizontal) { + } else if ( + // Count the intersection of the ray with the + // monotonic curve if the crossing is not the + // start of the curve, except if the winding + // changes... + (py !== yStart || winding !== prevWinding) + // ...and the point is not on the curve or on + // the horizontal connection between the last + // non-horizontal curve's end point and the + // current curve's start point. + && !(py === yStart + && (px - x) * (px - prevXEnd) < 0)) { if (x < xBefore) { windLeft += winding; } else if (x > xAfter) { @@ -415,8 +413,8 @@ PathItem.inject(new function() { } } } - // If the point was on a monocurve, we are on the path by definition. - // In this case ensure that the winding is at least 1. + // If the point was on a monotonic curve, we are on the path by + // definition. In this case ensure that the winding is at least 1. return Math.max(abs(windLeft), abs(windRight), isOnCurve ? 1 : 0); }