# Implementation Plan: Double-Elimination Connector Routing ## Overview Replace per-edge winner rail staggering with deterministic, collision-aware winner bundles while retaining the existing target-corridor `H-V-H` path model and the current loser/reset routing behavior. ## Architecture Decisions - Keep routing as a pure layout calculation; the React renderer consumes unchanged `BracketConnectorLayout` paths. - Allocate baseline rails first, then choose one rail for each same-target winner bundle while leaving loser/reset coordinates unchanged. - Score complete candidate paths by parallel-stroke clearance, strict crossings, and distance from the corridor midpoint. - Permit shared `verticalX` only when the participating vertical intervals do not overlap; otherwise search the same corridor for the nearest deterministic pair of separate rails with focused-stroke clearance. ## Task List ### Phase 1: Regression Contract - [x] Add tests proving quiet winner bundles use the corridor midpoint and all shareable same-target winner paths remain aligned. - [x] Replace target-column rail uniqueness with interval-aware segment assertions. - [x] Cover reversed A/B input where overlapping vertical spans require the deterministic separate-rail fallback. - [x] Confirm the focused test fails with the current allocator. ### Checkpoint: RED - [x] The new behavioral assertion fails for the expected unequal `verticalX`. - [x] Existing tests remain unchanged except where their invariant is obsolete. ### Phase 2: Bundle-Aware Allocator - [x] Represent connector routing inputs with precomputed source/target anchors. - [x] Retain stable independent rails for loser/reset routes. - [x] Group the two winners entering each target and select the nearest safe shared rail without card penetration, forbidden overlap, or avoidable added crossings. - [x] Fall back to the nearest deterministic, stroke-clear separate rails only when the pair's own vertical intervals overlap and cannot safely share a rail. ### Checkpoint: GREEN - [x] Focused layout tests pass for four-team, eight-team, reset-final, and shuffled input fixtures. - [x] Strict crossing, collinear-overlap, and 5px parallel-clearance safeguards pass. ### Phase 3: Verification and Review - [x] Run the full web suite, lint, and production build; document the unrelated pre-existing full-lint failures while verifying changed files separately. - [x] Inspect the diff for correctness, simplicity, security, performance, and adherence to the approved spec. - [x] Perform an independent review and address all required findings. ### Checkpoint: Complete - [x] All success criteria in the spec are verified. - [x] No unrelated files are modified. ## Risks and Mitigations | Risk | Impact | Mitigation | |---|---|---| | Blind midpoint alignment adds crossings in busy upper rounds | High | Score complete candidate paths and move the winner bundle together to the nearest safe rail. | | Shared rails create overlapping vertical segments | High | Check interval overlap before allowing a shared `verticalX`; search deterministic fallback rails with 5px clearance otherwise. | | Visually parallel rails pass exact-coordinate tests but overlap at stroke width | High | Require 5px clearance across overlapping vertical runs and cover it for 4/8-team fixtures. | | Routing changes depend on input array order | Medium | Sort routes and bundles by graph display order and retain shuffled-fixture equality tests. | | A long connector bends through an intermediate card | High | Restrict every candidate to the target corridor and retain card-penetration assertions. | | Reset-final slot carry-over is accidentally treated as a winner pair | Medium | Bundle only connectors whose computed kind is `winner`; keep reset paths independent. | ## Dependencies ```text Regression contract -> bundle-aware rail allocator -> full verification -> review ``` ## Open Questions None.