@rxflow/manhattan 0.0.2 → 0.0.3
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/cjs/geometry/Line.d.ts +21 -0
- package/cjs/geometry/Line.d.ts.map +1 -0
- package/cjs/geometry/Line.js +88 -0
- package/cjs/geometry/Point.d.ts +49 -0
- package/cjs/geometry/Point.d.ts.map +1 -0
- package/cjs/geometry/Point.js +94 -0
- package/cjs/geometry/Rectangle.d.ts +41 -0
- package/cjs/geometry/Rectangle.d.ts.map +1 -0
- package/cjs/geometry/Rectangle.js +65 -0
- package/cjs/geometry/collision.d.ts +15 -0
- package/cjs/geometry/collision.d.ts.map +1 -0
- package/cjs/geometry/collision.js +81 -0
- package/cjs/geometry/index.d.ts +5 -0
- package/cjs/geometry/index.d.ts.map +1 -0
- package/cjs/geometry/index.js +45 -0
- package/cjs/getManHattanPath.d.ts +53 -0
- package/cjs/getManHattanPath.d.ts.map +1 -0
- package/cjs/getManHattanPath.js +449 -0
- package/cjs/index.d.ts +16 -0
- package/cjs/index.d.ts.map +1 -0
- package/cjs/index.js +117 -0
- package/cjs/obstacle/ObstacleMap.d.ts +66 -0
- package/cjs/obstacle/ObstacleMap.d.ts.map +1 -0
- package/cjs/obstacle/ObstacleMap.js +328 -0
- package/cjs/obstacle/QuadTree.d.ts +119 -0
- package/cjs/obstacle/QuadTree.d.ts.map +1 -0
- package/cjs/obstacle/QuadTree.js +334 -0
- package/cjs/obstacle/index.d.ts +2 -0
- package/cjs/obstacle/index.d.ts.map +1 -0
- package/cjs/obstacle/index.js +12 -0
- package/cjs/options/defaults.d.ts +16 -0
- package/cjs/options/defaults.d.ts.map +1 -0
- package/cjs/options/defaults.js +39 -0
- package/cjs/options/index.d.ts +4 -0
- package/cjs/options/index.d.ts.map +1 -0
- package/cjs/options/index.js +38 -0
- package/cjs/options/resolver.d.ts +10 -0
- package/cjs/options/resolver.d.ts.map +1 -0
- package/cjs/options/resolver.js +248 -0
- package/cjs/options/types.d.ts +210 -0
- package/cjs/options/types.d.ts.map +1 -0
- package/cjs/options/types.js +5 -0
- package/cjs/pathfinder/PathCache.d.ts +92 -0
- package/cjs/pathfinder/PathCache.d.ts.map +1 -0
- package/cjs/pathfinder/PathCache.js +249 -0
- package/cjs/pathfinder/SortedSet.d.ts +35 -0
- package/cjs/pathfinder/SortedSet.d.ts.map +1 -0
- package/cjs/pathfinder/SortedSet.js +95 -0
- package/cjs/pathfinder/findRoute.d.ts +8 -0
- package/cjs/pathfinder/findRoute.d.ts.map +1 -0
- package/cjs/pathfinder/findRoute.js +395 -0
- package/cjs/pathfinder/index.d.ts +4 -0
- package/cjs/pathfinder/index.d.ts.map +1 -0
- package/cjs/pathfinder/index.js +44 -0
- package/cjs/svg/index.d.ts +3 -0
- package/cjs/svg/index.d.ts.map +1 -0
- package/cjs/svg/index.js +31 -0
- package/cjs/svg/pathConverter.d.ts +23 -0
- package/cjs/svg/pathConverter.d.ts.map +1 -0
- package/cjs/svg/pathConverter.js +285 -0
- package/cjs/svg/pathParser.d.ts +11 -0
- package/cjs/svg/pathParser.d.ts.map +1 -0
- package/cjs/svg/pathParser.js +76 -0
- package/cjs/utils/AdaptiveStepCalculator.d.ts +90 -0
- package/cjs/utils/AdaptiveStepCalculator.d.ts.map +1 -0
- package/cjs/utils/AdaptiveStepCalculator.js +224 -0
- package/cjs/utils/ErrorRecovery.d.ts +182 -0
- package/cjs/utils/ErrorRecovery.d.ts.map +1 -0
- package/cjs/utils/ErrorRecovery.js +413 -0
- package/cjs/utils/GlobalGrid.d.ts +99 -0
- package/cjs/utils/GlobalGrid.d.ts.map +1 -0
- package/cjs/utils/GlobalGrid.js +224 -0
- package/cjs/utils/PerformanceMonitor.d.ts +139 -0
- package/cjs/utils/PerformanceMonitor.d.ts.map +1 -0
- package/cjs/utils/PerformanceMonitor.js +305 -0
- package/cjs/utils/direction.d.ts +24 -0
- package/cjs/utils/direction.d.ts.map +1 -0
- package/cjs/utils/direction.js +54 -0
- package/cjs/utils/getAnchorPoints.d.ts +15 -0
- package/cjs/utils/getAnchorPoints.d.ts.map +1 -0
- package/cjs/utils/getAnchorPoints.js +71 -0
- package/cjs/utils/grid.d.ts +42 -0
- package/cjs/utils/grid.d.ts.map +1 -0
- package/cjs/utils/grid.js +73 -0
- package/cjs/utils/heuristics.d.ts +61 -0
- package/cjs/utils/heuristics.d.ts.map +1 -0
- package/cjs/utils/heuristics.js +141 -0
- package/cjs/utils/index.d.ts +14 -0
- package/cjs/utils/index.d.ts.map +1 -0
- package/cjs/utils/index.js +148 -0
- package/cjs/utils/node.d.ts +27 -0
- package/cjs/utils/node.d.ts.map +1 -0
- package/cjs/utils/node.js +36 -0
- package/cjs/utils/pathProcessing.d.ts +45 -0
- package/cjs/utils/pathProcessing.d.ts.map +1 -0
- package/cjs/utils/pathProcessing.js +270 -0
- package/cjs/utils/pathValidation.d.ts +11 -0
- package/cjs/utils/pathValidation.d.ts.map +1 -0
- package/cjs/utils/pathValidation.js +129 -0
- package/cjs/utils/rect.d.ts +9 -0
- package/cjs/utils/rect.d.ts.map +1 -0
- package/cjs/utils/rect.js +110 -0
- package/cjs/utils/route.d.ts +19 -0
- package/cjs/utils/route.d.ts.map +1 -0
- package/cjs/utils/route.js +92 -0
- package/esm/geometry/Line.d.ts +21 -0
- package/esm/geometry/Line.d.ts.map +1 -0
- package/esm/geometry/Point.d.ts +49 -0
- package/esm/geometry/Point.d.ts.map +1 -0
- package/esm/geometry/Rectangle.d.ts +41 -0
- package/esm/geometry/Rectangle.d.ts.map +1 -0
- package/esm/geometry/collision.d.ts +15 -0
- package/esm/geometry/collision.d.ts.map +1 -0
- package/esm/geometry/index.d.ts +5 -0
- package/esm/geometry/index.d.ts.map +1 -0
- package/esm/getManHattanPath.d.ts +53 -0
- package/esm/getManHattanPath.d.ts.map +1 -0
- package/esm/index.d.ts +16 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/obstacle/ObstacleMap.d.ts +66 -0
- package/esm/obstacle/ObstacleMap.d.ts.map +1 -0
- package/esm/obstacle/QuadTree.d.ts +119 -0
- package/esm/obstacle/QuadTree.d.ts.map +1 -0
- package/esm/obstacle/index.d.ts +2 -0
- package/esm/obstacle/index.d.ts.map +1 -0
- package/esm/options/defaults.d.ts +16 -0
- package/esm/options/defaults.d.ts.map +1 -0
- package/esm/options/index.d.ts +4 -0
- package/esm/options/index.d.ts.map +1 -0
- package/esm/options/resolver.d.ts +10 -0
- package/esm/options/resolver.d.ts.map +1 -0
- package/esm/options/types.d.ts +210 -0
- package/esm/options/types.d.ts.map +1 -0
- package/esm/pathfinder/PathCache.d.ts +92 -0
- package/esm/pathfinder/PathCache.d.ts.map +1 -0
- package/esm/pathfinder/SortedSet.d.ts +35 -0
- package/esm/pathfinder/SortedSet.d.ts.map +1 -0
- package/esm/pathfinder/findRoute.d.ts +8 -0
- package/esm/pathfinder/findRoute.d.ts.map +1 -0
- package/esm/pathfinder/index.d.ts +4 -0
- package/esm/pathfinder/index.d.ts.map +1 -0
- package/esm/svg/index.d.ts +3 -0
- package/esm/svg/index.d.ts.map +1 -0
- package/esm/svg/pathConverter.d.ts +23 -0
- package/esm/svg/pathConverter.d.ts.map +1 -0
- package/esm/svg/pathParser.d.ts +11 -0
- package/esm/svg/pathParser.d.ts.map +1 -0
- package/esm/utils/AdaptiveStepCalculator.d.ts +90 -0
- package/esm/utils/AdaptiveStepCalculator.d.ts.map +1 -0
- package/esm/utils/ErrorRecovery.d.ts +182 -0
- package/esm/utils/ErrorRecovery.d.ts.map +1 -0
- package/esm/utils/GlobalGrid.d.ts +99 -0
- package/esm/utils/GlobalGrid.d.ts.map +1 -0
- package/esm/utils/PerformanceMonitor.d.ts +139 -0
- package/esm/utils/PerformanceMonitor.d.ts.map +1 -0
- package/esm/utils/direction.d.ts +24 -0
- package/esm/utils/direction.d.ts.map +1 -0
- package/esm/utils/getAnchorPoints.d.ts +15 -0
- package/esm/utils/getAnchorPoints.d.ts.map +1 -0
- package/esm/utils/grid.d.ts +42 -0
- package/esm/utils/grid.d.ts.map +1 -0
- package/esm/utils/heuristics.d.ts +61 -0
- package/esm/utils/heuristics.d.ts.map +1 -0
- package/esm/utils/index.d.ts +14 -0
- package/esm/utils/index.d.ts.map +1 -0
- package/esm/utils/node.d.ts +27 -0
- package/esm/utils/node.d.ts.map +1 -0
- package/esm/utils/pathProcessing.d.ts +45 -0
- package/esm/utils/pathProcessing.d.ts.map +1 -0
- package/esm/utils/pathValidation.d.ts +11 -0
- package/esm/utils/pathValidation.d.ts.map +1 -0
- package/esm/utils/rect.d.ts +9 -0
- package/esm/utils/rect.d.ts.map +1 -0
- package/esm/utils/route.d.ts +19 -0
- package/esm/utils/route.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.PathCache = void 0;
|
|
7
|
+
exports.generateCacheKey = generateCacheKey;
|
|
8
|
+
exports.getGlobalPathCache = getGlobalPathCache;
|
|
9
|
+
exports.resetGlobalPathCache = resetGlobalPathCache;
|
|
10
|
+
/**
|
|
11
|
+
* PathCache - LRU cache for computed paths
|
|
12
|
+
* Feature: manhattan-optimization
|
|
13
|
+
*
|
|
14
|
+
* Implements a Least Recently Used (LRU) cache for storing computed paths.
|
|
15
|
+
* This improves performance by avoiding redundant path calculations for
|
|
16
|
+
* identical source-target-options combinations.
|
|
17
|
+
*
|
|
18
|
+
* Requirements: 3.4
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Cache entry containing the computed path and metadata
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Configuration for PathCache
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Default cache configuration
|
|
31
|
+
*/
|
|
32
|
+
const DEFAULT_CONFIG = {
|
|
33
|
+
maxSize: 1000,
|
|
34
|
+
ttl: 60000,
|
|
35
|
+
// 1 minute
|
|
36
|
+
enabled: true
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Generate a cache key from path parameters
|
|
41
|
+
*/
|
|
42
|
+
function generateCacheKey(sourceBBox, targetBBox, sourceAnchor, targetAnchor, options) {
|
|
43
|
+
// Include key configuration options that affect path calculation
|
|
44
|
+
const optionsKey = [options.step, options.extensionDistance, options.maxDirectionChange, options.sourcePosition || '', options.targetPosition || '', options.borderRadius].join(',');
|
|
45
|
+
return [
|
|
46
|
+
// Source bbox
|
|
47
|
+
`s:${sourceBBox.x},${sourceBBox.y},${sourceBBox.width},${sourceBBox.height}`,
|
|
48
|
+
// Target bbox
|
|
49
|
+
`t:${targetBBox.x},${targetBBox.y},${targetBBox.width},${targetBBox.height}`,
|
|
50
|
+
// Anchors
|
|
51
|
+
`sa:${sourceAnchor.x},${sourceAnchor.y}`, `ta:${targetAnchor.x},${targetAnchor.y}`,
|
|
52
|
+
// Options
|
|
53
|
+
`o:${optionsKey}`].join('|');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* LRU Cache for computed paths
|
|
58
|
+
*/
|
|
59
|
+
class PathCache {
|
|
60
|
+
cache;
|
|
61
|
+
config;
|
|
62
|
+
hits = 0;
|
|
63
|
+
misses = 0;
|
|
64
|
+
constructor(config = {}) {
|
|
65
|
+
this.config = {
|
|
66
|
+
...DEFAULT_CONFIG,
|
|
67
|
+
...config
|
|
68
|
+
};
|
|
69
|
+
this.cache = new Map();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Get a cached path if available and not expired
|
|
74
|
+
*/
|
|
75
|
+
get(key) {
|
|
76
|
+
if (!this.config.enabled) {
|
|
77
|
+
this.misses++;
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
const entry = this.cache.get(key);
|
|
81
|
+
if (!entry) {
|
|
82
|
+
this.misses++;
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Check TTL expiration
|
|
87
|
+
if (this.config.ttl > 0) {
|
|
88
|
+
const age = Date.now() - entry.timestamp;
|
|
89
|
+
if (age > this.config.ttl) {
|
|
90
|
+
this.cache.delete(key);
|
|
91
|
+
this.misses++;
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Update hit count and move to end (most recently used)
|
|
97
|
+
entry.hitCount++;
|
|
98
|
+
this.cache.delete(key);
|
|
99
|
+
this.cache.set(key, entry);
|
|
100
|
+
this.hits++;
|
|
101
|
+
// Return cloned path to prevent mutation
|
|
102
|
+
return entry.path.map(p => p.clone());
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Store a path in the cache
|
|
107
|
+
*/
|
|
108
|
+
set(key, path) {
|
|
109
|
+
if (!this.config.enabled) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Evict oldest entries if at capacity
|
|
114
|
+
while (this.cache.size >= this.config.maxSize) {
|
|
115
|
+
const oldestKey = this.cache.keys().next().value;
|
|
116
|
+
if (oldestKey) {
|
|
117
|
+
this.cache.delete(oldestKey);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
this.cache.set(key, {
|
|
121
|
+
path: path.map(p => p.clone()),
|
|
122
|
+
// Clone points to prevent mutation
|
|
123
|
+
timestamp: Date.now(),
|
|
124
|
+
hitCount: 0
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Check if a key exists in the cache (without updating LRU order)
|
|
130
|
+
*/
|
|
131
|
+
has(key) {
|
|
132
|
+
if (!this.config.enabled) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
const entry = this.cache.get(key);
|
|
136
|
+
if (!entry) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Check TTL expiration
|
|
141
|
+
if (this.config.ttl > 0) {
|
|
142
|
+
const age = Date.now() - entry.timestamp;
|
|
143
|
+
if (age > this.config.ttl) {
|
|
144
|
+
this.cache.delete(key);
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Clear all cached entries
|
|
153
|
+
*/
|
|
154
|
+
clear() {
|
|
155
|
+
this.cache.clear();
|
|
156
|
+
this.hits = 0;
|
|
157
|
+
this.misses = 0;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Get cache statistics
|
|
162
|
+
*/
|
|
163
|
+
getStats() {
|
|
164
|
+
const total = this.hits + this.misses;
|
|
165
|
+
return {
|
|
166
|
+
size: this.cache.size,
|
|
167
|
+
maxSize: this.config.maxSize,
|
|
168
|
+
hits: this.hits,
|
|
169
|
+
misses: this.misses,
|
|
170
|
+
hitRate: total > 0 ? this.hits / total : 0
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Update cache configuration
|
|
176
|
+
*/
|
|
177
|
+
updateConfig(config) {
|
|
178
|
+
this.config = {
|
|
179
|
+
...this.config,
|
|
180
|
+
...config
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
// If cache is disabled, clear it
|
|
184
|
+
if (!this.config.enabled) {
|
|
185
|
+
this.clear();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// If maxSize reduced, evict excess entries
|
|
189
|
+
while (this.cache.size > this.config.maxSize) {
|
|
190
|
+
const oldestKey = this.cache.keys().next().value;
|
|
191
|
+
if (oldestKey) {
|
|
192
|
+
this.cache.delete(oldestKey);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Get current configuration
|
|
199
|
+
*/
|
|
200
|
+
getConfig() {
|
|
201
|
+
return {
|
|
202
|
+
...this.config
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Remove expired entries (useful for periodic cleanup)
|
|
208
|
+
*/
|
|
209
|
+
cleanup() {
|
|
210
|
+
if (this.config.ttl <= 0) {
|
|
211
|
+
return 0;
|
|
212
|
+
}
|
|
213
|
+
const now = Date.now();
|
|
214
|
+
let removed = 0;
|
|
215
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
216
|
+
if (now - entry.timestamp > this.config.ttl) {
|
|
217
|
+
this.cache.delete(key);
|
|
218
|
+
removed++;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return removed;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Global path cache instance (singleton)
|
|
227
|
+
*/
|
|
228
|
+
exports.PathCache = PathCache;
|
|
229
|
+
let globalPathCache = null;
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Get the global path cache instance
|
|
233
|
+
*/
|
|
234
|
+
function getGlobalPathCache() {
|
|
235
|
+
if (!globalPathCache) {
|
|
236
|
+
globalPathCache = new PathCache();
|
|
237
|
+
}
|
|
238
|
+
return globalPathCache;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Reset the global path cache (useful for testing)
|
|
243
|
+
*/
|
|
244
|
+
function resetGlobalPathCache() {
|
|
245
|
+
if (globalPathCache) {
|
|
246
|
+
globalPathCache.clear();
|
|
247
|
+
}
|
|
248
|
+
globalPathCache = null;
|
|
249
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SortedSet class for managing open and closed sets in A* algorithm
|
|
3
|
+
* Maintains items sorted by their values
|
|
4
|
+
*/
|
|
5
|
+
export declare class SortedSet {
|
|
6
|
+
private items;
|
|
7
|
+
private hash;
|
|
8
|
+
private values;
|
|
9
|
+
constructor();
|
|
10
|
+
/**
|
|
11
|
+
* Add an item with its value, maintaining sorted order
|
|
12
|
+
*/
|
|
13
|
+
add(item: string, value: number): void;
|
|
14
|
+
/**
|
|
15
|
+
* Pop the item with minimum value and mark it as closed
|
|
16
|
+
*/
|
|
17
|
+
pop(): string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Check if item is in open set
|
|
20
|
+
*/
|
|
21
|
+
isOpen(item: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Check if item is in closed set
|
|
24
|
+
*/
|
|
25
|
+
isClose(item: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Check if open set is empty
|
|
28
|
+
*/
|
|
29
|
+
isEmpty(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Find sorted insertion index for an item
|
|
32
|
+
*/
|
|
33
|
+
private sortedIndexBy;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=SortedSet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SortedSet.d.ts","sourceRoot":"","sources":["../../src/pathfinder/SortedSet.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,KAAK,CAAU;IACvB,OAAO,CAAC,IAAI,CAAqB;IACjC,OAAO,CAAC,MAAM,CAAqB;;IAQnC;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAkBtC;;OAEG;IACH,GAAG,IAAI,MAAM,GAAG,SAAS;IAQzB;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI7B;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI9B;;OAEG;IACH,OAAO,IAAI,OAAO;IAIlB;;OAEG;IACH,OAAO,CAAC,aAAa;CAiBtB"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SortedSet = void 0;
|
|
7
|
+
const OPEN = 1;
|
|
8
|
+
const CLOSE = 2;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* SortedSet class for managing open and closed sets in A* algorithm
|
|
12
|
+
* Maintains items sorted by their values
|
|
13
|
+
*/
|
|
14
|
+
class SortedSet {
|
|
15
|
+
items;
|
|
16
|
+
hash;
|
|
17
|
+
values;
|
|
18
|
+
constructor() {
|
|
19
|
+
this.items = [];
|
|
20
|
+
this.hash = new Map();
|
|
21
|
+
this.values = new Map();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Add an item with its value, maintaining sorted order
|
|
26
|
+
*/
|
|
27
|
+
add(item, value) {
|
|
28
|
+
if (this.hash.get(item)) {
|
|
29
|
+
// Item removal - remove from items array
|
|
30
|
+
const index = this.items.indexOf(item);
|
|
31
|
+
if (index !== -1) {
|
|
32
|
+
this.items.splice(index, 1);
|
|
33
|
+
}
|
|
34
|
+
} else {
|
|
35
|
+
this.hash.set(item, OPEN);
|
|
36
|
+
}
|
|
37
|
+
this.values.set(item, value);
|
|
38
|
+
|
|
39
|
+
// Find insertion index using binary search
|
|
40
|
+
const index = this.sortedIndexBy(item);
|
|
41
|
+
this.items.splice(index, 0, item);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Pop the item with minimum value and mark it as closed
|
|
46
|
+
*/
|
|
47
|
+
pop() {
|
|
48
|
+
const item = this.items.shift();
|
|
49
|
+
if (item) {
|
|
50
|
+
this.hash.set(item, CLOSE);
|
|
51
|
+
}
|
|
52
|
+
return item;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Check if item is in open set
|
|
57
|
+
*/
|
|
58
|
+
isOpen(item) {
|
|
59
|
+
return this.hash.get(item) === OPEN;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Check if item is in closed set
|
|
64
|
+
*/
|
|
65
|
+
isClose(item) {
|
|
66
|
+
return this.hash.get(item) === CLOSE;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Check if open set is empty
|
|
71
|
+
*/
|
|
72
|
+
isEmpty() {
|
|
73
|
+
return this.items.length === 0;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Find sorted insertion index for an item
|
|
78
|
+
*/
|
|
79
|
+
sortedIndexBy(item) {
|
|
80
|
+
const value = this.values.get(item);
|
|
81
|
+
let low = 0;
|
|
82
|
+
let high = this.items.length;
|
|
83
|
+
while (low < high) {
|
|
84
|
+
const mid = low + high >>> 1;
|
|
85
|
+
const midValue = this.values.get(this.items[mid]);
|
|
86
|
+
if (midValue < value) {
|
|
87
|
+
low = mid + 1;
|
|
88
|
+
} else {
|
|
89
|
+
high = mid;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return low;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.SortedSet = SortedSet;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Point, Rectangle } from '../geometry';
|
|
2
|
+
import type { ResolvedOptions } from '../options';
|
|
3
|
+
import type { ObstacleMap } from '../obstacle';
|
|
4
|
+
/**
|
|
5
|
+
* Find route between two points using A* algorithm
|
|
6
|
+
*/
|
|
7
|
+
export declare function findRoute(sourceBBox: Rectangle, targetBBox: Rectangle, sourceAnchor: Point, targetAnchor: Point, map: ObstacleMap, options: ResolvedOptions): Point[] | null;
|
|
8
|
+
//# sourceMappingURL=findRoute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findRoute.d.ts","sourceRoot":"","sources":["../../src/pathfinder/findRoute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAiI9C;;GAEG;AACH,wBAAgB,SAAS,CACvB,UAAU,EAAE,SAAS,EACrB,UAAU,EAAE,SAAS,EACrB,YAAY,EAAE,KAAK,EACnB,YAAY,EAAE,KAAK,EACnB,GAAG,EAAE,WAAW,EAChB,OAAO,EAAE,eAAe,GACvB,KAAK,EAAE,GAAG,IAAI,CA2XhB"}
|