@@ -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-
378363export 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
489422export function getFreeformAnchorPoint (
0 commit comments