Skip to content

Floor the center third calculations to whole pixels - #1961

Open
AkiyamaKunka wants to merge 1 commit into
rxhanson:mainfrom
AkiyamaKunka:fix/center-thirds-pixels
Open

AkiyamaKunka wants to merge 1 commit into
rxhanson:mainfrom
AkiyamaKunka:fix/center-thirds-pixels

Conversation

@AkiyamaKunka

Copy link
Copy Markdown
Contributor

What

Three window calculations floor the window's origin but compute its size with a raw / 3.0:

// CenterThirdCalculation.landscapeRect
rect.origin.x   = visibleFrameOfScreen.minX + floor(visibleFrameOfScreen.width / 3.0)
rect.size.width = visibleFrameOfScreen.width / 3.0      // not floored

So on any screen whose width or height isn't a multiple of 3, they place windows on fractional pixels. On a 1000pt-wide frame the center third comes out 333.33pt wide — a non-integer window frame, and 0.67pt short of meeting the last third, which floors to 333. Every other calculation (first/last thirds, quarters, sixths, ninths, …) floors its size, so these three are the exception:

  • CenterThirdCalculation — width / height
  • CenterTwoThirdsCalculation — origin and size
  • MiddleVerticalThirdCalculation — height

The fix

Floor the sizes like the sibling calculations. The single center third now takes the remainder between the first and last thirds (width - 2 * floor(width / 3)), so the three thirds tile the screen with whole-pixel, gap-free geometry; the center two-thirds becomes 2 * floor(width / 3) centered with an integer margin.

Example on a 1000×800 frame:

action before after
center third (333, 0, 333.33, 800) (333, 0, 334, 800)
center two-thirds (166.5, 0, 666.67, 800) (167, 0, 666, 800)
middle vertical third y 266, h 266.67 y 266, h 268

Tests

Added CenterThirdsRectTests: whole-pixel geometry, the center third tiles contiguously with the first and last thirds, and the centered actions have equal margins on both sides. They fail on main and pass with the fix. The full test suite passes (729 tests).

CenterThirdCalculation, CenterTwoThirdsCalculation and
MiddleVerticalThirdCalculation floored the window origin but computed the
size with a raw / 3.0, so on screens whose width or height isn't a multiple
of 3 they placed windows on fractional pixels. A center third on a
1000pt-wide frame was 333.33pt wide, 0.67pt short of meeting the last third
(which floors to 333). Every sibling calculation floors its size, so these
three were the exception.

Floor the sizes to match. The single center third now fills the remainder
between the first and last thirds (width - 2 * floor(width / 3)) so the
thirds tile with whole-pixel, gap-free geometry, and the center two-thirds
is 2 * floor(width / 3) centered with an integer margin.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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