reactflow-edge-routing 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/routing-core.ts +19 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reactflow-edge-routing",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Orthogonal edge routing for React Flow using obstacle-router. Edges route around nodes while pins stay fixed at their anchor points.",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
package/src/routing-core.ts
CHANGED
|
@@ -287,7 +287,8 @@ function segmentIntersectsRect(
|
|
|
287
287
|
return tMin <= tMax;
|
|
288
288
|
}
|
|
289
289
|
|
|
290
|
-
/** Returns true if the direct line from srcPt to tgtPt is blocked by any node
|
|
290
|
+
/** Returns true if the direct line from srcPt to tgtPt is blocked by any node,
|
|
291
|
+
* including the source/target nodes themselves (e.g. edge going backward through its own node). */
|
|
291
292
|
function isEdgeDirectPathBlocked(
|
|
292
293
|
srcPt: { x: number; y: number },
|
|
293
294
|
tgtPt: { x: number; y: number },
|
|
@@ -297,10 +298,25 @@ function isEdgeDirectPathBlocked(
|
|
|
297
298
|
nodeById: Map<string, FlowNode>,
|
|
298
299
|
buffer: number
|
|
299
300
|
): boolean {
|
|
301
|
+
const dx = tgtPt.x - srcPt.x, dy = tgtPt.y - srcPt.y;
|
|
302
|
+
const len = Math.sqrt(dx * dx + dy * dy);
|
|
300
303
|
for (const node of nodes) {
|
|
301
|
-
if (node.id === srcNodeId || node.id === tgtNodeId) continue;
|
|
302
304
|
const bounds = Geometry.getNodeBoundsAbsolute(node, nodeById);
|
|
303
|
-
if (
|
|
305
|
+
if (node.id === srcNodeId || node.id === tgtNodeId) {
|
|
306
|
+
// The handle point sits on the node border, so a plain intersection check would
|
|
307
|
+
// always trigger. Nudge 1 px along the segment away from the handle and check
|
|
308
|
+
// from there — avoids the border false-positive while still catching lines that
|
|
309
|
+
// go backward through the node body.
|
|
310
|
+
if (len < 1e-6) continue;
|
|
311
|
+
const isSrc = node.id === srcNodeId;
|
|
312
|
+
const nudged = isSrc
|
|
313
|
+
? { x: srcPt.x + dx / len, y: srcPt.y + dy / len }
|
|
314
|
+
: { x: tgtPt.x - dx / len, y: tgtPt.y - dy / len };
|
|
315
|
+
const otherEnd = isSrc ? tgtPt : srcPt;
|
|
316
|
+
if (segmentIntersectsRect(nudged, otherEnd, bounds, buffer)) return true;
|
|
317
|
+
} else {
|
|
318
|
+
if (segmentIntersectsRect(srcPt, tgtPt, bounds, buffer)) return true;
|
|
319
|
+
}
|
|
304
320
|
}
|
|
305
321
|
return false;
|
|
306
322
|
}
|