code wiki / _hdl_build / nx_geo_distance_gate.nx

nx_geo_distance_gate.nx source

↩ module page · 57 lines · 2868 B

1// nx_geo_distance_gate.nx -- GATE for GEO-003 equirectangular distance. Proves on KATs: 2// 1deg latitude ~= 111195 m (the meters-per-degree anchor) 3// 1deg longitude at equator ~= 111195 m 4// 1deg longitude at 60N ~= half of that (cos(60)=0.5 -> longitude-compression in METERS) 5// same point -> 0 6// ratio: (1deg lon equator) ~= 2 * (1deg lon at 60N) -> the cos law holds in the distance, too 7// Tolerances are generous (equirectangular + fixed-point + isqrt rounding); the point is the 8// capability + the cos compression, not sub-meter accuracy. 9// 10// Evidence -> knowledge/status/geo_distance.log (GEODISTGATE authored=organ ... verdict=GREEN). 11// license_tier: ORIGINAL 12import "nx_geo_distance.nx" 13import "nx_syscalls.nx" 14 15const GD_LOG: *u8 = "knowledge/status/geo_distance.log" 16 17func gd_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 } 18func gd_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 } 19 20// 1 if |a-b| <= tol 21func gd_near(a: i64, b: i64, tol: i64) -> i64 { 22 var d: i64 = a - b 23 if d < 0 { d = 0 - d } 24 if d <= tol { return 1 } 25 return 0 26} 27 28func gd_emit(fd: i64, dlat: i64, dlonEq: i64, dlon60: i64, dzero: i64, ok: i64) -> i64 { 29 gd_w(fd, "GEODISTGATE authored=organ method=equirectangular-fixedpoint deg_lat_m=" as *u8); gd_wn(fd, dlat) 30 gd_w(fd, " deg_lon_equator_m=" as *u8); gd_wn(fd, dlonEq) 31 gd_w(fd, " deg_lon_60N_m=" as *u8); gd_wn(fd, dlon60) 32 gd_w(fd, " same_point_m=" as *u8); gd_wn(fd, dzero) 33 if ok == 1 { gd_w(fd, " verdict=GREEN\n" as *u8) } else { gd_w(fd, " verdict=RED\n" as *u8) } 34 return 0 35} 36 37func main() -> i64 { 38 let dlat: i64 = geo_distance_m(0, 0, 1000000, 0) // 1 deg north @ equator 39 let dlonEq: i64 = geo_distance_m(0, 0, 0, 1000000) // 1 deg east @ equator 40 let dlon60: i64 = geo_distance_m(60000000, 0, 60000000, 1000000) // 1 deg east @ 60N 41 let dzero: i64 = geo_distance_m(45000000, 45000000, 45000000, 45000000) // same point 42 43 var ok: i64 = 1 44 if gd_near(dlat, 111195, 300) != 1 { ok = 0 } 45 if gd_near(dlonEq, 111195, 600) != 1 { ok = 0 } 46 if gd_near(dlon60, 55600, 800) != 1 { ok = 0 } // ~half (cos 60 = 0.5) 47 if dzero != 0 { ok = 0 } 48 // the cos law in meters: 1deg lon at equator ~= 2 * (1deg lon at 60N) 49 if gd_near(dlonEq, dlon60 * 2, 1500) != 1 { ok = 0 } 50 51 gd_emit(1, dlat, dlonEq, dlon60, dzero, ok) 52 let lf: i64 = sys_openat_append(GD_LOG, 420) 53 if lf >= 0 { gd_emit(lf, dlat, dlonEq, dlon60, dzero, ok); sys_close(lf) } 54 55 if ok == 1 { return 0 } 56 return 1 57}