terra-route 0.0.9 → 0.0.11

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 (48) hide show
  1. package/README.md +23 -60
  2. package/assets/logo-dark-mode.png +0 -0
  3. package/assets/logo.png +0 -0
  4. package/dist/graph/graph.d.ts +31 -0
  5. package/dist/graph/methods/bounding-box.d.ts +13 -0
  6. package/dist/graph/methods/duplicates.d.ts +7 -0
  7. package/dist/graph/methods/leaf.d.ts +12 -0
  8. package/dist/graph/methods/spatial-index/geokdbush.d.ts +3 -0
  9. package/dist/graph/methods/spatial-index/kdbush.d.ts +16 -0
  10. package/dist/graph/methods/spatial-index/tinyqueue.d.ts +11 -0
  11. package/dist/graph/methods/unify.d.ts +2 -0
  12. package/dist/graph/methods/unique.d.ts +5 -0
  13. package/dist/heap/four-ary-heap.d.ts +17 -0
  14. package/dist/terra-route.cjs +1 -1
  15. package/dist/terra-route.cjs.map +1 -1
  16. package/dist/terra-route.d.ts +22 -14
  17. package/dist/terra-route.modern.js +1 -1
  18. package/dist/terra-route.modern.js.map +1 -1
  19. package/dist/terra-route.module.js +1 -1
  20. package/dist/terra-route.module.js.map +1 -1
  21. package/dist/terra-route.umd.js +1 -1
  22. package/dist/terra-route.umd.js.map +1 -1
  23. package/package.json +1 -1
  24. package/src/distance/haversine.ts +1 -0
  25. package/src/graph/graph.spec.ts +238 -0
  26. package/src/graph/graph.ts +63 -2
  27. package/src/graph/methods/bounding-box.spec.ts +199 -0
  28. package/src/graph/methods/bounding-box.ts +85 -0
  29. package/src/graph/methods/connected.spec.ts +3 -1
  30. package/src/graph/methods/duplicates.spec.ts +161 -0
  31. package/src/graph/methods/duplicates.ts +117 -0
  32. package/src/graph/methods/leaf.spec.ts +224 -0
  33. package/src/graph/methods/leaf.ts +88 -0
  34. package/src/graph/methods/spatial-index/geokdbush.spec.ts +86 -0
  35. package/src/graph/methods/spatial-index/geokdbush.ts +189 -0
  36. package/src/graph/methods/spatial-index/kdbush.spec.ts +67 -0
  37. package/src/graph/methods/spatial-index/kdbush.ts +189 -0
  38. package/src/graph/methods/spatial-index/tinyqueue.spec.ts +51 -0
  39. package/src/graph/methods/spatial-index/tinyqueue.ts +108 -0
  40. package/src/graph/methods/unify.spec.ts +475 -0
  41. package/src/graph/methods/unify.ts +132 -0
  42. package/src/graph/methods/unique.spec.ts +65 -0
  43. package/src/heap/four-ary-heap.spec.ts +149 -0
  44. package/src/heap/four-ary-heap.ts +143 -0
  45. package/src/terra-route.ts +279 -104
  46. package/src/test-utils/utils.ts +1 -1
  47. package/src/graph/methods/unique-segments.spec.ts +0 -16
  48. /package/src/graph/methods/{unique-segments.ts → unique.ts} +0 -0
package/README.md CHANGED
@@ -1,6 +1,12 @@
1
- # Terra Route
1
+ <picture>
2
+ <source media="(prefers-color-scheme: dark)" srcset="./assets/logo-dark-mode.png">
3
+ <source media="(prefers-color-scheme: light)" srcset="./assets/logo.png">
4
+ <img alt="Terra Draw logo" src="./assets/logo.png" width="400px">
5
+ </picture>
2
6
 
3
- Terra Route aims to be a fast library for routing on GeoJSON LineStrings networks, where LineStrings share identical coordinates. Terra Routes main aim is currently performance - it uses A* to help achieve this.
7
+ <p></p>
8
+
9
+ Terra Route aims to be a fast library for routing on GeoJSON LineStrings networks, where LineStrings share identical coordinates.
4
10
 
5
11
  ## Install
6
12
 
@@ -20,62 +26,20 @@ Here is a short example of how to use the TerraRoute class:
20
26
  import { FeatureCollection, LineString, Point, Feature } from "geojson";
21
27
  import { TerraRoute } from "terra-route";
22
28
 
23
- // Sample GeoJSON network (a simple "L" shape)
24
- const network: FeatureCollection<LineString> = {
25
- type: "FeatureCollection",
26
- features: [
27
- {
28
- type: "Feature",
29
- geometry: {
30
- type: "LineString",
31
- coordinates: [
32
- [0, 0], // A
33
- [0, 1], // B
34
- [0, 2], // C
35
- ],
36
- },
37
- properties: {},
38
- },
39
- {
40
- type: "Feature",
41
- geometry: {
42
- type: "LineString",
43
- coordinates: [
44
- [0, 1], // B
45
- [1, 1], // D
46
- ],
47
- },
48
- properties: {},
49
- },
50
- ],
51
- };
52
-
53
- // Define start and end points (A and D)
54
- const startPoint: Feature<Point> = {
55
- type: "Feature",
56
- geometry: {
57
- type: "Point",
58
- coordinates: [0, 0], // Point A
59
- },
60
- properties: {},
61
- };
62
-
63
- const endPoint: Feature<Point> = {
64
- type: "Feature",
65
- geometry: {
66
- type: "Point",
67
- coordinates: [1, 1], // Point D
68
- },
69
- properties: {},
70
- };
29
+ // We omit the literal values here in the README for brevity
30
+ import { network, startPoint, endPoint } from './network'
71
31
 
72
32
  // Initialize TerraRoute instance
73
33
  const router = new TerraRoute();
74
34
 
75
- // We must build the route graph first before calling getRoute
35
+ // network here is a FeatureCollection<LineString> where the all
36
+ // identical coordinates are considered connected.
37
+ // We must build the route graph first before calling getRoute.
76
38
  router.buildRouteGraph(network);
77
39
 
78
- // Get shortest route
40
+ // Get shortest route where startPoint and endpoint are Feature<Point> of
41
+ // a coordinate node which is present on the network (i.e. the coordinate
42
+ // exists in one of the linestrings)
79
43
  const route = router.getRoute(startPoint, endPoint);
80
44
 
81
45
  console.log("Shortest route:", JSON.stringify(route, null, 2));
@@ -83,7 +47,7 @@ console.log("Shortest route:", JSON.stringify(route, null, 2));
83
47
 
