Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

render_example_test.gno

3.27 Kb · 91 lines
 1package geohashdemo
 2
 3// ExampleRender pins the realm's root Render output as a testable example.
 4func ExampleRender() {
 5	print(Render(""))
 6	// Output:
 7	// # Geohash
 8	//
 9	// Turning a latitude and longitude into a short base32 string, demoing the [`p/moul/x/daily/geohash`](/p/moul/x/daily/geohash/v0) library.
10	//
11	// ## One point, at growing precision
12	//
13	// Jutland, Denmark, at 57.64911, 10.40744:
14	//
15	// ```
16	//  1  u
17	//  2  u4
18	//  3  u4p
19	//  4  u4pr
20	//  5  u4pru
21	//  6  u4pruy
22	//  7  u4pruyd
23	//  8  u4pruydq
24	//  9  u4pruydqq
25	// 10  u4pruydqqv
26	// 11  u4pruydqqvj
27	// ```
28	//
29	// Every character adds five bits and every prefix is itself a valid geohash of the same place, so truncating one zooms out. Two hashes sharing a long prefix are close together, which is what lets an avl tree keyed this way answer "everything near here" with a range scan and no geometry at all.
30	//
31	// Two more places, at the length each one needs:
32	//
33	// - Null Island (0, 0): `s0000`
34	// - Leon, Spain (42.6, -5.6): `ezs42`
35	// - Jutland, Denmark (57.64911, 10.40744): `u4pruy`
36	//
37	// > Next: [`/cell`](/r/moul/x/daily/geohashdemo/v0:cell) for the box a hash names, [`/neighbors`](/r/moul/x/daily/geohashdemo/v0:neighbors) for the eight cells around one.
38}
39
40// ExampleRender_cell pins the page that shows a geohash is a box, not a point.
41func ExampleRender_cell() {
42	print(Render("/cell"))
43	// Output:
44	// # Geohash
45	//
46	// Turning a latitude and longitude into a short base32 string, demoing the [`p/moul/x/daily/geohash`](/p/moul/x/daily/geohash/v0) library.
47	//
48	// ## The box `ezs42` names
49	//
50	// A geohash is a box, never a point, and the shorter the hash the bigger the box.
51	//
52	// ```
53	// latitude   42.5830078125 .. 42.626953125
54	// longitude  -5.625 .. -5.5810546875
55	// size       0.0439453125 by 0.0439453125 degrees
56	// ```
57	//
58	// `Decode` reports the centre, 42.60498046875, -5.60302734375, because the centre is the best single point a box can give. The coordinates that produced the hash, 42.6, -5.6, are inside it: yes.
59	//
60	// Null Island is not: no.
61	//
62	// > Next: [`/neighbors`](/r/moul/x/daily/geohashdemo/v0:neighbors).
63}
64
65// ExampleRender_neighbors pins the eight surrounding cells and the wrap at the
66// antimeridian.
67func ExampleRender_neighbors() {
68	print(Render("/neighbors"))
69	// Output:
70	// # Geohash
71	//
72	// Turning a latitude and longitude into a short base32 string, demoing the [`p/moul/x/daily/geohash`](/p/moul/x/daily/geohash/v0) library.
73	//
74	// ## The eight cells around `ezs42`
75	//
76	// ```
77	// ezefx ezs48 ezs49
78	// ezefr ezs42 ezs43
79	// ezefp ezs40 ezs41
80	// ```
81	//
82	// Each one is computed by walking exactly one cell from the centre and re-encoding. Every bound is an exact binary fraction, so the step lands on another centre rather than near one, and stepping back is the identity.
83	//
84	// ### The antimeridian is not an edge of the world
85	//
86	// `z` is the top right corner cell of the world. The cell east of it is `b`, the top left one, because longitude wraps. The classic lookup-table implementations report nothing there, which is a property of the tables and not of the globe.
87	//
88	// Latitude genuinely stops, though, so `z` has no northern neighbour and `Neighbors` returns 5 cells rather than eight: `b`, `8`, `x`, `w`, `y`.
89	//
90	// > Back to [the overview](/r/moul/x/daily/geohashdemo/v0).
91}