From 192437dbe26159a9b7412e258003c781ad469d5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sun, 23 Jun 2019 04:19:20 +0200 Subject: [PATCH] Boolean: Avoid winding edge cases Stay clear from testing winding on actual segments. Closes #1619 --- src/path/PathItem.Boolean.js | 3 ++- test/tests/Path_Boolean.js | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/path/PathItem.Boolean.js b/src/path/PathItem.Boolean.js index 30c38d36..e4f37459 100644 --- a/src/path/PathItem.Boolean.js +++ b/src/path/PathItem.Boolean.js @@ -751,7 +751,8 @@ PathItem.inject(new function() { // the best quality. var offsets = [0.5, 0.25, 0.75], winding = { winding: 0, quality: -1 }, - tMin = /*#=*/Numerical.CURVETIME_EPSILON, + // Don't go too close to segments, to avoid special winding cases: + tMin = 1e-3, tMax = 1 - tMin; for (var i = 0; i < offsets.length && winding.quality < 0.5; i++) { var length = totalLength * offsets[i]; diff --git a/test/tests/Path_Boolean.js b/test/tests/Path_Boolean.js index bab08843..292bede7 100644 --- a/test/tests/Path_Boolean.js +++ b/test/tests/Path_Boolean.js @@ -1230,3 +1230,25 @@ test('#1647', function() { var result = 'M57.83,48.25l-6.78143,11.75l-2.88143,0l7.50286,-13c0.88236,-1.55771 2.53981,-2.51466 4.33,-2.5v2.5c-0.89493,-0.00177 -1.72254,0.47497 -2.17,1.25z'; compareBoolean(path1.intersect(path2), result); }); + +test('#1619', function() { + var path1 = new Path.Rectangle({ + from: [200, 600], + to: [400, 300] + }); + + var path2 = new CompoundPath({ + children: [ + new Path({ + segments: [[420,320],[380,580],[220,580],[220,320]], + closed: true + }), + new Path({ + segments: [[313.36486,413.71682],[243.351,483.70296],[313.33714,553.71682],[383.351,483.73068]], + closed: true + }) + ] + }); + var result = 'M380,580h-160v-260l180,0v130zM313.36486,413.71682l-70.01386,69.98614l69.98614,70.01386l70.01386,-69.98614z'; + compareBoolean(path1.intersect(path2), result); +});