@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
|
@@ -0,0 +1,499 @@
|
|
|
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 _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; } } }; }
|
|
3
|
+
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); }
|
|
4
|
+
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; }
|
|
5
|
+
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; }
|
|
6
|
+
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; }
|
|
7
|
+
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; }
|
|
8
|
+
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); } }
|
|
9
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
11
|
+
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); }
|
|
12
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
13
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
14
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
15
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
16
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
17
|
+
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
|
|
18
|
+
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
|
19
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
20
|
+
function _isNativeFunction(fn) { try { return Function.toString.call(fn).indexOf("[native code]") !== -1; } catch (e) { return typeof fn === "function"; } }
|
|
21
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
22
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
23
|
+
/**
|
|
24
|
+
* ErrorRecovery - 错误恢复和降级策略
|
|
25
|
+
*
|
|
26
|
+
* 提供路径计算失败时的恢复机制,包括:
|
|
27
|
+
* - 超时检测和处理
|
|
28
|
+
* - 降级路径生成
|
|
29
|
+
* - 错误分类和报告
|
|
30
|
+
*
|
|
31
|
+
* Implements: Requirements 4.2, 3.6
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
import { Point } from "../geometry";
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 错误类型枚举
|
|
38
|
+
*/
|
|
39
|
+
export var PathfindingErrorType = /*#__PURE__*/function (PathfindingErrorType) {
|
|
40
|
+
PathfindingErrorType["TIMEOUT"] = "TIMEOUT";
|
|
41
|
+
PathfindingErrorType["NO_PATH"] = "NO_PATH";
|
|
42
|
+
PathfindingErrorType["INVALID_INPUT"] = "INVALID_INPUT";
|
|
43
|
+
PathfindingErrorType["BLOCKED"] = "BLOCKED";
|
|
44
|
+
PathfindingErrorType["INTERNAL"] = "INTERNAL";
|
|
45
|
+
return PathfindingErrorType;
|
|
46
|
+
}({});
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 路径计算错误
|
|
50
|
+
*/
|
|
51
|
+
export var PathfindingError = /*#__PURE__*/function (_Error) {
|
|
52
|
+
_inherits(PathfindingError, _Error);
|
|
53
|
+
var _super = _createSuper(PathfindingError);
|
|
54
|
+
function PathfindingError(type, message, details) {
|
|
55
|
+
var _this;
|
|
56
|
+
_classCallCheck(this, PathfindingError);
|
|
57
|
+
_this = _super.call(this, message);
|
|
58
|
+
_this.type = type;
|
|
59
|
+
_this.details = details;
|
|
60
|
+
_this.name = 'PathfindingError';
|
|
61
|
+
return _this;
|
|
62
|
+
}
|
|
63
|
+
return _createClass(PathfindingError);
|
|
64
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 恢复策略类型
|
|
68
|
+
*/
|
|
69
|
+
export var RecoveryStrategy = /*#__PURE__*/function (RecoveryStrategy) {
|
|
70
|
+
RecoveryStrategy["DIRECT_LINE"] = "DIRECT_LINE";
|
|
71
|
+
RecoveryStrategy["L_SHAPE"] = "L_SHAPE";
|
|
72
|
+
RecoveryStrategy["Z_SHAPE"] = "Z_SHAPE";
|
|
73
|
+
RecoveryStrategy["SIMPLE_MANHATTAN"] = "SIMPLE_MANHATTAN";
|
|
74
|
+
RecoveryStrategy["NONE"] = "NONE";
|
|
75
|
+
return RecoveryStrategy;
|
|
76
|
+
}({});
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 恢复结果
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 错误恢复配置
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 默认恢复配置
|
|
88
|
+
*/
|
|
89
|
+
export var DEFAULT_RECOVERY_CONFIG = {
|
|
90
|
+
enabled: true,
|
|
91
|
+
maxAttempts: 3,
|
|
92
|
+
strategyPriority: [RecoveryStrategy.SIMPLE_MANHATTAN, RecoveryStrategy.L_SHAPE, RecoveryStrategy.Z_SHAPE, RecoveryStrategy.DIRECT_LINE],
|
|
93
|
+
logRecovery: false
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 错误恢复类
|
|
98
|
+
*/
|
|
99
|
+
export var ErrorRecovery = /*#__PURE__*/function () {
|
|
100
|
+
function ErrorRecovery() {
|
|
101
|
+
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
102
|
+
_classCallCheck(this, ErrorRecovery);
|
|
103
|
+
_defineProperty(this, "config", void 0);
|
|
104
|
+
_defineProperty(this, "recoveryAttempts", 0);
|
|
105
|
+
this.config = _objectSpread(_objectSpread({}, DEFAULT_RECOVERY_CONFIG), config);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 尝试恢复路径计算
|
|
110
|
+
*/
|
|
111
|
+
_createClass(ErrorRecovery, [{
|
|
112
|
+
key: "recover",
|
|
113
|
+
value: function recover(from, to, error, obstacles) {
|
|
114
|
+
var startTime = performance.now();
|
|
115
|
+
if (!this.config.enabled) {
|
|
116
|
+
return {
|
|
117
|
+
success: false,
|
|
118
|
+
path: [],
|
|
119
|
+
strategy: RecoveryStrategy.NONE,
|
|
120
|
+
originalError: error,
|
|
121
|
+
recoveryTime: performance.now() - startTime
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
this.recoveryAttempts = 0;
|
|
125
|
+
var _iterator = _createForOfIteratorHelper(this.config.strategyPriority),
|
|
126
|
+
_step;
|
|
127
|
+
try {
|
|
128
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
129
|
+
var strategy = _step.value;
|
|
130
|
+
if (this.recoveryAttempts >= this.config.maxAttempts) {
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
this.recoveryAttempts++;
|
|
134
|
+
var path = this.applyStrategy(strategy, from, to, obstacles);
|
|
135
|
+
if (path.length > 0) {
|
|
136
|
+
if (this.config.logRecovery) {
|
|
137
|
+
console.info("[ErrorRecovery] Recovered using ".concat(strategy, " after ").concat(this.recoveryAttempts, " attempts"));
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
success: true,
|
|
141
|
+
path: path,
|
|
142
|
+
strategy: strategy,
|
|
143
|
+
originalError: error,
|
|
144
|
+
recoveryTime: performance.now() - startTime
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// 所有策略都失败,返回直线作为最后手段
|
|
150
|
+
} catch (err) {
|
|
151
|
+
_iterator.e(err);
|
|
152
|
+
} finally {
|
|
153
|
+
_iterator.f();
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
success: true,
|
|
157
|
+
path: [from, to],
|
|
158
|
+
strategy: RecoveryStrategy.DIRECT_LINE,
|
|
159
|
+
originalError: error,
|
|
160
|
+
recoveryTime: performance.now() - startTime
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* 应用恢复策略
|
|
166
|
+
*/
|
|
167
|
+
}, {
|
|
168
|
+
key: "applyStrategy",
|
|
169
|
+
value: function applyStrategy(strategy, from, to, obstacles) {
|
|
170
|
+
switch (strategy) {
|
|
171
|
+
case RecoveryStrategy.DIRECT_LINE:
|
|
172
|
+
return this.directLine(from, to);
|
|
173
|
+
case RecoveryStrategy.L_SHAPE:
|
|
174
|
+
return this.lShape(from, to, obstacles);
|
|
175
|
+
case RecoveryStrategy.Z_SHAPE:
|
|
176
|
+
return this.zShape(from, to, obstacles);
|
|
177
|
+
case RecoveryStrategy.SIMPLE_MANHATTAN:
|
|
178
|
+
return this.simpleManhattan(from, to, obstacles);
|
|
179
|
+
default:
|
|
180
|
+
return [];
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* 直线连接策略
|
|
186
|
+
*/
|
|
187
|
+
}, {
|
|
188
|
+
key: "directLine",
|
|
189
|
+
value: function directLine(from, to) {
|
|
190
|
+
return [from, to];
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* L形路径策略
|
|
195
|
+
*/
|
|
196
|
+
}, {
|
|
197
|
+
key: "lShape",
|
|
198
|
+
value: function lShape(from, to, obstacles) {
|
|
199
|
+
// 尝试先水平后垂直
|
|
200
|
+
var corner1 = new Point(to.x, from.y);
|
|
201
|
+
var path1 = [from, corner1, to];
|
|
202
|
+
if (!obstacles || !this.pathIntersectsObstacles(path1, obstacles)) {
|
|
203
|
+
return path1;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// 尝试先垂直后水平
|
|
207
|
+
var corner2 = new Point(from.x, to.y);
|
|
208
|
+
var path2 = [from, corner2, to];
|
|
209
|
+
if (!obstacles || !this.pathIntersectsObstacles(path2, obstacles)) {
|
|
210
|
+
return path2;
|
|
211
|
+
}
|
|
212
|
+
return [];
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Z形路径策略
|
|
217
|
+
*/
|
|
218
|
+
}, {
|
|
219
|
+
key: "zShape",
|
|
220
|
+
value: function zShape(from, to, obstacles) {
|
|
221
|
+
var midX = (from.x + to.x) / 2;
|
|
222
|
+
var midY = (from.y + to.y) / 2;
|
|
223
|
+
|
|
224
|
+
// 尝试水平-垂直-水平 Z形
|
|
225
|
+
var path1 = [from, new Point(midX, from.y), new Point(midX, to.y), to];
|
|
226
|
+
if (!obstacles || !this.pathIntersectsObstacles(path1, obstacles)) {
|
|
227
|
+
return path1;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// 尝试垂直-水平-垂直 Z形
|
|
231
|
+
var path2 = [from, new Point(from.x, midY), new Point(to.x, midY), to];
|
|
232
|
+
if (!obstacles || !this.pathIntersectsObstacles(path2, obstacles)) {
|
|
233
|
+
return path2;
|
|
234
|
+
}
|
|
235
|
+
return [];
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* 简化曼哈顿路径策略
|
|
240
|
+
*/
|
|
241
|
+
}, {
|
|
242
|
+
key: "simpleManhattan",
|
|
243
|
+
value: function simpleManhattan(from, to, obstacles) {
|
|
244
|
+
var offsets = [0.25, 0.5, 0.75, 0.1, 0.9];
|
|
245
|
+
for (var _i = 0, _offsets = offsets; _i < _offsets.length; _i++) {
|
|
246
|
+
var offset = _offsets[_i];
|
|
247
|
+
// 水平方向偏移
|
|
248
|
+
var midX = from.x + (to.x - from.x) * offset;
|
|
249
|
+
var path1 = [from, new Point(midX, from.y), new Point(midX, to.y), to];
|
|
250
|
+
if (!obstacles || !this.pathIntersectsObstacles(path1, obstacles)) {
|
|
251
|
+
return path1;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// 垂直方向偏移
|
|
255
|
+
var midY = from.y + (to.y - from.y) * offset;
|
|
256
|
+
var path2 = [from, new Point(from.x, midY), new Point(to.x, midY), to];
|
|
257
|
+
if (!obstacles || !this.pathIntersectsObstacles(path2, obstacles)) {
|
|
258
|
+
return path2;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return [];
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* 检查路径是否与障碍物相交
|
|
266
|
+
*/
|
|
267
|
+
}, {
|
|
268
|
+
key: "pathIntersectsObstacles",
|
|
269
|
+
value: function pathIntersectsObstacles(path, obstacles) {
|
|
270
|
+
for (var i = 0; i < path.length - 1; i++) {
|
|
271
|
+
var p1 = path[i];
|
|
272
|
+
var p2 = path[i + 1];
|
|
273
|
+
var _iterator2 = _createForOfIteratorHelper(obstacles),
|
|
274
|
+
_step2;
|
|
275
|
+
try {
|
|
276
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
277
|
+
var obstacle = _step2.value;
|
|
278
|
+
if (this.lineIntersectsRect(p1, p2, obstacle)) {
|
|
279
|
+
return true;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
} catch (err) {
|
|
283
|
+
_iterator2.e(err);
|
|
284
|
+
} finally {
|
|
285
|
+
_iterator2.f();
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* 检查线段是否与矩形相交
|
|
293
|
+
*/
|
|
294
|
+
}, {
|
|
295
|
+
key: "lineIntersectsRect",
|
|
296
|
+
value: function lineIntersectsRect(p1, p2, rect) {
|
|
297
|
+
var minX = rect.x;
|
|
298
|
+
var maxX = rect.x + rect.width;
|
|
299
|
+
var minY = rect.y;
|
|
300
|
+
var maxY = rect.y + rect.height;
|
|
301
|
+
|
|
302
|
+
// 检查线段是否完全在矩形外部
|
|
303
|
+
if (p1.x < minX && p2.x < minX || p1.x > maxX && p2.x > maxX || p1.y < minY && p2.y < minY || p1.y > maxY && p2.y > maxY) {
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// 检查线段端点是否在矩形内部
|
|
308
|
+
if (this.pointInRect(p1, rect) || this.pointInRect(p2, rect)) {
|
|
309
|
+
return true;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// 检查线段是否与矩形的四条边相交
|
|
313
|
+
return this.lineIntersectsLine(p1, p2, new Point(minX, minY), new Point(maxX, minY)) || this.lineIntersectsLine(p1, p2, new Point(maxX, minY), new Point(maxX, maxY)) || this.lineIntersectsLine(p1, p2, new Point(maxX, maxY), new Point(minX, maxY)) || this.lineIntersectsLine(p1, p2, new Point(minX, maxY), new Point(minX, minY));
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* 检查点是否在矩形内部
|
|
318
|
+
*/
|
|
319
|
+
}, {
|
|
320
|
+
key: "pointInRect",
|
|
321
|
+
value: function pointInRect(p, rect) {
|
|
322
|
+
return p.x > rect.x && p.x < rect.x + rect.width && p.y > rect.y && p.y < rect.y + rect.height;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* 检查两条线段是否相交
|
|
327
|
+
*/
|
|
328
|
+
}, {
|
|
329
|
+
key: "lineIntersectsLine",
|
|
330
|
+
value: function lineIntersectsLine(p1, p2, p3, p4) {
|
|
331
|
+
var d1 = this.direction(p3, p4, p1);
|
|
332
|
+
var d2 = this.direction(p3, p4, p2);
|
|
333
|
+
var d3 = this.direction(p1, p2, p3);
|
|
334
|
+
var d4 = this.direction(p1, p2, p4);
|
|
335
|
+
if ((d1 > 0 && d2 < 0 || d1 < 0 && d2 > 0) && (d3 > 0 && d4 < 0 || d3 < 0 && d4 > 0)) {
|
|
336
|
+
return true;
|
|
337
|
+
}
|
|
338
|
+
if (d1 === 0 && this.onSegment(p3, p4, p1)) return true;
|
|
339
|
+
if (d2 === 0 && this.onSegment(p3, p4, p2)) return true;
|
|
340
|
+
if (d3 === 0 && this.onSegment(p1, p2, p3)) return true;
|
|
341
|
+
if (d4 === 0 && this.onSegment(p1, p2, p4)) return true;
|
|
342
|
+
return false;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* 计算叉积方向
|
|
347
|
+
*/
|
|
348
|
+
}, {
|
|
349
|
+
key: "direction",
|
|
350
|
+
value: function direction(p1, p2, p3) {
|
|
351
|
+
return (p3.x - p1.x) * (p2.y - p1.y) - (p2.x - p1.x) * (p3.y - p1.y);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* 检查点是否在线段上
|
|
356
|
+
*/
|
|
357
|
+
}, {
|
|
358
|
+
key: "onSegment",
|
|
359
|
+
value: function onSegment(p1, p2, p) {
|
|
360
|
+
return p.x >= Math.min(p1.x, p2.x) && p.x <= Math.max(p1.x, p2.x) && p.y >= Math.min(p1.y, p2.y) && p.y <= Math.max(p1.y, p2.y);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* 创建超时错误
|
|
365
|
+
*/
|
|
366
|
+
}, {
|
|
367
|
+
key: "getRecoveryAttempts",
|
|
368
|
+
value:
|
|
369
|
+
/**
|
|
370
|
+
* 获取恢复尝试次数
|
|
371
|
+
*/
|
|
372
|
+
function getRecoveryAttempts() {
|
|
373
|
+
return this.recoveryAttempts;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* 重置恢复状态
|
|
378
|
+
*/
|
|
379
|
+
}, {
|
|
380
|
+
key: "reset",
|
|
381
|
+
value: function reset() {
|
|
382
|
+
this.recoveryAttempts = 0;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* 更新配置
|
|
387
|
+
*/
|
|
388
|
+
}, {
|
|
389
|
+
key: "updateConfig",
|
|
390
|
+
value: function updateConfig(config) {
|
|
391
|
+
this.config = _objectSpread(_objectSpread({}, this.config), config);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* 获取当前配置
|
|
396
|
+
*/
|
|
397
|
+
}, {
|
|
398
|
+
key: "getConfig",
|
|
399
|
+
value: function getConfig() {
|
|
400
|
+
return _objectSpread({}, this.config);
|
|
401
|
+
}
|
|
402
|
+
}], [{
|
|
403
|
+
key: "createTimeoutError",
|
|
404
|
+
value: function createTimeoutError(iterations, maxIterations) {
|
|
405
|
+
return new PathfindingError(PathfindingErrorType.TIMEOUT, "Pathfinding timeout: exceeded ".concat(maxIterations, " iterations"), {
|
|
406
|
+
iterations: iterations,
|
|
407
|
+
maxIterations: maxIterations
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* 创建无路径错误
|
|
413
|
+
*/
|
|
414
|
+
}, {
|
|
415
|
+
key: "createNoPathError",
|
|
416
|
+
value: function createNoPathError(from, to) {
|
|
417
|
+
return new PathfindingError(PathfindingErrorType.NO_PATH, "No path found from (".concat(from.x, ", ").concat(from.y, ") to (").concat(to.x, ", ").concat(to.y, ")"), {
|
|
418
|
+
from: {
|
|
419
|
+
x: from.x,
|
|
420
|
+
y: from.y
|
|
421
|
+
},
|
|
422
|
+
to: {
|
|
423
|
+
x: to.x,
|
|
424
|
+
y: to.y
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* 创建无效输入错误
|
|
431
|
+
*/
|
|
432
|
+
}, {
|
|
433
|
+
key: "createInvalidInputError",
|
|
434
|
+
value: function createInvalidInputError(message) {
|
|
435
|
+
return new PathfindingError(PathfindingErrorType.INVALID_INPUT, message);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* 创建阻塞错误
|
|
440
|
+
*/
|
|
441
|
+
}, {
|
|
442
|
+
key: "createBlockedError",
|
|
443
|
+
value: function createBlockedError(point, type) {
|
|
444
|
+
return new PathfindingError(PathfindingErrorType.BLOCKED, "".concat(type === 'source' ? 'Source' : 'Target', " point (").concat(point.x, ", ").concat(point.y, ") is blocked"), {
|
|
445
|
+
point: {
|
|
446
|
+
x: point.x,
|
|
447
|
+
y: point.y
|
|
448
|
+
},
|
|
449
|
+
type: type
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* 创建内部错误
|
|
455
|
+
*/
|
|
456
|
+
}, {
|
|
457
|
+
key: "createInternalError",
|
|
458
|
+
value: function createInternalError(message, cause) {
|
|
459
|
+
return new PathfindingError(PathfindingErrorType.INTERNAL, message, {
|
|
460
|
+
cause: cause === null || cause === void 0 ? void 0 : cause.message
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* 生成回退路径(静态方法)
|
|
466
|
+
*/
|
|
467
|
+
}, {
|
|
468
|
+
key: "generateFallbackPath",
|
|
469
|
+
value: function generateFallbackPath(source, target) {
|
|
470
|
+
var midX = (source.x + target.x) / 2;
|
|
471
|
+
return [source, new Point(midX, source.y), new Point(midX, target.y), target];
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* 验证并修复配置选项
|
|
476
|
+
*/
|
|
477
|
+
}, {
|
|
478
|
+
key: "validateAndFixOptions",
|
|
479
|
+
value: function validateAndFixOptions(options, defaults) {
|
|
480
|
+
var fixed = _objectSpread({}, options);
|
|
481
|
+
for (var _i2 = 0, _Object$keys = Object.keys(defaults); _i2 < _Object$keys.length; _i2++) {
|
|
482
|
+
var key = _Object$keys[_i2];
|
|
483
|
+
var value = fixed[key];
|
|
484
|
+
var defaultValue = defaults[key];
|
|
485
|
+
if (value === undefined || value === null) {
|
|
486
|
+
;
|
|
487
|
+
fixed[key] = defaultValue;
|
|
488
|
+
} else if (typeof defaultValue === 'number' && typeof value === 'number') {
|
|
489
|
+
if (value <= 0 && defaultValue > 0) {
|
|
490
|
+
console.warn("Invalid ".concat(key, " value (").concat(value, "), using default (").concat(defaultValue, ")"));
|
|
491
|
+
fixed[key] = defaultValue;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
return fixed;
|
|
496
|
+
}
|
|
497
|
+
}]);
|
|
498
|
+
return ErrorRecovery;
|
|
499
|
+
}();
|