Skip to content

Commit 4c49c39

Browse files
Revert "feat(library): connecting at a node corner exits the side facing the destination"
This reverts commit 1a2b102.
1 parent 1a2b102 commit 4c49c39

4 files changed

Lines changed: 6 additions & 111 deletions

File tree

library/lib/hooks/useStepPathEdge.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -879,15 +879,7 @@ export const useStepPathEdge = ({
879879

880880
const { node: nodeOnTop, rect } = snapTarget
881881

882-
// The OTHER (fixed) endpoint, so a drop near a corner exits toward it.
883-
const otherEndpoint =
884-
endpoint === "source" ? currentTargetEndpoint : currentSourceEndpoint
885-
const anchor = getEdgeAnchorFromPoint(
886-
nodeOnTop.type,
887-
flowPoint,
888-
rect,
889-
otherEndpoint
890-
)
882+
const anchor = getEdgeAnchorFromPoint(nodeOnTop.type, flowPoint, rect)
891883
if (!anchor) return null // node is not a connection target (mode "none")
892884
const resolvedAnchor = getEdgeAnchorPoint(nodeOnTop.type, rect, anchor)
893885
let sourceEndpoint = currentSourceEndpoint

library/lib/utils/connectionModes.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,7 @@ const rectBorderAlongRay = (
238238
export function getEdgeAnchorFromPoint(
239239
nodeType: string | undefined,
240240
point: XYPosition,
241-
rect: Rect,
242-
/** The edge's OTHER endpoint, so a drop near a corner exits toward it (see
243-
* `getFreeformAnchorFromPoint`). Only used for rect-border modes. */
244-
otherEndpoint?: XYPosition
241+
rect: Rect
245242
): FreeformEdgeAnchor | null {
246243
switch (getConnectionMode(nodeType)) {
247244
case "none":
@@ -257,7 +254,7 @@ export function getEdgeAnchorFromPoint(
257254
case "parallelogram":
258255
case "freeform-rect":
259256
default:
260-
return getFreeformAnchorFromPoint(point, rect, otherEndpoint)
257+
return getFreeformAnchorFromPoint(point, rect)
261258
}
262259
}
263260

library/lib/utils/edgeUtils.ts

Lines changed: 3 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -360,28 +360,9 @@ export function getSideHandleIdForPosition(
360360
return sideToHandleId[position]
361361
}
362362

363-
/** Outward unit normal of each rect side — the direction the edge LEAVES the node. */
364-
const SIDE_OUTWARD: Record<string, XYPosition> = {
365-
top: { x: 0, y: -1 },
366-
right: { x: 1, y: 0 },
367-
bottom: { x: 0, y: 1 },
368-
left: { x: -1, y: 0 },
369-
}
370-
371-
/**
372-
* A drop lands NEAR a corner when its offset along the nearest side is within this
373-
* fraction of an end. There the two sides meeting at the corner both fit, so the side is
374-
* disambiguated by which one's exit heads toward the OTHER endpoint (below).
375-
*/
376-
const CORNER_BAND = 0.15
377-
378363
export function getFreeformAnchorFromPoint(
379364
point: XYPosition,
380-
rect: Rect,
381-
/** The edge's OTHER endpoint. When given, a drop near a corner picks whichever of the
382-
* two adjacent sides exits TOWARD it, so the edge leaves toward its destination (a
383-
* side exit) instead of away from it (e.g. straight up out of a top corner). */
384-
otherEndpoint?: XYPosition
365+
rect: Rect
385366
): FreeformEdgeAnchor {
386367
const right = rect.x + rect.width
387368
const bottom = rect.y + rect.height
@@ -431,59 +412,11 @@ export function getFreeformAnchorFromPoint(
431412
}
432413

433414
const roundedOffset = clamp(Math.round(closest.offset), 0, closest.axisLength)
434-
const anchor: FreeformEdgeAnchor = {
415+
416+
return {
435417
side: closest.side,
436418
ratio: closest.axisLength > 0 ? roundedOffset / closest.axisLength : 0.5,
437419
}
438-
439-
if (!otherEndpoint) return anchor
440-
441-
// Near a corner, the two sides meeting there both fit the drop. Pick the one whose
442-
// outward exit heads toward the other endpoint, so a corner connection leaves the node
443-
// toward its destination instead of straight out (which forces an up-and-over route).
444-
const nearStart = anchor.ratio <= CORNER_BAND
445-
const nearEnd = anchor.ratio >= 1 - CORNER_BAND
446-
if (!nearStart && !nearEnd) return anchor
447-
448-
// The corner point + the perpendicular side sharing it (with that side's ratio AT the
449-
// corner). `nearStart` is the side's ratio-0 corner, `nearEnd` its ratio-1 corner.
450-
let corner: XYPosition
451-
let adjSide: Position
452-
let adjRatio: number
453-
switch (closest.side) {
454-
case "right":
455-
corner = nearStart ? { x: right, y: rect.y } : { x: right, y: bottom }
456-
adjSide = (nearStart ? "top" : "bottom") as Position
457-
adjRatio = 1
458-
break
459-
case "left":
460-
corner = nearStart ? { x: rect.x, y: rect.y } : { x: rect.x, y: bottom }
461-
adjSide = (nearStart ? "top" : "bottom") as Position
462-
adjRatio = 0
463-
break
464-
case "top":
465-
corner = nearStart ? { x: rect.x, y: rect.y } : { x: right, y: rect.y }
466-
adjSide = (nearStart ? "left" : "right") as Position
467-
adjRatio = 0
468-
break
469-
default: // bottom
470-
corner = nearStart ? { x: rect.x, y: bottom } : { x: right, y: bottom }
471-
adjSide = (nearStart ? "left" : "right") as Position
472-
adjRatio = 1
473-
break
474-
}
475-
476-
const toOther = {
477-
x: otherEndpoint.x - corner.x,
478-
y: otherEndpoint.y - corner.y,
479-
}
480-
const dot = (side: Position) =>
481-
SIDE_OUTWARD[side].x * toOther.x + SIDE_OUTWARD[side].y * toOther.y
482-
// Only switch when the adjacent side genuinely exits MORE toward the other endpoint;
483-
// a side already pointing that way is kept, so a clear side-drop never flips.
484-
return dot(adjSide) > dot(anchor.side)
485-
? { side: adjSide, ratio: adjRatio }
486-
: anchor
487420
}
488421

489422
export function getFreeformAnchorPoint(

library/tests/unit/edgeUtils.test.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -498,33 +498,6 @@ describe("freeform rectangle anchors", () => {
498498
})
499499
})
500500

501-
it("at a corner, exits the side facing the other endpoint (not straight out)", () => {
502-
// Drop AT the top-right corner (110, 20). Nearest-side alone ties to Top -> the edge
503-
// would leave straight UP. With the other endpoint below-right, the corner should
504-
// exit RIGHT instead, so the edge heads toward its destination.
505-
const corner = { x: rect.x + rect.width, y: rect.y } // (110, 20)
506-
const belowRight = { x: 200, y: 200 }
507-
508-
expect(getFreeformAnchorFromPoint(corner, rect).side).toBe(Position.Top)
509-
expect(getFreeformAnchorFromPoint(corner, rect, belowRight)).toEqual({
510-
side: Position.Right,
511-
ratio: 0,
512-
})
513-
514-
// Other endpoint straight ABOVE: Top exit is the one facing it, so it stays Top.
515-
expect(
516-
getFreeformAnchorFromPoint(corner, rect, { x: 100, y: -200 }).side
517-
).toBe(Position.Top)
518-
})
519-
520-
it("leaves a clear mid-side drop unchanged even with the other endpoint given", () => {
521-
// Well away from any corner (ratio 0.5): route-awareness must not move it.
522-
const midRight = { x: 112, y: 60 }
523-
expect(
524-
getFreeformAnchorFromPoint(midRight, rect, { x: 200, y: -200 })
525-
).toEqual(getFreeformAnchorFromPoint(midRight, rect))
526-
})
527-
528501
it("recognizes persisted freeform anchors", () => {
529502
expect(
530503
getFreeformAnchorPoint(rect, { side: Position.Left, ratio: 0.5 })

0 commit comments

Comments
 (0)