Boolean: Add check for paths with only one segment

Closes #1351
This commit is contained in:
Jürg Lehni 2019-06-22 18:48:16 +02:00
parent e779d24a6d
commit 978cd94a9e
2 changed files with 16 additions and 5 deletions

View file

@ -715,10 +715,14 @@ PathItem.inject(new function() {
totalLength = 0,
winding;
do {
var curve = segment.getCurve(),
length = curve.getLength();
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

View file

@ -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);
});