From f160e749367b327fdc4166251edbe6aaa8e0297f Mon Sep 17 00:00:00 2001 From: Jan Date: Wed, 31 Aug 2016 10:05:47 +0200 Subject: [PATCH 1/2] Use correct value for y 45 degree tangent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I got the pythagoras wrong when I wrote this. The length of the tangent vector is 1, therefore the y component is sqrt(0.5) for 45°. This will not make any difference, but still we should use the correct value. --- src/path/PathItem.Boolean.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/path/PathItem.Boolean.js b/src/path/PathItem.Boolean.js index 2bf83305..d8a6fb9c 100644 --- a/src/path/PathItem.Boolean.js +++ b/src/path/PathItem.Boolean.js @@ -610,8 +610,10 @@ PathItem.inject(new function() { pt = curve.getPointAtTime(t), // Determine the direction in which to check the winding // from the point (horizontal or vertical), based on the - // curve's direction at that point. - dir = abs(curve.getTangentAtTime(t).normalize().y) < 0.5 + // curve's direction at that point. If the tangent is less + // than 45° (y of tangent < sqrt(0.5)), cast the ray + // vertically, otherwise horizontally. + dir = abs(curve.getTangentAtTime(t).normalize().y) < 0.7071 ? 1 : 0; if (parent instanceof CompoundPath) path = parent; From 3b8d3cc47d8438ec0ad10712d50d6e3e2e3795c1 Mon Sep 17 00:00:00 2001 From: Jan Date: Wed, 31 Aug 2016 23:29:35 +0200 Subject: [PATCH 2/2] Use Math..SQRT1_2 instead of 0.7071 Makes code easier to understand. --- src/path/PathItem.Boolean.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/path/PathItem.Boolean.js b/src/path/PathItem.Boolean.js index d8a6fb9c..4dd172e4 100644 --- a/src/path/PathItem.Boolean.js +++ b/src/path/PathItem.Boolean.js @@ -611,10 +611,9 @@ PathItem.inject(new function() { // Determine the direction in which to check the winding // from the point (horizontal or vertical), based on the // curve's direction at that point. If the tangent is less - // than 45° (y of tangent < sqrt(0.5)), cast the ray - // vertically, otherwise horizontally. - dir = abs(curve.getTangentAtTime(t).normalize().y) < 0.7071 - ? 1 : 0; + // than 45°, cast the ray vertically, else horizontally. + dir = abs(curve.getTangentAtTime(t).normalize().y) + < Math.SQRT1_2 ? 1 : 0; if (parent instanceof CompoundPath) path = parent; // While subtracting, we need to omit this curve if it is