@johnmorrisdotca/wakusei-planets 0.45.0 → 0.46.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.46.0] - 2026-11-13
6
+
7
+ - **Standing on the Moon** (MODULES-1308). `<wakusei-surface>` (`@johnmorrisdotca/wakusei-planets/surface/element`) puts the viewer on the Moon at the Apollo 17 landing site, Taurus-Littrow: the ground is drawn from the measured 5 m LROC/LOLA height model (public domain, credited in NOTICE.md) with the Sun and the Earth where they really are at the moment shown (`moonSky`), hard shadows (the measured ground's baked into horizon maps, only the made detail marched, in three `quality` tiers with `auto` stepping down on a slow card), a ground picture from the LROC mosaic with its shading divided out, and made detail marked as made (craters from half a metre by the lunar size-frequency law, mostly old and soft; rounded, part-buried rocks lit like the ground). One draw when something changes, nothing at rest; drag to look, W A S D to walk at 1.4 m/s over the ground, zoom is the field of view. The first view is 4.2 MB (12.9 MB for the whole site), fetched in rings: the coarse level whole, the middle of the finest, nearest first after that; tiles and horizon maps are lossless WebP. The tiles are made by `scripts/make-moon-terrain.py` (`pnpm terrain:fetch` downloads the three NASA files, SHA-256 checked, then `pnpm terrain`) and the Pages build makes and serves them beside the body tiles (cached on the script; nothing is downloaded when the cache hits), in no package. Pure parts (`moonSky`, the camera, the tile decoding and filling, the made craters and rocks, `loadPlan`) are exported from `/surface`.
8
+ - **Coming down from orbit** (MODULES-1308). `import "@johnmorrisdotca/wakusei-planets/surface/land"` adds `land(site)`, `leave()`, `landed` and `standing` to `<wakusei-space>`: the camera goes to the Moon, turns over the site and comes in while the ground loads, and the standing view fades in (`wakusei-landing`, `wakusei-landed`, `wakusei-left`). The page has one renderer, so the ground is fetched on standby while the camera comes in, the orbit view goes to black as the standing view takes the renderer and the ground fades up; `leave()` gives it back through the new `resume()` on `<wakusei-space>`. The ground shows the orbit view's own moment (`time: "landing"` for the landing's). The Moon page of the demo uses it.
9
+ - **Guides** `docs/guides/surface.md` and its Japanese twin.
10
+ - **A travel test names where the move is recorded** (MODULES-1321, test only): `e2e/space-travel.demo.ts` asks for the move where the page records it.
11
+
12
+ ## [0.45.1] - 2026-11-13
13
+
14
+ - **Browser tests that pass on a busy machine** (test only). A sweep of the e2e specs for the races TEST-RULES lists: the draw count is taken in the same call as the change (`callCounted`, `setCounted`, `clickCounted`) in place of a read in one call and the change in the next; settles are the draws holding still with no picture pending (`quiet`, `quietElement`) in place of fixed sleeps; the soak warm-up goes to every body and step; the picker group buttons are the picker's own, not `.first()`; the body page's shaded looks are pinned to a date. `CPU_THROTTLE=4` (e2e/load.ts) runs any spec that imports it at a quarter of the speed.
15
+
5
16
  ## [0.45.0] - 2026-11-13
6
17
 
7
18
  - **Sharper Moon and Mars maps, switched off until asked** (MODULES-1264). `pnpm tiles:moon` and `pnpm tiles:mars` cut level 4 (32768 pixels across) from the LROC WAC 100 m mosaic and the Viking MDIM 2.1 mosaic at 232 m. The Pages build runs them only when the repository variable `WAKUSEI_SHARP_TILES` is `1`, and does not download those files otherwise. `tilePoint` names the tile pixel of a longitude and latitude.
