Merge loops in reorientPath().

This commit is contained in:
Jürg Lehni 2013-05-03 23:25:26 -07:00
parent 37300455a8
commit a5d00e64cf

View file

@ -64,17 +64,14 @@ PathItem.inject(new function() {
} }
/** /**
* To deal with a HTML canvas requirement where CompoundPaths' child contours * To deal with a HTML5 canvas requirement where CompoundPaths' child
* has to be of different winding direction for correctly filling holes. * contours has to be of different winding direction for correctly filling
* But if some individual countours are disjoint, i.e. islands, we have to * holes. But if some individual countours are disjoint, i.e. islands, we
* reorient them so that * have to reorient them so that:
* the holes have opposit winding direction (already handled by paperjs) * - the holes have opposit winding direction (already handled by paper.js)
* islands has to have same winding direction (as the first child of the path) * - islands have to have the same winding direction as the first child
* *
* Does NOT handle selfIntersecting CompoundPaths. * NOTE: Does NOT handle self-intersecting CompoundPaths.
*
* @param {CompoundPath} path - Input CompoundPath, Note: This path could be modified if need be.
* @return {boolean} the winding direction of the base contour(true if clockwise)
*/ */
function reorientPath(path) { function reorientPath(path) {
if (path instanceof CompoundPath) { if (path instanceof CompoundPath) {
@ -92,12 +89,9 @@ PathItem.inject(new function() {
if (i !== j && bounds[i].contains(bounds[j])) if (i !== j && bounds[i].contains(bounds[j]))
counters[j]++; counters[j]++;
} }
} // Omit the first child
// Omit the first child if (i > 0 && counters[i] % 2 === 0)
for (var i = 1; i < length; i++) {
if (counters[i] % 2 === 0) {
children[i].setClockwise(clockwise); children[i].setClockwise(clockwise);
}
} }
} }
return path; return path;