Repository navigation
Keep a very wide NominalWordWrap to its width [patch] - #192
Merged
Merged
Conversation
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
|
This was referenced Nov 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #174
What was wrong
NominalWordWrapabsorbs float error with a tolerance ofraw * 1e-6glyphs (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 of1_000_000fgave a 1,000,001-character first line, and10_000_000fgave 10,000,010. That breaks the documented "no line exceeds the computed width" guarantee.Change
Math.Min(raw * 1e-6, MaxGlyphRoundingTolerance), with the cap set to 0.25 glyphs.1e-3suggested in the issue: float error inn * glyphWidthgrows with the width, and1e-3is too small at mid-range widths. With1e-3,n = 100_000at a glyph width of13.3fwraps one character early, which is the NominalWordWrap wraps one character early when wrapWidth is an exact multiple of the glyph width (regression from #146) #171 bug coming back. A quarter glyph absorbs that error, and because it stays below half a glyph, a width half a glyph short still never rounds up.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.1e-3, the 13.3f/100k inexact case fails.Generated by Claude Code