@johnmorrisdotca/wakusei-planets 0.53.0 → 0.54.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,15 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.54.0] - 2026-11-14
6
+
7
+ - **A move within one planet's family no longer swings the destination across the picture, and loses it far less** (MODULES-1254, MODULES-1228). Between two moons (Titan to Enceladus, Phobos to Deimos), the straight way in could pass within a little more than the clearance of the planet, so the camera slid sideways over it and the destination swung across the picture, and sometimes out of it. Where that happens the way on is now made as a swing from a stand that clears the planet, the nearest one or one beyond the destination on the side away from the planet; of the ways tried the one with the fewest faults that has none of any kind more than the first way is taken, so every other move is the same, sample for sample, and a view that kept the planet in the picture all through keeps it. Walked from ten sides at three picture shapes and both scales, six pairs of moons (Callisto to Europa, Io to Ganymede, Titan to Enceladus, Oberon to Miranda, Phobos to Deimos, Triton to Proteus; 360 walks of 241 samples): samples where the destination drifted away from its place on the screen went from 605 to 61 to 69, empty pictures from 394 to 28 to 70, and samples where the destination was out of the picture after the turn from 45 to 12 to 15, with the planner's 60 ms budget (the range is over six runs, three of them under load; 54, 27 and 12 with no budget). What is left: Titan to Enceladus (drift on 2 sides of the compressed square, 2 of the compressed tall, where the destination is also lost, 2 of the true square and 1 of the true tall) and Phobos to Deimos (drift on 9 sides of the compressed tall, and an empty picture on 1 of the true tall). The planet is out of the picture more often in plain views, which never promised it.
8
+ Planning is kept quick: the planner measures far fewer moments than it did and has a time budget (`TravelInput.budget`, which the space view fills with `TRAVEL_BUDGET_MS`, 60 ms from the start of the plan; the planner reads no clock itself, and a page calling `travelPlan` directly gets no budget unless it passes one). On the author's Mac mini the first way alone takes a median of 4 ms and at most 37 ms, and a plan with the budget a median of 4.5 ms, 90 percent under 36 to 45 ms and at most 75 to 105 ms in quiet runs, and 126 ms in one run under load (105 to 119 ms with no budget; the same code took a median of 22 ms, 165 ms and 475 ms before this work). A slower device stops sooner and so does less well than these figures, though never with more faults of any kind than the first way; the same move can be planned differently on two devices, and the tests plan with no budget, so they do not depend on the speed of the machine. A move is planned once for the input it is given, and the input is frozen when it is planned (its top level: nested arrays such as `start.position` must not be changed either). Guide: the space-view guide and its Japanese twin. Tests: `test/space-travel.test.ts` (the plain views, with the cases left listed), `test/travel-baseline.test.ts` (912 moves the same as in 0.52.0 unless they had these faults), `test/travel-faults.test.ts` (the rule a way is taken by), `test/travel-budget.test.ts` and `scripts/travel-table.ts` (the table).
9
+
10
+ Prepared as 0.53.0 and not published. 0.54.0 contains this change. The version number 0.53.0 is the spin arrow, below.
11
+
12
+ - **A move within one planet's family keeps one of the moons in the picture far more often** (MODULES-1228). Going from one moon to another of the same planet (Callisto to Europa, Titan to Enceladus), or between a planet and a moon, could pass through a stretch where neither body was on the screen. Where the first and last views leave no way round the planet that keeps either in the picture, the camera now backs off from the body it is leaving, looking at a point that goes from it to the destination, until both are in the picture, turns, and comes in. It takes the same share of the move and ends in the same place, so the way on and the arrival are unchanged, and it is used only when it leaves fewer empty pictures and keeps to the pace limits; every other move is the same, sample for sample. Walked from ten sides, at three picture shapes and both scales, six pairs of moons (Callisto to Europa, Io to Ganymede, Titan to Enceladus, Oberon to Miranda, Phobos to Deimos, Triton to Proteus) had an empty picture in 288 of 360 walks before and have one in 31 now (394 of 86,760 samples). What is left: the moves where the turn would have to be made faster than the pace limits allow, and the way on of Titan's tall pictures, where the destination is lost. The destination also still drifts on the screen between Titan and Enceladus and between Phobos and Deimos (the way on passes close to the planet); that is not changed here. Guide: the space-view guide and its Japanese twin. Tests: `test/space-travel.test.ts` (the plain views, every fault counted, with the cases left listed), `test/travel-baseline.test.ts` (912 moves the same as in 0.52.0) and `scripts/travel-table.ts` (the table).
13
+
5
14
  ## [0.53.0] - 2026-11-14
6
15
 
7
16
  - **The spin arrow can sit above the pole** (MODULES-1359). `help-place` (and `space.helpPlace`) chooses where help mode's curved arrow is drawn. `pole`, the default, draws a small arrow just outside the surface, around the north-pole line. `across` draws the wide arrow a little off the centre, across the body, which is how it was drawn before. The arrow still turns by the right-hand rule about the axis the body really spins 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.53.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.54.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.53.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.54.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
 
@@ -537,7 +537,7 @@ BODIES.pluto.kind; // "dwarf-planet"
537
537
 
538
538
  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:
539
539
 
540
- > Morris, J. (2026). *Wakusei Planets* (version 0.53.0) [Computer software]. https://github.com/johnmorrisdotca/wakusei-planets
540
+ > Morris, J. (2026). *Wakusei Planets* (version 0.54.0) [Computer software]. https://github.com/johnmorrisdotca/wakusei-planets
541
541
 
542
542
  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).
543
543
 
@@ -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.53.0/dist/textures/";
14
+ export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@0.54.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.53.0/textures/";
26
+ export declare const TEXTURE_FAR_BASE = "https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v0.54.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.
@@ -8,7 +8,7 @@ export { besideMoon, BESIDE_RADII, type BesideCamera, type BesideInput } from ".
8
8
  export { ARROWS_PER_ORBIT, arrowCount, arrowSites, MAX_ARROWS_PER_ORBIT, chevron, helpSpin, readHelpPlace, spinArrow, type HelpPlace, type OrbitArrow } from "./arrows.ts";
9
9
  export { spinAxis, type SpinAxis } from "./spin.ts";
10
10
  export { COVER_ARROW_GAP, COVER_MIN_PX, coverArrows, coveredBy, type CoverArrow, type CoverEntry } from "./covered.ts";
11
- export { TRAVEL_CLEARANCE, arrivalSide, travelArrival, travelPlan, travelPose, type ArrivalCompanion, type TravelBody, type TravelInput, type TravelKind, type TravelPlan, type TravelSample, type TravelSight, type TravelView } from "./travel.ts";
11
+ export { TRAVEL_BUDGET_MS, TRAVEL_CLEARANCE, arrivalSide, travelArrival, travelPlan, travelPose, type ArrivalCompanion, type TravelBody, type TravelInput, type TravelKind, type TravelPlan, type TravelSample, type TravelSight, type TravelView } from "./travel.ts";
12
12
  export { regionOrbits, regionView, SUN_REGIONS, type SunRegion } from "./regions.ts";
13
13
  export { SIGHT_STEP_PX, sightChanged, sightOf, withinMargin, type Sight, type SightEdge, type SightInput } from "./sight.ts";
14
14
  export { besideFace, facingPoint, faceView, subCameraPoint, surfaceDirection, type Face, type FaceView } from "./face.ts";
