@osmix/router 0.0.4 → 0.0.6

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.
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Routing graph construction from OSM data.
3
+ *
4
+ * Builds a directed graph from OSM ways suitable for pathfinding. Edges are
5
+ * created between consecutive nodes in each way, with pre-computed distance
6
+ * and time costs. Respects one-way restrictions.
7
+ *
8
+ * Uses CSR (Compressed Sparse Row) format for efficient storage and
9
+ * zero-copy transfer between workers via SharedArrayBuffer.
10
+ *
11
+ * @module
12
+ */
13
+ import { type Osm } from "@osmix/core";
14
+ import type { LonLat } from "@osmix/shared/types";
15
+ import type { DefaultSpeeds, GraphEdge, HighwayFilter, RoutingGraphTransferables } from "./types";
16
+ /**
17
+ * Routing graph built from OSM ways and nodes.
18
+ *
19
+ * Uses CSR (Compressed Sparse Row) format internally for memory efficiency
20
+ * and zero-copy transfer between workers.
21
+ *
22
+ * @example Build from OSM data
23
+ * ```ts
24
+ * const graph = new RoutingGraph(osm)
25
+ * const route = router.route(graph, startNode, endNode)
26
+ * ```
27
+ *
28
+ * @example Transfer between workers
29
+ * ```ts
30
+ * // In source worker
31
+ * const buffers = graph.transferables()
32
+ * Comlink.transfer(buffers, getTransferableBuffers(buffers))
33
+ *
34
+ * // In target worker
35
+ * const graph = new RoutingGraph(buffers)
36
+ * ```
37
+ */
38
+ export declare class RoutingGraph {
39
+ /** Total number of nodes in the source OSM data. */
40
+ private nodeCount;
41
+ /** Total number of edges in the graph. */
42
+ private edgeCount;
43
+ private edgeOffsets;
44
+ private edgeTargets;
45
+ private edgeWayIndexes;
46
+ private edgeDistances;
47
+ private edgeTimes;
48
+ private routableBits;
49
+ private intersectionBits;
50
+ readonly filter: HighwayFilter;
51
+ readonly defaultSpeeds: DefaultSpeeds;
52
+ /**
53
+ * Create a RoutingGraph.
54
+ *
55
+ * @param source - Either an Osm instance to build from, or RoutingGraphTransferables to reconstruct.
56
+ * @param filter - Function to determine which ways are routable (only used when building from Osm).
57
+ * @param defaultSpeeds - Speed limits by highway type (only used when building from Osm).
58
+ */
59
+ constructor(source: Osm | RoutingGraphTransferables, filter?: HighwayFilter, defaultSpeeds?: DefaultSpeeds);
60
+ /**
61
+ * Reconstruct from transferables (worker transfer).
62
+ */
63
+ private fromTransferables;
64
+ /**
65
+ * Build the graph from OSM data.
66
+ */
67
+ private buildFromOsm;
68
+ /**
69
+ * Check if a node is part of the routable network.
70
+ */
71
+ isRoutable(nodeIndex: number): boolean;
72
+ /**
73
+ * Check if a node is an intersection (multiple ways meet).
74
+ */
75
+ isIntersection(nodeIndex: number): boolean;
76
+ /**
77
+ * Get outgoing edges from a node.
78
+ */
79
+ getEdges(nodeIndex: number): GraphEdge[];
80
+ /**
81
+ * Get transferable buffers for passing to another thread.
82
+ */
83
+ transferables(): RoutingGraphTransferables;
84
+ /**
85
+ * Get the number of nodes in the graph.
86
+ */
87
+ get size(): number;
88
+ /**
89
+ * Get the number of edges in the graph.
90
+ */
91
+ get edges(): number;
92
+ /**
93
+ * Find the nearest routable OSM node from a geographic point.
94
+ *
95
+ * Searches for nodes within the given radius that are part of the routing
96
+ * graph (i.e., lie on a routable way). Returns the closest match with its
97
+ * coordinates and distance.
98
+ *
99
+ * @param osm - The OSM dataset.
100
+ * @param point - The [lon, lat] coordinates to search from.
101
+ * @param maxDistanceM - Maximum search radius in meters.
102
+ * @returns The nearest routable node, or null if none found.
103
+ *
104
+ * @example
105
+ * ```ts
106
+ * const nearest = graph.findNearestNodeOnGraph(osm, [-73.989, 40.733], 0.5)
107
+ * if (nearest) {
108
+ * console.log(`Found node ${nearest.nodeIndex} at ${nearest.distance}m`)
109
+ * }
110
+ * ```
111
+ */
112
+ findNearestRoutableNode(osm: Osm, point: LonLat, maxDistanceM: number): {
113
+ nodeIndex: number;
114
+ coordinates: LonLat;
115
+ distance: number;
116
+ } | null;
117
+ }
118
+ /**
119
+ * Build a routing graph from OSM ways.
120
+ *
121
+ * Convenience function that creates a RoutingGraph.
122
+ *
123
+ * @param osm - The OSM dataset to build from.
124
+ * @param filter - Function to determine which ways are routable.
125
+ * @param defaultSpeeds - Speed limits (km/h) by highway type.
126
+ * @returns A RoutingGraph ready for pathfinding.
127
+ */
128
+ export declare function buildGraph(osm: Osm, filter?: HighwayFilter, defaultSpeeds?: DefaultSpeeds): RoutingGraph;
129
+ /**
130
+ * Get an array of buffers suitable for Comlink.transfer() or postMessage transfer list.
131
+ * Note: SharedArrayBuffers don't need to be transferred (they're shared automatically),
132
+ * but ArrayBuffers do. This returns only the ArrayBuffers that need explicit transfer.
133
+ */
134
+ export declare function getTransferableBuffers(t: RoutingGraphTransferables): ArrayBuffer[];
135
+ //# sourceMappingURL=graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../src/graph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAsC,KAAK,GAAG,EAAE,MAAM,aAAa,CAAA;AAE1E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,KAAK,EACX,aAAa,EACb,SAAS,EACT,aAAa,EACb,yBAAyB,EACzB,MAAM,SAAS,CAAA;AAGhB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,YAAY;IACxB,oDAAoD;IACpD,OAAO,CAAC,SAAS,CAAI;IACrB,0CAA0C;IAC1C,OAAO,CAAC,SAAS,CAAI;IAGrB,OAAO,CAAC,WAAW,CAA2B;IAC9C,OAAO,CAAC,WAAW,CAA2B;IAC9C,OAAO,CAAC,cAAc,CAA2B;IACjD,OAAO,CAAC,aAAa,CAA4B;IACjD,OAAO,CAAC,SAAS,CAA4B;IAC7C,OAAO,CAAC,YAAY,CAA0B;IAC9C,OAAO,CAAC,gBAAgB,CAA0B;IAGlD,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAA;IAC9B,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAA;IAErC;;;;;;OAMG;gBAEF,MAAM,EAAE,GAAG,GAAG,yBAAyB,EACvC,MAAM,GAAE,aAAoC,EAC5C,aAAa,GAAE,aAA8B;IAa9C;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAYzB;;OAEG;IACH,OAAO,CAAC,YAAY;IA0IpB;;OAEG;IACH,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;IAOtC;;OAEG;IACH,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;IAO1C;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,EAAE;IA0BxC;;OAEG;IACH,aAAa,IAAI,yBAAyB;IAc1C;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,uBAAuB,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;mBAQxD,MAAM;qBACJ,MAAM;kBACT,MAAM;;CAiBlB;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CACzB,GAAG,EAAE,GAAG,EACR,MAAM,GAAE,aAAoC,EAC5C,aAAa,GAAE,aAA8B,GAC3C,YAAY,CAEd;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CACrC,CAAC,EAAE,yBAAyB,GAC1B,WAAW,EAAE,CAef"}
package/dist/graph.js ADDED
@@ -0,0 +1,339 @@
1
+ /**
2
+ * Routing graph construction from OSM data.
3
+ *
4
+ * Builds a directed graph from OSM ways suitable for pathfinding. Edges are
5
+ * created between consecutive nodes in each way, with pre-computed distance
6
+ * and time costs. Respects one-way restrictions.
7
+ *
8
+ * Uses CSR (Compressed Sparse Row) format for efficient storage and
9
+ * zero-copy transfer between workers via SharedArrayBuffer.
10
+ *
11
+ * @module
12
+ */
13
+ import { BufferConstructor } from "@osmix/core";
14
+ import { haversineDistance } from "@osmix/shared/haversine-distance";
15
+ import { DEFAULT_SPEEDS, defaultHighwayFilter, getSpeedLimit } from "./utils";
16
+ /**
17
+ * Routing graph built from OSM ways and nodes.
18
+ *
19
+ * Uses CSR (Compressed Sparse Row) format internally for memory efficiency
20
+ * and zero-copy transfer between workers.
21
+ *
22
+ * @example Build from OSM data
23
+ * ```ts
24
+ * const graph = new RoutingGraph(osm)
25
+ * const route = router.route(graph, startNode, endNode)
26
+ * ```
27
+ *
28
+ * @example Transfer between workers
29
+ * ```ts
30
+ * // In source worker
31
+ * const buffers = graph.transferables()
32
+ * Comlink.transfer(buffers, getTransferableBuffers(buffers))
33
+ *
34
+ * // In target worker
35
+ * const graph = new RoutingGraph(buffers)
36
+ * ```
37
+ */
38
+ export class RoutingGraph {
39
+ /** Total number of nodes in the source OSM data. */
40
+ nodeCount = 0;
41
+ /** Total number of edges in the graph. */
42
+ edgeCount = 0;
43
+ // CSR format arrays (populated after compact())
44
+ edgeOffsets = null;
45
+ edgeTargets = null;
46
+ edgeWayIndexes = null;
47
+ edgeDistances = null;
48
+ edgeTimes = null;
49
+ routableBits = null;
50
+ intersectionBits = null;
51
+ // Expose highway filter and default speeds
52
+ filter;
53
+ defaultSpeeds;
54
+ /**
55
+ * Create a RoutingGraph.
56
+ *
57
+ * @param source - Either an Osm instance to build from, or RoutingGraphTransferables to reconstruct.
58
+ * @param filter - Function to determine which ways are routable (only used when building from Osm).
59
+ * @param defaultSpeeds - Speed limits by highway type (only used when building from Osm).
60
+ */
61
+ constructor(source, filter = defaultHighwayFilter, defaultSpeeds = DEFAULT_SPEEDS) {
62
+ this.filter = filter;
63
+ this.defaultSpeeds = defaultSpeeds;
64
+ if ("nodeCount" in source) {
65
+ // Reconstruct from transferables
66
+ this.fromTransferables(source);
67
+ }
68
+ else {
69
+ // Build from OSM data
70
+ this.buildFromOsm(source, filter, defaultSpeeds);
71
+ }
72
+ }
73
+ /**
74
+ * Reconstruct from transferables (worker transfer).
75
+ */
76
+ fromTransferables(t) {
77
+ this.nodeCount = t.nodeCount;
78
+ this.edgeCount = t.edgeCount;
79
+ this.edgeOffsets = new Uint32Array(t.edgeOffsets);
80
+ this.edgeTargets = new Uint32Array(t.edgeTargets);
81
+ this.edgeWayIndexes = new Uint32Array(t.edgeWayIndexes);
82
+ this.edgeDistances = new Float32Array(t.edgeDistances);
83
+ this.edgeTimes = new Float32Array(t.edgeTimes);
84
+ this.routableBits = new Uint8Array(t.routableBits);
85
+ this.intersectionBits = new Uint8Array(t.intersectionBits);
86
+ }
87
+ /**
88
+ * Build the graph from OSM data.
89
+ */
90
+ buildFromOsm(osm, filter, defaultSpeeds) {
91
+ this.nodeCount = osm.nodes.size;
92
+ const tempEdges = new Map();
93
+ const tempRoutable = new Set();
94
+ const tempIntersections = new Set();
95
+ const addEdgeToNode = (from, edge) => {
96
+ let nodeEdges = tempEdges.get(from);
97
+ if (!nodeEdges) {
98
+ nodeEdges = [];
99
+ tempEdges.set(from, nodeEdges);
100
+ }
101
+ nodeEdges.push(edge);
102
+ };
103
+ for (let wayIndex = 0; wayIndex < osm.ways.size; wayIndex++) {
104
+ const tags = osm.ways.tags.getTags(wayIndex);
105
+ if (!filter(tags))
106
+ continue;
107
+ const refs = osm.ways.getRefIds(wayIndex);
108
+ if (refs.length < 2)
109
+ continue;
110
+ // Create bidirectional edges between consecutive nodes (respecting one-way)
111
+ const oneway = tags?.["oneway"] === "yes" || tags?.["oneway"] === "1";
112
+ const speedKph = getSpeedLimit(tags, defaultSpeeds);
113
+ const speedMps = (speedKph * 1_000) / 60 / 60;
114
+ const nodes = refs.map((ref) => osm.nodes.ids.getIndexFromId(ref));
115
+ for (let i = 0; i < nodes.length - 1; i++) {
116
+ const nodeIndex = nodes[i];
117
+ const targetNodeIndex = nodes[i + 1];
118
+ const fromCoord = osm.nodes.getNodeLonLat({ index: nodeIndex });
119
+ const targetCoord = osm.nodes.getNodeLonLat({ index: targetNodeIndex });
120
+ const distanceM = haversineDistance(fromCoord, targetCoord);
121
+ const time = distanceM / speedMps;
122
+ // Forward edge
123
+ addEdgeToNode(nodeIndex, {
124
+ targetNodeIndex: targetNodeIndex,
125
+ wayIndex,
126
+ distance: distanceM,
127
+ time,
128
+ });
129
+ this.edgeCount++;
130
+ // Reverse edge (unless one-way)
131
+ if (!oneway) {
132
+ addEdgeToNode(targetNodeIndex, {
133
+ targetNodeIndex: nodeIndex,
134
+ wayIndex,
135
+ distance: distanceM,
136
+ time,
137
+ });
138
+ this.edgeCount++;
139
+ }
140
+ // Track routable nodes and intersections (nodes appearing in multiple ways)
141
+ if (tempRoutable.has(nodeIndex)) {
142
+ tempIntersections.add(nodeIndex);
143
+ }
144
+ else {
145
+ tempRoutable.add(nodeIndex);
146
+ }
147
+ if (tempRoutable.has(targetNodeIndex)) {
148
+ tempIntersections.add(targetNodeIndex);
149
+ }
150
+ else {
151
+ tempRoutable.add(targetNodeIndex);
152
+ }
153
+ }
154
+ }
155
+ // Convert to CSR format and free temporary structures
156
+ // Allocate CSR arrays
157
+ const offsetsBuffer = new BufferConstructor((this.nodeCount + 1) * Uint32Array.BYTES_PER_ELEMENT);
158
+ const targetsBuffer = new BufferConstructor(this.edgeCount * Uint32Array.BYTES_PER_ELEMENT);
159
+ const wayIndexesBuffer = new BufferConstructor(this.edgeCount * Uint32Array.BYTES_PER_ELEMENT);
160
+ const distancesBuffer = new BufferConstructor(this.edgeCount * Float32Array.BYTES_PER_ELEMENT);
161
+ const timesBuffer = new BufferConstructor(this.edgeCount * Float32Array.BYTES_PER_ELEMENT);
162
+ this.edgeOffsets = new Uint32Array(offsetsBuffer);
163
+ this.edgeTargets = new Uint32Array(targetsBuffer);
164
+ this.edgeWayIndexes = new Uint32Array(wayIndexesBuffer);
165
+ this.edgeDistances = new Float32Array(distancesBuffer);
166
+ this.edgeTimes = new Float32Array(timesBuffer);
167
+ // Build CSR format: iterate through all nodes in order
168
+ let edgeIndex = 0;
169
+ for (let nodeIndex = 0; nodeIndex < this.nodeCount; nodeIndex++) {
170
+ this.edgeOffsets[nodeIndex] = edgeIndex;
171
+ const edges = tempEdges.get(nodeIndex);
172
+ if (edges) {
173
+ for (const edge of edges) {
174
+ this.edgeTargets[edgeIndex] = edge.targetNodeIndex;
175
+ this.edgeWayIndexes[edgeIndex] = edge.wayIndex;
176
+ this.edgeDistances[edgeIndex] = edge.distance;
177
+ this.edgeTimes[edgeIndex] = edge.time;
178
+ edgeIndex++;
179
+ }
180
+ }
181
+ }
182
+ this.edgeOffsets[this.nodeCount] = edgeIndex;
183
+ // Build bitsets for routable and intersection flags
184
+ const bitsetLength = Math.ceil(this.nodeCount / 8);
185
+ const routableBuffer = new BufferConstructor(bitsetLength);
186
+ const intersectionBuffer = new BufferConstructor(bitsetLength);
187
+ this.routableBits = new Uint8Array(routableBuffer);
188
+ this.intersectionBits = new Uint8Array(intersectionBuffer);
189
+ for (const nodeIndex of tempRoutable) {
190
+ const byteIndex = nodeIndex >> 3;
191
+ const bitMask = 1 << (nodeIndex & 7);
192
+ this.routableBits[byteIndex] |= bitMask;
193
+ }
194
+ for (const nodeIndex of tempIntersections) {
195
+ const byteIndex = nodeIndex >> 3;
196
+ const bitMask = 1 << (nodeIndex & 7);
197
+ this.intersectionBits[byteIndex] |= bitMask;
198
+ }
199
+ }
200
+ /**
201
+ * Check if a node is part of the routable network.
202
+ */
203
+ isRoutable(nodeIndex) {
204
+ if (nodeIndex < 0 || nodeIndex >= this.nodeCount)
205
+ return false;
206
+ const byteIndex = nodeIndex >> 3;
207
+ const bitMask = 1 << (nodeIndex & 7);
208
+ return (this.routableBits[byteIndex] & bitMask) !== 0;
209
+ }
210
+ /**
211
+ * Check if a node is an intersection (multiple ways meet).
212
+ */
213
+ isIntersection(nodeIndex) {
214
+ if (nodeIndex < 0 || nodeIndex >= this.nodeCount)
215
+ return false;
216
+ const byteIndex = nodeIndex >> 3;
217
+ const bitMask = 1 << (nodeIndex & 7);
218
+ return (this.intersectionBits[byteIndex] & bitMask) !== 0;
219
+ }
220
+ /**
221
+ * Get outgoing edges from a node.
222
+ */
223
+ getEdges(nodeIndex) {
224
+ if (nodeIndex < 0 ||
225
+ nodeIndex >= this.nodeCount ||
226
+ !this.edgeOffsets ||
227
+ !this.edgeTargets) {
228
+ return [];
229
+ }
230
+ const start = this.edgeOffsets[nodeIndex];
231
+ const end = this.edgeOffsets[nodeIndex + 1];
232
+ const edges = [];
233
+ for (let i = start; i < end; i++) {
234
+ edges.push({
235
+ targetNodeIndex: this.edgeTargets[i],
236
+ wayIndex: this.edgeWayIndexes[i],
237
+ distance: this.edgeDistances[i],
238
+ time: this.edgeTimes[i],
239
+ });
240
+ }
241
+ return edges;
242
+ }
243
+ /**
244
+ * Get transferable buffers for passing to another thread.
245
+ */
246
+ transferables() {
247
+ return {
248
+ nodeCount: this.nodeCount,
249
+ edgeCount: this.edgeCount,
250
+ edgeOffsets: this.edgeOffsets.buffer,
251
+ edgeTargets: this.edgeTargets.buffer,
252
+ edgeWayIndexes: this.edgeWayIndexes.buffer,
253
+ edgeDistances: this.edgeDistances.buffer,
254
+ edgeTimes: this.edgeTimes.buffer,
255
+ routableBits: this.routableBits.buffer,
256
+ intersectionBits: this.intersectionBits.buffer,
257
+ };
258
+ }
259
+ /**
260
+ * Get the number of nodes in the graph.
261
+ */
262
+ get size() {
263
+ return this.nodeCount;
264
+ }
265
+ /**
266
+ * Get the number of edges in the graph.
267
+ */
268
+ get edges() {
269
+ return this.edgeCount;
270
+ }
271
+ /**
272
+ * Find the nearest routable OSM node from a geographic point.
273
+ *
274
+ * Searches for nodes within the given radius that are part of the routing
275
+ * graph (i.e., lie on a routable way). Returns the closest match with its
276
+ * coordinates and distance.
277
+ *
278
+ * @param osm - The OSM dataset.
279
+ * @param point - The [lon, lat] coordinates to search from.
280
+ * @param maxDistanceM - Maximum search radius in meters.
281
+ * @returns The nearest routable node, or null if none found.
282
+ *
283
+ * @example
284
+ * ```ts
285
+ * const nearest = graph.findNearestNodeOnGraph(osm, [-73.989, 40.733], 0.5)
286
+ * if (nearest) {
287
+ * console.log(`Found node ${nearest.nodeIndex} at ${nearest.distance}m`)
288
+ * }
289
+ * ```
290
+ */
291
+ findNearestRoutableNode(osm, point, maxDistanceM) {
292
+ const nearby = osm.nodes.findIndexesWithinRadius(point[0], point[1], maxDistanceM / 1_000);
293
+ let best = null;
294
+ let bestDistM = Number.POSITIVE_INFINITY;
295
+ for (const nodeIndex of nearby) {
296
+ if (!this.isRoutable(nodeIndex))
297
+ continue;
298
+ const nodeCoord = osm.nodes.getNodeLonLat({ index: nodeIndex });
299
+ const distance = haversineDistance(point, nodeCoord);
300
+ if (distance < bestDistM && distance <= maxDistanceM) {
301
+ bestDistM = distance;
302
+ best = { nodeIndex, coordinates: nodeCoord, distance };
303
+ }
304
+ }
305
+ return best;
306
+ }
307
+ }
308
+ /**
309
+ * Build a routing graph from OSM ways.
310
+ *
311
+ * Convenience function that creates a RoutingGraph.
312
+ *
313
+ * @param osm - The OSM dataset to build from.
314
+ * @param filter - Function to determine which ways are routable.
315
+ * @param defaultSpeeds - Speed limits (km/h) by highway type.
316
+ * @returns A RoutingGraph ready for pathfinding.
317
+ */
318
+ export function buildGraph(osm, filter = defaultHighwayFilter, defaultSpeeds = DEFAULT_SPEEDS) {
319
+ return new RoutingGraph(osm, filter, defaultSpeeds);
320
+ }
321
+ /**
322
+ * Get an array of buffers suitable for Comlink.transfer() or postMessage transfer list.
323
+ * Note: SharedArrayBuffers don't need to be transferred (they're shared automatically),
324
+ * but ArrayBuffers do. This returns only the ArrayBuffers that need explicit transfer.
325
+ */
326
+ export function getTransferableBuffers(t) {
327
+ const buffers = [
328
+ t.edgeOffsets,
329
+ t.edgeTargets,
330
+ t.edgeWayIndexes,
331
+ t.edgeDistances,
332
+ t.edgeTimes,
333
+ t.routableBits,
334
+ t.intersectionBits,
335
+ ];
336
+ // Only ArrayBuffers need to be transferred; SharedArrayBuffers are shared automatically
337
+ return buffers.filter((b) => b instanceof ArrayBuffer && !(b instanceof SharedArrayBuffer));
338
+ }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CAAC,SAAS,CAAC;gBAAE,SAAQ;YAEzC,MAAM,SAAS,GAAG,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAA;YAC/D,MAAM,QAAQ,GAAG,iBAAiB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;YACpD,IAAI,QAAQ,GAAG,SAAS,IAAI,QAAQ,IAAI,YAAY,EAAE,CAAC;gBACtD,SAAS,GAAG,QAAQ,CAAA;gBACpB,IAAI,GAAG,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAA;YACvD,CAAC;QACF,CAAC;QAED,OAAO,IAAI,CAAA;IACZ,CAAC;CACD;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,UAAU,CACzB,GAAQ,EACR,SAAwB,oBAAoB,EAC5C,gBAA+B,cAAc;IAE7C,OAAO,IAAI,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,aAAa,CAAC,CAAA;AACpD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CACrC,CAA4B;IAE5B,MAAM,OAAO,GAAG;QACf,CAAC,CAAC,WAAW;QACb,CAAC,CAAC,WAAW;QACb,CAAC,CAAC,cAAc;QAChB,CAAC,CAAC,aAAa;QACf,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,YAAY;QACd,CAAC,CAAC,gBAAgB;KAClB,CAAA;IACD,wFAAwF;IACxF,OAAO,OAAO,CAAC,MAAM,CACpB,CAAC,CAAC,EAAoB,EAAE,CACvB,CAAC,YAAY,WAAW,IAAI,CAAC,CAAC,CAAC,YAAY,iBAAiB,CAAC,CAC9D,CAAA;AACF,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @osmix/router - Pathfinding on OSM road networks.
3
+ *
4
+ * Builds a routeable graph from OSM ways and provides pathfinding algorithms
5
+ * (Dijkstra, A*, bidirectional) for finding routes between nodes. Supports
6
+ * both distance and time-based routing.
7
+ *
8
+ * Key features:
9
+ * - **Graph construction**: Build routing graphs from OSM ways with highway filtering.
10
+ * - **Multiple algorithms**: Dijkstra, A*, and bidirectional search.
11
+ * - **Time-based routing**: Uses maxspeed tags and default speeds by highway type.
12
+ * - **One-way support**: Respects oneway=yes/1 tags.
13
+ * - **Snapping**: Find nearest routable node from arbitrary coordinates.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { buildGraph, Router, findNearestNodeOnGraph } from "@osmix/router"
18
+ *
19
+ * const graph = buildGraph(osm)
20
+ * const router = new Router(osm, graph)
21
+ *
22
+ * const start = findNearestNodeOnGraph(osm, graph, [-73.989, 40.733], 1)
23
+ * const end = findNearestNodeOnGraph(osm, graph, [-73.988, 40.734], 1)
24
+ *
25
+ * if (start && end) {
26
+ * const path = router.route(start.nodeIndex, end.nodeIndex)
27
+ * if (path) {
28
+ * const result = router.buildResult(path)
29
+ * console.log(result.coordinates)
30
+ * }
31
+ * }
32
+ * ```
33
+ *
34
+ * @module @osmix/router
35
+ */
36
+ export * from "./algorithms";
37
+ export * from "./graph";
38
+ export * from "./router";
39
+ export * from "./types";
40
+ export * from "./utils";
41
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,cAAc,cAAc,CAAA;AAC5B,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @osmix/router - Pathfinding on OSM road networks.
3
+ *
4
+ * Builds a routeable graph from OSM ways and provides pathfinding algorithms
5
+ * (Dijkstra, A*, bidirectional) for finding routes between nodes. Supports
6
+ * both distance and time-based routing.
7
+ *
8
+ * Key features:
9
+ * - **Graph construction**: Build routing graphs from OSM ways with highway filtering.
10
+ * - **Multiple algorithms**: Dijkstra, A*, and bidirectional search.
11
+ * - **Time-based routing**: Uses maxspeed tags and default speeds by highway type.
12
+ * - **One-way support**: Respects oneway=yes/1 tags.
13
+ * - **Snapping**: Find nearest routable node from arbitrary coordinates.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { buildGraph, Router, findNearestNodeOnGraph } from "@osmix/router"
18
+ *
19
+ * const graph = buildGraph(osm)
20
+ * const router = new Router(osm, graph)
21
+ *
22
+ * const start = findNearestNodeOnGraph(osm, graph, [-73.989, 40.733], 1)
23
+ * const end = findNearestNodeOnGraph(osm, graph, [-73.988, 40.734], 1)
24
+ *
25
+ * if (start && end) {
26
+ * const path = router.route(start.nodeIndex, end.nodeIndex)
27
+ * if (path) {
28
+ * const result = router.buildResult(path)
29
+ * console.log(result.coordinates)
30
+ * }
31
+ * }
32
+ * ```
33
+ *
34
+ * @module @osmix/router
35
+ */
36
+ export * from "./algorithms";
37
+ export * from "./graph";
38
+ export * from "./router";
39
+ export * from "./types";
40
+ export * from "./utils";
41
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,cAAc,cAAc,CAAA;AAC5B,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * High-level router API.
3
+ *
4
+ * Wraps the routing graph and algorithms to provide a convenient interface
5
+ * for finding routes and building result objects with coordinates.
6
+ *
7
+ * @module
8
+ */
9
+ import type { Osm } from "@osmix/core";
10
+ import type { RoutingGraph } from "./graph";
11
+ import type { PathSegment, RouteOptions, RoutePathInfo, RouteResult, RouteStatistics } from "./types";
12
+ /**
13
+ * Router for finding paths through OSM road networks.
14
+ *
15
+ * Uses pathfinding algorithms (Dijkstra, A*, or bidirectional) to find
16
+ * routes between node indexes. Use `findNearestNodeOnGraph()` to snap
17
+ * arbitrary coordinates to routable nodes before calling `route()`.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * const router = new Router(osm, graph, { algorithm: "astar" })
22
+ * const path = router.route(startNodeIndex, endNodeIndex)
23
+ * if (path) {
24
+ * const result = router.buildResult(path)
25
+ * console.log(result.coordinates)
26
+ * }
27
+ * ```
28
+ */
29
+ export declare class Router {
30
+ readonly graph: RoutingGraph;
31
+ readonly osm: Osm;
32
+ private readonly defaults;
33
+ constructor(osm: Osm, graph: RoutingGraph, options?: Partial<RouteOptions>);
34
+ /**
35
+ * Find a route between two node indexes.
36
+ * Returns path segments or null if no path exists.
37
+ */
38
+ route(fromNodeIndex: number, toNodeIndex: number, options?: Partial<RouteOptions>): PathSegment[] | null;
39
+ /** Build route result with coordinates from path segments. */
40
+ buildResult(path: PathSegment[], options?: Partial<RouteOptions>): RouteResult;
41
+ /**
42
+ * Calculate route statistics (distance and time) from path segments.
43
+ * @param path - Path segments from route().
44
+ * @returns Total distance in meters and time in seconds.
45
+ */
46
+ getRouteStatistics(path: PathSegment[]): RouteStatistics;
47
+ /**
48
+ * Build route path info (segments and turn points) from path segments.
49
+ * Consecutive ways with the same name are merged into a single segment.
50
+ * @param path - Path segments from route().
51
+ * @returns Segments with per-way breakdown and turn point coordinates.
52
+ */
53
+ getRoutePathInfo(path: PathSegment[]): RoutePathInfo;
54
+ }
55
+ //# sourceMappingURL=router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AAGtC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,KAAK,EACX,WAAW,EACX,YAAY,EACZ,aAAa,EACb,WAAW,EACX,eAAe,EAEf,MAAM,SAAS,CAAA;AAEhB;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,MAAM;IAClB,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAA;IAC5B,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAA;IACjB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwB;gBAGhD,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,YAAY,EACnB,OAAO,GAAE,OAAO,CAAC,YAAY,CAAM;IAYpC;;;OAGG;IACH,KAAK,CACJ,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,EACnB,OAAO,GAAE,OAAO,CAAC,YAAY,CAAM,GACjC,WAAW,EAAE,GAAG,IAAI;IAmBvB,8DAA8D;IAC9D,WAAW,CACV,IAAI,EAAE,WAAW,EAAE,EACnB,OAAO,GAAE,OAAO,CAAC,YAAY,CAAM,GACjC,WAAW;IAsDd;;;;OAIG;IACH,kBAAkB,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,eAAe;IAqBxD;;;;;OAKG;IACH,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,aAAa;CAqFpD"}