Skip to content

fix: detect collisions for nearly axis-aligned segments (closes #1099) - #1100

Open
tcsenpai wants to merge 1 commit into
tscircuit:mainfrom
tcsenpai:fix/near-axis-aligned-collision
Open

tcsenpai wants to merge 1 commit into
tscircuit:mainfrom
tcsenpai:fix/near-axis-aligned-collision

Conversation

@tcsenpai

@tcsenpai tcsenpai commented Sep 8, 2026

Copy link
Copy Markdown

Closes #1099

Problem

segmentIntersectsRect classifies a segment as vertical or horizontal using EPS = 1e-9, then returns false for anything that matches neither. Pin coordinates are not always exactly on the routing grid, so a segment can be skewed by ~6e-5: far below the schematic grid, but five orders of magnitude above 1e-9. Those segments matched neither fast path and were reported as colliding with nothing.

UnroutedTraceRecoverySolver accepts the first candidate that passes pathCollidesWithObstacles, so a skewed candidate was accepted and emitted as the final trace, running straight through a chip body it does not terminate on.

Fix

When a segment matches neither fast path, classify it by its dominant axis if the off-axis deviation is under 1e-3 and test it as the axis-aligned segment it was meant to be. Genuinely diagonal segments still return false, so the change is limited to sub-grid skew.

The 1e-3 threshold sits below the schematic grid, so anything under it is float noise or an off-grid pin, never a deliberate diagonal.

Tests

tests/repros/near-axis-aligned-trace-through-chip.test.ts covers both levels:

  • the helper directly, asserting a skewed segment collides with a rect it passes through while a true diagonal still does not
  • the pipeline end to end, asserting no trace segment crosses the interior of a chip it does not terminate on

Both assertions fail on main and pass with this change.

bun test: 343 pass, 4 skip, 0 fail (main is also 0 fail, so no regressions).
bunx tsc --noEmit: clean.
No snapshots changed.

Provenance

Found by differential fuzzing over the fixtures in tests/bug-reports and tests/examples, judging each mutated variant against its base fixture's baseline. Two independent fuzzed inputs reduce to this same root cause. The reproducer in the test is the delta-debugged minimum: 3 chips, 1 connection.

This change was prepared with AI assistance and reviewed by the author.

@vercel

vercel Bot commented Sep 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
schematic-trace-solver Ready Ready Preview Sep 8, 2026 1:09pm UTC

Request Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: nearly axis-aligned segments escape all obstacle collision checks, letting traces pass through chips

1 participant