mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-19 14:10:14 -05:00
Clean up reorientCompoundPath().
This commit is contained in:
parent
25e5582a35
commit
d014ed3c68
1 changed files with 19 additions and 24 deletions
|
@ -77,35 +77,30 @@ PathItem.inject(new function() {
|
||||||
* @return {boolean} the winding direction of the base contour(true if clockwise)
|
* @return {boolean} the winding direction of the base contour(true if clockwise)
|
||||||
*/
|
*/
|
||||||
function reorientCompoundPath(path) {
|
function reorientCompoundPath(path) {
|
||||||
if (!(path instanceof CompoundPath)) {
|
if (!(path instanceof CompoundPath))
|
||||||
path.closed = true;
|
return path.isClockwise();
|
||||||
return path.clockwise;
|
var children = path._children,
|
||||||
|
length = children.length,
|
||||||
|
bounds = new Array(length),
|
||||||
|
counters = new Array(length),
|
||||||
|
clockwise = children[0].isClockwise();
|
||||||
|
for (var i = 0; i < length; i++) {
|
||||||
|
bounds[i] = children[i].getBounds();
|
||||||
|
counters[i] = 0;
|
||||||
}
|
}
|
||||||
var children = path.children, len = children.length, baseWinding;
|
for (var i = 0; i < length; i++) {
|
||||||
var bounds = new Array(len);
|
for (var j = 1; j < length; j++) {
|
||||||
var tmparray = new Array(len);
|
if (i !== j && bounds[i].contains(bounds[j]))
|
||||||
baseWinding = children[0].clockwise;
|
counters[j]++;
|
||||||
// Omit the first path
|
|
||||||
for (i = 0; i < len; i++) {
|
|
||||||
children[i].closed = true;
|
|
||||||
bounds[i] = children[i].bounds;
|
|
||||||
tmparray[i] = 0;
|
|
||||||
}
|
|
||||||
for (i = 0; i < len; i++) {
|
|
||||||
var p1 = children[i];
|
|
||||||
for (j = 0; j < len; j++) {
|
|
||||||
var p2 = children[j];
|
|
||||||
if (i !== j && bounds[i].contains(bounds[j])) {
|
|
||||||
tmparray[j]++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i = 1; i < len; i++) {
|
// Omit the first child
|
||||||
if (tmparray[i] % 2 === 0) {
|
for (var i = 1; i < length; i++) {
|
||||||
children[i].clockwise = baseWinding;
|
if (counters[i] % 2 === 0) {
|
||||||
|
children[i].setClockwise(clockwise);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return baseWinding;
|
return clockwise;
|
||||||
}
|
}
|
||||||
|
|
||||||
function computeBoolean(path1, path2, operator, subtract, _cache) {
|
function computeBoolean(path1, path2, operator, subtract, _cache) {
|
||||||
|
|
Loading…
Reference in a new issue