code wiki / _hdl_build / nx_geo_tiles_gate.nx
nx_geo_tiles_gate.nx source
↩ module page · 76 lines · 3607 B
1// nx_geo_tiles_gate.nx -- GATE for GEO-019 geodetic z/x/y tiles. Proves:
2// point->tile : NYC (40.7128,-74.006) at z=4 -> tile (tx=4, ty=4)
3// tile->bbox : bbox(z4,4,4) == [minlat 33750000, minlon -90000000, maxlat 45000000, maxlon -67500000]
4// round-trip : that bbox CONTAINS NYC (exact, no seam gap)
5// zoom0 : any point -> tile (0,0)
6// clamp : far corner (lat -90e6, lon 180e6) at z4 -> tile (15,15)
7//
8// Evidence -> knowledge/status/geo_tiles.log (GEOTILESGATE authored=organ ... verdict=GREEN).
9// license_tier: ORIGINAL
10import "nx_geo_tiles.nx"
11import "nx_syscalls.nx"
12import "nx_gate_verdict.nx"
13
14const GT_LOG: *u8 = "knowledge/status/geo_tiles.log"
15
16func gt_w(fd: i64, s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(fd, s, n); return 0 }
17func gt_wn(fd: i64, v: i64) -> i64 { let bb: *u8 = sys_mmap(28); var m: i64=v; if m<0 {m=0-m; sys_write(fd,"-" as *u8,1)}; let t: *u8 = sys_mmap(28); var k: i64=0; if m==0 {t[0]=48;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 {bb[i]=t[k-1-i]; i=i+1}; sys_write(fd, bb, k); return 0 }
18
19func gt_emit(fd: i64, tx: i64, ty: i64, contains: i64, minlat: i64, maxlon: i64, z0x: i64, z0y: i64, clx: i64, cly: i64, ok: i64) -> i64 {
20 gt_w(fd, "GEOTILESGATE authored=organ scheme=geodetic-plate-carree nyc_z4_tx=" as *u8); gt_wn(fd, tx)
21 gt_w(fd, " nyc_z4_ty=" as *u8); gt_wn(fd, ty)
22 gt_w(fd, " bbox_contains_nyc=" as *u8); gt_wn(fd, contains)
23 gt_w(fd, " bbox_minlat=" as *u8); gt_wn(fd, minlat)
24 gt_w(fd, " bbox_maxlon=" as *u8); gt_wn(fd, maxlon)
25 gt_w(fd, " z0_tx=" as *u8); gt_wn(fd, z0x); gt_w(fd, " z0_ty=" as *u8); gt_wn(fd, z0y)
26 gt_w(fd, " clamp_tx=" as *u8); gt_wn(fd, clx); gt_w(fd, " clamp_ty=" as *u8); gt_wn(fd, cly)
27 if ok == 1 { gt_w(fd, " verdict=GREEN\n" as *u8) } else { gt_w(fd, " verdict=RED\n" as *u8) }
28 return 0
29}
30
31func main() -> i64 {
32 let nyc_lat: i64 = 40712800
33 let nyc_lon: i64 = 0 - 74006000
34
35 let t: *i64 = sys_mmap(16) as *i64
36 geo_point_tile(4, nyc_lat, nyc_lon, t)
37 let tx: i64 = t[0]
38 let ty: i64 = t[1]
39
40 let bb: *i64 = sys_mmap(8 * 4) as *i64
41 geo_tile_bbox(4, tx, ty, bb)
42 let contains: i64 = geo_bbox_contains(bb, nyc_lat, nyc_lon)
43
44 let z0: *i64 = sys_mmap(16) as *i64
45 geo_point_tile(0, nyc_lat, nyc_lon, z0)
46
47 let cl: *i64 = sys_mmap(16) as *i64
48 geo_point_tile(4, 0 - 90000000, 180000000, cl)
49
50 var ok: i64 = 1
51 if tx != 4 { ok = 0 }
52 if ty != 4 { ok = 0 }
53 if contains != 1 { ok = 0 }
54 if bb[0] != 33750000 { ok = 0 }
55 if bb[1] != (0 - 90000000) { ok = 0 }
56 if bb[2] != 45000000 { ok = 0 }
57 if bb[3] != (0 - 67500000) { ok = 0 }
58 if z0[0] != 0 { ok = 0 }
59 if z0[1] != 0 { ok = 0 }
60 if cl[0] != 15 { ok = 0 }
61 if cl[1] != 15 { ok = 0 }
62
63 gt_emit(1, tx, ty, contains, bb[0], bb[3], z0[0], z0[1], cl[0], cl[1], ok)
64 let lf: i64 = sys_openat_append(GT_LOG, 420)
65 if lf >= 0 { gt_emit(lf, tx, ty, contains, bb[0], bb[3], z0[0], z0[1], cl[0], cl[1], ok); sys_close(lf) }
66
67 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
68 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
69 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
70 let ctr__dry: *i64 = gv_ctr()
71 ctr__dry[0] = ok
72 ctr__dry[1] = 1
73 let rc__dry: i64 = gv_verdict("GEO-TILES-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8)
74 sys_exit(rc__dry)
75 return rc__dry
76}