mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-19 14:10:14 -05:00
Various code and comment clean-ups in new bool-op code.
This commit is contained in:
parent
8726a3f082
commit
1a0eead28c
3 changed files with 12 additions and 18 deletions
|
@ -239,14 +239,14 @@ var CompoundPath = PathItem.extend(/** @lends CompoundPath# */{
|
|||
/**
|
||||
* Private method that returns all the curves in this CompoundPath, which
|
||||
* are monotonically decreasing or increasing in the 'y' direction.
|
||||
* Used by PathItem#_getWinding method.
|
||||
* Used by PathItem#_getWinding().
|
||||
*/
|
||||
_getMonotoneCurves: function() {
|
||||
var children = this._children,
|
||||
monoCurves = [];
|
||||
curves = [];
|
||||
for (var i = 0, l = children.length; i < l; i++)
|
||||
monoCurves.push.apply(monoCurves, children[i]._getMonotoneCurves());
|
||||
return monoCurves;
|
||||
curves.push.apply(curves, children[i]._getMonotoneCurves());
|
||||
return curves;
|
||||
},
|
||||
|
||||
// _getWinding: function(point) {
|
||||
|
|
|
@ -1712,7 +1712,7 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
/**
|
||||
* Private method that returns and caches all the curves in this Path, which
|
||||
* are monotonically decreasing or increasing in the 'y' direction.
|
||||
* Used by PathItem#_getWinding method.
|
||||
* Used by PathItem#_getWinding().
|
||||
*/
|
||||
_getMonotoneCurves: function() {
|
||||
var monoCurves = this._monotoneCurves,
|
||||
|
@ -1781,9 +1781,6 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
// If the path is not closed, we should join the end points
|
||||
// with a straight line, just like how filling open paths works.
|
||||
if (!this._closed && segments.length > 1) {
|
||||
// if (!this.hasFill()
|
||||
// || !this.getInternalRoughBounds()._containsPoint(point))
|
||||
// return 0;
|
||||
curves.push(new Curve(segments[segments.length - 1]._point,
|
||||
segments[0]._point));
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
* http://hkrish.com/playground/paperjs/booleanStudy.html
|
||||
*/
|
||||
|
||||
PathItem.inject(new function() { // FIXME: Is new necessary?
|
||||
PathItem.inject(new function() {
|
||||
/**
|
||||
* To deal with a HTML5 canvas requirement where CompoundPaths' child
|
||||
* contours has to be of different winding direction for correctly filling
|
||||
|
@ -87,7 +87,7 @@ PathItem.inject(new function() { // FIXME: Is new necessary?
|
|||
path1.reverse();
|
||||
if (!singlePathOp && !(subtract ^ path2.isClockwise()))
|
||||
path2.reverse();
|
||||
var intersections, i, j, l, lj, segment, wind,
|
||||
var i, j, l, lj, segment, wind,
|
||||
point, startSeg, crv, length, parent, v, horizontal,
|
||||
curveChain = [],
|
||||
windings = [],
|
||||
|
@ -98,14 +98,11 @@ PathItem.inject(new function() { // FIXME: Is new necessary?
|
|||
// Aggregate of all curves in both operands, monotonic in y
|
||||
monoCurves = [],
|
||||
result = new CompoundPath(),
|
||||
random = Math.random,
|
||||
abs = Math.abs,
|
||||
tolerance = /*#=*/ Numerical.TOLERANCE,
|
||||
getWinding = PathItem._getWinding;
|
||||
// Split curves at intersections on both paths.
|
||||
intersections = singlePathOp ? path1.getSelfIntersections(true)
|
||||
: path1.getIntersections(path2, true);
|
||||
PathItem._splitPath(intersections);
|
||||
// Split curves at intersections on both paths.
|
||||
PathItem._splitPath(intersections);
|
||||
// Collect all sub paths and segments
|
||||
paths.push.apply(paths, path1._children || [path1]);
|
||||
if (!singlePathOp)
|
||||
|
@ -152,7 +149,7 @@ PathItem.inject(new function() { // FIXME: Is new necessary?
|
|||
// the same (amortised) time.
|
||||
windings.length = 0;
|
||||
for (wind = 0; wind < 3; wind++) {
|
||||
length = lenCurves * random();
|
||||
length = lenCurves * Math.random();
|
||||
for (j = 0, lj = lengths.length ; j <= lj; j++)
|
||||
if (lengths[j] >= length) {
|
||||
length = j > 0 ? length - lengths[j-1] : length;
|
||||
|
@ -161,8 +158,8 @@ PathItem.inject(new function() { // FIXME: Is new necessary?
|
|||
crv = curveChain[j].getCurve();
|
||||
point = crv.getPointAt(length);
|
||||
v = crv.getValues();
|
||||
horizontal = (Curve.isLinear(v) && abs(v[1] - v[7]) < tolerance);
|
||||
windMedian = getWinding(point, monoCurves, horizontal);
|
||||
horizontal = Curve.isLinear(v) && Math.abs(v[1] - v[7]) < tolerance;
|
||||
windMedian = PathItem._getWinding(point, monoCurves, horizontal);
|
||||
// While subtracting, we need to omit this curve if this
|
||||
// curve is contributing to the second operand and is outside
|
||||
// the first operand.
|
||||
|
|
Loading…
Reference in a new issue