code wiki / _hdl_build / nx_viz_geo.nx
nx_viz_geo.nx source
↩ module page · 25 lines · 1233 B
1// nx_viz_geo.nx -- the GEO-PROJECT layer of the sovereign Nishi viz library (the d3-geo core, bits-up).
2// Two projections, pure integer: equirectangular (plate carree, exact) + orthographic (globe, equatorial view,
3// via nx_viz_trig) with back-hemisphere culling. lon in [-180,180], lat in [-90,90]. Closes geo-project.
4// license_tier: ORIGINAL
5import "nx_viz_trig.nx"
6import "nx_syscalls.nx"
7const K_MAGIC_100000000: i64 = 100000000
8const K_MAGIC_10000: i64 = 10000
9
10// equirectangular: lon/lat -> pixel in [0,W]x[0,H]. out2[0]=x out2[1]=y. always visible.
11func vg_equirect(lon: i64, lat: i64, W: i64, H: i64, out2: *i64) -> i64 {
12 out2[0] = (lon + 180) * W / 360
13 out2[1] = (90 - lat) * H / 180
14 return 1
15}
16// orthographic (globe centred on the equator at lon0), radius R. out2[0]=x out2[1]=y (math coords, +y = north).
17// returns 1 if on the near hemisphere (visible), 0 if on the far side (cull).
18func vg_ortho(lon: i64, lat: i64, lon0: i64, R: i64, out2: *i64) -> i64 {
19 let dlon: i64 = lon - lon0
20 out2[0] = (R * vs_cos(lat) * vs_sin(dlon)) / K_MAGIC_100000000
21 out2[1] = (R * vs_sin(lat)) / K_MAGIC_10000
22 if vs_cos(lat) * vs_cos(dlon) >= 0 { return 1 }
23 return 0
24}
25func main() -> i64 { return 0 }