@rxflow/manhattan 0.0.1-alpha.8 → 0.0.1
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/Rectangle.d.ts +1 -1
- package/cjs/geometry/Rectangle.js +2 -2
- package/cjs/getManHattanPath.d.ts.map +1 -1
- package/cjs/getManHattanPath.js +169 -34
- package/cjs/obstacle/ObstacleMap.d.ts +7 -1
- package/cjs/obstacle/ObstacleMap.d.ts.map +1 -1
- package/cjs/obstacle/ObstacleMap.js +53 -1
- package/cjs/options/defaults.d.ts +1 -1
- package/cjs/options/defaults.d.ts.map +1 -1
- package/cjs/options/defaults.js +2 -2
- package/cjs/options/resolver.d.ts.map +1 -1
- package/cjs/options/resolver.js +4 -2
- package/cjs/options/types.d.ts +19 -6
- package/cjs/options/types.d.ts.map +1 -1
- package/cjs/pathfinder/findRoute.d.ts.map +1 -1
- package/cjs/pathfinder/findRoute.js +187 -13
- package/cjs/svg/pathConverter.d.ts.map +1 -1
- package/cjs/svg/pathConverter.js +23 -12
- package/cjs/utils/getAnchorPoints.d.ts +15 -0
- package/cjs/utils/getAnchorPoints.d.ts.map +1 -0
- package/cjs/utils/getAnchorPoints.js +75 -0
- package/cjs/utils/grid.d.ts +1 -0
- package/cjs/utils/grid.d.ts.map +1 -1
- package/cjs/utils/grid.js +6 -18
- package/cjs/utils/index.d.ts +1 -0
- package/cjs/utils/index.d.ts.map +1 -1
- package/cjs/utils/index.js +11 -0
- package/esm/geometry/Rectangle.d.ts +1 -1
- package/esm/geometry/Rectangle.js +2 -2
- package/esm/getManHattanPath.d.ts.map +1 -1
- package/esm/getManHattanPath.js +186 -44
- package/esm/obstacle/ObstacleMap.d.ts +7 -1
- package/esm/obstacle/ObstacleMap.d.ts.map +1 -1
- package/esm/obstacle/ObstacleMap.js +78 -0
- package/esm/options/defaults.d.ts +1 -1
- package/esm/options/defaults.d.ts.map +1 -1
- package/esm/options/defaults.js +2 -2
- package/esm/options/resolver.d.ts.map +1 -1
- package/esm/options/resolver.js +5 -3
- package/esm/options/types.d.ts +19 -6
- package/esm/options/types.d.ts.map +1 -1
- package/esm/pathfinder/findRoute.d.ts.map +1 -1
- package/esm/pathfinder/findRoute.js +209 -21
- package/esm/svg/pathConverter.d.ts.map +1 -1
- package/esm/svg/pathConverter.js +23 -12
- package/esm/utils/getAnchorPoints.d.ts +15 -0
- package/esm/utils/getAnchorPoints.d.ts.map +1 -0
- package/esm/utils/getAnchorPoints.js +69 -0
- package/esm/utils/grid.d.ts +1 -0
- package/esm/utils/grid.d.ts.map +1 -1
- package/esm/utils/grid.js +6 -18
- package/esm/utils/index.d.ts +1 -0
- package/esm/utils/index.d.ts.map +1 -1
- package/esm/utils/index.js +2 -1
- package/package.json +1 -1
package/esm/getManHattanPath.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
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); }
|
|
1
2
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
3
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
4
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
@@ -8,12 +9,17 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
8
9
|
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
10
|
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; } }
|
|
10
11
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
+
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; }
|
|
13
|
+
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; }
|
|
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); }
|
|
11
17
|
import { getSmoothStepPath } from '@xyflow/react';
|
|
12
18
|
import { Point, Rectangle } from "./geometry";
|
|
13
19
|
import { ObstacleMap } from "./obstacle";
|
|
14
20
|
import { resolveOptions } from "./options";
|
|
15
21
|
import { findRoute } from "./pathfinder";
|
|
16
|
-
import { pointsToPath,
|
|
22
|
+
import { pointsToPath, parseSVGPath } from "./svg";
|
|
17
23
|
import { getNodeDimensions, getNodePosition, pathIntersectsObstacles } from "./utils";
|
|
18
24
|
|
|
19
25
|
/**
|
|
@@ -55,8 +61,17 @@ export function getManHattanPath(params) {
|
|
|
55
61
|
_params$options = params.options,
|
|
56
62
|
userOptions = _params$options === void 0 ? {} : _params$options;
|
|
57
63
|
|
|
58
|
-
// Resolve options
|
|
59
|
-
var options = resolveOptions(userOptions)
|
|
64
|
+
// Resolve options and add position information
|
|
65
|
+
var options = resolveOptions(_objectSpread(_objectSpread({}, userOptions), {}, {
|
|
66
|
+
sourcePosition: sourcePosition,
|
|
67
|
+
targetPosition: targetPosition
|
|
68
|
+
}));
|
|
69
|
+
|
|
70
|
+
// Direction control is automatically handled by getRectPoints:
|
|
71
|
+
// - When anchor is on an edge, only outward directions are allowed (via isDirectionOutward)
|
|
72
|
+
// - For sourcePosition="right": anchor on right edge -> only extends right
|
|
73
|
+
// - For targetPosition="left": anchor on left edge -> path approaches from right (outward from left)
|
|
74
|
+
// This ensures paths follow the sourcePosition and targetPosition constraints
|
|
60
75
|
|
|
61
76
|
// Get source and target nodes
|
|
62
77
|
var sourceNode = nodeLookup.get(sourceNodeId);
|
|
@@ -125,6 +140,19 @@ export function getManHattanPath(params) {
|
|
|
125
140
|
console.log('[getManHattanPath] Source anchor:', "(".concat(sourceAnchor.x, ", ").concat(sourceAnchor.y, ")"));
|
|
126
141
|
console.log('[getManHattanPath] Target anchor:', "(".concat(targetAnchor.x, ", ").concat(targetAnchor.y, ")"));
|
|
127
142
|
|
|
143
|
+
// If using smart point generation (sourcePosition/targetPosition specified),
|
|
144
|
+
// the route already contains the correct extension points, so skip manual processing
|
|
145
|
+
var useSmartPoints = sourcePosition || targetPosition;
|
|
146
|
+
if (useSmartPoints) {
|
|
147
|
+
console.log('[getManHattanPath] Using smart points, skipping manual extension point processing');
|
|
148
|
+
// Add source and target anchors to route
|
|
149
|
+
var _finalRoute = [sourceAnchor].concat(_toConsumableArray(route), [targetAnchor]);
|
|
150
|
+
console.log('[getManHattanPath] Final route:', _finalRoute.map(function (p) {
|
|
151
|
+
return "(".concat(p.x, ", ").concat(p.y, ")");
|
|
152
|
+
}));
|
|
153
|
+
return pointsToPath(_finalRoute, options.precision, options.borderRadius);
|
|
154
|
+
}
|
|
155
|
+
|
|
128
156
|
// Remove extension points from route that were added by getRectPoints
|
|
129
157
|
// We will add our own with fixed step distance
|
|
130
158
|
var step = options.step;
|
|
@@ -168,8 +196,9 @@ export function getManHattanPath(params) {
|
|
|
168
196
|
}
|
|
169
197
|
}
|
|
170
198
|
|
|
171
|
-
// Insert extension point at source - always extend away from node edge by fixed
|
|
199
|
+
// Insert extension point at source - always extend away from node edge by fixed distance
|
|
172
200
|
if (route.length > 0) {
|
|
201
|
+
var extensionDistance = options.extensionDistance;
|
|
173
202
|
var _firstPoint = route[0];
|
|
174
203
|
|
|
175
204
|
// Determine which edge the source anchor is on
|
|
@@ -180,8 +209,8 @@ export function getManHattanPath(params) {
|
|
|
180
209
|
|
|
181
210
|
// Insert extension point and corner point to ensure orthogonal path
|
|
182
211
|
if (_onRight2) {
|
|
183
|
-
// Anchor on right edge - extend right by
|
|
184
|
-
var extendX = sourceAnchor.x +
|
|
212
|
+
// Anchor on right edge - extend right by step + borderRadius
|
|
213
|
+
var extendX = sourceAnchor.x + extensionDistance;
|
|
185
214
|
var extensionPoint = new Point(extendX, sourceAnchor.y);
|
|
186
215
|
// Check if we need a corner point
|
|
187
216
|
if (Math.abs(extensionPoint.y - _firstPoint.y) > tolerance) {
|
|
@@ -190,8 +219,8 @@ export function getManHattanPath(params) {
|
|
|
190
219
|
route.unshift(extensionPoint); // Extension point (fixed distance)
|
|
191
220
|
console.log('[getManHattanPath] Inserted source extension (right):', "(".concat(extendX, ", ").concat(sourceAnchor.y, ")"));
|
|
192
221
|
} else if (_onLeft2) {
|
|
193
|
-
// Anchor on left edge - extend left by
|
|
194
|
-
var _extendX = sourceAnchor.x -
|
|
222
|
+
// Anchor on left edge - extend left by step + borderRadius
|
|
223
|
+
var _extendX = sourceAnchor.x - extensionDistance;
|
|
195
224
|
var _extensionPoint = new Point(_extendX, sourceAnchor.y);
|
|
196
225
|
if (Math.abs(_extensionPoint.y - _firstPoint.y) > tolerance) {
|
|
197
226
|
route.unshift(new Point(_extendX, _firstPoint.y));
|
|
@@ -199,8 +228,8 @@ export function getManHattanPath(params) {
|
|
|
199
228
|
route.unshift(_extensionPoint);
|
|
200
229
|
console.log('[getManHattanPath] Inserted source extension (left):', "(".concat(_extendX, ", ").concat(sourceAnchor.y, ")"));
|
|
201
230
|
} else if (_onBottom2) {
|
|
202
|
-
// Anchor on bottom edge - extend down by
|
|
203
|
-
var extendY = sourceAnchor.y +
|
|
231
|
+
// Anchor on bottom edge - extend down by step + borderRadius
|
|
232
|
+
var extendY = sourceAnchor.y + extensionDistance;
|
|
204
233
|
var _extensionPoint2 = new Point(sourceAnchor.x, extendY);
|
|
205
234
|
if (Math.abs(_extensionPoint2.x - _firstPoint.x) > tolerance) {
|
|
206
235
|
route.unshift(new Point(_firstPoint.x, extendY));
|
|
@@ -208,8 +237,8 @@ export function getManHattanPath(params) {
|
|
|
208
237
|
route.unshift(_extensionPoint2);
|
|
209
238
|
console.log('[getManHattanPath] Inserted source extension (down):', "(".concat(sourceAnchor.x, ", ").concat(extendY, ")"));
|
|
210
239
|
} else if (_onTop2) {
|
|
211
|
-
// Anchor on top edge - extend up by
|
|
212
|
-
var _extendY = sourceAnchor.y -
|
|
240
|
+
// Anchor on top edge - extend up by step + borderRadius
|
|
241
|
+
var _extendY = sourceAnchor.y - extensionDistance;
|
|
213
242
|
var _extensionPoint3 = new Point(sourceAnchor.x, _extendY);
|
|
214
243
|
if (Math.abs(_extensionPoint3.x - _firstPoint.x) > tolerance) {
|
|
215
244
|
route.unshift(new Point(_firstPoint.x, _extendY));
|
|
@@ -219,51 +248,118 @@ export function getManHattanPath(params) {
|
|
|
219
248
|
}
|
|
220
249
|
}
|
|
221
250
|
|
|
222
|
-
//
|
|
251
|
+
// Remove redundant points after source extension
|
|
252
|
+
// If the first route point has the same x or y coordinate as the source anchor, it's redundant
|
|
253
|
+
if (route.length > 2) {
|
|
254
|
+
var firstRoutePoint = route[0]; // Extension point
|
|
255
|
+
var secondRoutePoint = route[1]; // Corner point (if exists)
|
|
256
|
+
var thirdRoutePoint = route[2]; // Original A* point
|
|
257
|
+
|
|
258
|
+
// Check if the third point (original A* point) is redundant
|
|
259
|
+
// It's redundant if it's on the same line as the corner point and can be skipped
|
|
260
|
+
var sameX = Math.abs(thirdRoutePoint.x - sourceAnchor.x) < tolerance;
|
|
261
|
+
var sameY = Math.abs(thirdRoutePoint.y - sourceAnchor.y) < tolerance;
|
|
262
|
+
if (sameX || sameY) {
|
|
263
|
+
// The third point is aligned with the source anchor, likely redundant
|
|
264
|
+
// Check if we can skip it by connecting corner point directly to the next point
|
|
265
|
+
if (route.length > 3) {
|
|
266
|
+
var fourthPoint = route[3];
|
|
267
|
+
// If corner point and fourth point form a straight line, remove the third point
|
|
268
|
+
var cornerToThird = Math.abs(secondRoutePoint.x - thirdRoutePoint.x) < tolerance || Math.abs(secondRoutePoint.y - thirdRoutePoint.y) < tolerance;
|
|
269
|
+
var thirdToFourth = Math.abs(thirdRoutePoint.x - fourthPoint.x) < tolerance || Math.abs(thirdRoutePoint.y - fourthPoint.y) < tolerance;
|
|
270
|
+
if (cornerToThird && thirdToFourth) {
|
|
271
|
+
console.log('[getManHattanPath] Removing redundant point:', "(".concat(thirdRoutePoint.x, ", ").concat(thirdRoutePoint.y, ")"));
|
|
272
|
+
route.splice(2, 1); // Remove the third point
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Optimize zigzag patterns BEFORE inserting target extension
|
|
279
|
+
// Check for patterns like: (1360, 16) -> (815, 16) -> (815, -134)
|
|
280
|
+
// where the middle segment goes to target edge and then moves along it
|
|
281
|
+
// Use target bbox with padding (same as ObstacleMap)
|
|
282
|
+
var targetBBoxWithPadding = targetBBox.moveAndExpand(options.paddingBox);
|
|
283
|
+
console.log('[getManHattanPath] Route before zigzag check:', route.map(function (p) {
|
|
284
|
+
return "(".concat(p.x, ", ").concat(p.y, ")");
|
|
285
|
+
}));
|
|
286
|
+
console.log('[getManHattanPath] Target BBox with padding:', "x=".concat(targetBBoxWithPadding.x, ", y=").concat(targetBBoxWithPadding.y));
|
|
287
|
+
if (route.length >= 3) {
|
|
288
|
+
var _i = 0;
|
|
289
|
+
while (_i < route.length - 2) {
|
|
290
|
+
var p1 = route[_i];
|
|
291
|
+
var p2 = route[_i + 1];
|
|
292
|
+
var p3 = route[_i + 2];
|
|
293
|
+
|
|
294
|
+
// Check if p2 is on the target bbox edge (with padding)
|
|
295
|
+
var p2OnTargetLeftEdge = Math.abs(p2.x - targetBBoxWithPadding.x) < tolerance;
|
|
296
|
+
var p2OnTargetRightEdge = Math.abs(p2.x - (targetBBoxWithPadding.x + targetBBoxWithPadding.width)) < tolerance;
|
|
297
|
+
var p2OnTargetTopEdge = Math.abs(p2.y - targetBBoxWithPadding.y) < tolerance;
|
|
298
|
+
var p2OnTargetBottomEdge = Math.abs(p2.y - (targetBBoxWithPadding.y + targetBBoxWithPadding.height)) < tolerance;
|
|
299
|
+
var p2OnTargetEdge = p2OnTargetLeftEdge || p2OnTargetRightEdge || p2OnTargetTopEdge || p2OnTargetBottomEdge;
|
|
300
|
+
console.log("[getManHattanPath] Checking i=".concat(_i, ": p2=(").concat(p2.x, ", ").concat(p2.y, "), onEdge=").concat(p2OnTargetEdge));
|
|
301
|
+
if (p2OnTargetEdge) {
|
|
302
|
+
// Check if p1 -> p2 -> p3 forms a zigzag
|
|
303
|
+
var p1ToP2Horizontal = Math.abs(p1.y - p2.y) < tolerance;
|
|
304
|
+
var p2ToP3Vertical = Math.abs(p2.x - p3.x) < tolerance;
|
|
305
|
+
var p1ToP2Vertical = Math.abs(p1.x - p2.x) < tolerance;
|
|
306
|
+
var p2ToP3Horizontal = Math.abs(p2.y - p3.y) < tolerance;
|
|
307
|
+
console.log("[getManHattanPath] Zigzag pattern: H->V=".concat(p1ToP2Horizontal && p2ToP3Vertical, ", V->H=").concat(p1ToP2Vertical && p2ToP3Horizontal));
|
|
308
|
+
if (p1ToP2Horizontal && p2ToP3Vertical || p1ToP2Vertical && p2ToP3Horizontal) {
|
|
309
|
+
// We have a zigzag at target edge, remove p2 and p3
|
|
310
|
+
console.log('[getManHattanPath] Removing zigzag at target edge:', "(".concat(p2.x, ", ").concat(p2.y, ")"), "and (".concat(p3.x, ", ").concat(p3.y, ")"));
|
|
311
|
+
route.splice(_i + 1, 2); // Remove p2 and p3
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
_i++;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// Insert extension point at target - always extend away from node edge by fixed distance
|
|
223
320
|
if (route.length > 0) {
|
|
224
|
-
var
|
|
225
|
-
var _tolerance = 1;
|
|
321
|
+
var _extensionDistance = options.extensionDistance;
|
|
226
322
|
var _lastPoint = route[route.length - 1];
|
|
227
323
|
|
|
228
324
|
// Determine which edge the target anchor is on
|
|
229
|
-
var _onLeft3 = Math.abs(targetAnchor.x - targetBBox.x) <
|
|
230
|
-
var _onRight3 = Math.abs(targetAnchor.x - (targetBBox.x + targetBBox.width)) <
|
|
231
|
-
var _onTop3 = Math.abs(targetAnchor.y - targetBBox.y) <
|
|
232
|
-
var _onBottom3 = Math.abs(targetAnchor.y - (targetBBox.y + targetBBox.height)) <
|
|
325
|
+
var _onLeft3 = Math.abs(targetAnchor.x - targetBBox.x) < tolerance;
|
|
326
|
+
var _onRight3 = Math.abs(targetAnchor.x - (targetBBox.x + targetBBox.width)) < tolerance;
|
|
327
|
+
var _onTop3 = Math.abs(targetAnchor.y - targetBBox.y) < tolerance;
|
|
328
|
+
var _onBottom3 = Math.abs(targetAnchor.y - (targetBBox.y + targetBBox.height)) < tolerance;
|
|
233
329
|
|
|
234
330
|
// Insert extension point and corner point to ensure orthogonal path
|
|
235
331
|
if (_onLeft3) {
|
|
236
|
-
// Anchor on left edge - extend left by
|
|
237
|
-
var _extendX2 = targetAnchor.x -
|
|
332
|
+
// Anchor on left edge - extend left by step + borderRadius
|
|
333
|
+
var _extendX2 = targetAnchor.x - _extensionDistance;
|
|
238
334
|
var _extensionPoint4 = new Point(_extendX2, targetAnchor.y);
|
|
239
|
-
if (Math.abs(_extensionPoint4.y - _lastPoint.y) >
|
|
335
|
+
if (Math.abs(_extensionPoint4.y - _lastPoint.y) > tolerance) {
|
|
240
336
|
route.push(new Point(_extendX2, _lastPoint.y)); // Corner point
|
|
241
337
|
}
|
|
242
338
|
route.push(_extensionPoint4); // Extension point (fixed distance)
|
|
243
339
|
console.log('[getManHattanPath] Inserted target extension (left):', "(".concat(_extendX2, ", ").concat(targetAnchor.y, ")"));
|
|
244
340
|
} else if (_onRight3) {
|
|
245
|
-
// Anchor on right edge - extend right by
|
|
246
|
-
var _extendX3 = targetAnchor.x +
|
|
341
|
+
// Anchor on right edge - extend right by step + borderRadius
|
|
342
|
+
var _extendX3 = targetAnchor.x + _extensionDistance;
|
|
247
343
|
var _extensionPoint5 = new Point(_extendX3, targetAnchor.y);
|
|
248
|
-
if (Math.abs(_extensionPoint5.y - _lastPoint.y) >
|
|
344
|
+
if (Math.abs(_extensionPoint5.y - _lastPoint.y) > tolerance) {
|
|
249
345
|
route.push(new Point(_extendX3, _lastPoint.y));
|
|
250
346
|
}
|
|
251
347
|
route.push(_extensionPoint5);
|
|
252
348
|
console.log('[getManHattanPath] Inserted target extension (right):', "(".concat(_extendX3, ", ").concat(targetAnchor.y, ")"));
|
|
253
349
|
} else if (_onTop3) {
|
|
254
|
-
// Anchor on top edge - extend up by
|
|
255
|
-
var _extendY2 = targetAnchor.y -
|
|
350
|
+
// Anchor on top edge - extend up by step + borderRadius
|
|
351
|
+
var _extendY2 = targetAnchor.y - _extensionDistance;
|
|
256
352
|
var _extensionPoint6 = new Point(targetAnchor.x, _extendY2);
|
|
257
|
-
if (Math.abs(_extensionPoint6.x - _lastPoint.x) >
|
|
353
|
+
if (Math.abs(_extensionPoint6.x - _lastPoint.x) > tolerance) {
|
|
258
354
|
route.push(new Point(_lastPoint.x, _extendY2));
|
|
259
355
|
}
|
|
260
356
|
route.push(_extensionPoint6);
|
|
261
357
|
console.log('[getManHattanPath] Inserted target extension (up):', "(".concat(targetAnchor.x, ", ").concat(_extendY2, ")"));
|
|
262
358
|
} else if (_onBottom3) {
|
|
263
|
-
// Anchor on bottom edge - extend down by
|
|
264
|
-
var _extendY3 = targetAnchor.y +
|
|
359
|
+
// Anchor on bottom edge - extend down by step + borderRadius
|
|
360
|
+
var _extendY3 = targetAnchor.y + _extensionDistance;
|
|
265
361
|
var _extensionPoint7 = new Point(targetAnchor.x, _extendY3);
|
|
266
|
-
if (Math.abs(_extensionPoint7.x - _lastPoint.x) >
|
|
362
|
+
if (Math.abs(_extensionPoint7.x - _lastPoint.x) > tolerance) {
|
|
267
363
|
route.push(new Point(_lastPoint.x, _extendY3));
|
|
268
364
|
}
|
|
269
365
|
route.push(_extensionPoint7);
|
|
@@ -271,22 +367,68 @@ export function getManHattanPath(params) {
|
|
|
271
367
|
}
|
|
272
368
|
}
|
|
273
369
|
|
|
274
|
-
//
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
370
|
+
// Remove redundant points before target extension
|
|
371
|
+
// Similar logic for target side
|
|
372
|
+
if (route.length > 2) {
|
|
373
|
+
var lastIdx = route.length - 1;
|
|
374
|
+
var lastRoutePoint = route[lastIdx]; // Extension point
|
|
375
|
+
var secondLastPoint = route[lastIdx - 1]; // Corner point (if exists)
|
|
376
|
+
var thirdLastPoint = route[lastIdx - 2]; // Original A* point
|
|
279
377
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
378
|
+
// Check if the third-to-last point is redundant
|
|
379
|
+
var _sameX = Math.abs(thirdLastPoint.x - targetAnchor.x) < tolerance;
|
|
380
|
+
var _sameY = Math.abs(thirdLastPoint.y - targetAnchor.y) < tolerance;
|
|
381
|
+
if (_sameX || _sameY) {
|
|
382
|
+
if (route.length > 3) {
|
|
383
|
+
var fourthLastPoint = route[lastIdx - 3];
|
|
384
|
+
var fourthToThird = Math.abs(fourthLastPoint.x - thirdLastPoint.x) < tolerance || Math.abs(fourthLastPoint.y - thirdLastPoint.y) < tolerance;
|
|
385
|
+
var thirdToSecond = Math.abs(thirdLastPoint.x - secondLastPoint.x) < tolerance || Math.abs(thirdLastPoint.y - secondLastPoint.y) < tolerance;
|
|
386
|
+
if (fourthToThird && thirdToSecond) {
|
|
387
|
+
console.log('[getManHattanPath] Removing redundant point:', "(".concat(thirdLastPoint.x, ", ").concat(thirdLastPoint.y, ")"));
|
|
388
|
+
route.splice(lastIdx - 2, 1); // Remove the third-to-last point
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
285
392
|
}
|
|
286
393
|
|
|
287
|
-
//
|
|
288
|
-
|
|
289
|
-
|
|
394
|
+
// Additional optimization: Remove unnecessary zigzag patterns near target
|
|
395
|
+
// Check for patterns like: (1360, 16) -> (815, 16) -> (815, -134) -> (800, -134)
|
|
396
|
+
// where (815, 16) and (815, -134) form a zigzag at the target edge
|
|
397
|
+
var i = 0;
|
|
398
|
+
while (i < route.length - 2) {
|
|
399
|
+
var _p = route[i];
|
|
400
|
+
var _p2 = route[i + 1];
|
|
401
|
+
var _p3 = route[i + 2];
|
|
402
|
+
|
|
403
|
+
// Check if p2 is on the target bbox edge
|
|
404
|
+
var _p2OnTargetLeftEdge = Math.abs(_p2.x - targetBBox.x) < tolerance;
|
|
405
|
+
var _p2OnTargetRightEdge = Math.abs(_p2.x - (targetBBox.x + targetBBox.width)) < tolerance;
|
|
406
|
+
var _p2OnTargetTopEdge = Math.abs(_p2.y - targetBBox.y) < tolerance;
|
|
407
|
+
var _p2OnTargetBottomEdge = Math.abs(_p2.y - (targetBBox.y + targetBBox.height)) < tolerance;
|
|
408
|
+
var _p2OnTargetEdge = _p2OnTargetLeftEdge || _p2OnTargetRightEdge || _p2OnTargetTopEdge || _p2OnTargetBottomEdge;
|
|
409
|
+
if (_p2OnTargetEdge) {
|
|
410
|
+
// Check if p1 -> p2 -> p3 forms a zigzag
|
|
411
|
+
var _p1ToP2Horizontal = Math.abs(_p.y - _p2.y) < tolerance;
|
|
412
|
+
var _p2ToP3Vertical = Math.abs(_p2.x - _p3.x) < tolerance;
|
|
413
|
+
if (_p1ToP2Horizontal && _p2ToP3Vertical && i < route.length - 3) {
|
|
414
|
+
// We have horizontal -> vertical at target edge
|
|
415
|
+
// Check if we can skip p2 and p3
|
|
416
|
+
var p4 = route[i + 3];
|
|
417
|
+
var p3ToP4Horizontal = Math.abs(_p3.y - p4.y) < tolerance;
|
|
418
|
+
if (p3ToP4Horizontal) {
|
|
419
|
+
// Pattern: horizontal -> vertical -> horizontal (zigzag)
|
|
420
|
+
console.log('[getManHattanPath] Removing zigzag at target edge:', "(".concat(_p2.x, ", ").concat(_p2.y, ")"), "and (".concat(_p3.x, ", ").concat(_p3.y, ")"));
|
|
421
|
+
route.splice(i + 1, 2); // Remove p2 and p3
|
|
422
|
+
continue;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
i++;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// Add source and target anchors to route
|
|
430
|
+
var finalRoute = [sourceAnchor].concat(_toConsumableArray(route), [targetAnchor]);
|
|
431
|
+
console.log('[getManHattanPath] Final route:', finalRoute.map(function (p) {
|
|
290
432
|
return "(".concat(p.x, ", ").concat(p.y, ")");
|
|
291
433
|
}));
|
|
292
434
|
|
|
@@ -22,7 +22,13 @@ export declare class ObstacleMap {
|
|
|
22
22
|
private shrinkBBoxAroundAnchor;
|
|
23
23
|
/**
|
|
24
24
|
* Check if a point is accessible (not inside any obstacle)
|
|
25
|
+
* Uses binary search optimization: step -> step/2 -> step/4 -> ... -> 1px
|
|
25
26
|
*/
|
|
26
|
-
isAccessible(point: Point): boolean;
|
|
27
|
+
isAccessible(point: Point, checkRadius?: number): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Check accessibility using binary search optimization
|
|
30
|
+
* Tries step -> step/2 -> step/4 -> ... -> 1px
|
|
31
|
+
*/
|
|
32
|
+
private isAccessibleWithBinarySearch;
|
|
27
33
|
}
|
|
28
34
|
//# sourceMappingURL=ObstacleMap.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObstacleMap.d.ts","sourceRoot":"","sources":["../../src/obstacle/ObstacleMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAa,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAG7D;;;GAGG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,WAAW,CAAQ;IAC3B,OAAO,CAAC,GAAG,CAA0B;IACrC,OAAO,CAAC,YAAY,CAAC,CAAO;IAC5B,OAAO,CAAC,YAAY,CAAC,CAAO;gBAEhB,OAAO,EAAE,eAAe;IAMpC;;OAEG;IACH,KAAK,CACH,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,YAAY,CAAC,EAAE,KAAK,EACpB,YAAY,CAAC,EAAE,KAAK,GACnB,WAAW;IAiEd;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IA6D9B
|
|
1
|
+
{"version":3,"file":"ObstacleMap.d.ts","sourceRoot":"","sources":["../../src/obstacle/ObstacleMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAa,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAG7D;;;GAGG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,WAAW,CAAQ;IAC3B,OAAO,CAAC,GAAG,CAA0B;IACrC,OAAO,CAAC,YAAY,CAAC,CAAO;IAC5B,OAAO,CAAC,YAAY,CAAC,CAAO;gBAEhB,OAAO,EAAE,eAAe;IAMpC;;OAEG;IACH,KAAK,CACH,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,YAAY,CAAC,EAAE,KAAK,EACpB,YAAY,CAAC,EAAE,KAAK,GACnB,WAAW;IAiEd;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IA6D9B;;;OAGG;IACH,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,WAAW,GAAE,MAAU,GAAG,OAAO;IAiD5D;;;OAGG;IACH,OAAO,CAAC,4BAA4B;CAqCrC"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
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; }
|
|
2
5
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
3
6
|
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); } }
|
|
4
7
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
@@ -135,10 +138,12 @@ export var ObstacleMap = /*#__PURE__*/function () {
|
|
|
135
138
|
|
|
136
139
|
/**
|
|
137
140
|
* Check if a point is accessible (not inside any obstacle)
|
|
141
|
+
* Uses binary search optimization: step -> step/2 -> step/4 -> ... -> 1px
|
|
138
142
|
*/
|
|
139
143
|
}, {
|
|
140
144
|
key: "isAccessible",
|
|
141
145
|
value: function isAccessible(point) {
|
|
146
|
+
var checkRadius = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
142
147
|
var key = point.clone().snapToGrid(this.mapGridSize).toString();
|
|
143
148
|
var rects = this.map.get(key);
|
|
144
149
|
if (!rects) {
|
|
@@ -161,6 +166,11 @@ export var ObstacleMap = /*#__PURE__*/function () {
|
|
|
161
166
|
return true;
|
|
162
167
|
}
|
|
163
168
|
}
|
|
169
|
+
|
|
170
|
+
// If checkRadius is specified, use binary search to find accessible points
|
|
171
|
+
if (checkRadius > 0) {
|
|
172
|
+
return this.isAccessibleWithBinarySearch(point, checkRadius, rects);
|
|
173
|
+
}
|
|
164
174
|
var accessible = rects.every(function (rect) {
|
|
165
175
|
return !rect.containsPoint(point);
|
|
166
176
|
});
|
|
@@ -178,6 +188,74 @@ export var ObstacleMap = /*#__PURE__*/function () {
|
|
|
178
188
|
}
|
|
179
189
|
return accessible;
|
|
180
190
|
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Check accessibility using binary search optimization
|
|
194
|
+
* Tries step -> step/2 -> step/4 -> ... -> 1px
|
|
195
|
+
*/
|
|
196
|
+
}, {
|
|
197
|
+
key: "isAccessibleWithBinarySearch",
|
|
198
|
+
value: function isAccessibleWithBinarySearch(point, maxRadius, rects) {
|
|
199
|
+
// First check the point itself
|
|
200
|
+
if (rects.every(function (rect) {
|
|
201
|
+
return !rect.containsPoint(point);
|
|
202
|
+
})) {
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Binary search: start with step, then halve until we reach 1px
|
|
207
|
+
var radius = maxRadius;
|
|
208
|
+
var offsets = [{
|
|
209
|
+
dx: 1,
|
|
210
|
+
dy: 0
|
|
211
|
+
},
|
|
212
|
+
// right
|
|
213
|
+
{
|
|
214
|
+
dx: -1,
|
|
215
|
+
dy: 0
|
|
216
|
+
},
|
|
217
|
+
// left
|
|
218
|
+
{
|
|
219
|
+
dx: 0,
|
|
220
|
+
dy: 1
|
|
221
|
+
},
|
|
222
|
+
// down
|
|
223
|
+
{
|
|
224
|
+
dx: 0,
|
|
225
|
+
dy: -1
|
|
226
|
+
} // up
|
|
227
|
+
];
|
|
228
|
+
while (radius >= 1) {
|
|
229
|
+
var _iterator = _createForOfIteratorHelper(offsets),
|
|
230
|
+
_step;
|
|
231
|
+
try {
|
|
232
|
+
var _loop = function _loop() {
|
|
233
|
+
var offset = _step.value;
|
|
234
|
+
var testPoint = new Point(point.x + offset.dx * radius, point.y + offset.dy * radius);
|
|
235
|
+
if (rects.every(function (rect) {
|
|
236
|
+
return !rect.containsPoint(testPoint);
|
|
237
|
+
})) {
|
|
238
|
+
return {
|
|
239
|
+
v: true
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
_ret;
|
|
244
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
245
|
+
_ret = _loop();
|
|
246
|
+
if (_ret) return _ret.v;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Halve the radius for next iteration
|
|
250
|
+
} catch (err) {
|
|
251
|
+
_iterator.e(err);
|
|
252
|
+
} finally {
|
|
253
|
+
_iterator.f();
|
|
254
|
+
}
|
|
255
|
+
radius = Math.floor(radius / 2);
|
|
256
|
+
}
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
181
259
|
}]);
|
|
182
260
|
return ObstacleMap;
|
|
183
261
|
}();
|
|
@@ -3,7 +3,7 @@ import type { ManhattanRouterOptions } from './types';
|
|
|
3
3
|
/**
|
|
4
4
|
* Default configuration for Manhattan router
|
|
5
5
|
*/
|
|
6
|
-
export declare const defaults: Required<Omit<ManhattanRouterOptions, 'fallbackRoute'>>;
|
|
6
|
+
export declare const defaults: Required<Omit<ManhattanRouterOptions, 'fallbackRoute' | 'sourcePosition' | 'targetPosition'>>;
|
|
7
7
|
/**
|
|
8
8
|
* Direction map - maps direction names to unit vectors
|
|
9
9
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/options/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,KAAK,EAAE,sBAAsB,EAAa,MAAM,SAAS,CAAA;AAEhE;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,sBAAsB,EAAE,eAAe,CAAC,
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/options/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,KAAK,EAAE,sBAAsB,EAAa,MAAM,SAAS,CAAA;AAEhE;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,sBAAsB,EAAE,eAAe,GAAG,gBAAgB,GAAG,gBAAgB,CAAC,CAkBlH,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,YAAY;;;;;CAKxB,CAAA"}
|
package/esm/options/defaults.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../src/options/resolver.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAetE;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQpD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,GAAE,sBAA2B,GAAG,eAAe,
|
|
1
|
+
{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../src/options/resolver.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAetE;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQpD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,GAAE,sBAA2B,GAAG,eAAe,CAiEpF"}
|
package/esm/options/resolver.js
CHANGED
|
@@ -33,7 +33,7 @@ export function normalizeAngle(angle) {
|
|
|
33
33
|
* Resolve options by merging user options with defaults
|
|
34
34
|
*/
|
|
35
35
|
export function resolveOptions() {
|
|
36
|
-
var _options$step, _options$maxLoopCount, _options$precision, _options$maxDirection, _options$startDirecti, _options$endDirection, _options$excludeNodes, _options$excludeShape, _options$excludeTermi, _options$
|
|
36
|
+
var _options$step, _options$maxLoopCount, _options$precision, _options$maxDirection, _options$startDirecti, _options$endDirection, _options$excludeNodes, _options$excludeShape, _options$excludeTermi, _options$borderRadius, _options$extensionDis, _options$penalties, _options$padding;
|
|
37
37
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
38
38
|
var step = (_options$step = options.step) !== null && _options$step !== void 0 ? _options$step : defaults.step;
|
|
39
39
|
var maxLoopCount = (_options$maxLoopCount = options.maxLoopCount) !== null && _options$maxLoopCount !== void 0 ? _options$maxLoopCount : defaults.maxLoopCount;
|
|
@@ -44,8 +44,8 @@ export function resolveOptions() {
|
|
|
44
44
|
var excludeNodes = (_options$excludeNodes = options.excludeNodes) !== null && _options$excludeNodes !== void 0 ? _options$excludeNodes : defaults.excludeNodes;
|
|
45
45
|
var excludeShapes = (_options$excludeShape = options.excludeShapes) !== null && _options$excludeShape !== void 0 ? _options$excludeShape : defaults.excludeShapes;
|
|
46
46
|
var excludeTerminals = (_options$excludeTermi = options.excludeTerminals) !== null && _options$excludeTermi !== void 0 ? _options$excludeTermi : defaults.excludeTerminals;
|
|
47
|
-
var snapToGrid = (_options$snapToGrid = options.snapToGrid) !== null && _options$snapToGrid !== void 0 ? _options$snapToGrid : defaults.snapToGrid;
|
|
48
47
|
var borderRadius = (_options$borderRadius = options.borderRadius) !== null && _options$borderRadius !== void 0 ? _options$borderRadius : defaults.borderRadius;
|
|
48
|
+
var extensionDistance = (_options$extensionDis = options.extensionDistance) !== null && _options$extensionDis !== void 0 ? _options$extensionDis : defaults.extensionDistance;
|
|
49
49
|
var penalties = (_options$penalties = options.penalties) !== null && _options$penalties !== void 0 ? _options$penalties : defaults.penalties;
|
|
50
50
|
var fallbackRoute = options.fallbackRoute;
|
|
51
51
|
|
|
@@ -102,8 +102,10 @@ export function resolveOptions() {
|
|
|
102
102
|
excludeShapes: excludeShapes,
|
|
103
103
|
excludeTerminals: excludeTerminals,
|
|
104
104
|
paddingBox: paddingBox,
|
|
105
|
-
snapToGrid: snapToGrid,
|
|
106
105
|
borderRadius: borderRadius,
|
|
106
|
+
extensionDistance: extensionDistance,
|
|
107
|
+
sourcePosition: options.sourcePosition,
|
|
108
|
+
targetPosition: options.targetPosition,
|
|
107
109
|
directionMap: directionMap,
|
|
108
110
|
directions: directions,
|
|
109
111
|
penalties: penalties,
|
package/esm/options/types.d.ts
CHANGED
|
@@ -89,17 +89,28 @@ export interface ManhattanRouterOptions {
|
|
|
89
89
|
bottom: number;
|
|
90
90
|
left: number;
|
|
91
91
|
};
|
|
92
|
-
/**
|
|
93
|
-
* Whether the calculation results are aligned with the grid
|
|
94
|
-
* @default true
|
|
95
|
-
*/
|
|
96
|
-
snapToGrid?: boolean;
|
|
97
92
|
/**
|
|
98
93
|
* Border radius for rounded corners at path turns (in pixels)
|
|
99
94
|
* Set to 0 for sharp corners
|
|
100
95
|
* @default 5
|
|
101
96
|
*/
|
|
102
97
|
borderRadius?: number;
|
|
98
|
+
/**
|
|
99
|
+
* Extension distance from node edge for path start/end points (in pixels)
|
|
100
|
+
* This controls how far the path extends away from the node before turning
|
|
101
|
+
* @default 20
|
|
102
|
+
*/
|
|
103
|
+
extensionDistance?: number;
|
|
104
|
+
/**
|
|
105
|
+
* Source position (from ReactFlow)
|
|
106
|
+
* Used for smart point generation
|
|
107
|
+
*/
|
|
108
|
+
sourcePosition?: string;
|
|
109
|
+
/**
|
|
110
|
+
* Target position (from ReactFlow)
|
|
111
|
+
* Used for smart point generation
|
|
112
|
+
*/
|
|
113
|
+
targetPosition?: string;
|
|
103
114
|
/**
|
|
104
115
|
* A penalty received for direction change
|
|
105
116
|
*/
|
|
@@ -130,8 +141,10 @@ export interface ResolvedOptions {
|
|
|
130
141
|
width: number;
|
|
131
142
|
height: number;
|
|
132
143
|
};
|
|
133
|
-
snapToGrid: boolean;
|
|
134
144
|
borderRadius: number;
|
|
145
|
+
extensionDistance: number;
|
|
146
|
+
sourcePosition?: string;
|
|
147
|
+
targetPosition?: string;
|
|
135
148
|
directionMap: {
|
|
136
149
|
top: Point;
|
|
137
150
|
right: Point;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/options/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAEnC;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAA;AAE3D;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAA;IACV,QAAQ,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IAClC,SAAS,EAAE;QACT,gBAAgB,EAAE;YAAE,CAAC,EAAE,MAAM,CAAC;YAAC,CAAC,EAAE,MAAM,CAAA;SAAE,CAAA;KAC3C,CAAA;IACD,QAAQ,CAAC,EAAE;QACT,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,MAAM,CAAC,EAAE,MAAM,CAAA;KAChB,CAAA;IACD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACnB;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,GAAG,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;QACZ,OAAO,EAAE,MAAM,CAAA;QACf,OAAO,EAAE,MAAM,CAAA;QACf,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,WAAW,CAAC,EAAE,MAAM,CAAA;KACrB,CAAC,CAAA;IACF,SAAS,EAAE;QAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;IACtC,IAAI,EAAE,MAAM,CAAA;IACZ,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,KAAK,KAAK,EAAE,CAAA;IACnD,sBAAsB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACvC"}
|
|
@@ -1 +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;
|
|
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;AA+I9C;;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,CAiThB"}
|