@konfirm/geojson 1.0.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 (122) hide show
  1. package/.editorconfig +16 -0
  2. package/.github/workflows/release.yml +21 -0
  3. package/.github/workflows/tests.yml +56 -0
  4. package/CHANGELOG.md +21 -0
  5. package/LICENSE +21 -0
  6. package/README.md +260 -0
  7. package/dist/Domain/Constants.d.ts +5 -0
  8. package/dist/Domain/GeoJSON/Concept/Altitude.d.ts +3 -0
  9. package/dist/Domain/GeoJSON/Concept/BoundingBox.d.ts +6 -0
  10. package/dist/Domain/GeoJSON/Concept/ExteriorRing.d.ts +4 -0
  11. package/dist/Domain/GeoJSON/Concept/GeoJSONObject.d.ts +11 -0
  12. package/dist/Domain/GeoJSON/Concept/InteriorRing.d.ts +4 -0
  13. package/dist/Domain/GeoJSON/Concept/Latitude.d.ts +3 -0
  14. package/dist/Domain/GeoJSON/Concept/LinearRing.d.ts +4 -0
  15. package/dist/Domain/GeoJSON/Concept/Longitude.d.ts +3 -0
  16. package/dist/Domain/GeoJSON/Concept/Position.d.ts +7 -0
  17. package/dist/Domain/GeoJSON/Feature.d.ts +12 -0
  18. package/dist/Domain/GeoJSON/FeatureCollection.d.ts +8 -0
  19. package/dist/Domain/GeoJSON/GeoJSON.d.ts +7 -0
  20. package/dist/Domain/GeoJSON/Geometry/LineString.d.ts +11 -0
  21. package/dist/Domain/GeoJSON/Geometry/MultiLineString.d.ts +7 -0
  22. package/dist/Domain/GeoJSON/Geometry/MultiPoint.d.ts +8 -0
  23. package/dist/Domain/GeoJSON/Geometry/MultiPolygon.d.ts +7 -0
  24. package/dist/Domain/GeoJSON/Geometry/Point.d.ts +11 -0
  25. package/dist/Domain/GeoJSON/Geometry/Polygon.d.ts +11 -0
  26. package/dist/Domain/GeoJSON/Geometry.d.ts +9 -0
  27. package/dist/Domain/GeoJSON/GeometryCollection.d.ts +8 -0
  28. package/dist/Domain/GeoJSON/GeometryObject.d.ts +12 -0
  29. package/dist/Domain/Guards/Number.d.ts +3 -0
  30. package/dist/Domain/Guards/Tuple.d.ts +3 -0
  31. package/dist/Domain/Iterator/IterablePair.d.ts +32 -0
  32. package/dist/Domain/Iterator/SimpleGeometry.d.ts +90 -0
  33. package/dist/Domain/Utility/Calculate.d.ts +9 -0
  34. package/dist/Domain/Utility/Distance.d.ts +3 -0
  35. package/dist/Domain/Utility/Intersect.d.ts +2 -0
  36. package/dist/Domain/Utility/Segments.d.ts +2 -0
  37. package/dist/Domain/Utility/Winding.d.ts +3 -0
  38. package/dist/geojson.cjs.js +655 -0
  39. package/dist/geojson.cjs.min.js +1 -0
  40. package/dist/geojson.d.ts +198 -0
  41. package/dist/geojson.es.js +627 -0
  42. package/dist/geojson.es.min.js +1 -0
  43. package/dist/geojson.js +660 -0
  44. package/dist/geojson.min.js +1 -0
  45. package/dist/main.d.ts +15 -0
  46. package/package.json +63 -0
  47. package/rollup.config.mjs +43 -0
  48. package/source/Domain/Constants.ts +5 -0
  49. package/source/Domain/GeoJSON/Concept/Altitude.ts +9 -0
  50. package/source/Domain/GeoJSON/Concept/BoundingBox.ts +31 -0
  51. package/source/Domain/GeoJSON/Concept/ExteriorRing.ts +12 -0
  52. package/source/Domain/GeoJSON/Concept/GeoJSONObject.ts +23 -0
  53. package/source/Domain/GeoJSON/Concept/InteriorRing.ts +12 -0
  54. package/source/Domain/GeoJSON/Concept/Latitude.ts +7 -0
  55. package/source/Domain/GeoJSON/Concept/LinearRing.ts +14 -0
  56. package/source/Domain/GeoJSON/Concept/Longitude.ts +7 -0
  57. package/source/Domain/GeoJSON/Concept/Position.ts +18 -0
  58. package/source/Domain/GeoJSON/Feature.ts +24 -0
  59. package/source/Domain/GeoJSON/FeatureCollection.ts +16 -0
  60. package/source/Domain/GeoJSON/GeoJSON.ts +9 -0
  61. package/source/Domain/GeoJSON/Geometry/LineString.ts +12 -0
  62. package/source/Domain/GeoJSON/Geometry/MultiLineString.ts +9 -0
  63. package/source/Domain/GeoJSON/Geometry/MultiPoint.ts +10 -0
  64. package/source/Domain/GeoJSON/Geometry/MultiPolygon.ts +9 -0
  65. package/source/Domain/GeoJSON/Geometry/Point.ts +12 -0
  66. package/source/Domain/GeoJSON/Geometry/Polygon.ts +20 -0
  67. package/source/Domain/GeoJSON/Geometry.ts +11 -0
  68. package/source/Domain/GeoJSON/GeometryCollection.ts +23 -0
  69. package/source/Domain/GeoJSON/GeometryObject.ts +20 -0
  70. package/source/Domain/Guards/Number.ts +13 -0
  71. package/source/Domain/Guards/Tuple.ts +6 -0
  72. package/source/Domain/Guards/Utility.ts +1 -0
  73. package/source/Domain/Iterator/IterablePair.ts +47 -0
  74. package/source/Domain/Iterator/SimpleGeometry.ts +137 -0
  75. package/source/Domain/Utility/Calculate.ts +143 -0
  76. package/source/Domain/Utility/Distance.ts +56 -0
  77. package/source/Domain/Utility/Intersect.ts +42 -0
  78. package/source/Domain/Utility/Numeric.ts +8 -0
  79. package/source/Domain/Utility/Segments.ts +5 -0
  80. package/source/Domain/Utility/Winding.ts +19 -0
  81. package/source/main.ts +20 -0
  82. package/test/Domain/GeoJSON/Concept/Altitude.ts +58 -0
  83. package/test/Domain/GeoJSON/Concept/BoundingBox.ts +77 -0
  84. package/test/Domain/GeoJSON/Concept/ExteriorRing.ts +65 -0
  85. package/test/Domain/GeoJSON/Concept/GeoJSONObject.ts +56 -0
  86. package/test/Domain/GeoJSON/Concept/InteriorRing.ts +65 -0
  87. package/test/Domain/GeoJSON/Concept/Latitude.ts +56 -0
  88. package/test/Domain/GeoJSON/Concept/LinearRing.ts +63 -0
  89. package/test/Domain/GeoJSON/Concept/Longitude.ts +56 -0
  90. package/test/Domain/GeoJSON/Concept/Position.ts +56 -0
  91. package/test/Domain/GeoJSON/Feature.ts +9 -0
  92. package/test/Domain/GeoJSON/FeatureCollection.ts +9 -0
  93. package/test/Domain/GeoJSON/GeoJSON.ts +21 -0
  94. package/test/Domain/GeoJSON/Geometry/LineString.ts +11 -0
  95. package/test/Domain/GeoJSON/Geometry/MultiLineString.ts +11 -0
  96. package/test/Domain/GeoJSON/Geometry/MultiPoint.ts +11 -0
  97. package/test/Domain/GeoJSON/Geometry/MultiPolygon.ts +11 -0
  98. package/test/Domain/GeoJSON/Geometry/Point.ts +11 -0
  99. package/test/Domain/GeoJSON/Geometry/Polygon.ts +11 -0
  100. package/test/Domain/GeoJSON/Geometry.ts +9 -0
  101. package/test/Domain/GeoJSON/GeometryCollection.ts +9 -0
  102. package/test/Domain/GeoJSON/GeometryObject.ts +4 -0
  103. package/test/Domain/Guards/Number.ts +49 -0
  104. package/test/Domain/Guards/Tuple.ts +27 -0
  105. package/test/Domain/Iterator/IterablePair.ts +203 -0
  106. package/test/Domain/Iterator/SimpleGeometry.ts +195 -0
  107. package/test/Domain/Utility/Calculate.ts +178 -0
  108. package/test/Domain/Utility/Distance.ts +19 -0
  109. package/test/Domain/Utility/Intersect.ts +54 -0
  110. package/test/Domain/Utility/Numeric.ts +30 -0
  111. package/test/Domain/Utility/Winding.ts +52 -0
  112. package/test/README.ts +123 -0
  113. package/test/data/Distance.ts +51 -0
  114. package/test/data/HolySee.ts +74 -0
  115. package/test/data/Intersect.ts +300 -0
  116. package/test/data/Italy.ts +2883 -0
  117. package/test/data/SanMarino.ts +83 -0
  118. package/test/data/Shapes.ts +107 -0
  119. package/test/helper/geometry.ts +76 -0
  120. package/test/helper/malform.ts +82 -0
  121. package/test/main.ts +4 -0
  122. package/tsconfig.json +12 -0