84
48
  ## Additional Functionality
85
49
 
86
- Terra Route also exposes functionality for understanding GeoJSON route networks better called `LineStringGraph`. This can be useful for debugging as this class has a series of methods for determining things like unique nodes, edges, connected components as well as all their counts. With this class you can understand your graph better programmatically, for example determining it's size and if it is correctly connected.
50
+ Terra Route provides a utility called LineStringGraph for analyzing GeoJSON route networks. This class is especially useful for debugging, as it includes methods to identify unique nodes, edges, and connected components, along with their counts. Beyond debugging, these methods help you programmatically explore and understand the structure of your graph for example, by measuring its size and examining how its parts are connected.
87
51
 
88
52
  ```typescript
89
53
  const graph = new LineStringGraph(network);
@@ -93,9 +57,6 @@ const graphPoints = graph.getNodes();
93
57
 
94
58
  // Return all the unique edges as FeatureCollection<LineString>, where each unique edge is a Feature<LineString>
95
59
  const graphEdges = graph.getEdges();
96
-
97
- // The longest possible shortest path in the graph between two nodes (i.e. graph diameter)
98
- const longestShortestPath = graph.getMaxLengthShortestPath()
99
60
  ```
100
61
 
101
62
  ## Benchmarks
@@ -109,15 +70,17 @@ npm run benchmark
109
70
  Here is an example output of a benchmark run for routing:
110
71
 
111
72
  <pre>
112
- Terra Route | ███████████ 270ms
113
- GeoJSON Path Finder | █████████████████████████ 591ms
114
- ngraph.graph | ██████████████████████████████████████████████████ 1177ms
73
+ Terra Route | ██████ 186ms
74
+ GeoJSON Path Finder | ██████████████████ 566ms
75
+ ngraph.graph | ██████████████████████████████████████████████████ 1577ms
115
76
  </pre>
116
77
 
117
- Using default Haversine distance, Terra Route is approximately 2x faster than GeoJSON Path Finder with Haversine distance for A -> B path finding. If you pass in the CheapRuler distance metric (you can use the exposed `createCheapRuler` function), it is approximately x5 faster than GeoJSON Path Finder with Haversine distance.
78
+ Using default Haversine distance, Terra Route is approximately 3x faster than GeoJSON Path Finder with Haversine distance for A -> B path finding. If you pass in the CheapRuler distance metric (you can use the exposed `createCheapRuler` function), it is approximately x8 faster than GeoJSON Path Finder with Haversine distance.
118
79
 
119
80
  For initialisation of the network, Terra Route is approximately 10x faster with Haversine than GeoJSON Path Finder. Terra Draw splits out instantiating the Class of the library from the actual graph building, which is done via `buildRouteGraph`. This allows you to defer graph creation to an appropriate time.
120
81
 
82
+ Terra Route uses an [A* algorthm for pathfinding](https://en.wikipedia.org/wiki/A*_search_algorithm) and by default uses a [four-ary heap](https://en.wikipedia.org/wiki/D-ary_heap) for the underlying priority queue, although this is configurable.
83
+
121
84
  ## Limitations
122
85
 
123
86
  - Terra Route does not currently support weighting functions.
Binary file
Binary file
@@ -1,4 +1,5 @@
1
1
  import { Feature, FeatureCollection, LineString, Point } from "geojson";
2
+ import { BoundingBox } from "./methods/bounding-box";
2
3
  /**
3
4
  * Represents a graph constructed from a GeoJSON FeatureCollection of LineString features.
4
5
  * This class provides methods to analyze the graph, including connected components, node and edge counts,
@@ -18,6 +19,18 @@ export declare class LineStringGraph {
18
19
  * @returns A GeoJSON FeatureCollection of LineString features representing the network.
19
20
  */
20
21
  getNetwork(): FeatureCollection<LineString>;
22
+ /**
23
+ * Gets a filtered network containing only LineStrings that are completely within the specified bounding box.
24
+ * @param boundingBox A bounding box array in the format [minLng, minLat, maxLng, maxLat]
25
+ * @returns A GeoJSON FeatureCollection of LineString features representing the network filtered by the bounding box.
26
+ */
27
+ getNetworkInBoundingBox(boundingBox: BoundingBox): FeatureCollection<LineString>;
28
+ /**
29
+ * Gets the network without duplicate or subsection lines.
30
+ * This method processes the network to remove any duplicate lines or lines that are subsections of other lines.
31
+ * @returns A FeatureCollection<LineString> representing the network without duplicate or subsection lines.
32
+ */
33
+ getNetworkWithoutDuplicatesOrSubsections(): FeatureCollection<LineString, import("geojson").GeoJsonProperties>;
21
34
  /**
22
35
  * Gets the connected components of the graph.
23
36
  * @returns An array of FeatureCollection<LineString> representing the connected components.
@@ -80,4 +93,22 @@ export declare class LineStringGraph {
80
93
  * @returns The number of unique edges in the graph.
81
94
  */
82
95
  getEdgeCount(): number;
96
+ /**
97
+ * Gets the leaf edges of the graph. A leaf edge is defined as an edge whose start or end node has a degree of 1.
98
+ * Here an edge is defined as a LineString with two coordinates, representing the start and end points.
99
+ * @returns A FeatureCollection<LineString> containing only the leaf edges of the graph.
100
+ */
101
+ getLeafEdges(): FeatureCollection<LineString>;
102
+ /**
103
+ * Returns the pruned network, which is the network without the leaf edges.
104
+ * i.e. This method removes all leaf edges from the network, leaving only the non-leaf edges
105
+ * @return A FeatureCollection<LineString> representing the pruned network without leaf edges.
106
+ */
107
+ getPrunedEdges(depth?: number): FeatureCollection<LineString>;
108
+ /**
109
+ * Returns the network where all nodes that are with n meters of each other are unified.
110
+ * The function will avoid unifying coordinates in the same linestring.
111
+ * @param toleranceMeters the tolerance for unifying nodes in meters.
112
+ */
113
+ getUnifiedNetwork(toleranceMeters: number): FeatureCollection<LineString, import("geojson").GeoJsonProperties>;
83
114
  }
@@ -0,0 +1,13 @@
1
+ import { FeatureCollection, LineString } from 'geojson';
2
+ /**
3
+ * Type representing a bounding box as [minLng, minLat, maxLng, maxLat]
4
+ */
5
+ export type BoundingBox = [number, number, number, number];
6
+ /**
7
+ * Filters a FeatureCollection of LineString features to only include LineStrings
8
+ * that are completely within the specified bounding box.
9
+ * @param featureCollection - A GeoJSON FeatureCollection containing LineString features
10
+ * @param boundingBox - A bounding box array in the format [minLng, minLat, maxLng, maxLat]
11
+ * @returns A new FeatureCollection<LineString> containing only the LineStrings completely within the bounding box
12
+ */
13
+ export declare function getNetworkInBoundingBox(featureCollection: FeatureCollection<LineString>, boundingBox: BoundingBox): FeatureCollection<LineString>;
@@ -0,0 +1,7 @@
1
+ import { FeatureCollection, LineString } from 'geojson';
2
+ /**
3
+ * Remove any LineString that is either
4
+ * - an exact duplicate of an earlier one, or
5
+ * - a contiguous subsequence (in either direction) of any other.
6
+ */
7
+ export declare function removeDuplicateAndSubsectionLines(collection: FeatureCollection<LineString>): FeatureCollection<LineString>;
@@ -0,0 +1,12 @@
1
+ import { FeatureCollection, LineString } from 'geojson';
2
+ /**
3
+ * Separates a graph's edges into leaf and non-leaf edges.
4
+ * A leaf edge has a start or end node with degree 1.
5
+ *
6
+ * @param edgesFc - FeatureCollection containing LineString features representing edges of a graph
7
+ * @returns Object containing two FeatureCollections: leafEdges and nonLeafEdges
8
+ */
9
+ export declare function getLeafEdges(edgesFc: FeatureCollection<LineString>): {
10
+ leafEdges: FeatureCollection<LineString>;
11
+ nonLeafEdges: FeatureCollection<LineString>;
12
+ };
@@ -0,0 +1,3 @@
1
+ import { KDBush } from './kdbush';
2
+ export declare function around(index: KDBush, lng: number, lat: number, maxResults?: number, maxDistanceKm?: number): any[];
3
+ export declare function distance(lng1: number, lat1: number, lng2: number, lat2: number): number;
@@ -0,0 +1,16 @@
1
+ export declare class KDBush {
2
+ data: ArrayBuffer;
3
+ ids: Uint16Array | Uint32Array;
4
+ coords: InstanceType<TypedArrayConstructor>;
5
+ private _pos;
6
+ private _finished;
7
+ numItems: number;
8
+ nodeSize: number;
9
+ private ArrayType;
10
+ private IndexArrayType;
11
+ constructor(numItems: number, nodeSize?: number, ArrayType?: TypedArrayConstructor, data?: ArrayBuffer);
12
+ add(x: number, y: number): number;
13
+ finish(): this;
14
+ }
15
+ type TypedArrayConstructor = Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor;
16
+ export {};
@@ -0,0 +1,11 @@
1
+ export default class TinyQueue<T> {
2
+ private data;
3
+ length: number;
4
+ private compare;
5
+ constructor(data?: T[], compare?: (a: T, b: T) => number);
6
+ push(item: T): void;
7
+ pop(): T | undefined;
8
+ peek(): T | undefined;
9
+ private _up;
10
+ private _down;
11
+ }
@@ -0,0 +1,2 @@
1
+ import { FeatureCollection, LineString } from 'geojson';
2
+ export declare function unifyCloseCoordinates(featureCollection: FeatureCollection<LineString>, radiusMeters: number): FeatureCollection<LineString>;
@@ -0,0 +1,5 @@
1
+ import { FeatureCollection, LineString } from 'geojson';
2
+ /**
3
+ * Breaks LineStrings in a FeatureCollection into unique single line segments
4
+ */
5
+ export declare function graphGetUniqueSegments(input: FeatureCollection<LineString>): FeatureCollection<LineString>;
@@ -0,0 +1,17 @@
1
+ import { Heap } from "./heap";
2
+ /**
3
+ * A 4-ary min-heap with stable tie-breaking on insertion order.
4
+ * Parent(i) = floor((i - 1) / 4)
5
+ * Children(i) = 4*i + 1 .. 4*i + 4
6
+ */
7
+ export declare class FourAryHeap implements Heap {
8
+ private keys;
9
+ private values;
10
+ private idxs;
11
+ private length;
12
+ private insertCounter;
13
+ insert(key: number, value: number): void;
14
+ extractMin(): number | null;
15
+ size(): number;
16
+ private bubbleDown;
17
+ }
@@ -1,2 +1,2 @@
1
- function e(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function t(t,r){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,r){if(t){if("string"==typeof t)return e(t,r);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?e(t,r):void 0}}(t))||r&&t&&"number"==typeof t.length){n&&(t=n);var o=0;return function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r=function(e,t){var r=function(e){return e*Math.PI/180},n=r(e[1]),o=r(e[0]),a=r(t[1]),i=a-n,s=r(t[0])-o,u=Math.sin(i/2)*Math.sin(i/2)+Math.cos(n)*Math.cos(a)*Math.sin(s/2)*Math.sin(s/2);return 2*Math.atan2(Math.sqrt(u),Math.sqrt(1-u))*6371e3/1e3},n=/*#__PURE__*/function(){function e(){this.heap=[],this.insertCounter=0}var t=e.prototype;return t.insert=function(e,t){var r={key:e,value:t,index:this.insertCounter++},n=this.heap.length;for(this.heap.push(r);n>0;){var o=n-1>>>1,a=this.heap[o];if(e>a.key||e===a.key&&r.index>a.index)break;this.heap[n]=a,n=o}this.heap[n]=r},t.extractMin=function(){var e=this.heap,t=e.length;if(0===t)return null;var r=e[0],n=e.pop();return t>1&&(e[0]=n,this.bubbleDown(0)),r.value},t.size=function(){return this.heap.length},t.bubbleDown=function(e){for(var t=this.heap,r=t.length,n=t[e],o=n.key,a=n.index;;){var i=1+(e<<1);if(i>=r)break;var s=i,u=t[i],h=i+1;if(h<r){var d=t[h];(d.key<u.key||d.key===u.key&&d.index<u.index)&&(s=h,u=d)}if(!(u.key<o||u.key===o&&u.index<a))break;t[e]=u,e=s}t[e]=n},e}();function o(e,r,n){n[e]=!0;for(var a,i=t(r[e]);!(a=i()).done;){var s=a.value;n[s]||o(s,r,n)}}function a(e,t){var r=function(e,t){var r=e[0],n=t[0];return r<n||r===n&&e[1]<=t[1]?[e,t]:[t,e]}(e,t);return JSON.stringify([r[0],r[1]])}function i(e){for(var t=e.geometry.coordinates,n=0,o=0;o<t.length-1;o++)n+=r(t[o],t[o+1]);return n}var s=/*#__PURE__*/function(){function e(e){this.network=void 0,this.network=e}var r=e.prototype;return r.setNetwork=function(e){this.network=e},r.getNetwork=function(){return this.network},r.getConnectedComponents=function(){return function(e){var r=e.features,n=new Map,o=new Map;function a(e){return e[0]+","+e[1]}for(var i=0;i<r.length;i++)for(var s,u=t(r[i].geometry.coordinates);!(s=u()).done;){var h=a(s.value);o.has(h)||o.set(h,new Set),o.get(h).add(i)}for(var d=0;d<r.length;d++){n.set(d,new Set);for(var f,c=t(r[d].geometry.coordinates);!(f=c()).done;){var v=a(f.value),g=o.get(v);if(g)for(var l,p=t(g);!(l=p()).done;){var y=l.value;y!==d&&n.get(d).add(y)}}}var w=new Set,M=[];function m(e,o){for(var a=[e];a.length>0;){var i=a.pop();if(!w.has(i)){w.add(i),o.push(r[i]);var s=n.get(i);if(s)for(var u,h=t(s);!(u=h()).done;){var d=u.value;w.has(d)||a.push(d)}}}}for(var k=0;k<r.length;k++)if(!w.has(k)){var C=[];m(k,C),M.push({type:"FeatureCollection",features:C})}return M.sort(function(e,t){return e.features.length-t.features.length}),M}(this.network)},r.getConnectedComponentCount=function(){return function(e){for(var r,n=e.features,a=n.length,i=new Map,s=0;s<a;s++)for(var u,h=t(n[s].geometry.coordinates);!(u=h()).done;){var d=(r=u.value)[0]+","+r[1];i.has(d)||i.set(d,[]),i.get(d).push(s)}for(var f,c=Array.from({length:a},function(){return[]}),v=t(i.values());!(f=v()).done;)for(var g=f.value,l=0;l<g.length;l++)for(var p=l+1;p<g.length;p++){var y=g[l],w=g[p];c[y].push(w),c[w].push(y)}for(var M=new Array(a).fill(!1),m=0,k=0;k<a;k++)M[k]||(o(k,c,M),m++);return m}(this.network)},r.getNodeAndEdgeCount=function(){return function(e){for(var r,n=new Set,o=new Set,a=t(e.features);!(r=a()).done;){for(var i,s=r.value.geometry.coordinates,u=t(s);!(i=u()).done;)n.add(JSON.stringify(i.value));for(var h=0;h<s.length-1;h++){var d=(f=s[h+1],void 0,void 0,(c=JSON.stringify(s[h]))<(v=JSON.stringify(f))?c+"|"+v:v+"|"+c);o.add(d)}}var f,c,v;return{nodeCount:n.size,edgeCount:o.size}}(this.network)},r.getNodes=function(){return{type:"FeatureCollection",features:function(e){for(var r,n=new Set,o=[],a=t(e.features);!(r=a()).done;)for(var i,s=t(r.value.geometry.coordinates);!(i=s()).done;){var u=i.value,h=u.join(",");n.has(h)||(n.add(h),o.push({type:"Feature",geometry:{type:"Point",coordinates:u},properties:{}}))}return o}(this.network)}},r.getNodeCount=function(){return this.getNodeAndEdgeCount().nodeCount},r.getEdges=function(){return function(e){for(var r,n=new Map,o=t(e.features);!(r=o()).done;)for(var i=r.value.geometry.coordinates,s=0;s<i.length-1;s++){var u=i[s],h=i[s+1],d=a(u,h);n.has(d)||n.set(d,{type:"Feature",geometry:{type:"LineString",coordinates:[u,h]},properties:{}})}return{type:"FeatureCollection",features:Array.from(n.values())}}(this.network)},r.getLongestEdgeLength=function(){var e=this.getLongestEdge();return e?i(e):-1},r.getShortestEdgeLength=function(){var e=this.getShortestEdge();return e?i(e):-1},r.getLongestEdge=function(){var e=this.getEdges().features;if(0===e.length)return null;var t=e.sort(function(e,t){return i(e)-i(t)});return t[t.length-1]},r.getShortestEdge=function(){var e=this.getEdges().features;return 0===e.length?null:e.sort(function(e,t){return i(e)-i(t)})[0]},r.getEdgeCount=function(){return this.getNodeAndEdgeCount().edgeCount},e}(),u=/*#__PURE__*/function(){function e(e){var t,o;this.network=null,this.distanceMeasurement=void 0,this.heapConstructor=void 0,this.coordinateIndexMap=new Map,this.coordinates=[],this.adjacencyList=[],this.distanceMeasurement=null!=(t=null==e?void 0:e.distanceMeasurement)?t:r,this.heapConstructor=null!=(o=null==e?void 0:e.heap)?o:n}var o=e.prototype;return o.buildRouteGraph=function(e){this.network=e,this.coordinateIndexMap=new Map,this.coordinates=[],this.adjacencyList=[];for(var r,n=this.coordinateIndexMap,o=this.coordinates,a=this.adjacencyList,i=this.distanceMeasurement,s=t(e.features);!(r=s()).done;)for(var u=r.value.geometry.coordinates,h=0;h<u.length-1;h++){var d=u[h],f=d[0],c=d[1],v=u[h+1],g=v[0],l=v[1],p=n.get(f);p||(p=new Map,n.set(f,p));var y=p.get(c);void 0===y&&(y=o.length,o.push(u[h]),p.set(c,y),a[y]=[]);var w=n.get(g);w||(w=new Map,n.set(g,w));var M=w.get(l);void 0===M&&(M=o.length,o.push(u[h+1]),w.set(l,M),a[M]=[]);var m=i(u[h],u[h+1]);a[y].push({node:M,distance:m}),a[M].push({node:y,distance:m})}},o.getRoute=function(e,r){if(!this.network)throw new Error("Network not built. Please call buildRouteGraph(network) first.");var n=this.getOrCreateIndex(e.geometry.coordinates),o=this.getOrCreateIndex(r.geometry.coordinates);if(n===o)return null;var a=new this.heapConstructor;a.insert(0,n);var i=this.coordinates.length,s=new Array(i).fill(Infinity),u=new Array(i).fill(-1),h=new Array(i).fill(!1);for(s[n]=0;a.size()>0;){var d=a.extractMin();if(!h[d]){if(d===o)break;h[d]=!0;for(var f,c=t(this.adjacencyList[d]||[]);!(f=c()).done;){var v=f.value,g=s[d]+v.distance;if(g<s[v.node]){s[v.node]=g,u[v.node]=d;var l=this.distanceMeasurement(this.coordinates[v.node],this.coordinates[o]);a.insert(g+l,v.node)}}}}if(u[o]<0)return null;for(var p=[],y=o;y!==n;)p.unshift(this.coordinates[y]),y=u[y];return p.unshift(this.coordinates[n]),{type:"Feature",geometry:{type:"LineString",coordinates:p},properties:{}}},o.getOrCreateIndex=function(e){var t=e[0],r=e[1],n=this.coordinateIndexMap.get(t);n||(n=new Map,this.coordinateIndexMap.set(t,n));var o=n.get(r);return void 0===o&&(o=this.coordinates.length,this.coordinates.push(e),n.set(r,o),this.adjacencyList[o]=[]),o},e}();exports.LineStringGraph=s,exports.TerraRoute=u,exports.createCheapRuler=function(e){var t=1/298.257223563,r=t*(2-t),n=Math.PI/180,o=Math.cos(e*n),a=1/(1-r*(1-o*o)),i=Math.sqrt(a),s=6378.137*n,u=s*i*o,h=s*i*a*(1-r);return function(e,t){for(var r=e[0]-t[0];r<-180;)r+=360;for(;r>180;)r-=360;var n=r*u,o=(e[1]-t[1])*h;return Math.sqrt(n*n+o*o)}},exports.haversineDistance=r;
1
+ var t=function(t,e){var r=function(t){return t*Math.PI/180},n=r(t[1]),i=r(t[0]),a=r(e[1]),s=a-n,o=r(e[0])-i,h=Math.sin(s/2)*Math.sin(s/2)+Math.cos(n)*Math.cos(a)*Math.sin(o/2)*Math.sin(o/2);return 2*Math.atan2(Math.sqrt(h),Math.sqrt(1-h))*6371e3/1e3};function e(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function r(t,r){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,r){if(t){if("string"==typeof t)return e(t,r);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?e(t,r):void 0}}(t))||r&&t&&"number"==typeof t.length){n&&(t=n);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function n(){return n=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)({}).hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},n.apply(null,arguments)}function i(t,e,n){n[t]=!0;for(var a,s=r(e[t]);!(a=s()).done;){var o=a.value;n[o]||i(o,e,n)}}function a(t,e){var r=function(t,e){var r=t[0],n=e[0];return r<n||r===n&&t[1]<=e[1]?[t,e]:[e,t]}(t,e);return JSON.stringify([r[0],r[1]])}function s(t){for(var e,n=new Map,i=r(t.features);!(e=i()).done;)for(var s=e.value.geometry.coordinates,o=0;o<s.length-1;o++){var h=s[o],u=s[o+1],f=a(h,u);n.has(f)||n.set(f,{type:"Feature",geometry:{type:"LineString",coordinates:[h,u]},properties:{}})}return{type:"FeatureCollection",features:Array.from(n.values())}}function o(e){for(var r=e.geometry.coordinates,n=0,i=0;i<r.length-1;i++)n+=t(r[i],r[i+1]);return n}function h(t,e){var r=t.length,n=e.length;if(r>n)return!1;for(var i=0;i<=n-r;i++){for(var a=!0,s=0;s<r;s++)if(e[i+s][0]!==t[s][0]||e[i+s][1]!==t[s][1]){a=!1;break}if(a)return!0}for(var o=[].concat(t).reverse(),h=0;h<=n-r;h++){for(var u=!0,f=0;f<r;f++)if(e[h+f][0]!==o[f][0]||e[h+f][1]!==o[f][1]){u=!1;break}if(u)return!0}return!1}function u(t){var e=s(t),r=new Map;function n(t){return t.join(",")}for(var i=0;i<e.features.length;i++){var a=e.features[i].geometry.coordinates;if(!(a.length<2)){var o=n(a[0]),h=n(a[a.length-1]);r.set(o,(r.get(o)||0)+1),r.set(h,(r.get(h)||0)+1)}}for(var u=new Map,f=new Map,c=0;c<e.features.length;c++){var d=e.features[c],v=d.geometry.coordinates;if(!(v.length<2)){var l=n(v[0]),g=n(v[v.length-1]),p=r.get(l)||0,y=r.get(g)||0,m=v.map(n).join(";");1===p||1===y?u.has(m)||u.set(m,d):f.has(m)||f.set(m,d)}}return{leafEdges:{type:"FeatureCollection",features:Array.from(u.values())},nonLeafEdges:{type:"FeatureCollection",features:Array.from(f.values())}}}function f(t,e,n,i,a){for(var s,o=r(t.geometry.coordinates);!(s=o()).done;)if(!c(s.value,e,n,i,a))return!1;return!0}function c(t,e,r,n,i){var a=t[0],s=t[1];return a>=e&&a<=n&&s>=r&&s<=i}var d=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],v=/*#__PURE__*/function(){function t(t,e,r,n){if(void 0===e&&(e=64),void 0===r&&(r=Float64Array),this.data=void 0,this.ids=void 0,this.coords=void 0,this._pos=void 0,this._finished=void 0,this.numItems=void 0,this.nodeSize=void 0,this.ArrayType=void 0,this.IndexArrayType=void 0,isNaN(t)||t<0)throw new Error("Unexpected numItems value: "+t+".");this.numItems=t,this.nodeSize=Math.min(Math.max(e,2),65535),this.ArrayType=r,this.IndexArrayType=t<65536?Uint16Array:Uint32Array;var i=d.indexOf(this.ArrayType),a=2*t*this.ArrayType.BYTES_PER_ELEMENT,s=t*this.IndexArrayType.BYTES_PER_ELEMENT,o=(8-s%8)%8;if(i<0)throw new Error("Unexpected typed array class: "+r+".");n?(this.data=n,this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+s+o,2*t),this._pos=2*t,this._finished=!0):(this.data=new ArrayBuffer(8+a+s+o),this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+s+o,2*t),this._pos=0,this._finished=!1,new Uint8Array(this.data,0,2).set([219,16+i]),new Uint16Array(this.data,2,1)[0]=this.nodeSize,new Uint32Array(this.data,4,1)[0]=this.numItems)}var e=t.prototype;return e.add=function(t,e){var r=this._pos>>1;return this.ids[r]=r,this.coords[this._pos++]=t,this.coords[this._pos++]=e,r},e.finish=function(){var t=this._pos>>1;if(t!==this.numItems)throw new Error("Added "+t+" items when expected "+this.numItems+".");return l(this.ids,this.coords,this.nodeSize,0,this.numItems-1,0),this._finished=!0,this},t}();function l(t,e,r,n,i,a){if(!(i-n<=r)){var s=n+i>>1;g(t,e,s,n,i,a),l(t,e,r,n,s-1,1-a),l(t,e,r,s+1,i,1-a)}}function g(t,e,r,n,i,a){for(;i>n;){if(i-n>600){var s=i-n+1,o=r-n+1,h=Math.log(s),u=.5*Math.exp(2*h/3),f=.5*Math.sqrt(h*u*(s-u)/s)*(o-s/2<0?-1:1);g(t,e,r,Math.max(n,Math.floor(r-o*u/s+f)),Math.min(i,Math.floor(r+(s-o)*u/s+f)),a)}var c=e[2*r+a],d=n,v=i;for(p(t,e,n,r),e[2*i+a]>c&&p(t,e,n,i);d<v;){for(p(t,e,d,v),d++,v--;e[2*d+a]<c;)d++;for(;e[2*v+a]>c;)v--}e[2*n+a]===c?p(t,e,n,v):p(t,e,++v,i),v<=r&&(n=v+1),r<=v&&(i=v-1)}}function p(t,e,r,n){y(t,r,n),y(e,2*r,2*n),y(e,2*r+1,2*n+1)}function y(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}var m=/*#__PURE__*/function(){function t(t,e){if(void 0===t&&(t=[]),void 0===e&&(e=function(t,e){return t<e?-1:t>e?1:0}),this.data=void 0,this.length=void 0,this.compare=void 0,this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(var r=(this.length>>1)-1;r>=0;r--)this._down(r)}var e=t.prototype;return e.push=function(t){this.data.push(t),this._up(this.length++)},e.pop=function(){if(0!==this.length){var t=this.data[0],e=this.data.pop();return this.length--,this.length>0&&(this.data[0]=e,this._down(0)),t}},e.peek=function(){return this.data[0]},e._up=function(t){for(var e=this.data,r=this.compare,n=e[t];t>0;){var i=t-1>>1,a=e[i];if(r(n,a)>=0)break;e[t]=a,t=i}e[t]=n},e._down=function(t){for(var e=this.data,r=this.compare,n=this.length>>1,i=e[t];t<n;){var a=1+(t<<1),s=a+1;if(s<this.length&&r(e[s],e[a])<0&&(a=s),r(e[a],i)>=0)break;e[t]=e[a],t=a}e[t]=i},t}(),w=Math.PI/180;function M(t,e,r,n){var i=n.minLng,a=n.maxLng,s=n.minLat,o=n.maxLat;if(t>=i&&t<=a)return e<s?S((e-s)*w):e>o?S((e-o)*w):0;var h=Math.min(S((t-i)*w),S((t-a)*w)),u=function(t,e){var r=1-2*e;return r<=0?t>0?90:-90:Math.atan(Math.tan(t*w)/r)/w}(e,h);return u>s&&u<o?A(h,r,e,u):Math.min(A(h,r,e,s),A(h,r,e,o))}function x(t,e){return t.dist-e.dist}function S(t){var e=Math.sin(t/2);return e*e}function A(t,e,r,n){return e*Math.cos(n*w)*t+S((r-n)*w)}function I(t,e,r,n,i){return A(S((t-r)*w),i,e,n)}var k=/*#__PURE__*/function(){function e(t){this.network=void 0,this.network=t}var a=e.prototype;return a.setNetwork=function(t){this.network=t},a.getNetwork=function(){return this.network},a.getNetworkInBoundingBox=function(t){return function(t,e){var n=e[0],i=e[1],a=e[2],s=e[3];if(n>=a||i>=s)throw new Error("Invalid bounding box: min values must be less than max values");for(var o,h=[],u=r(t.features);!(o=u()).done;){var c=o.value;f(c,n,i,a,s)&&h.push(c)}return{type:"FeatureCollection",features:h}}(this.network,t)},a.getNetworkWithoutDuplicatesOrSubsections=function(){return function(t){for(var e=t.features,r=new Set,n=0;n<e.length;n++)for(var i=e[n].geometry.coordinates,a=0;a<e.length;a++)if(n!==a){var s=e[a].geometry.coordinates;if(h(i,s)&&(i.length<s.length||i.length===s.length&&n>a)){r.add(n);break}}return{type:"FeatureCollection",features:e.filter(function(t,e){return!r.has(e)})}}(this.network)},a.getConnectedComponents=function(){return function(t){var e=t.features,n=new Map,i=new Map;function a(t){return t[0]+","+t[1]}for(var s=0;s<e.length;s++)for(var o,h=r(e[s].geometry.coordinates);!(o=h()).done;){var u=a(o.value);i.has(u)||i.set(u,new Set),i.get(u).add(s)}for(var f=0;f<e.length;f++){n.set(f,new Set);for(var c,d=r(e[f].geometry.coordinates);!(c=d()).done;){var v=a(c.value),l=i.get(v);if(l)for(var g,p=r(l);!(g=p()).done;){var y=g.value;y!==f&&n.get(f).add(y)}}}var m=new Set,w=[];function M(t,i){for(var a=[t];a.length>0;){var s=a.pop();if(!m.has(s)){m.add(s),i.push(e[s]);var o=n.get(s);if(o)for(var h,u=r(o);!(h=u()).done;){var f=h.value;m.has(f)||a.push(f)}}}}for(var x=0;x<e.length;x++)if(!m.has(x)){var S=[];M(x,S),w.push({type:"FeatureCollection",features:S})}return w.sort(function(t,e){return t.features.length-e.features.length}),w}(this.network)},a.getConnectedComponentCount=function(){return function(t){for(var e,n=t.features,a=n.length,s=new Map,o=0;o<a;o++)for(var h,u=r(n[o].geometry.coordinates);!(h=u()).done;){var f=(e=h.value)[0]+","+e[1];s.has(f)||s.set(f,[]),s.get(f).push(o)}for(var c,d=Array.from({length:a},function(){return[]}),v=r(s.values());!(c=v()).done;)for(var l=c.value,g=0;g<l.length;g++)for(var p=g+1;p<l.length;p++){var y=l[g],m=l[p];d[y].push(m),d[m].push(y)}for(var w=new Array(a).fill(!1),M=0,x=0;x<a;x++)w[x]||(i(x,d,w),M++);return M}(this.network)},a.getNodeAndEdgeCount=function(){return function(t){for(var e,n=new Set,i=new Set,a=r(t.features);!(e=a()).done;){for(var s,o=e.value.geometry.coordinates,h=r(o);!(s=h()).done;)n.add(JSON.stringify(s.value));for(var u=0;u<o.length-1;u++){var f=(c=o[u+1],(d=JSON.stringify(o[u]))<(v=JSON.stringify(c))?d+"|"+v:v+"|"+d);i.add(f)}}var c,d,v;return{nodeCount:n.size,edgeCount:i.size}}(this.network)},a.getNodes=function(){return{type:"FeatureCollection",features:function(t){for(var e,n=new Set,i=[],a=r(t.features);!(e=a()).done;)for(var s,o=r(e.value.geometry.coordinates);!(s=o()).done;){var h=s.value,u=h.join(",");n.has(u)||(n.add(u),i.push({type:"Feature",geometry:{type:"Point",coordinates:h},properties:{}}))}return i}(this.network)}},a.getNodeCount=function(){return this.getNodeAndEdgeCount().nodeCount},a.getEdges=function(){return s(this.network)},a.getLongestEdgeLength=function(){var t=this.getLongestEdge();return t?o(t):-1},a.getShortestEdgeLength=function(){var t=this.getShortestEdge();return t?o(t):-1},a.getLongestEdge=function(){var t=this.getEdges().features;if(0===t.length)return null;var e=t.sort(function(t,e){return o(t)-o(e)});return e[e.length-1]},a.getShortestEdge=function(){var t=this.getEdges().features;return 0===t.length?null:t.sort(function(t,e){return o(t)-o(e)})[0]},a.getEdgeCount=function(){return this.getNodeAndEdgeCount().edgeCount},a.getLeafEdges=function(){return u(this.network).leafEdges},a.getPrunedEdges=function(t){if(t&&t>0){for(var e=this.network,r=0;r<t;r++)e=u(e).nonLeafEdges;return e}return u(this.network).nonLeafEdges},a.getUnifiedNetwork=function(e){return function(e,i){if(e.features.length<2)return e;for(var a,s=new Set,o=new Map,h=[],u=new Map,f=r(e.features);!(a=f()).done;)for(var c,d=r(a.value.geometry.coordinates);!(c=d()).done;){var l=c.value,g=l[0]+","+l[1];u.has(g)||(u.set(g,h.length),h.push(l))}for(var p=new v(h.length),y=0,A=h;y<A.length;y++){var k=A[y];p.add(k[0],k[1])}function L(e,n,a){for(var o,u=null,f=Infinity,c=r(function(t,e,r,n,i){void 0===n&&(n=Infinity),void 0===i&&(i=Infinity);var a=1,s=[];void 0===n&&(n=Infinity),void 0!==i&&(a=S(i/6371));for(var o=new m([],x),h={left:0,right:t.ids.length-1,axis:0,dist:0,minLng:-180,minLat:-90,maxLng:180,maxLat:90},u=Math.cos(r*w);h;){var f=h.right,c=h.left;if(f-c<=t.nodeSize)for(var d=c;d<=f;d++){var v=t.ids[d],l=I(e,r,t.coords[2*d],t.coords[2*d+1],u);o.push({id:v,dist:l})}else{var g=c+f>>1,p=t.coords[2*g],y=t.coords[2*g+1],A=t.ids[g],k=I(e,r,p,y,u);o.push({id:A,dist:k});var L=(h.axis+1)%2,C={left:c,right:g-1,axis:L,minLng:h.minLng,minLat:h.minLat,maxLng:0===h.axis?p:h.maxLng,maxLat:1===h.axis?y:h.maxLat,dist:0},E={left:g+1,right:f,axis:L,minLng:0===h.axis?p:h.minLng,minLat:1===h.axis?y:h.minLat,maxLng:h.maxLng,maxLat:h.maxLat,dist:0};C.dist=M(e,r,u,C),E.dist=M(e,r,u,E),o.push(C),o.push(E)}for(;o.length&&null!=o.peek().id;){var b=o.pop();if(b.dist>a)return s;if(s.push(b.id),s.length===n)return s}h=o.pop()}return s}(p,e[0],e[1],Infinity,i/1e3));!(o=c()).done;){var d=h[o.value],v=d[0]+","+d[1];if(s.has(v)&&!n.includes(d)&&!a.has(v)){var l=1e3*t(d,e);l<=i&&l<f&&(u=d,f=l)}}return null!==u?u:(s.add(e[0]+","+e[1]),e)}p.finish();var C=e.features.map(function(t){for(var e,i=[],a=[],s=new Set,h=r(t.geometry.coordinates);!(e=h()).done;){var u=e.value,f=u[0]+","+u[1];if(!o.has(f)){var c=L(u,i,s);s.has(c[0]+","+c[1])?o.set(f,u):o.set(f,c)}var d=o.get(f),v=d[0]+","+d[1];s.has(v)||(a.push(d),s.add(v)),i.push(u)}return n({},t,{geometry:n({},t.geometry,{coordinates:a})})});return n({},e,{features:C})}(this.network,e)},e}(),L=/*#__PURE__*/function(){function t(){this.keys=[],this.values=[],this.idxs=[],this.length=0,this.insertCounter=0}var e=t.prototype;return e.insert=function(t,e){var r=this.length;this.length=r+1;for(var n=t,i=e,a=this.insertCounter++;r>0;){var s=r-1>>>2,o=this.keys[s],h=this.idxs[s];if(n>o||n===o&&a>h)break;this.keys[r]=o,this.values[r]=this.values[s],this.idxs[r]=h,r=s}this.keys[r]=n,this.values[r]=i,this.idxs[r]=a},e.extractMin=function(){var t=this.length;if(0===t)return null;var e=this.values[0],r=t-1;return this.length=r,r>0&&(this.keys[0]=this.keys[r],this.values[0]=this.values[r],this.idxs[0]=this.idxs[r],this.bubbleDown(0)),e},e.size=function(){return this.length},e.bubbleDown=function(t){for(var e=this.length,r=this.keys,n=this.values,i=this.idxs,a=r[t],s=n[t],o=i[t];;){var h=1+(t<<2);if(h>=e)break;var u=h,f=r[h],c=i[h],d=n[h],v=h+1;if(v<e){var l=r[v],g=i[v];(l<f||l===f&&g<c)&&(u=v,f=l,c=g,d=n[v])}var p=h+2;if(p<e){var y=r[p],m=i[p];(y<f||y===f&&m<c)&&(u=p,f=y,c=m,d=n[p])}var w=h+3;if(w<e){var M=r[w],x=i[w];(M<f||M===f&&x<c)&&(u=w,f=M,c=x,d=n[w])}if(!(f<a||f===a&&c<o))break;r[t]=f,n[t]=d,i[t]=c,t=u}r[t]=a,n[t]=s,i[t]=o},t}(),C=/*#__PURE__*/function(){function e(e){var r,n;this.network=null,this.distanceMeasurement=void 0,this.heapConstructor=void 0,this.coordinateIndexMap=new Map,this.coordinates=[],this.adjacencyList=[],this.csrOffsets=null,this.csrIndices=null,this.csrDistances=null,this.csrNodeCount=0,this.gScoreScratch=null,this.cameFromScratch=null,this.visitedScratch=null,this.hScratch=null,this.scratchCapacity=0,this.distanceMeasurement=null!=(r=null==e?void 0:e.distanceMeasurement)?r:t,this.heapConstructor=null!=(n=null==e?void 0:e.heap)?n:L}var r=e.prototype;return r.buildRouteGraph=function(t){this.network=t,this.coordinateIndexMap=new Map,this.coordinates=[],this.adjacencyList=[],this.csrOffsets=null,this.csrIndices=null,this.csrDistances=null,this.csrNodeCount=0;for(var e=this.coordinateIndexMap,r=this.coordinates,n=this.distanceMeasurement,i=t.features,a=[],s=0,o=i.length;s<o;s++)for(var h=i[s].geometry.coordinates,u=0,f=h.length-1;u<f;u++){var c,d,v=h[u],l=h[u+1],g=v[0],p=v[1],y=l[0],m=l[1],w=e.get(g);void 0===w&&(w=new Map,e.set(g,w));var M=w.get(p);void 0===M&&(M=r.length,r.push(v),w.set(p,M));var x=e.get(y);void 0===x&&(x=new Map,e.set(y,x));var S=x.get(m);void 0===S&&(S=r.length,r.push(l),x.set(m,S)),a[M]=(null!=(c=a[M])?c:0)+1,a[S]=(null!=(d=a[S])?d:0)+1}var A=this.coordinates.length;this.csrNodeCount=A;for(var I=new Int32Array(A+1),k=0;k<A;k++){var L,C=null!=(L=a[k])?L:0;I[k+1]=I[k]+C}for(var E=I[A],b=new Int32Array(E),N=new Float64Array(E),O=I.slice(),F=0,_=i.length;F<_;F++)for(var T=i[F].geometry.coordinates,U=0,j=T.length-1;U<j;U++){var P=T[U],z=T[U+1],D=P[1],R=z[0],q=z[1],B=this.coordinateIndexMap.get(P[0]).get(D),J=this.coordinateIndexMap.get(R).get(q),G=n(P,z),Y=O[B]++;b[Y]=J,N[Y]=G,b[Y=O[J]++]=B,N[Y]=G}this.csrOffsets=I,this.csrIndices=b,this.csrDistances=N,this.adjacencyList=new Array(A)},r.getRoute=function(t,e){if(null===this.network)throw new Error("Network not built. Please call buildRouteGraph(network) first.");var r=this.getOrCreateIndex(t.geometry.coordinates),n=this.getOrCreateIndex(e.geometry.coordinates);if(r===n)return null;var i=this.coordinates,a=this.adjacencyList,s=this.distanceMeasurement,o=i.length;this.ensureScratch(o);var h=this.gScoreScratch,u=this.cameFromScratch,f=this.visitedScratch,c=this.hScratch;h.fill(Number.POSITIVE_INFINITY,0,o),u.fill(-1,0,o),f.fill(0,0,o),c.fill(-1,0,o);var d=new this.heapConstructor,v=i[n],l=c[r];for(l<0&&(l=s(i[r],v),c[r]=l),d.insert(l,r),h[r]=0;d.size()>0;){var g=d.extractMin();if(0===f[g]){if(g===n)break;if(f[g]=1,this.csrOffsets&&g<this.csrNodeCount)for(var p=this.csrOffsets,y=this.csrIndices,m=this.csrDistances,w=p[g+1],M=p[g];M<w;M++){var x=y[M],S=h[g]+m[M];if(S<h[x]){h[x]=S,u[x]=g;var A=c[x];A<0&&(A=s(i[x],v),c[x]=A),d.insert(S+A,x)}}else{var I=a[g];if(!I||0===I.length)continue;for(var k=0,L=I.length;k<L;k++){var C=I[k],E=C.node,b=h[g]+C.distance;if(b<h[E]){h[E]=b,u[E]=g;var N=c[E];N<0&&(N=s(i[E],v),c[E]=N),d.insert(b+N,E)}}}}}if(u[n]<0)return null;for(var O=[],F=n;F!==r;)O.push(i[F]),F=u[F];return O.push(i[r]),O.reverse(),{type:"Feature",geometry:{type:"LineString",coordinates:O},properties:{}}},r.getOrCreateIndex=function(t){var e=t[0],r=t[1],n=this.coordinateIndexMap.get(e);void 0===n&&(n=new Map,this.coordinateIndexMap.set(e,n));var i=n.get(r);if(void 0===i&&(i=this.coordinates.length,this.coordinates.push(t),n.set(r,i),this.adjacencyList[i]=[],this.csrOffsets)){var a=this.csrNodeCount;if(i===a){var s=new Int32Array(a+2);s.set(this.csrOffsets,0),s[a+1]=s[a],this.csrOffsets=s,this.csrNodeCount=a+1}}return i},r.ensureScratch=function(t){if(!(this.scratchCapacity>=t&&this.gScoreScratch&&this.cameFromScratch&&this.visitedScratch&&this.hScratch)){var e=0|t;this.gScoreScratch=new Float64Array(e),this.cameFromScratch=new Int32Array(e),this.visitedScratch=new Uint8Array(e),this.hScratch=new Float64Array(e),this.scratchCapacity=e}},e}();exports.LineStringGraph=k,exports.TerraRoute=C,exports.createCheapRuler=function(t){var e=1/298.257223563,r=e*(2-e),n=Math.PI/180,i=Math.cos(t*n),a=1/(1-r*(1-i*i)),s=Math.sqrt(a),o=6378.137*n,h=o*s*i,u=o*s*a*(1-r);return function(t,e){for(var r=t[0]-e[0];r<-180;)r+=360;for(;r>180;)r-=360;var n=r*h,i=(t[1]-e[1])*u;return Math.sqrt(n*n+i*i)}},exports.haversineDistance=t;
2
2
  //# sourceMappingURL=terra-route.cjs.map