@konfirm/geojson 1.0.1 → 2.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.
package/dist/main.mjs CHANGED
@@ -1,8 +1,96 @@
1
- // source/Domain/GeoJSON/Concept/Position.ts
2
- import { any } from "@konfirm/guard";
1
+ // node_modules/@konfirm/guard/dist/guard.es.js
2
+ var TypeMapper = class {
3
+ constructor(mapping = {}) {
4
+ this.mapping = Object.keys(mapping).map((key) => (value) => mapping[key](value) ? key : void 0).concat((value) => typeof value);
5
+ }
6
+ map(value) {
7
+ return this.mapping.reduce((carry, map) => carry || map(value), void 0);
8
+ }
9
+ };
10
+ var ValueMapper = class {
11
+ constructor(types2 = new TypeMapper(), mapping = {}) {
12
+ this.types = types2;
13
+ this.mapping = mapping;
14
+ }
15
+ map(value) {
16
+ const type = this.types.map(value);
17
+ const map = (value2) => this.map(value2);
18
+ return type in this.mapping ? this.mapping[type](value, map) : (value === null || value === void 0 ? void 0 : value.toString()) || "undefined";
19
+ }
20
+ };
21
+ var types = new TypeMapper({
22
+ date: (value) => value instanceof Date,
23
+ regexp: (value) => value instanceof RegExp,
24
+ array: (value) => Array.isArray(value),
25
+ null: (value) => value === null
26
+ });
27
+ var stringifier = new ValueMapper(types, {
28
+ string: (value) => value ? `"${value}"` : "EmptyString",
29
+ date: (value, map) => map(value.toISOString()),
30
+ object: (value, map) => {
31
+ const string = String(value);
32
+ if (/^\[([a-z]+) \1\]$/i.test(string)) {
33
+ const mapped = Object.keys(value).map((key) => `${key}:${map(value[key])}`);
34
+ return `{${mapped.join(",")}}`;
35
+ }
36
+ return string;
37
+ },
38
+ array: (value, map) => `[${value.map(map).join(",")}]`,
39
+ null: () => "NULL",
40
+ undefined: () => "Undefined",
41
+ function: (value) => {
42
+ const { constructor: { name: cname }, name } = value;
43
+ const [, async, generator, func] = cname.match(/^(async)?(generator)?(function)$/i);
44
+ const [, stype, sname] = value.toString().match(/^(?:async)?(?:[\s\*]+)?(class|function)?(?:[\s\*]+)?([a-z_]\w*)?\s*[\(\{]?/i);
45
+ const parts = [].concat(stype && !(name || sname) ? "anonymous" : []).concat(name && !stype && sname ? "shorthand" : []).concat(async || [], generator || []).concat(!(stype || sname) ? "arrow" : []).concat(stype || func).map((key) => key[0].toUpperCase() + key.slice(1));
46
+ return [parts.join("")].concat(name || []).join(" ");
47
+ }
48
+ });
49
+ function is(type) {
50
+ return (value) => typeof value === type;
51
+ }
52
+ function any(...checks) {
53
+ return (value) => checks.some((check) => check(value));
54
+ }
55
+ function all(...checks) {
56
+ return (value) => checks.every((check) => check(value));
57
+ }
58
+ function not(...checks) {
59
+ return (value) => checks.every((check) => !check(value));
60
+ }
61
+ var isArray = (value) => Array.isArray(value);
62
+ var isBigInt = is("bigint");
63
+ var isBoolean = is("boolean");
64
+ var isFunction = is("function");
65
+ var isNULL = (value) => value === null;
66
+ var isNumber = is("number");
67
+ var isObject = all(not(isArray), not(isNULL), is("object"));
68
+ var isString = is("string");
69
+ var isSymbol = is("symbol");
70
+ var isUndefined = is("undefined");
71
+ function isArrayOfType(...validators) {
72
+ const check = all(...validators);
73
+ return all(isArray, (value) => value.every(check));
74
+ }
75
+ function isArrayOfSize(min, max = Infinity) {
76
+ return all(isArray, (value) => value.length >= min && value.length <= max);
77
+ }
78
+ function isKey(key) {
79
+ return all(isObject, (value) => key in value);
80
+ }
81
+ function isKeyOfType(key, ...validators) {
82
+ return all(isKey(key), (value) => validators.every((check) => check(value[key])));
83
+ }
84
+ function isOptionalKeyOfType(key, ...validators) {
85
+ return any(all(isObject, not(isKey(key))), isKeyOfType(key, ...validators));
86
+ }
87
+ function isStructure(struct, ...options) {
88
+ const optional = options.reduce((carry, key) => carry.concat(key), []);
89
+ const validators = Object.keys(struct).map((key) => (optional.includes(key) ? isOptionalKeyOfType : isKeyOfType)(key, struct[key]));
90
+ return all(isObject, ...validators);
91
+ }
3
92
 
4
93
  // source/Domain/Guards/Tuple.ts
5
- import { isArray } from "@konfirm/guard";
6
94
  function isTuple(...rules) {
7
95
  return (value) => isArray(value) && value.length === rules.length && rules.every((rule, index) => rule(value[index]));
8
96
  }
@@ -15,13 +103,12 @@ var EARTH_FLATTENING = 298.257223563;
15
103
  var GPS_SATELLITE_ORBIT = 2018e4;
16
104
 
17
105
  // source/Domain/Guards/Number.ts
18
- import { isNumber } from "@konfirm/guard";
19
106
  function isNumberValue(value) {
20
107
  return isNumber(value) && Number.isFinite(value);
21
108
  }
22
- function isNumberBetween(a, b = Infinity) {
23
- const min = Math.min(a, b);
24
- const max = Math.max(a, b);
109
+ function isNumberBetween(a2, b2 = Infinity) {
110
+ const min = Math.min(a2, b2);
111
+ const max = Math.max(a2, b2);
25
112
  return (value) => isNumberValue(value) && value >= min && value <= max;
26
113
  }
27
114
 
@@ -56,14 +143,7 @@ var isStrictPosition = any(
56
143
  isTuple(isStrictLongitude, isStrictLatitude, isStrictAltitude)
57
144
  );
58
145
 
59
- // source/Domain/GeoJSON/Feature.ts
60
- import { all as all9, any as any5, isNULL, isObject, isStructure as isStructure2 } from "@konfirm/guard";
61
-
62
- // source/Domain/GeoJSON/Concept/GeoJSONObject.ts
63
- import { all as all2, isString, isStructure } from "@konfirm/guard";
64
-
65
146
  // source/Domain/GeoJSON/Concept/BoundingBox.ts
66
- import { all, any as any2 } from "@konfirm/guard";
67
147
  var isBoundingBoxWithAltitude = all(
68
148
  isTuple(
69
149
  isLongitude,
@@ -73,17 +153,17 @@ var isBoundingBoxWithAltitude = all(
73
153
  isLatitude,
74
154
  isAltitude
75
155
  ),
76
- ([, s, , , n]) => s <= n
156
+ ([, s, , , n2]) => s <= n2
77
157
  );
78
158
  var isBoundingBoxWithoutAltitude = all(
79
159
  isTuple(isLongitude, isLatitude, isLongitude, isLatitude),
80
- ([, s, , n]) => s <= n
160
+ ([, s, , n2]) => s <= n2
81
161
  );
82
- var isBoundingBox = any2(
162
+ var isBoundingBox = any(
83
163
  isBoundingBoxWithAltitude,
84
164
  isBoundingBoxWithoutAltitude
85
165
  );
86
- var isStrictBoundingBox = any2(
166
+ var isStrictBoundingBox = any(
87
167
  all(
88
168
  isTuple(
89
169
  isStrictLongitude,
@@ -110,28 +190,21 @@ var isStrictBoundingBox = any2(
110
190
  function isGeoJSONObject(type) {
111
191
  return isStructure(
112
192
  {
113
- type: all2(isString, (value) => value === type),
193
+ type: all(isString, (value) => value === type),
114
194
  bbox: isBoundingBox
115
195
  },
116
196
  "bbox"
117
197
  );
118
198
  }
119
199
 
120
- // source/Domain/GeoJSON/Geometry.ts
121
- import { any as any3 } from "@konfirm/guard";
122
-
123
200
  // source/Domain/GeoJSON/GeometryObject.ts
124
- import { all as all3, isKeyOfType } from "@konfirm/guard";
125
201
  function isGeometryObject(type, isCoordinates) {
126
- return all3(
202
+ return all(
127
203
  isGeoJSONObject(type),
128
204
  isKeyOfType("coordinates", isCoordinates)
129
205
  );
130
206
  }
131
207
 
132
- // source/Domain/GeoJSON/Geometry/MultiPoint.ts
133
- import { isArrayOfType } from "@konfirm/guard";
134
-
135
208
  // source/Domain/GeoJSON/Geometry/Point.ts
136
209
  var isPointCoordinates = isPosition;
137
210
  var isPoint = isGeometryObject(
@@ -166,15 +239,14 @@ var isStrictLineStringCoordinates = isStrictMultiPointCoordinates;
166
239
  var isStrictLineString = isGeometryObject("LineString", isStrictLineStringCoordinates);
167
240
 
168
241
  // source/Domain/GeoJSON/Geometry/MultiLineString.ts
169
- import { isArrayOfType as isArrayOfType2 } from "@konfirm/guard";
170
- var isMultiLineStringCoordinates = isArrayOfType2(
242
+ var isMultiLineStringCoordinates = isArrayOfType(
171
243
  isLineStringCoordinates
172
244
  );
173
245
  var isMultiLineString = isGeometryObject(
174
246
  "MultiLineString",
175
247
  isMultiLineStringCoordinates
176
248
  );
177
- var isStrictMultiLineStringCoordinates = isArrayOfType2(
249
+ var isStrictMultiLineStringCoordinates = isArrayOfType(
178
250
  isStrictLineStringCoordinates
179
251
  );
180
252
  var isStrictMultiLineString = isGeometryObject(
@@ -182,69 +254,57 @@ var isStrictMultiLineString = isGeometryObject(
182
254
  isStrictMultiLineStringCoordinates
183
255
  );
184
256
 
185
- // source/Domain/GeoJSON/Geometry/MultiPolygon.ts
186
- import { isArrayOfType as isArrayOfType6 } from "@konfirm/guard";
187
-
188
- // source/Domain/GeoJSON/Geometry/Polygon.ts
189
- import { all as all7, isArrayOfType as isArrayOfType5 } from "@konfirm/guard";
190
-
191
- // source/Domain/GeoJSON/Concept/ExteriorRing.ts
192
- import { all as all5 } from "@konfirm/guard";
193
-
194
257
  // source/Domain/Utility/Winding.ts
195
- import { isArrayOfType as isArrayOfType3 } from "@konfirm/guard";
196
- function winding(positions2) {
197
- return positions2.reduce((carry, [x, y], i, a) => {
198
- const [nx, ny] = a[(i + 1) % a.length];
199
- return carry + (nx - x) * (ny + y);
258
+ function shoelace(positions2) {
259
+ return positions2.reduce((carry, [x, y], i, a2) => {
260
+ const [nx, ny] = a2[(i + 1) % a2.length];
261
+ return carry + (x * ny - nx * y);
200
262
  }, 0);
201
263
  }
202
- var isPositionArray = isArrayOfType3(isPosition);
264
+ var isPositionArray = isArrayOfType(isPosition);
203
265
  function isClockwiseWinding(value) {
204
- return isPositionArray(value) && winding(value) <= 0;
266
+ return isPositionArray(value) && shoelace(value) <= 0;
205
267
  }
206
268
  function isCounterClockwiseWinding(value) {
207
- return isPositionArray(value) && winding(value) >= 0;
269
+ return isPositionArray(value) && shoelace(value) >= 0;
208
270
  }
209
271
 
210
272
  // source/Domain/GeoJSON/Concept/LinearRing.ts
211
- import { all as all4, isArrayOfSize, isArrayOfType as isArrayOfType4 } from "@konfirm/guard";
212
- var isLinearRing = all4(
213
- isArrayOfType4(isPosition),
273
+ var isLinearRing = all(
274
+ isArrayOfType(isPosition),
214
275
  isArrayOfSize(4),
215
276
  (value) => value[value.length - 1].every((v, i) => v === value[0][i])
216
277
  );
217
- var isStrictLinearRing = all4(
218
- isArrayOfType4(isStrictPosition),
278
+ var isStrictLinearRing = all(
279
+ isArrayOfType(isStrictPosition),
219
280
  isArrayOfSize(4),
220
281
  (value) => value[value.length - 1].every((v, i) => v === value[0][i])
221
282
  );
222
283
 
223
284
  // source/Domain/GeoJSON/Concept/ExteriorRing.ts
224
- var isExteriorRing = all5(isLinearRing);
225
- var isStrictExteriorRing = all5(
285
+ var isExteriorRing = all(isLinearRing);
286
+ var isStrictExteriorRing = all(
226
287
  isStrictLinearRing,
227
288
  isCounterClockwiseWinding
228
289
  );
229
290
 
230
291
  // source/Domain/GeoJSON/Concept/InteriorRing.ts
231
- import { all as all6 } from "@konfirm/guard";
232
- var isInteriorRing = all6(isLinearRing);
233
- var isStrictInteriorRing = all6(
292
+ var isInteriorRing = all(isLinearRing);
293
+ var isStrictInteriorRing = all(
234
294
  isStrictLinearRing,
235
295
  isClockwiseWinding
236
296
  );
237
297
 
238
298
  // source/Domain/GeoJSON/Geometry/Polygon.ts
239
- var isPolygonCoordinates = all7(isArrayOfType5(isLinearRing));
299
+ var isPolygonCoordinates = all(isArrayOfType(isLinearRing));
240
300
  var isPolygon = isGeometryObject(
241
301
  "Polygon",
242
302
  isPolygonCoordinates
243
303
  );
244
- var isStrictPolygonCoordinates = all7(
245
- isArrayOfType5(isStrictLinearRing),
246
- (value) => isExteriorRing(value[0]),
247
- (value) => value.slice(1).every(isInteriorRing)
304
+ var isStrictPolygonCoordinates = all(
305
+ isArrayOfType(isStrictLinearRing),
306
+ (value) => isStrictExteriorRing(value[0]),
307
+ (value) => value.slice(1).every(isStrictInteriorRing)
248
308
  );
249
309
  var isStrictPolygon = isGeometryObject(
250
310
  "Polygon",
@@ -252,12 +312,12 @@ var isStrictPolygon = isGeometryObject(
252
312
  );
253
313
 
254
314
  // source/Domain/GeoJSON/Geometry/MultiPolygon.ts
255
- var isMultiPolygonCoordinates = isArrayOfType6(isPolygonCoordinates);
315
+ var isMultiPolygonCoordinates = isArrayOfType(isPolygonCoordinates);
256
316
  var isMultiPolygon = isGeometryObject(
257
317
  "MultiPolygon",
258
318
  isMultiPolygonCoordinates
259
319
  );
260
- var isStrictMultiPolygonCoordinates = isArrayOfType6(
320
+ var isStrictMultiPolygonCoordinates = isArrayOfType(
261
321
  isStrictPolygonCoordinates
262
322
  );
263
323
  var isStrictMultiPolygon = isGeometryObject(
@@ -266,7 +326,7 @@ var isStrictMultiPolygon = isGeometryObject(
266
326
  );
267
327
 
268
328
  // source/Domain/GeoJSON/Geometry.ts
269
- var isGeometry = any3(
329
+ var isGeometryPrimitive = any(
270
330
  isPoint,
271
331
  isMultiPoint,
272
332
  isLineString,
@@ -274,7 +334,7 @@ var isGeometry = any3(
274
334
  isPolygon,
275
335
  isMultiPolygon
276
336
  );
277
- var isStrictGeometry = any3(
337
+ var isStrictGeometryPrimitive = any(
278
338
  isStrictPoint,
279
339
  isStrictMultiPoint,
280
340
  isStrictLineString,
@@ -282,66 +342,77 @@ var isStrictGeometry = any3(
282
342
  isStrictPolygon,
283
343
  isStrictMultiPolygon
284
344
  );
285
-
286
- // source/Domain/GeoJSON/GeometryCollection.ts
287
- import { all as all8, any as any4, isArrayOfType as isArrayOfType7, isKeyOfType as isKeyOfType2 } from "@konfirm/guard";
288
- var isGeometryCollectionObject = all8(
345
+ var isGeometry = any(
346
+ isGeometryPrimitive,
347
+ isGeometryCollection
348
+ );
349
+ var isStrictGeometry = any(
350
+ isStrictGeometryPrimitive,
351
+ isStrictGeometryCollection
352
+ );
353
+ var isGeometryCollectionObject = all(
289
354
  isGeoJSONObject("GeometryCollection"),
290
- isKeyOfType2(
291
- "geometries",
292
- isArrayOfType7(any4(isGeometry, isGeometryCollection))
293
- )
355
+ isKeyOfType("geometries", isArrayOfType(isGeometry))
294
356
  );
295
- var isStrictGeometryCollectionObject = all8(
357
+ var isStrictGeometryCollectionObject = all(
296
358
  isGeoJSONObject("GeometryCollection"),
297
- isKeyOfType2(
298
- "geometries",
299
- isArrayOfType7(any4(isStrictGeometry, isStrictGeometryCollection))
300
- )
359
+ isKeyOfType("geometries", isArrayOfType(isStrictGeometry))
301
360
  );
302
- function isGeometryCollection(value) {
303
- return isGeometryCollectionObject(value);
361
+ function isGeometryCollection(value, isG = isGeometryPrimitive) {
362
+ return isGeometryCollectionObject(value) && value.geometries.every((g) => isG(g) || isGeometryCollection(g, isG));
304
363
  }
305
- function isStrictGeometryCollection(value) {
306
- return isStrictGeometryCollectionObject(value);
364
+ function isStrictGeometryCollection(value, isG = isStrictGeometryPrimitive) {
365
+ return isStrictGeometryCollectionObject(value) && value.geometries.every(
366
+ (g) => isG(g) || isStrictGeometryCollection(g, isG)
367
+ );
307
368
  }
308
369
 
309
370
  // source/Domain/GeoJSON/Feature.ts
310
- var isFeature = all9(
371
+ var isFeatureObject = all(
311
372
  isGeoJSONObject("Feature"),
312
- isStructure2({
313
- geometry: any5(isGeometry, isGeometryCollection),
314
- properties: any5(isNULL, isObject)
373
+ isStructure({
374
+ geometry: any(isNULL, isGeometry),
375
+ properties: any(isNULL, isObject)
315
376
  })
316
377
  );
317
- var isStrictFeature = all9(
378
+ var isStrictFeatureObject = all(
318
379
  isGeoJSONObject("Feature"),
319
- isStructure2({
320
- geometry: any5(isStrictGeometry, isStrictGeometryCollection),
321
- properties: any5(isNULL, isObject)
380
+ isStructure({
381
+ geometry: any(isNULL, isStrictGeometry),
382
+ properties: any(isNULL, isObject)
322
383
  })
323
384
  );
385
+ function isFeature(input, isG = any(isNULL, isGeometry)) {
386
+ return isFeatureObject(input) && isG(input.geometry);
387
+ }
388
+ function isStrictFeature(input, isG = any(isNULL, isStrictGeometry)) {
389
+ return isStrictFeatureObject(input) && isG(input.geometry);
390
+ }
324
391
 
325
392
  // source/Domain/GeoJSON/FeatureCollection.ts
326
- import { all as all10, isArrayOfType as isArrayOfType8, isKeyOfType as isKeyOfType3 } from "@konfirm/guard";
327
- var isFeatureCollection = all10(
393
+ var isFeatureCollectionObject = all(
328
394
  isGeoJSONObject("FeatureCollection"),
329
- isKeyOfType3("features", isArrayOfType8(isFeature))
395
+ isKeyOfType("features", isArrayOfType(isFeature))
330
396
  );
331
- var isStrictFeatureCollection = all10(
397
+ var isStrictFeatureCollectionObject = all(
332
398
  isGeoJSONObject("FeatureCollection"),
333
- isKeyOfType3("features", isArrayOfType8(isStrictFeature))
399
+ isKeyOfType("features", isArrayOfType(isStrictFeature))
334
400
  );
401
+ function isFeatureCollection(value, isG = any(isNULL, isGeometry)) {
402
+ return isFeatureCollectionObject(value) && value.features.every((feature) => isFeature(feature, isG));
403
+ }
404
+ function isStrictFeatureCollection(value, isG = any(isNULL, isGeometry)) {
405
+ return isStrictFeatureCollectionObject(value) && value.features.every((feature) => isStrictFeature(feature, isG));
406
+ }
335
407
 
336
408
  // source/Domain/GeoJSON/GeoJSON.ts
337
- import { any as any6 } from "@konfirm/guard";
338
- var isGeoJSON = any6(
409
+ var isGeoJSON = any(
339
410
  isGeometry,
340
411
  isGeometryCollection,
341
412
  isFeature,
342
413
  isFeatureCollection
343
414
  );
344
- var isStrictGeoJSON = any6(
415
+ var isStrictGeoJSON = any(
345
416
  isStrictGeometry,
346
417
  isStrictGeometryCollection,
347
418
  isStrictFeature,
@@ -383,11 +454,15 @@ var reducers = {
383
454
  }
384
455
  },
385
456
  *Feature({ geometry }, unwrap) {
386
- yield* unwrap(geometry);
457
+ if (geometry) {
458
+ yield* unwrap(geometry);
459
+ }
387
460
  },
388
461
  *FeatureCollection({ features }, unwrap) {
389
462
  for (const { geometry } of features) {
390
- yield* unwrap(geometry);
463
+ if (geometry) {
464
+ yield* unwrap(geometry);
465
+ }
391
466
  }
392
467
  }
393
468
  };
@@ -443,9 +518,9 @@ var IterablePairIterator = class {
443
518
  * @memberof IterablePairIterator
444
519
  */
445
520
  *[Symbol.iterator]() {
446
- for (const [a, b] of this.pairs(this.iterators)) {
447
- for (const one of a) {
448
- for (const two of b) {
521
+ for (const [a2, b2] of this.pairs(this.iterators)) {
522
+ for (const one of a2) {
523
+ for (const two of b2) {
449
524
  yield [one, two];
450
525
  }
451
526
  }
@@ -461,7 +536,7 @@ var IterablePairIterator = class {
461
536
  */
462
537
  pairs(source) {
463
538
  return source.flatMap(
464
- (a, i) => source.slice(i + 1).map((b) => [a, b])
539
+ (a2, i) => source.slice(i + 1).map((b2) => [a2, b2])
465
540
  );
466
541
  }
467
542
  };
@@ -493,70 +568,605 @@ function isWithinBox([lon, lat], [minLon, minLat, maxLon, maxLat]) {
493
568
  return lon >= minLon && lon <= maxLon && lat >= minLat && lat <= maxLat;
494
569
  }
495
570
 
496
- // source/Domain/Utility/Calculate.ts
571
+ // source/Domain/Utility/Common.ts
572
+ function values(_, ...values2) {
573
+ return values2;
574
+ }
575
+
576
+ // source/Domain/Utility/Numeric.ts
577
+ function squared(n2) {
578
+ return n2 * n2;
579
+ }
580
+
581
+ // source/Domain/Utility/Geodesic.ts
582
+ var a = EARTH_RADIUS_MAJOR;
583
+ var f = 1 / EARTH_FLATTENING;
584
+ var f1 = 1 - f;
585
+ var n = f / (2 - f);
586
+ var b = a * f1;
587
+ var ep2 = f * (2 - f) / (f1 * f1);
497
588
  var D2R = Math.PI / 180;
589
+ var TINY = Number.EPSILON;
590
+ var TOL0 = Number.EPSILON;
591
+ var TOL1 = 200 * TOL0;
592
+ var TOL2 = Math.sqrt(TOL0);
593
+ var TOLB = TOL0 * TOL2;
594
+ var XTHRESH = 1e3 * TOL2;
595
+ var MAXIT1 = 20;
596
+ var MAXIT2 = MAXIT1 + 80;
597
+ var ETOL2 = 0.1 * TOL2 / Math.sqrt(Math.max(1e-3, Math.abs(f)) * Math.min(1, 1 - f / 2) / 2);
598
+ var ORDER = 6;
599
+ var A1M1_COEFF = [1, 4, 64, 0, 256];
600
+ var C1_COEFF = values`
601
+ ${-1} ${6} ${-16} ${32},
602
+ ${-9} ${64} ${-128} ${2048},
603
+ ${9} ${-16} ${768}
604
+ ${3} ${-5} ${512}
605
+ ${-7} ${1280}
606
+ ${-7} ${2048}
607
+ `;
608
+ var A2M1_COEFF = [-11, -28, -192, 0, 256];
609
+ var C2_COEFF = values`
610
+ ${1} ${2} ${16} ${32}
611
+ ${35} ${64} ${384} ${2048}
612
+ ${15} ${80} ${768}
613
+ ${7} ${35} ${512}
614
+ ${63} ${1280}
615
+ ${77} ${2048}
616
+ `;
617
+ var A3_COEFF = values`
618
+ ${-3} ${128}
619
+ ${-2} ${-3} ${64}
620
+ ${-1} ${-3} ${-1} ${16}
621
+ ${3} ${-1} ${-2} ${8}
622
+ ${1} ${-1} ${2}
623
+ ${1} ${1}
624
+ `;
625
+ var C3_COEFF = values`
626
+ ${3} ${128}
627
+ ${2} ${5} ${128}
628
+ ${-1} ${3} ${3} ${64}
629
+ ${-1} ${0} ${1} ${8}
630
+ ${-1} ${1} ${4}
631
+ ${5} ${256}
632
+ ${1} ${3} ${128}
633
+ ${-3} ${-2} ${3} ${64}
634
+ ${1} ${-3} ${2} ${32}
635
+ ${7} ${512}
636
+ ${-10} ${9} ${384}
637
+ ${5} ${-9} ${5} ${192}
638
+ ${7} ${512}
639
+ ${-14} ${7} ${512}
640
+ ${21} ${2560}
641
+ `;
642
+ function hypot(x, y) {
643
+ return Math.sqrt(x * x + y * y);
644
+ }
645
+ function copysign(x, y) {
646
+ return Math.abs(x) * (y < 0 || y === 0 && 1 / y < 0 ? -1 : 1);
647
+ }
648
+ function polyval(N, p, s, x) {
649
+ let i = s;
650
+ let n2 = N;
651
+ let y = p[i++];
652
+ while (n2-- > 0) y = y * x + p[i++];
653
+ return y;
654
+ }
655
+ function angNormalize(x) {
656
+ const v = x % 360;
657
+ return v <= -180 ? v + 360 : v > 180 ? v - 360 : v;
658
+ }
659
+ function sinCosSeries(sinx, cosx, c) {
660
+ let k = c.length;
661
+ let cn = k - 1;
662
+ const ar = 2 * (cosx - sinx) * (cosx + sinx);
663
+ let y0 = cn & 1 ? c[--k] : 0;
664
+ let y1 = 0;
665
+ cn = Math.floor(cn / 2);
666
+ while (cn--) {
667
+ y1 = ar * y0 - y1 + c[--k];
668
+ y0 = ar * y1 - y0 + c[--k];
669
+ }
670
+ return 2 * sinx * cosx * y0;
671
+ }
672
+ function astroid(x, y) {
673
+ const p = squared(x);
674
+ const q = squared(y);
675
+ const r = (p + q - 1) / 6;
676
+ const S = p * q / 4;
677
+ const r2 = squared(r);
678
+ const r3 = r * r2;
679
+ const disc = S * (S + 2 * r3);
680
+ let u = r;
681
+ if (disc >= 0) {
682
+ let T3 = S + r3;
683
+ T3 += Math.sqrt(disc);
684
+ const T = Math.cbrt(T3);
685
+ u += T + r2 / T;
686
+ } else {
687
+ const ang = Math.atan2(Math.sqrt(-disc), -(S + r3));
688
+ u += 2 * r * Math.cos(ang / 3);
689
+ }
690
+ const v = Math.sqrt(squared(u) + q);
691
+ const uv = u < 0 ? q / (v - u) : u + v;
692
+ const w = (uv - q) / (2 * v);
693
+ return uv / (Math.sqrt(uv + squared(w)) + w);
694
+ }
695
+ function A1m1f(eps) {
696
+ const p = Math.floor(ORDER / 2);
697
+ const t = polyval(p, A1M1_COEFF, 0, squared(eps)) / A1M1_COEFF[p + 1];
698
+ return (t + eps) / (1 - eps);
699
+ }
700
+ function C1f(eps, c) {
701
+ const eps2 = squared(eps);
702
+ let d = eps;
703
+ let o = 0;
704
+ for (let l = 1; l <= ORDER; l++) {
705
+ const p = Math.floor((ORDER - l) / 2);
706
+ c[l] = d * polyval(p, C1_COEFF, o, eps2) / C1_COEFF[o + p + 1];
707
+ o += p + 2;
708
+ d *= eps;
709
+ }
710
+ }
711
+ function A2m1f(eps) {
712
+ const p = Math.floor(ORDER / 2);
713
+ const t = polyval(p, A2M1_COEFF, 0, squared(eps)) / A2M1_COEFF[p + 1];
714
+ return (t - eps) / (1 + eps);
715
+ }
716
+ function C2f(eps, c) {
717
+ const eps2 = squared(eps);
718
+ let d = eps;
719
+ let o = 0;
720
+ for (let l = 1; l <= ORDER; l++) {
721
+ const p = Math.floor((ORDER - l) / 2);
722
+ c[l] = d * polyval(p, C2_COEFF, o, eps2) / C2_COEFF[o + p + 1];
723
+ o += p + 2;
724
+ d *= eps;
725
+ }
726
+ }
727
+ function buildA3x() {
728
+ const ax = new Array(ORDER);
729
+ let o = 0;
730
+ let k = 0;
731
+ for (let j = ORDER - 1; j >= 0; j--) {
732
+ const p = Math.min(ORDER - j - 1, j);
733
+ ax[k++] = polyval(p, A3_COEFF, o, n) / A3_COEFF[o + p + 1];
734
+ o += p + 2;
735
+ }
736
+ return ax;
737
+ }
738
+ function buildC3x() {
739
+ const cx = [];
740
+ let o = 0;
741
+ for (let l = 1; l < ORDER; l++) {
742
+ for (let j = ORDER - 1; j >= l; j--) {
743
+ const p = Math.min(ORDER - j - 1, j);
744
+ cx.push(polyval(p, C3_COEFF, o, n) / C3_COEFF[o + p + 1]);
745
+ o += p + 2;
746
+ }
747
+ }
748
+ return cx;
749
+ }
750
+ var A3x = buildA3x();
751
+ var C3x = buildC3x();
752
+ function A3f(eps) {
753
+ return polyval(ORDER - 1, A3x, 0, eps);
754
+ }
755
+ function C3f(eps, c) {
756
+ let mult = 1;
757
+ let o = 0;
758
+ for (let l = 1; l < ORDER; l++) {
759
+ const p = ORDER - l - 1;
760
+ mult *= eps;
761
+ c[l] = mult * polyval(p, C3x, o, eps);
762
+ o += p + 1;
763
+ }
764
+ }
765
+ function geodesicLengths(eps, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2, C1a, C2a) {
766
+ C1f(eps, C1a);
767
+ C2f(eps, C2a);
768
+ const a1 = A1m1f(eps);
769
+ const a2 = A2m1f(eps);
770
+ const m0x = a1 - a2;
771
+ const A1 = 1 + a1;
772
+ const A2 = 1 + a2;
773
+ const B1 = sinCosSeries(ssig2, csig2, C1a) - sinCosSeries(ssig1, csig1, C1a);
774
+ const B2 = sinCosSeries(ssig2, csig2, C2a) - sinCosSeries(ssig1, csig1, C2a);
775
+ const J12 = m0x * sig12 + (A1 * B1 - A2 * B2);
776
+ return {
777
+ s12b: A1 * (sig12 + B1),
778
+ m12b: dn2 * (csig1 * ssig2) - dn1 * (ssig1 * csig2) - csig1 * csig2 * J12
779
+ };
780
+ }
781
+ function Lambda12(sbet1, cbet1, dn1, sbet2, cbet2, dn2, salp1, calp1, slam12, clam12, _diffp, C1a, C2a, C3a) {
782
+ const salp0 = salp1 * cbet1;
783
+ const calp0 = hypot(calp1, salp1 * sbet1);
784
+ let ssig1 = sbet1;
785
+ const somg1 = salp0 * sbet1;
786
+ let csig1 = calp1 * cbet1;
787
+ const comg1 = csig1;
788
+ let t = hypot(ssig1, csig1);
789
+ ssig1 /= t;
790
+ csig1 /= t;
791
+ const salp2 = cbet2 !== cbet1 ? salp0 / cbet2 : salp1;
792
+ const calp2 = cbet2 !== cbet1 || Math.abs(sbet2) !== -sbet1 ? Math.sqrt(
793
+ squared(calp1 * cbet1) + (cbet1 < -sbet1 ? (cbet2 - cbet1) * (cbet1 + cbet2) : (sbet1 - sbet2) * (sbet1 + sbet2))
794
+ ) / cbet2 : Math.abs(calp1);
795
+ let ssig2 = sbet2;
796
+ const somg2 = salp0 * sbet2;
797
+ let csig2 = calp2 * cbet2;
798
+ const comg2 = csig2;
799
+ t = hypot(ssig2, csig2);
800
+ ssig2 /= t;
801
+ csig2 /= t;
802
+ const sig12 = Math.atan2(
803
+ Math.max(0, csig1 * ssig2 - ssig1 * csig2),
804
+ csig1 * csig2 + ssig1 * ssig2
805
+ );
806
+ const somg12 = Math.max(0, comg1 * somg2 - somg1 * comg2);
807
+ const comg12 = comg1 * comg2 + somg1 * somg2;
808
+ const eta = Math.atan2(
809
+ somg12 * clam12 - comg12 * slam12,
810
+ comg12 * clam12 + somg12 * slam12
811
+ );
812
+ const k2 = squared(calp0) * ep2;
813
+ const eps = k2 / (2 * (1 + Math.sqrt(1 + k2)) + k2);
814
+ C3f(eps, C3a);
815
+ const B312 = sinCosSeries(ssig2, csig2, C3a) - sinCosSeries(ssig1, csig1, C3a);
816
+ const domg12 = -f * A3f(eps) * salp0 * (sig12 + B312);
817
+ const lam12 = eta + domg12;
818
+ let dlam12;
819
+ if (calp2 === 0) {
820
+ dlam12 = -2 * f1 * dn1 / sbet1;
821
+ } else {
822
+ const nv = geodesicLengths(
823
+ eps,
824
+ sig12,
825
+ ssig1,
826
+ csig1,
827
+ dn1,
828
+ ssig2,
829
+ csig2,
830
+ dn2,
831
+ C1a,
832
+ C2a
833
+ );
834
+ dlam12 = nv.m12b * f1 / (calp2 * cbet2);
835
+ }
836
+ return {
837
+ lam12,
838
+ dlam12,
839
+ salp2,
840
+ calp2,
841
+ sig12,
842
+ ssig1,
843
+ csig1,
844
+ ssig2,
845
+ csig2,
846
+ eps
847
+ };
848
+ }
849
+ function inverseStart(sbet1, cbet1, _dn1, sbet2, cbet2, _dn2, lam12, slam12, clam12, _C1a, _C2a) {
850
+ const sbet12 = sbet2 * cbet1 - cbet2 * sbet1;
851
+ const cbet12 = cbet2 * cbet1 + sbet2 * sbet1;
852
+ const sbet12a = sbet2 * cbet1 + cbet2 * sbet1;
853
+ const shortline = cbet12 >= 0 && sbet12 < 0.5 && cbet2 * lam12 < 0.5;
854
+ let somg12;
855
+ let comg12;
856
+ let dnm = 1;
857
+ if (shortline) {
858
+ const sbetm2 = squared(sbet1 + sbet2) / (squared(sbet1 + sbet2) + squared(cbet1 + cbet2));
859
+ dnm = Math.sqrt(1 + ep2 * sbetm2);
860
+ const omg12 = lam12 / (f1 * dnm);
861
+ somg12 = Math.sin(omg12);
862
+ comg12 = Math.cos(omg12);
863
+ } else {
864
+ somg12 = slam12;
865
+ comg12 = clam12;
866
+ }
867
+ let salp1 = cbet2 * somg12;
868
+ let calp1 = comg12 >= 0 ? sbet12 + cbet2 * sbet1 * squared(somg12) / (1 + comg12) : sbet12a - cbet2 * sbet1 * squared(somg12) / (1 - comg12);
869
+ const ssig12 = hypot(salp1, calp1);
870
+ const csig12 = sbet1 * sbet2 + cbet1 * cbet2 * comg12;
871
+ let salp2 = 0;
872
+ let calp2 = 0;
873
+ let sig12 = -1;
874
+ if (shortline && ssig12 < ETOL2) {
875
+ salp2 = cbet1 * somg12;
876
+ calp2 = sbet12 - cbet1 * sbet2 * squared(somg12) / (1 + comg12);
877
+ const nt = hypot(salp2, calp2);
878
+ salp2 /= nt;
879
+ calp2 /= nt;
880
+ sig12 = Math.atan2(ssig12, csig12);
881
+ } else if (Math.abs(n) > 0.1 || csig12 >= 0 || ssig12 >= 6 * Math.abs(n) * Math.PI * squared(cbet1)) {
882
+ } else {
883
+ const lam12x = Math.atan2(-slam12, -clam12);
884
+ const k2 = squared(sbet1) * ep2;
885
+ const eps = k2 / (2 * (1 + Math.sqrt(1 + k2)) + k2);
886
+ const lamscale = f * cbet1 * A3f(eps) * Math.PI;
887
+ const betscale = lamscale * cbet1;
888
+ const x = lam12x / lamscale;
889
+ const y = sbet12a / betscale;
890
+ if (y > -TOL1 && x > -1 - XTHRESH) {
891
+ salp1 = Math.min(1, -x);
892
+ calp1 = -Math.sqrt(1 - squared(salp1));
893
+ } else {
894
+ const k = astroid(x, y);
895
+ const omg12a = lamscale * (-x * k / (1 + k));
896
+ somg12 = Math.sin(omg12a);
897
+ comg12 = -Math.cos(omg12a);
898
+ salp1 = cbet2 * somg12;
899
+ calp1 = sbet12a - cbet2 * sbet1 * squared(somg12) / (1 - comg12);
900
+ }
901
+ }
902
+ if (!(salp1 <= 0)) {
903
+ const nt = hypot(salp1, calp1);
904
+ salp1 /= nt;
905
+ calp1 /= nt;
906
+ } else {
907
+ salp1 = 1;
908
+ calp1 = 0;
909
+ }
910
+ return { sig12, salp1, calp1, salp2, calp2, dnm };
911
+ }
912
+ function inverseDistance(lat1, lon1, lat2, lon2) {
913
+ let \u03C61 = Math.max(-90, Math.min(90, lat1));
914
+ let \u03C62 = Math.max(-90, Math.min(90, lat2));
915
+ let lon12 = angNormalize(angNormalize(lon2) - angNormalize(lon1));
916
+ const lonsign = lon12 >= 0 ? 1 : -1;
917
+ lon12 = lonsign * lon12;
918
+ const slam12 = lon12 === 180 ? 0 : Math.sin(lon12 * D2R);
919
+ const clam12 = Math.cos(lon12 * D2R);
920
+ const swapp = Math.abs(\u03C61) >= Math.abs(\u03C62) ? 1 : -1;
921
+ if (swapp < 0) [\u03C62, \u03C61] = [\u03C61, \u03C62];
922
+ const latsign = \u03C61 <= 0 ? 1 : -1;
923
+ \u03C61 *= latsign;
924
+ \u03C62 *= latsign;
925
+ let sbet1 = f1 * Math.sin(\u03C61 * D2R);
926
+ let cbet1 = Math.cos(\u03C61 * D2R);
927
+ let t = hypot(sbet1, cbet1);
928
+ sbet1 /= t;
929
+ cbet1 /= t;
930
+ cbet1 = Math.max(TINY, cbet1);
931
+ let sbet2 = f1 * Math.sin(\u03C62 * D2R);
932
+ let cbet2 = Math.cos(\u03C62 * D2R);
933
+ t = hypot(sbet2, cbet2);
934
+ sbet2 /= t;
935
+ cbet2 /= t;
936
+ cbet2 = Math.max(TINY, cbet2);
937
+ if (cbet1 < -sbet1) {
938
+ if (cbet2 === cbet1) sbet2 = copysign(sbet1, sbet2);
939
+ } else {
940
+ if (Math.abs(sbet2) === -sbet1) cbet2 = cbet1;
941
+ }
942
+ const dn1 = Math.sqrt(1 + ep2 * squared(sbet1));
943
+ const dn2 = Math.sqrt(1 + ep2 * squared(sbet2));
944
+ const lam12 = lon12 * D2R;
945
+ const C1a = new Array(ORDER + 1);
946
+ const C2a = new Array(ORDER + 1);
947
+ const C3a = new Array(ORDER);
948
+ let s12b;
949
+ let calp1;
950
+ let salp1;
951
+ let calp2;
952
+ let ssig1;
953
+ let csig1;
954
+ let ssig2;
955
+ let csig2;
956
+ let eps;
957
+ const meridian = \u03C61 === -90 || slam12 === 0;
958
+ if (meridian) {
959
+ calp1 = clam12;
960
+ salp1 = slam12;
961
+ calp2 = 1;
962
+ ssig1 = sbet1;
963
+ csig1 = calp1 * cbet1;
964
+ ssig2 = sbet2;
965
+ csig2 = calp2 * cbet2;
966
+ const sig12m = Math.atan2(
967
+ Math.max(0, csig1 * ssig2 - ssig1 * csig2),
968
+ csig1 * csig2 + ssig1 * ssig2
969
+ );
970
+ eps = n;
971
+ const nv2 = geodesicLengths(
972
+ eps,
973
+ sig12m,
974
+ ssig1,
975
+ csig1,
976
+ dn1,
977
+ ssig2,
978
+ csig2,
979
+ dn2,
980
+ C1a,
981
+ C2a
982
+ );
983
+ s12b = nv2.s12b;
984
+ if (sig12m < 3 * TINY) {
985
+ s12b = 0;
986
+ }
987
+ return b * s12b;
988
+ }
989
+ if (sbet1 === 0 && (f <= 0 || 180 - lon12 >= f * 180)) {
990
+ return a * lam12;
991
+ }
992
+ const ns = inverseStart(
993
+ sbet1,
994
+ cbet1,
995
+ dn1,
996
+ sbet2,
997
+ cbet2,
998
+ dn2,
999
+ lam12,
1000
+ slam12,
1001
+ clam12,
1002
+ C1a,
1003
+ C2a
1004
+ );
1005
+ let sig12 = ns.sig12;
1006
+ salp1 = ns.salp1;
1007
+ calp1 = ns.calp1;
1008
+ if (sig12 >= 0) {
1009
+ calp2 = ns.calp2;
1010
+ s12b = sig12 * b * ns.dnm;
1011
+ return s12b;
1012
+ }
1013
+ calp2 = 0;
1014
+ ssig1 = 0;
1015
+ csig1 = 0;
1016
+ ssig2 = 0;
1017
+ csig2 = 0;
1018
+ eps = 0;
1019
+ let salp1a = TINY;
1020
+ let calp1a = 1;
1021
+ let salp1b = TINY;
1022
+ let calp1b = -1;
1023
+ let tripn = false;
1024
+ let tripb = false;
1025
+ for (let numit = 0; ; ++numit) {
1026
+ const lv = Lambda12(
1027
+ sbet1,
1028
+ cbet1,
1029
+ dn1,
1030
+ sbet2,
1031
+ cbet2,
1032
+ dn2,
1033
+ salp1,
1034
+ calp1,
1035
+ slam12,
1036
+ clam12,
1037
+ numit < MAXIT1,
1038
+ C1a,
1039
+ C2a,
1040
+ C3a
1041
+ );
1042
+ const v = lv.lam12;
1043
+ calp2 = lv.calp2;
1044
+ sig12 = lv.sig12;
1045
+ ssig1 = lv.ssig1;
1046
+ csig1 = lv.csig1;
1047
+ ssig2 = lv.ssig2;
1048
+ csig2 = lv.csig2;
1049
+ eps = lv.eps;
1050
+ const dv = lv.dlam12;
1051
+ if (tripb || !(Math.abs(v) >= (tripn ? 8 : 1) * TOL0) || numit === MAXIT2)
1052
+ break;
1053
+ if (v > 0) {
1054
+ salp1b = salp1;
1055
+ calp1b = calp1;
1056
+ }
1057
+ if (v < 0) {
1058
+ salp1a = salp1;
1059
+ calp1a = calp1;
1060
+ }
1061
+ {
1062
+ const dalp1 = -v / dv;
1063
+ const sdalp1 = Math.sin(dalp1);
1064
+ const cdalp1 = Math.cos(dalp1);
1065
+ const nsalp1 = salp1 * cdalp1 + calp1 * sdalp1;
1066
+ if (nsalp1 > 0) {
1067
+ calp1 = calp1 * cdalp1 - salp1 * sdalp1;
1068
+ salp1 = nsalp1;
1069
+ t = hypot(salp1, calp1);
1070
+ salp1 /= t;
1071
+ calp1 /= t;
1072
+ tripn = Math.abs(v) <= 16 * TOL0;
1073
+ continue;
1074
+ }
1075
+ }
1076
+ salp1 = (salp1a + salp1b) / 2;
1077
+ calp1 = (calp1a + calp1b) / 2;
1078
+ t = hypot(salp1, calp1);
1079
+ salp1 /= t;
1080
+ calp1 /= t;
1081
+ tripn = false;
1082
+ tripb = Math.abs(salp1a - salp1) + (calp1a - calp1) < TOLB || Math.abs(salp1 - salp1b) + (calp1 - calp1b) < TOLB;
1083
+ }
1084
+ const nv = geodesicLengths(
1085
+ eps,
1086
+ sig12,
1087
+ ssig1,
1088
+ csig1,
1089
+ dn1,
1090
+ ssig2,
1091
+ csig2,
1092
+ dn2,
1093
+ C1a,
1094
+ C2a
1095
+ );
1096
+ return b * nv.s12b;
1097
+ }
1098
+ function karney([lon1, lat1], [lon2, lat2]) {
1099
+ return inverseDistance(lat1, lon1, lat2, lon2);
1100
+ }
1101
+
1102
+ // source/Domain/Utility/Calculate.ts
1103
+ var D2R2 = Math.PI / 180;
498
1104
  var \u03C0 = Math.PI;
499
1105
  function constrain(value, min, max) {
500
1106
  return Math.max(Math.min(value, max), min);
501
1107
  }
502
- function squared(n) {
503
- return n * n;
504
- }
505
- function rad(n) {
506
- return n * D2R;
1108
+ function rad(n2) {
1109
+ return n2 * D2R2;
507
1110
  }
508
1111
  var EARTH_RADIUS_MAJOR_SQUARED = squared(EARTH_RADIUS_MAJOR);
509
1112
  var EARTH_RADIUS_MINOR_SQUARED = squared(EARTH_RADIUS_MINOR);
510
1113
  var EARTH_RADIUS_FACTOR = (EARTH_RADIUS_MAJOR_SQUARED - EARTH_RADIUS_MINOR_SQUARED) / EARTH_RADIUS_MINOR_SQUARED;
511
1114
  var EARTH_INVERSE_FLATTENING = 1 / EARTH_FLATTENING;
1115
+ function cartesian([\u03BBa, \u03C6a], [\u03BBb, \u03C6b]) {
1116
+ return EARTH_RADIUS * rad(Math.sqrt(squared(\u03BBb - \u03BBa) + squared(\u03C6b - \u03C6a)));
1117
+ }
1118
+ function haversine([\u03BBa, \u03C6a], [\u03BBb, \u03C6b]) {
1119
+ const \u0394 = squared(Math.sin(rad(\u03C6b - \u03C6a) / 2)) + Math.cos(rad(\u03C6a)) * Math.cos(rad(\u03C6b)) * squared(Math.sin(rad(\u03BBb - \u03BBa) / 2));
1120
+ return EARTH_RADIUS * Math.atan2(Math.sqrt(\u0394), Math.sqrt(1 - \u0394)) * 2;
1121
+ }
1122
+ function vincenty(a2, b2) {
1123
+ const [[\u03BB1, \u03C61], [\u03BB2, \u03C62]] = [a2, b2].map((p) => p.map(rad));
1124
+ const L = \u03BB2 - \u03BB1;
1125
+ const tanU1 = (1 - EARTH_INVERSE_FLATTENING) * Math.tan(\u03C61), cosU1 = 1 / Math.sqrt(1 + tanU1 * tanU1), sinU1 = tanU1 * cosU1;
1126
+ const tanU2 = (1 - EARTH_INVERSE_FLATTENING) * Math.tan(\u03C62), cosU2 = 1 / Math.sqrt(1 + tanU2 * tanU2), sinU2 = tanU2 * cosU2;
1127
+ const antipodal = Math.abs(L) > \u03C0 / 2 || Math.abs(\u03C62 - \u03C61) > \u03C0 / 2;
1128
+ let \u03BB = L;
1129
+ let sin\u03BB = null;
1130
+ let cos\u03BB = null;
1131
+ let \u03C3 = antipodal ? \u03C0 : 0;
1132
+ let sin\u03C3 = 0;
1133
+ let cos\u03C3 = antipodal ? -1 : 1;
1134
+ let sinSq\u03C3 = null;
1135
+ let cos2\u03C3\u2098 = 1;
1136
+ let cosSq\u03B1 = 1;
1137
+ let \u03BB\u02B9 = null;
1138
+ let prev\u0394\u03BB = Infinity;
1139
+ let iterations = 0;
1140
+ do {
1141
+ sin\u03BB = Math.sin(\u03BB);
1142
+ cos\u03BB = Math.cos(\u03BB);
1143
+ sinSq\u03C3 = (cosU2 * sin\u03BB) ** 2 + (cosU1 * sinU2 - sinU1 * cosU2 * cos\u03BB) ** 2;
1144
+ if (Math.abs(sinSq\u03C3) < 1e-24) break;
1145
+ sin\u03C3 = Math.sqrt(sinSq\u03C3);
1146
+ cos\u03C3 = sinU1 * sinU2 + cosU1 * cosU2 * cos\u03BB;
1147
+ \u03C3 = Math.atan2(sin\u03C3, cos\u03C3);
1148
+ const sin\u03B1 = cosU1 * cosU2 * sin\u03BB / sin\u03C3;
1149
+ cosSq\u03B1 = 1 - sin\u03B1 * sin\u03B1;
1150
+ cos2\u03C3\u2098 = cosSq\u03B1 !== 0 ? cos\u03C3 - 2 * sinU1 * sinU2 / cosSq\u03B1 : 0;
1151
+ const C = EARTH_INVERSE_FLATTENING / 16 * cosSq\u03B1 * (4 + EARTH_INVERSE_FLATTENING * (4 - 3 * cosSq\u03B1));
1152
+ \u03BB\u02B9 = \u03BB;
1153
+ \u03BB = L + (1 - C) * EARTH_INVERSE_FLATTENING * sin\u03B1 * (\u03C3 + C * sin\u03C3 * (cos2\u03C3\u2098 + C * cos\u03C3 * (-1 + 2 * cos2\u03C3\u2098 * cos2\u03C3\u2098)));
1154
+ const \u0394\u03BB = Math.abs(\u03BB - \u03BB\u02B9);
1155
+ if (\u0394\u03BB !== 0 && \u0394\u03BB === prev\u0394\u03BB || ++iterations > 1e3)
1156
+ throw new EvalError("Vincenty formula failed to converge");
1157
+ prev\u0394\u03BB = \u0394\u03BB;
1158
+ } while (Math.abs(\u03BB - \u03BB\u02B9) > 1e-12);
1159
+ const uSq = cosSq\u03B1 * EARTH_RADIUS_FACTOR;
1160
+ const A = 1 + uSq / 16384 * (4096 + uSq * (-768 + uSq * (320 - 175 * uSq)));
1161
+ const B = uSq / 1024 * (256 + uSq * (-128 + uSq * (74 - 47 * uSq)));
1162
+ const \u0394\u03C3 = B * sin\u03C3 * (cos2\u03C3\u2098 + B / 4 * (cos\u03C3 * (-1 + 2 * cos2\u03C3\u2098 * cos2\u03C3\u2098) - B / 6 * cos2\u03C3\u2098 * (-3 + 4 * sin\u03C3 * sin\u03C3) * (-3 + 4 * cos2\u03C3\u2098 * cos2\u03C3\u2098)));
1163
+ return EARTH_RADIUS_MINOR * A * (\u03C3 - \u0394\u03C3);
1164
+ }
512
1165
  var PointToPoint = {
513
- cartesian([\u03BBa, \u03C6a], [\u03BBb, \u03C6b]) {
514
- return EARTH_RADIUS * rad(Math.sqrt(squared(\u03BBb - \u03BBa) + squared(\u03C6b - \u03C6a)));
515
- },
516
- haversine([\u03BBa, \u03C6a], [\u03BBb, \u03C6b]) {
517
- const \u0394 = squared(Math.sin(rad(\u03C6b - \u03C6a) / 2)) + Math.cos(rad(\u03C6a)) * Math.cos(rad(\u03C6b)) * squared(Math.sin(rad(\u03BBb - \u03BBa) / 2));
518
- return EARTH_RADIUS * Math.atan2(Math.sqrt(\u0394), Math.sqrt(1 - \u0394)) * 2;
519
- },
520
- vincenty(...points) {
521
- const [[\u03BB1, \u03C61], [\u03BB2, \u03C62]] = points.map(
522
- (p) => p.map(rad)
523
- );
524
- const L = \u03BB2 - \u03BB1;
525
- const tanU1 = (1 - EARTH_INVERSE_FLATTENING) * Math.tan(\u03C61), cosU1 = 1 / Math.sqrt(1 + tanU1 * tanU1), sinU1 = tanU1 * cosU1;
526
- const tanU2 = (1 - EARTH_INVERSE_FLATTENING) * Math.tan(\u03C62), cosU2 = 1 / Math.sqrt(1 + tanU2 * tanU2), sinU2 = tanU2 * cosU2;
527
- const antipodal = Math.abs(L) > \u03C0 / 2 || Math.abs(\u03C62 - \u03C61) > \u03C0 / 2;
528
- let \u03BB = L;
529
- let sin\u03BB = null;
530
- let cos\u03BB = null;
531
- let \u03C3 = antipodal ? \u03C0 : 0;
532
- let sin\u03C3 = 0;
533
- let cos\u03C3 = antipodal ? -1 : 1;
534
- let sinSq\u03C3 = null;
535
- let cos2\u03C3\u2098 = 1;
536
- let cosSq\u03B1 = 1;
537
- let \u03BB\u02B9 = null;
538
- let iterations = 0;
539
- do {
540
- sin\u03BB = Math.sin(\u03BB);
541
- cos\u03BB = Math.cos(\u03BB);
542
- sinSq\u03C3 = (cosU2 * sin\u03BB) ** 2 + (cosU1 * sinU2 - sinU1 * cosU2 * cos\u03BB) ** 2;
543
- if (Math.abs(sinSq\u03C3) < 1e-24) break;
544
- sin\u03C3 = Math.sqrt(sinSq\u03C3);
545
- cos\u03C3 = sinU1 * sinU2 + cosU1 * cosU2 * cos\u03BB;
546
- \u03C3 = Math.atan2(sin\u03C3, cos\u03C3);
547
- const sin\u03B1 = cosU1 * cosU2 * sin\u03BB / sin\u03C3;
548
- cosSq\u03B1 = 1 - sin\u03B1 * sin\u03B1;
549
- cos2\u03C3\u2098 = cosSq\u03B1 !== 0 ? cos\u03C3 - 2 * sinU1 * sinU2 / cosSq\u03B1 : 0;
550
- const C = EARTH_INVERSE_FLATTENING / 16 * cosSq\u03B1 * (4 + EARTH_INVERSE_FLATTENING * (4 - 3 * cosSq\u03B1));
551
- \u03BB\u02B9 = \u03BB;
552
- \u03BB = L + (1 - C) * EARTH_INVERSE_FLATTENING * sin\u03B1 * (\u03C3 + C * sin\u03C3 * (cos2\u03C3\u2098 + C * cos\u03C3 * (-1 + 2 * cos2\u03C3\u2098 * cos2\u03C3\u2098)));
553
- } while (Math.abs(\u03BB - \u03BB\u02B9) > 1e-12 && ++iterations < 1e3);
554
- const uSq = cosSq\u03B1 * EARTH_RADIUS_FACTOR;
555
- const A = 1 + uSq / 16384 * (4096 + uSq * (-768 + uSq * (320 - 175 * uSq)));
556
- const B = uSq / 1024 * (256 + uSq * (-128 + uSq * (74 - 47 * uSq)));
557
- const \u0394\u03C3 = B * sin\u03C3 * (cos2\u03C3\u2098 + B / 4 * (cos\u03C3 * (-1 + 2 * cos2\u03C3\u2098 * cos2\u03C3\u2098) - B / 6 * cos2\u03C3\u2098 * (-3 + 4 * sin\u03C3 * sin\u03C3) * (-3 + 4 * cos2\u03C3\u2098 * cos2\u03C3\u2098)));
558
- return EARTH_RADIUS_MINOR * A * (\u03C3 - \u0394\u03C3);
559
- }
1166
+ cartesian,
1167
+ haversine,
1168
+ vincenty,
1169
+ karney
560
1170
  };
561
1171
  function getClosestPointOnLineByPoint(point, line) {
562
1172
  const [[px, py], [ax, ay], [bx, by]] = [point, ...line];
@@ -569,10 +1179,10 @@ function getClosestPointOnLineByPoint(point, line) {
569
1179
  );
570
1180
  return t === 0 || t === 1 ? line[t] : [ax + abx * t, ay + aby * t];
571
1181
  }
572
- function getDistanceOfPointToPoint(a, b, calculation) {
1182
+ function getDistanceOfPointToPoint(a2, b2, calculation) {
573
1183
  const calc = typeof calculation === "function" ? calculation : PointToPoint[calculation];
574
1184
  if (typeof calc === "function") {
575
- return calc(a, b);
1185
+ return calc(a2, b2);
576
1186
  }
577
1187
  throw new Error(`Not a PointToPoint calculation function ${calculation}`);
578
1188
  }
@@ -583,15 +1193,15 @@ function getDistanceOfPointToLine(point, line, calculation) {
583
1193
  calculation
584
1194
  );
585
1195
  }
586
- function getDistanceOfLineToLine(a, b, calculation) {
587
- return isLinesCrossing(a, b) ? 0 : Math.min(
588
- ...a.map((a2) => getDistanceOfPointToLine(a2, b, calculation)),
589
- ...b.map((b2) => getDistanceOfPointToLine(b2, a, calculation))
1196
+ function getDistanceOfLineToLine(a2, b2, calculation) {
1197
+ return isLinesCrossing(a2, b2) ? 0 : Math.min(
1198
+ ...a2.map((a3) => getDistanceOfPointToLine(a3, b2, calculation)),
1199
+ ...b2.map((b3) => getDistanceOfPointToLine(b3, a2, calculation))
590
1200
  );
591
1201
  }
592
- function isLinesCrossing(a, b) {
593
- const [[a1x, a1y], [a2x, a2y]] = a;
594
- const [[b1x, b1y], [b2x, b2y]] = b;
1202
+ function isLinesCrossing(a2, b2) {
1203
+ const [[a1x, a1y], [a2x, a2y]] = a2;
1204
+ const [[b1x, b1y], [b2x, b2y]] = b2;
595
1205
  const [s1x, s1y, s2x, s2y] = [a2x - a1x, a2y - a1y, b2x - b1x, b2y - b1y];
596
1206
  const s = (-s1y * (a1x - b1x) + s1x * (a1y - b1y)) / (-s2x * s1y + s1x * s2y);
597
1207
  const t = (s2x * (a1y - b1y) - s2y * (a1x - b1x)) / (-s2x * s1y + s1x * s2y);
@@ -605,13 +1215,13 @@ function isPointInRing(p, ring) {
605
1215
  return false;
606
1216
  }
607
1217
  const { length } = ring;
608
- const odd = ring.reduce((odd2, a, i) => {
609
- const b = ring[(length + i - 1) % length];
610
- 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]) ? odd2 ^ Number(
611
- a[0] + (p[1] - a[1]) / (b[1] - a[1]) * (b[0] - a[0]) < p[0]
1218
+ const odd = ring.reduce((odd2, a2, i) => {
1219
+ const b2 = ring[(length + i - 1) % length];
1220
+ return (a2[1] < p[1] && b2[1] >= p[1] || b2[1] < p[1] && a2[1] >= p[1]) && (a2[0] <= p[0] || b2[0] <= p[0]) ? odd2 ^ Number(
1221
+ a2[0] + (p[1] - a2[1]) / (b2[1] - a2[1]) * (b2[0] - a2[0]) < p[0]
612
1222
  ) : odd2;
613
1223
  }, 0);
614
- return odd !== 0 || ring.slice(1).some((a, index) => isPointOnLine(p, [ring[index], a]));
1224
+ return odd !== 0 || ring.slice(1).some((a2, index) => isPointOnLine(p, [ring[index], a2]));
615
1225
  }
616
1226
 
617
1227
  // source/Domain/Utility/Segments.ts
@@ -621,76 +1231,88 @@ function segments(line) {
621
1231
 
622
1232
  // source/Domain/Utility/Distance.ts
623
1233
  var geometries = {
624
- PointPoint(a, b, calculation) {
625
- return getDistanceOfPointToPoint(a, b, calculation);
1234
+ PointPoint(a2, b2, calculation) {
1235
+ return getDistanceOfPointToPoint(a2, b2, calculation);
626
1236
  },
627
- LineStringPoint(a, b, calculation) {
1237
+ LineStringPoint(a2, b2, calculation) {
628
1238
  return Math.min(
629
- ...segments(a).map(
630
- (line) => getDistanceOfPointToLine(b, line, calculation)
1239
+ ...segments(a2).map(
1240
+ (line) => getDistanceOfPointToLine(b2, line, calculation)
631
1241
  )
632
1242
  );
633
1243
  },
634
- LineStringLineString(a, b, calculation) {
635
- const sa = segments(a);
636
- const sb = segments(b);
1244
+ LineStringLineString(a2, b2, calculation) {
1245
+ const sa = segments(a2);
1246
+ const sb = segments(b2);
637
1247
  return sa.reduce(
638
- (carry, a2) => sb.reduce(
639
- (carry2, b2) => carry2 > 0 ? Math.min(
1248
+ (carry, a3) => sb.reduce(
1249
+ (carry2, b3) => carry2 > 0 ? Math.min(
640
1250
  carry2,
641
- getDistanceOfLineToLine(a2, b2, calculation)
1251
+ getDistanceOfLineToLine(a3, b3, calculation)
642
1252
  ) : carry2,
643
1253
  carry
644
1254
  ),
645
1255
  Infinity
646
1256
  );
647
1257
  },
648
- PolygonPoint([exterior, ...interior], b, calculation) {
649
- if (isPointInRing(b, exterior)) {
1258
+ PolygonPoint([exterior, ...interior], b2, calculation) {
1259
+ if (isPointInRing(b2, exterior)) {
650
1260
  const [excluded] = interior.filter(
651
- (ring) => isPointInRing(b, ring)
1261
+ (ring) => isPointInRing(b2, ring)
652
1262
  );
653
- return excluded ? this.LineStringPoint(excluded, b, calculation) : 0;
1263
+ return excluded ? this.LineStringPoint(excluded, b2, calculation) : 0;
654
1264
  }
655
- return this.LineStringPoint(exterior, b, calculation);
1265
+ return this.LineStringPoint(exterior, b2, calculation);
656
1266
  },
657
- PolygonLineString(a, b, calculation) {
658
- const [exterior, ...interior] = a;
659
- const line = segments(b);
660
- const ring = b.some((b2) => isPointInRing(b2, exterior)) ? interior.find((a2) => b.every((b2) => isPointInRing(b2, a2))) : exterior;
1267
+ PolygonLineString(a2, b2, calculation) {
1268
+ const [exterior, ...interior] = a2;
1269
+ const line = segments(b2);
1270
+ const ring = b2.some((b3) => isPointInRing(b3, exterior)) ? interior.find((a3) => b2.every((b3) => isPointInRing(b3, a3))) : exterior;
661
1271
  return ring ? Math.min(
662
1272
  ...segments(ring).map(
663
- (a2) => Math.min(
1273
+ (a3) => Math.min(
664
1274
  ...line.map(
665
- (b2) => getDistanceOfLineToLine(a2, b2, calculation)
1275
+ (b3) => getDistanceOfLineToLine(a3, b3, calculation)
666
1276
  )
667
1277
  )
668
1278
  )
669
1279
  ) : 0;
670
1280
  },
671
- PolygonPolygon(a, b, calculation) {
1281
+ PolygonPolygon(a2, b2, calculation) {
672
1282
  return Math.min(
673
- this.PolygonLineString(a, b[0], calculation),
674
- this.PolygonLineString(b, a[0], calculation)
1283
+ this.PolygonLineString(a2, b2[0], calculation),
1284
+ this.PolygonLineString(b2, a2[0], calculation)
675
1285
  );
676
1286
  }
677
1287
  };
678
- function distance(a, b, calculation = "cartesian") {
1288
+ function cartesian2(a2, b2) {
1289
+ return distance(a2, b2, cartesian);
1290
+ }
1291
+ function haversine2(a2, b2) {
1292
+ return distance(a2, b2, haversine);
1293
+ }
1294
+ function vincenty2(a2, b2) {
1295
+ return distance(a2, b2, vincenty);
1296
+ }
1297
+ function karney2(a2, b2) {
1298
+ return distance(a2, b2, karney);
1299
+ }
1300
+ function distance(a2, b2, calculation = "haversine") {
679
1301
  const lookup = geometries;
680
1302
  return Math.min(
681
1303
  ...[
682
1304
  ...new IterablePairIterator(
683
- new SimpleGeometryIterator(a),
684
- new SimpleGeometryIterator(b)
1305
+ new SimpleGeometryIterator(a2),
1306
+ new SimpleGeometryIterator(b2)
685
1307
  )
686
- ].map(([a2, b2]) => {
687
- return a2.type + b2.type in lookup ? lookup[a2.type + b2.type](
688
- a2.coordinates,
689
- b2.coordinates,
1308
+ ].map(([a3, b3]) => {
1309
+ return a3.type + b3.type in lookup ? lookup[a3.type + b3.type](
1310
+ a3.coordinates,
1311
+ b3.coordinates,
690
1312
  calculation
691
- ) : b2.type + a2.type in lookup ? lookup[b2.type + a2.type](
692
- b2.coordinates,
693
- a2.coordinates,
1313
+ ) : b3.type + a3.type in lookup ? lookup[b3.type + a3.type](
1314
+ b3.coordinates,
1315
+ a3.coordinates,
694
1316
  calculation
695
1317
  ) : Infinity;
696
1318
  })
@@ -699,37 +1321,37 @@ function distance(a, b, calculation = "cartesian") {
699
1321
 
700
1322
  // source/Domain/Utility/Intersect.ts
701
1323
  var geometries2 = {
702
- PointPoint(a, b) {
703
- return a.length >= 2 && b.length >= 2 && a.slice(0, 2).every((v, i) => v === b[i]);
1324
+ PointPoint(a2, b2) {
1325
+ return a2.length >= 2 && b2.length >= 2 && a2.slice(0, 2).every((v, i) => v === b2[i]);
704
1326
  },
705
- LineStringPoint(a, b) {
706
- return a.some((a2) => this.PointPoint(a2, b)) || segments(a).some((line) => isPointOnLine(b, line));
1327
+ LineStringPoint(a2, b2) {
1328
+ return a2.some((a3) => this.PointPoint(a3, b2)) || segments(a2).some((line) => isPointOnLine(b2, line));
707
1329
  },
708
- LineStringLineString(a, b) {
709
- const lines = segments(b);
710
- return segments(a).some(
711
- (a2) => lines.some((b2) => isLinesCrossing(a2, b2))
1330
+ LineStringLineString(a2, b2) {
1331
+ const lines = segments(b2);
1332
+ return segments(a2).some(
1333
+ (a3) => lines.some((b3) => isLinesCrossing(a3, b3))
712
1334
  );
713
1335
  },
714
- PolygonPoint([exterior, ...interior], b) {
715
- return (this.LineStringPoint(exterior, b) || isPointInRing(b, exterior)) && (!interior.length || interior.every((ring) => !isPointInRing(b, ring)));
1336
+ PolygonPoint([exterior, ...interior], b2) {
1337
+ return (this.LineStringPoint(exterior, b2) || isPointInRing(b2, exterior)) && (!interior.length || interior.every((ring) => !isPointInRing(b2, ring)));
716
1338
  },
717
- PolygonLineString(a, b) {
718
- return a.some((ring) => this.LineStringLineString(ring, b)) || b.some((point) => this.PolygonPoint(a, point));
1339
+ PolygonLineString(a2, b2) {
1340
+ return a2.some((ring) => this.LineStringLineString(ring, b2)) || b2.some((point) => this.PolygonPoint(a2, point));
719
1341
  },
720
- PolygonPolygon(a, b) {
721
- return b.some(
722
- (b1) => this.PolygonLineString(a, b1) || b1.some((b2) => this.PolygonPoint(a, b2))
723
- ) || a.some(
724
- (a1) => this.PolygonLineString(b, a1) || a1.some((a2) => this.PolygonPoint(b, a2))
1342
+ PolygonPolygon(a2, b2) {
1343
+ return b2.some(
1344
+ (b1) => this.PolygonLineString(a2, b1) || b1.some((b22) => this.PolygonPoint(a2, b22))
1345
+ ) || a2.some(
1346
+ (a1) => this.PolygonLineString(b2, a1) || a1.some((a22) => this.PolygonPoint(b2, a22))
725
1347
  );
726
1348
  }
727
1349
  };
728
- function intersect(a, b) {
1350
+ function intersect(a2, b2) {
729
1351
  const lookup = geometries2;
730
1352
  for (const [itA, itB] of new IterablePairIterator(
731
- new SimpleGeometryIterator(a),
732
- new SimpleGeometryIterator(b)
1353
+ new SimpleGeometryIterator(a2),
1354
+ new SimpleGeometryIterator(b2)
733
1355
  )) {
734
1356
  if (itA.type + itB.type in lookup && lookup[itA.type + itB.type](
735
1357
  itA.coordinates,
@@ -742,13 +1364,16 @@ function intersect(a, b) {
742
1364
  }
743
1365
  export {
744
1366
  SimpleGeometryIterator,
1367
+ cartesian2 as cartesian,
745
1368
  distance,
1369
+ haversine2 as haversine,
746
1370
  intersect,
747
1371
  isFeature,
748
1372
  isFeatureCollection,
749
1373
  isGeoJSON,
750
1374
  isGeometry,
751
1375
  isGeometryCollection,
1376
+ isGeometryPrimitive,
752
1377
  isLineString,
753
1378
  isMultiLineString,
754
1379
  isMultiPoint,
@@ -761,12 +1386,15 @@ export {
761
1386
  isStrictGeoJSON,
762
1387
  isStrictGeometry,
763
1388
  isStrictGeometryCollection,
1389
+ isStrictGeometryPrimitive,
764
1390
  isStrictLineString,
765
1391
  isStrictMultiLineString,
766
1392
  isStrictMultiPoint,
767
1393
  isStrictMultiPolygon,
768
1394
  isStrictPoint,
769
1395
  isStrictPolygon,
770
- isStrictPosition
1396
+ isStrictPosition,
1397
+ karney2 as karney,
1398
+ vincenty2 as vincenty
771
1399
  };
772
1400
  //# sourceMappingURL=main.mjs.map