Skip to content

Keep a very wide NominalWordWrap to its width [patch] - #192

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/174-bound-wrap-tolerance
Nov 10, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/174-bound-wrap-tolerance

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #174

What was wrong

NominalWordWrap absorbs float error with a tolerance of raw * 1e-6 glyphs (added in #173 for #171). Once the width reaches 1,000,000 glyphs that is a whole glyph or more, so an exact width rounded up: a width of 1_000_000f gave a 1,000,001-character first line, and 10_000_000f gave 10,000,010. That breaks the documented "no line exceeds the computed width" guarantee.

Change

Tests

  • NominalWordWrapFitsExactlyNGlyphsInAVeryWideWidth: n ∈ {1e6, 2e6, 1e7} at glyph width 1 hold exactly n characters.
  • NominalWordWrapDoesNotRoundUpAVeryWideWidthHalfAGlyphShort: n − 0.5 for n ∈ {1e6, 2e6, 4e6} holds n − 1. 1e7 isn't included because 9,999,999.5 can't be represented as a float.
  • NominalWordWrapStillAbsorbsFloatErrorAtLargeInexactWidths: widths of 50k–200k glyphs at 0.7f, 6.6f and 13.3f. This guards the size of the cap.
  • With the fix reverted, all 6 very-wide cases fail. With the cap set to 1e-3, the 13.3f/100k inexact case fails.
  • The full suite passes locally: 245/245 on net10.0.

Generated by Claude Code

The float-error tolerance added for #171 was raw * 1e-6 glyphs, which reaches a
whole glyph once the width is 1,000,000 glyphs, so an exact width rounded up and
the first line ran one character (or more) past it. Cap the tolerance at a
quarter glyph: still enough to absorb float error at large inexact widths, and
below half a glyph so a width half a glyph short never rounds up.

Fixes #174

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW66FJ9HR9vCd1x5h4H
@sonarqubecloud

sonarqubecloud Bot commented Nov 7, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 94a6096 into main Nov 10, 2026
15 checks passed
@matt-edmondson
matt-edmondson deleted the fix/174-bound-wrap-tolerance branch November 10, 2026 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants