code wiki / _hdl_build / nx_brand_snap.nx
nx_brand_snap.nx source
↩ module page · 26 lines · 1202 B
1// nx_brand_snap.nx -- editor-maturity primitives: grid SNAPPING + alignment GUIDES for the free-form canvas.
2// bs_snap rounds a placement coord to the nearest grid line (so dragged elements land on the rhythm); bs_aligned
3// detects when two elements share an edge within a tolerance (-> draw an alignment guide). Engine-level (deterministic,
4// no-float), so the studio canvas snaps BY CONSTRUCTION, not just via a JS hint. (Webflow-depth widget breadth stays
5// the R6 honest BEHIND.) Library. 100% sovereign. license_tier: ORIGINAL
6import "nx_syscalls.nx"
7
8// nearest multiple of `grid` (round half up). grid<=0 -> identity.
9func bs_snap(v: i64, grid: i64) -> i64 {
10 if grid <= 0 { return v }
11 return ((v + grid / 2) / grid) * grid
12}
13// 1 iff |a-b| <= tol (the two edges align -> show a guide).
14func bs_aligned(a: i64, b: i64, tol: i64) -> i64 {
15 var d: i64 = a - b
16 if d < 0 { d = 0 - d }
17 if d <= tol { return 1 }
18 return 0
19}
20// snap a whole placement (x,y,w) onto the grid, in place via an i64[3] buffer.
21func bs_snap_place(buf: *i64, grid: i64) -> i64 {
22 buf[0] = bs_snap(buf[0], grid)
23 buf[1] = bs_snap(buf[1], grid)
24 buf[2] = bs_snap(buf[2], grid)
25 return 1
26}