Skip to content

Step only near-straight wall joins on retry, within 20 degrees (WOR-878) - #420

Merged
kcjonson merged 4 commits into
mainfrom
fix/WOR-878-retry-near-straight
Nov 16, 2026
Merged

kcjonson merged 4 commits into
mainfrom
fix/WOR-878-retry-near-straight

Conversation

@kcjonson

Copy link
Copy Markdown
Owner

WOR-878, second part. Stacked on PR 419 (the bounded walk), which it includes until that merges.

PR 417 gave resolveWallBands a retry: when a wall's corner cut overruns the wall, the junctions at that wall's ends are redrawn as steps. It was written for a short wall meeting a wall of another thickness a few degrees off straight. Its condition was much wider than that: any wedge beside a failed band whose two walls point more than 90 degrees apart, square corners included.

Two things followed. At near-square corners the step code's walk did not terminate (PR 419 bounds it). And some inputs the code used to reject were "resolved" with wrong shapes: in a 40,000-draw sweep of short chains, 5 of 11,982 non-folding inputs failed the tiling checks (a junction vertex past the miter bound, or a 3.6 mm gap), at corners about 100 to 105 degrees apart.

What changes

  • The retry steps only near-straight joins. withinRetryBend(dirL, dirR): the wedge's two walls must be within 20 degrees of straight, tested exactly in 128-bit integers (|cross| * 11 <= -dot * 4; 4/11 is tan of 19.98 degrees). It gates the whole stepping condition. Anything further from straight is rejected, as it was before the retry existed.
  • Why 20 degrees. A short wall joining another thickness at one end fails within about 9 degrees of straight. A wall of the minimum length (500 mm) with such a join at both ends fails up to about 18.5 degrees; past 20 a wall of that length resolves as a miter without the retry. A first version of this change used 15 degrees and review showed it rejected again 12 of 72 legal-length cases at 15.5 degrees that the wide retry had resolved correctly.
  • The step walk stops early where walking cannot help. When the line crossing is behind the corner or the lines are parallel, it checks 4 mm for rounding and then goes straight to the wall's length (the same rejection). A 10 km wall in that case took 206 ms per call; it takes 7 microseconds.

The invariant

Every input the pre-retry code accepted produces identical output. WallProperties.NearStraightRetryKeepsEveryAcceptedJoin (about 160,000 inputs against a copy of the pre-retry logic) passes untouched with the same counts as before this change: 155,909 accepted, 3,216 rescued, 18 excused as main's own step geometry. So nothing the retry was written for is lost. A reviewer rebuilt both versions outside the repo and recounted the same numbers, comparing pieces and outline on every accepted input.

How checked

  • geometry-tests 494 passed. sim-tests 1202 and world-sim-tests 61 passed on the commit that added the gate; the two commits since touch only the constant, comments, and the geometry test file.
  • WallProperties.ShortMixedChainsRejectOrTile now runs 40,000 draws with nothing excused (1.4 s). With the gate switched off the same run fails exactly the five inputs above.
  • New WallProperties.ShortWallJoiningOtherThicknessAtBothEndsResolves: a 500 or 600 mm wall between two walls of another thickness, every thickness pairing, as a Z and as a C, each end from 3 to 20 degrees off straight (15,552 inputs, 2.2 s). With the gate at 15 degrees it fails on 66.
  • The reviewer's runs on the 15 degree version: no mismatch against the old unbounded walk over 60,209 walks; the capped branch never needed more than 1 mm; the original hanging input returns in 9 microseconds.

What 20 degrees costs

On 6,000 short-armed T and star inputs (arms 150 to 750 mm), 4 are rescued with wrong shapes at 20 degrees against 1 at 15. The three new ones are T-junctions with the through-run bent 16 to 20 degrees and an arm of 162 to 268 mm, under the legal wall length; a T-junction split can leave arms that short. Example: (0,0)->(162,0) h100; (-403,128)->(0,0) h150; (0,0)->(-199,-199) h75. It is the family already tracked on WOR-877 (a stem on a stepped through-run).

Perf: nothing on layouts that resolve. On the retry path, one exact comparison per wedge, and the walk is at most 4 steps in the no-progress cases. Nothing was timed beyond the reviewer's single-input measurements above.

The step walks the thinner band's corner until it clears the thicker band's cap, whose line runs between two rounded points. Where the retry steps a nearly square corner, that line can lean off square by more than the bands lean off 90 degrees apart, so the corner runs along it and never clears. The walk now stops at the thin segment's length, where the band is gone and the graph is rejected, as it was before the retry.
The retry stepped every two-wall join beside a failed band whose walls
pointed more than 90 degrees apart, square corners included, and some short
chains came out past the miter bound. It now steps only joins within about
15 degrees of straight, decided exactly in Int128. A step whose thin corner
can never clear the cap by walking jumps to the wall's length after a few
millimetres instead of walking there. The short-chain sweep runs 40,000
draws, which covers the inputs that failed.
A 500 mm wall joining another thickness at both ends fails without the retry up to about
18.5 degrees off straight, past the 15 degree gate, so legal walls were rejected again.
At 20 degrees such a wall resolves as a miter on its own.
@kcjonson
kcjonson marked this pull request as ready for review November 15, 2026 17:40
Copilot AI balanced review requested due to automatic review settings November 15, 2026 17:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@kcjonson
kcjonson merged commit cff0919 into main Nov 16, 2026
6 checks passed
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.

2 participants