package/NOTICE.md CHANGED
@@ -261,6 +261,17 @@ The rows of `/moon-catalogue` (`src/data/moon-catalogue.ts`, made by `scripts/ma
261
261
  - **Groups** are this package's own sorting of the mean orbits by a stated rule (the guide "Every known moon"); the group names are the usual ones, each named after its largest member.
262
262
  - **Japanese names** are given only for the 29 moons the package draws in full, whose katakana was checked; the other moons keep their English names and designations.
263
263
 
264
+ ## The Moon's ground (standing on the Moon)
265
+
266
+ The height tiles of `<wakusei-surface>` (`scripts/make-moon-terrain.py`; they are made by the Pages workflow and are in no package and no repository), read on 2026-11-13. Only files from the NASA Planetary Data System archive are used, from the hosts `pds.lroc.im-ldi.com` (the LROC data node) and `pds-geosciences.wustl.edu` (the Geosciences node); the originals are kept outside the checkout.
267
+
268
+ - **Heights near the Apollo 17 landing site**: `NAC_DTM_APOLLO17.TIF`, the Lunar Reconnaissance Orbiter Camera (LROC) narrow angle camera height model of Taurus-Littrow, 5 m a pixel (https://pds.lroc.im-ldi.com/data/LRO-L-LROC-5-RDR-V1.0/LROLRC_2001/DATA/SDP/NAC_DTM/APOLLO17/NAC_DTM_APOLLO17.TIF, 463,397,471 bytes, data set `LRO-L-LROC-5-RDR-V1.0`, product version 1.9), made by Arizona State University with the methods of Henriksen et al. (2017), "Extracting accurate and precise topography from LROC narrow angle camera stereo observations", Icarus 283, 122-137 (https://doi.org/10.1016/j.icarus.2016.05.012): registered to the laser altimeter's profiles, so absolute accuracy follows the altimeter's (about 1 m in height and 10 m in place) and relative precision is better than the 5 m pixel.
269
+ - **The ground picture**: the browse picture of `NAC_ROI_APOLLO17LOC_E205N0306_5M`, the Apollo 17 low-Sun controlled narrow angle camera mosaic, 5 m a pixel (https://pds.lroc.im-ldi.com/data/LRO-L-LROC-5-RDR-V1.0/LROLRC_2001/EXTRAS/BROWSE/NAC_ROI/APOLLO17LOC/NAC_ROI_APOLLO17LOC_E205N0306_5M.TIF, 108,949,491 bytes). The build fits the Sun the mosaic was lit by to the heights, divides that shading out and keeps the ground's own light and dark (the fit for Apollo 17: azimuth 264 degrees, elevation 7 degrees, correlation 0.76).
270
+ - **Heights beyond the model**: the Lunar Orbiter Laser Altimeter (LOLA) global height map at 64 pixels a degree (`ldem_64.img`, data set `LRO-L-LOLA-4-GDR-V1.0`, https://pds-geosciences.wustl.edu/lro/lro-l-lola-3-rdr-v1/lrolol_1xxx/data/lola_gdr/cylindrical/img/ldem_64.img, 23,040 x 11,520 samples of 16 bits, height = 0.5 m x value above a sphere of radius 1,737.4 km), of which only the window round the site is read, by HTTP byte ranges (about 25 MB of a 531 MB file).
271
+ - **Terms**: the PDS Geosciences Node's FAQ (https://pds-geosciences.wustl.edu/faq.html, read 2026-11-13): "Data sets archived in the PDS are in the public domain." The LROC terms of use (https://lroc.im-ldi.com/about/terms, read 2026-11-13) say the products of the LROC data node and the PDS archive are in the public domain, that images elsewhere on the LROC website (featured images and curated products) are copyrighted and are not used here, and ask for the credit "NASA/GSFC/Arizona State University". The credit lines the page shows are that, and "LOLA Team (NASA/GSFC)", with the Planetary Data System as the publisher of the data sets (the PDS asks that a data set be cited like published research; its DOI is in the PDS DOI portal).
272
+ - **Left out**: the merged LOLA and Kaguya (SELENE) height grid. The JAXA part's terms could not be found, and an MIT-licensed package can pass on only what it knows to be free to pass on.
273
+ - **Made, not measured**: everything below the 5 m grid (small craters from 0.5 to 20 m, the roughness of the dust, rocks of 0.1 to 1.5 m) is made by this package from a seeded random grid, by the lunar size-frequency law, and is not a picture or a measurement of any place. The picture says so under the ground.
274
+
264
275
  ## Interior cutaway
265
276
 
266
277
  The cutaway's figures were read on 2026-11-13. NASA content is not subject to copyright in the United States. Nothing was copied from the pages; the numbers and the materials they name are the pages' facts, and a figure the page gives as "about" stays marked about.
package/README.md CHANGED
@@ -19,7 +19,7 @@ Wakusei Planets runs in the browser of a phone, a tablet or a computer: nothing
19
19
 
20
20
  <p align="center"><img alt="The demo on a desk: Saturn in the painted look, turning in the big view, with the page's links to the portrait builder, the colouring sheets, the space view, the star page and the size line-up above it, and the choice of body and its moons below" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/main/docs/images/home-desk.webp" width="620"> <img alt="The same page on a phone: the same links in rows, and Saturn in the painted look below them" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/main/docs/images/home-phone.webp" width="200"></p>
21
21
 
22
- <p align="center"><img alt="Every body at one scale, the Earth among them: each small body has a magnified picture joined by a line, and the Sun shows only its edge" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.45.0/docs/images/lineup-desk.png" width="640"></p>
22
+ <p align="center"><img alt="Every body at one scale, the Earth among them: each small body has a magnified picture joined by a line, and the Sun shows only its edge" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.46.0/docs/images/lineup-desk.png" width="640"></p>
23
23
 
24
24
  ## Who it is for
25
25
 
@@ -388,7 +388,7 @@ The tiles of every body share one 48 MB budget, six loads at a time for a source
388
388
 
389
389
  ## The portrait builder
390
390
 
391
- <p align="center"><img alt="The Sun and the planets in an arc, painted, with their names, in the portrait builder" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.45.0/docs/images/portrait-family.png" width="640"></p>
391
+ <p align="center"><img alt="The Sun and the planets in an arc, painted, with their names, in the portrait builder" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.46.0/docs/images/portrait-family.png" width="640"></p>
392
392
 
393
393
  [The portrait builder](https://johnmorrisdotca.github.io/wakusei-planets/portrait.html) puts any bodies in one picture: drag them, size them, turn them, order them front to back, arrange them in a row, an arc, a grid or at true orbit distance (true or readable sizes, a planet's moons round it in orbit order), light them from one direction, and take the code, a PNG or an SVG. The scene is kept in the address, and every body is drawn in one WebGL scene, so the page holds one WebGL context. [The portrait builder](docs/guides/portrait-builder.md) is its guide.
394
394
 
@@ -483,6 +483,7 @@ Each guide has a Japanese twin in [docs/guides/ja](docs/guides/ja/getting-starte
483
483
  | [Close zoom and map tiles](docs/guides/close-zoom.md) | How far each body zooms and why, the finer map tiles for a close zoom (made from public-domain maps, served beside the demo, never in the package), the generic detail, what it costs |
484
484
  | [Outside data, the data door](docs/guides/data-door.md) | Hand the package your own maps of a body or small bodies with their licence and credit, switch them off, and show whose data is on the screen |
485
485
  | [Riding along](docs/guides/ride-along.md) | The camera on a moon, a planet or any moving point, looking at what it goes round |
486
+ | [Standing on the Moon](docs/guides/surface.md) | A person at the Apollo 17 landing site: the measured ground, the Sun and the Earth where they are, hard shadows, and detail that is made and says so |
486
487
  | [Accuracy](docs/guides/accuracy.md) | How far each body is from JPL Horizons |
487
488
  | [In your own three.js scene](docs/guides/in-your-own-scene.md) | `painter.make` |
488
489
  | [Time](docs/guides/time.md) | Julian dates, calendars, time scales, sidereal time, Mars time |
@@ -534,7 +535,7 @@ BODIES.pluto.kind; // "dwarf-planet"
534
535
 
535
536
  If this package helps a paper, a talk or a class, please cite it as software. GitHub's "Cite this repository" button reads [CITATION.cff](CITATION.cff) and gives BibTeX and APA; in plain text:
536
537
 
537
- > Morris, J. (2026). *Wakusei Planets* (version 0.45.0) [Computer software]. https://github.com/johnmorrisdotca/wakusei-planets
538
+ > Morris, J. (2026). *Wakusei Planets* (version 0.46.0) [Computer software]. https://github.com/johnmorrisdotca/wakusei-planets
538
539
 
539
540
  Cite the version you used (`npm ls @johnmorrisdotca/wakusei-planets`), and cite the sources of the numbers you use as well: [NOTICE.md](NOTICE.md) names each one, with the paper or the page it was read from (the IAU working group's report for sizes and poles, VSOP87B, ELP2000-82B, L1.2 and TASS1.7 for positions, and NASA's JPL Horizons for the fits and the spacecraft).
540
541
 
@@ -11,7 +11,7 @@ import { type BodyMapSource } from "../door/map.ts";
11
11
  * console.log(TEXTURE_BASE);
12
12
  * ```
13
13
  */
14
- export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@0.45.0/dist/textures/";
14
+ export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@0.46.0/dist/textures/";
15
15
  /**
16
16
  * Where the sharpest surface pictures are: the files of this exact version in the repository, on jsDelivr's GitHub address. The npm package holds only the two smaller widths, so a page that
17
17
  * never zooms in never fetches them. Set `texture-far-base` on an element to serve them yourself.
@@ -23,7 +23,7 @@ export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdot
23
23
  * console.log(TEXTURE_FAR_BASE);
24
24
  * ```
25
25
  */
26
- export declare const TEXTURE_FAR_BASE = "https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v0.45.0/textures/";
26
+ export declare const TEXTURE_FAR_BASE = "https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v0.46.0/textures/";
27
27
  /**
28
28
  * Where the finer map tiles are by default: the demo site's `tiles/` folder (GitHub Pages sends `access-control-allow-origin: *`). The tiles are made by `scripts/make-body-tiles.py` and are in no package and no repository:
29
29
  * a page that serves its own gives the folder in the `tiles` attribute, and `tiles="off"` turns them off. A page that sets `texture-base` (it serves its own pictures) has none unless it says where they are.
@@ -366,6 +366,13 @@ export declare class WakuseiSpace extends HTMLElement {
366
366
  set farOpacity(value: number);
367
367
  /** The body under the pointer, a finger or the keyboard's focus now, or null: its system's names are drawn at full strength. */
368
368
  get hovered(): BodyId | null;
369
+ /**
370
+ * Take the renderer back and draw: the page has one renderer and one view has it at a time, so after another view (the standing view that `land` of `/surface/land` puts over this one) has had it, this view is blank
371
+ * until it is given back. Resolves true when this view is live again.
372
+ *
373
+ * @returns Whether the view is live.
374
+ */
375
+ resume(): Promise<boolean>;
369
376
  /**
370
377
  * Where each body is for the picture at the last draw: in view or not, and for one out of view the edge of the picture it lies beyond, the point on that edge, the way to it, and whether it is behind the camera. It
371
378
  * covers the Sun, the planets, the dwarf planets and the minor bodies, the moons of the body looked at and any other moon drawn; not the body the camera rides on. `wakusei-sight` fires with the same list whenever a
@@ -1006,6 +1006,18 @@ export class WakuseiSpace extends HTMLElement {
1006
1006
  get hovered() {
1007
1007
  return this.#hovered;
1008
1008
  }
1009
+ /**
1010
+ * Take the renderer back and draw: the page has one renderer and one view has it at a time, so after another view (the standing view that `land` of `/surface/land` puts over this one) has had it, this view is blank
1011
+ * until it is given back. Resolves true when this view is live again.
1012
+ *
1013
+ * @returns Whether the view is live.
1014
+ */
1015
+ async resume() {
1016
+ const live = (await this.#view?.focus()) ?? false;
1017
+ if (live)
1018
+ this.#gate?.request();
1019
+ return live;
1020
+ }
1009
1021
  /**
1010
1022
  * Where each body is for the picture at the last draw: in view or not, and for one out of view the edge of the picture it lies beyond, the point on that edge, the way to it, and whether it is behind the camera. It
1011
1023
  * covers the Sun, the planets, the dwarf planets and the minor bodies, the moons of the body looked at and any other moon drawn; not the body the camera rides on. `wakusei-sight` fires with the same list whenever a
@@ -0,0 +1,169 @@
1
+ /** The smallest crater's nominal diameter in metres: each octave doubles it, up to `OCTAVES` octaves (0.5, 1, 2, 4, 8, 16). A crater in an octave is between 1 and 2 times its nominal diameter. */
2
+ export declare const D0 = 0.5;
3
+ export declare const OCTAVES = 6;
4
+ /** A cell is this many nominal diameters across, with at most one crater in it. */
5
+ export declare const CELL = 3;
6
+ /** The share of a cell, from its edge, within which the craters of the cell over the edge are looked for. */
7
+ export declare const NEAR_EDGE = 0.2;
8
+ /** The PCG hash of two 32 bit integers, as the shader does it. */
9
+ export declare function pcg2d(x: number, y: number): [number, number];
10
+ /** A hash cut to a number from 0 up to but not including 1, exact in 24 bits. */
11
+ export declare const unit24: (h: number) => number;
12
+ /**
13
+ * One crater: where its middle is (metres in the site's plane), its radius, how deep and how high its rim, how wide its rim, and how old (0 fresh, 1 worn flat).
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { craterProfile, type Crater } from "@johnmorrisdotca/wakusei-planets/surface";
18
+ *
19
+ * const crater: Crater = { x: 0, y: 0, radius: 4, depth: 0.8, rim: 0.2, rimWidth: 0.3, age: 0.2 };
20
+ * console.log(`${craterProfile(crater, 0, 0).h.toFixed(2)} m at the middle`);
21
+ * ```
22
+ */
23
+ export interface Crater {
24
+ x: number;
25
+ y: number;
26
+ radius: number;
27
+ depth: number;
28
+ rim: number;
29
+ rimWidth: number;
30
+ age: number;
31
+ }
32
+ /** The share of cells that hold a crater in an octave: many small, few large. */
33
+ export declare const occupancy: (octave: number) => number;
34
+ /**
35
+ * The crater in a cell of an octave, or `undefined` for an empty cell.
36
+ *
37
+ * @param cx - The cell's column.
38
+ * @param cy - The cell's row.
39
+ * @param octave - 0 for the smallest (0.5 m) up.
40
+ * @returns The crater, or `undefined` when the cell holds none (most cells do not: see `occupancy`).
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * import { craterIn } from "@johnmorrisdotca/wakusei-planets/surface";
45
+ *
46
+ * console.log(craterIn(4, -2, 3)?.radius.toFixed(2), craterIn(0, 0, 3));
47
+ * ```
48
+ */
49
+ export declare function craterIn(cx: number, cy: number, octave: number): Crater | undefined;
50
+ /**
51
+ * A crater's height at a point: the bowl, the soft rim. Also the slope along x and y.
52
+ *
53
+ * @param c - The crater.
54
+ * @param px - Metres east of the site.
55
+ * @param py - Metres north of the site.
56
+ * @returns The height in metres (negative in the bowl, positive on the rim) and the slope along east (`gx`) and north (`gy`).
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * import { craterProfile, type Crater } from "@johnmorrisdotca/wakusei-planets/surface";
61
+ *
62
+ * const crater: Crater = { x: 0, y: 0, radius: 4, depth: 0.8, rim: 0.2, rimWidth: 0.3, age: 0.2 };
63
+ * console.log(craterProfile(crater, 0, 0).h.toFixed(2), craterProfile(crater, 4, 0).h.toFixed(2));
64
+ * ```
65
+ */
66
+ export declare function craterProfile(c: Crater, px: number, py: number): {
67
+ h: number;
68
+ gx: number;
69
+ gy: number;
70
+ };
71
+ /** How far a crater's reach goes in multiples of its radius, beyond which the apron is too faint to count. */
72
+ export declare const REACH = 4;
73
+ /**
74
+ * The made ground's height at a point, and its slope, from every crater of every octave not smaller than `fromDiameter` (a crater is faded in over a factor of two above it, so none
75
+ * pops). The cell the point is in is looked at in each octave, and a neighbouring cell when the point is within a fifth of the edge between them: a crater is kept to the middle of its cell, so its rim and the strong part of its apron reach no further.
76
+ *
77
+ * @param x - Metres east of the site.
78
+ * @param y - Metres north of the site.
79
+ * @param fromDiameter - The smallest nominal diameter to count, in metres: a distance's worth of pixels (craters smaller than a few pixels only shimmer).
80
+ * @returns The height in metres and the slope along east and north.
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * import { madeGround } from "@johnmorrisdotca/wakusei-planets/surface";
85
+ *
86
+ * console.log(madeGround(12.5, -8, 0.5).h.toFixed(2));
87
+ * ```
88
+ */
89
+ export declare function madeGround(x: number, y: number, fromDiameter: number): {
90
+ h: number;
91
+ gx: number;
92
+ gy: number;
93
+ };
94
+ /**
95
+ * One rock: where it lies, how big (its longest side in metres), which of the three shapes, how it is turned, how bright it is, and how flat.
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * import { rocksAround, type Rock } from "@johnmorrisdotca/wakusei-planets/surface";
100
+ *
101
+ * const rock: Rock | undefined = rocksAround(0, 0, 20, 0.0024)[0];
102
+ * console.log(rock?.size.toFixed(2), rock?.shape);
103
+ * ```
104
+ */
105
+ export interface Rock {
106
+ x: number;
107
+ y: number;
108
+ size: number;
109
+ shape: number;
110
+ turn: number;
111
+ tone: number;
112
+ flat: number;
113
+ }
114
+ /** The rocks of a class are `ROCK_MIN * 2 ** class` metres: 0.05, 0.1, 0.2, 0.4, 0.8, 1.6; a rock of a class is between 1 and 1.4 times that. */
115
+ export declare const ROCK_MIN = 0.05;
116
+ export declare const ROCK_CLASSES = 6;
117
+ /**
118
+ * How much denser the rocks are at a point for fresh crater rims near it: 1 away from any, up to 5 on a young crater's rim.
119
+ *
120
+ * @param x - Metres east of the site.
121
+ * @param y - Metres north of the site.
122
+ * @returns A factor from 1 (no young rim near) up to 5 (on one).
123
+ *
124
+ * @example
125
+ * ```ts
126
+ * import { rimBoost } from "@johnmorrisdotca/wakusei-planets/surface";
127
+ *
128
+ * console.log(rimBoost(0, 0), rimBoost(51, -19) >= 1);
129
+ * ```
130
+ */
131
+ export declare function rimBoost(x: number, y: number): number;
132
+ /**
133
+ * The rocks round a point, within `radius` metres: seeded and fixed to the place. Many small, few large (about a third as many of each class up), denser by fresh rims; a rock too small for a few pixels at its
134
+ * distance is left out, so nothing shimmers. They are made, not measured.
135
+ *
136
+ * @param cx - Metres east of the site.
137
+ * @param cy - Metres north of the site.
138
+ * @param radius - How far round to look, in metres.
139
+ * @param pixel - The angle one pixel takes in radians (a rock smaller than three pixels at its distance is left out).
140
+ * @returns The rocks, nearest first.
141
+ *
142
+ * @example
143
+ * ```ts
144
+ * import { rocksAround } from "@johnmorrisdotca/wakusei-planets/surface";
145
+ *
146
+ * console.log(rocksAround(0, 0, 20, 0.0024).length > 100);
147
+ * ```
148
+ */
149
+ export declare function rocksAround(cx: number, cy: number, radius: number, pixel: number): Rock[];
150
+ /**
151
+ * The nearest place to a point where a person can stand without being in a made crater or on a made rim: the made ground there is level over two metres round. The landing point itself is
152
+ * the first tried, so most of the time a person stands where the lunar module stood.
153
+ *
154
+ * @param x - Metres east of the site.
155
+ * @param y - Metres north of the site.
156
+ * @returns A place within thirty metres of the point.
157
+ *
158
+ * @example
159
+ * ```ts
160
+ * import { standingPlace } from "@johnmorrisdotca/wakusei-planets/surface";
161
+ *
162
+ * const place = standingPlace(0, 0);
163
+ * console.log(Math.hypot(place.x, place.y) < 30);
164
+ * ```
165
+ */
166
+ export declare function standingPlace(x?: number, y?: number): {
167
+ x: number;
168
+ y: number;
169
+ };
@@ -0,0 +1,292 @@
1
+ // The made detail: what is smaller than the 5 m grid. Craters by the lunar size-frequency law (many small, few large, soft rims, a depth of a fifth of the diameter when fresh and shallower as they
2
+ // age), laid on a seeded grid of cells, so the same place is always the same. It is MADE, not measured, and the page says so. The shader (glsl.ts) holds the same formulas; this is the same
3
+ // maths in JS, for the feet (the eyes follow the made ground too), for the rocks (placed on the ground and denser by fresh rims) and for the tests that hold the two together.
4
+ // Every random number is an integer hash (PCG, 32 bit) cut to 24 bits, so the two agree exactly.
5
+ /** The smallest crater's nominal diameter in metres: each octave doubles it, up to `OCTAVES` octaves (0.5, 1, 2, 4, 8, 16). A crater in an octave is between 1 and 2 times its nominal diameter. */
6
+ export const D0 = 0.5;
7
+ export const OCTAVES = 6;
8
+ /** A cell is this many nominal diameters across, with at most one crater in it. */
9
+ export const CELL = 3;
10
+ /** The share of a cell, from its edge, within which the craters of the cell over the edge are looked for. */
11
+ export const NEAR_EDGE = 0.2;
12
+ const mul = (a, b) => Math.imul(a, b) >>> 0;
13
+ /** The PCG hash of two 32 bit integers, as the shader does it. */
14
+ export function pcg2d(x, y) {
15
+ let vx = (mul(x, 1664525) + 1013904223) >>> 0;
16
+ let vy = (mul(y, 1664525) + 1013904223) >>> 0;
17
+ vx = (vx + mul(vy, 1664525)) >>> 0;
18
+ vy = (vy + mul(vx, 1664525)) >>> 0;
19
+ vx = (vx ^ (vx >>> 16)) >>> 0;
20
+ vy = (vy ^ (vy >>> 16)) >>> 0;
21
+ vx = (vx + mul(vy, 1664525)) >>> 0;
22
+ vy = (vy + mul(vx, 1664525)) >>> 0;
23
+ vx = (vx ^ (vx >>> 16)) >>> 0;
24
+ vy = (vy ^ (vy >>> 16)) >>> 0;
25
+ return [vx, vy];
26
+ }
27
+ /** A hash cut to a number from 0 up to but not including 1, exact in 24 bits. */
28
+ export const unit24 = (h) => (h >>> 8) / 16777216;
29
+ /** The share of cells that hold a crater in an octave: many small, few large. */
30
+ export const occupancy = (octave) => (octave >= 3 ? 0.5 : 1) * 0.36 * Math.pow(2, -0.5 * octave);
31
+ /**
32
+ * The crater in a cell of an octave, or `undefined` for an empty cell.
33
+ *
34
+ * @param cx - The cell's column.
35
+ * @param cy - The cell's row.
36
+ * @param octave - 0 for the smallest (0.5 m) up.
37
+ * @returns The crater, or `undefined` when the cell holds none (most cells do not: see `occupancy`).
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * import { craterIn } from "@johnmorrisdotca/wakusei-planets/surface";
42
+ *
43
+ * console.log(craterIn(4, -2, 3)?.radius.toFixed(2), craterIn(0, 0, 3));
44
+ * ```
45
+ */
46
+ export function craterIn(cx, cy, octave) {
47
+ const [a, b] = pcg2d((cx | 0) >>> 0, ((cy | 0) + octave * 7919) >>> 0);
48
+ if (unit24(a) >= occupancy(octave))
49
+ return undefined;
50
+ const [c, d] = pcg2d(((cx | 0) + 104729) >>> 0, ((cy | 0) + octave * 7919 + 15485863) >>> 0);
51
+ const nominal = D0 * 2 ** octave;
52
+ const cell = CELL * nominal;
53
+ const diameter = nominal * (1 + (octave === OCTAVES - 1 ? 0.25 : 1) * unit24(d));
54
+ // most craters are old: of every hundred, about four are fresh (age under 0.15) and three in four are worn (over 0.7): soft, shallow, nearly rimless bowls
55
+ const r = (a & 255) / 255;
56
+ const age = 1 - r * r * r * r;
57
+ const radius = diameter / 2;
58
+ const vary = 0.6 + 0.4 * ((c & 255) / 255);
59
+ return {
60
+ x: (cx + 0.25 + 0.5 * unit24(b)) * cell,
61
+ y: (cy + 0.25 + 0.5 * unit24(c)) * cell,
62
+ radius,
63
+ depth: diameter * (0.2 - 0.17 * age) * vary,
64
+ rim: 0.045 * diameter * (1 - age) ** 1.5,
65
+ rimWidth: 0.22 + 0.5 * age,
66
+ age,
67
+ };
68
+ }
69
+ /**
70
+ * A crater's height at a point: the bowl, the soft rim. Also the slope along x and y.
71
+ *
72
+ * @param c - The crater.
73
+ * @param px - Metres east of the site.
74
+ * @param py - Metres north of the site.
75
+ * @returns The height in metres (negative in the bowl, positive on the rim) and the slope along east (`gx`) and north (`gy`).
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * import { craterProfile, type Crater } from "@johnmorrisdotca/wakusei-planets/surface";
80
+ *
81
+ * const crater: Crater = { x: 0, y: 0, radius: 4, depth: 0.8, rim: 0.2, rimWidth: 0.3, age: 0.2 };
82
+ * console.log(craterProfile(crater, 0, 0).h.toFixed(2), craterProfile(crater, 4, 0).h.toFixed(2));
83
+ * ```
84
+ */
85
+ export function craterProfile(c, px, py) {
86
+ const dx = px - c.x;
87
+ const dy = py - c.y;
88
+ const r = Math.hypot(dx, dy);
89
+ const x = r / c.radius;
90
+ let h = 0;
91
+ let dh = 0;
92
+ if (x < 1) {
93
+ // a fresh bowl is a plain parabola with a sharp edge; a worn one has a flat rim and a slope that dies out at the edge, so no outline shows
94
+ const bowl = 1 - x * x;
95
+ const pw = 1 + c.age;
96
+ h = -c.depth * bowl ** pw;
97
+ dh = 2 * c.depth * pw * x * bowl ** c.age;
98
+ }
99
+ const e = (x - 1) / c.rimWidth;
100
+ const rim = c.rim * Math.exp(-e * e);
101
+ h += rim;
102
+ dh += (-2 * c.rim * e * Math.exp(-e * e)) / c.rimWidth;
103
+ // a long soft apron past the rim: the ejecta, a thin tail
104
+ if (x > 1) {
105
+ const tail = 0.25 * c.rim * Math.pow(1 / x, 3);
106
+ h += tail;
107
+ dh += -0.75 * c.rim * Math.pow(1 / x, 4);
108
+ }
109
+ const k = r > 1e-9 ? dh / (c.radius * r) : 0;
110
+ return { h, gx: k * dx, gy: k * dy };
111
+ }
112
+ /** How far a crater's reach goes in multiples of its radius, beyond which the apron is too faint to count. */
113
+ export const REACH = 4;
114
+ /**
115
+ * The made ground's height at a point, and its slope, from every crater of every octave not smaller than `fromDiameter` (a crater is faded in over a factor of two above it, so none
116
+ * pops). The cell the point is in is looked at in each octave, and a neighbouring cell when the point is within a fifth of the edge between them: a crater is kept to the middle of its cell, so its rim and the strong part of its apron reach no further.
117
+ *
118
+ * @param x - Metres east of the site.
119
+ * @param y - Metres north of the site.
120
+ * @param fromDiameter - The smallest nominal diameter to count, in metres: a distance's worth of pixels (craters smaller than a few pixels only shimmer).
121
+ * @returns The height in metres and the slope along east and north.
122
+ *
123
+ * @example
124
+ * ```ts
125
+ * import { madeGround } from "@johnmorrisdotca/wakusei-planets/surface";
126
+ *
127
+ * console.log(madeGround(12.5, -8, 0.5).h.toFixed(2));
128
+ * ```
129
+ */
130
+ export function madeGround(x, y, fromDiameter) {
131
+ let h = 0;
132
+ let gx = 0;
133
+ let gy = 0;
134
+ for (let octave = OCTAVES - 1; octave >= 0; octave -= 1) {
135
+ const nominal = D0 * 2 ** octave;
136
+ const fade = Math.max(0, Math.min(1, (nominal / fromDiameter - 1) * 1));
137
+ if (fade <= 0)
138
+ break;
139
+ const cell = CELL * nominal;
140
+ const ix = Math.floor(x / cell);
141
+ const iy = Math.floor(y / cell);
142
+ const fx = x / cell - ix;
143
+ const fy = y / cell - iy;
144
+ for (let j = -1; j <= 1; j += 1) {
145
+ for (let i = -1; i <= 1; i += 1) {
146
+ // a crater is kept inside the middle half of its cell and no wider than a third of it, so a neighbour's reaches this cell only within a fifth of the cell's edge
147
+ if ((i === -1 && fx > NEAR_EDGE) || (i === 1 && fx < 1 - NEAR_EDGE) || (j === -1 && fy > NEAR_EDGE) || (j === 1 && fy < 1 - NEAR_EDGE))
148
+ continue;
149
+ const crater = craterIn(ix + i, iy + j, octave);
150
+ if (crater === undefined)
151
+ continue;
152
+ const p = craterProfile(crater, x, y);
153
+ h += fade * p.h;
154
+ gx += fade * p.gx;
155
+ gy += fade * p.gy;
156
+ }
157
+ }
158
+ }
159
+ return { h, gx, gy };
160
+ }
161
+ /** The rocks of a class are `ROCK_MIN * 2 ** class` metres: 0.05, 0.1, 0.2, 0.4, 0.8, 1.6; a rock of a class is between 1 and 1.4 times that. */
162
+ export const ROCK_MIN = 0.05;
163
+ export const ROCK_CLASSES = 6;
164
+ /** Rocks a square metre is dealt of the smallest class (two and a half times what stays on ground far from a rim: a rock is kept in proportion to how near a young rim it is), and the side of the cells they are laid on, in metres. */
165
+ const ROCK_DENSITY = 0.8;
166
+ const ROCK_CELL = 6;
167
+ /**
168
+ * How much denser the rocks are at a point for fresh crater rims near it: 1 away from any, up to 5 on a young crater's rim.
169
+ *
170
+ * @param x - Metres east of the site.
171
+ * @param y - Metres north of the site.
172
+ * @returns A factor from 1 (no young rim near) up to 5 (on one).
173
+ *
174
+ * @example
175
+ * ```ts
176
+ * import { rimBoost } from "@johnmorrisdotca/wakusei-planets/surface";
177
+ *
178
+ * console.log(rimBoost(0, 0), rimBoost(51, -19) >= 1);
179
+ * ```
180
+ */
181
+ export function rimBoost(x, y) {
182
+ let boost = 1;
183
+ for (let octave = 2; octave < OCTAVES; octave += 1) {
184
+ const cell = CELL * D0 * 2 ** octave;
185
+ const ix = Math.floor(x / cell);
186
+ const iy = Math.floor(y / cell);
187
+ for (let j = -1; j <= 1; j += 1) {
188
+ for (let i = -1; i <= 1; i += 1) {
189
+ const c = craterIn(ix + i, iy + j, octave);
190
+ if (c === undefined || c.age > 0.35)
191
+ continue;
192
+ const t = Math.abs(Math.hypot(x - c.x, y - c.y) / c.radius - 1.0);
193
+ if (t < 0.4)
194
+ boost = Math.max(boost, 1 + 4 * (1 - t / 0.4) * (1 - c.age / 0.35));
195
+ }
196
+ }
197
+ }
198
+ return boost;
199
+ }
200
+ /**
201
+ * The rocks round a point, within `radius` metres: seeded and fixed to the place. Many small, few large (about a third as many of each class up), denser by fresh rims; a rock too small for a few pixels at its
202
+ * distance is left out, so nothing shimmers. They are made, not measured.
203
+ *
204
+ * @param cx - Metres east of the site.
205
+ * @param cy - Metres north of the site.
206
+ * @param radius - How far round to look, in metres.
207
+ * @param pixel - The angle one pixel takes in radians (a rock smaller than three pixels at its distance is left out).
208
+ * @returns The rocks, nearest first.
209
+ *
210
+ * @example
211
+ * ```ts
212
+ * import { rocksAround } from "@johnmorrisdotca/wakusei-planets/surface";
213
+ *
214
+ * console.log(rocksAround(0, 0, 20, 0.0024).length > 100);
215
+ * ```
216
+ */
217
+ export function rocksAround(cx, cy, radius, pixel) {
218
+ const out = [];
219
+ const i0 = Math.floor((cx - radius) / ROCK_CELL);
220
+ const i1 = Math.floor((cx + radius) / ROCK_CELL);
221
+ const j0 = Math.floor((cy - radius) / ROCK_CELL);
222
+ const j1 = Math.floor((cy + radius) / ROCK_CELL);
223
+ for (let j = j0; j <= j1; j += 1) {
224
+ for (let i = i0; i <= i1; i += 1) {
225
+ for (let k = 0; k < ROCK_CLASSES; k += 1) {
226
+ const [a, b] = pcg2d((i | 0) >>> 0, ((j | 0) + k * 6151 + 1000003) >>> 0);
227
+ const lambda = ROCK_DENSITY * ROCK_CELL * ROCK_CELL * 0.3 ** k;
228
+ let count = Math.floor(lambda);
229
+ if (unit24(a) < lambda - count)
230
+ count += 1;
231
+ for (let n = 0; n < Math.min(count, 48); n += 1) {
232
+ const [c, d] = pcg2d(((i | 0) + n * 31 + 7) >>> 0, ((j | 0) + k * 6151 + n * 977 + 1000033) >>> 0);
233
+ const x = (i + unit24(c)) * ROCK_CELL;
234
+ const y = (j + unit24(d)) * ROCK_CELL;
235
+ const dist = Math.hypot(x - cx, y - cy);
236
+ if (dist > radius)
237
+ continue;
238
+ const size = ROCK_MIN * 2 ** k * (1 + 0.4 * unit24(b >>> 0 ^ (c << 3)));
239
+ if (size < 3 * dist * pixel)
240
+ continue;
241
+ // fewer where the rims are not near: two fifths of what is dealt on the plain, all of it by a young rim
242
+ const boost = rimBoost(x, y);
243
+ if (unit24(pcg2d(c, d)[0]) > 0.3 * boost)
244
+ continue;
245
+ const [e, f] = pcg2d(c ^ 0x9e3779b9, d + 17);
246
+ out.push({ x, y, size, shape: e % 3, turn: unit24(f) * Math.PI * 2, tone: 0.75 + 0.5 * unit24(e >>> 3), flat: 0.45 + 0.4 * unit24(f >>> 5) });
247
+ }
248
+ }
249
+ }
250
+ }
251
+ return out.sort((p, q) => Math.hypot(p.x - cx, p.y - cy) - Math.hypot(q.x - cx, q.y - cy));
252
+ }
253
+ /**
254
+ * The nearest place to a point where a person can stand without being in a made crater or on a made rim: the made ground there is level over two metres round. The landing point itself is
255
+ * the first tried, so most of the time a person stands where the lunar module stood.
256
+ *
257
+ * @param x - Metres east of the site.
258
+ * @param y - Metres north of the site.
259
+ * @returns A place within thirty metres of the point.
260
+ *
261
+ * @example
262
+ * ```ts
263
+ * import { standingPlace } from "@johnmorrisdotca/wakusei-planets/surface";
264
+ *
265
+ * const place = standingPlace(0, 0);
266
+ * console.log(Math.hypot(place.x, place.y) < 30);
267
+ * ```
268
+ */
269
+ export function standingPlace(x = 0, y = 0) {
270
+ const level = (px, py) => {
271
+ const here = madeGround(px, py, 0.35);
272
+ if (Math.hypot(here.gx, here.gy) > 0.05)
273
+ return false;
274
+ for (let k = 0; k < 8; k += 1) {
275
+ const a = (k * Math.PI) / 4;
276
+ if (Math.abs(madeGround(px + 2.2 * Math.cos(a), py + 2.2 * Math.sin(a), 0.35).h - here.h) > 0.12)
277
+ return false;
278
+ }
279
+ return true;
280
+ };
281
+ for (let r = 0; r <= 30; r += 2) {
282
+ const n = Math.max(1, Math.round(r * 1.2));
283
+ for (let k = 0; k < n; k += 1) {
284
+ const a = (k / n) * Math.PI * 2;
285
+ const px = x + r * Math.cos(a);
286
+ const py = y + r * Math.sin(a);
287
+ if (level(px, py))
288
+ return { x: px, y: py };
289
+ }
290
+ }
291
+ return { x, y };
292
+ }