@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,2873 @@
1
+ "use strict";
2
+
3
+ // https://d3js.org/d3-geo/ v3.1.1 Copyright 2010-2024 Mike Bostock, 2008-2012 Charles Karney
4
+ (function (global, factory) {
5
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require("../../d3-array/src/index.js")) : typeof define === 'function' && define.amd ? define(['exports', 'd3-array'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3 = global.d3 || {}, global.d3));
6
+ })(this, function (exports, d3Array) {
7
+ 'use strict';
8
+
9
+ var epsilon = 1e-6;
10
+ var epsilon2 = 1e-12;
11
+ var pi = Math.PI;
12
+ var halfPi = pi / 2;
13
+ var quarterPi = pi / 4;
14
+ var tau = pi * 2;
15
+ var degrees = 180 / pi;
16
+ var radians = pi / 180;
17
+ var abs = Math.abs;
18
+ var atan = Math.atan;
19
+ var atan2 = Math.atan2;
20
+ var cos = Math.cos;
21
+ var ceil = Math.ceil;
22
+ var exp = Math.exp;
23
+ var hypot = Math.hypot;
24
+ var log = Math.log;
25
+ var pow = Math.pow;
26
+ var sin = Math.sin;
27
+ var sign = Math.sign || function (x) {
28
+ return x > 0 ? 1 : x < 0 ? -1 : 0;
29
+ };
30
+ var sqrt = Math.sqrt;
31
+ var tan = Math.tan;
32
+ function acos(x) {
33
+ return x > 1 ? 0 : x < -1 ? pi : Math.acos(x);
34
+ }
35
+ function asin(x) {
36
+ return x > 1 ? halfPi : x < -1 ? -halfPi : Math.asin(x);
37
+ }
38
+ function haversin(x) {
39
+ return (x = sin(x / 2)) * x;
40
+ }
41
+ function noop() {}
42
+ function streamGeometry(geometry, stream) {
43
+ if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
44
+ streamGeometryType[geometry.type](geometry, stream);
45
+ }
46
+ }
47
+ var streamObjectType = {
48
+ Feature: function (object, stream) {
49
+ streamGeometry(object.geometry, stream);
50
+ },
51
+ FeatureCollection: function (object, stream) {
52
+ var features = object.features,
53
+ i = -1,
54
+ n = features.length;
55
+ while (++i < n) streamGeometry(features[i].geometry, stream);
56
+ }
57
+ };
58
+ var streamGeometryType = {
59
+ Sphere: function (object, stream) {
60
+ stream.sphere();
61
+ },
62
+ Point: function (object, stream) {
63
+ object = object.coordinates;
64
+ stream.point(object[0], object[1], object[2]);
65
+ },
66
+ MultiPoint: function (object, stream) {
67
+ var coordinates = object.coordinates,
68
+ i = -1,
69
+ n = coordinates.length;
70
+ while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
71
+ },
72
+ LineString: function (object, stream) {
73
+ streamLine(object.coordinates, stream, 0);
74
+ },
75
+ MultiLineString: function (object, stream) {
76
+ var coordinates = object.coordinates,
77
+ i = -1,
78
+ n = coordinates.length;
79
+ while (++i < n) streamLine(coordinates[i], stream, 0);
80
+ },
81
+ Polygon: function (object, stream) {
82
+ streamPolygon(object.coordinates, stream);
83
+ },
84
+ MultiPolygon: function (object, stream) {
85
+ var coordinates = object.coordinates,
86
+ i = -1,
87
+ n = coordinates.length;
88
+ while (++i < n) streamPolygon(coordinates[i], stream);
89
+ },
90
+ GeometryCollection: function (object, stream) {
91
+ var geometries = object.geometries,
92
+ i = -1,
93
+ n = geometries.length;
94
+ while (++i < n) streamGeometry(geometries[i], stream);
95
+ }
96
+ };
97
+ function streamLine(coordinates, stream, closed) {
98
+ var i = -1,
99
+ n = coordinates.length - closed,
100
+ coordinate;
101
+ stream.lineStart();
102
+ while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
103
+ stream.lineEnd();
104
+ }
105
+ function streamPolygon(coordinates, stream) {
106
+ var i = -1,
107
+ n = coordinates.length;
108
+ stream.polygonStart();
109
+ while (++i < n) streamLine(coordinates[i], stream, 1);
110
+ stream.polygonEnd();
111
+ }
112
+ function geoStream(object, stream) {
113
+ if (object && streamObjectType.hasOwnProperty(object.type)) {
114
+ streamObjectType[object.type](object, stream);
115
+ } else {
116
+ streamGeometry(object, stream);
117
+ }
118
+ }
119
+ var areaRingSum$1 = new d3Array.Adder();
120
+
121
+ // hello?
122
+
123
+ var areaSum$1 = new d3Array.Adder(),
124
+ lambda00$2,
125
+ phi00$2,
126
+ lambda0$2,
127
+ cosPhi0$1,
128
+ sinPhi0$1;
129
+ var areaStream$1 = {
130
+ point: noop,
131
+ lineStart: noop,
132
+ lineEnd: noop,
133
+ polygonStart: function () {
134
+ areaRingSum$1 = new d3Array.Adder();
135
+ areaStream$1.lineStart = areaRingStart$1;
136
+ areaStream$1.lineEnd = areaRingEnd$1;
137
+ },
138
+ polygonEnd: function () {
139
+ var areaRing = +areaRingSum$1;
140
+ areaSum$1.add(areaRing < 0 ? tau + areaRing : areaRing);
141
+ this.lineStart = this.lineEnd = this.point = noop;
142
+ },
143
+ sphere: function () {
144
+ areaSum$1.add(tau);
145
+ }
146
+ };
147
+ function areaRingStart$1() {
148
+ areaStream$1.point = areaPointFirst$1;
149
+ }
150
+ function areaRingEnd$1() {
151
+ areaPoint$1(lambda00$2, phi00$2);
152
+ }
153
+ function areaPointFirst$1(lambda, phi) {
154
+ areaStream$1.point = areaPoint$1;
155
+ lambda00$2 = lambda, phi00$2 = phi;
156
+ lambda *= radians, phi *= radians;
157
+ lambda0$2 = lambda, cosPhi0$1 = cos(phi = phi / 2 + quarterPi), sinPhi0$1 = sin(phi);
158
+ }
159
+ function areaPoint$1(lambda, phi) {
160
+ lambda *= radians, phi *= radians;
161
+ phi = phi / 2 + quarterPi; // half the angular distance from south pole
162
+
163
+ // Spherical excess E for a spherical triangle with vertices: south pole,
164
+ // previous point, current point. Uses a formula derived from Cagnoli’s
165
+ // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
166
+ var dLambda = lambda - lambda0$2,
167
+ sdLambda = dLambda >= 0 ? 1 : -1,
168
+ adLambda = sdLambda * dLambda,
169
+ cosPhi = cos(phi),
170
+ sinPhi = sin(phi),
171
+ k = sinPhi0$1 * sinPhi,
172
+ u = cosPhi0$1 * cosPhi + k * cos(adLambda),
173
+ v = k * sdLambda * sin(adLambda);
174
+ areaRingSum$1.add(atan2(v, u));
175
+
176
+ // Advance the previous points.
177
+ lambda0$2 = lambda, cosPhi0$1 = cosPhi, sinPhi0$1 = sinPhi;
178
+ }
179
+ function area(object) {
180
+ areaSum$1 = new d3Array.Adder();
181
+ geoStream(object, areaStream$1);
182
+ return areaSum$1 * 2;
183
+ }
184
+ function spherical(cartesian) {
185
+ return [atan2(cartesian[1], cartesian[0]), asin(cartesian[2])];
186
+ }
187
+ function cartesian(spherical) {
188
+ var lambda = spherical[0],
189
+ phi = spherical[1],
190
+ cosPhi = cos(phi);
191
+ return [cosPhi * cos(lambda), cosPhi * sin(lambda), sin(phi)];
192
+ }
193
+ function cartesianDot(a, b) {
194
+ return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
195
+ }
196
+ function cartesianCross(a, b) {
197
+ return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
198
+ }
199
+
200
+ // TODO return a
201
+ function cartesianAddInPlace(a, b) {
202
+ a[0] += b[0], a[1] += b[1], a[2] += b[2];
203
+ }
204
+ function cartesianScale(vector, k) {
205
+ return [vector[0] * k, vector[1] * k, vector[2] * k];
206
+ }
207
+
208
+ // TODO return d
209
+ function cartesianNormalizeInPlace(d) {
210
+ var l = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
211
+ d[0] /= l, d[1] /= l, d[2] /= l;
212
+ }
213
+ var lambda0$1, phi0, lambda1, phi1,
214
+ // bounds
215
+ lambda2,
216
+ // previous lambda-coordinate
217
+ lambda00$1, phi00$1,
218
+ // first point
219
+ p0,
220
+ // previous 3D point
221
+ deltaSum, ranges, range;
222
+ var boundsStream$1 = {
223
+ point: boundsPoint$1,
224
+ lineStart: boundsLineStart,
225
+ lineEnd: boundsLineEnd,
226
+ polygonStart: function () {
227
+ boundsStream$1.point = boundsRingPoint;
228
+ boundsStream$1.lineStart = boundsRingStart;
229
+ boundsStream$1.lineEnd = boundsRingEnd;
230
+ deltaSum = new d3Array.Adder();
231
+ areaStream$1.polygonStart();
232
+ },
233
+ polygonEnd: function () {
234
+ areaStream$1.polygonEnd();
235
+ boundsStream$1.point = boundsPoint$1;
236
+ boundsStream$1.lineStart = boundsLineStart;
237
+ boundsStream$1.lineEnd = boundsLineEnd;
238
+ if (areaRingSum$1 < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);else if (deltaSum > epsilon) phi1 = 90;else if (deltaSum < -epsilon) phi0 = -90;
239
+ range[0] = lambda0$1, range[1] = lambda1;
240
+ },
241
+ sphere: function () {
242
+ lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
243
+ }
244
+ };
245
+ function boundsPoint$1(lambda, phi) {
246
+ ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
247
+ if (phi < phi0) phi0 = phi;
248
+ if (phi > phi1) phi1 = phi;
249
+ }
250
+ function linePoint(lambda, phi) {
251
+ var p = cartesian([lambda * radians, phi * radians]);
252
+ if (p0) {
253
+ var normal = cartesianCross(p0, p),
254
+ equatorial = [normal[1], -normal[0], 0],
255
+ inflection = cartesianCross(equatorial, normal);
256
+ cartesianNormalizeInPlace(inflection);
257
+ inflection = spherical(inflection);
258
+ var delta = lambda - lambda2,
259
+ sign = delta > 0 ? 1 : -1,
260
+ lambdai = inflection[0] * degrees * sign,
261
+ phii,
262
+ antimeridian = abs(delta) > 180;
263
+ if (antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
264
+ phii = inflection[1] * degrees;
265
+ if (phii > phi1) phi1 = phii;
266
+ } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
267
+ phii = -inflection[1] * degrees;
268
+ if (phii < phi0) phi0 = phii;
269
+ } else {
270
+ if (phi < phi0) phi0 = phi;
271
+ if (phi > phi1) phi1 = phi;
272
+ }
273
+ if (antimeridian) {
274
+ if (lambda < lambda2) {
275
+ if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
276
+ } else {
277
+ if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
278
+ }
279
+ } else {
280
+ if (lambda1 >= lambda0$1) {
281
+ if (lambda < lambda0$1) lambda0$1 = lambda;
282
+ if (lambda > lambda1) lambda1 = lambda;
283
+ } else {
284
+ if (lambda > lambda2) {
285
+ if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
286
+ } else {
287
+ if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
288
+ }
289
+ }
290
+ }
291
+ } else {
292
+ ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
293
+ }
294
+ if (phi < phi0) phi0 = phi;
295
+ if (phi > phi1) phi1 = phi;
296
+ p0 = p, lambda2 = lambda;
297
+ }
298
+ function boundsLineStart() {
299
+ boundsStream$1.point = linePoint;
300
+ }
301
+ function boundsLineEnd() {
302
+ range[0] = lambda0$1, range[1] = lambda1;
303
+ boundsStream$1.point = boundsPoint$1;
304
+ p0 = null;
305
+ }
306
+ function boundsRingPoint(lambda, phi) {
307
+ if (p0) {
308
+ var delta = lambda - lambda2;
309
+ deltaSum.add(abs(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
310
+ } else {
311
+ lambda00$1 = lambda, phi00$1 = phi;
312
+ }
313
+ areaStream$1.point(lambda, phi);
314
+ linePoint(lambda, phi);
315
+ }
316
+ function boundsRingStart() {
317
+ areaStream$1.lineStart();
318
+ }
319
+ function boundsRingEnd() {
320
+ boundsRingPoint(lambda00$1, phi00$1);
321
+ areaStream$1.lineEnd();
322
+ if (abs(deltaSum) > epsilon) lambda0$1 = -(lambda1 = 180);
323
+ range[0] = lambda0$1, range[1] = lambda1;
324
+ p0 = null;
325
+ }
326
+
327
+ // Finds the left-right distance between two longitudes.
328
+ // This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
329
+ // the distance between ±180° to be 360°.
330
+ function angle(lambda0, lambda1) {
331
+ return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
332
+ }
333
+ function rangeCompare(a, b) {
334
+ return a[0] - b[0];
335
+ }
336
+ function rangeContains(range, x) {
337
+ return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
338
+ }
339
+ function bounds(feature) {
340
+ var i, n, a, b, merged, deltaMax, delta;
341
+ phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
342
+ ranges = [];
343
+ geoStream(feature, boundsStream$1);
344
+
345
+ // First, sort ranges by their minimum longitudes.
346
+ if (n = ranges.length) {
347
+ ranges.sort(rangeCompare);
348
+
349
+ // Then, merge any ranges that overlap.
350
+ for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
351
+ b = ranges[i];
352
+ if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
353
+ if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
354
+ if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
355
+ } else {
356
+ merged.push(a = b);
357
+ }
358
+ }
359
+
360
+ // Finally, find the largest gap between the merged ranges.
361
+ // The final bounding box will be the inverse of this gap.
362
+ for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
363
+ b = merged[i];
364
+ if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
365
+ }
366
+ }
367
+ ranges = range = null;
368
+ return lambda0$1 === Infinity || phi0 === Infinity ? [[NaN, NaN], [NaN, NaN]] : [[lambda0$1, phi0], [lambda1, phi1]];
369
+ }
370
+ var W0, W1, X0$1, Y0$1, Z0$1, X1$1, Y1$1, Z1$1, X2$1, Y2$1, Z2$1, lambda00, phi00,
371
+ // first point
372
+ x0$4, y0$4, z0; // previous point
373
+
374
+ var centroidStream$1 = {
375
+ sphere: noop,
376
+ point: centroidPoint$1,
377
+ lineStart: centroidLineStart$1,
378
+ lineEnd: centroidLineEnd$1,
379
+ polygonStart: function () {
380
+ centroidStream$1.lineStart = centroidRingStart$1;
381
+ centroidStream$1.lineEnd = centroidRingEnd$1;
382
+ },
383
+ polygonEnd: function () {
384
+ centroidStream$1.lineStart = centroidLineStart$1;
385
+ centroidStream$1.lineEnd = centroidLineEnd$1;
386
+ }
387
+ };
388
+
389
+ // Arithmetic mean of Cartesian vectors.
390
+ function centroidPoint$1(lambda, phi) {
391
+ lambda *= radians, phi *= radians;
392
+ var cosPhi = cos(phi);
393
+ centroidPointCartesian(cosPhi * cos(lambda), cosPhi * sin(lambda), sin(phi));
394
+ }
395
+ function centroidPointCartesian(x, y, z) {
396
+ ++W0;
397
+ X0$1 += (x - X0$1) / W0;
398
+ Y0$1 += (y - Y0$1) / W0;
399
+ Z0$1 += (z - Z0$1) / W0;
400
+ }
401
+ function centroidLineStart$1() {
402
+ centroidStream$1.point = centroidLinePointFirst;
403
+ }
404
+ function centroidLinePointFirst(lambda, phi) {
405
+ lambda *= radians, phi *= radians;
406
+ var cosPhi = cos(phi);
407
+ x0$4 = cosPhi * cos(lambda);
408
+ y0$4 = cosPhi * sin(lambda);
409
+ z0 = sin(phi);
410
+ centroidStream$1.point = centroidLinePoint;
411
+ centroidPointCartesian(x0$4, y0$4, z0);
412
+ }
413
+ function centroidLinePoint(lambda, phi) {
414
+ lambda *= radians, phi *= radians;
415
+ var cosPhi = cos(phi),
416
+ x = cosPhi * cos(lambda),
417
+ y = cosPhi * sin(lambda),
418
+ z = sin(phi),
419
+ w = atan2(sqrt((w = y0$4 * z - z0 * y) * w + (w = z0 * x - x0$4 * z) * w + (w = x0$4 * y - y0$4 * x) * w), x0$4 * x + y0$4 * y + z0 * z);
420
+ W1 += w;
421
+ X1$1 += w * (x0$4 + (x0$4 = x));
422
+ Y1$1 += w * (y0$4 + (y0$4 = y));
423
+ Z1$1 += w * (z0 + (z0 = z));
424
+ centroidPointCartesian(x0$4, y0$4, z0);
425
+ }
426
+ function centroidLineEnd$1() {
427
+ centroidStream$1.point = centroidPoint$1;
428
+ }
429
+
430
+ // See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
431
+ // J. Applied Mechanics 42, 239 (1975).
432
+ function centroidRingStart$1() {
433
+ centroidStream$1.point = centroidRingPointFirst;
434
+ }
435
+ function centroidRingEnd$1() {
436
+ centroidRingPoint(lambda00, phi00);
437
+ centroidStream$1.point = centroidPoint$1;
438
+ }
439
+ function centroidRingPointFirst(lambda, phi) {
440
+ lambda00 = lambda, phi00 = phi;
441
+ lambda *= radians, phi *= radians;
442
+ centroidStream$1.point = centroidRingPoint;
443
+ var cosPhi = cos(phi);
444
+ x0$4 = cosPhi * cos(lambda);
445
+ y0$4 = cosPhi * sin(lambda);
446
+ z0 = sin(phi);
447
+ centroidPointCartesian(x0$4, y0$4, z0);
448
+ }
449
+ function centroidRingPoint(lambda, phi) {
450
+ lambda *= radians, phi *= radians;
451
+ var cosPhi = cos(phi),
452
+ x = cosPhi * cos(lambda),
453
+ y = cosPhi * sin(lambda),
454
+ z = sin(phi),
455
+ cx = y0$4 * z - z0 * y,
456
+ cy = z0 * x - x0$4 * z,
457
+ cz = x0$4 * y - y0$4 * x,
458
+ m = hypot(cx, cy, cz),
459
+ w = asin(m),
460
+ // line weight = angle
461
+ v = m && -w / m; // area weight multiplier
462
+ X2$1.add(v * cx);
463
+ Y2$1.add(v * cy);
464
+ Z2$1.add(v * cz);
465
+ W1 += w;
466
+ X1$1 += w * (x0$4 + (x0$4 = x));
467
+ Y1$1 += w * (y0$4 + (y0$4 = y));
468
+ Z1$1 += w * (z0 + (z0 = z));
469
+ centroidPointCartesian(x0$4, y0$4, z0);
470
+ }
471
+ function centroid(object) {
472
+ W0 = W1 = X0$1 = Y0$1 = Z0$1 = X1$1 = Y1$1 = Z1$1 = 0;
473
+ X2$1 = new d3Array.Adder();
474
+ Y2$1 = new d3Array.Adder();
475
+ Z2$1 = new d3Array.Adder();
476
+ geoStream(object, centroidStream$1);
477
+ var x = +X2$1,
478
+ y = +Y2$1,
479
+ z = +Z2$1,
480
+ m = hypot(x, y, z);
481
+
482
+ // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
483
+ if (m < epsilon2) {
484
+ x = X1$1, y = Y1$1, z = Z1$1;
485
+ // If the feature has zero length, fall back to arithmetic mean of point vectors.
486
+ if (W1 < epsilon) x = X0$1, y = Y0$1, z = Z0$1;
487
+ m = hypot(x, y, z);
488
+ // If the feature still has an undefined ccentroid, then return.
489
+ if (m < epsilon2) return [NaN, NaN];
490
+ }
491
+ return [atan2(y, x) * degrees, asin(z / m) * degrees];
492
+ }
493
+ function constant(x) {
494
+ return function () {
495
+ return x;
496
+ };
497
+ }
498
+ function compose(a, b) {
499
+ function compose(x, y) {
500
+ return x = a(x, y), b(x[0], x[1]);
501
+ }
502
+ if (a.invert && b.invert) compose.invert = function (x, y) {
503
+ return x = b.invert(x, y), x && a.invert(x[0], x[1]);
504
+ };
505
+ return compose;
506
+ }
507
+ function rotationIdentity(lambda, phi) {
508
+ if (abs(lambda) > pi) lambda -= Math.round(lambda / tau) * tau;
509
+ return [lambda, phi];
510
+ }
511
+ rotationIdentity.invert = rotationIdentity;
512
+ function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
513
+ return (deltaLambda %= tau) ? deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma)) : rotationLambda(deltaLambda) : deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma) : rotationIdentity;
514
+ }
515
+ function forwardRotationLambda(deltaLambda) {
516
+ return function (lambda, phi) {
517
+ lambda += deltaLambda;
518
+ if (abs(lambda) > pi) lambda -= Math.round(lambda / tau) * tau;
519
+ return [lambda, phi];
520
+ };
521
+ }
522
+ function rotationLambda(deltaLambda) {
523
+ var rotation = forwardRotationLambda(deltaLambda);
524
+ rotation.invert = forwardRotationLambda(-deltaLambda);
525
+ return rotation;
526
+ }
527
+ function rotationPhiGamma(deltaPhi, deltaGamma) {
528
+ var cosDeltaPhi = cos(deltaPhi),
529
+ sinDeltaPhi = sin(deltaPhi),
530
+ cosDeltaGamma = cos(deltaGamma),
531
+ sinDeltaGamma = sin(deltaGamma);
532
+ function rotation(lambda, phi) {
533
+ var cosPhi = cos(phi),
534
+ x = cos(lambda) * cosPhi,
535
+ y = sin(lambda) * cosPhi,
536
+ z = sin(phi),
537
+ k = z * cosDeltaPhi + x * sinDeltaPhi;
538
+ return [atan2(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi), asin(k * cosDeltaGamma + y * sinDeltaGamma)];
539
+ }
540
+ rotation.invert = function (lambda, phi) {
541
+ var cosPhi = cos(phi),
542
+ x = cos(lambda) * cosPhi,
543
+ y = sin(lambda) * cosPhi,
544
+ z = sin(phi),
545
+ k = z * cosDeltaGamma - y * sinDeltaGamma;
546
+ return [atan2(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi), asin(k * cosDeltaPhi - x * sinDeltaPhi)];
547
+ };
548
+ return rotation;
549
+ }
550
+ function rotation(rotate) {
551
+ rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
552
+ function forward(coordinates) {
553
+ coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
554
+ return coordinates[0] *= degrees, coordinates[1] *= degrees, coordinates;
555
+ }
556
+ forward.invert = function (coordinates) {
557
+ coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
558
+ return coordinates[0] *= degrees, coordinates[1] *= degrees, coordinates;
559
+ };
560
+ return forward;
561
+ }
562
+
563
+ // Generates a circle centered at [0°, 0°], with a given radius and precision.
564
+ function circleStream(stream, radius, delta, direction, t0, t1) {
565
+ if (!delta) return;
566
+ var cosRadius = cos(radius),
567
+ sinRadius = sin(radius),
568
+ step = direction * delta;
569
+ if (t0 == null) {
570
+ t0 = radius + direction * tau;
571
+ t1 = radius - step / 2;
572
+ } else {
573
+ t0 = circleRadius(cosRadius, t0);
574
+ t1 = circleRadius(cosRadius, t1);
575
+ if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau;
576
+ }
577
+ for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
578
+ point = spherical([cosRadius, -sinRadius * cos(t), -sinRadius * sin(t)]);
579
+ stream.point(point[0], point[1]);
580
+ }
581
+ }
582
+
583
+ // Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
584
+ function circleRadius(cosRadius, point) {
585
+ point = cartesian(point), point[0] -= cosRadius;
586
+ cartesianNormalizeInPlace(point);
587
+ var radius = acos(-point[1]);
588
+ return ((-point[2] < 0 ? -radius : radius) + tau - epsilon) % tau;
589
+ }
590
+ function circle() {
591
+ var center = constant([0, 0]),
592
+ radius = constant(90),
593
+ precision = constant(2),
594
+ ring,
595
+ rotate,
596
+ stream = {
597
+ point: point
598
+ };
599
+ function point(x, y) {
600
+ ring.push(x = rotate(x, y));
601
+ x[0] *= degrees, x[1] *= degrees;
602
+ }
603
+ function circle() {
604
+ var c = center.apply(this, arguments),
605
+ r = radius.apply(this, arguments) * radians,
606
+ p = precision.apply(this, arguments) * radians;
607
+ ring = [];
608
+ rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
609
+ circleStream(stream, r, p, 1);
610
+ c = {
611
+ type: "Polygon",
612
+ coordinates: [ring]
613
+ };
614
+ ring = rotate = null;
615
+ return c;
616
+ }
617
+ circle.center = function (_) {
618
+ return arguments.length ? (center = typeof _ === "function" ? _ : constant([+_[0], +_[1]]), circle) : center;
619
+ };
620
+ circle.radius = function (_) {
621
+ return arguments.length ? (radius = typeof _ === "function" ? _ : constant(+_), circle) : radius;
622
+ };
623
+ circle.precision = function (_) {
624
+ return arguments.length ? (precision = typeof _ === "function" ? _ : constant(+_), circle) : precision;
625
+ };
626
+ return circle;
627
+ }
628
+ function clipBuffer() {
629
+ var lines = [],
630
+ line;
631
+ return {
632
+ point: function (x, y, m) {
633
+ line.push([x, y, m]);
634
+ },
635
+ lineStart: function () {
636
+ lines.push(line = []);
637
+ },
638
+ lineEnd: noop,
639
+ rejoin: function () {
640
+ if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
641
+ },
642
+ result: function () {
643
+ var result = lines;
644
+ lines = [];
645
+ line = null;
646
+ return result;
647
+ }
648
+ };
649
+ }
650
+ function pointEqual(a, b) {
651
+ return abs(a[0] - b[0]) < epsilon && abs(a[1] - b[1]) < epsilon;
652
+ }
653
+ function Intersection(point, points, other, entry) {
654
+ this.x = point;
655
+ this.z = points;
656
+ this.o = other; // another intersection
657
+ this.e = entry; // is an entry?
658
+ this.v = false; // visited
659
+ this.n = this.p = null; // next & previous
660
+ }
661
+
662
+ // A generalized polygon clipping algorithm: given a polygon that has been cut
663
+ // into its visible line segments, and rejoins the segments by interpolating
664
+ // along the clip edge.
665
+ function clipRejoin(segments, compareIntersection, startInside, interpolate, stream) {
666
+ var subject = [],
667
+ clip = [],
668
+ i,
669
+ n;
670
+ segments.forEach(function (segment) {
671
+ if ((n = segment.length - 1) <= 0) return;
672
+ var n,
673
+ p0 = segment[0],
674
+ p1 = segment[n],
675
+ x;
676
+ if (pointEqual(p0, p1)) {
677
+ if (!p0[2] && !p1[2]) {
678
+ stream.lineStart();
679
+ for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
680
+ stream.lineEnd();
681
+ return;
682
+ }
683
+ // handle degenerate cases by moving the point
684
+ p1[0] += 2 * epsilon;
685
+ }
686
+ subject.push(x = new Intersection(p0, segment, null, true));
687
+ clip.push(x.o = new Intersection(p0, null, x, false));
688
+ subject.push(x = new Intersection(p1, segment, null, false));
689
+ clip.push(x.o = new Intersection(p1, null, x, true));
690
+ });
691
+ if (!subject.length) return;
692
+ clip.sort(compareIntersection);
693
+ link(subject);
694
+ link(clip);
695
+ for (i = 0, n = clip.length; i < n; ++i) {
696
+ clip[i].e = startInside = !startInside;
697
+ }
698
+ var start = subject[0],
699
+ points,
700
+ point;
701
+ while (1) {
702
+ // Find first unvisited intersection.
703
+ var current = start,
704
+ isSubject = true;
705
+ while (current.v) if ((current = current.n) === start) return;
706
+ points = current.z;
707
+ stream.lineStart();
708
+ do {
709
+ current.v = current.o.v = true;
710
+ if (current.e) {
711
+ if (isSubject) {
712
+ for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
713
+ } else {
714
+ interpolate(current.x, current.n.x, 1, stream);
715
+ }
716
+ current = current.n;
717
+ } else {
718
+ if (isSubject) {
719
+ points = current.p.z;
720
+ for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
721
+ } else {
722
+ interpolate(current.x, current.p.x, -1, stream);
723
+ }
724
+ current = current.p;
725
+ }
726
+ current = current.o;
727
+ points = current.z;
728
+ isSubject = !isSubject;
729
+ } while (!current.v);
730
+ stream.lineEnd();
731
+ }
732
+ }
733
+ function link(array) {
734
+ if (!(n = array.length)) return;
735
+ var n,
736
+ i = 0,
737
+ a = array[0],
738
+ b;
739
+ while (++i < n) {
740
+ a.n = b = array[i];
741
+ b.p = a;
742
+ a = b;
743
+ }
744
+ a.n = b = array[0];
745
+ b.p = a;
746
+ }
747
+ function longitude(point) {
748
+ return abs(point[0]) <= pi ? point[0] : sign(point[0]) * ((abs(point[0]) + pi) % tau - pi);
749
+ }
750
+ function polygonContains(polygon, point) {
751
+ var lambda = longitude(point),
752
+ phi = point[1],
753
+ sinPhi = sin(phi),
754
+ normal = [sin(lambda), -cos(lambda), 0],
755
+ angle = 0,
756
+ winding = 0;
757
+ var sum = new d3Array.Adder();
758
+ if (sinPhi === 1) phi = halfPi + epsilon;else if (sinPhi === -1) phi = -halfPi - epsilon;
759
+ for (var i = 0, n = polygon.length; i < n; ++i) {
760
+ if (!(m = (ring = polygon[i]).length)) continue;
761
+ var ring,
762
+ m,
763
+ point0 = ring[m - 1],
764
+ lambda0 = longitude(point0),
765
+ phi0 = point0[1] / 2 + quarterPi,
766
+ sinPhi0 = sin(phi0),
767
+ cosPhi0 = cos(phi0);
768
+ for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
769
+ var point1 = ring[j],
770
+ lambda1 = longitude(point1),
771
+ phi1 = point1[1] / 2 + quarterPi,
772
+ sinPhi1 = sin(phi1),
773
+ cosPhi1 = cos(phi1),
774
+ delta = lambda1 - lambda0,
775
+ sign = delta >= 0 ? 1 : -1,
776
+ absDelta = sign * delta,
777
+ antimeridian = absDelta > pi,
778
+ k = sinPhi0 * sinPhi1;
779
+ sum.add(atan2(k * sign * sin(absDelta), cosPhi0 * cosPhi1 + k * cos(absDelta)));
780
+ angle += antimeridian ? delta + sign * tau : delta;
781
+
782
+ // Are the longitudes either side of the point’s meridian (lambda),
783
+ // and are the latitudes smaller than the parallel (phi)?
784
+ if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
785
+ var arc = cartesianCross(cartesian(point0), cartesian(point1));
786
+ cartesianNormalizeInPlace(arc);
787
+ var intersection = cartesianCross(normal, arc);
788
+ cartesianNormalizeInPlace(intersection);
789
+ var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin(intersection[2]);
790
+ if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
791
+ winding += antimeridian ^ delta >= 0 ? 1 : -1;
792
+ }
793
+ }
794
+ }
795
+ }
796
+
797
+ // First, determine whether the South pole is inside or outside:
798
+ //
799
+ // It is inside if:
800
+ // * the polygon winds around it in a clockwise direction.
801
+ // * the polygon does not (cumulatively) wind around it, but has a negative
802
+ // (counter-clockwise) area.
803
+ //
804
+ // Second, count the (signed) number of times a segment crosses a lambda
805
+ // from the point to the South pole. If it is zero, then the point is the
806
+ // same side as the South pole.
807
+
808
+ return (angle < -epsilon || angle < epsilon && sum < -epsilon2) ^ winding & 1;
809
+ }
810
+ function clip(pointVisible, clipLine, interpolate, start) {
811
+ return function (sink) {
812
+ var line = clipLine(sink),
813
+ ringBuffer = clipBuffer(),
814
+ ringSink = clipLine(ringBuffer),
815
+ polygonStarted = false,
816
+ polygon,
817
+ segments,
818
+ ring;
819
+ var clip = {
820
+ point: point,
821
+ lineStart: lineStart,
822
+ lineEnd: lineEnd,
823
+ polygonStart: function () {
824
+ clip.point = pointRing;
825
+ clip.lineStart = ringStart;
826
+ clip.lineEnd = ringEnd;
827
+ segments = [];
828
+ polygon = [];
829
+ },
830
+ polygonEnd: function () {
831
+ clip.point = point;
832
+ clip.lineStart = lineStart;
833
+ clip.lineEnd = lineEnd;
834
+ segments = d3Array.merge(segments);
835
+ var startInside = polygonContains(polygon, start);
836
+ if (segments.length) {
837
+ if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
838
+ clipRejoin(segments, compareIntersection, startInside, interpolate, sink);
839
+ } else if (startInside) {
840
+ if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
841
+ sink.lineStart();
842
+ interpolate(null, null, 1, sink);
843
+ sink.lineEnd();
844
+ }
845
+ if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
846
+ segments = polygon = null;
847
+ },
848
+ sphere: function () {
849
+ sink.polygonStart();
850
+ sink.lineStart();
851
+ interpolate(null, null, 1, sink);
852
+ sink.lineEnd();
853
+ sink.polygonEnd();
854
+ }
855
+ };
856
+ function point(lambda, phi) {
857
+ if (pointVisible(lambda, phi)) sink.point(lambda, phi);
858
+ }
859
+ function pointLine(lambda, phi) {
860
+ line.point(lambda, phi);
861
+ }
862
+ function lineStart() {
863
+ clip.point = pointLine;
864
+ line.lineStart();
865
+ }
866
+ function lineEnd() {
867
+ clip.point = point;
868
+ line.lineEnd();
869
+ }
870
+ function pointRing(lambda, phi) {
871
+ ring.push([lambda, phi]);
872
+ ringSink.point(lambda, phi);
873
+ }
874
+ function ringStart() {
875
+ ringSink.lineStart();
876
+ ring = [];
877
+ }
878
+ function ringEnd() {
879
+ pointRing(ring[0][0], ring[0][1]);
880
+ ringSink.lineEnd();
881
+ var clean = ringSink.clean(),
882
+ ringSegments = ringBuffer.result(),
883
+ i,
884
+ n = ringSegments.length,
885
+ m,
886
+ segment,
887
+ point;
888
+ ring.pop();
889
+ polygon.push(ring);
890
+ ring = null;
891
+ if (!n) return;
892
+
893
+ // No intersections.
894
+ if (clean & 1) {
895
+ segment = ringSegments[0];
896
+ if ((m = segment.length - 1) > 0) {
897
+ if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
898
+ sink.lineStart();
899
+ for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
900
+ sink.lineEnd();
901
+ }
902
+ return;
903
+ }
904
+
905
+ // Rejoin connected segments.
906
+ // TODO reuse ringBuffer.rejoin()?
907
+ if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
908
+ segments.push(ringSegments.filter(validSegment));
909
+ }
910
+ return clip;
911
+ };
912
+ }
913
+ function validSegment(segment) {
914
+ return segment.length > 1;
915
+ }
916
+
917
+ // Intersections are sorted along the clip edge. For both antimeridian cutting
918
+ // and circle clipping, the same comparison is used.
919
+ function compareIntersection(a, b) {
920
+ return ((a = a.x)[0] < 0 ? a[1] - halfPi - epsilon : halfPi - a[1]) - ((b = b.x)[0] < 0 ? b[1] - halfPi - epsilon : halfPi - b[1]);
921
+ }
922
+ var clipAntimeridian = clip(function () {
923
+ return true;
924
+ }, clipAntimeridianLine, clipAntimeridianInterpolate, [-pi, -halfPi]);
925
+
926
+ // Takes a line and cuts into visible segments. Return values: 0 - there were
927
+ // intersections or the line was empty; 1 - no intersections; 2 - there were
928
+ // intersections, and the first and last segments should be rejoined.
929
+ function clipAntimeridianLine(stream) {
930
+ var lambda0 = NaN,
931
+ phi0 = NaN,
932
+ sign0 = NaN,
933
+ clean; // no intersections
934
+
935
+ return {
936
+ lineStart: function () {
937
+ stream.lineStart();
938
+ clean = 1;
939
+ },
940
+ point: function (lambda1, phi1) {
941
+ var sign1 = lambda1 > 0 ? pi : -pi,
942
+ delta = abs(lambda1 - lambda0);
943
+ if (abs(delta - pi) < epsilon) {
944
+ // line crosses a pole
945
+ stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi : -halfPi);
946
+ stream.point(sign0, phi0);
947
+ stream.lineEnd();
948
+ stream.lineStart();
949
+ stream.point(sign1, phi0);
950
+ stream.point(lambda1, phi0);
951
+ clean = 0;
952
+ } else if (sign0 !== sign1 && delta >= pi) {
953
+ // line crosses antimeridian
954
+ if (abs(lambda0 - sign0) < epsilon) lambda0 -= sign0 * epsilon; // handle degeneracies
955
+ if (abs(lambda1 - sign1) < epsilon) lambda1 -= sign1 * epsilon;
956
+ phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
957
+ stream.point(sign0, phi0);
958
+ stream.lineEnd();
959
+ stream.lineStart();
960
+ stream.point(sign1, phi0);
961
+ clean = 0;
962
+ }
963
+ stream.point(lambda0 = lambda1, phi0 = phi1);
964
+ sign0 = sign1;
965
+ },
966
+ lineEnd: function () {
967
+ stream.lineEnd();
968
+ lambda0 = phi0 = NaN;
969
+ },
970
+ clean: function () {
971
+ return 2 - clean; // if intersections, rejoin first and last segments
972
+ }
973
+ };
974
+ }
975
+ function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
976
+ var cosPhi0,
977
+ cosPhi1,
978
+ sinLambda0Lambda1 = sin(lambda0 - lambda1);
979
+ return abs(sinLambda0Lambda1) > epsilon ? atan((sin(phi0) * (cosPhi1 = cos(phi1)) * sin(lambda1) - sin(phi1) * (cosPhi0 = cos(phi0)) * sin(lambda0)) / (cosPhi0 * cosPhi1 * sinLambda0Lambda1)) : (phi0 + phi1) / 2;
980
+ }
981
+ function clipAntimeridianInterpolate(from, to, direction, stream) {
982
+ var phi;
983
+ if (from == null) {
984
+ phi = direction * halfPi;
985
+ stream.point(-pi, phi);
986
+ stream.point(0, phi);
987
+ stream.point(pi, phi);
988
+ stream.point(pi, 0);
989
+ stream.point(pi, -phi);
990
+ stream.point(0, -phi);
991
+ stream.point(-pi, -phi);
992
+ stream.point(-pi, 0);
993
+ stream.point(-pi, phi);
994
+ } else if (abs(from[0] - to[0]) > epsilon) {
995
+ var lambda = from[0] < to[0] ? pi : -pi;
996
+ phi = direction * lambda / 2;
997
+ stream.point(-lambda, phi);
998
+ stream.point(0, phi);
999
+ stream.point(lambda, phi);
1000
+ } else {
1001
+ stream.point(to[0], to[1]);
1002
+ }
1003
+ }
1004
+ function clipCircle(radius) {
1005
+ var cr = cos(radius),
1006
+ delta = 2 * radians,
1007
+ smallRadius = cr > 0,
1008
+ notHemisphere = abs(cr) > epsilon; // TODO optimise for this common case
1009
+
1010
+ function interpolate(from, to, direction, stream) {
1011
+ circleStream(stream, radius, delta, direction, from, to);
1012
+ }
1013
+ function visible(lambda, phi) {
1014
+ return cos(lambda) * cos(phi) > cr;
1015
+ }
1016
+
1017
+ // Takes a line and cuts into visible segments. Return values used for polygon
1018
+ // clipping: 0 - there were intersections or the line was empty; 1 - no
1019
+ // intersections 2 - there were intersections, and the first and last segments
1020
+ // should be rejoined.
1021
+ function clipLine(stream) {
1022
+ var point0,
1023
+ // previous point
1024
+ c0,
1025
+ // code for previous point
1026
+ v0,
1027
+ // visibility of previous point
1028
+ v00,
1029
+ // visibility of first point
1030
+ clean; // no intersections
1031
+ return {
1032
+ lineStart: function () {
1033
+ v00 = v0 = false;
1034
+ clean = 1;
1035
+ },
1036
+ point: function (lambda, phi) {
1037
+ var point1 = [lambda, phi],
1038
+ point2,
1039
+ v = visible(lambda, phi),
1040
+ c = smallRadius ? v ? 0 : code(lambda, phi) : v ? code(lambda + (lambda < 0 ? pi : -pi), phi) : 0;
1041
+ if (!point0 && (v00 = v0 = v)) stream.lineStart();
1042
+ if (v !== v0) {
1043
+ point2 = intersect(point0, point1);
1044
+ if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2)) point1[2] = 1;
1045
+ }
1046
+ if (v !== v0) {
1047
+ clean = 0;
1048
+ if (v) {
1049
+ // outside going in
1050
+ stream.lineStart();
1051
+ point2 = intersect(point1, point0);
1052
+ stream.point(point2[0], point2[1]);
1053
+ } else {
1054
+ // inside going out
1055
+ point2 = intersect(point0, point1);
1056
+ stream.point(point2[0], point2[1], 2);
1057
+ stream.lineEnd();
1058
+ }
1059
+ point0 = point2;
1060
+ } else if (notHemisphere && point0 && smallRadius ^ v) {
1061
+ var t;
1062
+ // If the codes for two points are different, or are both zero,
1063
+ // and there this segment intersects with the small circle.
1064
+ if (!(c & c0) && (t = intersect(point1, point0, true))) {
1065
+ clean = 0;
1066
+ if (smallRadius) {
1067
+ stream.lineStart();
1068
+ stream.point(t[0][0], t[0][1]);
1069
+ stream.point(t[1][0], t[1][1]);
1070
+ stream.lineEnd();
1071
+ } else {
1072
+ stream.point(t[1][0], t[1][1]);
1073
+ stream.lineEnd();
1074
+ stream.lineStart();
1075
+ stream.point(t[0][0], t[0][1], 3);
1076
+ }
1077
+ }
1078
+ }
1079
+ if (v && (!point0 || !pointEqual(point0, point1))) {
1080
+ stream.point(point1[0], point1[1]);
1081
+ }
1082
+ point0 = point1, v0 = v, c0 = c;
1083
+ },
1084
+ lineEnd: function () {
1085
+ if (v0) stream.lineEnd();
1086
+ point0 = null;
1087
+ },
1088
+ // Rejoin first and last segments if there were intersections and the first
1089
+ // and last points were visible.
1090
+ clean: function () {
1091
+ return clean | (v00 && v0) << 1;
1092
+ }
1093
+ };
1094
+ }
1095
+
1096
+ // Intersects the great circle between a and b with the clip circle.
1097
+ function intersect(a, b, two) {
1098
+ var pa = cartesian(a),
1099
+ pb = cartesian(b);
1100
+
1101
+ // We have two planes, n1.p = d1 and n2.p = d2.
1102
+ // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
1103
+ var n1 = [1, 0, 0],
1104
+ // normal
1105
+ n2 = cartesianCross(pa, pb),
1106
+ n2n2 = cartesianDot(n2, n2),
1107
+ n1n2 = n2[0],
1108
+ // cartesianDot(n1, n2),
1109
+ determinant = n2n2 - n1n2 * n1n2;
1110
+
1111
+ // Two polar points.
1112
+ if (!determinant) return !two && a;
1113
+ var c1 = cr * n2n2 / determinant,
1114
+ c2 = -cr * n1n2 / determinant,
1115
+ n1xn2 = cartesianCross(n1, n2),
1116
+ A = cartesianScale(n1, c1),
1117
+ B = cartesianScale(n2, c2);
1118
+ cartesianAddInPlace(A, B);
1119
+
1120
+ // Solve |p(t)|^2 = 1.
1121
+ var u = n1xn2,
1122
+ w = cartesianDot(A, u),
1123
+ uu = cartesianDot(u, u),
1124
+ t2 = w * w - uu * (cartesianDot(A, A) - 1);
1125
+ if (t2 < 0) return;
1126
+ var t = sqrt(t2),
1127
+ q = cartesianScale(u, (-w - t) / uu);
1128
+ cartesianAddInPlace(q, A);
1129
+ q = spherical(q);
1130
+ if (!two) return q;
1131
+
1132
+ // Two intersection points.
1133
+ var lambda0 = a[0],
1134
+ lambda1 = b[0],
1135
+ phi0 = a[1],
1136
+ phi1 = b[1],
1137
+ z;
1138
+ if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
1139
+ var delta = lambda1 - lambda0,
1140
+ polar = abs(delta - pi) < epsilon,
1141
+ meridian = polar || delta < epsilon;
1142
+ if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
1143
+
1144
+ // Check that the first point is between a and b.
1145
+ if (meridian ? polar ? phi0 + phi1 > 0 ^ q[1] < (abs(q[0] - lambda0) < epsilon ? phi0 : phi1) : phi0 <= q[1] && q[1] <= phi1 : delta > pi ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
1146
+ var q1 = cartesianScale(u, (-w + t) / uu);
1147
+ cartesianAddInPlace(q1, A);
1148
+ return [q, spherical(q1)];
1149
+ }
1150
+ }
1151
+
1152
+ // Generates a 4-bit vector representing the location of a point relative to
1153
+ // the small circle's bounding box.
1154
+ function code(lambda, phi) {
1155
+ var r = smallRadius ? radius : pi - radius,
1156
+ code = 0;
1157
+ if (lambda < -r) code |= 1; // left
1158
+ else if (lambda > r) code |= 2; // right
1159
+ if (phi < -r) code |= 4; // below
1160
+ else if (phi > r) code |= 8; // above
1161
+ return code;
1162
+ }
1163
+ return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi, radius - pi]);
1164
+ }
1165
+ function clipLine(a, b, x0, y0, x1, y1) {
1166
+ var ax = a[0],
1167
+ ay = a[1],
1168
+ bx = b[0],
1169
+ by = b[1],
1170
+ t0 = 0,
1171
+ t1 = 1,
1172
+ dx = bx - ax,
1173
+ dy = by - ay,
1174
+ r;
1175
+ r = x0 - ax;
1176
+ if (!dx && r > 0) return;
1177
+ r /= dx;
1178
+ if (dx < 0) {
1179
+ if (r < t0) return;
1180
+ if (r < t1) t1 = r;
1181
+ } else if (dx > 0) {
1182
+ if (r > t1) return;
1183
+ if (r > t0) t0 = r;
1184
+ }
1185
+ r = x1 - ax;
1186
+ if (!dx && r < 0) return;
1187
+ r /= dx;
1188
+ if (dx < 0) {
1189
+ if (r > t1) return;
1190
+ if (r > t0) t0 = r;
1191
+ } else if (dx > 0) {
1192
+ if (r < t0) return;
1193
+ if (r < t1) t1 = r;
1194
+ }
1195
+ r = y0 - ay;
1196
+ if (!dy && r > 0) return;
1197
+ r /= dy;
1198
+ if (dy < 0) {
1199
+ if (r < t0) return;
1200
+ if (r < t1) t1 = r;
1201
+ } else if (dy > 0) {
1202
+ if (r > t1) return;
1203
+ if (r > t0) t0 = r;
1204
+ }
1205
+ r = y1 - ay;
1206
+ if (!dy && r < 0) return;
1207
+ r /= dy;
1208
+ if (dy < 0) {
1209
+ if (r > t1) return;
1210
+ if (r > t0) t0 = r;
1211
+ } else if (dy > 0) {
1212
+ if (r < t0) return;
1213
+ if (r < t1) t1 = r;
1214
+ }
1215
+ if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
1216
+ if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
1217
+ return true;
1218
+ }
1219
+ var clipMax = 1e9,
1220
+ clipMin = -clipMax;
1221
+
1222
+ // TODO Use d3-polygon’s polygonContains here for the ring check?
1223
+ // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
1224
+
1225
+ function clipRectangle(x0, y0, x1, y1) {
1226
+ function visible(x, y) {
1227
+ return x0 <= x && x <= x1 && y0 <= y && y <= y1;
1228
+ }
1229
+ function interpolate(from, to, direction, stream) {
1230
+ var a = 0,
1231
+ a1 = 0;
1232
+ if (from == null || (a = corner(from, direction)) !== (a1 = corner(to, direction)) || comparePoint(from, to) < 0 ^ direction > 0) {
1233
+ do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0); while ((a = (a + direction + 4) % 4) !== a1);
1234
+ } else {
1235
+ stream.point(to[0], to[1]);
1236
+ }
1237
+ }
1238
+ function corner(p, direction) {
1239
+ return abs(p[0] - x0) < epsilon ? direction > 0 ? 0 : 3 : abs(p[0] - x1) < epsilon ? direction > 0 ? 2 : 1 : abs(p[1] - y0) < epsilon ? direction > 0 ? 1 : 0 : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
1240
+ }
1241
+ function compareIntersection(a, b) {
1242
+ return comparePoint(a.x, b.x);
1243
+ }
1244
+ function comparePoint(a, b) {
1245
+ var ca = corner(a, 1),
1246
+ cb = corner(b, 1);
1247
+ 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];
1248
+ }
1249
+ return function (stream) {
1250
+ var activeStream = stream,
1251
+ bufferStream = clipBuffer(),
1252
+ segments,
1253
+ polygon,
1254
+ ring,
1255
+ x__,
1256
+ y__,
1257
+ v__,
1258
+ // first point
1259
+ x_,
1260
+ y_,
1261
+ v_,
1262
+ // previous point
1263
+ first,
1264
+ clean;
1265
+ var clipStream = {
1266
+ point: point,
1267
+ lineStart: lineStart,
1268
+ lineEnd: lineEnd,
1269
+ polygonStart: polygonStart,
1270
+ polygonEnd: polygonEnd
1271
+ };
1272
+ function point(x, y) {
1273
+ if (visible(x, y)) activeStream.point(x, y);
1274
+ }
1275
+ function polygonInside() {
1276
+ var winding = 0;
1277
+ for (var i = 0, n = polygon.length; i < n; ++i) {
1278
+ for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
1279
+ a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
1280
+ if (a1 <= y1) {
1281
+ if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding;
1282
+ } else {
1283
+ if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding;
1284
+ }
1285
+ }
1286
+ }
1287
+ return winding;
1288
+ }
1289
+
1290
+ // Buffer geometry within a polygon and then clip it en masse.
1291
+ function polygonStart() {
1292
+ activeStream = bufferStream, segments = [], polygon = [], clean = true;
1293
+ }
1294
+ function polygonEnd() {
1295
+ var startInside = polygonInside(),
1296
+ cleanInside = clean && startInside,
1297
+ visible = (segments = d3Array.merge(segments)).length;
1298
+ if (cleanInside || visible) {
1299
+ stream.polygonStart();
1300
+ if (cleanInside) {
1301
+ stream.lineStart();
1302
+ interpolate(null, null, 1, stream);
1303
+ stream.lineEnd();
1304
+ }
1305
+ if (visible) {
1306
+ clipRejoin(segments, compareIntersection, startInside, interpolate, stream);
1307
+ }
1308
+ stream.polygonEnd();
1309
+ }
1310
+ activeStream = stream, segments = polygon = ring = null;
1311
+ }
1312
+ function lineStart() {
1313
+ clipStream.point = linePoint;
1314
+ if (polygon) polygon.push(ring = []);
1315
+ first = true;
1316
+ v_ = false;
1317
+ x_ = y_ = NaN;
1318
+ }
1319
+
1320
+ // TODO rather than special-case polygons, simply handle them separately.
1321
+ // Ideally, coincident intersection points should be jittered to avoid
1322
+ // clipping issues.
1323
+ function lineEnd() {
1324
+ if (segments) {
1325
+ linePoint(x__, y__);
1326
+ if (v__ && v_) bufferStream.rejoin();
1327
+ segments.push(bufferStream.result());
1328
+ }
1329
+ clipStream.point = point;
1330
+ if (v_) activeStream.lineEnd();
1331
+ }
1332
+ function linePoint(x, y) {
1333
+ var v = visible(x, y);
1334
+ if (polygon) ring.push([x, y]);
1335
+ if (first) {
1336
+ x__ = x, y__ = y, v__ = v;
1337
+ first = false;
1338
+ if (v) {
1339
+ activeStream.lineStart();
1340
+ activeStream.point(x, y);
1341
+ }
1342
+ } else {
1343
+ if (v && v_) activeStream.point(x, y);else {
1344
+ var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
1345
+ b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
1346
+ if (clipLine(a, b, x0, y0, x1, y1)) {
1347
+ if (!v_) {
1348
+ activeStream.lineStart();
1349
+ activeStream.point(a[0], a[1]);
1350
+ }
1351
+ activeStream.point(b[0], b[1]);
1352
+ if (!v) activeStream.lineEnd();
1353
+ clean = false;
1354
+ } else if (v) {
1355
+ activeStream.lineStart();
1356
+ activeStream.point(x, y);
1357
+ clean = false;
1358
+ }
1359
+ }
1360
+ }
1361
+ x_ = x, y_ = y, v_ = v;
1362
+ }
1363
+ return clipStream;
1364
+ };
1365
+ }
1366
+ function extent() {
1367
+ var x0 = 0,
1368
+ y0 = 0,
1369
+ x1 = 960,
1370
+ y1 = 500,
1371
+ cache,
1372
+ cacheStream,
1373
+ clip;
1374
+ return clip = {
1375
+ stream: function (stream) {
1376
+ return cache && cacheStream === stream ? cache : cache = clipRectangle(x0, y0, x1, y1)(cacheStream = stream);
1377
+ },
1378
+ extent: function (_) {
1379
+ return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
1380
+ }
1381
+ };
1382
+ }
1383
+ var lengthSum$1, lambda0, sinPhi0, cosPhi0;
1384
+ var lengthStream$1 = {
1385
+ sphere: noop,
1386
+ point: noop,
1387
+ lineStart: lengthLineStart,
1388
+ lineEnd: noop,
1389
+ polygonStart: noop,
1390
+ polygonEnd: noop
1391
+ };
1392
+ function lengthLineStart() {
1393
+ lengthStream$1.point = lengthPointFirst$1;
1394
+ lengthStream$1.lineEnd = lengthLineEnd;
1395
+ }
1396
+ function lengthLineEnd() {
1397
+ lengthStream$1.point = lengthStream$1.lineEnd = noop;
1398
+ }
1399
+ function lengthPointFirst$1(lambda, phi) {
1400
+ lambda *= radians, phi *= radians;
1401
+ lambda0 = lambda, sinPhi0 = sin(phi), cosPhi0 = cos(phi);
1402
+ lengthStream$1.point = lengthPoint$1;
1403
+ }
1404
+ function lengthPoint$1(lambda, phi) {
1405
+ lambda *= radians, phi *= radians;
1406
+ var sinPhi = sin(phi),
1407
+ cosPhi = cos(phi),
1408
+ delta = abs(lambda - lambda0),
1409
+ cosDelta = cos(delta),
1410
+ sinDelta = sin(delta),
1411
+ x = cosPhi * sinDelta,
1412
+ y = cosPhi0 * sinPhi - sinPhi0 * cosPhi * cosDelta,
1413
+ z = sinPhi0 * sinPhi + cosPhi0 * cosPhi * cosDelta;
1414
+ lengthSum$1.add(atan2(sqrt(x * x + y * y), z));
1415
+ lambda0 = lambda, sinPhi0 = sinPhi, cosPhi0 = cosPhi;
1416
+ }
1417
+ function length(object) {
1418
+ lengthSum$1 = new d3Array.Adder();
1419
+ geoStream(object, lengthStream$1);
1420
+ return +lengthSum$1;
1421
+ }
1422
+ var coordinates = [null, null],
1423
+ object = {
1424
+ type: "LineString",
1425
+ coordinates: coordinates
1426
+ };
1427
+ function distance(a, b) {
1428
+ coordinates[0] = a;
1429
+ coordinates[1] = b;
1430
+ return length(object);
1431
+ }
1432
+ var containsObjectType = {
1433
+ Feature: function (object, point) {
1434
+ return containsGeometry(object.geometry, point);
1435
+ },
1436
+ FeatureCollection: function (object, point) {
1437
+ var features = object.features,
1438
+ i = -1,
1439
+ n = features.length;
1440
+ while (++i < n) if (containsGeometry(features[i].geometry, point)) return true;
1441
+ return false;
1442
+ }
1443
+ };
1444
+ var containsGeometryType = {
1445
+ Sphere: function () {
1446
+ return true;
1447
+ },
1448
+ Point: function (object, point) {
1449
+ return containsPoint(object.coordinates, point);
1450
+ },
1451
+ MultiPoint: function (object, point) {
1452
+ var coordinates = object.coordinates,
1453
+ i = -1,
1454
+ n = coordinates.length;
1455
+ while (++i < n) if (containsPoint(coordinates[i], point)) return true;
1456
+ return false;
1457
+ },
1458
+ LineString: function (object, point) {
1459
+ return containsLine(object.coordinates, point);
1460
+ },
1461
+ MultiLineString: function (object, point) {
1462
+ var coordinates = object.coordinates,
1463
+ i = -1,
1464
+ n = coordinates.length;
1465
+ while (++i < n) if (containsLine(coordinates[i], point)) return true;
1466
+ return false;
1467
+ },
1468
+ Polygon: function (object, point) {
1469
+ return containsPolygon(object.coordinates, point);
1470
+ },
1471
+ MultiPolygon: function (object, point) {
1472
+ var coordinates = object.coordinates,
1473
+ i = -1,
1474
+ n = coordinates.length;
1475
+ while (++i < n) if (containsPolygon(coordinates[i], point)) return true;
1476
+ return false;
1477
+ },
1478
+ GeometryCollection: function (object, point) {
1479
+ var geometries = object.geometries,
1480
+ i = -1,
1481
+ n = geometries.length;
1482
+ while (++i < n) if (containsGeometry(geometries[i], point)) return true;
1483
+ return false;
1484
+ }
1485
+ };
1486
+ function containsGeometry(geometry, point) {
1487
+ return geometry && containsGeometryType.hasOwnProperty(geometry.type) ? containsGeometryType[geometry.type](geometry, point) : false;
1488
+ }
1489
+ function containsPoint(coordinates, point) {
1490
+ return distance(coordinates, point) === 0;
1491
+ }
1492
+ function containsLine(coordinates, point) {
1493
+ var ao, bo, ab;
1494
+ for (var i = 0, n = coordinates.length; i < n; i++) {
1495
+ bo = distance(coordinates[i], point);
1496
+ if (bo === 0) return true;
1497
+ if (i > 0) {
1498
+ ab = distance(coordinates[i], coordinates[i - 1]);
1499
+ if (ab > 0 && ao <= ab && bo <= ab && (ao + bo - ab) * (1 - Math.pow((ao - bo) / ab, 2)) < epsilon2 * ab) return true;
1500
+ }
1501
+ ao = bo;
1502
+ }
1503
+ return false;
1504
+ }
1505
+ function containsPolygon(coordinates, point) {
1506
+ return !!polygonContains(coordinates.map(ringRadians), pointRadians(point));
1507
+ }
1508
+ function ringRadians(ring) {
1509
+ return ring = ring.map(pointRadians), ring.pop(), ring;
1510
+ }
1511
+ function pointRadians(point) {
1512
+ return [point[0] * radians, point[1] * radians];
1513
+ }
1514
+ function contains(object, point) {
1515
+ return (object && containsObjectType.hasOwnProperty(object.type) ? containsObjectType[object.type] : containsGeometry)(object, point);
1516
+ }
1517
+ function graticuleX(y0, y1, dy) {
1518
+ var y = d3Array.range(y0, y1 - epsilon, dy).concat(y1);
1519
+ return function (x) {
1520
+ return y.map(function (y) {
1521
+ return [x, y];
1522
+ });
1523
+ };
1524
+ }
1525
+ function graticuleY(x0, x1, dx) {
1526
+ var x = d3Array.range(x0, x1 - epsilon, dx).concat(x1);
1527
+ return function (y) {
1528
+ return x.map(function (x) {
1529
+ return [x, y];
1530
+ });
1531
+ };
1532
+ }
1533
+ function graticule() {
1534
+ var x1,
1535
+ x0,
1536
+ X1,
1537
+ X0,
1538
+ y1,
1539
+ y0,
1540
+ Y1,
1541
+ Y0,
1542
+ dx = 10,
1543
+ dy = dx,
1544
+ DX = 90,
1545
+ DY = 360,
1546
+ x,
1547
+ y,
1548
+ X,
1549
+ Y,
1550
+ precision = 2.5;
1551
+ function graticule() {
1552
+ return {
1553
+ type: "MultiLineString",
1554
+ coordinates: lines()
1555
+ };
1556
+ }
1557
+ function lines() {
1558
+ return d3Array.range(ceil(X0 / DX) * DX, X1, DX).map(X).concat(d3Array.range(ceil(Y0 / DY) * DY, Y1, DY).map(Y)).concat(d3Array.range(ceil(x0 / dx) * dx, x1, dx).filter(function (x) {
1559
+ return abs(x % DX) > epsilon;
1560
+ }).map(x)).concat(d3Array.range(ceil(y0 / dy) * dy, y1, dy).filter(function (y) {
1561
+ return abs(y % DY) > epsilon;
1562
+ }).map(y));
1563
+ }
1564
+ graticule.lines = function () {
1565
+ return lines().map(function (coordinates) {
1566
+ return {
1567
+ type: "LineString",
1568
+ coordinates: coordinates
1569
+ };
1570
+ });
1571
+ };
1572
+ graticule.outline = function () {
1573
+ return {
1574
+ type: "Polygon",
1575
+ coordinates: [X(X0).concat(Y(Y1).slice(1), X(X1).reverse().slice(1), Y(Y0).reverse().slice(1))]
1576
+ };
1577
+ };
1578
+ graticule.extent = function (_) {
1579
+ if (!arguments.length) return graticule.extentMinor();
1580
+ return graticule.extentMajor(_).extentMinor(_);
1581
+ };
1582
+ graticule.extentMajor = function (_) {
1583
+ if (!arguments.length) return [[X0, Y0], [X1, Y1]];
1584
+ X0 = +_[0][0], X1 = +_[1][0];
1585
+ Y0 = +_[0][1], Y1 = +_[1][1];
1586
+ if (X0 > X1) _ = X0, X0 = X1, X1 = _;
1587
+ if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
1588
+ return graticule.precision(precision);
1589
+ };
1590
+ graticule.extentMinor = function (_) {
1591
+ if (!arguments.length) return [[x0, y0], [x1, y1]];
1592
+ x0 = +_[0][0], x1 = +_[1][0];
1593
+ y0 = +_[0][1], y1 = +_[1][1];
1594
+ if (x0 > x1) _ = x0, x0 = x1, x1 = _;
1595
+ if (y0 > y1) _ = y0, y0 = y1, y1 = _;
1596
+ return graticule.precision(precision);
1597
+ };
1598
+ graticule.step = function (_) {
1599
+ if (!arguments.length) return graticule.stepMinor();
1600
+ return graticule.stepMajor(_).stepMinor(_);
1601
+ };
1602
+ graticule.stepMajor = function (_) {
1603
+ if (!arguments.length) return [DX, DY];
1604
+ DX = +_[0], DY = +_[1];
1605
+ return graticule;
1606
+ };
1607
+ graticule.stepMinor = function (_) {
1608
+ if (!arguments.length) return [dx, dy];
1609
+ dx = +_[0], dy = +_[1];
1610
+ return graticule;
1611
+ };
1612
+ graticule.precision = function (_) {
1613
+ if (!arguments.length) return precision;
1614
+ precision = +_;
1615
+ x = graticuleX(y0, y1, 90);
1616
+ y = graticuleY(x0, x1, precision);
1617
+ X = graticuleX(Y0, Y1, 90);
1618
+ Y = graticuleY(X0, X1, precision);
1619
+ return graticule;
1620
+ };
1621
+ return graticule.extentMajor([[-180, -90 + epsilon], [180, 90 - epsilon]]).extentMinor([[-180, -80 - epsilon], [180, 80 + epsilon]]);
1622
+ }
1623
+ function graticule10() {
1624
+ return graticule()();
1625
+ }
1626
+ function interpolate(a, b) {
1627
+ var x0 = a[0] * radians,
1628
+ y0 = a[1] * radians,
1629
+ x1 = b[0] * radians,
1630
+ y1 = b[1] * radians,
1631
+ cy0 = cos(y0),
1632
+ sy0 = sin(y0),
1633
+ cy1 = cos(y1),
1634
+ sy1 = sin(y1),
1635
+ kx0 = cy0 * cos(x0),
1636
+ ky0 = cy0 * sin(x0),
1637
+ kx1 = cy1 * cos(x1),
1638
+ ky1 = cy1 * sin(x1),
1639
+ d = 2 * asin(sqrt(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
1640
+ k = sin(d);
1641
+ var interpolate = d ? function (t) {
1642
+ var B = sin(t *= d) / k,
1643
+ A = sin(d - t) / k,
1644
+ x = A * kx0 + B * kx1,
1645
+ y = A * ky0 + B * ky1,
1646
+ z = A * sy0 + B * sy1;
1647
+ return [atan2(y, x) * degrees, atan2(z, sqrt(x * x + y * y)) * degrees];
1648
+ } : function () {
1649
+ return [x0 * degrees, y0 * degrees];
1650
+ };
1651
+ interpolate.distance = d;
1652
+ return interpolate;
1653
+ }
1654
+ var identity$1 = x => x;
1655
+ var areaSum = new d3Array.Adder(),
1656
+ areaRingSum = new d3Array.Adder(),
1657
+ x00$2,
1658
+ y00$2,
1659
+ x0$3,
1660
+ y0$3;
1661
+ var areaStream = {
1662
+ point: noop,
1663
+ lineStart: noop,
1664
+ lineEnd: noop,
1665
+ polygonStart: function () {
1666
+ areaStream.lineStart = areaRingStart;
1667
+ areaStream.lineEnd = areaRingEnd;
1668
+ },
1669
+ polygonEnd: function () {
1670
+ areaStream.lineStart = areaStream.lineEnd = areaStream.point = noop;
1671
+ areaSum.add(abs(areaRingSum));
1672
+ areaRingSum = new d3Array.Adder();
1673
+ },
1674
+ result: function () {
1675
+ var area = areaSum / 2;
1676
+ areaSum = new d3Array.Adder();
1677
+ return area;
1678
+ }
1679
+ };
1680
+ function areaRingStart() {
1681
+ areaStream.point = areaPointFirst;
1682
+ }
1683
+ function areaPointFirst(x, y) {
1684
+ areaStream.point = areaPoint;
1685
+ x00$2 = x0$3 = x, y00$2 = y0$3 = y;
1686
+ }
1687
+ function areaPoint(x, y) {
1688
+ areaRingSum.add(y0$3 * x - x0$3 * y);
1689
+ x0$3 = x, y0$3 = y;
1690
+ }
1691
+ function areaRingEnd() {
1692
+ areaPoint(x00$2, y00$2);
1693
+ }
1694
+ var x0$2 = Infinity,
1695
+ y0$2 = x0$2,
1696
+ x1 = -x0$2,
1697
+ y1 = x1;
1698
+ var boundsStream = {
1699
+ point: boundsPoint,
1700
+ lineStart: noop,
1701
+ lineEnd: noop,
1702
+ polygonStart: noop,
1703
+ polygonEnd: noop,
1704
+ result: function () {
1705
+ var bounds = [[x0$2, y0$2], [x1, y1]];
1706
+ x1 = y1 = -(y0$2 = x0$2 = Infinity);
1707
+ return bounds;
1708
+ }
1709
+ };
1710
+ function boundsPoint(x, y) {
1711
+ if (x < x0$2) x0$2 = x;
1712
+ if (x > x1) x1 = x;
1713
+ if (y < y0$2) y0$2 = y;
1714
+ if (y > y1) y1 = y;
1715
+ }
1716
+
1717
+ // TODO Enforce positive area for exterior, negative area for interior?
1718
+
1719
+ var X0 = 0,
1720
+ Y0 = 0,
1721
+ Z0 = 0,
1722
+ X1 = 0,
1723
+ Y1 = 0,
1724
+ Z1 = 0,
1725
+ X2 = 0,
1726
+ Y2 = 0,
1727
+ Z2 = 0,
1728
+ x00$1,
1729
+ y00$1,
1730
+ x0$1,
1731
+ y0$1;
1732
+ var centroidStream = {
1733
+ point: centroidPoint,
1734
+ lineStart: centroidLineStart,
1735
+ lineEnd: centroidLineEnd,
1736
+ polygonStart: function () {
1737
+ centroidStream.lineStart = centroidRingStart;
1738
+ centroidStream.lineEnd = centroidRingEnd;
1739
+ },
1740
+ polygonEnd: function () {
1741
+ centroidStream.point = centroidPoint;
1742
+ centroidStream.lineStart = centroidLineStart;
1743
+ centroidStream.lineEnd = centroidLineEnd;
1744
+ },
1745
+ result: function () {
1746
+ var centroid = Z2 ? [X2 / Z2, Y2 / Z2] : Z1 ? [X1 / Z1, Y1 / Z1] : Z0 ? [X0 / Z0, Y0 / Z0] : [NaN, NaN];
1747
+ X0 = Y0 = Z0 = X1 = Y1 = Z1 = X2 = Y2 = Z2 = 0;
1748
+ return centroid;
1749
+ }
1750
+ };
1751
+ function centroidPoint(x, y) {
1752
+ X0 += x;
1753
+ Y0 += y;
1754
+ ++Z0;
1755
+ }
1756
+ function centroidLineStart() {
1757
+ centroidStream.point = centroidPointFirstLine;
1758
+ }
1759
+ function centroidPointFirstLine(x, y) {
1760
+ centroidStream.point = centroidPointLine;
1761
+ centroidPoint(x0$1 = x, y0$1 = y);
1762
+ }
1763
+ function centroidPointLine(x, y) {
1764
+ var dx = x - x0$1,
1765
+ dy = y - y0$1,
1766
+ z = sqrt(dx * dx + dy * dy);
1767
+ X1 += z * (x0$1 + x) / 2;
1768
+ Y1 += z * (y0$1 + y) / 2;
1769
+ Z1 += z;
1770
+ centroidPoint(x0$1 = x, y0$1 = y);
1771
+ }
1772
+ function centroidLineEnd() {
1773
+ centroidStream.point = centroidPoint;
1774
+ }
1775
+ function centroidRingStart() {
1776
+ centroidStream.point = centroidPointFirstRing;
1777
+ }
1778
+ function centroidRingEnd() {
1779
+ centroidPointRing(x00$1, y00$1);
1780
+ }
1781
+ function centroidPointFirstRing(x, y) {
1782
+ centroidStream.point = centroidPointRing;
1783
+ centroidPoint(x00$1 = x0$1 = x, y00$1 = y0$1 = y);
1784
+ }
1785
+ function centroidPointRing(x, y) {
1786
+ var dx = x - x0$1,
1787
+ dy = y - y0$1,
1788
+ z = sqrt(dx * dx + dy * dy);
1789
+ X1 += z * (x0$1 + x) / 2;
1790
+ Y1 += z * (y0$1 + y) / 2;
1791
+ Z1 += z;
1792
+ z = y0$1 * x - x0$1 * y;
1793
+ X2 += z * (x0$1 + x);
1794
+ Y2 += z * (y0$1 + y);
1795
+ Z2 += z * 3;
1796
+ centroidPoint(x0$1 = x, y0$1 = y);
1797
+ }
1798
+ function PathContext(context) {
1799
+ this._context = context;
1800
+ }
1801
+ PathContext.prototype = {
1802
+ _radius: 4.5,
1803
+ pointRadius: function (_) {
1804
+ return this._radius = _, this;
1805
+ },
1806
+ polygonStart: function () {
1807
+ this._line = 0;
1808
+ },
1809
+ polygonEnd: function () {
1810
+ this._line = NaN;
1811
+ },
1812
+ lineStart: function () {
1813
+ this._point = 0;
1814
+ },
1815
+ lineEnd: function () {
1816
+ if (this._line === 0) this._context.closePath();
1817
+ this._point = NaN;
1818
+ },
1819
+ point: function (x, y) {
1820
+ switch (this._point) {
1821
+ case 0:
1822
+ {
1823
+ this._context.moveTo(x, y);
1824
+ this._point = 1;
1825
+ break;
1826
+ }
1827
+ case 1:
1828
+ {
1829
+ this._context.lineTo(x, y);
1830
+ break;
1831
+ }
1832
+ default:
1833
+ {
1834
+ this._context.moveTo(x + this._radius, y);
1835
+ this._context.arc(x, y, this._radius, 0, tau);
1836
+ break;
1837
+ }
1838
+ }
1839
+ },
1840
+ result: noop
1841
+ };
1842
+ var lengthSum = new d3Array.Adder(),
1843
+ lengthRing,
1844
+ x00,
1845
+ y00,
1846
+ x0,
1847
+ y0;
1848
+ var lengthStream = {
1849
+ point: noop,
1850
+ lineStart: function () {
1851
+ lengthStream.point = lengthPointFirst;
1852
+ },
1853
+ lineEnd: function () {
1854
+ if (lengthRing) lengthPoint(x00, y00);
1855
+ lengthStream.point = noop;
1856
+ },
1857
+ polygonStart: function () {
1858
+ lengthRing = true;
1859
+ },
1860
+ polygonEnd: function () {
1861
+ lengthRing = null;
1862
+ },
1863
+ result: function () {
1864
+ var length = +lengthSum;
1865
+ lengthSum = new d3Array.Adder();
1866
+ return length;
1867
+ }
1868
+ };
1869
+ function lengthPointFirst(x, y) {
1870
+ lengthStream.point = lengthPoint;
1871
+ x00 = x0 = x, y00 = y0 = y;
1872
+ }
1873
+ function lengthPoint(x, y) {
1874
+ x0 -= x, y0 -= y;
1875
+ lengthSum.add(sqrt(x0 * x0 + y0 * y0));
1876
+ x0 = x, y0 = y;
1877
+ }
1878
+
1879
+ // Simple caching for constant-radius points.
1880
+ let cacheDigits, cacheAppend, cacheRadius, cacheCircle;
1881
+ class PathString {
1882
+ constructor(digits) {
1883
+ this._append = digits == null ? append : appendRound(digits);
1884
+ this._radius = 4.5;
1885
+ this._ = "";
1886
+ }
1887
+ pointRadius(_) {
1888
+ this._radius = +_;
1889
+ return this;
1890
+ }
1891
+ polygonStart() {
1892
+ this._line = 0;
1893
+ }
1894
+ polygonEnd() {
1895
+ this._line = NaN;
1896
+ }
1897
+ lineStart() {
1898
+ this._point = 0;
1899
+ }
1900
+ lineEnd() {
1901
+ if (this._line === 0) this._ += "Z";
1902
+ this._point = NaN;
1903
+ }
1904
+ point(x, y) {
1905
+ switch (this._point) {
1906
+ case 0:
1907
+ {
1908
+ this._append`M${x},${y}`;
1909
+ this._point = 1;
1910
+ break;
1911
+ }
1912
+ case 1:
1913
+ {
1914
+ this._append`L${x},${y}`;
1915
+ break;
1916
+ }
1917
+ default:
1918
+ {
1919
+ this._append`M${x},${y}`;
1920
+ if (this._radius !== cacheRadius || this._append !== cacheAppend) {
1921
+ const r = this._radius;
1922
+ const s = this._;
1923
+ this._ = ""; // stash the old string so we can cache the circle path fragment
1924
+ this._append`m0,${r}a${r},${r} 0 1,1 0,${-2 * r}a${r},${r} 0 1,1 0,${2 * r}z`;
1925
+ cacheRadius = r;
1926
+ cacheAppend = this._append;
1927
+ cacheCircle = this._;
1928
+ this._ = s;
1929
+ }
1930
+ this._ += cacheCircle;
1931
+ break;
1932
+ }
1933
+ }
1934
+ }
1935
+ result() {
1936
+ const result = this._;
1937
+ this._ = "";
1938
+ return result.length ? result : null;
1939
+ }
1940
+ }
1941
+ function append(strings) {
1942
+ let i = 1;
1943
+ this._ += strings[0];
1944
+ for (const j = strings.length; i < j; ++i) {
1945
+ this._ += arguments[i] + strings[i];
1946
+ }
1947
+ }
1948
+ function appendRound(digits) {
1949
+ const d = Math.floor(digits);
1950
+ if (!(d >= 0)) throw new RangeError(`invalid digits: ${digits}`);
1951
+ if (d > 15) return append;
1952
+ if (d !== cacheDigits) {
1953
+ const k = 10 ** d;
1954
+ cacheDigits = d;
1955
+ cacheAppend = function append(strings) {
1956
+ let i = 1;
1957
+ this._ += strings[0];
1958
+ for (const j = strings.length; i < j; ++i) {
1959
+ this._ += Math.round(arguments[i] * k) / k + strings[i];
1960
+ }
1961
+ };
1962
+ }
1963
+ return cacheAppend;
1964
+ }
1965
+ function index(projection, context) {
1966
+ let digits = 3,
1967
+ pointRadius = 4.5,
1968
+ projectionStream,
1969
+ contextStream;
1970
+ function path(object) {
1971
+ if (object) {
1972
+ if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
1973
+ geoStream(object, projectionStream(contextStream));
1974
+ }
1975
+ return contextStream.result();
1976
+ }
1977
+ path.area = function (object) {
1978
+ geoStream(object, projectionStream(areaStream));
1979
+ return areaStream.result();
1980
+ };
1981
+ path.measure = function (object) {
1982
+ geoStream(object, projectionStream(lengthStream));
1983
+ return lengthStream.result();
1984
+ };
1985
+ path.bounds = function (object) {
1986
+ geoStream(object, projectionStream(boundsStream));
1987
+ return boundsStream.result();
1988
+ };
1989
+ path.centroid = function (object) {
1990
+ geoStream(object, projectionStream(centroidStream));
1991
+ return centroidStream.result();
1992
+ };
1993
+ path.projection = function (_) {
1994
+ if (!arguments.length) return projection;
1995
+ projectionStream = _ == null ? (projection = null, identity$1) : (projection = _).stream;
1996
+ return path;
1997
+ };
1998
+ path.context = function (_) {
1999
+ if (!arguments.length) return context;
2000
+ contextStream = _ == null ? (context = null, new PathString(digits)) : new PathContext(context = _);
2001
+ if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
2002
+ return path;
2003
+ };
2004
+ path.pointRadius = function (_) {
2005
+ if (!arguments.length) return pointRadius;
2006
+ pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
2007
+ return path;
2008
+ };
2009
+ path.digits = function (_) {
2010
+ if (!arguments.length) return digits;
2011
+ if (_ == null) digits = null;else {
2012
+ const d = Math.floor(_);
2013
+ if (!(d >= 0)) throw new RangeError(`invalid digits: ${_}`);
2014
+ digits = d;
2015
+ }
2016
+ if (context === null) contextStream = new PathString(digits);
2017
+ return path;
2018
+ };
2019
+ return path.projection(projection).digits(digits).context(context);
2020
+ }
2021
+ function transform(methods) {
2022
+ return {
2023
+ stream: transformer(methods)
2024
+ };
2025
+ }
2026
+ function transformer(methods) {
2027
+ return function (stream) {
2028
+ var s = new TransformStream();
2029
+ for (var key in methods) s[key] = methods[key];
2030
+ s.stream = stream;
2031
+ return s;
2032
+ };
2033
+ }
2034
+ function TransformStream() {}
2035
+ TransformStream.prototype = {
2036
+ constructor: TransformStream,
2037
+ point: function (x, y) {
2038
+ this.stream.point(x, y);
2039
+ },
2040
+ sphere: function () {
2041
+ this.stream.sphere();
2042
+ },
2043
+ lineStart: function () {
2044
+ this.stream.lineStart();
2045
+ },
2046
+ lineEnd: function () {
2047
+ this.stream.lineEnd();
2048
+ },
2049
+ polygonStart: function () {
2050
+ this.stream.polygonStart();
2051
+ },
2052
+ polygonEnd: function () {
2053
+ this.stream.polygonEnd();
2054
+ }
2055
+ };
2056
+ function fit(projection, fitBounds, object) {
2057
+ var clip = projection.clipExtent && projection.clipExtent();
2058
+ projection.scale(150).translate([0, 0]);
2059
+ if (clip != null) projection.clipExtent(null);
2060
+ geoStream(object, projection.stream(boundsStream));
2061
+ fitBounds(boundsStream.result());
2062
+ if (clip != null) projection.clipExtent(clip);
2063
+ return projection;
2064
+ }
2065
+ function fitExtent(projection, extent, object) {
2066
+ return fit(projection, function (b) {
2067
+ var w = extent[1][0] - extent[0][0],
2068
+ h = extent[1][1] - extent[0][1],
2069
+ k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
2070
+ x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
2071
+ y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
2072
+ projection.scale(150 * k).translate([x, y]);
2073
+ }, object);
2074
+ }
2075
+ function fitSize(projection, size, object) {
2076
+ return fitExtent(projection, [[0, 0], size], object);
2077
+ }
2078
+ function fitWidth(projection, width, object) {
2079
+ return fit(projection, function (b) {
2080
+ var w = +width,
2081
+ k = w / (b[1][0] - b[0][0]),
2082
+ x = (w - k * (b[1][0] + b[0][0])) / 2,
2083
+ y = -k * b[0][1];
2084
+ projection.scale(150 * k).translate([x, y]);
2085
+ }, object);
2086
+ }
2087
+ function fitHeight(projection, height, object) {
2088
+ return fit(projection, function (b) {
2089
+ var h = +height,
2090
+ k = h / (b[1][1] - b[0][1]),
2091
+ x = -k * b[0][0],
2092
+ y = (h - k * (b[1][1] + b[0][1])) / 2;
2093
+ projection.scale(150 * k).translate([x, y]);
2094
+ }, object);
2095
+ }
2096
+ var maxDepth = 16,
2097
+ // maximum depth of subdivision
2098
+ cosMinDistance = cos(30 * radians); // cos(minimum angular distance)
2099
+
2100
+ function resample(project, delta2) {
2101
+ return +delta2 ? resample$1(project, delta2) : resampleNone(project);
2102
+ }
2103
+ function resampleNone(project) {
2104
+ return transformer({
2105
+ point: function (x, y) {
2106
+ x = project(x, y);
2107
+ this.stream.point(x[0], x[1]);
2108
+ }
2109
+ });
2110
+ }
2111
+ function resample$1(project, delta2) {
2112
+ function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
2113
+ var dx = x1 - x0,
2114
+ dy = y1 - y0,
2115
+ d2 = dx * dx + dy * dy;
2116
+ if (d2 > 4 * delta2 && depth--) {
2117
+ var a = a0 + a1,
2118
+ b = b0 + b1,
2119
+ c = c0 + c1,
2120
+ m = sqrt(a * a + b * b + c * c),
2121
+ phi2 = asin(c /= m),
2122
+ lambda2 = abs(abs(c) - 1) < epsilon || abs(lambda0 - lambda1) < epsilon ? (lambda0 + lambda1) / 2 : atan2(b, a),
2123
+ p = project(lambda2, phi2),
2124
+ x2 = p[0],
2125
+ y2 = p[1],
2126
+ dx2 = x2 - x0,
2127
+ dy2 = y2 - y0,
2128
+ dz = dy * dx2 - dx * dy2;
2129
+ if (dz * dz / d2 > delta2 // perpendicular projected distance
2130
+ || abs((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
2131
+ || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) {
2132
+ // angular distance
2133
+ resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
2134
+ stream.point(x2, y2);
2135
+ resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
2136
+ }
2137
+ }
2138
+ }
2139
+ return function (stream) {
2140
+ var lambda00, x00, y00, a00, b00, c00,
2141
+ // first point
2142
+ lambda0, x0, y0, a0, b0, c0; // previous point
2143
+
2144
+ var resampleStream = {
2145
+ point: point,
2146
+ lineStart: lineStart,
2147
+ lineEnd: lineEnd,
2148
+ polygonStart: function () {
2149
+ stream.polygonStart();
2150
+ resampleStream.lineStart = ringStart;
2151
+ },
2152
+ polygonEnd: function () {
2153
+ stream.polygonEnd();
2154
+ resampleStream.lineStart = lineStart;
2155
+ }
2156
+ };
2157
+ function point(x, y) {
2158
+ x = project(x, y);
2159
+ stream.point(x[0], x[1]);
2160
+ }
2161
+ function lineStart() {
2162
+ x0 = NaN;
2163
+ resampleStream.point = linePoint;
2164
+ stream.lineStart();
2165
+ }
2166
+ function linePoint(lambda, phi) {
2167
+ var c = cartesian([lambda, phi]),
2168
+ p = project(lambda, phi);
2169
+ resampleLineTo(x0, y0, lambda0, a0, b0, c0, x0 = p[0], y0 = p[1], lambda0 = lambda, a0 = c[0], b0 = c[1], c0 = c[2], maxDepth, stream);
2170
+ stream.point(x0, y0);
2171
+ }
2172
+ function lineEnd() {
2173
+ resampleStream.point = point;
2174
+ stream.lineEnd();
2175
+ }
2176
+ function ringStart() {
2177
+ lineStart();
2178
+ resampleStream.point = ringPoint;
2179
+ resampleStream.lineEnd = ringEnd;
2180
+ }
2181
+ function ringPoint(lambda, phi) {
2182
+ linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
2183
+ resampleStream.point = linePoint;
2184
+ }
2185
+ function ringEnd() {
2186
+ resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
2187
+ resampleStream.lineEnd = lineEnd;
2188
+ lineEnd();
2189
+ }
2190
+ return resampleStream;
2191
+ };
2192
+ }
2193
+ var transformRadians = transformer({
2194
+ point: function (x, y) {
2195
+ this.stream.point(x * radians, y * radians);
2196
+ }
2197
+ });
2198
+ function transformRotate(rotate) {
2199
+ return transformer({
2200
+ point: function (x, y) {
2201
+ var r = rotate(x, y);
2202
+ return this.stream.point(r[0], r[1]);
2203
+ }
2204
+ });
2205
+ }
2206
+ function scaleTranslate(k, dx, dy, sx, sy) {
2207
+ function transform(x, y) {
2208
+ x *= sx;
2209
+ y *= sy;
2210
+ return [dx + k * x, dy - k * y];
2211
+ }
2212
+ transform.invert = function (x, y) {
2213
+ return [(x - dx) / k * sx, (dy - y) / k * sy];
2214
+ };
2215
+ return transform;
2216
+ }
2217
+ function scaleTranslateRotate(k, dx, dy, sx, sy, alpha) {
2218
+ if (!alpha) return scaleTranslate(k, dx, dy, sx, sy);
2219
+ var cosAlpha = cos(alpha),
2220
+ sinAlpha = sin(alpha),
2221
+ a = cosAlpha * k,
2222
+ b = sinAlpha * k,
2223
+ ai = cosAlpha / k,
2224
+ bi = sinAlpha / k,
2225
+ ci = (sinAlpha * dy - cosAlpha * dx) / k,
2226
+ fi = (sinAlpha * dx + cosAlpha * dy) / k;
2227
+ function transform(x, y) {
2228
+ x *= sx;
2229
+ y *= sy;
2230
+ return [a * x - b * y + dx, dy - b * x - a * y];
2231
+ }
2232
+ transform.invert = function (x, y) {
2233
+ return [sx * (ai * x - bi * y + ci), sy * (fi - bi * x - ai * y)];
2234
+ };
2235
+ return transform;
2236
+ }
2237
+ function projection(project) {
2238
+ return projectionMutator(function () {
2239
+ return project;
2240
+ })();
2241
+ }
2242
+ function projectionMutator(projectAt) {
2243
+ var project,
2244
+ k = 150,
2245
+ // scale
2246
+ x = 480,
2247
+ y = 250,
2248
+ // translate
2249
+ lambda = 0,
2250
+ phi = 0,
2251
+ // center
2252
+ deltaLambda = 0,
2253
+ deltaPhi = 0,
2254
+ deltaGamma = 0,
2255
+ rotate,
2256
+ // pre-rotate
2257
+ alpha = 0,
2258
+ // post-rotate angle
2259
+ sx = 1,
2260
+ // reflectX
2261
+ sy = 1,
2262
+ // reflectX
2263
+ theta = null,
2264
+ preclip = clipAntimeridian,
2265
+ // pre-clip angle
2266
+ x0 = null,
2267
+ y0,
2268
+ x1,
2269
+ y1,
2270
+ postclip = identity$1,
2271
+ // post-clip extent
2272
+ delta2 = 0.5,
2273
+ // precision
2274
+ projectResample,
2275
+ projectTransform,
2276
+ projectRotateTransform,
2277
+ cache,
2278
+ cacheStream;
2279
+ function projection(point) {
2280
+ return projectRotateTransform(point[0] * radians, point[1] * radians);
2281
+ }
2282
+ function invert(point) {
2283
+ point = projectRotateTransform.invert(point[0], point[1]);
2284
+ return point && [point[0] * degrees, point[1] * degrees];
2285
+ }
2286
+ projection.stream = function (stream) {
2287
+ return cache && cacheStream === stream ? cache : cache = transformRadians(transformRotate(rotate)(preclip(projectResample(postclip(cacheStream = stream)))));
2288
+ };
2289
+ projection.preclip = function (_) {
2290
+ return arguments.length ? (preclip = _, theta = undefined, reset()) : preclip;
2291
+ };
2292
+ projection.postclip = function (_) {
2293
+ return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
2294
+ };
2295
+ projection.clipAngle = function (_) {
2296
+ return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees;
2297
+ };
2298
+ projection.clipExtent = function (_) {
2299
+ return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$1) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
2300
+ };
2301
+ projection.scale = function (_) {
2302
+ return arguments.length ? (k = +_, recenter()) : k;
2303
+ };
2304
+ projection.translate = function (_) {
2305
+ return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
2306
+ };
2307
+ projection.center = function (_) {
2308
+ return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees, phi * degrees];
2309
+ };
2310
+ projection.rotate = function (_) {
2311
+ return arguments.length ? (deltaLambda = _[0] % 360 * radians, deltaPhi = _[1] % 360 * radians, deltaGamma = _.length > 2 ? _[2] % 360 * radians : 0, recenter()) : [deltaLambda * degrees, deltaPhi * degrees, deltaGamma * degrees];
2312
+ };
2313
+ projection.angle = function (_) {
2314
+ return arguments.length ? (alpha = _ % 360 * radians, recenter()) : alpha * degrees;
2315
+ };
2316
+ projection.reflectX = function (_) {
2317
+ return arguments.length ? (sx = _ ? -1 : 1, recenter()) : sx < 0;
2318
+ };
2319
+ projection.reflectY = function (_) {
2320
+ return arguments.length ? (sy = _ ? -1 : 1, recenter()) : sy < 0;
2321
+ };
2322
+ projection.precision = function (_) {
2323
+ return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt(delta2);
2324
+ };
2325
+ projection.fitExtent = function (extent, object) {
2326
+ return fitExtent(projection, extent, object);
2327
+ };
2328
+ projection.fitSize = function (size, object) {
2329
+ return fitSize(projection, size, object);
2330
+ };
2331
+ projection.fitWidth = function (width, object) {
2332
+ return fitWidth(projection, width, object);
2333
+ };
2334
+ projection.fitHeight = function (height, object) {
2335
+ return fitHeight(projection, height, object);
2336
+ };
2337
+ function recenter() {
2338
+ var center = scaleTranslateRotate(k, 0, 0, sx, sy, alpha).apply(null, project(lambda, phi)),
2339
+ transform = scaleTranslateRotate(k, x - center[0], y - center[1], sx, sy, alpha);
2340
+ rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma);
2341
+ projectTransform = compose(project, transform);
2342
+ projectRotateTransform = compose(rotate, projectTransform);
2343
+ projectResample = resample(projectTransform, delta2);
2344
+ return reset();
2345
+ }
2346
+ function reset() {
2347
+ cache = cacheStream = null;
2348
+ return projection;
2349
+ }
2350
+ return function () {
2351
+ project = projectAt.apply(this, arguments);
2352
+ projection.invert = project.invert && invert;
2353
+ return recenter();
2354
+ };
2355
+ }
2356
+ function conicProjection(projectAt) {
2357
+ var phi0 = 0,
2358
+ phi1 = pi / 3,
2359
+ m = projectionMutator(projectAt),
2360
+ p = m(phi0, phi1);
2361
+ p.parallels = function (_) {
2362
+ return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees, phi1 * degrees];
2363
+ };
2364
+ return p;
2365
+ }
2366
+ function cylindricalEqualAreaRaw(phi0) {
2367
+ var cosPhi0 = cos(phi0);
2368
+ function forward(lambda, phi) {
2369
+ return [lambda * cosPhi0, sin(phi) / cosPhi0];
2370
+ }
2371
+ forward.invert = function (x, y) {
2372
+ return [x / cosPhi0, asin(y * cosPhi0)];
2373
+ };
2374
+ return forward;
2375
+ }
2376
+ function conicEqualAreaRaw(y0, y1) {
2377
+ var sy0 = sin(y0),
2378
+ n = (sy0 + sin(y1)) / 2;
2379
+
2380
+ // Are the parallels symmetrical around the Equator?
2381
+ if (abs(n) < epsilon) return cylindricalEqualAreaRaw(y0);
2382
+ var c = 1 + sy0 * (2 * n - sy0),
2383
+ r0 = sqrt(c) / n;
2384
+ function project(x, y) {
2385
+ var r = sqrt(c - 2 * n * sin(y)) / n;
2386
+ return [r * sin(x *= n), r0 - r * cos(x)];
2387
+ }
2388
+ project.invert = function (x, y) {
2389
+ var r0y = r0 - y,
2390
+ l = atan2(x, abs(r0y)) * sign(r0y);
2391
+ if (r0y * n < 0) l -= pi * sign(x) * sign(r0y);
2392
+ return [l / n, asin((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
2393
+ };
2394
+ return project;
2395
+ }
2396
+ function conicEqualArea() {
2397
+ return conicProjection(conicEqualAreaRaw).scale(155.424).center([0, 33.6442]);
2398
+ }
2399
+ function albers() {
2400
+ return conicEqualArea().parallels([29.5, 45.5]).scale(1070).translate([480, 250]).rotate([96, 0]).center([-0.6, 38.7]);
2401
+ }
2402
+
2403
+ // The projections must have mutually exclusive clip regions on the sphere,
2404
+ // as this will avoid emitting interleaving lines and polygons.
2405
+ function multiplex(streams) {
2406
+ var n = streams.length;
2407
+ return {
2408
+ point: function (x, y) {
2409
+ var i = -1;
2410
+ while (++i < n) streams[i].point(x, y);
2411
+ },
2412
+ sphere: function () {
2413
+ var i = -1;
2414
+ while (++i < n) streams[i].sphere();
2415
+ },
2416
+ lineStart: function () {
2417
+ var i = -1;
2418
+ while (++i < n) streams[i].lineStart();
2419
+ },
2420
+ lineEnd: function () {
2421
+ var i = -1;
2422
+ while (++i < n) streams[i].lineEnd();
2423
+ },
2424
+ polygonStart: function () {
2425
+ var i = -1;
2426
+ while (++i < n) streams[i].polygonStart();
2427
+ },
2428
+ polygonEnd: function () {
2429
+ var i = -1;
2430
+ while (++i < n) streams[i].polygonEnd();
2431
+ }
2432
+ };
2433
+ }
2434
+
2435
+ // A composite projection for the United States, configured by default for
2436
+ // 960×500. The projection also works quite well at 960×600 if you change the
2437
+ // scale to 1285 and adjust the translate accordingly. The set of standard
2438
+ // parallels for each region comes from USGS, which is published here:
2439
+ // http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
2440
+ function albersUsa() {
2441
+ var cache,
2442
+ cacheStream,
2443
+ lower48 = albers(),
2444
+ lower48Point,
2445
+ alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]),
2446
+ alaskaPoint,
2447
+ // EPSG:3338
2448
+ hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]),
2449
+ hawaiiPoint,
2450
+ // ESRI:102007
2451
+ point,
2452
+ pointStream = {
2453
+ point: function (x, y) {
2454
+ point = [x, y];
2455
+ }
2456
+ };
2457
+ function albersUsa(coordinates) {
2458
+ var x = coordinates[0],
2459
+ y = coordinates[1];
2460
+ return point = null, (lower48Point.point(x, y), point) || (alaskaPoint.point(x, y), point) || (hawaiiPoint.point(x, y), point);
2461
+ }
2462
+ albersUsa.invert = function (coordinates) {
2463
+ var k = lower48.scale(),
2464
+ t = lower48.translate(),
2465
+ x = (coordinates[0] - t[0]) / k,
2466
+ y = (coordinates[1] - t[1]) / k;
2467
+ return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii : lower48).invert(coordinates);
2468
+ };
2469
+ albersUsa.stream = function (stream) {
2470
+ return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
2471
+ };
2472
+ albersUsa.precision = function (_) {
2473
+ if (!arguments.length) return lower48.precision();
2474
+ lower48.precision(_), alaska.precision(_), hawaii.precision(_);
2475
+ return reset();
2476
+ };
2477
+ albersUsa.scale = function (_) {
2478
+ if (!arguments.length) return lower48.scale();
2479
+ lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
2480
+ return albersUsa.translate(lower48.translate());
2481
+ };
2482
+ albersUsa.translate = function (_) {
2483
+ if (!arguments.length) return lower48.translate();
2484
+ var k = lower48.scale(),
2485
+ x = +_[0],
2486
+ y = +_[1];
2487
+ lower48Point = lower48.translate(_).clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]]).stream(pointStream);
2488
+ alaskaPoint = alaska.translate([x - 0.307 * k, y + 0.201 * k]).clipExtent([[x - 0.425 * k + epsilon, y + 0.120 * k + epsilon], [x - 0.214 * k - epsilon, y + 0.234 * k - epsilon]]).stream(pointStream);
2489
+ hawaiiPoint = hawaii.translate([x - 0.205 * k, y + 0.212 * k]).clipExtent([[x - 0.214 * k + epsilon, y + 0.166 * k + epsilon], [x - 0.115 * k - epsilon, y + 0.234 * k - epsilon]]).stream(pointStream);
2490
+ return reset();
2491
+ };
2492
+ albersUsa.fitExtent = function (extent, object) {
2493
+ return fitExtent(albersUsa, extent, object);
2494
+ };
2495
+ albersUsa.fitSize = function (size, object) {
2496
+ return fitSize(albersUsa, size, object);
2497
+ };
2498
+ albersUsa.fitWidth = function (width, object) {
2499
+ return fitWidth(albersUsa, width, object);
2500
+ };
2501
+ albersUsa.fitHeight = function (height, object) {
2502
+ return fitHeight(albersUsa, height, object);
2503
+ };
2504
+ function reset() {
2505
+ cache = cacheStream = null;
2506
+ return albersUsa;
2507
+ }
2508
+ return albersUsa.scale(1070);
2509
+ }
2510
+ function azimuthalRaw(scale) {
2511
+ return function (x, y) {
2512
+ var cx = cos(x),
2513
+ cy = cos(y),
2514
+ k = scale(cx * cy);
2515
+ if (k === Infinity) return [2, 0];
2516
+ return [k * cy * sin(x), k * sin(y)];
2517
+ };
2518
+ }
2519
+ function azimuthalInvert(angle) {
2520
+ return function (x, y) {
2521
+ var z = sqrt(x * x + y * y),
2522
+ c = angle(z),
2523
+ sc = sin(c),
2524
+ cc = cos(c);
2525
+ return [atan2(x * sc, z * cc), asin(z && y * sc / z)];
2526
+ };
2527
+ }
2528
+ var azimuthalEqualAreaRaw = azimuthalRaw(function (cxcy) {
2529
+ return sqrt(2 / (1 + cxcy));
2530
+ });
2531
+ azimuthalEqualAreaRaw.invert = azimuthalInvert(function (z) {
2532
+ return 2 * asin(z / 2);
2533
+ });
2534
+ function azimuthalEqualArea() {
2535
+ return projection(azimuthalEqualAreaRaw).scale(124.75).clipAngle(180 - 1e-3);
2536
+ }
2537
+ var azimuthalEquidistantRaw = azimuthalRaw(function (c) {
2538
+ return (c = acos(c)) && c / sin(c);
2539
+ });
2540
+ azimuthalEquidistantRaw.invert = azimuthalInvert(function (z) {
2541
+ return z;
2542
+ });
2543
+ function azimuthalEquidistant() {
2544
+ return projection(azimuthalEquidistantRaw).scale(79.4188).clipAngle(180 - 1e-3);
2545
+ }
2546
+ function mercatorRaw(lambda, phi) {
2547
+ return [lambda, log(tan((halfPi + phi) / 2))];
2548
+ }
2549
+ mercatorRaw.invert = function (x, y) {
2550
+ return [x, 2 * atan(exp(y)) - halfPi];
2551
+ };
2552
+ function mercator() {
2553
+ return mercatorProjection(mercatorRaw).scale(961 / tau);
2554
+ }
2555
+ function mercatorProjection(project) {
2556
+ var m = projection(project),
2557
+ center = m.center,
2558
+ scale = m.scale,
2559
+ translate = m.translate,
2560
+ clipExtent = m.clipExtent,
2561
+ x0 = null,
2562
+ y0,
2563
+ x1,
2564
+ y1; // clip extent
2565
+
2566
+ m.scale = function (_) {
2567
+ return arguments.length ? (scale(_), reclip()) : scale();
2568
+ };
2569
+ m.translate = function (_) {
2570
+ return arguments.length ? (translate(_), reclip()) : translate();
2571
+ };
2572
+ m.center = function (_) {
2573
+ return arguments.length ? (center(_), reclip()) : center();
2574
+ };
2575
+ m.clipExtent = function (_) {
2576
+ return arguments.length ? (_ == null ? x0 = y0 = x1 = y1 = null : (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reclip()) : x0 == null ? null : [[x0, y0], [x1, y1]];
2577
+ };
2578
+ function reclip() {
2579
+ var k = pi * scale(),
2580
+ t = m(rotation(m.rotate()).invert([0, 0]));
2581
+ return clipExtent(x0 == null ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]] : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
2582
+ }
2583
+ return reclip();
2584
+ }
2585
+ function tany(y) {
2586
+ return tan((halfPi + y) / 2);
2587
+ }
2588
+ function conicConformalRaw(y0, y1) {
2589
+ var cy0 = cos(y0),
2590
+ n = y0 === y1 ? sin(y0) : log(cy0 / cos(y1)) / log(tany(y1) / tany(y0)),
2591
+ f = cy0 * pow(tany(y0), n) / n;
2592
+ if (!n) return mercatorRaw;
2593
+ function project(x, y) {
2594
+ if (f > 0) {
2595
+ if (y < -halfPi + epsilon) y = -halfPi + epsilon;
2596
+ } else {
2597
+ if (y > halfPi - epsilon) y = halfPi - epsilon;
2598
+ }
2599
+ var r = f / pow(tany(y), n);
2600
+ return [r * sin(n * x), f - r * cos(n * x)];
2601
+ }
2602
+ project.invert = function (x, y) {
2603
+ var fy = f - y,
2604
+ r = sign(n) * sqrt(x * x + fy * fy),
2605
+ l = atan2(x, abs(fy)) * sign(fy);
2606
+ if (fy * n < 0) l -= pi * sign(x) * sign(fy);
2607
+ return [l / n, 2 * atan(pow(f / r, 1 / n)) - halfPi];
2608
+ };
2609
+ return project;
2610
+ }
2611
+ function conicConformal() {
2612
+ return conicProjection(conicConformalRaw).scale(109.5).parallels([30, 30]);
2613
+ }
2614
+ function equirectangularRaw(lambda, phi) {
2615
+ return [lambda, phi];
2616
+ }
2617
+ equirectangularRaw.invert = equirectangularRaw;
2618
+ function equirectangular() {
2619
+ return projection(equirectangularRaw).scale(152.63);
2620
+ }
2621
+ function conicEquidistantRaw(y0, y1) {
2622
+ var cy0 = cos(y0),
2623
+ n = y0 === y1 ? sin(y0) : (cy0 - cos(y1)) / (y1 - y0),
2624
+ g = cy0 / n + y0;
2625
+ if (abs(n) < epsilon) return equirectangularRaw;
2626
+ function project(x, y) {
2627
+ var gy = g - y,
2628
+ nx = n * x;
2629
+ return [gy * sin(nx), g - gy * cos(nx)];
2630
+ }
2631
+ project.invert = function (x, y) {
2632
+ var gy = g - y,
2633
+ l = atan2(x, abs(gy)) * sign(gy);
2634
+ if (gy * n < 0) l -= pi * sign(x) * sign(gy);
2635
+ return [l / n, g - sign(n) * sqrt(x * x + gy * gy)];
2636
+ };
2637
+ return project;
2638
+ }
2639
+ function conicEquidistant() {
2640
+ return conicProjection(conicEquidistantRaw).scale(131.154).center([0, 13.9389]);
2641
+ }
2642
+ var A1 = 1.340264,
2643
+ A2 = -0.081106,
2644
+ A3 = 0.000893,
2645
+ A4 = 0.003796,
2646
+ M = sqrt(3) / 2,
2647
+ iterations = 12;
2648
+ function equalEarthRaw(lambda, phi) {
2649
+ var l = asin(M * sin(phi)),
2650
+ l2 = l * l,
2651
+ l6 = l2 * l2 * l2;
2652
+ return [lambda * cos(l) / (M * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2))), l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2))];
2653
+ }
2654
+ equalEarthRaw.invert = function (x, y) {
2655
+ var l = y,
2656
+ l2 = l * l,
2657
+ l6 = l2 * l2 * l2;
2658
+ for (var i = 0, delta, fy, fpy; i < iterations; ++i) {
2659
+ fy = l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2)) - y;
2660
+ fpy = A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2);
2661
+ l -= delta = fy / fpy, l2 = l * l, l6 = l2 * l2 * l2;
2662
+ if (abs(delta) < epsilon2) break;
2663
+ }
2664
+ return [M * x * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2)) / cos(l), asin(sin(l) / M)];
2665
+ };
2666
+ function equalEarth() {
2667
+ return projection(equalEarthRaw).scale(177.158);
2668
+ }
2669
+ function gnomonicRaw(x, y) {
2670
+ var cy = cos(y),
2671
+ k = cos(x) * cy;
2672
+ return [cy * sin(x) / k, sin(y) / k];
2673
+ }
2674
+ gnomonicRaw.invert = azimuthalInvert(atan);
2675
+ function gnomonic() {
2676
+ return projection(gnomonicRaw).scale(144.049).clipAngle(60);
2677
+ }
2678
+ function identity() {
2679
+ var k = 1,
2680
+ tx = 0,
2681
+ ty = 0,
2682
+ sx = 1,
2683
+ sy = 1,
2684
+ // scale, translate and reflect
2685
+ alpha = 0,
2686
+ ca,
2687
+ sa,
2688
+ // angle
2689
+ x0 = null,
2690
+ y0,
2691
+ x1,
2692
+ y1,
2693
+ // clip extent
2694
+ kx = 1,
2695
+ ky = 1,
2696
+ transform = transformer({
2697
+ point: function (x, y) {
2698
+ var p = projection([x, y]);
2699
+ this.stream.point(p[0], p[1]);
2700
+ }
2701
+ }),
2702
+ postclip = identity$1,
2703
+ cache,
2704
+ cacheStream;
2705
+ function reset() {
2706
+ kx = k * sx;
2707
+ ky = k * sy;
2708
+ cache = cacheStream = null;
2709
+ return projection;
2710
+ }
2711
+ function projection(p) {
2712
+ var x = p[0] * kx,
2713
+ y = p[1] * ky;
2714
+ if (alpha) {
2715
+ var t = y * ca - x * sa;
2716
+ x = x * ca + y * sa;
2717
+ y = t;
2718
+ }
2719
+ return [x + tx, y + ty];
2720
+ }
2721
+ projection.invert = function (p) {
2722
+ var x = p[0] - tx,
2723
+ y = p[1] - ty;
2724
+ if (alpha) {
2725
+ var t = y * ca + x * sa;
2726
+ x = x * ca - y * sa;
2727
+ y = t;
2728
+ }
2729
+ return [x / kx, y / ky];
2730
+ };
2731
+ projection.stream = function (stream) {
2732
+ return cache && cacheStream === stream ? cache : cache = transform(postclip(cacheStream = stream));
2733
+ };
2734
+ projection.postclip = function (_) {
2735
+ return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
2736
+ };
2737
+ projection.clipExtent = function (_) {
2738
+ return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$1) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
2739
+ };
2740
+ projection.scale = function (_) {
2741
+ return arguments.length ? (k = +_, reset()) : k;
2742
+ };
2743
+ projection.translate = function (_) {
2744
+ return arguments.length ? (tx = +_[0], ty = +_[1], reset()) : [tx, ty];
2745
+ };
2746
+ projection.angle = function (_) {
2747
+ return arguments.length ? (alpha = _ % 360 * radians, sa = sin(alpha), ca = cos(alpha), reset()) : alpha * degrees;
2748
+ };
2749
+ projection.reflectX = function (_) {
2750
+ return arguments.length ? (sx = _ ? -1 : 1, reset()) : sx < 0;
2751
+ };
2752
+ projection.reflectY = function (_) {
2753
+ return arguments.length ? (sy = _ ? -1 : 1, reset()) : sy < 0;
2754
+ };
2755
+ projection.fitExtent = function (extent, object) {
2756
+ return fitExtent(projection, extent, object);
2757
+ };
2758
+ projection.fitSize = function (size, object) {
2759
+ return fitSize(projection, size, object);
2760
+ };
2761
+ projection.fitWidth = function (width, object) {
2762
+ return fitWidth(projection, width, object);
2763
+ };
2764
+ projection.fitHeight = function (height, object) {
2765
+ return fitHeight(projection, height, object);
2766
+ };
2767
+ return projection;
2768
+ }
2769
+ function naturalEarth1Raw(lambda, phi) {
2770
+ var phi2 = phi * phi,
2771
+ phi4 = phi2 * phi2;
2772
+ return [lambda * (0.8707 - 0.131979 * phi2 + phi4 * (-0.013791 + phi4 * (0.003971 * phi2 - 0.001529 * phi4))), phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4)))];
2773
+ }
2774
+ naturalEarth1Raw.invert = function (x, y) {
2775
+ var phi = y,
2776
+ i = 25,
2777
+ delta;
2778
+ do {
2779
+ var phi2 = phi * phi,
2780
+ phi4 = phi2 * phi2;
2781
+ phi -= delta = (phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4))) - y) / (1.007226 + phi2 * (0.015085 * 3 + phi4 * (-0.044475 * 7 + 0.028874 * 9 * phi2 - 0.005916 * 11 * phi4)));
2782
+ } while (abs(delta) > epsilon && --i > 0);
2783
+ return [x / (0.8707 + (phi2 = phi * phi) * (-0.131979 + phi2 * (-0.013791 + phi2 * phi2 * phi2 * (0.003971 - 0.001529 * phi2)))), phi];
2784
+ };
2785
+ function naturalEarth1() {
2786
+ return projection(naturalEarth1Raw).scale(175.295);
2787
+ }
2788
+ function orthographicRaw(x, y) {
2789
+ return [cos(y) * sin(x), sin(y)];
2790
+ }
2791
+ orthographicRaw.invert = azimuthalInvert(asin);
2792
+ function orthographic() {
2793
+ return projection(orthographicRaw).scale(249.5).clipAngle(90 + epsilon);
2794
+ }
2795
+ function stereographicRaw(x, y) {
2796
+ var cy = cos(y),
2797
+ k = 1 + cos(x) * cy;
2798
+ return [cy * sin(x) / k, sin(y) / k];
2799
+ }
2800
+ stereographicRaw.invert = azimuthalInvert(function (z) {
2801
+ return 2 * atan(z);
2802
+ });
2803
+ function stereographic() {
2804
+ return projection(stereographicRaw).scale(250).clipAngle(142);
2805
+ }
2806
+ function transverseMercatorRaw(lambda, phi) {
2807
+ return [log(tan((halfPi + phi) / 2)), -lambda];
2808
+ }
2809
+ transverseMercatorRaw.invert = function (x, y) {
2810
+ return [-y, 2 * atan(exp(x)) - halfPi];
2811
+ };
2812
+ function transverseMercator() {
2813
+ var m = mercatorProjection(transverseMercatorRaw),
2814
+ center = m.center,
2815
+ rotate = m.rotate;
2816
+ m.center = function (_) {
2817
+ return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
2818
+ };
2819
+ m.rotate = function (_) {
2820
+ return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
2821
+ };
2822
+ return rotate([0, 0, 90]).scale(159.155);
2823
+ }
2824
+ exports.geoAlbers = albers;
2825
+ exports.geoAlbersUsa = albersUsa;
2826
+ exports.geoArea = area;
2827
+ exports.geoAzimuthalEqualArea = azimuthalEqualArea;
2828
+ exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
2829
+ exports.geoAzimuthalEquidistant = azimuthalEquidistant;
2830
+ exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
2831
+ exports.geoBounds = bounds;
2832
+ exports.geoCentroid = centroid;
2833
+ exports.geoCircle = circle;
2834
+ exports.geoClipAntimeridian = clipAntimeridian;
2835
+ exports.geoClipCircle = clipCircle;
2836
+ exports.geoClipExtent = extent;
2837
+ exports.geoClipRectangle = clipRectangle;
2838
+ exports.geoConicConformal = conicConformal;
2839
+ exports.geoConicConformalRaw = conicConformalRaw;
2840
+ exports.geoConicEqualArea = conicEqualArea;
2841
+ exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
2842
+ exports.geoConicEquidistant = conicEquidistant;
2843
+ exports.geoConicEquidistantRaw = conicEquidistantRaw;
2844
+ exports.geoContains = contains;
2845
+ exports.geoDistance = distance;
2846
+ exports.geoEqualEarth = equalEarth;
2847
+ exports.geoEqualEarthRaw = equalEarthRaw;
2848
+ exports.geoEquirectangular = equirectangular;
2849
+ exports.geoEquirectangularRaw = equirectangularRaw;
2850
+ exports.geoGnomonic = gnomonic;
2851
+ exports.geoGnomonicRaw = gnomonicRaw;
2852
+ exports.geoGraticule = graticule;
2853
+ exports.geoGraticule10 = graticule10;
2854
+ exports.geoIdentity = identity;
2855
+ exports.geoInterpolate = interpolate;
2856
+ exports.geoLength = length;
2857
+ exports.geoMercator = mercator;
2858
+ exports.geoMercatorRaw = mercatorRaw;
2859
+ exports.geoNaturalEarth1 = naturalEarth1;
2860
+ exports.geoNaturalEarth1Raw = naturalEarth1Raw;
2861
+ exports.geoOrthographic = orthographic;
2862
+ exports.geoOrthographicRaw = orthographicRaw;
2863
+ exports.geoPath = index;
2864
+ exports.geoProjection = projection;
2865
+ exports.geoProjectionMutator = projectionMutator;
2866
+ exports.geoRotation = rotation;
2867
+ exports.geoStereographic = stereographic;
2868
+ exports.geoStereographicRaw = stereographicRaw;
2869
+ exports.geoStream = geoStream;
2870
+ exports.geoTransform = transform;
2871
+ exports.geoTransverseMercator = transverseMercator;
2872
+ exports.geoTransverseMercatorRaw = transverseMercatorRaw;
2873
+ });