From d7be4431199e03b8f4d3056e8d60ee5ecfbd144a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sun, 2 Mar 2014 21:19:31 +0100 Subject: [PATCH] Simplify path filtering code in tracePaths() a bit, and improve documentation. --- src/path/PathItem.Boolean.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/path/PathItem.Boolean.js b/src/path/PathItem.Boolean.js index 19bf1f77..5ceceeac 100644 --- a/src/path/PathItem.Boolean.js +++ b/src/path/PathItem.Boolean.js @@ -446,11 +446,15 @@ PathItem.inject(new function() { } else { path.lastSegment._handleOut.set(0, 0); } - // Add the path to the result. - // Try to avoid stray segments and incomplete paths. - var count = path._segments.length; - if ((path._closed && count) || count > 2 - || (count === 2 && path._closed && !path.isPolygon())) + // Add the path to the result, while avoiding stray segments and + // incomplete paths. The amount of segments for valid paths depend + // on their geometry: + // - Closed paths with only straight lines (polygons) need more than + // two segments. + // - Closed paths with curves can consist of only one segment. + // - Open paths need at least two segments. + if (path._segments.length > + (path._closed ? path.isPolygon() ? 2 : 0 : 1)) paths.push(path); } return paths;