Skip to content

NSGeometry: complete NSIntegralRectWithOptions#700

Open
DTW-Thalion wants to merge 1 commit into
gnustep:masterfrom
DTW-Thalion:fix/nsintegralrect-options
Open

NSGeometry: complete NSIntegralRectWithOptions#700
DTW-Thalion wants to merge 1 commit into
gnustep:masterfrom
DTW-Thalion:fix/nsintegralrect-options

Conversation

@DTW-Thalion

Copy link
Copy Markdown
Contributor

NSIntegralRectWithOptions did not implement its full contract:

  • The NSAlignWidth*/NSAlignHeight* options were ignored; it always aligned both the minimum and maximum edge of each axis.
  • It never validated the options, so a set that does not select exactly two of an axis' minimum edge, maximum edge and size silently returned a rectangle instead of raising.
  • NSAlignRectFlipped was not handled.
  • An empty or zero-size rectangle was collapsed to {0,0,0,0} rather than aligned in place.
  • A nearest tie used round(), which rounds a negative half away from zero, instead of towards positive infinity.

Each axis is now aligned from exactly two of its minimum edge, maximum edge and size (raising NSInvalidArgumentException otherwise); an inward option rounds an edge toward the interior of the rectangle, outward away from it, nearest to the closest unit with a tie towards positive infinity (negative infinity for a Y edge under NSAlignRectFlipped); and an empty or zero-size rectangle keeps its aligned origin.

Every option combination, the flipped tie, the empty/zero-size handling and the exception were checked against Apple Foundation on a macOS runner. The behaviour is exercised by a new NSIntegralRectWithOptions set in Tests/base/Functions/NSGeometry2.m (7 of its assertions fail against the previous implementation).

The function ignored the width and height options, always aligned both the
minimum and maximum edge of each axis, did not handle NSAlignRectFlipped and
collapsed an empty rectangle to the zero rect. Align each axis from exactly two
of its minimum edge, maximum edge and size, raising NSInvalidArgumentException
otherwise; round a nearest tie towards positive infinity, or negative infinity
for a flipped edge; and align an empty or zero-size rectangle in place rather
than discarding it. Behaviour checked against Apple Foundation.
@DTW-Thalion
DTW-Thalion requested a review from rfm as a code owner July 25, 2026 00:30
@fredkiefer

Copy link
Copy Markdown
Member

With that change in place you could rewrite your gui change to use this function.

@DTW-Thalion

Copy link
Copy Markdown
Contributor Author

Thanks. Once this is in, I will rewrite -[NSView backingAlignedRect:options:] to call NSIntegralRectWithOptions instead of the private alignment helper it uses now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants