Skip to content

Add the Foundation geometry structs: NSPoint, NSSize, NSRect - #10

Merged
tannevaled merged 1 commit into
mainfrom
feat/foundation-geometry
Aug 30, 2026
Merged

tannevaled merged 1 commit into
mainfrom
feat/foundation-geometry

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

A message that takes an NSSize takes it by value, in floating-point
registers. A struct of the wrong shape is not a compile error — it is two
garbage numbers arriving at AppKit. Every caller redeclaring its own is every
caller getting one chance to be wrong, so the shape belongs here once.

The tests assert the layout rather than arithmetic, because the layout is the
part that is a contract: sizes, and the offset of every field.

The immediate consumer. An NSImage built from data takes its size from
the bitmap's pixel count, so a 36-pixel icon reports 36 points — and lands
in a 22-point menu bar taller than the bar it sits in. That is a live defect in
go-widgets/tray today. Fixing it needs -[NSImage setSize:], which needs an
NSSize.

Measured through purego before this was written, not assumed:

taille AVANT setSize: 36.0 x 36.0 pt
taille APRÈS setSize: 18.0 x 18.0 pt

They are an ABI contract, not a convenience. A message that takes an NSSize
takes it by value in floating-point registers, so a struct of the wrong shape
is not a compile error — it is two garbage numbers arriving at AppKit. Every
caller redeclaring its own is every caller getting one chance to be wrong.

The immediate consumer is go-widgets/tray. An NSImage built from data takes
its size from the bitmap's pixel count, so a 36-pixel icon reports 36 POINTS
and lands in a 22-point menu bar taller than the bar itself. Fixing that needs
-[NSImage setSize:], which needs an NSSize.

Measured through purego before writing this, not assumed: size read back 36x36
before, 18x18 after.
@tannevaled
tannevaled merged commit 60a5dee into main Aug 30, 2026
3 checks passed
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