mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Define CompoundPath#reverse() and #clockwise, and replace reversePath() with it.
This commit is contained in:
parent
bd3031cdff
commit
25e5582a35
3 changed files with 33 additions and 22 deletions
|
@ -89,11 +89,36 @@ var CompoundPath = this.CompoundPath = PathItem.extend(/** @lends CompoundPath#
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Reverses the orientation of all nested paths.
|
||||
*/
|
||||
reverse: function() {
|
||||
var children = this._children;
|
||||
for (var i = 0, l = children.length; i < l; i++)
|
||||
children[i].reverse();
|
||||
},
|
||||
|
||||
smooth: function() {
|
||||
for (var i = 0, l = this._children.length; i < l; i++)
|
||||
this._children[i].smooth();
|
||||
},
|
||||
|
||||
/**
|
||||
* Specifies whether the compound path is oriented clock-wise.
|
||||
*
|
||||
* @type Boolean
|
||||
* @bean
|
||||
*/
|
||||
isClockwise: function() {
|
||||
var child = this.getFirstChild();
|
||||
return child && child.isClockwise();
|
||||
},
|
||||
|
||||
setClockwise: function(clockwise) {
|
||||
if (this.isClockwise() != !!clockwise)
|
||||
this.reverse();
|
||||
},
|
||||
|
||||
/**
|
||||
* The first Segment contained within the path.
|
||||
*
|
||||
|
|
|
@ -1085,19 +1085,18 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
|
|||
},
|
||||
|
||||
setClockwise: function(clockwise) {
|
||||
// Only revers the path if its clockwise orientation is not the same
|
||||
// as what it is now demanded to be.
|
||||
// On-the-fly conversion to boolean:
|
||||
if (this.isClockwise() != (clockwise = !!clockwise)) {
|
||||
// Only revers the path if its clockwise orientation is not the same
|
||||
// as what it is now demanded to be.
|
||||
if (this.isClockwise() != (clockwise = !!clockwise))
|
||||
this.reverse();
|
||||
}
|
||||
// Reverse only flips _clockwise state if it was already set, so let's
|
||||
// always set this here now.
|
||||
this._clockwise = clockwise;
|
||||
},
|
||||
|
||||
/**
|
||||
* Reverses the segments of the path.
|
||||
* Reverses the orientation of the path, by reversing all its segments.
|
||||
*/
|
||||
reverse: function() {
|
||||
this._segments.reverse();
|
||||
|
|
|
@ -108,21 +108,6 @@ PathItem.inject(new function() {
|
|||
return baseWinding;
|
||||
}
|
||||
|
||||
function reversePath(path) {
|
||||
var baseWinding;
|
||||
if (path instanceof CompoundPath) {
|
||||
var children = path.children, i, len;
|
||||
for (i = 0, len = children.length; i < len; i++) {
|
||||
children[i].reverse();
|
||||
}
|
||||
baseWinding = children[0].clockwise;
|
||||
} else {
|
||||
path.reverse();
|
||||
baseWinding = path.clockwise;
|
||||
}
|
||||
return baseWinding;
|
||||
}
|
||||
|
||||
function computeBoolean(path1, path2, operator, subtract, _cache) {
|
||||
var _path1, _path2, path1Clockwise, path2Clockwise;
|
||||
var ixs, path1Id, path2Id;
|
||||
|
@ -147,8 +132,10 @@ PathItem.inject(new function() {
|
|||
path1Id = _path1.id;
|
||||
path2Id = _path2.id;
|
||||
// Do operator specific calculations before we begin
|
||||
if (subtract)
|
||||
path2Clockwise = reversePath(_path2);
|
||||
if (subtract) {
|
||||
_path2.reverse();
|
||||
path2Clockwise = !path2Clockwise;
|
||||
}
|
||||
|
||||
var i, j, len, path, crv;
|
||||
var paths = [];
|
||||
|
|
Loading…
Reference in a new issue