(x0, y0, x1, y1)
| 2644 | } |
| 2645 | var d3_geo_clipViewMAX = 1e9; |
| 2646 | function d3_geo_clipView(x0, y0, x1, y1) { |
| 2647 | return function(listener) { |
| 2648 | var listener_ = listener, bufferListener = d3_geo_clipBufferListener(), segments, polygon, ring; |
| 2649 | var clip = { |
| 2650 | point: point, |
| 2651 | lineStart: lineStart, |
| 2652 | lineEnd: lineEnd, |
| 2653 | polygonStart: function() { |
| 2654 | listener = bufferListener; |
| 2655 | segments = []; |
| 2656 | polygon = []; |
| 2657 | }, |
| 2658 | polygonEnd: function() { |
| 2659 | listener = listener_; |
| 2660 | if ((segments = d3.merge(segments)).length) { |
| 2661 | listener.polygonStart(); |
| 2662 | d3_geo_clipPolygon(segments, compare, inside, interpolate, listener); |
| 2663 | listener.polygonEnd(); |
| 2664 | } else if (insidePolygon([ x0, y0 ])) { |
| 2665 | listener.polygonStart(), listener.lineStart(); |
| 2666 | interpolate(null, null, 1, listener); |
| 2667 | listener.lineEnd(), listener.polygonEnd(); |
| 2668 | } |
| 2669 | segments = polygon = ring = null; |
| 2670 | } |
| 2671 | }; |
| 2672 | function inside(point) { |
| 2673 | var a = corner(point, -1), i = insidePolygon([ a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0 ]); |
| 2674 | return i; |
| 2675 | } |
| 2676 | function insidePolygon(p) { |
| 2677 | var wn = 0, n = polygon.length, y = p[1]; |
| 2678 | for (var i = 0; i < n; ++i) { |
| 2679 | for (var j = 1, v = polygon[i], m = v.length, a = v[0]; j < m; ++j) { |
| 2680 | b = v[j]; |
| 2681 | if (a[1] <= y) { |
| 2682 | if (b[1] > y && isLeft(a, b, p) > 0) ++wn; |
| 2683 | } else { |
| 2684 | if (b[1] <= y && isLeft(a, b, p) < 0) --wn; |
| 2685 | } |
| 2686 | a = b; |
| 2687 | } |
| 2688 | } |
| 2689 | return wn !== 0; |
| 2690 | } |
| 2691 | function isLeft(a, b, c) { |
| 2692 | return (b[0] - a[0]) * (c[1] - a[1]) - (c[0] - a[0]) * (b[1] - a[1]); |
| 2693 | } |
| 2694 | function interpolate(from, to, direction, listener) { |
| 2695 | var a = 0, a1 = 0; |
| 2696 | if (from == null || (a = corner(from, direction)) !== (a1 = corner(to, direction)) || comparePoints(from, to) < 0 ^ direction > 0) { |
| 2697 | do { |
| 2698 | listener.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0); |
| 2699 | } while ((a = (a + direction + 4) % 4) !== a1); |
| 2700 | } else { |
| 2701 | listener.point(to[0], to[1]); |
| 2702 | } |
| 2703 | } |
no test coverage detected