diff --git a/src/__Libraries/StellaOps.ElkSharp/ElkEdgeRouterIterative.BoundaryFirst.CorridorReroute.cs b/src/__Libraries/StellaOps.ElkSharp/ElkEdgeRouterIterative.BoundaryFirst.CorridorReroute.cs index 1afb03343..0e0ac05e2 100644 --- a/src/__Libraries/StellaOps.ElkSharp/ElkEdgeRouterIterative.BoundaryFirst.CorridorReroute.cs +++ b/src/__Libraries/StellaOps.ElkSharp/ElkEdgeRouterIterative.BoundaryFirst.CorridorReroute.cs @@ -209,12 +209,30 @@ internal static partial class ElkEdgeRouterIterative && bestPushY < graphMaxY + 56d && Math.Abs(bestPushY - laneY) > 2d) { - var newPath = new List(path.Count); + var newPath = new List(path.Count + 2); for (var i = 0; i < path.Count; i++) { if (i >= bestSegStart && i <= bestSegStart + 1 && Math.Abs(path[i].Y - laneY) <= 2d) { + // Preserve source connection (first point). + if (i == 0) + { + newPath.Add(path[i]); + continue; + } + + // Preserve target connection (last point) — + // insert a vertical step to reconnect. + if (i == path.Count - 1) + { + var stepX = path[i].X + (path[i - 1].X > path[i].X ? 24d : -24d); + newPath.Add(new ElkPoint { X = stepX, Y = bestPushY }); + newPath.Add(new ElkPoint { X = stepX, Y = path[i].Y }); + newPath.Add(path[i]); + continue; + } + newPath.Add(new ElkPoint { X = path[i].X, Y = bestPushY }); } else