@mui/x-charts-vendor 9.0.0 → 9.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/d3-geo.d.ts +4 -0
  2. package/d3-geo.js +5 -0
  3. package/d3-geo.mjs +5 -0
  4. package/lib-vendor/d3-geo/LICENSE +34 -0
  5. package/lib-vendor/d3-geo/dist/d3-geo.js +2873 -0
  6. package/lib-vendor/d3-geo/dist/d3-geo.min.js +1957 -0
  7. package/lib-vendor/d3-geo/src/area.js +77 -0
  8. package/lib-vendor/d3-geo/src/bounds.js +169 -0
  9. package/lib-vendor/d3-geo/src/cartesian.js +42 -0
  10. package/lib-vendor/d3-geo/src/centroid.js +134 -0
  11. package/lib-vendor/d3-geo/src/circle.js +77 -0
  12. package/lib-vendor/d3-geo/src/clip/antimeridian.js +89 -0
  13. package/lib-vendor/d3-geo/src/clip/buffer.js +30 -0
  14. package/lib-vendor/d3-geo/src/clip/circle.js +173 -0
  15. package/lib-vendor/d3-geo/src/clip/extent.js +25 -0
  16. package/lib-vendor/d3-geo/src/clip/index.js +124 -0
  17. package/lib-vendor/d3-geo/src/clip/line.js +60 -0
  18. package/lib-vendor/d3-geo/src/clip/rectangle.js +159 -0
  19. package/lib-vendor/d3-geo/src/clip/rejoin.js +103 -0
  20. package/lib-vendor/d3-geo/src/compose.js +15 -0
  21. package/lib-vendor/d3-geo/src/constant.js +11 -0
  22. package/lib-vendor/d3-geo/src/contains.js +95 -0
  23. package/lib-vendor/d3-geo/src/distance.js +18 -0
  24. package/lib-vendor/d3-geo/src/graticule.js +118 -0
  25. package/lib-vendor/d3-geo/src/identity.js +8 -0
  26. package/lib-vendor/d3-geo/src/index.js +335 -0
  27. package/lib-vendor/d3-geo/src/interpolate.js +35 -0
  28. package/lib-vendor/d3-geo/src/length.js +50 -0
  29. package/lib-vendor/d3-geo/src/math.js +44 -0
  30. package/lib-vendor/d3-geo/src/noop.js +7 -0
  31. package/lib-vendor/d3-geo/src/path/area.js +50 -0
  32. package/lib-vendor/d3-geo/src/path/bounds.js +31 -0
  33. package/lib-vendor/d3-geo/src/path/centroid.js +89 -0
  34. package/lib-vendor/d3-geo/src/path/context.js +53 -0
  35. package/lib-vendor/d3-geo/src/path/index.js +71 -0
  36. package/lib-vendor/d3-geo/src/path/measure.js +47 -0
  37. package/lib-vendor/d3-geo/src/path/string.js +93 -0
  38. package/lib-vendor/d3-geo/src/pointEqual.js +10 -0
  39. package/lib-vendor/d3-geo/src/polygonContains.js +72 -0
  40. package/lib-vendor/d3-geo/src/projection/albers.js +11 -0
  41. package/lib-vendor/d3-geo/src/projection/albersUsa.js +118 -0
  42. package/lib-vendor/d3-geo/src/projection/azimuthal.js +26 -0
  43. package/lib-vendor/d3-geo/src/projection/azimuthalEqualArea.js +20 -0
  44. package/lib-vendor/d3-geo/src/projection/azimuthalEquidistant.js +20 -0
  45. package/lib-vendor/d3-geo/src/projection/conic.js +18 -0
  46. package/lib-vendor/d3-geo/src/projection/conicConformal.js +39 -0
  47. package/lib-vendor/d3-geo/src/projection/conicEqualArea.js +33 -0
  48. package/lib-vendor/d3-geo/src/projection/conicEquidistant.js +31 -0
  49. package/lib-vendor/d3-geo/src/projection/cylindricalEqualArea.js +17 -0
  50. package/lib-vendor/d3-geo/src/projection/equalEarth.js +37 -0
  51. package/lib-vendor/d3-geo/src/projection/equirectangular.js +16 -0
  52. package/lib-vendor/d3-geo/src/projection/fit.js +52 -0
  53. package/lib-vendor/d3-geo/src/projection/gnomonic.js +20 -0
  54. package/lib-vendor/d3-geo/src/projection/identity.js +103 -0
  55. package/lib-vendor/d3-geo/src/projection/index.js +181 -0
  56. package/lib-vendor/d3-geo/src/projection/mercator.js +51 -0
  57. package/lib-vendor/d3-geo/src/projection/naturalEarth1.js +29 -0
  58. package/lib-vendor/d3-geo/src/projection/orthographic.js +18 -0
  59. package/lib-vendor/d3-geo/src/projection/resample.js +106 -0
  60. package/lib-vendor/d3-geo/src/projection/stereographic.js +22 -0
  61. package/lib-vendor/d3-geo/src/projection/transverseMercator.js +27 -0
  62. package/lib-vendor/d3-geo/src/rotation.js +65 -0
  63. package/lib-vendor/d3-geo/src/stream.js +83 -0
  64. package/lib-vendor/d3-geo/src/transform.js +42 -0
  65. package/package.json +18 -2
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = _default;
8
+ var _cartesian = require("../cartesian.js");
9
+ var _circle = require("../circle.js");
10
+ var _math = require("../math.js");
11
+ var _pointEqual = _interopRequireDefault(require("../pointEqual.js"));
12
+ var _index = _interopRequireDefault(require("./index.js"));
13
+ function _default(radius) {
14
+ var cr = (0, _math.cos)(radius),
15
+ delta = 2 * _math.radians,
16
+ smallRadius = cr > 0,
17
+ notHemisphere = (0, _math.abs)(cr) > _math.epsilon; // TODO optimise for this common case
18
+
19
+ function interpolate(from, to, direction, stream) {
20
+ (0, _circle.circleStream)(stream, radius, delta, direction, from, to);
21
+ }
22
+ function visible(lambda, phi) {
23
+ return (0, _math.cos)(lambda) * (0, _math.cos)(phi) > cr;
24
+ }
25
+
26
+ // Takes a line and cuts into visible segments. Return values used for polygon
27
+ // clipping: 0 - there were intersections or the line was empty; 1 - no
28
+ // intersections 2 - there were intersections, and the first and last segments
29
+ // should be rejoined.
30
+ function clipLine(stream) {
31
+ var point0,
32
+ // previous point
33
+ c0,
34
+ // code for previous point
35
+ v0,
36
+ // visibility of previous point
37
+ v00,
38
+ // visibility of first point
39
+ clean; // no intersections
40
+ return {
41
+ lineStart: function () {
42
+ v00 = v0 = false;
43
+ clean = 1;
44
+ },
45
+ point: function (lambda, phi) {
46
+ var point1 = [lambda, phi],
47
+ point2,
48
+ v = visible(lambda, phi),
49
+ c = smallRadius ? v ? 0 : code(lambda, phi) : v ? code(lambda + (lambda < 0 ? _math.pi : -_math.pi), phi) : 0;
50
+ if (!point0 && (v00 = v0 = v)) stream.lineStart();
51
+ if (v !== v0) {
52
+ point2 = intersect(point0, point1);
53
+ if (!point2 || (0, _pointEqual.default)(point0, point2) || (0, _pointEqual.default)(point1, point2)) point1[2] = 1;
54
+ }
55
+ if (v !== v0) {
56
+ clean = 0;
57
+ if (v) {
58
+ // outside going in
59
+ stream.lineStart();
60
+ point2 = intersect(point1, point0);
61
+ stream.point(point2[0], point2[1]);
62
+ } else {
63
+ // inside going out
64
+ point2 = intersect(point0, point1);
65
+ stream.point(point2[0], point2[1], 2);
66
+ stream.lineEnd();
67
+ }
68
+ point0 = point2;
69
+ } else if (notHemisphere && point0 && smallRadius ^ v) {
70
+ var t;
71
+ // If the codes for two points are different, or are both zero,
72
+ // and there this segment intersects with the small circle.
73
+ if (!(c & c0) && (t = intersect(point1, point0, true))) {
74
+ clean = 0;
75
+ if (smallRadius) {
76
+ stream.lineStart();
77
+ stream.point(t[0][0], t[0][1]);
78
+ stream.point(t[1][0], t[1][1]);
79
+ stream.lineEnd();
80
+ } else {
81
+ stream.point(t[1][0], t[1][1]);
82
+ stream.lineEnd();
83
+ stream.lineStart();
84
+ stream.point(t[0][0], t[0][1], 3);
85
+ }
86
+ }
87
+ }
88
+ if (v && (!point0 || !(0, _pointEqual.default)(point0, point1))) {
89
+ stream.point(point1[0], point1[1]);
90
+ }
91
+ point0 = point1, v0 = v, c0 = c;
92
+ },
93
+ lineEnd: function () {
94
+ if (v0) stream.lineEnd();
95
+ point0 = null;
96
+ },
97
+ // Rejoin first and last segments if there were intersections and the first
98
+ // and last points were visible.
99
+ clean: function () {
100
+ return clean | (v00 && v0) << 1;
101
+ }
102
+ };
103
+ }
104
+
105
+ // Intersects the great circle between a and b with the clip circle.
106
+ function intersect(a, b, two) {
107
+ var pa = (0, _cartesian.cartesian)(a),
108
+ pb = (0, _cartesian.cartesian)(b);
109
+
110
+ // We have two planes, n1.p = d1 and n2.p = d2.
111
+ // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
112
+ var n1 = [1, 0, 0],
113
+ // normal
114
+ n2 = (0, _cartesian.cartesianCross)(pa, pb),
115
+ n2n2 = (0, _cartesian.cartesianDot)(n2, n2),
116
+ n1n2 = n2[0],
117
+ // cartesianDot(n1, n2),
118
+ determinant = n2n2 - n1n2 * n1n2;
119
+
120
+ // Two polar points.
121
+ if (!determinant) return !two && a;
122
+ var c1 = cr * n2n2 / determinant,
123
+ c2 = -cr * n1n2 / determinant,
124
+ n1xn2 = (0, _cartesian.cartesianCross)(n1, n2),
125
+ A = (0, _cartesian.cartesianScale)(n1, c1),
126
+ B = (0, _cartesian.cartesianScale)(n2, c2);
127
+ (0, _cartesian.cartesianAddInPlace)(A, B);
128
+
129
+ // Solve |p(t)|^2 = 1.
130
+ var u = n1xn2,
131
+ w = (0, _cartesian.cartesianDot)(A, u),
132
+ uu = (0, _cartesian.cartesianDot)(u, u),
133
+ t2 = w * w - uu * ((0, _cartesian.cartesianDot)(A, A) - 1);
134
+ if (t2 < 0) return;
135
+ var t = (0, _math.sqrt)(t2),
136
+ q = (0, _cartesian.cartesianScale)(u, (-w - t) / uu);
137
+ (0, _cartesian.cartesianAddInPlace)(q, A);
138
+ q = (0, _cartesian.spherical)(q);
139
+ if (!two) return q;
140
+
141
+ // Two intersection points.
142
+ var lambda0 = a[0],
143
+ lambda1 = b[0],
144
+ phi0 = a[1],
145
+ phi1 = b[1],
146
+ z;
147
+ if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
148
+ var delta = lambda1 - lambda0,
149
+ polar = (0, _math.abs)(delta - _math.pi) < _math.epsilon,
150
+ meridian = polar || delta < _math.epsilon;
151
+ if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
152
+
153
+ // Check that the first point is between a and b.
154
+ if (meridian ? polar ? phi0 + phi1 > 0 ^ q[1] < ((0, _math.abs)(q[0] - lambda0) < _math.epsilon ? phi0 : phi1) : phi0 <= q[1] && q[1] <= phi1 : delta > _math.pi ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
155
+ var q1 = (0, _cartesian.cartesianScale)(u, (-w + t) / uu);
156
+ (0, _cartesian.cartesianAddInPlace)(q1, A);
157
+ return [q, (0, _cartesian.spherical)(q1)];
158
+ }
159
+ }
160
+
161
+ // Generates a 4-bit vector representing the location of a point relative to
162
+ // the small circle's bounding box.
163
+ function code(lambda, phi) {
164
+ var r = smallRadius ? radius : _math.pi - radius,
165
+ code = 0;
166
+ if (lambda < -r) code |= 1; // left
167
+ else if (lambda > r) code |= 2; // right
168
+ if (phi < -r) code |= 4; // below
169
+ else if (phi > r) code |= 8; // above
170
+ return code;
171
+ }
172
+ return (0, _index.default)(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-_math.pi, radius - _math.pi]);
173
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = _default;
8
+ var _rectangle = _interopRequireDefault(require("./rectangle.js"));
9
+ function _default() {
10
+ var x0 = 0,
11
+ y0 = 0,
12
+ x1 = 960,
13
+ y1 = 500,
14
+ cache,
15
+ cacheStream,
16
+ clip;
17
+ return clip = {
18
+ stream: function (stream) {
19
+ return cache && cacheStream === stream ? cache : cache = (0, _rectangle.default)(x0, y0, x1, y1)(cacheStream = stream);
20
+ },
21
+ extent: function (_) {
22
+ return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
23
+ }
24
+ };
25
+ }
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = _default;
8
+ var _buffer = _interopRequireDefault(require("./buffer.js"));
9
+ var _rejoin = _interopRequireDefault(require("./rejoin.js"));
10
+ var _math = require("../math.js");
11
+ var _polygonContains = _interopRequireDefault(require("../polygonContains.js"));
12
+ var _index = require("../../../d3-array/src/index.js");
13
+ function _default(pointVisible, clipLine, interpolate, start) {
14
+ return function (sink) {
15
+ var line = clipLine(sink),
16
+ ringBuffer = (0, _buffer.default)(),
17
+ ringSink = clipLine(ringBuffer),
18
+ polygonStarted = false,
19
+ polygon,
20
+ segments,
21
+ ring;
22
+ var clip = {
23
+ point: point,
24
+ lineStart: lineStart,
25
+ lineEnd: lineEnd,
26
+ polygonStart: function () {
27
+ clip.point = pointRing;
28
+ clip.lineStart = ringStart;
29
+ clip.lineEnd = ringEnd;
30
+ segments = [];
31
+ polygon = [];
32
+ },
33
+ polygonEnd: function () {
34
+ clip.point = point;
35
+ clip.lineStart = lineStart;
36
+ clip.lineEnd = lineEnd;
37
+ segments = (0, _index.merge)(segments);
38
+ var startInside = (0, _polygonContains.default)(polygon, start);
39
+ if (segments.length) {
40
+ if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
41
+ (0, _rejoin.default)(segments, compareIntersection, startInside, interpolate, sink);
42
+ } else if (startInside) {
43
+ if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
44
+ sink.lineStart();
45
+ interpolate(null, null, 1, sink);
46
+ sink.lineEnd();
47
+ }
48
+ if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
49
+ segments = polygon = null;
50
+ },
51
+ sphere: function () {
52
+ sink.polygonStart();
53
+ sink.lineStart();
54
+ interpolate(null, null, 1, sink);
55
+ sink.lineEnd();
56
+ sink.polygonEnd();
57
+ }
58
+ };
59
+ function point(lambda, phi) {
60
+ if (pointVisible(lambda, phi)) sink.point(lambda, phi);
61
+ }
62
+ function pointLine(lambda, phi) {
63
+ line.point(lambda, phi);
64
+ }
65
+ function lineStart() {
66
+ clip.point = pointLine;
67
+ line.lineStart();
68
+ }
69
+ function lineEnd() {
70
+ clip.point = point;
71
+ line.lineEnd();
72
+ }
73
+ function pointRing(lambda, phi) {
74
+ ring.push([lambda, phi]);
75
+ ringSink.point(lambda, phi);
76
+ }
77
+ function ringStart() {
78
+ ringSink.lineStart();
79
+ ring = [];
80
+ }
81
+ function ringEnd() {
82
+ pointRing(ring[0][0], ring[0][1]);
83
+ ringSink.lineEnd();
84
+ var clean = ringSink.clean(),
85
+ ringSegments = ringBuffer.result(),
86
+ i,
87
+ n = ringSegments.length,
88
+ m,
89
+ segment,
90
+ point;
91
+ ring.pop();
92
+ polygon.push(ring);
93
+ ring = null;
94
+ if (!n) return;
95
+
96
+ // No intersections.
97
+ if (clean & 1) {
98
+ segment = ringSegments[0];
99
+ if ((m = segment.length - 1) > 0) {
100
+ if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
101
+ sink.lineStart();
102
+ for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
103
+ sink.lineEnd();
104
+ }
105
+ return;
106
+ }
107
+
108
+ // Rejoin connected segments.
109
+ // TODO reuse ringBuffer.rejoin()?
110
+ if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
111
+ segments.push(ringSegments.filter(validSegment));
112
+ }
113
+ return clip;
114
+ };
115
+ }
116
+ function validSegment(segment) {
117
+ return segment.length > 1;
118
+ }
119
+
120
+ // Intersections are sorted along the clip edge. For both antimeridian cutting
121
+ // and circle clipping, the same comparison is used.
122
+ function compareIntersection(a, b) {
123
+ return ((a = a.x)[0] < 0 ? a[1] - _math.halfPi - _math.epsilon : _math.halfPi - a[1]) - ((b = b.x)[0] < 0 ? b[1] - _math.halfPi - _math.epsilon : _math.halfPi - b[1]);
124
+ }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = _default;
7
+ function _default(a, b, x0, y0, x1, y1) {
8
+ var ax = a[0],
9
+ ay = a[1],
10
+ bx = b[0],
11
+ by = b[1],
12
+ t0 = 0,
13
+ t1 = 1,
14
+ dx = bx - ax,
15
+ dy = by - ay,
16
+ r;
17
+ r = x0 - ax;
18
+ if (!dx && r > 0) return;
19
+ r /= dx;
20
+ if (dx < 0) {
21
+ if (r < t0) return;
22
+ if (r < t1) t1 = r;
23
+ } else if (dx > 0) {
24
+ if (r > t1) return;
25
+ if (r > t0) t0 = r;
26
+ }
27
+ r = x1 - ax;
28
+ if (!dx && r < 0) return;
29
+ r /= dx;
30
+ if (dx < 0) {
31
+ if (r > t1) return;
32
+ if (r > t0) t0 = r;
33
+ } else if (dx > 0) {
34
+ if (r < t0) return;
35
+ if (r < t1) t1 = r;
36
+ }
37
+ r = y0 - ay;
38
+ if (!dy && r > 0) return;
39
+ r /= dy;
40
+ if (dy < 0) {
41
+ if (r < t0) return;
42
+ if (r < t1) t1 = r;
43
+ } else if (dy > 0) {
44
+ if (r > t1) return;
45
+ if (r > t0) t0 = r;
46
+ }
47
+ r = y1 - ay;
48
+ if (!dy && r < 0) return;
49
+ r /= dy;
50
+ if (dy < 0) {
51
+ if (r > t1) return;
52
+ if (r > t0) t0 = r;
53
+ } else if (dy > 0) {
54
+ if (r < t0) return;
55
+ if (r < t1) t1 = r;
56
+ }
57
+ if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
58
+ if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
59
+ return true;
60
+ }
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = clipRectangle;
8
+ var _math = require("../math.js");
9
+ var _buffer = _interopRequireDefault(require("./buffer.js"));
10
+ var _line = _interopRequireDefault(require("./line.js"));
11
+ var _rejoin = _interopRequireDefault(require("./rejoin.js"));
12
+ var _index = require("../../../d3-array/src/index.js");
13
+ var clipMax = 1e9,
14
+ clipMin = -clipMax;
15
+
16
+ // TODO Use d3-polygon’s polygonContains here for the ring check?
17
+ // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
18
+
19
+ function clipRectangle(x0, y0, x1, y1) {
20
+ function visible(x, y) {
21
+ return x0 <= x && x <= x1 && y0 <= y && y <= y1;
22
+ }
23
+ function interpolate(from, to, direction, stream) {
24
+ var a = 0,
25
+ a1 = 0;
26
+ if (from == null || (a = corner(from, direction)) !== (a1 = corner(to, direction)) || comparePoint(from, to) < 0 ^ direction > 0) {
27
+ do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0); while ((a = (a + direction + 4) % 4) !== a1);
28
+ } else {
29
+ stream.point(to[0], to[1]);
30
+ }
31
+ }
32
+ function corner(p, direction) {
33
+ return (0, _math.abs)(p[0] - x0) < _math.epsilon ? direction > 0 ? 0 : 3 : (0, _math.abs)(p[0] - x1) < _math.epsilon ? direction > 0 ? 2 : 1 : (0, _math.abs)(p[1] - y0) < _math.epsilon ? direction > 0 ? 1 : 0 : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
34
+ }
35
+ function compareIntersection(a, b) {
36
+ return comparePoint(a.x, b.x);
37
+ }
38
+ function comparePoint(a, b) {
39
+ var ca = corner(a, 1),
40
+ cb = corner(b, 1);
41
+ return ca !== cb ? ca - cb : ca === 0 ? b[1] - a[1] : ca === 1 ? a[0] - b[0] : ca === 2 ? a[1] - b[1] : b[0] - a[0];
42
+ }
43
+ return function (stream) {
44
+ var activeStream = stream,
45
+ bufferStream = (0, _buffer.default)(),
46
+ segments,
47
+ polygon,
48
+ ring,
49
+ x__,
50
+ y__,
51
+ v__,
52
+ // first point
53
+ x_,
54
+ y_,
55
+ v_,
56
+ // previous point
57
+ first,
58
+ clean;
59
+ var clipStream = {
60
+ point: point,
61
+ lineStart: lineStart,
62
+ lineEnd: lineEnd,
63
+ polygonStart: polygonStart,
64
+ polygonEnd: polygonEnd
65
+ };
66
+ function point(x, y) {
67
+ if (visible(x, y)) activeStream.point(x, y);
68
+ }
69
+ function polygonInside() {
70
+ var winding = 0;
71
+ for (var i = 0, n = polygon.length; i < n; ++i) {
72
+ for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
73
+ a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
74
+ if (a1 <= y1) {
75
+ if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding;
76
+ } else {
77
+ if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding;
78
+ }
79
+ }
80
+ }
81
+ return winding;
82
+ }
83
+
84
+ // Buffer geometry within a polygon and then clip it en masse.
85
+ function polygonStart() {
86
+ activeStream = bufferStream, segments = [], polygon = [], clean = true;
87
+ }
88
+ function polygonEnd() {
89
+ var startInside = polygonInside(),
90
+ cleanInside = clean && startInside,
91
+ visible = (segments = (0, _index.merge)(segments)).length;
92
+ if (cleanInside || visible) {
93
+ stream.polygonStart();
94
+ if (cleanInside) {
95
+ stream.lineStart();
96
+ interpolate(null, null, 1, stream);
97
+ stream.lineEnd();
98
+ }
99
+ if (visible) {
100
+ (0, _rejoin.default)(segments, compareIntersection, startInside, interpolate, stream);
101
+ }
102
+ stream.polygonEnd();
103
+ }
104
+ activeStream = stream, segments = polygon = ring = null;
105
+ }
106
+ function lineStart() {
107
+ clipStream.point = linePoint;
108
+ if (polygon) polygon.push(ring = []);
109
+ first = true;
110
+ v_ = false;
111
+ x_ = y_ = NaN;
112
+ }
113
+
114
+ // TODO rather than special-case polygons, simply handle them separately.
115
+ // Ideally, coincident intersection points should be jittered to avoid
116
+ // clipping issues.
117
+ function lineEnd() {
118
+ if (segments) {
119
+ linePoint(x__, y__);
120
+ if (v__ && v_) bufferStream.rejoin();
121
+ segments.push(bufferStream.result());
122
+ }
123
+ clipStream.point = point;
124
+ if (v_) activeStream.lineEnd();
125
+ }
126
+ function linePoint(x, y) {
127
+ var v = visible(x, y);
128
+ if (polygon) ring.push([x, y]);
129
+ if (first) {
130
+ x__ = x, y__ = y, v__ = v;
131
+ first = false;
132
+ if (v) {
133
+ activeStream.lineStart();
134
+ activeStream.point(x, y);
135
+ }
136
+ } else {
137
+ if (v && v_) activeStream.point(x, y);else {
138
+ var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
139
+ b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
140
+ if ((0, _line.default)(a, b, x0, y0, x1, y1)) {
141
+ if (!v_) {
142
+ activeStream.lineStart();
143
+ activeStream.point(a[0], a[1]);
144
+ }
145
+ activeStream.point(b[0], b[1]);
146
+ if (!v) activeStream.lineEnd();
147
+ clean = false;
148
+ } else if (v) {
149
+ activeStream.lineStart();
150
+ activeStream.point(x, y);
151
+ clean = false;
152
+ }
153
+ }
154
+ }
155
+ x_ = x, y_ = y, v_ = v;
156
+ }
157
+ return clipStream;
158
+ };
159
+ }
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = _default;
8
+ var _pointEqual = _interopRequireDefault(require("../pointEqual.js"));
9
+ var _math = require("../math.js");
10
+ function Intersection(point, points, other, entry) {
11
+ this.x = point;
12
+ this.z = points;
13
+ this.o = other; // another intersection
14
+ this.e = entry; // is an entry?
15
+ this.v = false; // visited
16
+ this.n = this.p = null; // next & previous
17
+ }
18
+
19
+ // A generalized polygon clipping algorithm: given a polygon that has been cut
20
+ // into its visible line segments, and rejoins the segments by interpolating
21
+ // along the clip edge.
22
+ function _default(segments, compareIntersection, startInside, interpolate, stream) {
23
+ var subject = [],
24
+ clip = [],
25
+ i,
26
+ n;
27
+ segments.forEach(function (segment) {
28
+ if ((n = segment.length - 1) <= 0) return;
29
+ var n,
30
+ p0 = segment[0],
31
+ p1 = segment[n],
32
+ x;
33
+ if ((0, _pointEqual.default)(p0, p1)) {
34
+ if (!p0[2] && !p1[2]) {
35
+ stream.lineStart();
36
+ for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
37
+ stream.lineEnd();
38
+ return;
39
+ }
40
+ // handle degenerate cases by moving the point
41
+ p1[0] += 2 * _math.epsilon;
42
+ }
43
+ subject.push(x = new Intersection(p0, segment, null, true));
44
+ clip.push(x.o = new Intersection(p0, null, x, false));
45
+ subject.push(x = new Intersection(p1, segment, null, false));
46
+ clip.push(x.o = new Intersection(p1, null, x, true));
47
+ });
48
+ if (!subject.length) return;
49
+ clip.sort(compareIntersection);
50
+ link(subject);
51
+ link(clip);
52
+ for (i = 0, n = clip.length; i < n; ++i) {
53
+ clip[i].e = startInside = !startInside;
54
+ }
55
+ var start = subject[0],
56
+ points,
57
+ point;
58
+ while (1) {
59
+ // Find first unvisited intersection.
60
+ var current = start,
61
+ isSubject = true;
62
+ while (current.v) if ((current = current.n) === start) return;
63
+ points = current.z;
64
+ stream.lineStart();
65
+ do {
66
+ current.v = current.o.v = true;
67
+ if (current.e) {
68
+ if (isSubject) {
69
+ for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
70
+ } else {
71
+ interpolate(current.x, current.n.x, 1, stream);
72
+ }
73
+ current = current.n;
74
+ } else {
75
+ if (isSubject) {
76
+ points = current.p.z;
77
+ for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
78
+ } else {
79
+ interpolate(current.x, current.p.x, -1, stream);
80
+ }
81
+ current = current.p;
82
+ }
83
+ current = current.o;
84
+ points = current.z;
85
+ isSubject = !isSubject;
86
+ } while (!current.v);
87
+ stream.lineEnd();
88
+ }
89
+ }
90
+ function link(array) {
91
+ if (!(n = array.length)) return;
92
+ var n,
93
+ i = 0,
94
+ a = array[0],
95
+ b;
96
+ while (++i < n) {
97
+ a.n = b = array[i];
98
+ b.p = a;
99
+ a = b;
100
+ }
101
+ a.n = b = array[0];
102
+ b.p = a;
103
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = _default;
7
+ function _default(a, b) {
8
+ function compose(x, y) {
9
+ return x = a(x, y), b(x[0], x[1]);
10
+ }
11
+ if (a.invert && b.invert) compose.invert = function (x, y) {
12
+ return x = b.invert(x, y), x && a.invert(x[0], x[1]);
13
+ };
14
+ return compose;
15
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = _default;
7
+ function _default(x) {
8
+ return function () {
9
+ return x;
10
+ };
11
+ }