Skip to content

fix(linebreak): allow Knuth-Plass to place words longer than width - #5

Merged
tomconder merged 1 commit into
mainfrom
fix/knuthplass-overlong-word
Jul 25, 2026
Merged

fix(linebreak): allow Knuth-Plass to place words longer than width#5
tomconder merged 1 commit into
mainfrom
fix/knuthplass-overlong-word

Conversation

@tomconder

Copy link
Copy Markdown
Owner

Summary

  • A word longer than the target width could never get a finite cost in the Knuth-Plass DP, leaving minCost stuck at +Inf and collapsing the entire input onto a single line instead of wrapping.
  • Fixed by always allowing a single-word line (j == i+1) to be costed even when it overflows the width, matching Greedy's existing behavior of never dropping an overlong word.

Test plan

  • Added Word longer than width case to TestKnuthPlass
  • go test ./... passes

Words longer than the target width could never be assigned a finite
cost, leaving minCost stuck at +Inf and collapsing the whole input
onto a single line instead of wrapping.
@tomconder
tomconder merged commit 955fb52 into main Jul 25, 2026
1 check passed
@tomconder
tomconder deleted the fix/knuthplass-overlong-word branch July 25, 2026 21:02
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