Skip to content

layout: reorder_attachments_by_position loses visual ordering when flows change faces #446

@bpowers

Description

@bpowers

Description

In reorder_attachments_by_position (src/simlin-engine/src/layout/mod.rs), when flows change faces (e.g., from Bottom to Right after a chain is removed), the sort key uses the new side's axis (y for Right). However, the old attachment points from the Bottom face all share the same y-coordinate, so they collapse to identical sort keys and fall back to alphabetical ordering, losing their original left-to-right visual positioning.

Concrete example

Suppose a stock has three flows attached to its Bottom face at positions x=100, x=200, x=300. When the layout logic moves these flows to the Right face, it sorts by the y-coordinate (the natural axis for the Right face). But all three flows still have their old Bottom-face coordinates where y is identical (the bottom edge of the stock). The sort produces equal keys for all three, so they end up ordered alphabetically rather than preserving the x=100, x=200, x=300 visual sequence.

Why it matters

  • Correctness: Flow attachment order affects the visual layout of the diagram. Losing spatial ordering means flows get rearranged in a way that does not match user intent.
  • User experience: When a chain is removed or restructured, flows jumping to unexpected positions is confusing.

Component(s) affected

  • simlin-engine -- specifically src/simlin-engine/src/layout/mod.rs, the reorder_attachments_by_position function

Possible approaches

  1. Sort by the axis with more variance among the attachment points (i.e., if all points have the same y, sort by x instead).
  2. Use the old side's natural axis as the sort key rather than the new side's axis.
  3. Use a composite sort key incorporating both x and y coordinates, with the primary key being the axis that has actual variance.

Context

Identified during code review of PR #444 (layout: route non-chain flows perpendicular to aging chains). Classified as P3 -- the issue is real but unlikely to be triggered frequently in current usage patterns.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions