mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-22 07:19:57 -05:00
Some boolean code clean-up.
This commit is contained in:
parent
ea2ff5ec28
commit
e2d2c836e5
2 changed files with 30 additions and 19 deletions
|
@ -888,6 +888,26 @@ statics: {
|
||||||
isCollinear: function(curve) {
|
isCollinear: function(curve) {
|
||||||
return curve && this.isStraight() && curve.isStraight()
|
return curve && this.isStraight() && curve.isStraight()
|
||||||
&& this.getVector().isCollinear(curve.getVector());
|
&& this.getVector().isCollinear(curve.getVector());
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the curve is a straight horizontal line.
|
||||||
|
*
|
||||||
|
* @return {Boolean} {@true if the line is horizontal}
|
||||||
|
*/
|
||||||
|
isHorizontal: function() {
|
||||||
|
return this.isStraight() && Math.abs(this.getTangentAt(0.5, true).y)
|
||||||
|
< /*#=*/Numerical.GEOMETRIC_EPSILON;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the curve is a straight vertical line.
|
||||||
|
*
|
||||||
|
* @return {Boolean} {@true if the line is vertical}
|
||||||
|
*/
|
||||||
|
isVertical: function() {
|
||||||
|
return this.isStraight() && Math.abs(this.getTangentAt(0.5, true).x)
|
||||||
|
< /*#=*/Numerical.GEOMETRIC_EPSILON;
|
||||||
}
|
}
|
||||||
}), /** @lends Curve# */{
|
}), /** @lends Curve# */{
|
||||||
// Explicitly deactivate the creation of beans, as we have functions here
|
// Explicitly deactivate the creation of beans, as we have functions here
|
||||||
|
|
|
@ -222,19 +222,6 @@ PathItem.inject(new function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMainPath(item) {
|
|
||||||
var path = item._path,
|
|
||||||
parent = path._parent;
|
|
||||||
return parent instanceof CompoundPath ? parent : path;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isHorizontal(curve) {
|
|
||||||
// Determine if the curve is a horizontal straight curve by checking the
|
|
||||||
// slope of it's tangent.
|
|
||||||
return curve.isStraight() && Math.abs(curve.getTangentAt(0.5, true).y)
|
|
||||||
< /*#=*/Numerical.GEOMETRIC_EPSILON;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private method that returns the winding contribution of the given point
|
* Private method that returns the winding contribution of the given point
|
||||||
* with respect to a given set of monotone curves.
|
* with respect to a given set of monotone curves.
|
||||||
|
@ -368,8 +355,9 @@ PathItem.inject(new function() {
|
||||||
totalLength = 0,
|
totalLength = 0,
|
||||||
windingSum = 0;
|
windingSum = 0;
|
||||||
do {
|
do {
|
||||||
var length = segment.getCurve().getLength();
|
var curve = segment.getCurve(),
|
||||||
chain.push({ segment: segment, length: length });
|
length = curve.getLength();
|
||||||
|
chain.push({ segment: segment, curve: curve, length: length });
|
||||||
totalLength += length;
|
totalLength += length;
|
||||||
segment = segment.getNext();
|
segment = segment.getNext();
|
||||||
} while (segment && !segment._intersection && segment !== startSeg);
|
} while (segment && !segment._intersection && segment !== startSeg);
|
||||||
|
@ -389,10 +377,13 @@ PathItem.inject(new function() {
|
||||||
// beginning or end, use the curve's center instead.
|
// beginning or end, use the curve's center instead.
|
||||||
if (length < epsilon || curveLength - length < epsilon)
|
if (length < epsilon || curveLength - length < epsilon)
|
||||||
length = curveLength / 2;
|
length = curveLength / 2;
|
||||||
var curve = node.segment.getCurve(),
|
var curve = node.curve,
|
||||||
|
path = curve._path,
|
||||||
|
parent = path._parent,
|
||||||
pt = curve.getPointAt(length),
|
pt = curve.getPointAt(length),
|
||||||
hor = isHorizontal(curve),
|
hor = curve.isHorizontal();
|
||||||
path = getMainPath(curve);
|
if (parent instanceof CompoundPath)
|
||||||
|
path = parent;
|
||||||
// While subtracting, we need to omit this curve if this
|
// While subtracting, we need to omit this curve if this
|
||||||
// curve is contributing to the second operand and is
|
// curve is contributing to the second operand and is
|
||||||
// outside the first operand.
|
// outside the first operand.
|
||||||
|
@ -564,7 +555,7 @@ PathItem.inject(new function() {
|
||||||
drawSegment(seg, 'overlap ' + dir, i, 'orange');
|
drawSegment(seg, 'overlap ' + dir, i, 'orange');
|
||||||
var curve = interSeg.getCurve();
|
var curve = interSeg.getCurve();
|
||||||
if (getWinding(curve.getPointAt(0.5, true),
|
if (getWinding(curve.getPointAt(0.5, true),
|
||||||
monoCurves, isHorizontal(curve)) === 1) {
|
monoCurves, curve.isHorizontal()) === 1) {
|
||||||
seg._visited = interSeg._visited;
|
seg._visited = interSeg._visited;
|
||||||
seg = interSeg;
|
seg = interSeg;
|
||||||
dir = 1;
|
dir = 1;
|
||||||
|
|
Loading…
Reference in a new issue