@@ -9,7 +9,7 @@ export { besideMoon, BESIDE_RADII } from "./beside.js";
9
9
  export { ARROWS_PER_ORBIT, arrowCount, arrowSites, MAX_ARROWS_PER_ORBIT, chevron, helpSpin, readHelpPlace, spinArrow } from "./arrows.js";
10
10
  export { spinAxis } from "./spin.js";
11
11
  export { COVER_ARROW_GAP, COVER_MIN_PX, coverArrows, coveredBy } from "./covered.js";
12
- export { TRAVEL_CLEARANCE, arrivalSide, travelArrival, travelPlan, travelPose } from "./travel.js";
12
+ export { TRAVEL_BUDGET_MS, TRAVEL_CLEARANCE, arrivalSide, travelArrival, travelPlan, travelPose } from "./travel.js";
13
13
  export { regionOrbits, regionView, SUN_REGIONS } from "./regions.js";
14
14
  export { SIGHT_STEP_PX, sightChanged, sightOf, withinMargin } from "./sight.js";
15
15
  export { besideFace, facingPoint, faceView, subCameraPoint, surfaceDirection } from "./face.js";
@@ -20,7 +20,7 @@ import { BALL_FRAGMENT, VERTEX } from "../scene/glsl.js";
20
20
  import { ridePose } from "./ride.js";
21
21
  import { moonDistance, moonSizeFactor, orbitLine, placeAround, placeBodies, placeMoon, radiusIn } from "./scale.js";
22
22
  import { regionOrbits, regionView } from "./regions.js";
23
- import { travelPlan, travelPose } from "./travel.js";
23
+ import { TRAVEL_BUDGET_MS, travelPlan, travelPose } from "./travel.js";
24
24
  const RAD = Math.PI / 180;
25
25
  /** The camera's distance, in radii of the body it looks at, at which that body fills the view at zoom 1. */
26
26
  export const FIT_DISTANCE = 4.1;
@@ -629,7 +629,7 @@ export function createSpaceItem(model, deps) {
629
629
  const end = { position: [camera.position.x + shift[0], camera.position.y + shift[1], camera.position.z + shift[2]], forward: [ef.x, ef.y, ef.z], up: [eu.x, eu.y, eu.z], fov: fovNow };
630
630
  // every body of the view is kept clear of, the two ends of the move and the planet circled aside
631
631
  const others = SPACE_BODIES.filter((id) => id !== glide.leaving && id !== glide.destination && id !== family).map((id) => bodyOf(id));
632
- const input = { start, end, leaving, destination, others, aspect: size.width / Math.max(1, size.height), kind: glide.kind, pace: glide.pace };
632
+ const input = { start, end, leaving, destination, others, aspect: size.width / Math.max(1, size.height), kind: glide.kind, pace: glide.pace, budget: { now: () => performance.now(), ms: TRAVEL_BUDGET_MS } };
633
633
  if (around !== null)
634
634
  input.around = bodyOf(around);
635
635
  return { input, plan: travelPlan(input) };
@@ -24,6 +24,22 @@ export type TravelKind = "turn-travel" | "direct" | "look-back" | "auto" | "cut"
24
24
  * ```
25
25
  */
26
26
  export declare const TRAVEL_CLEARANCE = 1;
27
+ /**
28
+ * The time in milliseconds, counted from the start of the plan, that the space view lets the planner spend on the other ways of a move within a planet's family (`TravelInput.budget`); the first way, with its aim
29
+ * turn, is always worked out. Measured on the author's Mac mini over the 360 surveyed plain-view moves of six pairs of moons (most need no other way): the first way alone takes a median of 4 ms, 90 percent under
30
+ * 10 ms and at most 37 ms; with this budget a plan takes a median of 4.5 ms (up to 9.5 under load), 90 percent under 36 to 45 ms and at most 75 to 105 ms in quiet runs (126 ms in one loaded run), against the same median, 34 ms and 105 to 119 ms with no budget. A phone is several times
31
+ * slower, so there the planner stops sooner and keeps the best way found, and the same move can be planned differently on two devices (never with more faults than the first way). On this machine the budget costs
32
+ * little in faults, and what it costs depends on the load: over the 360 walks, 61 to 69 drifting samples, 32 to 70 empty and 12 to 15 lost in six runs (three of them with two other copies running at once),
33
+ * against 54, 27 and 12 with no budget and 605, 394 and 45 before the other ways; never more faults of any kind than the first way.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * import { TRAVEL_BUDGET_MS } from "@johnmorrisdotca/wakusei-planets/space";
38
+ *
39
+ * console.log(TRAVEL_BUDGET_MS);
40
+ * ```
41
+ */
42
+ export declare const TRAVEL_BUDGET_MS = 60;
27
43
  /**
28
44
  * A camera: where it is, the unit vectors it looks along and has up in the picture, and its vertical field of view in degrees. The same four as `besideMoon` and `ridePose` give.
29
45
  *
@@ -65,6 +81,9 @@ export interface TravelBody {
65
81
  * What `travelPose` and `travelPlan` are asked: the camera now (`start`) and the framed view to end in (`end`, worked out for the destination's place at the end of the move), the body being left and the
66
82
  * destination, the planet when both are of one planet's family, any other body to keep clear of, and the picture's width over its height.
67
83
  *
84
+ * A move is planned once for the input it is given (a second call, or `travelPose` without a plan, uses the first plan), so an input is not to be changed after it has been planned: `travelPlan` and `travelPose`
85
+ * freeze it (its top level only: nested arrays and objects such as `start.position` are not frozen, and must not be changed either), and a changed move is a new input.
86
+ *
68
87
  * @example
69
88
  * ```ts
70
89
  * import type { TravelInput } from "@johnmorrisdotca/wakusei-planets/space";
@@ -100,6 +119,15 @@ export interface TravelInput {
100
119
  pace?: number;
101
120
  /** How near the path may come to a body, in its radii above its surface: `TRAVEL_CLEARANCE` when left out. */
102
121
  clearance?: number;
122
+ /**
123
+ * A limit on the time the planner spends on a move within a planet's family: `now` gives the time in milliseconds (`performance.now`), and once `ms` have gone on the aim turn and the other ways the planner stops
124
+ * and keeps the best so far, which is never worse than the first way it made. The planner reads no clock itself: without `budget` it tries every way, and the same input always gives the
125
+ * same plan. With it, the plan can differ with the speed of the device (a slower one may stop sooner), though never to one with more faults than the first way. `TRAVEL_BUDGET_MS` is the value the space view passes.
126
+ */
127
+ budget?: {
128
+ now: () => number;
129
+ ms: number;
130
+ };
103
131
  }
104
132
  /**
105
133
  * Where a body is in the picture at one moment: `inside` when its centre (the place of its marker) is within the frame, `x` and `y` from -1 at the left and bottom edges to 1 at the right and top, and `radius`,
@@ -172,6 +200,24 @@ export interface TravelPlan {
172
200
  /** The path itself, for `travelPose`. */
173
201
  route: unknown;
174
202
  }
