code wiki / _hdl_build / nx_viz_contour.nx
nx_viz_contour.nx source
↩ module page · 35 lines · 1881 B
1// nx_viz_contour.nx -- the GEO-CONTOUR layer of the sovereign Nishi viz library (the d3-contour core, bits-up).
2// Marching squares: classify each grid cell's 4 corners vs a threshold -> 4-bit case -> contour line segments
3// across the cell edges (0=top 1=right 2=bottom 3=left). Pure integer. Closes geo-contour. license_tier: ORIGINAL
4import "nx_syscalls.nx"
5
6// 4-bit case from the cell corners (bit3=TL bit2=TR bit1=BR bit0=BL), each set if value >= threshold.
7func vc_ms_case(tl: i64, tr: i64, br: i64, bl: i64, t: i64) -> i64 {
8 var c: i64 = 0
9 if tl >= t { c = c + 8 }
10 if tr >= t { c = c + 4 }
11 if br >= t { c = c + 2 }
12 if bl >= t { c = c + 1 }
13 return c
14}
15// contour segments for a case: fills segs_out with edge-index pairs (2 per segment). returns segment count (0/1/2).
16func vc_ms_segs(c: i64, segs_out: *i64) -> i64 {
17 if c == 0 { return 0 }
18 if c == 15 { return 0 }
19 if c == 1 { segs_out[0] = 3; segs_out[1] = 2; return 1 }
20 if c == 2 { segs_out[0] = 2; segs_out[1] = 1; return 1 }
21 if c == 3 { segs_out[0] = 3; segs_out[1] = 1; return 1 }
22 if c == 4 { segs_out[0] = 0; segs_out[1] = 1; return 1 }
23 if c == 5 { segs_out[0] = 0; segs_out[1] = 3; segs_out[2] = 2; segs_out[3] = 1; return 2 }
24 if c == 6 { segs_out[0] = 0; segs_out[1] = 2; return 1 }
25 if c == 7 { segs_out[0] = 0; segs_out[1] = 3; return 1 }
26 if c == 8 { segs_out[0] = 0; segs_out[1] = 3; return 1 }
27 if c == 9 { segs_out[0] = 0; segs_out[1] = 2; return 1 }
28 if c == 10 { segs_out[0] = 0; segs_out[1] = 1; segs_out[2] = 3; segs_out[3] = 2; return 2 }
29 if c == 11 { segs_out[0] = 0; segs_out[1] = 1; return 1 }
30 if c == 12 { segs_out[0] = 3; segs_out[1] = 1; return 1 }
31 if c == 13 { segs_out[0] = 2; segs_out[1] = 1; return 1 }
32 if c == 14 { segs_out[0] = 3; segs_out[1] = 2; return 1 }
33 return 0
34}
35func main() -> i64 { return 0 }