Simplify path filtering code in tracePaths() a bit, and improve documentation.

This commit is contained in:
Jürg Lehni 2014-03-02 21:19:31 +01:00
parent cb810c73bd
commit d7be443119

View file

@ -446,11 +446,15 @@ PathItem.inject(new function() {
} else { } else {
path.lastSegment._handleOut.set(0, 0); path.lastSegment._handleOut.set(0, 0);
} }
// Add the path to the result. // Add the path to the result, while avoiding stray segments and
// Try to avoid stray segments and incomplete paths. // incomplete paths. The amount of segments for valid paths depend
var count = path._segments.length; // on their geometry:
if ((path._closed && count) || count > 2 // - Closed paths with only straight lines (polygons) need more than
|| (count === 2 && path._closed && !path.isPolygon())) // 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); paths.push(path);
} }
return paths; return paths;