@rxflow/manhattan 0.0.2-alpha.8 → 0.0.2
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 +214 -10
- package/esm/getManHattanPath.js +92 -69
- package/esm/obstacle/ObstacleMap.js +218 -99
- package/esm/obstacle/QuadTree.js +488 -0
- package/esm/options/resolver.js +147 -18
- package/esm/pathfinder/PathCache.js +278 -0
- package/esm/pathfinder/findRoute.js +98 -44
- package/esm/pathfinder/index.js +2 -1
- package/esm/svg/pathConverter.js +170 -1
- package/esm/utils/AdaptiveStepCalculator.js +252 -0
- package/esm/utils/ErrorRecovery.js +499 -0
- package/esm/utils/GlobalGrid.js +259 -0
- package/esm/utils/PerformanceMonitor.js +360 -0
- package/esm/utils/getAnchorPoints.js +0 -4
- package/esm/utils/grid.js +18 -13
- package/esm/utils/heuristics.js +144 -0
- package/esm/utils/index.js +7 -1
- package/esm/utils/pathProcessing.js +270 -0
- package/esm/utils/pathValidation.js +0 -1
- package/esm/utils/rect.js +11 -4
- package/esm/utils/route.js +18 -2
- package/package.json +10 -2
- package/cjs/geometry/Line.d.ts +0 -21
- package/cjs/geometry/Line.d.ts.map +0 -1
- package/cjs/geometry/Line.js +0 -88
- package/cjs/geometry/Point.d.ts +0 -49
- package/cjs/geometry/Point.d.ts.map +0 -1
- package/cjs/geometry/Point.js +0 -94
- package/cjs/geometry/Rectangle.d.ts +0 -41
- package/cjs/geometry/Rectangle.d.ts.map +0 -1
- package/cjs/geometry/Rectangle.js +0 -65
- package/cjs/geometry/collision.d.ts +0 -15
- package/cjs/geometry/collision.d.ts.map +0 -1
- package/cjs/geometry/collision.js +0 -81
- package/cjs/geometry/index.d.ts +0 -5
- package/cjs/geometry/index.d.ts.map +0 -1
- package/cjs/geometry/index.js +0 -45
- package/cjs/getManHattanPath.d.ts +0 -53
- package/cjs/getManHattanPath.d.ts.map +0 -1
- package/cjs/getManHattanPath.js +0 -418
- package/cjs/index.d.ts +0 -16
- package/cjs/index.d.ts.map +0 -1
- package/cjs/index.js +0 -117
- package/cjs/obstacle/ObstacleMap.d.ts +0 -34
- package/cjs/obstacle/ObstacleMap.d.ts.map +0 -1
- package/cjs/obstacle/ObstacleMap.js +0 -223
- package/cjs/obstacle/index.d.ts +0 -2
- package/cjs/obstacle/index.d.ts.map +0 -1
- package/cjs/obstacle/index.js +0 -12
- package/cjs/options/defaults.d.ts +0 -16
- package/cjs/options/defaults.d.ts.map +0 -1
- package/cjs/options/defaults.js +0 -39
- package/cjs/options/index.d.ts +0 -4
- package/cjs/options/index.d.ts.map +0 -1
- package/cjs/options/index.js +0 -38
- package/cjs/options/resolver.d.ts +0 -10
- package/cjs/options/resolver.d.ts.map +0 -1
- package/cjs/options/resolver.js +0 -120
- package/cjs/options/types.d.ts +0 -169
- package/cjs/options/types.d.ts.map +0 -1
- package/cjs/options/types.js +0 -5
- package/cjs/pathfinder/SortedSet.d.ts +0 -35
- package/cjs/pathfinder/SortedSet.d.ts.map +0 -1
- package/cjs/pathfinder/SortedSet.js +0 -95
- package/cjs/pathfinder/findRoute.d.ts +0 -8
- package/cjs/pathfinder/findRoute.d.ts.map +0 -1
- package/cjs/pathfinder/findRoute.js +0 -330
- package/cjs/pathfinder/index.d.ts +0 -3
- package/cjs/pathfinder/index.d.ts.map +0 -1
- package/cjs/pathfinder/index.js +0 -19
- package/cjs/svg/index.d.ts +0 -3
- package/cjs/svg/index.d.ts.map +0 -1
- package/cjs/svg/index.js +0 -31
- package/cjs/svg/pathConverter.d.ts +0 -10
- package/cjs/svg/pathConverter.d.ts.map +0 -1
- package/cjs/svg/pathConverter.js +0 -116
- package/cjs/svg/pathParser.d.ts +0 -11
- package/cjs/svg/pathParser.d.ts.map +0 -1
- package/cjs/svg/pathParser.js +0 -76
- package/cjs/utils/direction.d.ts +0 -24
- package/cjs/utils/direction.d.ts.map +0 -1
- package/cjs/utils/direction.js +0 -54
- package/cjs/utils/getAnchorPoints.d.ts +0 -15
- package/cjs/utils/getAnchorPoints.d.ts.map +0 -1
- package/cjs/utils/getAnchorPoints.js +0 -75
- package/cjs/utils/grid.d.ts +0 -27
- package/cjs/utils/grid.d.ts.map +0 -1
- package/cjs/utils/grid.js +0 -66
- package/cjs/utils/index.d.ts +0 -8
- package/cjs/utils/index.d.ts.map +0 -1
- package/cjs/utils/index.js +0 -82
- package/cjs/utils/node.d.ts +0 -27
- package/cjs/utils/node.d.ts.map +0 -1
- package/cjs/utils/node.js +0 -36
- package/cjs/utils/pathValidation.d.ts +0 -11
- package/cjs/utils/pathValidation.d.ts.map +0 -1
- package/cjs/utils/pathValidation.js +0 -130
- package/cjs/utils/rect.d.ts +0 -9
- package/cjs/utils/rect.d.ts.map +0 -1
- package/cjs/utils/rect.js +0 -103
- package/cjs/utils/route.d.ts +0 -19
- package/cjs/utils/route.d.ts.map +0 -1
- package/cjs/utils/route.js +0 -76
- package/esm/geometry/Line.d.ts +0 -21
- package/esm/geometry/Line.d.ts.map +0 -1
- package/esm/geometry/Point.d.ts +0 -49
- package/esm/geometry/Point.d.ts.map +0 -1
- package/esm/geometry/Rectangle.d.ts +0 -41
- package/esm/geometry/Rectangle.d.ts.map +0 -1
- package/esm/geometry/collision.d.ts +0 -15
- package/esm/geometry/collision.d.ts.map +0 -1
- package/esm/geometry/index.d.ts +0 -5
- package/esm/geometry/index.d.ts.map +0 -1
- package/esm/getManHattanPath.d.ts +0 -53
- package/esm/getManHattanPath.d.ts.map +0 -1
- package/esm/index.d.ts +0 -16
- package/esm/index.d.ts.map +0 -1
- package/esm/obstacle/ObstacleMap.d.ts +0 -34
- package/esm/obstacle/ObstacleMap.d.ts.map +0 -1
- package/esm/obstacle/index.d.ts +0 -2
- package/esm/obstacle/index.d.ts.map +0 -1
- package/esm/options/defaults.d.ts +0 -16
- package/esm/options/defaults.d.ts.map +0 -1
- package/esm/options/index.d.ts +0 -4
- package/esm/options/index.d.ts.map +0 -1
- package/esm/options/resolver.d.ts +0 -10
- package/esm/options/resolver.d.ts.map +0 -1
- package/esm/options/types.d.ts +0 -169
- package/esm/options/types.d.ts.map +0 -1
- package/esm/pathfinder/SortedSet.d.ts +0 -35
- package/esm/pathfinder/SortedSet.d.ts.map +0 -1
- package/esm/pathfinder/findRoute.d.ts +0 -8
- package/esm/pathfinder/findRoute.d.ts.map +0 -1
- package/esm/pathfinder/index.d.ts +0 -3
- package/esm/pathfinder/index.d.ts.map +0 -1
- package/esm/svg/index.d.ts +0 -3
- package/esm/svg/index.d.ts.map +0 -1
- package/esm/svg/pathConverter.d.ts +0 -10
- package/esm/svg/pathConverter.d.ts.map +0 -1
- package/esm/svg/pathParser.d.ts +0 -11
- package/esm/svg/pathParser.d.ts.map +0 -1
- package/esm/utils/direction.d.ts +0 -24
- package/esm/utils/direction.d.ts.map +0 -1
- package/esm/utils/getAnchorPoints.d.ts +0 -15
- package/esm/utils/getAnchorPoints.d.ts.map +0 -1
- package/esm/utils/grid.d.ts +0 -27
- package/esm/utils/grid.d.ts.map +0 -1
- package/esm/utils/index.d.ts +0 -8
- package/esm/utils/index.d.ts.map +0 -1
- package/esm/utils/node.d.ts +0 -27
- package/esm/utils/node.d.ts.map +0 -1
- package/esm/utils/pathValidation.d.ts +0 -11
- package/esm/utils/pathValidation.d.ts.map +0 -1
- package/esm/utils/rect.d.ts +0 -9
- package/esm/utils/rect.d.ts.map +0 -1
- package/esm/utils/route.d.ts +0 -19
- package/esm/utils/route.d.ts.map +0 -1
package/esm/options/resolver.js
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
1
7
|
import { Point } from "../geometry";
|
|
2
8
|
import { defaults, directionMap } from "./defaults";
|
|
9
|
+
import { DEFAULT_ADAPTIVE_STEP_CONFIG } from "../utils/AdaptiveStepCalculator";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Default performance configuration
|
|
13
|
+
*/
|
|
14
|
+
var DEFAULT_PERFORMANCE_CONFIG = {
|
|
15
|
+
enableCache: true,
|
|
16
|
+
cacheSize: 100,
|
|
17
|
+
enableQuadTree: true,
|
|
18
|
+
earlyTermination: false
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Default debug configuration
|
|
23
|
+
*/
|
|
24
|
+
var DEFAULT_DEBUG_CONFIG = {
|
|
25
|
+
enableLogging: false,
|
|
26
|
+
enableMetrics: false,
|
|
27
|
+
logLevel: 'info'
|
|
28
|
+
};
|
|
3
29
|
|
|
4
30
|
/**
|
|
5
31
|
* Normalize padding value to box format
|
|
@@ -29,28 +55,123 @@ export function normalizeAngle(angle) {
|
|
|
29
55
|
return angle;
|
|
30
56
|
}
|
|
31
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Validate and fix configuration options
|
|
60
|
+
*/
|
|
61
|
+
function validateAndFixOptions(options) {
|
|
62
|
+
var fixed = _objectSpread({}, options);
|
|
63
|
+
|
|
64
|
+
// Validate step
|
|
65
|
+
if (fixed.step !== undefined && fixed.step <= 0) {
|
|
66
|
+
console.warn('[ManhattanRouter] Invalid step value, using default');
|
|
67
|
+
fixed.step = defaults.step;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Validate maxLoopCount
|
|
71
|
+
if (fixed.maxLoopCount !== undefined && fixed.maxLoopCount <= 0) {
|
|
72
|
+
console.warn('[ManhattanRouter] Invalid maxLoopCount, using default');
|
|
73
|
+
fixed.maxLoopCount = defaults.maxLoopCount;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Validate borderRadius
|
|
77
|
+
if (fixed.borderRadius !== undefined && fixed.borderRadius < 0) {
|
|
78
|
+
console.warn('[ManhattanRouter] Invalid borderRadius, using default');
|
|
79
|
+
fixed.borderRadius = defaults.borderRadius;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Validate extensionDistance
|
|
83
|
+
if (fixed.extensionDistance !== undefined && fixed.extensionDistance < 0) {
|
|
84
|
+
console.warn('[ManhattanRouter] Invalid extensionDistance, using default');
|
|
85
|
+
fixed.extensionDistance = defaults.extensionDistance;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Validate precision
|
|
89
|
+
if (fixed.precision !== undefined && (fixed.precision < 0 || fixed.precision > 10)) {
|
|
90
|
+
console.warn('[ManhattanRouter] Invalid precision, using default');
|
|
91
|
+
fixed.precision = defaults.precision;
|
|
92
|
+
}
|
|
93
|
+
return fixed;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Resolve adaptive step configuration
|
|
98
|
+
*/
|
|
99
|
+
function resolveAdaptiveStepConfig(config) {
|
|
100
|
+
var _config$enabled, _config$minStep, _config$maxStep, _config$densityBased$, _config$densityBased, _config$densityBased$2, _config$densityBased2, _config$distanceBased, _config$distanceBased2, _config$distanceBased3, _config$distanceBased4, _config$distanceBased5, _config$distanceBased6;
|
|
101
|
+
if (!config) {
|
|
102
|
+
return _objectSpread({}, DEFAULT_ADAPTIVE_STEP_CONFIG);
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
enabled: (_config$enabled = config.enabled) !== null && _config$enabled !== void 0 ? _config$enabled : DEFAULT_ADAPTIVE_STEP_CONFIG.enabled,
|
|
106
|
+
minStep: (_config$minStep = config.minStep) !== null && _config$minStep !== void 0 ? _config$minStep : DEFAULT_ADAPTIVE_STEP_CONFIG.minStep,
|
|
107
|
+
maxStep: (_config$maxStep = config.maxStep) !== null && _config$maxStep !== void 0 ? _config$maxStep : DEFAULT_ADAPTIVE_STEP_CONFIG.maxStep,
|
|
108
|
+
densityBased: {
|
|
109
|
+
enabled: (_config$densityBased$ = (_config$densityBased = config.densityBased) === null || _config$densityBased === void 0 ? void 0 : _config$densityBased.enabled) !== null && _config$densityBased$ !== void 0 ? _config$densityBased$ : DEFAULT_ADAPTIVE_STEP_CONFIG.densityBased.enabled,
|
|
110
|
+
threshold: (_config$densityBased$2 = (_config$densityBased2 = config.densityBased) === null || _config$densityBased2 === void 0 ? void 0 : _config$densityBased2.threshold) !== null && _config$densityBased$2 !== void 0 ? _config$densityBased$2 : DEFAULT_ADAPTIVE_STEP_CONFIG.densityBased.threshold
|
|
111
|
+
},
|
|
112
|
+
distanceBased: {
|
|
113
|
+
enabled: (_config$distanceBased = (_config$distanceBased2 = config.distanceBased) === null || _config$distanceBased2 === void 0 ? void 0 : _config$distanceBased2.enabled) !== null && _config$distanceBased !== void 0 ? _config$distanceBased : DEFAULT_ADAPTIVE_STEP_CONFIG.distanceBased.enabled,
|
|
114
|
+
shortPathThreshold: (_config$distanceBased3 = (_config$distanceBased4 = config.distanceBased) === null || _config$distanceBased4 === void 0 ? void 0 : _config$distanceBased4.shortPathThreshold) !== null && _config$distanceBased3 !== void 0 ? _config$distanceBased3 : DEFAULT_ADAPTIVE_STEP_CONFIG.distanceBased.shortPathThreshold,
|
|
115
|
+
longPathThreshold: (_config$distanceBased5 = (_config$distanceBased6 = config.distanceBased) === null || _config$distanceBased6 === void 0 ? void 0 : _config$distanceBased6.longPathThreshold) !== null && _config$distanceBased5 !== void 0 ? _config$distanceBased5 : DEFAULT_ADAPTIVE_STEP_CONFIG.distanceBased.longPathThreshold
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Resolve performance configuration
|
|
122
|
+
*/
|
|
123
|
+
function resolvePerformanceConfig(config) {
|
|
124
|
+
var _config$enableCache, _config$cacheSize, _config$enableQuadTre, _config$earlyTerminat;
|
|
125
|
+
if (!config) {
|
|
126
|
+
return _objectSpread({}, DEFAULT_PERFORMANCE_CONFIG);
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
enableCache: (_config$enableCache = config.enableCache) !== null && _config$enableCache !== void 0 ? _config$enableCache : DEFAULT_PERFORMANCE_CONFIG.enableCache,
|
|
130
|
+
cacheSize: (_config$cacheSize = config.cacheSize) !== null && _config$cacheSize !== void 0 ? _config$cacheSize : DEFAULT_PERFORMANCE_CONFIG.cacheSize,
|
|
131
|
+
enableQuadTree: (_config$enableQuadTre = config.enableQuadTree) !== null && _config$enableQuadTre !== void 0 ? _config$enableQuadTre : DEFAULT_PERFORMANCE_CONFIG.enableQuadTree,
|
|
132
|
+
earlyTermination: (_config$earlyTerminat = config.earlyTermination) !== null && _config$earlyTerminat !== void 0 ? _config$earlyTerminat : DEFAULT_PERFORMANCE_CONFIG.earlyTermination
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Resolve debug configuration
|
|
138
|
+
*/
|
|
139
|
+
function resolveDebugConfig(config) {
|
|
140
|
+
var _config$enableLogging, _config$enableMetrics, _config$logLevel;
|
|
141
|
+
if (!config) {
|
|
142
|
+
return _objectSpread({}, DEFAULT_DEBUG_CONFIG);
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
enableLogging: (_config$enableLogging = config.enableLogging) !== null && _config$enableLogging !== void 0 ? _config$enableLogging : DEFAULT_DEBUG_CONFIG.enableLogging,
|
|
146
|
+
enableMetrics: (_config$enableMetrics = config.enableMetrics) !== null && _config$enableMetrics !== void 0 ? _config$enableMetrics : DEFAULT_DEBUG_CONFIG.enableMetrics,
|
|
147
|
+
logLevel: (_config$logLevel = config.logLevel) !== null && _config$logLevel !== void 0 ? _config$logLevel : DEFAULT_DEBUG_CONFIG.logLevel
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
32
151
|
/**
|
|
33
152
|
* Resolve options by merging user options with defaults
|
|
34
153
|
*/
|
|
35
154
|
export function resolveOptions() {
|
|
36
|
-
var
|
|
155
|
+
var _validatedOptions$ste, _validatedOptions$max, _validatedOptions$pre, _validatedOptions$max2, _validatedOptions$sta, _validatedOptions$end, _validatedOptions$exc, _validatedOptions$exc2, _validatedOptions$exc3, _validatedOptions$bor, _validatedOptions$ext, _validatedOptions$pen, _validatedOptions$pad;
|
|
37
156
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
38
|
-
|
|
39
|
-
var
|
|
40
|
-
var
|
|
41
|
-
var
|
|
42
|
-
var
|
|
43
|
-
var
|
|
44
|
-
var
|
|
45
|
-
var
|
|
46
|
-
var
|
|
47
|
-
var
|
|
48
|
-
var
|
|
49
|
-
var
|
|
50
|
-
var
|
|
157
|
+
// Validate and fix options first
|
|
158
|
+
var validatedOptions = validateAndFixOptions(options);
|
|
159
|
+
var step = (_validatedOptions$ste = validatedOptions.step) !== null && _validatedOptions$ste !== void 0 ? _validatedOptions$ste : defaults.step;
|
|
160
|
+
var maxLoopCount = (_validatedOptions$max = validatedOptions.maxLoopCount) !== null && _validatedOptions$max !== void 0 ? _validatedOptions$max : defaults.maxLoopCount;
|
|
161
|
+
var precision = (_validatedOptions$pre = validatedOptions.precision) !== null && _validatedOptions$pre !== void 0 ? _validatedOptions$pre : defaults.precision;
|
|
162
|
+
var maxDirectionChange = (_validatedOptions$max2 = validatedOptions.maxDirectionChange) !== null && _validatedOptions$max2 !== void 0 ? _validatedOptions$max2 : defaults.maxDirectionChange;
|
|
163
|
+
var startDirections = (_validatedOptions$sta = validatedOptions.startDirections) !== null && _validatedOptions$sta !== void 0 ? _validatedOptions$sta : defaults.startDirections;
|
|
164
|
+
var endDirections = (_validatedOptions$end = validatedOptions.endDirections) !== null && _validatedOptions$end !== void 0 ? _validatedOptions$end : defaults.endDirections;
|
|
165
|
+
var excludeNodes = (_validatedOptions$exc = validatedOptions.excludeNodes) !== null && _validatedOptions$exc !== void 0 ? _validatedOptions$exc : defaults.excludeNodes;
|
|
166
|
+
var excludeShapes = (_validatedOptions$exc2 = validatedOptions.excludeShapes) !== null && _validatedOptions$exc2 !== void 0 ? _validatedOptions$exc2 : defaults.excludeShapes;
|
|
167
|
+
var excludeTerminals = (_validatedOptions$exc3 = validatedOptions.excludeTerminals) !== null && _validatedOptions$exc3 !== void 0 ? _validatedOptions$exc3 : defaults.excludeTerminals;
|
|
168
|
+
var borderRadius = (_validatedOptions$bor = validatedOptions.borderRadius) !== null && _validatedOptions$bor !== void 0 ? _validatedOptions$bor : defaults.borderRadius;
|
|
169
|
+
var extensionDistance = (_validatedOptions$ext = validatedOptions.extensionDistance) !== null && _validatedOptions$ext !== void 0 ? _validatedOptions$ext : defaults.extensionDistance;
|
|
170
|
+
var penalties = (_validatedOptions$pen = validatedOptions.penalties) !== null && _validatedOptions$pen !== void 0 ? _validatedOptions$pen : defaults.penalties;
|
|
171
|
+
var fallbackRoute = validatedOptions.fallbackRoute;
|
|
51
172
|
|
|
52
173
|
// Convert padding to paddingBox
|
|
53
|
-
var padding = (
|
|
174
|
+
var padding = (_validatedOptions$pad = validatedOptions.padding) !== null && _validatedOptions$pad !== void 0 ? _validatedOptions$pad : defaults.padding;
|
|
54
175
|
var sides = normalizePadding(padding);
|
|
55
176
|
var paddingBox = {
|
|
56
177
|
x: -sides.left,
|
|
@@ -91,6 +212,11 @@ export function resolveOptions() {
|
|
|
91
212
|
var point2 = new Point(direction.offsetX, direction.offsetY);
|
|
92
213
|
direction.angle = normalizeAngle(point1.theta(point2));
|
|
93
214
|
});
|
|
215
|
+
|
|
216
|
+
// Resolve new configuration sections
|
|
217
|
+
var adaptiveStep = resolveAdaptiveStepConfig(validatedOptions.adaptiveStep);
|
|
218
|
+
var performance = resolvePerformanceConfig(validatedOptions.performance);
|
|
219
|
+
var debug = resolveDebugConfig(validatedOptions.debug);
|
|
94
220
|
return {
|
|
95
221
|
step: step,
|
|
96
222
|
maxLoopCount: maxLoopCount,
|
|
@@ -104,13 +230,16 @@ export function resolveOptions() {
|
|
|
104
230
|
paddingBox: paddingBox,
|
|
105
231
|
borderRadius: borderRadius,
|
|
106
232
|
extensionDistance: extensionDistance,
|
|
107
|
-
sourcePosition:
|
|
108
|
-
targetPosition:
|
|
233
|
+
sourcePosition: validatedOptions.sourcePosition,
|
|
234
|
+
targetPosition: validatedOptions.targetPosition,
|
|
109
235
|
directionMap: directionMap,
|
|
110
236
|
directions: directions,
|
|
111
237
|
penalties: penalties,
|
|
112
238
|
cost: cost,
|
|
113
239
|
fallbackRoute: fallbackRoute,
|
|
114
|
-
previousDirectionAngle: undefined
|
|
240
|
+
previousDirectionAngle: undefined,
|
|
241
|
+
adaptiveStep: adaptiveStep,
|
|
242
|
+
performance: performance,
|
|
243
|
+
debug: debug
|
|
115
244
|
};
|
|
116
245
|
}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
3
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
5
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
6
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
7
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
8
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
9
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
10
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
11
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
12
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
13
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
14
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
15
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
16
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
17
|
+
/**
|
|
18
|
+
* PathCache - LRU cache for computed paths
|
|
19
|
+
* Feature: manhattan-optimization
|
|
20
|
+
*
|
|
21
|
+
* Implements a Least Recently Used (LRU) cache for storing computed paths.
|
|
22
|
+
* This improves performance by avoiding redundant path calculations for
|
|
23
|
+
* identical source-target-options combinations.
|
|
24
|
+
*
|
|
25
|
+
* Requirements: 3.4
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Cache entry containing the computed path and metadata
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Configuration for PathCache
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Default cache configuration
|
|
38
|
+
*/
|
|
39
|
+
var DEFAULT_CONFIG = {
|
|
40
|
+
maxSize: 1000,
|
|
41
|
+
ttl: 60000,
|
|
42
|
+
// 1 minute
|
|
43
|
+
enabled: true
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Generate a cache key from path parameters
|
|
48
|
+
*/
|
|
49
|
+
export function generateCacheKey(sourceBBox, targetBBox, sourceAnchor, targetAnchor, options) {
|
|
50
|
+
// Include key configuration options that affect path calculation
|
|
51
|
+
var optionsKey = [options.step, options.extensionDistance, options.maxDirectionChange, options.sourcePosition || '', options.targetPosition || '', options.borderRadius].join(',');
|
|
52
|
+
return [// Source bbox
|
|
53
|
+
"s:".concat(sourceBBox.x, ",").concat(sourceBBox.y, ",").concat(sourceBBox.width, ",").concat(sourceBBox.height), // Target bbox
|
|
54
|
+
"t:".concat(targetBBox.x, ",").concat(targetBBox.y, ",").concat(targetBBox.width, ",").concat(targetBBox.height), // Anchors
|
|
55
|
+
"sa:".concat(sourceAnchor.x, ",").concat(sourceAnchor.y), "ta:".concat(targetAnchor.x, ",").concat(targetAnchor.y), // Options
|
|
56
|
+
"o:".concat(optionsKey)].join('|');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* LRU Cache for computed paths
|
|
61
|
+
*/
|
|
62
|
+
export var PathCache = /*#__PURE__*/function () {
|
|
63
|
+
function PathCache() {
|
|
64
|
+
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
65
|
+
_classCallCheck(this, PathCache);
|
|
66
|
+
_defineProperty(this, "cache", void 0);
|
|
67
|
+
_defineProperty(this, "config", void 0);
|
|
68
|
+
_defineProperty(this, "hits", 0);
|
|
69
|
+
_defineProperty(this, "misses", 0);
|
|
70
|
+
this.config = _objectSpread(_objectSpread({}, DEFAULT_CONFIG), config);
|
|
71
|
+
this.cache = new Map();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Get a cached path if available and not expired
|
|
76
|
+
*/
|
|
77
|
+
_createClass(PathCache, [{
|
|
78
|
+
key: "get",
|
|
79
|
+
value: function get(key) {
|
|
80
|
+
if (!this.config.enabled) {
|
|
81
|
+
this.misses++;
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
var entry = this.cache.get(key);
|
|
85
|
+
if (!entry) {
|
|
86
|
+
this.misses++;
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Check TTL expiration
|
|
91
|
+
if (this.config.ttl > 0) {
|
|
92
|
+
var age = Date.now() - entry.timestamp;
|
|
93
|
+
if (age > this.config.ttl) {
|
|
94
|
+
this.cache.delete(key);
|
|
95
|
+
this.misses++;
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Update hit count and move to end (most recently used)
|
|
101
|
+
entry.hitCount++;
|
|
102
|
+
this.cache.delete(key);
|
|
103
|
+
this.cache.set(key, entry);
|
|
104
|
+
this.hits++;
|
|
105
|
+
// Return cloned path to prevent mutation
|
|
106
|
+
return entry.path.map(function (p) {
|
|
107
|
+
return p.clone();
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Store a path in the cache
|
|
113
|
+
*/
|
|
114
|
+
}, {
|
|
115
|
+
key: "set",
|
|
116
|
+
value: function set(key, path) {
|
|
117
|
+
if (!this.config.enabled) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Evict oldest entries if at capacity
|
|
122
|
+
while (this.cache.size >= this.config.maxSize) {
|
|
123
|
+
var oldestKey = this.cache.keys().next().value;
|
|
124
|
+
if (oldestKey) {
|
|
125
|
+
this.cache.delete(oldestKey);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
this.cache.set(key, {
|
|
129
|
+
path: path.map(function (p) {
|
|
130
|
+
return p.clone();
|
|
131
|
+
}),
|
|
132
|
+
// Clone points to prevent mutation
|
|
133
|
+
timestamp: Date.now(),
|
|
134
|
+
hitCount: 0
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Check if a key exists in the cache (without updating LRU order)
|
|
140
|
+
*/
|
|
141
|
+
}, {
|
|
142
|
+
key: "has",
|
|
143
|
+
value: function has(key) {
|
|
144
|
+
if (!this.config.enabled) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
var entry = this.cache.get(key);
|
|
148
|
+
if (!entry) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Check TTL expiration
|
|
153
|
+
if (this.config.ttl > 0) {
|
|
154
|
+
var age = Date.now() - entry.timestamp;
|
|
155
|
+
if (age > this.config.ttl) {
|
|
156
|
+
this.cache.delete(key);
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Clear all cached entries
|
|
165
|
+
*/
|
|
166
|
+
}, {
|
|
167
|
+
key: "clear",
|
|
168
|
+
value: function clear() {
|
|
169
|
+
this.cache.clear();
|
|
170
|
+
this.hits = 0;
|
|
171
|
+
this.misses = 0;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Get cache statistics
|
|
176
|
+
*/
|
|
177
|
+
}, {
|
|
178
|
+
key: "getStats",
|
|
179
|
+
value: function getStats() {
|
|
180
|
+
var total = this.hits + this.misses;
|
|
181
|
+
return {
|
|
182
|
+
size: this.cache.size,
|
|
183
|
+
maxSize: this.config.maxSize,
|
|
184
|
+
hits: this.hits,
|
|
185
|
+
misses: this.misses,
|
|
186
|
+
hitRate: total > 0 ? this.hits / total : 0
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Update cache configuration
|
|
192
|
+
*/
|
|
193
|
+
}, {
|
|
194
|
+
key: "updateConfig",
|
|
195
|
+
value: function updateConfig(config) {
|
|
196
|
+
this.config = _objectSpread(_objectSpread({}, this.config), config);
|
|
197
|
+
|
|
198
|
+
// If cache is disabled, clear it
|
|
199
|
+
if (!this.config.enabled) {
|
|
200
|
+
this.clear();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// If maxSize reduced, evict excess entries
|
|
204
|
+
while (this.cache.size > this.config.maxSize) {
|
|
205
|
+
var oldestKey = this.cache.keys().next().value;
|
|
206
|
+
if (oldestKey) {
|
|
207
|
+
this.cache.delete(oldestKey);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Get current configuration
|
|
214
|
+
*/
|
|
215
|
+
}, {
|
|
216
|
+
key: "getConfig",
|
|
217
|
+
value: function getConfig() {
|
|
218
|
+
return _objectSpread({}, this.config);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Remove expired entries (useful for periodic cleanup)
|
|
223
|
+
*/
|
|
224
|
+
}, {
|
|
225
|
+
key: "cleanup",
|
|
226
|
+
value: function cleanup() {
|
|
227
|
+
if (this.config.ttl <= 0) {
|
|
228
|
+
return 0;
|
|
229
|
+
}
|
|
230
|
+
var now = Date.now();
|
|
231
|
+
var removed = 0;
|
|
232
|
+
var _iterator = _createForOfIteratorHelper(this.cache.entries()),
|
|
233
|
+
_step;
|
|
234
|
+
try {
|
|
235
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
236
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
|
237
|
+
key = _step$value[0],
|
|
238
|
+
entry = _step$value[1];
|
|
239
|
+
if (now - entry.timestamp > this.config.ttl) {
|
|
240
|
+
this.cache.delete(key);
|
|
241
|
+
removed++;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
} catch (err) {
|
|
245
|
+
_iterator.e(err);
|
|
246
|
+
} finally {
|
|
247
|
+
_iterator.f();
|
|
248
|
+
}
|
|
249
|
+
return removed;
|
|
250
|
+
}
|
|
251
|
+
}]);
|
|
252
|
+
return PathCache;
|
|
253
|
+
}();
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Global path cache instance (singleton)
|
|
257
|
+
*/
|
|
258
|
+
var globalPathCache = null;
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Get the global path cache instance
|
|
262
|
+
*/
|
|
263
|
+
export function getGlobalPathCache() {
|
|
264
|
+
if (!globalPathCache) {
|
|
265
|
+
globalPathCache = new PathCache();
|
|
266
|
+
}
|
|
267
|
+
return globalPathCache;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Reset the global path cache (useful for testing)
|
|
272
|
+
*/
|
|
273
|
+
export function resetGlobalPathCache() {
|
|
274
|
+
if (globalPathCache) {
|
|
275
|
+
globalPathCache.clear();
|
|
276
|
+
}
|
|
277
|
+
globalPathCache = null;
|
|
278
|
+
}
|