Skip to content

Fix canvas sizing in InterconnectionLayoutEngine for waypoints#27

Merged
Malcolmnixon merged 1 commit into
mainfrom
fix/canvas-sizing-ignores-waypoints
Jul 17, 2026
Merged

Fix canvas sizing in InterconnectionLayoutEngine for waypoints#27
Malcolmnixon merged 1 commit into
mainfrom
fix/canvas-sizing-ignores-waypoints

Conversation

@Malcolmnixon

Copy link
Copy Markdown
Member

This pull request addresses a subtle but important issue in the layout engine: previously, the canvas size was only based on the node rectangles, which could result in routed connector waypoints being clipped if they extended beyond these bounds—especially in graphs with reversed (back) edges. The update ensures the canvas is always large enough to contain all routed geometry by widening it to cover every connector waypoint. The test suite and documentation have been updated to reflect this new, intentional behavior difference from the legacy engine.

Canvas Sizing and Routing Fixes:

  • The InterconnectionLayoutEngine.Place method now ensures the canvas (TotalWidth/TotalHeight) always covers all routed connector waypoints, not just the node rectangles, by folding in every waypoint's coordinates. This prevents connectors from being clipped when they extend beyond the node bounds, especially for reversed (back) edges.
  • Documentation (interconnection-layout-engine.md) has been updated to explain the new canvas-sizing logic and its impact, clarifying when and why the totals may diverge from the legacy oracle.

Test Suite and Equivalence Logic Updates:

  • Added a new test (Place_CyclicGraphWithTallNode_AllWaypointsWithinCanvasBounds) to directly assert that all connector waypoints are within canvas bounds for a cyclic graph with a tall node.
  • Updated the equivalence tests to treat graphs with waypoints beyond node bounds as a third, intentional divergence from the legacy oracle, and to skip strict bit-for-bit comparisons in these cases. [1] [2]
  • Refactored named topology tests: "longedge" and "cycle" topologies now have a dedicated test (Place_LongEdgeAndCycleTopologies_NoWaypointClipsCanvas) that asserts no waypoint clips the canvas, instead of requiring bit-for-bit equivalence with the legacy oracle.
  • Added the HasWaypointBeyondNodeBounds helper to detect when the new canvas-widening logic changes the output versus the legacy engine.

InterconnectionLayoutEngine.Place() computed TotalWidth/TotalHeight purely
from placed node rects (and, for the single-component fast path, the
column geometry), never accounting for the actual routed connector
waypoints. A reversed (back) edge's wrap-around approach in
LayeredCorridorRouter can route a bend point beyond the far edge of the
last node it passes, so the reported canvas silently clipped that
connector's rendered path.

Fix: after computing the node-derived totals, fold every routed
waypoint's coordinates (plus the existing Padding) into
TotalWidth/TotalHeight via Math.Max, so the canvas can only ever grow to
cover what is actually drawn and never shrinks below the existing floor.

Reproduced the clipping with a 5-node cycle plus a long edge and a much
taller node (waypoint Y=200 exceeded a computed TotalHeight of ~198.5),
confirmed the fix resolves it, and added a permanent regression test
(Place_CyclicGraphWithTallNode_AllWaypointsWithinCanvasBounds) that fails
with the fix reverted.

The fix also changes results for the frozen legacy-oracle equivalence
suite on any graph whose back-edge routing would otherwise clip
(including the existing 'longedge' and 'cycle' named topologies and one
random-seed case), since the legacy oracle still has this bug. Documented
this as a third intentional divergence (HasWaypointBeyondNodeBounds),
matching the existing isolated-node and component-packing divergence
pattern, and moved 'longedge'/'cycle' to a dedicated test asserting the
new no-clip behavior directly.

Updated the InterconnectionLayoutEngine design doc to describe the
waypoint-based canvas widening. Regenerated the gallery to confirm no
committed diagram currently triggers this clipping case (no real content
diff after filtering line-ending noise).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Malcolmnixon Malcolmnixon added the bug Something isn't working label Jul 17, 2026
@Malcolmnixon
Malcolmnixon merged commit 7037da7 into main Jul 17, 2026
6 checks passed
@Malcolmnixon
Malcolmnixon deleted the fix/canvas-sizing-ignores-waypoints branch July 17, 2026 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant