MCPcopy Create free account
hub / github.com/breck7/scroll / clipRejoin

Function clipRejoin

external/.d3.js:10537–10609  ·  view source on GitHub ↗
(segments, compareIntersection, startInside, interpolate, stream)

Source from the content-addressed store, hash-verified

10535// into its visible line segments, and rejoins the segments by interpolating
10536// along the clip edge.
10537function 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 {

Callers 2

clipFunction · 0.85
polygonEndFunction · 0.85

Calls 8

pointEqualFunction · 0.85
link$1Function · 0.85
interpolateFunction · 0.85
forEachMethod · 0.80
sortMethod · 0.80
lineStartMethod · 0.45
pointMethod · 0.45
lineEndMethod · 0.45

Tested by

no test coverage detected