mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Revert "Never starting in intersections allows for further code simplifications."
This reverts commit 892154e8f8
.
This commit is contained in:
parent
892154e8f8
commit
c45ae4b51a
1 changed files with 17 additions and 8 deletions
|
@ -566,6 +566,7 @@ PathItem.inject(new function() {
|
|||
|
||||
var paths = [],
|
||||
start,
|
||||
otherStart,
|
||||
operator = operators[operation],
|
||||
// Adjust winding contributions for specific operations on overlaps:
|
||||
overlapWinding = {
|
||||
|
@ -585,6 +586,10 @@ PathItem.inject(new function() {
|
|||
return operator(winding);
|
||||
}
|
||||
|
||||
function isStart(seg) {
|
||||
return seg === start || seg === otherStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the curve from seg1 to seg2 is part of an overlap.
|
||||
*/
|
||||
|
@ -616,7 +621,7 @@ PathItem.inject(new function() {
|
|||
+ nextSeg._index
|
||||
+ ', seg vis:' + !!seg._visited
|
||||
+ ', next vis:' + !!nextSeg._visited
|
||||
+ ', next start:' + (nextSeg === start)
|
||||
+ ', next start:' + isStart(nextSeg)
|
||||
+ ', seg wi:' + seg._winding
|
||||
+ ', next wi:' + nextSeg._winding
|
||||
+ ', seg op:' + isValid(seg, true)
|
||||
|
@ -643,7 +648,7 @@ PathItem.inject(new function() {
|
|||
// result, the non-strict mode is used, in which invalid current
|
||||
// segments are tolerated, and overlaps for the next segment are
|
||||
// allowed as long as they are valid when not adjusted.
|
||||
if (nextSeg === start
|
||||
if (isStart(nextSeg)
|
||||
|| !seg._visited && !nextSeg._visited
|
||||
// Self-intersections (!operator) don't need isValid() calls
|
||||
&& (!operator
|
||||
|
@ -670,13 +675,14 @@ PathItem.inject(new function() {
|
|||
|
||||
for (var i = 0, l = segments.length; i < l; i++) {
|
||||
var seg = segments[i],
|
||||
path = null;
|
||||
path = null,
|
||||
finished = false;
|
||||
// Do not start a chain with segments that have intersections,
|
||||
// segments that are already visited, or that are invalid.
|
||||
if (seg._intersection || !isValid(seg))
|
||||
continue;
|
||||
start = null;
|
||||
while (seg !== start) {
|
||||
start = otherStart = null;
|
||||
while (!finished) {
|
||||
var inter = seg._intersection;
|
||||
// Once we started a chain, see if there are multiple
|
||||
// intersections, and if so, pick the best one:
|
||||
|
@ -735,8 +741,9 @@ PathItem.inject(new function() {
|
|||
drawSegment(seg, null, 'stay', i, 'blue');
|
||||
}
|
||||
if (seg._visited) {
|
||||
if (seg === start) {
|
||||
if (isStart(seg)) {
|
||||
drawSegment(seg, null, 'done', i, 'red');
|
||||
finished = true;
|
||||
} else {
|
||||
// We didn't manage to switch, so stop right here.
|
||||
console.error('Visited segment encountered, aborting #'
|
||||
|
@ -750,21 +757,23 @@ PathItem.inject(new function() {
|
|||
if (!path) {
|
||||
path = new Path(Item.NO_INSERT);
|
||||
start = seg;
|
||||
otherStart = other;
|
||||
}
|
||||
// Add the current segment to the path, and mark the added
|
||||
// segment as visited.
|
||||
path.add(new Segment(seg._point, handleIn, seg._handleOut));
|
||||
seg._visited = true;
|
||||
seg = seg.getNext();
|
||||
if (seg === start) {
|
||||
if (isStart(seg)) {
|
||||
drawSegment(seg, null, 'done', i, 'red');
|
||||
finished = true;
|
||||
}
|
||||
}
|
||||
if (!path)
|
||||
continue;
|
||||
// Finish with closing the paths if necessary, correctly linking up
|
||||
// curves etc.
|
||||
if (seg === start) {
|
||||
if (finished) {
|
||||
path.firstSegment.setHandleIn(seg._handleIn);
|
||||
path.setClosed(true);
|
||||
if (window.reportSegments) {
|
||||
|
|
Loading…
Reference in a new issue