code wiki / _hdl_build / nx_curve_smoothness_census.nx

nx_curve_smoothness_census.nx

buildroot/runtime/_hdl_build/nx_curve_smoothness_census.nx

12306 B226 linesdepth 10pulls 45 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_curve_smoothness_census.nx -- a WEIGHT-INVARIANT smoothness metric that actually isolates FACETING (the thing edge-complexity confounded). Insight: faceting is about the CONTOUR'S TURNING, not its thickness. A smooth curve turns UNIFORMLY (a circle's curvature is constant); a faceted polygon concentrates all its turning into a few sharp vertices. So along the traced outer contour: facet_index = n * Sum(T_i^2) / (Sum|T_i|)^2 where T_i = per-step turning of the tangent For a perfectly-uniform (smooth) contour this = 1.0; for turning concentrated at k corners it -> ~n/k. Scale-free, weight-free, trig-free (turning via integer cross-product of normalized tangent vectors). SELF-VALIDATING LIAR-KILL: a synthetic CIRCLE must read near 1 (smooth) and a HEXAGON must read MUCH higher (6 corners) -- if the metric can't tell a circle from a hexagon it declares ITSELF broken. Only then does it report our "O" vs Chrome's "O". license_tier: ORIGINAL expect_exit: 0

dependencies 1 imports · 0 importers

nx_img_bytes_to_rgb.nx nx_curve_smoothness_census.nx

imports: nx_img_bytes_to_rgb.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main cs_puts cs_make_circle cs_fill_white cs_dot cs_trace cs_ink cs_lum cs_facet cs_isqrt cs_make_hexagon cs_fill_white ↻ cs_dot ↻ cs_num cs_measure_png cs_load sys_read_file sys_openat_rd sys_lseek sys_mmap sys_read sys_close nx_img_bytes_to_rgb sys_mmap ↻ nx_jpeg_decode_rgb sys_mmap ↻ nx_jpeg_dec_ctx_init sys_mmap ↻ _jpeg_ascii_probe_sof sys_mmap ↻ nx_jpeg_seg_init nx_jpeg_seg_next nx_jpeg_sof_parse nx_jpeg_is_progressive prog_be16 nx_jpeg_prog_decode sys_mmap ↻ prog_be16 ↻ nx_jpeg_dqt_parse nx_jpeg_dht_parse

structs

none

consts

12const K_MAGIC_2126: i64 = 2126
13const K_MAGIC_7152: i64 = 7152
14const K_MAGIC_10000: i64 = 10000
15const K_MAGIC_1024: i64 = 1024
16const K_MAGIC_40000: i64 = 40000

functions

18func cs_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
called by 1: main
19func cs_num(v: i64) -> i64 { let b: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 }
called by 1: main
20func cs_lum(rgb: *u8, o: i64) -> i64 { return (K_MAGIC_2126*(rgb[o] as i64)+K_MAGIC_7152*(rgb[o+1] as i64)+722*(rgb[o+2] as i64))/K_MAGIC_10000 }
called by 1: cs_ink
21func cs_ink(rgb: *u8, w: i64, h: i64, x: i64, y: i64) -> i64
called by 1: cs_trace calls 1: cs_lum
26func cs_isqrt(n: i64) -> i64 { if n<=0 { return 0 } var x: i64=n; var y: i64=(x+1)/2; while y<x { x=y; y=(x+n/x)/2 } return x }
called by 1: cs_facet
29func cs_fill_white(rgb: *u8, w: i64, h: i64) -> i64 { var i: i64=0; while i<w*h*3 { rgb[i]=255 as u8; i=i+1 } return 0 }
30func cs_dot(rgb: *u8, w: i64, x: i64, y: i64) -> i64 { let o: i64=(y*w+x)*3; rgb[o]=20 as u8; rgb[o+1]=20 as u8; rgb[o+2]=43 as u8; return 0 }
31func cs_make_circle(rgb: *u8, w: i64, h: i64, cx: i64, cy: i64, r: i64) -> i64
called by 1: main calls 2: cs_fill_whitecs_dot
38func cs_make_hexagon(rgb: *u8, w: i64, h: i64, cx: i64, cy: i64, r: i64, vx: *i64, vy: *i64) -> i64
called by 1: main calls 2: cs_fill_whitecs_dot
68func cs_trace(rgb: *u8, w: i64, h: i64, px: *i64, py: *i64, maxn: i64) -> i64
called by 2: cs_measure_pngmain calls 1: cs_ink
109func cs_facet(px: *i64, py: *i64, n: i64, w: i64) -> i64
called by 2: cs_measure_pngmain calls 1: cs_isqrt
140func cs_load(path: *u8, wh: *i64) -> *u8
147func cs_measure_png(path: *u8) -> i64
called by 1: main calls 3: cs_loadcs_tracecs_facet
158func main() -> i64