Skip to content

Fix countTurns using exact float equality instead of epsilon - #817

Open
Priyanshubhartistm wants to merge 1 commit into
tscircuit:mainfrom
Priyanshubhartistm:fix-countturns-float-equality
Open

Fix countTurns using exact float equality instead of epsilon#817
Priyanshubhartistm wants to merge 1 commit into
tscircuit:mainfrom
Priyanshubhartistm:fix-countturns-float-equality

Conversation

@Priyanshubhartistm

@Priyanshubhartistm Priyanshubhartistm commented Aug 15, 2026

Copy link
Copy Markdown

Summary

  • countTurns classified segment orientation with strict prev.x === curr.x, which breaks on the float drift produced by chained += math elsewhere in the pipeline (e.g. TraceOverlapIssueSolver's jog offsets) - a geometrically straight run could get miscounted as having a turn.
  • Switched to an epsilon comparison (Math.abs(...) < EPS), matching the pattern already used elsewhere in the codebase (e.g. isVertical/isHorizontal in SchematicTraceSingleLineSolver2/collisions.ts).
  • countTurns feeds path-scoring in turnMinimization.ts, minimizeTurnsWithFilteredLabels.ts, and scoreRailAlignment.ts, so a wrong turn count can make those solvers reject a genuinely straighter candidate path.
  • Added tests/functions/countTurns.test.ts - confirmed it fails against the old === code and passes against the fix.

Validation

  • bunx tsc --noEmit
  • bun test (185 pass, 4 pre-existing skips, 0 fail, no snapshot changes)
  • Verified the new test fails on the pre-fix code via git stash before confirming the fix

@vercel

vercel Bot commented Aug 15, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
schematic-trace-solver Ready Ready Preview Aug 15, 2026 6:06pm

Request Review

countTurns() classified segment orientation with strict prev.x === curr.x,
which breaks on float drift produced by chained += math elsewhere in the
pipeline (e.g. TraceOverlapIssueSolver jog offsets) - a geometrically
straight run could get miscounted as having a turn. Since countTurns feeds
path-scoring in turnMinimization.ts, minimizeTurnsWithFilteredLabels.ts, and
scoreRailAlignment.ts, this could make those solvers reject a genuinely
straighter candidate path.

Switch to an epsilon comparison matching the isVertical/isHorizontal
pattern already used elsewhere (e.g. collisions.ts).
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.

1 participant