203
+ /** The faults a walk of a move has that the way on is judged by: samples with neither body in the picture, with the destination out of it after the turn, where the destination moves away from its last place on the screen (and the most it does in a sample), and where it moves a third of the frame in one. */
204
+ export interface Faults {
205
+ empty: number;
206
+ lost: number;
207
+ drift: number;
208
+ driftWorst: number;
209
+ step: number;
210
+ /** Moments the look direction turns six degrees or more, turns away from the last view's, or the camera jumps a sixth of the way, and whether the whole turn is over 1.25 times the least plus 2 degrees. */
211
+ pace: number;
212
+ /** Samples with the planet circled out of the picture (not a fault: it breaks a tie). */
213
+ planet: number;
214
+ }
215
+ export declare const total: (f: Faults) => number;
216
+ /**
217
+ * `now` has no kind of fault more than `was` (and no more of the drift in its worst sample) and fewer in all. A way that keeps the planet in the picture all through (`was.planet` is 0: the views promised it) must go
218
+ * on keeping it; where the first way did not (plain views never promised it) the planet out of the picture is not a fault, and only breaks a tie between two ways.
219
+ */
220
+ export declare const betterThan: (now: Faults, was: Faults) => boolean;
175
221
  /**
176
222
  * The plan of a move: its stages and the share of the time each takes, how long it should last, and how it is eased. The length is a suggestion from how far the picture changes (16 milliseconds a degree
177
223
  * turned, 320 for each time the distance changes by a factor of e, between 1.2 and 9 seconds, times `pace`); a page may use its own, since `travelPose` takes the moment as a share of the move.
@@ -17,9 +17,38 @@
17
17
  // - the destination directly behind the body being left, or the two in one direction: the pivot puts the body left to one side, backing up until the straight line to the destination clears it;
18
18
  // - the destination is the Sun, or a planet that is a point until the last stretch (the true scale): its place on the screen is reported at every moment, so a marker can stand for it;
19
19
  // - the camera starts inside a beside-a-moon view: the moon, or its planet for a move within the planet's family, is the pivot;
20
+ // - a move within one planet's family (two moons, or the planet and a moon) whose first and last views (the whole body from the side the camera comes from) leave no turn about the planet or the body left that keeps one of them in the picture: the turn
21
+ // is made by an AIM POINT instead (see `Aim`), the camera backing off from the moon left, looking at a point that goes from it to the destination, until both are in the picture together, and coming in; it takes
22
+ // the same share of the move and ends in the same place, so the way on is the same, and it is used only when it leaves fewer empty pictures and keeps to the pace limits (`PACE_*`);
23
+ // - a move within a planet's family whose straight way on would pass close to the planet (the camera slides over the planet's clearance and the destination swings across the picture): the way on is made again as a
24
+ // swing from a stand that clears the planet, the nearest one, or one beyond the destination on the far side from the planet, and the way with the fewest faults that has none of any kind more than the first is taken;
20
25
  // - the two views almost the same: no turn stage, a short move;
21
26
  // - a view of a region (a set of orbits round a body): a straight pull back or push in with no turn of its own.
22
- import { add, cross, dot, length, RAD, scale, sub, unit } from "../vec.js";
27
+ import { add, cross, dot, RAD, scale, sub } from "../vec.js";
28
+ // The planner measures a very large number of lengths. This is `Math.hypot(x, y, z)` worked out in the same steps as the engine does (scaled by the largest, compensated sum, square root), so it gives the same
29
+ // numbers, without the cost of calling the built-in with a list of arguments.
30
+ const length = (a) => {
31
+ const x = Math.abs(a[0]);
32
+ const y = Math.abs(a[1]);
33
+ const z = Math.abs(a[2]);
34
+ const max = x > y ? (x > z ? x : z) : y > z ? y : z;
35
+ if (max === 0)
36
+ return 0;
37
+ let sum = 0;
38
+ let comp = 0;
39
+ for (let i = 0; i < 3; i += 1) {
40
+ const n = Math.abs(a[i]) / max;
41
+ const summand = n * n - comp;
42
+ const preliminary = sum + summand;
43
+ comp = preliminary - sum - summand;
44
+ sum = preliminary;
45
+ }
46
+ return Math.sqrt(sum) * max;
47
+ };
48
+ const unit = (a) => {
49
+ const n = length(a);
50
+ return n === 0 ? [0, 0, 0] : [a[0] / n, a[1] / n, a[2] / n];
51
+ };
23
52
  /**
24
53
  * How near a move may come to a body, in that body's radii above its surface: 1, so a body passed is never more than 60 degrees across. A move that starts or ends nearer than one and a half times that keeps two thirds of the nearer distance.
25
54
  *
@@ -31,12 +60,41 @@ import { add, cross, dot, length, RAD, scale, sub, unit } from "../vec.js";
31
60
  * ```
32
61
  */
33
62
  export const TRAVEL_CLEARANCE = 1;
63
+ /**
64
+ * The time in milliseconds, counted from the start of the plan, that the space view lets the planner spend on the other ways of a move within a planet's family (`TravelInput.budget`); the first way, with its aim
65
+ * turn, is always worked out. Measured on the author's Mac mini over the 360 surveyed plain-view moves of six pairs of moons (most need no other way): the first way alone takes a median of 4 ms, 90 percent under
66
+ * 10 ms and at most 37 ms; with this budget a plan takes a median of 4.5 ms (up to 9.5 under load), 90 percent under 36 to 45 ms and at most 75 to 105 ms in quiet runs (126 ms in one loaded run), against the same median, 34 ms and 105 to 119 ms with no budget. A phone is several times
67
+ * slower, so there the planner stops sooner and keeps the best way found, and the same move can be planned differently on two devices (never with more faults than the first way). On this machine the budget costs
68
+ * little in faults, and what it costs depends on the load: over the 360 walks, 61 to 69 drifting samples, 32 to 70 empty and 12 to 15 lost in six runs (three of them with two other copies running at once),
69
+ * against 54, 27 and 12 with no budget and 605, 394 and 45 before the other ways; never more faults of any kind than the first way.
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * import { TRAVEL_BUDGET_MS } from "@johnmorrisdotca/wakusei-planets/space";
74
+ *
75
+ * console.log(TRAVEL_BUDGET_MS);
76
+ * ```
77
+ */
78
+ export const TRAVEL_BUDGET_MS = 60;
34
79
  const clamp01 = (x) => Math.min(1, Math.max(0, x));
35
80
  /** Slow out, fast between, slow in, with no jerk at either end. */
36
81
  const ease = (x) => {
37
82
  const t = clamp01(x);
38
83
  return t * t * t * (t * (t * 6 - 15) + 10);
39
84
  };
