From 978cd94a9ea9b1dab1bcafc3bd68b86f4225d53e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sat, 22 Jun 2019 18:48:16 +0200 Subject: [PATCH] Boolean: Add check for paths with only one segment Closes #1351 --- src/path/PathItem.Boolean.js | 12 ++++++++---- test/tests/Path_Boolean.js | 9 ++++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/path/PathItem.Boolean.js b/src/path/PathItem.Boolean.js index 018555aa..3534a224 100644 --- a/src/path/PathItem.Boolean.js +++ b/src/path/PathItem.Boolean.js @@ -715,10 +715,14 @@ PathItem.inject(new function() { totalLength = 0, winding; do { - var curve = segment.getCurve(), - length = curve.getLength(); - chain.push({ segment: segment, curve: curve, length: length }); - totalLength += length; + var curve = segment.getCurve(); + // We can encounter paths with only one segment, which would not + // have a curve. + if (curve) { + var length = curve.getLength(); + chain.push({ segment: segment, curve: curve, length: length }); + totalLength += length; + } segment = segment.getNext(); } while (segment && !segment._intersection && segment !== start); // Determine winding at three points in the chain. If a winding with diff --git a/test/tests/Path_Boolean.js b/test/tests/Path_Boolean.js index 764fdcae..0d448243 100644 --- a/test/tests/Path_Boolean.js +++ b/test/tests/Path_Boolean.js @@ -1214,4 +1214,11 @@ test('#1419', function() { }); var result = 'M-50,0c0,-27.61424 22.38576,-50 50,-50c7.33673,0 14.30439,1.5802 20.58119,4.41881c-7.84546,-17.34804 -25.30368,-29.41881 -45.58119,-29.41881c-27.61424,0 -50,22.38576 -50,50c0,20.27751 12.07077,37.73573 29.41881,45.58119c-2.83861,-6.2768 -4.41881,-13.24446 -4.41881,-20.58119zM50,0c0,27.61424 -22.38576,50 -50,50c-20.27751,0 -37.73573,-12.07077 -45.58119,-29.41881c6.2768,2.83861 13.24446,4.41881 20.58119,4.41881c27.61424,0 50,-22.38576 50,-50c0,-7.33673 -1.5802,-14.30439 -4.41881,-20.58119c17.34804,7.84546 29.41881,25.30368 29.41881,45.58119z'; compareBoolean(circle1.exclude(circle2), result); -}) +}); + +test('#1351', function() { + var path1 = new CompoundPath(new Path([10, 10], [100, 100]), new Path([150, 25])); + var path2 = new Path([20, 80], [80, 20]); + var result = 'M10,10l40,40l50,50'; + compareBoolean(path1.unite(path2), result); +});