Expand description
The grid: the pitch, the snapping ladder, the screen-mapping constants every shape is measured against, and the bridge to the document’s own integer geometry.
This module is the scalar half — one axis at a time, no document type involved. The typed half converts whole points, vectors and rects; it is re-exported here so a call site reads one namespace.
Modules§
- bridge 🔒
- The bridge between world pixels and the document’s own integer geometry,
encoded once (the conversion table in
docs/op-emitter-playbook.md). Each op emitter lands the rows it consumes through these, and the geometry layer reads them back through the same functions, so a rect drawn and a rect committed cannot disagree about where a cell is.
Structs§
- Grid
Cell - A grid cell in the
x,yspelling scripts use: the cell nearest a world position.
Constants§
- BLOCK_
STROKE_ WIDTH - Stroke width of a block/port outline, in world units. The single source of
truth shared by the frame (
draw_block_frame) and the pins that butt against it: a pin stub stops half this width outside the bbox edge so it meets the outline’s outer face instead of crossing into it. - BLOCK_
TYPE_ TEXT_ SIZE - A block’s type label, drawn slightly smaller than its title.
- DEFAULT_
SCALE_ FOR_ NEW_ VIEW - When a block is expanded into its own view, its boundary ports are laid out to mirror the parent’s pin arrangement, magnified by this factor so there is room to place interior child blocks between them.
- GRID_
SIZE - GROUP_
SELECTION_ PAD - Padding between a multi-selection’s contents and the group frame drawn around them, so the frame sits clear of the shapes’ own edges rather than hugging them.
- HIT_
RADIUS - Larger radius used for hit-testing interactive control points (ports,
waypoints, resize handles). Intentionally bigger than
PORT_RADIUSso targets are easier to click without changing how they look. - LINE_
RADIUS - LOCK_
HINT_ SIZE - Side length of the passive “locked” padlock hint drawn in a selected locked block’s upper-right corner. Grid-relative and small so it reads as a hint.
- MAX_
LABEL_ CHARS - Maximum length of a short on-canvas label (pin name and its two lines, block or area title, pin/block tag, route label). The rename editors enforce this so an accidental paste of a long string can’t break the canvas layout.
- MAX_
LOCATION_ CHARS - Maximum length of a pin’s short “location” designator (its
tag, e.g. “A1”). Tighter thanMAX_LABEL_CHARSsince it’s a compact label drawn above the stub. - MAX_
TEXT_ BOX_ CHARS - Maximum length of a free-floating text box. Much larger than a label since a text box is a paragraph annotation, but still bounded so an accidental paste of a huge string can’t blow up the layout.
- MOVE_
HOVER_ DISTANCE - PIN_
PITCH - On-screen distance between consecutive pin slots.
- PIN_
PITCH_ GRID - Vertical space a pin slot occupies, in grid units. Adjacent integer offsets are this many grid units apart.
- PIN_
TOP_ MARGIN - Vertical margin from a block’s top edge to its first pin slot, and the
matching clearance kept below the lowest slot. A whole number of grid cells,
kept independent of
PIN_PITCHso the pitch may be odd: the first pin sits this far down and pins are a fullPIN_PITCHapart. - PORT_
RADIUS - PORT_
RENDER_ HEIGHT - PORT_
SUBTITLE_ TEXT_ SIZE - Subtitle (second line) of a pin/port name. Slightly smaller than the name.
- PORT_
TEXT_ SIZE - RESIZE_
SHIM - ROUTE_
HIT_ MARGIN - Generous margin for snapping a route to a pin: the cursor registers anywhere
near the pin’s stub or its end, not just on the connection point. Kept just
under half a
PIN_PITCHso adjacent pins stay distinct. - ROUTE_
TEXT_ SIZE - SHIM
- TAG_
SHIM - Horizontal gap between a block/port edge and the start of its tag label.
- TAG_
TEXT_ SIZE - TITLE_
TEXT_ SIZE - TYPE_
SHIM_ Y - Vertical nudge applied to the pin’s type label, which is otherwise centered
one
GRID_SIZEbelow the name. Zero keeps it centered exactly a grid cell below the stub; the wider pin pitch leaves room for the full gap.
Functions§
- artwork_
rect - The inverse of
screen_rect. - ceil_
block_ height - The smallest valid block height (see
snap_block_height) that still holdsheight_px— the height counterpart ofceil_to_grid. - ceil_
to_ grid - The smallest whole grid width that still holds
width_px. A resize floor has to be expressed on the lattice the drop snaps to, or the snap rounds back through it. - grid_
i32 - grid_
point - A world-space gesture point onto the grid cell nearest it.
- grid_
pos - The world-space position of a grid cell’s corner, for the places that author canvas coordinates in whole cells.
- grid_
rect - The grid rect a two-corner gesture drew — either corner may be either end of the drag.
- grid_
size_ ceil - A world-space extent as the whole cells that fully enclose it — the measured size a text box records.
- grid_
u32 - grid_
u32_ ceil - A world-space extent in whole grid cells, rounded up so the cell count always fully encloses the extent, and clamped to at least one cell per axis.
- grid_
vec - A drag delta as the whole-cell offset the move commits at.
- max_
pin_ slot - The largest pin slot that fits within a shape of the given
heightwhile keeping at least aPIN_TOP_MARGINof clearance below it. Slotssits atpin_offset_y=top + PIN_TOP_MARGIN + PIN_PITCH * s, so the lowest slot leaving aPIN_TOP_MARGINabove the bottom edge isfloor((height - 2 * PIN_TOP_MARGIN) / PIN_PITCH). This is the bound that bounds-checks pin placement (seeBlock::new_pin_locations). - pin_
offset_ y - Screen y of pin slot
offsetwithin a shape whose top edge is attop.offsetis a plain contiguous integer index; the pitch lives here, not in the stored value. The first slot sits aPIN_TOP_MARGINbelow the top edge; each further slot is onePIN_PITCHdown. - pin_
slot - Pixel offset (
slot * PIN_PITCH) → slot index. - pin_
slot_ row pin_offset_yin whole grid cells: the row slotoffsetsits on in a shape whose top edge is at celltop. The document’s own geometry is integer, so a reader that stays in grid space never crosses through pixels to place a pin.- px
- px_
point - The world-space corner of a grid cell — the inverse of
grid_point. - px_rect
- The world-space rect a grid rect covers.
- px_u
- px_vec
- The world-space vector a snapped
grid_veccovers — what artwork riding a grid move (a block’s icon) translates by. - round_
to_ grid - round_
to_ pitch - Round a pixel offset to the nearest pin slot, in pixels.
- screen_
rect - Artwork geometry — free-floating images and block icons — is the one float rect the document stores: unsnapped, so a placed image keeps the aspect the drag gave it.
- snap_
block_ height - A block’s height is constrained to
2 * PIN_TOP_MARGIN + h * PIN_PITCHfor an unsignedh: aPIN_TOP_MARGINabove the top pin slot and below the bottom one, plus onePIN_PITCHper added slot. So a height-hblock holdsh + 1pins, at offsets0..=h(andmax_pin_slotof this height is exactlyh). This rounds a raw pixel height to the nearest such valid height, floored at theh = 0minimum of2 * PIN_TOP_MARGIN. - snap_
block_ height_ cells snap_block_heightexpressed in whole grid cells — the form a block’sinner.size.hstores. The minimum is 4 cells (2 * PIN_TOP_MARGIN) and each added slot addsPIN_PITCH_GRIDcells: one of4, 7, 10, ….- snap_
offset - Grid-snap a translation
delta(the vector form ofsnap_to_grid), used to round a drag offset to whole grid steps. - snap_
rect - A world-space rect with both corners snapped to the grid.
- snap_
to_ grid