code wiki / _hdl_build / nx_geo_tiles_gate.nx

nx_geo_tiles_gate.nx source

↩ module page · 68 lines · 3072 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" 12 13const GT_LOG: *u8 = "knowledge/status/geo_tiles.log" 14 15func 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 } 16func 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 } 17 18func 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 { 19 gt_w(fd, "GEOTILESGATE authored=organ scheme=geodetic-plate-carree nyc_z4_tx=" as *u8); gt_wn(fd, tx) 20 gt_w(fd, " nyc_z4_ty=" as *u8); gt_wn(fd, ty) 21 gt_w(fd, " bbox_contains_nyc=" as *u8); gt_wn(fd, contains) 22 gt_w(fd, " bbox_minlat=" as *u8); gt_wn(fd, minlat) 23 gt_w(fd, " bbox_maxlon=" as *u8); gt_wn(fd, maxlon) 24 gt_w(fd, " z0_tx=" as *u8); gt_wn(fd, z0x); gt_w(fd, " z0_ty=" as *u8); gt_wn(fd, z0y) 25 gt_w(fd, " clamp_tx=" as *u8); gt_wn(fd, clx); gt_w(fd, " clamp_ty=" as *u8); gt_wn(fd, cly) 26 if ok == 1 { gt_w(fd, " verdict=GREEN\n" as *u8) } else { gt_w(fd, " verdict=RED\n" as *u8) } 27 return 0 28} 29 30func main() -> i64 { 31 let nyc_lat: i64 = 40712800 32 let nyc_lon: i64 = 0 - 74006000 33 34 let t: *i64 = sys_mmap(16) as *i64 35 geo_point_tile(4, nyc_lat, nyc_lon, t) 36 let tx: i64 = t[0] 37 let ty: i64 = t[1] 38 39 let bb: *i64 = sys_mmap(8 * 4) as *i64 40 geo_tile_bbox(4, tx, ty, bb) 41 let contains: i64 = geo_bbox_contains(bb, nyc_lat, nyc_lon) 42 43 let z0: *i64 = sys_mmap(16) as *i64 44 geo_point_tile(0, nyc_lat, nyc_lon, z0) 45 46 let cl: *i64 = sys_mmap(16) as *i64 47 geo_point_tile(4, 0 - 90000000, 180000000, cl) 48 49 var ok: i64 = 1 50 if tx != 4 { ok = 0 } 51 if ty != 4 { ok = 0 } 52 if contains != 1 { ok = 0 } 53 if bb[0] != 33750000 { ok = 0 } 54 if bb[1] != (0 - 90000000) { ok = 0 } 55 if bb[2] != 45000000 { ok = 0 } 56 if bb[3] != (0 - 67500000) { ok = 0 } 57 if z0[0] != 0 { ok = 0 } 58 if z0[1] != 0 { ok = 0 } 59 if cl[0] != 15 { ok = 0 } 60 if cl[1] != 15 { ok = 0 } 61 62 gt_emit(1, tx, ty, contains, bb[0], bb[3], z0[0], z0[1], cl[0], cl[1], ok) 63 let lf: i64 = sys_openat_append(GT_LOG, 420) 64 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) } 65 66 if ok == 1 { return 0 } 67 return 1 68}