mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-04 03:45:58 -05:00
Merge loops in reorientPath().
This commit is contained in:
parent
37300455a8
commit
a5d00e64cf
1 changed files with 9 additions and 15 deletions
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue