terra-route 0.0.11 → 0.0.13
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/README.md +7 -17
- package/dist/terra-route.cjs +1 -1
- package/dist/terra-route.cjs.map +1 -1
- package/dist/terra-route.d.ts +1 -2
- 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/instructions.md +13 -0
- package/package.json +2 -1
- package/src/terra-route.compare.spec.ts +81 -0
- package/src/terra-route.spec.ts +576 -0
- package/src/terra-route.ts +370 -154
- package/src/graph/graph.spec.ts +0 -238
- package/src/graph/graph.ts +0 -212
- package/src/graph/methods/bounding-box.spec.ts +0 -199
- package/src/graph/methods/bounding-box.ts +0 -85
- package/src/graph/methods/connected.spec.ts +0 -219
- package/src/graph/methods/connected.ts +0 -168
- package/src/graph/methods/duplicates.spec.ts +0 -161
- package/src/graph/methods/duplicates.ts +0 -117
- package/src/graph/methods/leaf.spec.ts +0 -224
- package/src/graph/methods/leaf.ts +0 -88
- package/src/graph/methods/nodes.spec.ts +0 -317
- package/src/graph/methods/nodes.ts +0 -77
- package/src/graph/methods/spatial-index/geokdbush.spec.ts +0 -86
- package/src/graph/methods/spatial-index/geokdbush.ts +0 -189
- package/src/graph/methods/spatial-index/kdbush.spec.ts +0 -67
- package/src/graph/methods/spatial-index/kdbush.ts +0 -189
- package/src/graph/methods/spatial-index/tinyqueue.spec.ts +0 -51
- package/src/graph/methods/spatial-index/tinyqueue.ts +0 -108
- package/src/graph/methods/unify.spec.ts +0 -475
- package/src/graph/methods/unify.ts +0 -132
- package/src/graph/methods/unique.spec.ts +0 -65
- package/src/graph/methods/unique.ts +0 -69
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Feature,
|
|
3
|
-
FeatureCollection,
|
|
4
|
-
LineString,
|
|
5
|
-
Position
|
|
6
|
-
} from 'geojson';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Normalize a segment so that [A, B] is equal to [B, A]
|
|
10
|
-
*/
|
|
11
|
-
function normalizeSegment(start: Position, end: Position): [Position, Position] {
|
|
12
|
-
const [aLat, aLng] = start;
|
|
13
|
-
const [bLat, bLng] = end;
|
|
14
|
-
|
|
15
|
-
if (
|
|
16
|
-
aLat < bLat ||
|
|
17
|
-
(aLat === bLat && aLng <= bLng)
|
|
18
|
-
) {
|
|
19
|
-
return [start, end];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return [end, start];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Convert a pair of Positions to a string key for deduplication
|
|
27
|
-
*/
|
|
28
|
-
function segmentKey(start: Position, end: Position): string {
|
|
29
|
-
const [normalizedStart, normalizedEnd] = normalizeSegment(start, end);
|
|
30
|
-
return JSON.stringify([normalizedStart, normalizedEnd]);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Breaks LineStrings in a FeatureCollection into unique single line segments
|
|
35
|
-
*/
|
|
36
|
-
export function graphGetUniqueSegments(
|
|
37
|
-
input: FeatureCollection<LineString>
|
|
38
|
-
): FeatureCollection<LineString> {
|
|
39
|
-
const uniqueSegments = new Map<string, Feature<LineString>>();
|
|
40
|
-
|
|
41
|
-
for (const feature of input.features) {
|
|
42
|
-
const coordinates = feature.geometry.coordinates;
|
|
43
|
-
|
|
44
|
-
for (let index = 0; index < coordinates.length - 1; index++) {
|
|
45
|
-
const start = coordinates[index];
|
|
46
|
-
const end = coordinates[index + 1];
|
|
47
|
-
|
|
48
|
-
const key = segmentKey(start, end);
|
|
49
|
-
|
|
50
|
-
if (!uniqueSegments.has(key)) {
|
|
51
|
-
const segment: Feature<LineString> = {
|
|
52
|
-
type: 'Feature',
|
|
53
|
-
geometry: {
|
|
54
|
-
type: 'LineString',
|
|
55
|
-
coordinates: [start, end]
|
|
56
|
-
},
|
|
57
|
-
properties: {}
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
uniqueSegments.set(key, segment);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return {
|
|
66
|
-
type: 'FeatureCollection',
|
|
67
|
-
features: Array.from(uniqueSegments.values())
|
|
68
|
-
};
|
|
69
|
-
}
|