mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-08-28 22:08:54 -04:00
Correctly handle self-intersections when deciding to switch segments.
Closes #765
This commit is contained in:
parent
4770cfe2f8
commit
c69ea345da
1 changed files with 11 additions and 7 deletions
|
@ -496,6 +496,7 @@ PathItem.inject(new function() {
|
||||||
|
|
||||||
labelSegment(seg, '#' + pathIndex + '.' + (i + 1)
|
labelSegment(seg, '#' + pathIndex + '.' + (i + 1)
|
||||||
+ ' i: ' + !!inter
|
+ ' i: ' + !!inter
|
||||||
|
+ ' p: ' + seg._path._id
|
||||||
+ ' x: ' + seg._point.x
|
+ ' x: ' + seg._point.x
|
||||||
+ ' y: ' + seg._point.y
|
+ ' y: ' + seg._point.y
|
||||||
+ ' o: ' + (inter && inter._overlap || 0)
|
+ ' o: ' + (inter && inter._overlap || 0)
|
||||||
|
@ -526,20 +527,23 @@ PathItem.inject(new function() {
|
||||||
do {
|
do {
|
||||||
var handleIn = dir > 0 ? seg._handleIn : seg._handleOut,
|
var handleIn = dir > 0 ? seg._handleIn : seg._handleOut,
|
||||||
handleOut = dir > 0 ? seg._handleOut : seg._handleIn,
|
handleOut = dir > 0 ? seg._handleOut : seg._handleIn,
|
||||||
interSeg;
|
inter = seg._intersection,
|
||||||
|
interSeg = inter && inter._segment;
|
||||||
// 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 (added && (!operator(seg._winding))
|
if (added && interSeg && interSeg !== startSeg) {
|
||||||
&& (inter = seg._intersection)
|
if (interSeg._path === seg._path) { // Self-intersection
|
||||||
&& (interSeg = inter._segment)
|
drawSegment(seg, 'self-int ' + dir, i, 'red');
|
||||||
&& interSeg !== startSeg) {
|
// Switch to the intersection segment, as we need to
|
||||||
if (interSeg._path === seg._path) {
|
|
||||||
// Switch to the intersection segment, if we are
|
|
||||||
// resolving self-Intersections.
|
// resolving self-Intersections.
|
||||||
seg._visited = interSeg._visited;
|
seg._visited = interSeg._visited;
|
||||||
seg = interSeg;
|
seg = interSeg;
|
||||||
dir = 1;
|
dir = 1;
|
||||||
|
} else if (operator(seg._winding)) {
|
||||||
|
// Do not switch to the intersection as the segment is
|
||||||
|
// part of the boolean result.
|
||||||
|
drawSegment(seg, 'keep', i, 'black');
|
||||||
} else if (inter._overlap && operation !== 'intersect') {
|
} else if (inter._overlap && operation !== 'intersect') {
|
||||||
// Switch to the overlapping intersection segment
|
// Switch to the overlapping intersection segment
|
||||||
// if its winding number along the curve is 1, to
|
// if its winding number along the curve is 1, to
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue