terra-route 0.0.13 → 0.0.17
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/CHANGELOG.md +105 -0
- package/README.md +6 -6
- package/dist/heap/four-ary-heap.d.ts +2 -0
- package/dist/terra-route.cjs +1 -1
- package/dist/terra-route.cjs.map +1 -1
- package/dist/terra-route.d.ts +25 -1
- package/dist/terra-route.modern.js +1 -1
- package/dist/terra-route.modern.js.map +1 -1
- package/dist/terra-route.module.js +1 -1
- package/dist/terra-route.module.js.map +1 -1
- package/dist/terra-route.umd.js +1 -1
- package/dist/terra-route.umd.js.map +1 -1
- package/fta.config.json +9 -0
- package/jest.config.js +1 -1
- package/package.json +35 -8
- package/scripts/bump.mjs +57 -0
- package/scripts/release.mjs +30 -0
- package/scripts/versionrc.cjs +26 -0
- package/src/distance/haversine.ts +13 -15
- package/src/heap/fibonacci-heap.ts +9 -0
- package/src/heap/four-ary-heap.ts +10 -0
- package/src/heap/heap.d.ts +5 -0
- package/src/heap/min-heap.ts +9 -0
- package/src/heap/pairing-heap.ts +5 -0
- package/src/terra-route.compare.spec.ts +4 -5
- package/src/terra-route.spec.ts +81 -0
- package/src/terra-route.ts +282 -196
- package/dist/fibonacci-heap.d.ts +0 -11
- package/dist/graph/graph.d.ts +0 -114
- package/dist/graph/methods/bounding-box.d.ts +0 -13
- package/dist/graph/methods/connected.d.ts +0 -9
- package/dist/graph/methods/duplicates.d.ts +0 -7
- package/dist/graph/methods/leaf.d.ts +0 -12
- package/dist/graph/methods/nodes.d.ts +0 -17
- package/dist/graph/methods/spatial-index/geokdbush.d.ts +0 -3
- package/dist/graph/methods/spatial-index/kdbush.d.ts +0 -16
- package/dist/graph/methods/spatial-index/tinyqueue.d.ts +0 -11
- package/dist/graph/methods/unify.d.ts +0 -2
- package/dist/graph/methods/unique-segments.d.ts +0 -5
- package/dist/graph/methods/unique.d.ts +0 -5
- package/dist/heap/min-heap.d.ts +0 -9
- package/dist/min-heap.d.ts +0 -8
- package/dist/test-utils/utils.d.ts +0 -50
- package/instructions.md +0 -13
package/dist/fibonacci-heap.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export declare class FibonacciHeap {
|
|
2
|
-
private nodeCount;
|
|
3
|
-
private minNode;
|
|
4
|
-
insert(key: number, value: number): void;
|
|
5
|
-
extractMin(): number | null;
|
|
6
|
-
size(): number;
|
|
7
|
-
private consolidate;
|
|
8
|
-
private link;
|
|
9
|
-
private mergeLists;
|
|
10
|
-
private removeFromList;
|
|
11
|
-
}
|
package/dist/graph/graph.d.ts
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { Feature, FeatureCollection, LineString, Point } from "geojson";
|
|
2
|
-
import { BoundingBox } from "./methods/bounding-box";
|
|
3
|
-
/**
|
|
4
|
-
* Represents a graph constructed from a GeoJSON FeatureCollection of LineString features.
|
|
5
|
-
* This class provides methods to analyze the graph, including connected components, node and edge counts,
|
|
6
|
-
* and shortest paths. Coordinates in the LineStrings are considered connected if they share identical coordinates.
|
|
7
|
-
*/
|
|
8
|
-
export declare class LineStringGraph {
|
|
9
|
-
constructor(network: FeatureCollection<LineString>);
|
|
10
|
-
private network;
|
|
11
|
-
/**
|
|
12
|
-
* Sets the network for the graph.
|
|
13
|
-
* This method replaces the current network with a new one.
|
|
14
|
-
* @param network A GeoJSON FeatureCollection of LineString features representing the network.
|
|
15
|
-
*/
|
|
16
|
-
setNetwork(network: FeatureCollection<LineString>): void;
|
|
17
|
-
/**
|
|
18
|
-
* Gets the current network of the graph.
|
|
19
|
-
* @returns A GeoJSON FeatureCollection of LineString features representing the network.
|
|
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>;
|
|
34
|
-
/**
|
|
35
|
-
* Gets the connected components of the graph.
|
|
36
|
-
* @returns An array of FeatureCollection<LineString> representing the connected components.
|
|
37
|
-
*/
|
|
38
|
-
getConnectedComponents(): FeatureCollection<LineString>[];
|
|
39
|
-
/**
|
|
40
|
-
* Gets the count of connected components in the graph.
|
|
41
|
-
* @returns The number of connected components in the graph.
|
|
42
|
-
*/
|
|
43
|
-
getConnectedComponentCount(): number;
|
|
44
|
-
/**
|
|
45
|
-
* Gets the count of unique nodes and edges in the graph.
|
|
46
|
-
* @returns An object containing the counts of nodes and edges.
|
|
47
|
-
*/
|
|
48
|
-
getNodeAndEdgeCount(): {
|
|
49
|
-
nodeCount: number;
|
|
50
|
-
edgeCount: number;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Gets the unique nodes of the graph as a FeatureCollection of Point features.
|
|
54
|
-
* @returns A FeatureCollection<Point> containing the nodes of the graph.
|
|
55
|
-
*/
|
|
56
|
-
getNodes(): FeatureCollection<Point>;
|
|
57
|
-
/**
|
|
58
|
-
* Gets the count of unique nodes in the graph.
|
|
59
|
-
* @returns The number of unique nodes in the graph.
|
|
60
|
-
*/
|
|
61
|
-
getNodeCount(): number;
|
|
62
|
-
/**
|
|
63
|
-
* Gets the unique edges of the graph as a FeatureCollection of LineString features. Each edge is represented as a LineString.
|
|
64
|
-
* This method ensures that each edge is unique, meaning that edges are not duplicated in the collection. Each linestring only
|
|
65
|
-
* two coordinates, representing the start and end points of the edge.
|
|
66
|
-
* @returns A FeatureCollection<LineString> containing the unique edges of the graph.
|
|
67
|
-
*/
|
|
68
|
-
getEdges(): FeatureCollection<LineString>;
|
|
69
|
-
/**
|
|
70
|
-
* Gets the length of the longest edge in the graph based on the length of the LineString.
|
|
71
|
-
* If no edges exist, it returns -1.
|
|
72
|
-
* @returns The length of the longest edge in meters, or 0 if no edges exist.
|
|
73
|
-
*/
|
|
74
|
-
getLongestEdgeLength(): number;
|
|
75
|
-
/**
|
|
76
|
-
* Gets the length of the shortest edge in the graph based on the length of the LineString.
|
|
77
|
-
* If no edges exist, it returns -1.
|
|
78
|
-
* @returns The length of the shortest edge in meters, or 0 if no edges exist.
|
|
79
|
-
*/
|
|
80
|
-
getShortestEdgeLength(): number;
|
|
81
|
-
/**
|
|
82
|
-
* Gets the longest edge in the graph based on the length of the LineString.
|
|
83
|
-
* @returns The longest edge as a Feature<LineString> or null if no edges exist.
|
|
84
|
-
*/
|
|
85
|
-
getLongestEdge(): Feature<LineString> | null;
|
|
86
|
-
/**
|
|
87
|
-
* Gets the shortest edge in the graph based on the length of the LineString.
|
|
88
|
-
* @returns The shortest edge as a Feature<LineString> or null if no edges exist.
|
|
89
|
-
*/
|
|
90
|
-
getShortestEdge(): Feature<LineString> | null;
|
|
91
|
-
/**
|
|
92
|
-
* Gets the count of unique edges in the graph.
|
|
93
|
-
* @returns The number of unique edges in the graph.
|
|
94
|
-
*/
|
|
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>;
|
|
114
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
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>;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { FeatureCollection, LineString } from 'geojson';
|
|
2
|
-
/**
|
|
3
|
-
* Counts the number of connected components in a graph represented by LineString features in a GeoJSON FeatureCollection.
|
|
4
|
-
* Each LineString is treated as an edge in the graph, and connected components are determined by shared coordinates.
|
|
5
|
-
* @param featureCollection - A GeoJSON FeatureCollection containing LineString features
|
|
6
|
-
* @returns The number of connected components in the graph represented by the LineStrings
|
|
7
|
-
*/
|
|
8
|
-
export declare function graphGetConnectedComponentCount(featureCollection: FeatureCollection<LineString>): number;
|
|
9
|
-
export declare function graphGetConnectedComponents(featureCollection: FeatureCollection<LineString>): FeatureCollection<LineString>[];
|
|
@@ -1,7 +0,0 @@
|
|
|
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>;
|
|
@@ -1,12 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Feature, FeatureCollection, LineString, Point } from 'geojson';
|
|
2
|
-
/**
|
|
3
|
-
* Counts the unique nodes and edges in a GeoJSON FeatureCollection of LineString features.
|
|
4
|
-
* @param featureCollection - A GeoJSON FeatureCollection containing LineString features
|
|
5
|
-
* @returns An object containing the count of unique nodes and edges
|
|
6
|
-
*/
|
|
7
|
-
export declare function graphGetNodeAndEdgeCount(featureCollection: FeatureCollection<LineString>): {
|
|
8
|
-
nodeCount: number;
|
|
9
|
-
edgeCount: number;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Converts a FeatureCollection of LineString features into a FeatureCollection of Point features,
|
|
13
|
-
* where each unique coordinate in the LineStrings becomes a Point.
|
|
14
|
-
* @param lines - A GeoJSON FeatureCollection containing LineString features
|
|
15
|
-
* @returns A FeatureCollection of Point features representing unique nodes
|
|
16
|
-
*/
|
|
17
|
-
export declare function graphGetNodesAsPoints(lines: FeatureCollection<LineString>): Feature<Point>[];
|
|
@@ -1,16 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,11 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/heap/min-heap.d.ts
DELETED
package/dist/min-heap.d.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { Position, Feature, Point, LineString, FeatureCollection } from "geojson";
|
|
2
|
-
/**
|
|
3
|
-
* Calculates the total length of a LineString route in meters.
|
|
4
|
-
*
|
|
5
|
-
* @param line - A GeoJSON Feature<LineString> representing the route
|
|
6
|
-
* @returns The total length of the route in meters
|
|
7
|
-
*/
|
|
8
|
-
export declare function routeLength(line: Feature<LineString>): number;
|
|
9
|
-
/**
|
|
10
|
-
* Extracts unique coordinates from a FeatureCollection of LineStrings.
|
|
11
|
-
*
|
|
12
|
-
* @param collection - A GeoJSON FeatureCollection of LineStrings
|
|
13
|
-
* @returns An array of unique Position coordinates
|
|
14
|
-
*/
|
|
15
|
-
export declare function getUniqueCoordinatesFromLineStrings(collection: FeatureCollection<LineString>): Position[];
|
|
16
|
-
/**
|
|
17
|
-
* Validates a GeoJSON Feature<LineString> route.
|
|
18
|
-
*
|
|
19
|
-
* @param route - The GeoJSON feature to validate
|
|
20
|
-
* @returns A boolean indicating if it is a valid LineString route
|
|
21
|
-
*/
|
|
22
|
-
export declare function getReasonIfLineStringInvalid(route: Feature<LineString> | null | undefined): string | undefined;
|
|
23
|
-
/**
|
|
24
|
-
* Checks if the start and end coordinates of a LineString match the given start and end points.
|
|
25
|
-
*
|
|
26
|
-
* @param line - The LineString feature to check
|
|
27
|
-
* @param start - The start point feature
|
|
28
|
-
* @param end - The end point feature
|
|
29
|
-
* @return True if the start and end coordinates match, false otherwise
|
|
30
|
-
* */
|
|
31
|
-
export declare function startAndEndAreCorrect(line: Feature<LineString>, start: Feature<Point>, end: Feature<Point>): boolean;
|
|
32
|
-
/**
|
|
33
|
-
* Checks if the route represented by a LineString is longer than the direct path.
|
|
34
|
-
* In theory, a route should always longer than the direct path if it has more than two points.
|
|
35
|
-
* @param line - The LineString feature representing the route
|
|
36
|
-
* @param start - The start point feature
|
|
37
|
-
* @param end - The end point feature
|
|
38
|
-
* @returns - True if the route is longer than the direct path, false otherwise
|
|
39
|
-
*/
|
|
40
|
-
export declare function routeIsLongerThanDirectPath(line: Feature<LineString>, start: Feature<Point>, end: Feature<Point>): boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Modifies a FeatureCollection of LineStrings to break connections
|
|
43
|
-
* between lines that share coordinates, by adjusting one of the shared
|
|
44
|
-
* coordinates within a given tolerance.
|
|
45
|
-
*
|
|
46
|
-
* @param collection - The input FeatureCollection of LineStrings
|
|
47
|
-
* @param tolerance - The amount by which to offset shared coordinates (in degrees)
|
|
48
|
-
* @returns A new FeatureCollection with modified coordinates
|
|
49
|
-
*/
|
|
50
|
-
export declare function disconnectLineStrings(collection: FeatureCollection<LineString>, tolerance: number): FeatureCollection<LineString>;
|
package/instructions.md
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
Here we want to improve the performance by a consistently significant amount for the getRoute method TerraRoute class.
|
|
2
|
-
|
|
3
|
-
We could achieve this via data structures or algorithmic changes to the class. Look into the academic literature of Shortest Path Algorithms to get good suggestions for what would yield speedups. Also think about how this would work most effectively in the JavaScript language.
|
|
4
|
-
|
|
5
|
-
You can run tests with:
|
|
6
|
-
|
|
7
|
-
npm run test
|
|
8
|
-
|
|
9
|
-
You can assume unit tests are already passing, and do not need to run them until changes are made. You should not need to make any changes to the unit test files (.spec.ts files). In addition to unit tests, you can run a benchmark with the following command:
|
|
10
|
-
|
|
11
|
-
npm run benchmark:loop
|
|
12
|
-
|
|
13
|
-
This will run the benchmark tool 8 times. Run this first to get a comparison for future changes. You can assume the unit test
|