85
+ /** The share of a turn that `ease` has taken to `p`. */
86
+ const unease = (p) => {
87
+ let lo = 0;
88
+ let hi = 1;
89
+ for (let i = 0; i < 30; i += 1) {
90
+ const mid = (lo + hi) / 2;
91
+ if (ease(mid) < p)
92
+ lo = mid;
93
+ else
94
+ hi = mid;
95
+ }
96
+ return (lo + hi) / 2;
97
+ };
40
98
  const smooth = (x) => {
41
99
  const t = clamp01(x);
42
100
  return t * t * (3 - 2 * t);
@@ -159,8 +217,46 @@ function leftOf(q, l, ea, eb) {
159
217
  const m = smooth(q);
160
218
  return l * ((1 - m) * (1 - gone) + m * left);
161
219
  }
220
+ const AIM_STEPS = 96;
221
+ /** How far beyond the destination the far-side stands are, in the distance from the planet to the destination. */
222
+ const FAR_SIDE = [0.5, 1, 2, 4, 8];
223
+ /** How far the aim point has gone from the moon left to the destination at `p` of the turn: still on the moon left until 0.15, a smooth step to the destination by 0.85, and on the destination after. */
224
+ const aimPan = (p) => smooth((p - 0.15) / 0.7);
225
+ /** The direction from the aim point to the camera, as the aim goes `w` of the way from the moon left to the destination. */
226
+ function aimSide(a, w) {
227
+ const n = arc(a.n0, a.n1, w);
228
+ return a.bend === 0 ? n : unit(add(n, scale(a.lean, a.bend * Math.sin(Math.PI * w) ** 2)));
229
+ }
230
+ /** The camera's distance from the aim point at `p` of the turn: a smooth step up from the first distance to `far` times the larger of the two ends by 0.5, and a smooth step down to the last from 0.5 to 1. */
231
+ function aimDistance(a, p) {
232
+ const top = Math.max(a.r0, a.r1) * a.far;
233
+ return Math.exp(Math.log(a.r0) + (Math.log(top) - Math.log(a.r0)) * smooth(p / 0.5) + (Math.log(a.r1) - Math.log(top)) * smooth((p - 0.5) / 0.5));
234
+ }
235
+ /** The backing off to try, in turn, and how far from the middle of the picture the nearer moon may get (1 is the edge), and how many moments of the turn are looked at. */
236
+ const AIM_FAR = Array.from({ length: 19 }, (_, k) => 1.5 ** k);
237
+ const AIM_BEND = [0, 0.5, 1, 2, 4];
238
+ const AIM_SLOW = [1, 1.4, 2, 3, 4.5];
239
+ const AIM_EDGE = 0.95;
240
+ const AIM_CHECKS = 240;
241
+ /** The pace the aim point's turn keeps to, a little inside the limits the move is walked against: degrees the look direction turns in a 240th of the move, the share of the frame the destination moves in it, the degrees it may turn back, and the share of the way the camera goes in it. */
242
+ const PACE_DEGREES = 5;
243
+ const PACE_SCREEN = 0.25;
244
+ const PACE_UNTURN = 0.04;
245
+ const PACE_WAY = 0.045;
162
246
  const LOOK_BACK_TURN = 0.4;
163
- function turnAt(turn, p, t) {
247
+ function turnAt(turn, p, t, share) {
248
+ if (turn.aim !== undefined) {
249
+ const a = turn.aim;
250
+ // the aim point's turn goes at its own pace, the share of the turn gone and not the eased share
251
+ const q = share ?? unease(p);
252
+ const x = q * AIM_STEPS;
253
+ const i = Math.min(AIM_STEPS - 1, Math.floor(x));
254
+ const f = unit(mix(a.facings[i].f, a.facings[i + 1].f, x - i));
255
+ const u = mix(a.facings[i].u, a.facings[i + 1].u, x - i);
256
+ const w = aimPan(q);
257
+ const aim = mix(placeOf(a.from, t), placeOf(a.to, t), w);
258
+ return { position: add(aim, scale(aimSide(a, w), aimDistance(a, q))), o: { f, u: unit(sub(u, scale(f, dot(u, f)))) }, fov: fovBetween(turn.fov0, turn.fov1, p) };
259
+ }
164
260
  const o = swingAt(turn.swing, p);
165
261
  // the lift is early: the camera backs off as it starts to turn, so the body left goes into the picture, not out of its side
166
262
  const w = Math.sqrt(p);
@@ -211,7 +307,7 @@ function clearOf(route, position, t) {
211
307
  }
212
308
  function along(route, t) {
213
309
  const inTurn = route.turn !== null && t < route.share;
214
- const at = inTurn ? turnAt(route.turn, ease(t / route.share), t) : legAt(route.leg, ease(route.share >= 1 ? 1 : (t - route.share) / (1 - route.share)), t);
310
+ const at = inTurn ? turnAt(route.turn, ease(t / route.share), t, clamp01(t / route.share)) : legAt(route.leg, ease(route.share >= 1 ? 1 : (t - route.share) / (1 - route.share)), t);
215
311
  return { position: clearOf(route, at.position, t), o: at.o, fov: at.fov, stage: inTurn ? "turn" : t < route.arrive ? "travel" : "arrive" };
216
312
  }
217
313
  function sightOf(body, t, position, o, frame) {
@@ -223,7 +319,7 @@ function sightOf(body, t, position, o, frame) {
223
319
  return { inside: v[2] > 0 && Math.abs(x) <= 1 && Math.abs(y) <= 1, x, y, radius: d <= body.radius ? 90 : Math.asin(body.radius / d) / RAD };
224
320
  }
225
321
  /** The pivot's stand at the end of the turn, for a moment `tm` of the move. */
226
- function standAt(input, tm, family) {
322
+ function standAt(input, tm, family, variant = 0) {
227
323
  const o0 = facingOf(input.start);
228
324
  const o1 = facingOf(input.end);
229
325
  const clearance = input.clearance ?? TRAVEL_CLEARANCE;
@@ -275,8 +371,15 @@ function standAt(input, tm, family) {
275
371
  break search;
276
372
  }
277
373
  }
278
- if (straight === null && family)
279
- straight = fallback;
374
+ // a stand that is nearest to a good one is taken for two bodies of a family; with `far`, only if the straight way from it to the last view clears the planet, and if not the way on is made as a swing (below), from
375
+ // a stand where the way to the destination clears it
376
+ if (straight === null && family && fallback !== null) {
377
+ const stand = sub(v, toScene(o1, fallback));
378
+ if (variant === 0 || missOf(stand, last, v) >= Math.min(1.52 * (1 + clearance) * pivot.radius, 0.9 * length(fallback), 0.98 * length(apex)))
379
+ straight = fallback;
380
+ }
381
+ if (variant >= 2)
382
+ straight = null;
280
383
  if (straight !== null) {
281
384
  const dm = Math.max(1e-12, length(straight));
282
385
  const stand = sub(v, toScene(o1, straight));
@@ -311,16 +414,36 @@ function standAt(input, tm, family) {
311
414
  }
312
415
  const first0 = intoFrame(toCamera(om, toScene(o0, u0)), frame0, 0.85);
313
416
  let chosen = null;
314
- search: for (const far of tries) {
315
- for (const spot of spots(first0, frame0, 0.85)) {
316
- const stand = sub(v, scale(toScene(om, spot), far * d0));
317
- const miss = missOf(stand, b, v);
318
- const seen = within(toCamera(om, sub(b, stand)), frame0, 0.9);
319
- if (seen && (chosen === null || miss > chosen.miss))
320
- chosen = { stand, u: spot, d: far * d0, miss };
321
- if (seen && miss >= Math.min(1.52 * (1 + clearance) * pivot.radius, 0.9 * far * d0)) {
322
- chosen = { stand, u: spot, d: far * d0, miss };
323
- break search;
417
+ if (variant >= 2) {
418
+ // the far side: the camera stands on the line back from the destination along a look direction of the turn, as far from it as the variant says, and the look direction that puts the planet furthest from that line
419
+ // is taken, so the way in to the destination never goes near the planet; the turn is along the arc as before, and the destination is in the middle of the picture at the stand
420
+ const dist = FAR_SIDE[variant - 2] * Math.max(length(sub(b, v)), 1e-12);
421
+ let bestK = 0;
422
+ let bestMiss = -1;
423
+ for (let k = 0; k <= 50; k += 1) {
424
+ const o = swingAt(whole, k / 50);
425
+ const miss = missOf(sub(b, scale(o.f, dist)), b, v);
426
+ if (miss > bestMiss + 1e-12) {
427
+ bestMiss = miss;
428
+ bestK = k;
429
+ }
430
+ }
431
+ om = swingAt(whole, bestK / 50);
432
+ const stand = sub(b, scale(om.f, dist));
433
+ chosen = { stand, u: unit(toCamera(om, sub(v, stand))), d: Math.max(1e-12, length(sub(v, stand))), miss: bestMiss };
434
+ }
435
+ else {
436
+ search: for (const far of tries) {
437
+ for (const spot of spots(first0, frame0, 0.85)) {
438
+ const stand = sub(v, scale(toScene(om, spot), far * d0));
439
+ const miss = missOf(stand, b, v);
440
+ const seen = within(toCamera(om, sub(b, stand)), frame0, 0.9);
441
+ if (seen && (chosen === null || miss > chosen.miss))
442
+ chosen = { stand, u: spot, d: far * d0, miss };
443
+ if (seen && miss >= Math.min(1.52 * (1 + clearance) * pivot.radius, 0.9 * far * d0)) {
444
+ chosen = { stand, u: spot, d: far * d0, miss };
445
+ break search;
446
+ }
324
447
  }
325
448
  }
326
449
  }
@@ -347,11 +470,174 @@ function lineLeg(input, about, watch) {
347
470
  }
348
471
  /** The way on is never hurried by a long turn: it takes at least 45 percent of the turn's time. */
349
472
  const legMs = (leg, turn = 0) => Math.max(0.45 * turn, 900 + 320 * Math.max(Math.log1p(leg.l / (leg.ea + leg.eb)), Math.abs(Math.log(Math.max(1e-12, leg.d1) / Math.max(1e-12, leg.d0)))) + 16 * swingDegrees(leg.swing));
473
+ /** The aim point's turn without its backing off: the look directions and ups, from the first view's to the last, for the stand `end` of a turn that was a swing about the planet. */
474
+ function aimOf(input, turn, tm, bend, slow) {
475
+ const o0 = turn.swing.from;
476
+ const end = turnAt(turn, 1, tm);
477
+ const from = sub(input.start.position, input.leaving.from);
478
+ const to = sub(end.position, placeOf(input.destination, tm));
479
+ const r0 = Math.max(1e-12, length(from));
480
+ const r1 = Math.max(1e-12, length(to));
481
+ const n0 = length(from) < 1e-12 ? scale(o0.f, -1) : unit(from);
482
+ const n1 = length(to) < 1e-12 ? scale(end.o.f, -1) : unit(to);
483
+ // out from the planet, square to the line between the two moons, for the middle of the turn
484
+ const middle = sub(mix(placeOf(input.leaving, tm / 2), placeOf(input.destination, tm / 2), 0.5), placeOf(turn.pivot, tm / 2));
485
+ const line = unit(sub(placeOf(input.destination, tm / 2), placeOf(input.leaving, tm / 2)));
486
+ const square = sub(middle, scale(line, dot(middle, line)));
487
+ const lean = length(square) < 1e-9 * Math.max(1, length(middle)) ? squareTo(line) : unit(square);
488
+ // the small turns that join the direction to the aim point to the first and the last views
489
+ const first = angleOf(scale(n0, -1), o0.f);
490
+ const last = angleOf(scale(n1, -1), end.o.f);
491
+ const axis0 = length(cross(scale(n0, -1), o0.f)) < 1e-9 ? squareTo(o0.f) : unit(cross(scale(n0, -1), o0.f));
492
+ const axis1 = length(cross(scale(n1, -1), end.o.f)) < 1e-9 ? squareTo(end.o.f) : unit(cross(scale(n1, -1), end.o.f));
493
+ const ups = [];
494
+ const looks = [];
495
+ for (let k = 0; k <= AIM_STEPS; k += 1) {
496
+ const p = k / AIM_STEPS;
497
+ const g = aimPan(p);
498
+ looks.push(unit(spin(spin(scale(aimSide({ n0, n1, lean, bend }, g), -1), axis1, last * g), axis0, first * (1 - g))));
499
+ }
500
+ // the up carried along the looks by the least turn, and the roll that is left spread evenly
501
+ ups.push(o0.u);
502
+ for (let k = 1; k <= AIM_STEPS; k += 1) {
503
+ const a = looks[k - 1];
504
+ const b = looks[k];
505
+ const turned = angleOf(a, b);
506
+ const carried = turned < 1e-12 ? ups[k - 1] : spin(ups[k - 1], unit(cross(a, b)), turned);
507
+ ups.push(unit(sub(carried, scale(b, dot(carried, b)))));
508
+ }
509
+ const final = ups[AIM_STEPS];
510
+ const roll = Math.atan2(dot(cross(final, end.o.u), looks[AIM_STEPS]), dot(final, end.o.u));
511
+ const facings = looks.map((f, k) => {
512
+ const rolled = spin(ups[k], f, roll * (k / AIM_STEPS));
513
+ return { f, u: unit(sub(rolled, scale(f, dot(rolled, f)))) };
514
+ });
515
+ let degrees = 0;
516
+ for (let k = 1; k <= AIM_STEPS; k += 1)
517
+ degrees += angleOf(facings[k - 1].f, facings[k].f) / RAD;
518
+ return { from: input.leaving, to: input.destination, n0, n1, r0, r1, lean, bend, slow, degrees, facings };
519
+ }
350
520
  const turnMs = (turn) => {
521
+ if (turn.aim !== undefined) {
522
+ const a = turn.aim;
523
+ return Math.max(500, 24 * a.slow * a.degrees + 400 * (Math.log(Math.max(a.r0, a.r1) * a.far / a.r0) + Math.log(Math.max(a.r0, a.r1) * a.far / a.r1)) / 2);
524
+ }
351
525
  const ms = 16 * swingDegrees(turn.swing) + 8 * (angleOf(turn.u0, turn.u1) / RAD) + 400 * Math.abs(Math.log(turn.d1 / turn.d0)) + 600 * turn.lift;
352
526
  return ms < 40 ? 0 : Math.max(500, ms);
353
527
  };
354
- function routeOf(input) {
528
+ /**
529
+ * How a turn made by an aim point does when walked at the moments a walk of the move samples (a 240th of the move apart), with the turn taking `sc` of the move: the furthest from the middle of the picture
530
+ * the nearer of the two moons gets (1 is the edge, infinity is neither in the picture at some moment), and whether it keeps to the pace limits: the look direction turns less than `PACE_DEGREES` between two
531
+ * moments, the destination moves less than `PACE_SCREEN` of the frame, the look direction does not turn away from the last view's by more than `PACE_UNTURN` degrees, the camera goes less than `PACE_WAY` of the
532
+ * way, and the whole turn is under 1.2 times the least plus 1.5 degrees.
533
+ */
534
+ function aimFlaws(input, candidate, shells, leg, sc) {
535
+ const last = unit(input.end.forward);
536
+ const least = angleOf(unit(input.start.forward), last) / RAD;
537
+ let edge = 0;
538
+ let fair = true;
539
+ let before = null;
540
+ let way = 0;
541
+ let turned = 0;
542
+ const seen = [];
543
+ for (let i = 0; i <= Math.floor(AIM_CHECKS * sc) + 1; i += 1) {
544
+ const x = Math.min(1, i / (AIM_CHECKS * sc));
545
+ const t = sc * x;
546
+ const at = turnAt(candidate, ease(x), t, x);
547
+ const position = clearOf({ shells, leg }, at.position, t);
548
+ const frame = frameOf(at.fov, input.aspect);
549
+ const l = sightOf(input.leaving, t, position, at.o, frame);
550
+ const d = sightOf(input.destination, t, position, at.o, frame);
551
+ const off = (sight) => (sight.inside ? Math.max(Math.abs(sight.x), Math.abs(sight.y)) : Number.POSITIVE_INFINITY);
552
+ edge = Math.max(edge, Math.min(off(l), off(d)));
553
+ // a candidate is only wanted if the nearer moon stays inside `AIM_EDGE` and the pace is kept, so the walk stops at the first moment that is not
554
+ if (edge > AIM_EDGE)
555
+ return { edge, fair: false };
556
+ const now = { position, f: at.o.f, dest: d };
557
+ if (before !== null) {
558
+ const step = angleOf(before.f, at.o.f) / RAD;
559
+ turned += step;
560
+ way += length(sub(position, before.position));
561
+ if (step > PACE_DEGREES)
562
+ fair = false;
563
+ if (before.dest.inside && d.inside && Math.hypot(d.x - before.dest.x, d.y - before.dest.y) > PACE_SCREEN)
564
+ fair = false;
565
+ if (angleOf(at.o.f, last) - angleOf(before.f, last) > PACE_UNTURN * RAD)
566
+ fair = false;
567
+ if (!fair)
568
+ return { edge, fair };
569
+ }
570
+ seen.push(now);
571
+ before = now;
572
+ if (x >= 1)
573
+ break;
574
+ }
575
+ if (before !== null) {
576
+ const rest = length(sub(input.end.position, before.position));
577
+ for (let k = 1; k < seen.length; k += 1)
578
+ if (length(sub(seen[k].position, seen[k - 1].position)) > PACE_WAY * (way + rest))
579
+ fair = false;
580
+ if (turned + angleOf(before.f, last) / RAD > 1.2 * least + 1.5)
581
+ fair = false;
582
+ }
583
+ return { edge, fair };
584
+ }
585
+ /**
586
+ * The count of moments of a turn, among 68 from its first moments (sampled finely: the body left is nearest then, and nearest to being lost) to its last, at which neither the body left nor the destination is
587
+ * inside 0.9 of the picture, as a function of the lift and the hold that are tried on the turn: what does not depend on them (the look direction, the field of view, the places of the bodies, the pivot's
588
+ * direction) is worked out once for the turn. Every hold tried on a turn has the same direction `u` and body, as the search gives it. It gives the numbers `turnAt` and `sightOf` give, and stops counting at `cap`; the moments that missed before are looked at first.
589
+ */
590
+ function backOffKit(input, turn, share) {
591
+ const xs = [];
592
+ for (let i = 1; i < 64; i += 1)
593
+ for (const x of i === 1 ? [0.0005, 0.001, 0.002, 0.004, 0.008, 1 / 64] : [i / 64])
594
+ xs.push(x);
595
+ const moments = xs.map((x) => {
596
+ const t = share * x;
597
+ const p = ease(x);
598
+ const o = swingAt(turn.swing, p);
599
+ return {
600
+ t, p, o,
601
+ w: Math.sqrt(p),
602
+ base: Math.log(turn.d0) + (Math.log(turn.d1) - Math.log(turn.d0)) * p,
603
+ dir: toScene(o, arc(turn.u0, turn.u1, p)),
604
+ pivot: placeOf(turn.pivot, t),
605
+ frame: frameOf(fovBetween(turn.fov0, turn.fov1, p), input.aspect),
606
+ holdDir: null,
607
+ holdAt: null,
608
+ };
609
+ });
610
+ // the moments that missed are moved to the front, so that a candidate that misses is found out early
611
+ const order = moments.map((_, i) => i);
612
+ const seen = (body, m, position) => {
613
+ const sight = sightOf(body, m.t, position, m.o, m.frame);
614
+ return sight.inside && Math.abs(sight.x) <= 0.9 && Math.abs(sight.y) <= 0.9;
615
+ };
616
+ return (lift, hold, cap) => {
617
+ let missed = 0;
618
+ for (let k = 0; k < order.length && missed < cap; k += 1) {
619
+ const m = moments[order[k]];
620
+ const d = Math.exp(m.base + lift * 4 * m.w * (1 - m.w));
621
+ let position = sub(m.pivot, scale(m.dir, d));
622
+ if (hold !== undefined) {
623
+ m.holdDir ??= toScene(m.o, hold.u);
624
+ m.holdAt ??= placeOf(hold.body, m.t);
625
+ const near = sub(m.holdAt, scale(m.holdDir, hold.d * (1 + (hold.far - 1) * smooth(m.p / hold.q))));
626
+ position = mix(near, position, smooth(m.p / hold.q));
627
+ }
628
+ if (!seen(input.leaving, m, position) && !seen(input.destination, m, position)) {
629
+ missed += 1;
630
+ if (k > 0) {
631
+ const at = order[k];
632
+ order.splice(k, 1);
633
+ order.unshift(at);
634
+ }
635
+ }
636
+ }
637
+ return missed;
638
+ };
639
+ }
640
+ function routeBase(input, variant = 0) {
355
641
  const wanted = input.reduced ? "cut" : (input.kind ?? "turn-travel");
356
642
  const kind = wanted === "auto" ? "turn-travel" : wanted;
357
643
  const clearance = input.clearance ?? TRAVEL_CLEARANCE;
@@ -381,7 +667,7 @@ function routeOf(input) {
381
667
  const d0 = length(sub(input.leaving.from, input.start.position));
382
668
  const facing = swingDegrees(swingOf(o0, facingOf(input.end))) < 1 && within(toCamera(o0, sub(input.destination.from, input.start.position)), frameOf(input.start.fov, input.aspect), 0.93);
383
669
  const open = missOf(input.start.position, input.end.position, input.leaving.from) >= Math.min(1.52 * (1 + clearance) * input.leaving.radius, 0.9 * d0);
384
- let stand = facing && open ? { turn: { pivot: input.leaving, swing: swingOf(o0, o0), u0: [0, 0, 1], u1: [0, 0, 1], d0: 1, d1: 1, lift: 0, fov0: input.start.fov, fov1: input.start.fov }, leg: lineLeg(input, input.destination, undefined) } : standAt(input, 0.25, family);
670
+ let stand = facing && open ? { turn: { pivot: input.leaving, swing: swingOf(o0, o0), u0: [0, 0, 1], u1: [0, 0, 1], d0: 1, d1: 1, lift: 0, fov0: input.start.fov, fov1: input.start.fov }, leg: lineLeg(input, input.destination, undefined) } : standAt(input, 0.25, family, variant);
385
671
  // the stand is worked out for the moment the turn ends, which is the share of the move its own length gives: found by trying, until the two agree (the bodies move, so a stand for another moment would not meet the way on)
386
672
  let tm = 0.25;
387
673
  for (let pass = 0; pass < 8; pass += 1) {
@@ -390,7 +676,7 @@ function routeOf(input) {
390
676
  if ((facing && open) || share === 0 || Math.abs(share - tm) < 0.002)
391
677
  break;
392
678
  tm = pass === 0 ? share : (tm + share) / 2;
393
- stand = standAt(input, tm, family);
679
+ stand = standAt(input, tm, family, variant);
394
680
  }
395
681
  if (share > 0 && !(facing && open))
396
682
  share = tm;
@@ -409,30 +695,14 @@ function routeOf(input) {
409
695
  }
410
696
  else if (family && turn.pivot !== input.leaving) {
411
697
  // the planet is held, not the moon left: back the turn off in its middle until one of the two bodies is in the picture at every moment of it
412
- const frameAt = (fov) => frameOf(fov, input.aspect);
413
698
  // the stand is for the moment the turn ends, so when the backed-off turn takes another share of the move the stand is worked out again for that moment, until the two agree
414
699
  for (let round = 0; round < 4; round += 1) {
415
- const missing = (candidate) => {
416
- let missed = 0;
417
- for (let i = 1; i < 64; i += 1) {
418
- // the first moments are sampled finely: the body left is nearest then, and nearest to being lost
419
- for (const x of i === 1 ? [0.0005, 0.001, 0.002, 0.004, 0.008, 1 / 64] : [i / 64]) {
420
- const t = share * x;
421
- const at = turnAt(candidate, ease(x), t);
422
- const frame = frameAt(at.fov);
423
- const seen = (body) => {
424
- const sight = sightOf(body, t, at.position, at.o, frame);
425
- return sight.inside && Math.abs(sight.x) <= 0.9 && Math.abs(sight.y) <= 0.9;
426
- };
427
- if (!seen(input.leaving) && !seen(input.destination))
428
- missed += 1;
429
- }
430
- }
431
- return missed;
432
- };
700
+ // `cap`: the count is only wanted if it is under the best so far, so it stops counting when it is not
701
+ const kit = backOffKit(input, turn, share);
702
+ const missing = (candidate, cap = Number.POSITIVE_INFINITY) => kit(candidate.lift, candidate.hold, cap);
433
703
  let best = { turn, missed: Number.POSITIVE_INFINITY };
434
704
  for (let lift = 0; lift <= 3.31 && best.missed > 0; lift += 0.3) {
435
- const missed = missing({ ...turn, lift });
705
+ const missed = missing({ ...turn, lift }, best.missed);
436
706
  if (missed < best.missed)
437
707
  best = { turn: { ...turn, lift }, missed };
438
708
  }
@@ -444,7 +714,7 @@ function routeOf(input) {
444
714
  for (const q of [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]) {
445
715
  for (let lift = 0; lift <= 3.31 && best.missed > 0; lift += 0.3) {
446
716
  const candidate = { ...turn, lift, hold: { body: input.leaving, u, d, q, far } };
447
- const missed = missing(candidate);
717
+ const missed = missing(candidate, best.missed);
448
718
  if (missed < best.missed)
449
719
  best = { turn: candidate, missed };
450
720
  }
@@ -457,7 +727,7 @@ function routeOf(input) {
457
727
  if (Math.abs(next - share) < 0.002 || round === 3)
458
728
  break;
459
729
  share = (share + next) / 2;
460
- const again = standAt(input, share, family);
730
+ const again = standAt(input, share, family, variant);
461
731
  turn = again.turn;
462
732
  leg = again.leg;
463
733
  }
@@ -479,6 +749,183 @@ function routeOf(input) {
479
749
  const route = { ...base, cut: false, turn, share, arrive, leg };
480
750
  return { route, plan: { kind, path, stages: { turn: share, travel: arrive - share, arrive: 1 - arrive }, duration: Math.round(Math.min(9000, Math.max(1200, total)) * Math.max(0.05, input.pace ?? 1)), turn: least, settle: leg.type === "swing" ? swingDegrees(leg.swing) : 0, easing } };
481
751
  }
752
+ const FAULT_DRIFT = 0.02;
753
+ const FAULT_STEP = 0.3;
754
+ function faultsOf(route) {
755
+ const input = route.input;
756
+ const plan = { route };
757
+ const at = (t) => travelPose(input, t, plan);
758
+ const last = at(1);
759
+ const faults = { empty: 0, lost: 0, drift: 0, driftWorst: 0, step: 0, pace: 0, planet: 0 };
760
+ const lastF = unit(input.end.forward);
761
+ let turned = 0;
762
+ let way = 0;
763
+ const positions = [at(0).position];
764
+ let before = at(0);
765
+ const afterTurn = route.turn !== null ? Math.max(1, Math.ceil(route.share * 240 - 1e-9)) : 0;
766
+ for (let i = 1; i <= 240; i += 1) {
767
+ const s = at(i / 240);
768
+ if (!s.leaving.inside && !s.destination.inside)
769
+ faults.empty += 1;
770
+ if (s.around !== undefined && !s.around.inside)
771
+ faults.planet += 1;
772
+ if (i >= afterTurn && !s.destination.inside)
773
+ faults.lost += 1;
774
+ if (i > afterTurn) {
775
+ const off = Math.hypot(s.destination.x - last.destination.x, s.destination.y - last.destination.y);
776
+ const offBefore = Math.hypot(before.destination.x - last.destination.x, before.destination.y - last.destination.y);
777
+ if (before.destination.inside && off > offBefore + FAULT_DRIFT) {
778
+ faults.drift += 1;
779
+ faults.driftWorst = Math.max(faults.driftWorst, off - offBefore);
780
+ }
781
+ }
782
+ if (s.destination.inside && before.destination.inside && Math.hypot(s.destination.x - before.destination.x, s.destination.y - before.destination.y) >= FAULT_STEP)
783
+ faults.step += 1;
784
+ const turn = angleOf(before.forward, s.forward) / RAD;
785
+ turned += turn;
786
+ if (turn >= 6 || angleOf(s.forward, lastF) - angleOf(before.forward, lastF) > 0.05 * RAD)
787
+ faults.pace += 1;
788
+ way += length(sub(s.position, before.position));
789
+ positions.push(s.position);
790
+ before = s;
791
+ }
792
+ for (let i = 1; i < positions.length; i += 1)
793
+ if (length(sub(positions[i], positions[i - 1])) > 0.06 * way)
794
+ faults.pace += 1;
795
+ if (turned > 1.25 * (angleOf(unit(input.start.forward), lastF) / RAD) + 2)
796
+ faults.pace += 1;
797
+ return faults;
798
+ }
799
+ export const total = (f) => f.empty + f.lost + f.drift + f.step;
800
+ /**
801
+ * `now` has no kind of fault more than `was` (and no more of the drift in its worst sample) and fewer in all. A way that keeps the planet in the picture all through (`was.planet` is 0: the views promised it) must go
802
+ * on keeping it; where the first way did not (plain views never promised it) the planet out of the picture is not a fault, and only breaks a tie between two ways.
803
+ */
804
+ export const betterThan = (now, was) => now.empty <= was.empty && now.lost <= was.lost && now.drift <= was.drift && now.step <= was.step && now.pace <= was.pace && now.driftWorst <= was.driftWorst + 1e-12 && (was.planet > 0 || now.planet === 0) && total(now) < total(was);
805
+ /** The samples of a walk of the move (a 240th of it apart) at which neither the moon left nor the destination is in the picture. */
806
+ function emptyMoments(route) {
807
+ const input = route.input;
808
+ const frameFor = (fov) => frameOf(fov, input.aspect);
809
+ let empty = 0;
810
+ for (let i = 1; i <= 240; i += 1) {
811
+ const t = i / 240;
812
+ const at = along(route, t);
813
+ const frame = frameFor(at.fov);
814
+ if (!sightOf(input.leaving, t, at.position, at.o, frame).inside && !sightOf(input.destination, t, at.position, at.o, frame).inside)
815
+ empty += 1;
816
+ }
817
+ return empty;
818
+ }
819
+ function withAim(input, first, stop) {
820
+ const route = first.route;
821
+ if (route.turn === null || first.plan.path !== "circle" || route.cut || route.share <= 0)
822
+ return first;
823
+ const was = emptyMoments(route);
824
+ if (was === 0)
825
+ return first;
826
+ const share = route.share;
827
+ const swing = route.turn;
828
+ const flawsOf = (candidate) => aimFlaws(input, candidate, route.shells, route.leg, share);
829
+ // each way of leaning out and each pace, with the least backing off that keeps the nearer moon inside 0.95 of the way to the edge and every pace of the walk inside its limit; of those the one
830
+ // that costs least (the log of the backing off, the lean and the slowing) is taken, and none if none will do
831
+ let cost = Number.POSITIVE_INFINITY;
832
+ let best = null;
833
+ const kinds = AIM_SLOW.flatMap((slow) => AIM_BEND.map((bend) => ({ slow, bend, spent: 0.5 * bend + 2 * Math.log(slow) }))).sort((a, b) => a.spent - b.spent);
834
+ const bases = new Map();
835
+ for (const { slow, bend, spent: lean } of kinds) {
836
+ if (best !== null && lean >= cost)
837
+ break;
838
+ if (stop?.() === true)
839
+ break;
840
+ // the look directions and ups are the same at every pace: they are worked out once for each lean
841
+ if (!bases.has(bend))
842
+ bases.set(bend, aimOf(input, swing, share, bend, 1));
843
+ const base = { ...bases.get(bend), slow };
844
+ for (const far of AIM_FAR) {
845
+ const spent = Math.log(far) + lean;
846
+ if (best !== null && spent >= cost)
847
+ break;
848
+ if (stop?.() === true)
849
+ break;
850
+ const candidate = { ...swing, aim: { ...base, far } };
851
+ const flaws = flawsOf(candidate);
852
+ if (flaws.edge <= AIM_EDGE && flaws.fair) {
853
+ best = candidate;
854
+ cost = spent;
855
+ break;
856
+ }
857
+ }
858
+ }
859
+ if (best === null)
860
+ return first;
861
+ const aimed = { ...route, turn: best };
862
+ if (!flawsOf(best).fair || emptyMoments(aimed) >= was)
863
+ return first;
864
+ // the same shares of the move, and a length that is not less than it was
865
+ const t0 = turnMs(best);
866
+ const total = Math.max(t0 / share, first.plan.duration / Math.max(0.05, input.pace ?? 1));
867
+ return { route: aimed, plan: { ...first.plan, duration: Math.round(Math.min(9000, Math.max(1200, total)) * Math.max(0.05, input.pace ?? 1)) } };
868
+ }
869
+ /**
870
+ * The route of a move. A move within one planet's family (the path `circle`) is first made as it always was. If a walk of it has a picture with neither the body left nor the destination in it, its turn is made again by an
871
+ * aim point (see `Aim`): the turn takes the same share of the move and ends in the same place, so the way on and the arrival are the same, sample for sample, and only the turn is new. The new turn is taken when
872
+ * it leaves fewer such pictures and keeps to the pace limits. Every other move, and every such move whose walk has no empty picture, is the one it always was.
873
+ */
874
+ const routes = new WeakMap();
875
+ /** The ways to try in turn, the likeliest to be taken first (by how often each was in the survey of 360 walks): the nearest stand and a swing, a stand beyond the destination at 2, 4 and then 1 and 8 times the planet's distance from it. */
876
+ const WAYS = [1, 2, 4, 5, 3, 6];
877
+ function routeOf(input) {
878
+ const kept = routes.get(input);
879
+ if (kept !== undefined)
880
+ return kept;
881
+ // a plan is kept for the input it was made for, so the input is frozen (its top level: a field set after planning would be a plan of something else; the views and bodies are not to be changed either)
882
+ Object.freeze(input);
883
+ const made = routeMade(input);
884
+ routes.set(input, made);
885
+ return made;
886
+ }
887
+ function routeMade(input) {
888
+ // the time is counted from the start of the plan, and when it is up the other ways stop looking and the best so far is kept; the way a move is first made, with its aim turn, is always worked out, as it is the way
889
+ // before the other ways were tried and what they are measured against
890
+ const started = input.budget?.now();
891
+ const stop = input.budget === undefined || started === undefined ? undefined : () => input.budget.now() - started >= input.budget.ms;
892
+ const first = withAim(input, routeBase(input));
893
+ if (first.route.turn === null || first.plan.path !== "circle" || first.route.cut || first.route.share <= 0)
894
+ return first;
895
+ const was = faultsOf(first.route);
896
+ if (total(was) === 0)
897
+ return first;
898
+ // other ways of making the way on, each given the aim turn if it needs one: the nearest stand if its way clears the planet and a swing if not, and stands beyond the destination; the one with the fewest faults
899
+ // that has none of any kind more than the way it was made is taken, and of two with the same faults the one that keeps the planet in the picture longer; the first with no fault stops the search, and so does the
900
+ // budget, keeping the best so far
901
+ let best = first;
902
+ let least = was;
903
+ for (const variant of WAYS) {
904
+ if (stop?.() === true)
905
+ break;
906
+ const raw = routeBase(input, variant);
907
+ if (stop?.() === true)
908
+ break;
909
+ if (raw.plan.path !== "circle" || raw.route.turn === null)
910
+ continue;
911
+ // the aim turn cures only the empty pictures of the turn: a way made with more of any other fault than the way it was is not taken further
912
+ const rough = faultsOf(raw.route);
913
+ if (rough.lost > was.lost || rough.drift > was.drift || rough.step > was.step || rough.pace > was.pace || rough.driftWorst > was.driftWorst + 1e-12)
914
+ continue;
915
+ const other = rough.empty > 0 ? withAim(input, raw, stop) : raw;
916
+ if (other.route.turn === null)
917
+ continue;
918
+ const faults = rough.empty > 0 ? faultsOf(other.route) : rough;
919
+ const wins = (a, b) => total(a) < total(b) || (total(a) === total(b) && (a.driftWorst < b.driftWorst - 1e-12 || (a.driftWorst <= b.driftWorst + 1e-12 && a.planet < b.planet)));
920
+ if (betterThan(faults, was) && (best === first || wins(faults, least))) {
921
+ best = other;
922
+ least = faults;
923
+ }
924
+ if (total(least) === 0)
925
+ break;
926
+ }
927
+ return best;
928
+ }
482
929
  /**
483
930
  * The plan of a move: its stages and the share of the time each takes, how long it should last, and how it is eased. The length is a suggestion from how far the picture changes (16 milliseconds a degree
484
931
  * turned, 320 for each time the distance changes by a factor of e, between 1.2 and 9 seconds, times `pace`); a page may use its own, since `travelPose` takes the moment as a share of the move.
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.53.0";
1
+ export declare const VERSION = "0.54.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "0.53.0";
1
+ export const VERSION = "0.54.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/wakusei-planets",
3
- "version": "0.53.0",
3
+ "version": "0.54.0",
4
4
  "description": "Wakusei Planets 惑星 — The Sun, planets and moons for the web: each as a clean line drawing, a shaded realistic drawing or a painted surface map, with real sizes, axial tilt and rotation as data, and positions of the moons for any date and time. SVG for the lines, three.js (optional) for the rest.",
5
5
  "keywords": [
6
6
  "planets",