Remove backtrack overshoots in SVG edge rendering

When three consecutive points are on the same axis and the middle one
overshoots then returns (e.g., Y goes 170→119→135), remove the
overshoot point. This eliminates the visible inverted-U loop above the
Parallel Execution Join node.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
master
2026-04-02 16:47:00 +03:00
parent 58d2ba83ab
commit 2f8adc0435

View File

@@ -2041,9 +2041,45 @@ public sealed class WorkflowRenderSvgRenderer
// When removing a jog, snap the next point to the previous point's
// axis so we get a clean L-shape instead of a diagonal.
var mutablePoints = points.ToList();
// No debug needed — the S-curve comes from the corner radius
// on short intermediate segments, not from tiny jog points.
// Remove backtracks: when three consecutive points are on the same
// axis (same X or same Y) and the middle one overshoots then returns,
// remove the overshoot point.
for (var i = 1; i < mutablePoints.Count - 1; i++)
{
var prev = mutablePoints[i - 1];
var curr = mutablePoints[i];
var next = mutablePoints[i + 1];
var sameX = Math.Abs(prev.X - curr.X) < 2d && Math.Abs(curr.X - next.X) < 2d;
var sameY = Math.Abs(prev.Y - curr.Y) < 2d && Math.Abs(curr.Y - next.Y) < 2d;
if (sameX)
{
// All three on same X. Check if curr overshoots: prev→curr goes
// one direction, curr→next goes the opposite.
var d1 = curr.Y - prev.Y;
var d2 = next.Y - curr.Y;
if (d1 * d2 < 0d) // opposite directions = backtrack
{
mutablePoints.RemoveAt(i);
i--;
continue;
}
}
if (sameY)
{
var d1 = curr.X - prev.X;
var d2 = next.X - curr.X;
if (d1 * d2 < 0d)
{
mutablePoints.RemoveAt(i);
i--;
continue;
}
}
}
// Remove tiny jog segments (< 30px) that create visible zigzag steps.
var cleaned = new List<WorkflowRenderPoint> { mutablePoints[0] };
for (var i = 1; i < mutablePoints.Count; i++)
{