terra-route 0.0.3 → 0.0.5
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 +26 -3
- package/dist/terra-route.cjs +1 -1
- package/dist/terra-route.cjs.map +1 -1
- package/dist/terra-route.d.ts +8 -4
- 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/eslint.config.mjs +54 -0
- package/package.json +88 -105
- package/src/min-heap.ts +37 -25
- package/src/terra-route.spec.ts +249 -14
- package/src/terra-route.ts +110 -55
- package/src/test-utils/test-utils.ts +369 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import typescriptEslint from "@typescript-eslint/eslint-plugin";
|
|
2
|
+
import tsParser from "@typescript-eslint/parser";
|
|
3
|
+
import eslintPluginPrettier from "eslint-plugin-prettier";
|
|
4
|
+
import prettierConfig from "eslint-config-prettier";
|
|
5
|
+
import json from "@eslint/json";
|
|
6
|
+
import markdown from "@eslint/markdown";
|
|
7
|
+
|
|
8
|
+
const ignores = ["**/node_modules", "**/dist", "**/docs", ".github", ".husky", ".vscode", "**/public", "**/coverage", "packages/e2e/playwright-report"];
|
|
9
|
+
|
|
10
|
+
export default [
|
|
11
|
+
{
|
|
12
|
+
ignores
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
files: ["**/*.json"],
|
|
16
|
+
language: "json/json",
|
|
17
|
+
plugins: {
|
|
18
|
+
json,
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
files: ["**/*.md"],
|
|
23
|
+
plugins: {
|
|
24
|
+
markdown
|
|
25
|
+
},
|
|
26
|
+
language: "markdown/commonmark",
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: "prettier", // Configuration name
|
|
30
|
+
files: ["**/*.{js,jsx,ts,tsx,json,md,yml,yaml,html,css}"],
|
|
31
|
+
ignores: ['**.json'],
|
|
32
|
+
plugins: {
|
|
33
|
+
prettier: eslintPluginPrettier, // Include Prettier plugin
|
|
34
|
+
},
|
|
35
|
+
rules: {
|
|
36
|
+
...prettierConfig.rules, // Disable ESLint rules that conflict with Prettier
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: "typescript", // Configuration name
|
|
41
|
+
files: ["**/*.ts"], // TypeScript-specific configuration
|
|
42
|
+
plugins: {
|
|
43
|
+
"@typescript-eslint": typescriptEslint, // Include TypeScript ESLint plugin
|
|
44
|
+
},
|
|
45
|
+
languageOptions: {
|
|
46
|
+
parser: tsParser,
|
|
47
|
+
},
|
|
48
|
+
rules: {
|
|
49
|
+
"@typescript-eslint/no-empty-function": "warn",
|
|
50
|
+
"@typescript-eslint/no-explicit-any": "warn",
|
|
51
|
+
"no-console": process.env.CI ? "error" : "warn",
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
];
|
package/package.json
CHANGED
|
@@ -1,110 +1,93 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
2
|
+
"name": "terra-route",
|
|
3
|
+
"version": "0.0.5",
|
|
4
|
+
"description": "A library for routing along GeoJSON LineString networks",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"docs": "typedoc",
|
|
7
|
+
"docs:serve": "serve ./docs",
|
|
8
|
+
"test": "jest",
|
|
9
|
+
"benchmark": "tsx benchmark/benchmark.ts",
|
|
10
|
+
"build": "microbundle",
|
|
11
|
+
"watch": "microbundle --watch --format modern",
|
|
12
|
+
"unused": "knip",
|
|
13
|
+
"lint": "eslint --config eslint.config.mjs",
|
|
14
|
+
"lint:quiet": "eslint --quiet --config eslint.config.mjs",
|
|
15
|
+
"lint:fix": "eslint --fix --config eslint.config.mjs",
|
|
16
|
+
"lint:fix:quiet": "eslint --fix --quiet --config eslint.config.mjs",
|
|
17
|
+
"format": "prettier --ignore-path .gitignore --write \"**/*.+(js|ts|json)\"",
|
|
18
|
+
"format:quiet": "prettier --ignore-path .gitignore --write \"**/*.+(js|ts|json)\" --log-level=silent"
|
|
19
|
+
},
|
|
20
|
+
"type": "module",
|
|
21
|
+
"source": "src/terra-route.ts",
|
|
22
|
+
"exports": {
|
|
23
|
+
"types": "./dist/terra-route.d.ts",
|
|
24
|
+
"require": "./dist/terra-route.cjs",
|
|
25
|
+
"default": "./dist/terra-route.modern.js"
|
|
26
|
+
},
|
|
21
27
|
"types": "./dist/terra-route.d.ts",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"typedoc": "^0.28.1",
|
|
48
|
-
"typescript": "^5.6.3"
|
|
49
|
-
},
|
|
50
|
-
"dependencies": {
|
|
51
|
-
"@turf/turf": "^7.1.0"
|
|
52
|
-
},
|
|
53
|
-
"keywords": [
|
|
54
|
-
"geojson",
|
|
55
|
-
"linestring",
|
|
56
|
-
"routing",
|
|
57
|
-
"pathfinding",
|
|
58
|
-
"network",
|
|
59
|
-
"geospatial",
|
|
60
|
-
"astar",
|
|
61
|
-
"djikstra"
|
|
62
|
-
],
|
|
63
|
-
"eslintConfig": {
|
|
64
|
-
"parser": "@typescript-eslint/parser",
|
|
65
|
-
"plugins": [
|
|
66
|
-
"@typescript-eslint"
|
|
67
|
-
],
|
|
68
|
-
"rules": {
|
|
69
|
-
"@typescript-eslint/no-empty-function": "warn",
|
|
70
|
-
"@typescript-eslint/no-explicit-any": "warn"
|
|
28
|
+
"main": "./dist/terra-route.cjs",
|
|
29
|
+
"module": "./dist/terra-route.module.js",
|
|
30
|
+
"unpkg": "./dist/terra-route.umd.js",
|
|
31
|
+
"author": "James Milner",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@eslint/json": "^0.11.0",
|
|
35
|
+
"@eslint/markdown": "^6.3.0",
|
|
36
|
+
"@types/jest": "^29.5.14",
|
|
37
|
+
"@types/lodash": "^4.17.13",
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "8.16.0",
|
|
39
|
+
"@typescript-eslint/parser": "8.16.0",
|
|
40
|
+
"eslint": "8.57.1",
|
|
41
|
+
"eslint-config-prettier": "9.1.0",
|
|
42
|
+
"eslint-plugin-prettier": "5.2.1",
|
|
43
|
+
"geojson": "^0.5.0",
|
|
44
|
+
"geojson-path-finder": "^2.0.2",
|
|
45
|
+
"jest": "^29.7.0",
|
|
46
|
+
"knip": "^5.38.1",
|
|
47
|
+
"microbundle": "0.15.1",
|
|
48
|
+
"serve": "^14.2.4",
|
|
49
|
+
"ts-jest": "^29.2.5",
|
|
50
|
+
"tsx": "^4.19.3",
|
|
51
|
+
"typedoc": "^0.28.1",
|
|
52
|
+
"typescript": "^5.8.3"
|
|
71
53
|
},
|
|
72
|
-
"
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
"knip": {
|
|
83
|
-
"$schema": "https://unpkg.com/knip@5/schema.json",
|
|
84
|
-
"entry": [
|
|
85
|
-
"src/terra-route.ts"
|
|
86
|
-
],
|
|
87
|
-
"project": [
|
|
88
|
-
"src/**/*.ts"
|
|
54
|
+
"dependencies": {},
|
|
55
|
+
"keywords": [
|
|
56
|
+
"geojson",
|
|
57
|
+
"linestring",
|
|
58
|
+
"routing",
|
|
59
|
+
"pathfinding",
|
|
60
|
+
"network",
|
|
61
|
+
"geospatial",
|
|
62
|
+
"astar",
|
|
63
|
+
"djikstra"
|
|
89
64
|
],
|
|
90
|
-
"
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
65
|
+
"knip": {
|
|
66
|
+
"$schema": "https://unpkg.com/knip@5/schema.json",
|
|
67
|
+
"entry": [
|
|
68
|
+
"src/terra-route.ts"
|
|
69
|
+
],
|
|
70
|
+
"project": [
|
|
71
|
+
"src/**/*.ts"
|
|
72
|
+
],
|
|
73
|
+
"include": [
|
|
74
|
+
"files",
|
|
75
|
+
"types"
|
|
76
|
+
]
|
|
77
|
+
},
|
|
78
|
+
"typedocOptions": {
|
|
79
|
+
"entryPoints": [
|
|
80
|
+
"src/terra-route.ts"
|
|
81
|
+
],
|
|
82
|
+
"excludeExternals": true,
|
|
83
|
+
"exclude": [
|
|
84
|
+
"benchmark/",
|
|
85
|
+
"coverage/",
|
|
86
|
+
"dist/",
|
|
87
|
+
"node_modules/"
|
|
88
|
+
],
|
|
89
|
+
"out": "docs",
|
|
90
|
+
"skipErrorChecking": true,
|
|
91
|
+
"sourceLinkExternal": true
|
|
92
|
+
}
|
|
110
93
|
}
|
package/src/min-heap.ts
CHANGED
|
@@ -38,38 +38,50 @@ export class MinHeap {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
private bubbleDown(idx: number): void {
|
|
41
|
-
const
|
|
42
|
-
const
|
|
41
|
+
const { heap } = this;
|
|
42
|
+
const length = heap.length;
|
|
43
|
+
// Grab the parent node once, then move it down only if needed
|
|
44
|
+
const node = heap[idx];
|
|
45
|
+
const nodeKey = node.key;
|
|
46
|
+
const nodeIndex = node.index;
|
|
43
47
|
|
|
44
48
|
while (true) {
|
|
49
|
+
// Calculate left and right child indexes
|
|
45
50
|
const leftIdx = (idx << 1) + 1;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (
|
|
50
|
-
leftIdx < length &&
|
|
51
|
-
(this.heap[leftIdx].key < this.heap[smallestIdx].key ||
|
|
52
|
-
(this.heap[leftIdx].key === this.heap[smallestIdx].key &&
|
|
53
|
-
this.heap[leftIdx].index < this.heap[smallestIdx].index))
|
|
54
|
-
) {
|
|
55
|
-
smallestIdx = leftIdx;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (
|
|
59
|
-
rightIdx < length &&
|
|
60
|
-
(this.heap[rightIdx].key < this.heap[smallestIdx].key ||
|
|
61
|
-
(this.heap[rightIdx].key === this.heap[smallestIdx].key &&
|
|
62
|
-
this.heap[rightIdx].index < this.heap[smallestIdx].index))
|
|
63
|
-
) {
|
|
64
|
-
smallestIdx = rightIdx;
|
|
51
|
+
if (leftIdx >= length) {
|
|
52
|
+
// No children => we’re already in place
|
|
53
|
+
break;
|
|
65
54
|
}
|
|
66
55
|
|
|
67
|
-
|
|
56
|
+
// Assume left child is the smaller one by default
|
|
57
|
+
let smallestIdx = leftIdx;
|
|
58
|
+
let smallestKey = heap[leftIdx].key;
|
|
59
|
+
let smallestIndex = heap[leftIdx].index;
|
|
68
60
|
|
|
69
|
-
|
|
70
|
-
|
|
61
|
+
const rightIdx = leftIdx + 1;
|
|
62
|
+
if (rightIdx < length) {
|
|
63
|
+
// Compare left child vs. right child
|
|
64
|
+
const rightKey = heap[rightIdx].key;
|
|
65
|
+
const rightIndex = heap[rightIdx].index;
|
|
66
|
+
if (rightKey < smallestKey || (rightKey === smallestKey && rightIndex < smallestIndex)) {
|
|
67
|
+
smallestIdx = rightIdx;
|
|
68
|
+
smallestKey = rightKey;
|
|
69
|
+
smallestIndex = rightIndex;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
71
72
|
|
|
72
|
-
|
|
73
|
+
// Compare the smaller child with the parent
|
|
74
|
+
if (smallestKey < nodeKey || (smallestKey === nodeKey && smallestIndex < nodeIndex)) {
|
|
75
|
+
// Swap the smaller child up
|
|
76
|
+
heap[idx] = heap[smallestIdx];
|
|
77
|
+
idx = smallestIdx;
|
|
78
|
+
} else {
|
|
79
|
+
// We’re in the correct position now, so stop
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
73
82
|
}
|
|
83
|
+
|
|
84
|
+
// Place the original node in its final position
|
|
85
|
+
heap[idx] = node;
|
|
74
86
|
}
|
|
75
87
|
}
|