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.
Files changed (37) hide show
  1. package/README.md +7 -17
  2. package/dist/terra-route.cjs +1 -1
  3. package/dist/terra-route.cjs.map +1 -1
  4. package/dist/terra-route.d.ts +1 -2
  5. package/dist/terra-route.modern.js +1 -1
  6. package/dist/terra-route.modern.js.map +1 -1
  7. package/dist/terra-route.module.js +1 -1
  8. package/dist/terra-route.module.js.map +1 -1
  9. package/dist/terra-route.umd.js +1 -1
  10. package/dist/terra-route.umd.js.map +1 -1
  11. package/instructions.md +13 -0
  12. package/package.json +2 -1
  13. package/src/terra-route.compare.spec.ts +81 -0
  14. package/src/terra-route.spec.ts +576 -0
  15. package/src/terra-route.ts +370 -154
  16. package/src/graph/graph.spec.ts +0 -238
  17. package/src/graph/graph.ts +0 -212
  18. package/src/graph/methods/bounding-box.spec.ts +0 -199
  19. package/src/graph/methods/bounding-box.ts +0 -85
  20. package/src/graph/methods/connected.spec.ts +0 -219
  21. package/src/graph/methods/connected.ts +0 -168
  22. package/src/graph/methods/duplicates.spec.ts +0 -161
  23. package/src/graph/methods/duplicates.ts +0 -117
  24. package/src/graph/methods/leaf.spec.ts +0 -224
  25. package/src/graph/methods/leaf.ts +0 -88
  26. package/src/graph/methods/nodes.spec.ts +0 -317
  27. package/src/graph/methods/nodes.ts +0 -77
  28. package/src/graph/methods/spatial-index/geokdbush.spec.ts +0 -86
  29. package/src/graph/methods/spatial-index/geokdbush.ts +0 -189
  30. package/src/graph/methods/spatial-index/kdbush.spec.ts +0 -67
  31. package/src/graph/methods/spatial-index/kdbush.ts +0 -189
  32. package/src/graph/methods/spatial-index/tinyqueue.spec.ts +0 -51
  33. package/src/graph/methods/spatial-index/tinyqueue.ts +0 -108
  34. package/src/graph/methods/unify.spec.ts +0 -475
  35. package/src/graph/methods/unify.ts +0 -132
  36. package/src/graph/methods/unique.spec.ts +0 -65
  37. 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
- }