Skip to main content

Module geom

Module geom 

Source
Expand description

Sizes, points and rectangles, in the two coordinate spaces a window has.

§Physical and logical are different types on purpose

Every windowing bug that outlives a release is a scale-factor bug, and every scale-factor bug is a physical value used where a logical one was meant (or the reverse). So the two are separate types and the only way between them is an explicit conversion that takes the scale factor:

  • Physical (PhysicalSize, PhysicalPoint, PhysicalRect) — device pixels. This is what a swapchain is sized in, what a viewport is sized in, and what a pointer position is reported in. Never guess it.
  • Logical (LogicalSize, LogicalPoint) — scale-independent units. This is what a request is expressed in (“open a 1280×720 window”), what min/max constraints are expressed in, and what the UI lays out in. It is f64 rather than integer because fractional scaling (Wayland’s fractional-scale-v1 reports scale in 1/120ths) makes physical / scale non-integral in general.

The engine’s rule: events report physical, requests carry logical. A window asks for a size in a unit the user recognizes; the renderer allocates in the unit the GPU recognizes; the shell is the only thing that converts.

§Rounding

LogicalSize::to_physical rounds to nearest and clamps to at least 1×1. Zero-sized swapchains are invalid in Vulkan, and a minimized window on Win32 genuinely reports 0×0 — so the clamp is not paranoia, it is the difference between “the window is minimized” and a validation error.

Structs§

AspectRatio
A width-to-height ratio, exact.
LogicalPoint
A point in scale-independent units, relative to a window’s top-left corner.
LogicalRect
An axis-aligned rectangle in scale-independent units, relative to a window’s top-left corner.
LogicalSize
A size in scale-independent units.
PhysicalPoint
A point in device pixels, relative to a window’s top-left corner.
PhysicalRect
An axis-aligned rectangle in device pixels.
PhysicalSize
A size in device pixels.