mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-07 13:22:07 -05:00
More clean-up and some variable renaming.
This commit is contained in:
parent
de6650a6ca
commit
50433400f0
1 changed files with 22 additions and 23 deletions
|
@ -435,41 +435,41 @@ statics: {
|
||||||
operator = operator || function() {
|
operator = operator || function() {
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
var j,
|
|
||||||
// A list of both curves at an intersection, except the entry curves
|
// A list of both curves at an intersection, except the entry curves
|
||||||
// along with their winding values and tangents.
|
// along with their winding values and tangents.
|
||||||
curves = [{}, {}],
|
var curves = [{}, {}],
|
||||||
paths = [],
|
paths = [],
|
||||||
// Values for getTangentAt() that are almost 0 and 1.
|
// Values for getTangentAt() that are almost 0 and 1.
|
||||||
// TODO: Correctly support getTangentAt(0) / (1)?
|
// TODO: Correctly support getTangentAt(0) / (1)?
|
||||||
ZERO = 1e-3,
|
ZERO = 1e-3,
|
||||||
ONE = 1 - ZERO;
|
ONE = 1 - ZERO;
|
||||||
for (var i = 0, seg, startSeg, l = segments.length; i < l; i++) {
|
for (var i = 0, seg, startSeg, l = segments.length; i < l; i++) {
|
||||||
startSeg = seg = segments[i];
|
seg = startSeg = segments[i];
|
||||||
if (seg._visited || !operator(seg._winding))
|
if (seg._visited || !operator(seg._winding))
|
||||||
continue;
|
continue;
|
||||||
// Initialise a new path chain with the seed segment.
|
// Initialise a new path chain with the seed segment.
|
||||||
var path = new Path({ insert: false }),
|
var path = new Path({ insert: false }),
|
||||||
ixOther = seg._intersection,
|
inter = seg._intersection,
|
||||||
startSegIx = ixOther && ixOther._segment,
|
startInterSeg = inter && inter._segment,
|
||||||
firstHandleIn = null,
|
firstHandleIn = null,
|
||||||
dir = 1;
|
dir = 1;
|
||||||
do {
|
do {
|
||||||
ixOther = seg._intersection;
|
|
||||||
var nextHandleIn = dir > 0 ? seg._handleIn : seg._handleOut,
|
var nextHandleIn = dir > 0 ? seg._handleIn : seg._handleOut,
|
||||||
nextHandleOut = dir > 0 ? seg._handleOut : seg._handleIn,
|
nextHandleOut = dir > 0 ? seg._handleOut : seg._handleIn,
|
||||||
ixOtherSeg;
|
interSeg;
|
||||||
// If the intersection segment is valid, try switching to
|
// If the intersection segment is valid, try switching to
|
||||||
// it, with an appropriate direction to continue traversal.
|
// it, with an appropriate direction to continue traversal.
|
||||||
// Else, stay on the same contour.
|
// Else, stay on the same contour.
|
||||||
if (ixOther && (!operator(seg._winding) || selfIx)
|
if (firstHandleIn
|
||||||
&& (ixOtherSeg = ixOther._segment)
|
&& (!operator(seg._winding) || selfIx)
|
||||||
&& ixOtherSeg !== startSeg && firstHandleIn) {
|
&& (inter = seg._intersection)
|
||||||
|
&& (interSeg = inter._segment)
|
||||||
|
&& interSeg !== startSeg) {
|
||||||
var c1 = seg.getCurve();
|
var c1 = seg.getCurve();
|
||||||
if (dir > 0)
|
if (dir > 0)
|
||||||
c1 = c1.getPrevious();
|
c1 = c1.getPrevious();
|
||||||
var t1 = c1.getTangentAt(dir < 1 ? ZERO : ONE, true),
|
var t1 = c1.getTangentAt(dir < 1 ? ZERO : ONE, true),
|
||||||
c4 = curves[1].c = ixOtherSeg.getCurve(),
|
c4 = curves[1].c = interSeg.getCurve(),
|
||||||
c3 = curves[0].c = c4.getPrevious();
|
c3 = curves[0].c = c4.getPrevious();
|
||||||
curves[0].t = c3.getTangentAt(ONE, true);
|
curves[0].t = c3.getTangentAt(ONE, true);
|
||||||
curves[1].t = c4.getTangentAt(ZERO, true);
|
curves[1].t = c4.getTangentAt(ZERO, true);
|
||||||
|
@ -485,8 +485,8 @@ statics: {
|
||||||
// Compare tangents to sort curves counter clockwise
|
// Compare tangents to sort curves counter clockwise
|
||||||
return a.w - b.w;
|
return a.w - b.w;
|
||||||
});
|
});
|
||||||
var nextSeg,
|
var j = 0,
|
||||||
j = 0;
|
nextSeg;
|
||||||
do {
|
do {
|
||||||
var curve = curves[j++].c;
|
var curve = curves[j++].c;
|
||||||
nextSeg = curve._segment1;
|
nextSeg = curve._segment1;
|
||||||
|
@ -499,8 +499,8 @@ statics: {
|
||||||
dir = 1;
|
dir = 1;
|
||||||
} else {
|
} else {
|
||||||
// Switch to the intersection segment.
|
// Switch to the intersection segment.
|
||||||
seg._visited = ixOtherSeg._visited;
|
seg._visited = interSeg._visited;
|
||||||
seg = ixOtherSeg;
|
seg = interSeg;
|
||||||
if (nextSeg._visited)
|
if (nextSeg._visited)
|
||||||
dir = 1;
|
dir = 1;
|
||||||
}
|
}
|
||||||
|
@ -519,15 +519,14 @@ statics: {
|
||||||
seg._visited = true;
|
seg._visited = true;
|
||||||
// Move to the next segment according to the traversal direction
|
// Move to the next segment according to the traversal direction
|
||||||
seg = dir > 0 ? seg.getNext() : seg. getPrevious();
|
seg = dir > 0 ? seg.getNext() : seg. getPrevious();
|
||||||
} while (seg && seg !== startSeg && seg !== startSegIx
|
} while (seg && !seg._visited
|
||||||
&& !seg._visited
|
&& seg !== startSeg && seg !== startInterSeg
|
||||||
&& (seg._intersection || operator(seg._winding)));
|
&& (seg._intersection || operator(seg._winding)));
|
||||||
// Finish with closing the paths if necessary, correctly linking up
|
// Finish with closing the paths if necessary, correctly linking up
|
||||||
// curves etc.
|
// curves etc.
|
||||||
if (seg && (seg === startSeg || seg === startSegIx)) {
|
if (seg && (seg === startSeg || seg === startInterSeg)) {
|
||||||
path.firstSegment.setHandleIn(seg === startSegIx
|
path.firstSegment.setHandleIn(
|
||||||
? startSegIx._handleIn
|
(seg === startInterSeg ? startInterSeg : seg)._handleIn);
|
||||||
: seg._handleIn);
|
|
||||||
path.setClosed(true);
|
path.setClosed(true);
|
||||||
} else {
|
} else {
|
||||||
path.lastSegment._handleOut.set(0, 0);
|
path.lastSegment._handleOut.set(0, 0);
|
||||||
|
|
Loading…
Reference in a new issue