(segments, compareIntersection, startInside, interpolate, stream)
| 10535 | // into its visible line segments, and rejoins the segments by interpolating |
| 10536 | // along the clip edge. |
| 10537 | function clipRejoin(segments, compareIntersection, startInside, interpolate, stream) { |
| 10538 | var subject = [], |
| 10539 | clip = [], |
| 10540 | i, |
| 10541 | n; |
| 10542 | |
| 10543 | segments.forEach(function(segment) { |
| 10544 | if ((n = segment.length - 1) <= 0) return; |
| 10545 | var n, p0 = segment[0], p1 = segment[n], x; |
| 10546 | |
| 10547 | if (pointEqual(p0, p1)) { |
| 10548 | if (!p0[2] && !p1[2]) { |
| 10549 | stream.lineStart(); |
| 10550 | for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]); |
| 10551 | stream.lineEnd(); |
| 10552 | return; |
| 10553 | } |
| 10554 | // handle degenerate cases by moving the point |
| 10555 | p1[0] += 2 * epsilon$1; |
| 10556 | } |
| 10557 | |
| 10558 | subject.push(x = new Intersection(p0, segment, null, true)); |
| 10559 | clip.push(x.o = new Intersection(p0, null, x, false)); |
| 10560 | subject.push(x = new Intersection(p1, segment, null, false)); |
| 10561 | clip.push(x.o = new Intersection(p1, null, x, true)); |
| 10562 | }); |
| 10563 | |
| 10564 | if (!subject.length) return; |
| 10565 | |
| 10566 | clip.sort(compareIntersection); |
| 10567 | link$1(subject); |
| 10568 | link$1(clip); |
| 10569 | |
| 10570 | for (i = 0, n = clip.length; i < n; ++i) { |
| 10571 | clip[i].e = startInside = !startInside; |
| 10572 | } |
| 10573 | |
| 10574 | var start = subject[0], |
| 10575 | points, |
| 10576 | point; |
| 10577 | |
| 10578 | while (1) { |
| 10579 | // Find first unvisited intersection. |
| 10580 | var current = start, |
| 10581 | isSubject = true; |
| 10582 | while (current.v) if ((current = current.n) === start) return; |
| 10583 | points = current.z; |
| 10584 | stream.lineStart(); |
| 10585 | do { |
| 10586 | current.v = current.o.v = true; |
| 10587 | if (current.e) { |
| 10588 | if (isSubject) { |
| 10589 | for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]); |
| 10590 | } else { |
| 10591 | interpolate(current.x, current.n.x, 1, stream); |
| 10592 | } |
| 10593 | current = current.n; |
| 10594 | } else { |
no test coverage detected