@@ -0,0 +1,655 @@
1
+ 'use strict';
2
+
3
+ function segments(line) {
4
+ return line.slice(1).map((point, index) => [line[index], point]);
5
+ }
6
+
7
+ const EARTH_RADIUS = 6371008.7714; // mean radius
8
+ const EARTH_RADIUS_MAJOR = 6378137; // equatorial radius
9
+ const EARTH_RADIUS_MINOR = 6356752.314245; // semiminor axis
10
+ const EARTH_FLATTENING = 298.257223563;
11
+ const GPS_SATELLITE_ORBIT = 20180000;
12
+
13
+ const D2R = Math.PI / 180;
14
+ const π = Math.PI;
15
+ function constrain(value, min, max) {
16
+ return Math.max(Math.min(value, max), min);
17
+ }
18
+ function squared(n) {
19
+ return n * n;
20
+ }
21
+ function rad(n) {
22
+ return n * D2R;
23
+ }
24
+ const EARTH_RADIUS_MAJOR_SQUARED = squared(EARTH_RADIUS_MAJOR);
25
+ const EARTH_RADIUS_MINOR_SQUARED = squared(EARTH_RADIUS_MINOR);
26
+ const EARTH_RADIUS_FACTOR = (EARTH_RADIUS_MAJOR_SQUARED - EARTH_RADIUS_MINOR_SQUARED) / EARTH_RADIUS_MINOR_SQUARED;
27
+ const EARTH_INVERSE_FLATTENING = 1 / EARTH_FLATTENING;
28
+ const PointToPoint = {
29
+ cartesian([λa, φa], [λb, φb]) {
30
+ return EARTH_RADIUS * rad(Math.sqrt(squared(λb - λa) + squared(φb - φa)));
31
+ },
32
+ haversine([λa, φa], [λb, φb]) {
33
+ //https://www.movable-type.co.uk/scripts/latlong.html
34
+ const Δ = squared(Math.sin(rad(φb - φa) / 2)) + Math.cos(rad(φa)) * Math.cos(rad(φb)) * squared(Math.sin(rad(λb - λa) / 2));
35
+ return EARTH_RADIUS * Math.atan2(Math.sqrt(Δ), Math.sqrt(1 - Δ)) * 2;
36
+ },
37
+ vincenty(...points) {
38
+ //https://www.movable-type.co.uk/scripts/latlong-vincenty.html
39
+ const [[λ1, φ1], [λ2, φ2]] = points.map((p) => p.map(rad));
40
+ const L = λ2 - λ1; // L = difference in longitude, U = reduced latitude, defined by tan U = (1-f)·tanφ.
41
+ const tanU1 = (1 - EARTH_INVERSE_FLATTENING) * Math.tan(φ1), cosU1 = 1 / Math.sqrt((1 + tanU1 * tanU1)), sinU1 = tanU1 * cosU1;
42
+ const tanU2 = (1 - EARTH_INVERSE_FLATTENING) * Math.tan(φ2), cosU2 = 1 / Math.sqrt((1 + tanU2 * tanU2)), sinU2 = tanU2 * cosU2;
43
+ const antipodal = Math.abs(L) > π / 2 || Math.abs(φ2 - φ1) > π / 2;
44
+ let λ = L;
45
+ let sinλ = null;
46
+ let cosλ = null; // λ = difference in longitude on an auxiliary sphere
47
+ let σ = antipodal ? π : 0;
48
+ let sinσ = 0;
49
+ let cosσ = antipodal ? -1 : 1;
50
+ let sinSqσ = null; // σ = angular distance P₁ P₂ on the sphere
51
+ let cos2σₘ = 1; // σₘ = angular distance on the sphere from the equator to the midpoint of the line
52
+ let cosSqα = 1; // α = azimuth of the geodesic at the equator
53
+ let λʹ = null;
54
+ let iterations = 0;
55
+ do {
56
+ sinλ = Math.sin(λ);
57
+ cosλ = Math.cos(λ);
58
+ sinSqσ = (cosU2 * sinλ) ** 2 + (cosU1 * sinU2 - sinU1 * cosU2 * cosλ) ** 2;
59
+ if (Math.abs(sinSqσ) < 1e-24)
60
+ break; // co-incident/antipodal points (σ < ≈0.006mm)
61
+ sinσ = Math.sqrt(sinSqσ);
62
+ cosσ = sinU1 * sinU2 + cosU1 * cosU2 * cosλ;
63
+ σ = Math.atan2(sinσ, cosσ);
64
+ const sinα = cosU1 * cosU2 * sinλ / sinσ;
65
+ cosSqα = 1 - sinα * sinα;
66
+ cos2σₘ = (cosSqα != 0) ? (cosσ - 2 * sinU1 * sinU2 / cosSqα) : 0; // on equatorial line cos²α = 0 (§6)
67
+ const C = EARTH_INVERSE_FLATTENING / 16 * cosSqα * (4 + EARTH_INVERSE_FLATTENING * (4 - 3 * cosSqα));
68
+ λʹ = λ;
69
+ λ = L + (1 - C) * EARTH_INVERSE_FLATTENING * sinα * (σ + C * sinσ * (cos2σₘ + C * cosσ * (-1 + 2 * cos2σₘ * cos2σₘ)));
70
+ // TODO: add tests
71
+ // const iterationCheck = antipodal ? Math.abs(λ) - π : Math.abs(λ);
72
+ // if (iterationCheck > π) throw new EvalError('λ > π');
73
+ } while (Math.abs(λ - λʹ) > 1e-12 && ++iterations < 1000); // TV: 'iterate until negligible change in λ' (≈0.006mm)
74
+ // TODO: add tests
75
+ // if (iterations >= 1000) throw new EvalError('Vincenty formula failed to converge');
76
+ const uSq = cosSqα * EARTH_RADIUS_FACTOR;
77
+ const A = 1 + uSq / 16384 * (4096 + uSq * (-768 + uSq * (320 - 175 * uSq)));
78
+ const B = uSq / 1024 * (256 + uSq * (-128 + uSq * (74 - 47 * uSq)));
79
+ const Δσ = B * sinσ * (cos2σₘ + B / 4 * (cosσ * (-1 + 2 * cos2σₘ * cos2σₘ) - B / 6 * cos2σₘ * (-3 + 4 * sinσ * sinσ) * (-3 + 4 * cos2σₘ * cos2σₘ)));
80
+ return EARTH_RADIUS_MINOR * A * (σ - Δσ);
81
+ },
82
+ };
83
+ function getClosestPointOnLineByPoint(point, line) {
84
+ const [[px, py], [ax, ay], [bx, by]] = [point, ...line];
85
+ const [abx, aby] = [bx - ax, by - ay];
86
+ const [apx, apy] = [px - ax, py - ay];
87
+ const t = constrain((apx * abx + apy * aby) / (abx * abx + aby * aby), 0, 1);
88
+ return t === 0 || t === 1 ? line[t] : [ax + abx * t, ay + aby * t];
89
+ }
90
+ function getDistanceOfPointToPoint(a, b, calculation) {
91
+ const calc = typeof calculation === 'function' ? calculation : PointToPoint[calculation];
92
+ if (typeof calc === 'function') {
93
+ return calc(a, b);
94
+ }
95
+ throw new Error(`Not a PointToPoint calculation function ${calculation}`);
96
+ }
97
+ function getDistanceOfPointToLine(point, line, calculation) {
98
+ return getDistanceOfPointToPoint(point, getClosestPointOnLineByPoint(point, line), calculation);
99
+ }
100
+ function getDistanceOfLineToLine(a, b, calculation) {
101
+ return isLinesCrossing(a, b)
102
+ ? 0
103
+ : Math.min(...a.map((a) => getDistanceOfPointToLine(a, b, calculation)), ...b.map((b) => getDistanceOfPointToLine(b, a, calculation)));
104
+ }
105
+ function isLinesCrossing(a, b) {
106
+ const [[a1x, a1y], [a2x, a2y]] = a;
107
+ const [[b1x, b1y], [b2x, b2y]] = b;
108
+ const [s1x, s1y, s2x, s2y] = [a2x - a1x, a2y - a1y, b2x - b1x, b2y - b1y];
109
+ const s = (-s1y * (a1x - b1x) + s1x * (a1y - b1y)) / (-s2x * s1y + s1x * s2y);
110
+ const t = (s2x * (a1y - b1y) - s2y * (a1x - b1x)) / (-s2x * s1y + s1x * s2y);
111
+ return s >= 0 && s <= 1 && t >= 0 && t <= 1;
112
+ }
113
+ function isPointOnLine(point, line, threshold = 1e-14) {
114
+ return getDistanceOfPointToLine(point, line, 'cartesian') < threshold;
115
+ }
116
+ function isPointInRing(p, ring) {
117
+ const { length } = ring;
118
+ const odd = ring
119
+ .reduce((odd, a, i) => {
120
+ const b = ring[(length + i - 1) % length];
121
+ return (a[1] < p[1] && b[1] >= p[1] || b[1] < p[1] && a[1] >= p[1]) && (a[0] <= p[0] || b[0] <= p[0])
122
+ ? odd ^ Number(a[0] + (p[1] - a[1]) / (b[1] - a[1]) * (b[0] - a[0]) < p[0])
123
+ : odd;
124
+ }, 0);
125
+ return odd !== 0 || ring.slice(1).some((a, index) => isPointOnLine(p, [ring[index], a]));
126
+ }
127
+
128
+ /**
129
+ * Iterator class to turn any GeoJSON structure into one or more SimpleGeometry (Point | LineString | Polygon) objects
130
+ *
131
+ * @export
132
+ * @class SimpleGeometryIterator
133
+ */
134
+ class SimpleGeometryIterator {
135
+ /**
136
+ * Creates an instance of SimpleGeometryIterator
137
+ *
138
+ * @param {...[GeoJSON, ...Array<GeoJSON>]} inputs
139
+ * @memberof SimpleGeometryIterator
140
+ */
141
+ constructor(...inputs) {
142
+ this.inputs = [];
143
+ this.inputs = inputs;
144
+ }
145
+ /**
146
+ * Generator yielding all SimpleGeometry objects from the provided GeoJSON structure(s)
147
+ *
148
+ * @return {*} {Iterator<SimpleGeometry>}
149
+ * @memberof SimpleGeometryIterator
150
+ */
151
+ *[Symbol.iterator]() {
152
+ for (const input of this.inputs) {
153
+ for (const simple of this.unwrap(input)) {
154
+ yield simple;
155
+ }
156
+ }
157
+ }
158
+ /**
159
+ * unwrap any GeoJSON object into one or more SimpleGeometry object
160
+ *
161
+ * @private
162
+ * @param {GeoJSON} geo
163
+ * @return {*} {Iterable<SimpleGeometry>}
164
+ * @memberof SimpleGeometryIterator
165
+ */
166
+ *unwrap(geo) {
167
+ geo.type in this
168
+ ? yield* this[geo.type](geo)
169
+ : yield geo;
170
+ }
171
+ /**
172
+ * Generate the geometries in a GeometryCollection
173
+ *
174
+ * @private
175
+ * @param {GeometryCollection} { geometries }
176
+ * @return {*} {Iterable<SimpleGeometry>}
177
+ * @memberof SimpleGeometryIterator
178
+ */
179
+ *GeometryCollection({ geometries }) {
180
+ for (const geometry of geometries) {
181
+ yield* this.unwrap(geometry);
182
+ }
183
+ }
184
+ /**
185
+ * Generate the geometries of the Feature object(s) in a FeatureCollection
186
+ *
187
+ * @private
188
+ * @param {FeatureCollection} { features }
189
+ * @return {*} {Iterable<SimpleGeometry>}
190
+ * @memberof SimpleGeometryIterator
191
+ */
192
+ *FeatureCollection({ features }) {
193
+ for (const { geometry } of features) {
194
+ yield* this.unwrap(geometry);
195
+ }
196
+ }
197
+ /**
198
+ * Generate the geometry of a Feature object
199
+ *
200
+ * @private
201
+ * @param {Feature} { geometry }
202
+ * @return {*} {Iterable<SimpleGeometry>}
203
+ * @memberof SimpleGeometryIterator
204
+ */
205
+ *Feature({ geometry }) {
206
+ yield* this.unwrap(geometry);
207
+ }
208
+ /**
209
+ * Generate Point objects from a MultiPoint object
210
+ *
211
+ * @private
212
+ * @param {MultiPoint} multi
213
+ * @return {*} {Iterable<Point>}
214
+ * @memberof SimpleGeometryIterator
215
+ */
216
+ *MultiPoint(multi) {
217
+ for (const coordinates of multi.coordinates) {
218
+ yield { type: 'Point', coordinates };
219
+ }
220
+ }
221
+ /**
222
+ * Generate LineString objects from a MultiLineString object
223
+ *
224
+ * @private
225
+ * @param {MultiLineString} multi
226
+ * @return {*} {Iterable<LineString>}
227
+ * @memberof SimpleGeometryIterator
228
+ */
229
+ *MultiLineString(multi) {
230
+ for (const coordinates of multi.coordinates) {
231
+ yield { type: 'LineString', coordinates };
232
+ }
233
+ }
234
+ /**
235
+ * Generate Polygon objects from a MultiPolygon object
236
+ *
237
+ * @private
238
+ * @param {MultiPolygon} multi
239
+ * @return {*} {Iterable<Polygon>}
240
+ * @memberof SimpleGeometryIterator
241
+ */
242
+ *MultiPolygon(multi) {
243
+ for (const coordinates of multi.coordinates) {
244
+ yield { type: 'Polygon', coordinates };
245
+ }
246
+ }
247
+ }
248
+
249
+ /**
250
+ * Iterator class which traverses all value pairs of two or more Iterable instances
251
+ *
252
+ * @export
253
+ * @class IterablePairIterator
254
+ * @template T
255
+ */
256
+ class IterablePairIterator {
257
+ /**
258
+ * Constructs a new instance of IterablePairIterator
259
+ *
260
+ * @param iterators
261
+ */
262
+ constructor(...iterators) {
263
+ this.iterators = [];
264
+ this.iterators = iterators;
265
+ }
266
+ /**
267
+ * Generator yielding all value pairs from the provided iterators
268
+ *
269
+ * @return {*} {Iterator<[T, T]>}
270
+ * @memberof IterablePairIterator
271
+ */
272
+ *[Symbol.iterator]() {
273
+ for (const [a, b] of this.pairs(this.iterators)) {
274
+ for (const one of a) {
275
+ for (const two of b) {
276
+ yield [one, two];
277
+ }
278
+ }
279
+ }
280
+ }
281
+ /**
282
+ * Create unique Iterator<T> combinations to traverse over
283
+ *
284
+ * @private
285
+ * @param {Array<Iterable<T>>} source
286
+ * @return {*} {Array<[Iterable<T>, Iterable<T>]>}
287
+ * @memberof IterablePairIterator
288
+ */
289
+ pairs(source) {
290
+ return source.map((a, i) => source.slice(i + 1).map((b) => [a, b])).flat();
291
+ }
292
+ }
293
+
294
+ const geometries$1 = {
295
+ PointPoint(a, b) {
296
+ return a.length >= 2 && b.length >= 2 && a.slice(0, 2).every((v, i) => v === b[i]);
297
+ },
298
+ LineStringPoint(a, b) {
299
+ return a.some((a) => this.PointPoint(a, b)) || segments(a).some((line) => isPointOnLine(b, line));
300
+ },
301
+ LineStringLineString(a, b) {
302
+ const lines = segments(b);
303
+ return segments(a).some((a) => lines.some((b) => isLinesCrossing(a, b)));
304
+ },
305
+ PolygonPoint([exterior, ...interior], b) {
306
+ return (this.LineStringPoint(exterior, b) || isPointInRing(b, exterior)) && (!interior.length || interior.every((ring) => !isPointInRing(b, ring)));
307
+ },
308
+ PolygonLineString(a, b) {
309
+ return a.some((ring) => this.LineStringLineString(ring, b)) || b.some((point) => this.PolygonPoint(a, point));
310
+ },
311
+ PolygonPolygon(a, b) {
312
+ return b.some((b1) => this.PolygonLineString(a, b1) || b1.some((b2) => this.PolygonPoint(a, b2)))
313
+ || a.some((a1) => this.PolygonLineString(b, a1) || a1.some((a2) => this.PolygonPoint(b, a2)));
314
+ },
315
+ };
316
+ function intersect(a, b) {
317
+ for (const [itA, itB] of new IterablePairIterator(new SimpleGeometryIterator(a), new SimpleGeometryIterator(b))) {
318
+ if ((itA.type + itB.type in geometries$1 && geometries$1[itA.type + itB.type](itA.coordinates, itB.coordinates)) || (itB.type + itA.type in geometries$1 && geometries$1[itB.type + itA.type](itB.coordinates, itA.coordinates))) {
319
+ return true;
320
+ }
321
+ }
322
+ return false;
323
+ }
324
+
325
+ const geometries = {
326
+ PointPoint(a, b, calculation) {
327
+ return getDistanceOfPointToPoint(a, b, calculation);
328
+ },
329
+ LineStringPoint(a, b, calculation) {
330
+ return Math.min(...segments(a).map((line) => getDistanceOfPointToLine(b, line, calculation)));
331
+ },
332
+ LineStringLineString(a, b, calculation) {
333
+ const sa = segments(a);
334
+ const sb = segments(b);
335
+ return sa.reduce((carry, a) => sb.reduce((carry, b) => carry > 0 ? Math.min(carry, getDistanceOfLineToLine(a, b, calculation)) : carry, carry), Infinity);
336
+ },
337
+ PolygonPoint([exterior, ...interior], b, calculation) {
338
+ if (isPointInRing(b, exterior)) {
339
+ const [excluded] = interior.filter((ring) => isPointInRing(b, ring));
340
+ return excluded ? this.LineStringPoint(excluded, b, calculation) : 0;
341
+ }
342
+ return this.LineStringPoint(exterior, b, calculation);
343
+ },
344
+ PolygonLineString(a, b, calculation) {
345
+ const [exterior, ...interior] = a;
346
+ const line = segments(b);
347
+ const ring = b.some((b) => isPointInRing(b, exterior))
348
+ ? interior.find((a) => b.every((b) => isPointInRing(b, a)))
349
+ : exterior;
350
+ return ring
351
+ ? Math.min(...segments(ring).map((a) => Math.min(...line.map((b) => getDistanceOfLineToLine(a, b, calculation)))))
352
+ : 0;
353
+ },
354
+ PolygonPolygon(a, b, calculation) {
355
+ return Math.min(this.PolygonLineString(a, b[0], calculation), this.PolygonLineString(b, a[0], calculation));
356
+ },
357
+ };
358
+ function distance(a, b, calculation = 'cartesian') {
359
+ return Math.min(...[...new IterablePairIterator(new SimpleGeometryIterator(a), new SimpleGeometryIterator(b))].map(([a, b]) => {
360
+ return a.type + b.type in geometries
361
+ ? geometries[a.type + b.type](a.coordinates, b.coordinates, calculation)
362
+ : b.type + a.type in geometries
363
+ ? geometries[b.type + a.type](b.coordinates, a.coordinates, calculation)
364
+ : Infinity;
365
+ }));
366
+ }
367
+
368
+ class TypeMapper {
369
+ constructor(mapping = {}) {
370
+ this.mapping = Object.keys(mapping)
371
+ .map((key) => (value) => mapping[key](value) ? key : undefined)
372
+ .concat((value) => typeof value);
373
+ }
374
+ map(value) {
375
+ return this.mapping.reduce((carry, map) => carry || map(value), undefined);
376
+ }
377
+ }
378
+
379
+ class ValueMapper {
380
+ constructor(types = new TypeMapper(), mapping = {}) {
381
+ this.types = types;
382
+ this.mapping = mapping;
383
+ }
384
+ map(value) {
385
+ const type = this.types.map(value);
386
+ const map = (value) => this.map(value);
387
+ return type in this.mapping
388
+ ? this.mapping[type](value, map)
389
+ : (value === null || value === void 0 ? void 0 : value.toString()) || 'undefined';
390
+ }
391
+ }
392
+
393
+ const types = new TypeMapper({
394
+ date: (value) => value instanceof Date,
395
+ regexp: (value) => value instanceof RegExp,
396
+ array: (value) => Array.isArray(value),
397
+ null: (value) => value === null,
398
+ });
399
+ new ValueMapper(types, {
400
+ string: (value) => value ? `"${value}"` : 'EmptyString',
401
+ date: (value, map) => map(value.toISOString()),
402
+ object: (value, map) => {
403
+ const string = String(value);
404
+ if (/^\[([a-z]+) \1\]$/i.test(string)) {
405
+ const mapped = Object.keys(value)
406
+ .map((key) => `${key}:${map(value[key])}`);
407
+ return `{${mapped.join(',')}}`;
408
+ }
409
+ return string;
410
+ },
411
+ array: (value, map) => `[${value.map(map).join(',')}]`,
412
+ null: () => 'NULL',
413
+ undefined: () => 'Undefined',
414
+ function: (value) => {
415
+ const { constructor: { name: cname }, name } = value;
416
+ const [, async, generator, func] = cname.match(/^(async)?(generator)?(function)$/i);
417
+ const [, stype, sname] = value.toString().match(/^(?:async)?(?:[\s\*]+)?(class|function)?(?:[\s\*]+)?([a-z_]\w*)?\s*[\(\{]?/i);
418
+ const parts = []
419
+ .concat(stype && !(name || sname) ? 'anonymous' : [])
420
+ .concat(name && !stype && sname ? 'shorthand' : [])
421
+ .concat(async || [], generator || [])
422
+ .concat(!(stype || sname) ? 'arrow' : [])
423
+ .concat(stype || func)
424
+ .map((key) => key[0].toUpperCase() + key.slice(1));
425
+ return [parts.join('')].concat(name || []).join(' ');
426
+ },
427
+ });
428
+
429
+ /**
430
+ * Create a guard verifying the given value matches the specified type
431
+ */
432
+ function is(type) {
433
+ return (value) => typeof value === type;
434
+ }
435
+ /**
436
+ * Create a guard verifying the given value matches any of the validators
437
+ */
438
+ function any(...checks) {
439
+ return (value) => checks.some((check) => check(value));
440
+ }
441
+ /**
442
+ * Create a guard verifying the given value matches all of the validators
443
+ */
444
+ function all(...checks) {
445
+ return (value) => checks.every((check) => check(value));
446
+ }
447
+ /**
448
+ * Create a guard verifying the given value matches none of the validators
449
+ */
450
+ function not(...checks) {
451
+ return (value) => checks.every((check) => !check(value));
452
+ }
453
+
454
+ /**
455
+ * Guard verifying the value is a array
456
+ */
457
+ const isArray = (value) => Array.isArray(value);
458
+ /**
459
+ * Guard verifying the value is a null
460
+ */
461
+ const isNULL = (value) => value === null;
462
+ /**
463
+ * Guard verifying the value is a number
464
+ */
465
+ const isNumber = is('number');
466
+ /**
467
+ * Guard verifying the value is a object
468
+ */
469
+ const isObject = all(not(isArray), not(isNULL), is('object'));
470
+ /**
471
+ * Guard verifying the value is a string
472
+ */
473
+ const isString = is('string');
474
+
475
+ /**
476
+ * Guard verifying the value to be an array containing only elements matching the validators
477
+ */
478
+ function isArrayOfType(...validators) {
479
+ const check = all(...validators);
480
+ return all(isArray, (value) => value.every(check));
481
+ }
482
+ /**
483
+ * Guard verifying the value to be an array with a length between the given boundaries
484
+ */
485
+ function isArrayOfSize(min, max = Infinity) {
486
+ return all(isArray, (value) => value.length >= min && value.length <= max);
487
+ }
488
+
489
+ /**
490
+ * Creates a guard verifying the value is an object and has the given key
491
+ */
492
+ function isKey(key) {
493
+ return all(isObject, (value) => key in value);
494
+ }
495
+ /**
496
+ * Creates a guard verifying the value is an object and has the given key matching the validators
497
+ */
498
+ function isKeyOfType(key, ...validators) {
499
+ return all(isKey(key), (value) => validators.every((check) => check(value[key])));
500
+ }
501
+ /**
502
+ * Creates a guard verifying the value is an object and doesn't have the key or has the given key matching the validators
503
+ */
504
+ function isOptionalKeyOfType(key, ...validators) {
505
+ return any(all(isObject, not(isKey(key))), isKeyOfType(key, ...validators));
506
+ }
507
+ /**
508
+ * Creates a guard verifying the value is an object matching at least the structure
509
+ */
510
+ function isStructure(struct, ...options) {
511
+ const optional = options.reduce((carry, key) => carry.concat(key), []);
512
+ const validators = Object.keys(struct)
513
+ .map((key) => (optional.includes(key) ? isOptionalKeyOfType : isKeyOfType)(key, struct[key]));
514
+ return all(isObject, ...validators);
515
+ }
516
+
517
+ function isTuple(...rules) {
518
+ return (value) => isArray(value) && value.length === rules.length && rules.every((rule, index) => rule(value[index]));
519
+ }
520
+
521
+ function isNumberValue(value) {
522
+ return isNumber(value) && Number.isFinite(value);
523
+ }
524
+ function isNumberBetween(a, b = Infinity) {
525
+ const min = Math.min(a, b);
526
+ const max = Math.max(a, b);
527
+ return (value) => isNumberValue(value) && value >= min && value <= max;
528
+ }
529
+
530
+ function isAltitude(value) {
531
+ return isNumberValue(value);
532
+ }
533
+ const isStrictAltitude = isNumberBetween(-EARTH_RADIUS, GPS_SATELLITE_ORBIT);
534
+
535
+ function isLatitude(value) {
536
+ return isNumberValue(value);
537
+ }
538
+ const isStrictLatitude = isNumberBetween(-90, 90);
539
+
540
+ function isLongitude(value) {
541
+ return isNumberValue(value);
542
+ }
543
+ const isStrictLongitude = isNumberBetween(-180, 180);
544
+
545
+ const isPosition = any(isTuple(isLongitude, isLatitude), isTuple(isLongitude, isLatitude, isAltitude));
546
+ const isStrictPosition = any(isTuple(isStrictLongitude, isStrictLatitude), isTuple(isStrictLongitude, isStrictLatitude, isStrictAltitude));
547
+
548
+ const isBoundingBoxWithAltitude = all(isTuple(isLongitude, isLatitude, isAltitude, isLongitude, isLatitude, isAltitude), ([, s, , , n]) => s <= n);
549
+ const isBoundingBoxWithoutAltitude = all(isTuple(isLongitude, isLatitude, isLongitude, isLatitude), ([, s, , n]) => s <= n);
550
+ const isBoundingBox = any(isBoundingBoxWithAltitude, isBoundingBoxWithoutAltitude);
551
+
552
+ function isGeoJSONObject(type) {
553
+ return isStructure({
554
+ type: all(isString, (value) => value === type),
555
+ bbox: isBoundingBox,
556
+ }, 'bbox');
557
+ }
558
+
559
+ function isGeometryObject(type, isCoordinates) {
560
+ return all(isGeoJSONObject(type), isKeyOfType('coordinates', isCoordinates));
561
+ }
562
+
563
+ const isPointCoordinates = isPosition;
564
+ const isPoint = isGeometryObject('Point', isPointCoordinates);
565
+ const isStrictPointCoordinates = isStrictPosition;
566
+ const isStrictPoint = isGeometryObject('Point', isStrictPointCoordinates);
567
+
568
+ const isMultiPointCoordinates = isArrayOfType(isPointCoordinates);
569
+ const isMultiPoint = isGeometryObject('MultiPoint', isMultiPointCoordinates);
570
+ const isStrictMultiPointCoordinates = isArrayOfType(isStrictPointCoordinates);
571
+ const isStrictMultiPoint = isGeometryObject('MultiPoint', isStrictMultiPointCoordinates);
572
+
573
+ const isLineStringCoordinates = isMultiPointCoordinates;
574
+ const isLineString = isGeometryObject('LineString', isLineStringCoordinates);
575
+ const isStrictLineStringCoordinates = isStrictMultiPointCoordinates;
576
+ const isStrictLineString = isGeometryObject('LineString', isStrictLineStringCoordinates);
577
+
578
+ const isMultiLineStringCoordinates = isArrayOfType(isLineStringCoordinates);
579
+ const isMultiLineString = isGeometryObject('MultiLineString', isMultiLineStringCoordinates);
580
+ const isStrictMultiLineStringCoordinates = isArrayOfType(isStrictLineStringCoordinates);
581
+ const isStrictMultiLineString = isGeometryObject('MultiLineString', isStrictMultiLineStringCoordinates);
582
+
583
+ isArrayOfType(isPosition);
584
+
585
+ const isLinearRing = all(isArrayOfType(isPosition), isArrayOfSize(4), (value) => value[value.length - 1].every((v, i) => v === value[0][i]));
586
+ const isStrictLinearRing = all(isArrayOfType(isStrictPosition), isArrayOfSize(4), (value) => value[value.length - 1].every((v, i) => v === value[0][i]));
587
+
588
+ const isExteriorRing = all(isLinearRing);
589
+
590
+ const isInteriorRing = all(isLinearRing);
591
+
592
+ const isPolygonCoordinates = all(isArrayOfType(isLinearRing));
593
+ const isPolygon = isGeometryObject('Polygon', isPolygonCoordinates);
594
+ const isStrictPolygonCoordinates = all(isArrayOfType(isStrictLinearRing), (value) => isExteriorRing(value[0]), (value) => value.slice(1).every(isInteriorRing));
595
+ const isStrictPolygon = isGeometryObject('Polygon', isStrictPolygonCoordinates);
596
+
597
+ const isMultiPolygonCoordinates = isArrayOfType(isPolygonCoordinates);
598
+ const isMultiPolygon = isGeometryObject('MultiPolygon', isMultiPolygonCoordinates);
599
+ const isStrictMultiPolygonCoordinates = isArrayOfType(isStrictPolygonCoordinates);
600
+ const isStrictMultiPolygon = isGeometryObject('MultiPolygon', isStrictMultiPolygonCoordinates);
601
+
602
+ const isGeometry = any(isPoint, isMultiPoint, isLineString, isMultiLineString, isPolygon, isMultiPolygon);
603
+ const isStrictGeometry = any(isStrictPoint, isStrictMultiPoint, isStrictLineString, isStrictMultiLineString, isStrictPolygon, isStrictMultiPolygon);
604
+
605
+ const isGeometryCollectionObject = all(isGeoJSONObject('GeometryCollection'), isKeyOfType('geometries', isArrayOfType(any(isGeometry, isGeometryCollection))));
606
+ const isStrictGeometryCollectionObject = all(isGeoJSONObject('GeometryCollection'), isKeyOfType('geometries', isArrayOfType(any(isStrictGeometry, isStrictGeometryCollection))));
607
+ function isGeometryCollection(value) {
608
+ return isGeometryCollectionObject(value);
609
+ }
610
+ function isStrictGeometryCollection(value) {
611
+ return isStrictGeometryCollectionObject(value);
612
+ }
613
+
614
+ const isFeature = all(isGeoJSONObject('Feature'), isStructure({
615
+ geometry: any(isGeometry, isGeometryCollection),
616
+ properties: any(isNULL, isObject)
617
+ }));
618
+ const isStrictFeature = all(isGeoJSONObject('Feature'), isStructure({
619
+ geometry: any(isStrictGeometry, isStrictGeometryCollection),
620
+ properties: any(isNULL, isObject)
621
+ }));
622
+
623
+ const isFeatureCollection = all(isGeoJSONObject('FeatureCollection'), isKeyOfType('features', isArrayOfType(isFeature)));
624
+ const isStrictFeatureCollection = all(isGeoJSONObject('FeatureCollection'), isKeyOfType('features', isArrayOfType(isStrictFeature)));
625
+
626
+ const isGeoJSON = any(isGeometry, isGeometryCollection, isFeature, isFeatureCollection);
627
+ const isStrictGeoJSON = any(isStrictGeometry, isStrictGeometryCollection, isStrictFeature, isStrictFeatureCollection);
628
+
629
+ exports.SimpleGeometryIterator = SimpleGeometryIterator;
630
+ exports.distance = distance;
631
+ exports.intersect = intersect;
632
+ exports.isFeature = isFeature;
633
+ exports.isFeatureCollection = isFeatureCollection;
634
+ exports.isGeoJSON = isGeoJSON;
635
+ exports.isGeometry = isGeometry;
636
+ exports.isGeometryCollection = isGeometryCollection;
637
+ exports.isLineString = isLineString;
638
+ exports.isMultiLineString = isMultiLineString;
639
+ exports.isMultiPoint = isMultiPoint;
640
+ exports.isMultiPolygon = isMultiPolygon;
641
+ exports.isPoint = isPoint;
642
+ exports.isPolygon = isPolygon;
643
+ exports.isPosition = isPosition;
644
+ exports.isStrictFeature = isStrictFeature;
645
+ exports.isStrictFeatureCollection = isStrictFeatureCollection;
646
+ exports.isStrictGeoJSON = isStrictGeoJSON;
647
+ exports.isStrictGeometry = isStrictGeometry;
648
+ exports.isStrictGeometryCollection = isStrictGeometryCollection;
649
+ exports.isStrictLineString = isStrictLineString;
650
+ exports.isStrictMultiLineString = isStrictMultiLineString;
651
+ exports.isStrictMultiPoint = isStrictMultiPoint;
652
+ exports.isStrictMultiPolygon = isStrictMultiPolygon;
653
+ exports.isStrictPoint = isStrictPoint;
654
+ exports.isStrictPolygon = isStrictPolygon;
655
+ exports.isStrictPosition = isStrictPosition;
@@ -0,0 +1 @@
1
+ "use strict";function t(t){return t.slice(1).map(((n,e)=>[t[e],n]))}const n=6371008.7714,e=6356752.314245,o=Math.PI/180,i=Math.PI;function r(t){return t*t}function s(t){return t*o}const c=r(6378137),a=r(e),u=(c-a)/a,l=1/298.257223563,p={cartesian:([t,e],[o,i])=>n*s(Math.sqrt(r(o-t)+r(i-e))),haversine([t,e],[o,i]){const c=r(Math.sin(s(i-e)/2))+Math.cos(s(e))*Math.cos(s(i))*r(Math.sin(s(o-t)/2));return n*Math.atan2(Math.sqrt(c),Math.sqrt(1-c))*2},vincenty(...t){const[[n,o],[r,c]]=t.map((t=>t.map(s))),a=r-n,p=.9966471893352525*Math.tan(o),y=1/Math.sqrt(1+p*p),g=p*y,h=.9966471893352525*Math.tan(c),f=1/Math.sqrt(1+h*h),m=h*f,P=Math.abs(a)>i/2||Math.abs(c-o)>i/2;let S=a,M=null,d=null,x=P?i:0,L=0,b=P?-1:1,w=null,v=1,C=1,F=null,G=0;do{if(M=Math.sin(S),d=Math.cos(S),w=(f*M)**2+(y*m-g*f*d)**2,Math.abs(w)<1e-24)break;L=Math.sqrt(w),b=g*m+y*f*d,x=Math.atan2(L,b);const t=y*f*M/L;C=1-t*t,v=0!=C?b-2*g*m/C:0;const n=.00020955066654671753*C*(4+l*(4-3*C));F=S,S=a+(1-n)*l*t*(x+n*L*(v+n*b*(2*v*v-1)))}while(Math.abs(S-F)>1e-12&&++G<1e3);const j=C*u,$=j/1024*(256+j*(j*(74-47*j)-128));return e*(1+j/16384*(4096+j*(j*(320-175*j)-768)))*(x-$*L*(v+$/4*(b*(2*v*v-1)-$/6*v*(4*L*L-3)*(4*v*v-3))))}};function y(t,n){const[[e,o],[i,r],[s,c]]=[t,...n],[a,u]=[s-i,c-r],[l,p]=[e-i,o-r],y=(g=(l*a+p*u)/(a*a+u*u),h=0,f=1,Math.max(Math.min(g,f),h));var g,h,f;return 0===y||1===y?n[y]:[i+a*y,r+u*y]}function g(t,n,e){const o="function"==typeof e?e:p[e];if("function"==typeof o)return o(t,n);throw new Error(`Not a PointToPoint calculation function ${e}`)}function h(t,n,e){return g(t,y(t,n),e)}function f(t,n,e){return m(t,n)?0:Math.min(...t.map((t=>h(t,n,e))),...n.map((n=>h(n,t,e))))}function m(t,n){const[[e,o],[i,r]]=t,[[s,c],[a,u]]=n,[l,p,y,g]=[i-e,r-o,a-s,u-c],h=(-p*(e-s)+l*(o-c))/(-y*p+l*g),f=(y*(o-c)-g*(e-s))/(-y*p+l*g);return h>=0&&h<=1&&f>=0&&f<=1}function P(t,n,e=1e-14){return h(t,n,"cartesian")<e}function S(t,n){const{length:e}=n;return 0!==n.reduce(((o,i,r)=>{const s=n[(e+r-1)%e];return(i[1]<t[1]&&s[1]>=t[1]||s[1]<t[1]&&i[1]>=t[1])&&(i[0]<=t[0]||s[0]<=t[0])?o^Number(i[0]+(t[1]-i[1])/(s[1]-i[1])*(s[0]-i[0])<t[0]):o}),0)||n.slice(1).some(((e,o)=>P(t,[n[o],e])))}class M{constructor(...t){this.inputs=[],this.inputs=t}*[Symbol.iterator](){for(const t of this.inputs)for(const n of this.unwrap(t))yield n}*unwrap(t){t.type in this?yield*this[t.type](t):yield t}*GeometryCollection({geometries:t}){for(const n of t)yield*this.unwrap(n)}*FeatureCollection({features:t}){for(const{geometry:n}of t)yield*this.unwrap(n)}*Feature({geometry:t}){yield*this.unwrap(t)}*MultiPoint(t){for(const n of t.coordinates)yield{type:"Point",coordinates:n}}*MultiLineString(t){for(const n of t.coordinates)yield{type:"LineString",coordinates:n}}*MultiPolygon(t){for(const n of t.coordinates)yield{type:"Polygon",coordinates:n}}}class d{constructor(...t){this.iterators=[],this.iterators=t}*[Symbol.iterator](){for(const[t,n]of this.pairs(this.iterators))for(const e of t)for(const t of n)yield[e,t]}pairs(t){return t.map(((n,e)=>t.slice(e+1).map((t=>[n,t])))).flat()}}const x={PointPoint:(t,n)=>t.length>=2&&n.length>=2&&t.slice(0,2).every(((t,e)=>t===n[e])),LineStringPoint(n,e){return n.some((t=>this.PointPoint(t,e)))||t(n).some((t=>P(e,t)))},LineStringLineString(n,e){const o=t(e);return t(n).some((t=>o.some((n=>m(t,n)))))},PolygonPoint([t,...n],e){return(this.LineStringPoint(t,e)||S(e,t))&&(!n.length||n.every((t=>!S(e,t))))},PolygonLineString(t,n){return t.some((t=>this.LineStringLineString(t,n)))||n.some((n=>this.PolygonPoint(t,n)))},PolygonPolygon(t,n){return n.some((n=>this.PolygonLineString(t,n)||n.some((n=>this.PolygonPoint(t,n)))))||t.some((t=>this.PolygonLineString(n,t)||t.some((t=>this.PolygonPoint(n,t)))))}};const L={PointPoint:(t,n,e)=>g(t,n,e),LineStringPoint:(n,e,o)=>Math.min(...t(n).map((t=>h(e,t,o)))),LineStringLineString(n,e,o){const i=t(n),r=t(e);return i.reduce(((t,n)=>r.reduce(((t,e)=>t>0?Math.min(t,f(n,e,o)):t),t)),1/0)},PolygonPoint([t,...n],e,o){if(S(e,t)){const[t]=n.filter((t=>S(e,t)));return t?this.LineStringPoint(t,e,o):0}return this.LineStringPoint(t,e,o)},PolygonLineString(n,e,o){const[i,...r]=n,s=t(e),c=e.some((t=>S(t,i)))?r.find((t=>e.every((n=>S(n,t))))):i;return c?Math.min(...t(c).map((t=>Math.min(...s.map((n=>f(t,n,o))))))):0},PolygonPolygon(t,n,e){return Math.min(this.PolygonLineString(t,n[0],e),this.PolygonLineString(n,t[0],e))}};class b{constructor(t={}){this.mapping=Object.keys(t).map((n=>e=>t[n](e)?n:void 0)).concat((t=>typeof t))}map(t){return this.mapping.reduce(((n,e)=>n||e(t)),void 0)}}const w=new b({date:t=>t instanceof Date,regexp:t=>t instanceof RegExp,array:t=>Array.isArray(t),null:t=>null===t});function v(t){return n=>typeof n===t}function C(...t){return n=>t.some((t=>t(n)))}function F(...t){return n=>t.every((t=>t(n)))}function G(...t){return n=>t.every((t=>!t(n)))}new class{constructor(t=new b,n={}){this.types=t,this.mapping=n}map(t){const n=this.types.map(t);return n in this.mapping?this.mapping[n](t,(t=>this.map(t))):(null==t?void 0:t.toString())||"undefined"}}(w,{string:t=>t?`"${t}"`:"EmptyString",date:(t,n)=>n(t.toISOString()),object:(t,n)=>{const e=String(t);if(/^\[([a-z]+) \1\]$/i.test(e)){return`{${Object.keys(t).map((e=>`${e}:${n(t[e])}`)).join(",")}}`}return e},array:(t,n)=>`[${t.map(n).join(",")}]`,null:()=>"NULL",undefined:()=>"Undefined",function:t=>{const{constructor:{name:n},name:e}=t,[,o,i,r]=n.match(/^(async)?(generator)?(function)$/i),[,s,c]=t.toString().match(/^(?:async)?(?:[\s\*]+)?(class|function)?(?:[\s\*]+)?([a-z_]\w*)?\s*[\(\{]?/i);return[[].concat(!s||e||c?[]:"anonymous").concat(e&&!s&&c?"shorthand":[]).concat(o||[],i||[]).concat(s||c?[]:"arrow").concat(s||r).map((t=>t[0].toUpperCase()+t.slice(1))).join("")].concat(e||[]).join(" ")}});const j=t=>Array.isArray(t),$=t=>null===t,q=v("number"),N=F(G(j),G($),v("object")),O=v("string");function k(...t){const n=F(...t);return F(j,(t=>t.every(n)))}function A(t,n=1/0){return F(j,(e=>e.length>=t&&e.length<=n))}function I(t){return F(N,(n=>t in n))}function E(t,...n){return F(I(t),(e=>n.every((n=>n(e[t])))))}function U(t,...n){return C(F(N,G(I(t))),E(t,...n))}function z(t,...n){const e=n.reduce(((t,n)=>t.concat(n)),[]),o=Object.keys(t).map((n=>(e.includes(n)?U:E)(n,t[n])));return F(N,...o)}function J(...t){return n=>j(n)&&n.length===t.length&&t.every(((t,e)=>t(n[e])))}function D(t){return q(t)&&Number.isFinite(t)}function R(t,n=1/0){const e=Math.min(t,n),o=Math.max(t,n);return t=>D(t)&&t>=e&&t<=o}function T(t){return D(t)}const _=R(-6371008.7714,2018e4);function B(t){return D(t)}const H=R(-90,90);function K(t){return D(t)}const Q=R(-180,180),V=C(J(K,B),J(K,B,T)),W=C(J(Q,H),J(Q,H,_)),X=C(F(J(K,B,T,K,B,T),(([,t,,,n])=>t<=n)),F(J(K,B,K,B),(([,t,,n])=>t<=n)));function Y(t){return z({type:F(O,(n=>n===t)),bbox:X},"bbox")}function Z(t,n){return F(Y(t),E("coordinates",n))}const tt=V,nt=Z("Point",tt),et=W,ot=Z("Point",et),it=k(tt),rt=Z("MultiPoint",it),st=k(et),ct=Z("MultiPoint",st),at=it,ut=Z("LineString",at),lt=st,pt=Z("LineString",lt),yt=Z("MultiLineString",k(at)),gt=Z("MultiLineString",k(lt));k(V);const ht=F(k(V),A(4),(t=>t[t.length-1].every(((n,e)=>n===t[0][e])))),ft=F(k(W),A(4),(t=>t[t.length-1].every(((n,e)=>n===t[0][e])))),mt=F(ht),Pt=F(ht),St=F(k(ht)),Mt=Z("Polygon",St),dt=F(k(ft),(t=>mt(t[0])),(t=>t.slice(1).every(Pt))),xt=Z("Polygon",dt),Lt=Z("MultiPolygon",k(St)),bt=Z("MultiPolygon",k(dt)),wt=C(nt,rt,ut,yt,Mt,Lt),vt=C(ot,ct,pt,gt,xt,bt),Ct=F(Y("GeometryCollection"),E("geometries",k(C(wt,Gt)))),Ft=F(Y("GeometryCollection"),E("geometries",k(C(vt,jt))));function Gt(t){return Ct(t)}function jt(t){return Ft(t)}const $t=F(Y("Feature"),z({geometry:C(wt,Gt),properties:C($,N)})),qt=F(Y("Feature"),z({geometry:C(vt,jt),properties:C($,N)})),Nt=F(Y("FeatureCollection"),E("features",k($t))),Ot=F(Y("FeatureCollection"),E("features",k(qt))),kt=C(wt,Gt,$t,Nt),At=C(vt,jt,qt,Ot);exports.SimpleGeometryIterator=M,exports.distance=function(t,n,e="cartesian"){return Math.min(...[...new d(new M(t),new M(n))].map((([t,n])=>t.type+n.type in L?L[t.type+n.type](t.coordinates,n.coordinates,e):n.type+t.type in L?L[n.type+t.type](n.coordinates,t.coordinates,e):1/0)))},exports.intersect=function(t,n){for(const[e,o]of new d(new M(t),new M(n)))if(e.type+o.type in x&&x[e.type+o.type](e.coordinates,o.coordinates)||o.type+e.type in x&&x[o.type+e.type](o.coordinates,e.coordinates))return!0;return!1},exports.isFeature=$t,exports.isFeatureCollection=Nt,exports.isGeoJSON=kt,exports.isGeometry=wt,exports.isGeometryCollection=Gt,exports.isLineString=ut,exports.isMultiLineString=yt,exports.isMultiPoint=rt,exports.isMultiPolygon=Lt,exports.isPoint=nt,exports.isPolygon=Mt,exports.isPosition=V,exports.isStrictFeature=qt,exports.isStrictFeatureCollection=Ot,exports.isStrictGeoJSON=At,exports.isStrictGeometry=vt,exports.isStrictGeometryCollection=jt,exports.isStrictLineString=pt,exports.isStrictMultiLineString=gt,exports.isStrictMultiPoint=ct,exports.isStrictMultiPolygon=bt,exports.isStrictPoint=ot,exports.isStrictPolygon=xt,exports.isStrictPosition=W;