Skip to main content

Module alignment

Module alignment 

Source
Expand description

Alignment guides shown while dragging. A dragged element’s features (edges, centers, pin stubs, or a single corner) are matched against the same features of every other shape; each like-kind coincidence draws a thin line spanning the aligned pair, drawn over the diagram so a center guide (which runs through the opaque shapes it aligns) stays visible.

Grid-quantized shapes (blocks, areas) coincide at discrete grid steps, so their guides are stable. Free-positioned images/icons don’t, so snap_drag_offset makes their drag magnetic — snapping a center onto a nearby feature so the guide lands instead of merely flashing past.

Structs§

Candidate 🔒

Enums§

Axis 🔒
Kind 🔒

Constants§

EPS 🔒
Coordinates within this many world units count as aligned when drawing a guide (only absorbs float error — grid shapes coincide exactly).
SNAP_RADIUS
How near (world units) a freely-dragged image/icon feature must be to a static feature for snap_drag_offset to pull it into exact alignment.

Functions§

build_statics 🔒
The resting alignment features of every shape (plus areas) except those is_excluded — the static set a drag or resize matches its moving features against.
draw_guides
Draw the computed guide segments. Call this after the scene so a center guide — which runs through the opaque shapes it aligns — stays visible.
match_guides 🔒
pin_drag_guides
Guides for a pin drag: each previewed pin — the same PinMove the commit will carry — matches against every other pin stub except exclude.
push_pin_rows 🔒
Each pin’s stub row: a horizontal guide at the stub’s y, shifted by offset. Only the row is offered — a pin sits at a fixed offset from the edge it attaches to, so its x is not a meaningful alignment feature (the edge is); its y lets pins on different blocks line up. Works for block pins and the port pin.
push_point_candidates 🔒
A single point contributes one vertical and one horizontal guide candidate.
push_rect_candidates 🔒
push_rect_edges 🔒
A rect’s four edge candidates (the left/right verticals, top/bottom horizontals) — no centers.
resize_guides
Alignment guides for a resize: the shape’s features at its previewed resized rect, matched against every other shape’s resting features. A resize doesn’t translate the shape, so it can’t reuse shape_drag_guides’s offset path.
resized_candidates 🔒
The features a shape at rect contributes while being resized: rect shapes (blocks, areas) offer edges + centers; images/icons offer edges (the ones the resize magnetism snaps — see snap_resize_corner); ports offer their tip/back columns. Text boxes aren’t resizable.
shape_candidates 🔒
The features a shape contributes. Blocks: edges, centers, and pin rows. Ports: the pin row plus two verticals at the pentagon’s tip and flat back. Areas: edges and centers. Text boxes: only the top-left corner (their box is normally hidden). Images/icons: only the center, so they align center-to-center (an icon to its containing block’s center). offset previews a drag (zero for a resting shape).
shape_drag_guides
Guides for a shape (or group) drag: the dragged shapes — previewed at offset — contribute their features; every other shape (including areas) contributes the same at its resting position.
snap_drag_offset
Magnetic alignment for a freely-positioned image/icon drag: adjust raw_offset so a dragged feature snaps exactly onto a nearby static feature of the same kind/axis (within SNAP_RADIUS), per axis independently — so a drag can snap horizontally, vertically, or both. Returns raw_offset unchanged where nothing is near. The static set is every other shape (plus areas), matching shape_drag_guides, so a snap always coincides with a drawn guide.
snap_resize_corner
Snap a resize’s dragged corner to a nearby static edge — its x to the nearest static vertical edge, its y to the nearest static horizontal edge, each within SNAP_RADIUS and independently — so a free image/icon edge lines up as a move would. exclude is the shape being resized (its own edges aren’t targets). Returns the corrected corner.