@heroiclands/package-build 22.4.5 → 22.4.6

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.
@@ -34,26 +34,32 @@ export function bearingSteps(a: unknown, b: unknown): number | undefined;
34
34
  * days nobody stated, is named. One log step beyond the horizon, so the rim
35
35
  * reads as the next ring rather than a margin.
36
36
  *
37
+ * @param {number} [horizon] - The horizon in days; the map from a place's
38
+ * by default.
37
39
  * @returns {number} Points.
38
40
  */
39
- export function rimRadius(): number;
41
+ export function rimRadius(horizon?: number): number;
40
42
  /**
41
43
  * The radius of the ring a days value sits on.
42
44
  *
43
45
  * Logarithmic in days, so equal ratios of days are equal steps of radius: a
44
- * day to two days is the same step as five to ten. Any value beyond the
45
- * horizon, and no value at all, is the rim.
46
+ * day to two days is the same step as five to ten, whatever the horizon. Any
47
+ * value beyond the horizon, and no value at all, is the rim.
46
48
  *
47
49
  * @param {number|undefined} days - A days value, on the scale or not.
50
+ * @param {number} [horizon] - The horizon in days; the map from a place's
51
+ * by default.
48
52
  * @returns {number} Points.
49
53
  */
50
- export function ringRadius(days: number | undefined): number;
54
+ export function ringRadius(days: number | undefined, horizon?: number): number;
51
55
  /**
52
56
  * The rings, inside out — one per marker up to the horizon.
53
57
  *
58
+ * @param {number} [horizon] - The horizon in days; the map from a place's
59
+ * by default.
54
60
  * @returns {Array<{days: number, radius: number}>} Each marker and its radius.
55
61
  */
56
- export function rings(): Array<{
62
+ export function rings(horizon?: number): Array<{
57
63
  days: number;
58
64
  radius: number;
59
65
  }>;
@@ -79,24 +85,37 @@ export function daysMarker(total: number | undefined): number | undefined;
79
85
  */
80
86
  export function edgeLength(days: number | undefined): number;
81
87
  /**
82
- * One hop of a journey: a bearing and, for a route, its days.
88
+ * A chain of hops composed into one bearing and one total, or nothing where
89
+ * a hop turns back.
90
+ *
91
+ * The composed direction is that of the hops added as vectors weighted by
92
+ * their days, and the total is their sum. Each hop after the first is
93
+ * checked against the running direction of the chain before it — not
94
+ * against the previous hop — and composes only where it lies within one
95
+ * octant of that direction, so a path may bend a little at every hop and
96
+ * drift past an octant of where it began, but a hop that turns back ends
97
+ * the chain: a place east and then north of here is not in any one
98
+ * direction, and the drawing omits it rather than guess. A hop with no days
99
+ * — a border — makes the total unknown, because a frontier states no
100
+ * distance, and then every hop weighs the same, because nothing says which
101
+ * is the longer.
83
102
  *
84
- * @typedef {object} Hop
85
- * @property {string} bearing - Where the far end lies from the near end.
86
- * @property {number} [days] - The route's marker; absent for a border.
103
+ * @param {Hop[]} hops - The hops, from the centre outward.
104
+ * @returns {{angle: number, days: number|undefined}|undefined} The composed
105
+ * bearing in degrees and the total days, or `undefined` where a hop turns
106
+ * back, a bearing is not one, or there are no hops.
87
107
  */
108
+ export function composeChain(hops: Hop[]): {
109
+ angle: number;
110
+ days: number | undefined;
111
+ } | undefined;
88
112
  /**
89
113
  * Two hops composed into one bearing and one total, or nothing where they
90
114
  * disagree.
91
115
  *
92
- * Two hops agree when their bearings are the same or adjacent; then the
93
- * composed direction is that of the two hops added as vectors weighted by
94
- * their days, and the total is their sum. A hop with no days — a border —
95
- * makes the total unknown, because a frontier states no distance, and then
96
- * the two hops weigh the same, because nothing says which is the longer.
97
- * Hops two or more steps apart do not compose:
98
- * a place east and then north of here is not in any one direction, and the
99
- * map omits it rather than guess.
116
+ * Two hops agree when their bearings are the same or adjacent — the
117
+ * two-hop case of {@link composeChain}: the second hop is checked against
118
+ * the first, which is the whole running direction at that point.
100
119
  *
101
120
  * @param {Hop} first - The hop from the centre.
102
121
  * @param {Hop} second - The hop onward.
@@ -133,7 +152,8 @@ export function relationsOf(places: Map<string, MapPlace>, shortcode: string): {
133
152
  }>;
134
153
  };
135
154
  /**
136
- * Lay out the map from a place.
155
+ * Lay out the map from a place: two hops, a horizon of 90 days, and a rim
156
+ * naming what lies beyond it.
137
157
  *
138
158
  * The centre at the origin. Every neighbour it states, or that states it, at
139
159
  * the angle of its bearing and on the ring of its days — the innermost ring
@@ -147,25 +167,35 @@ export function relationsOf(places: Map<string, MapPlace>, shortcode: string): {
147
167
  *
148
168
  * @param {Map<string, MapPlace>} places - Every place, by shortcode.
149
169
  * @param {string} centre - The place the map is from.
150
- * @returns {{centre: string, nodes: FromNode[], edges: FromEdge[],
151
- * rings: Array<{days: number, radius: number}>, rim: number,
152
- * unresolved: Array<{from: string, to: string}>}} The layout, in points.
170
+ * @returns {FromLayout} The layout, in points.
153
171
  * @throws {Error} When `centre` is not a place.
154
172
  */
155
- export function layoutFrom(places: Map<string, MapPlace>, centre: string): {
156
- centre: string;
157
- nodes: FromNode[];
158
- edges: FromEdge[];
159
- rings: Array<{
160
- days: number;
161
- radius: number;
162
- }>;
163
- rim: number;
164
- unresolved: Array<{
165
- from: string;
166
- to: string;
167
- }>;
168
- };
173
+ export function layoutFrom(places: Map<string, MapPlace>, centre: string): FromLayout;
174
+ /**
175
+ * Lay out the chart from a place: the map from it at a larger horizon.
176
+ *
177
+ * The neighbours as on the map from a place. Beyond them the hops chain on,
178
+ * each checked against the running direction of the chain so far and
179
+ * composing only within one octant of it, so a path bends but never turns
180
+ * back; a place is drawn at the composed bearing on the ring of the summed
181
+ * days, and where several chains reach it, by the one with the fewest. A
182
+ * border beyond the first hop makes the total unknown and sends the place to
183
+ * the rim, and nothing is drawn beyond it. A place whose total exceeds the
184
+ * horizon is left out — the chart is already the larger view — so the rim
185
+ * holds the unknown alone.
186
+ *
187
+ * @param {Map<string, MapPlace>} places - Every place, by shortcode.
188
+ * @param {string} centre - The place the chart is from.
189
+ * @param {object} [opts]
190
+ * @param {number} [opts.horizon] - The horizon in days, a marker of the
191
+ * scale; {@link CHART_HORIZON_DAYS} by default.
192
+ * @returns {FromLayout} The layout, in points.
193
+ * @throws {Error} When `centre` is not a place, or `horizon` is not a marker
194
+ * of the scale.
195
+ */
196
+ export function layoutChart(places: Map<string, MapPlace>, centre: string, { horizon }?: {
197
+ horizon?: number | undefined;
198
+ }): FromLayout;
169
199
  /**
170
200
  * One edge of the whole route graph.
171
201
  *
@@ -213,18 +243,12 @@ export const HORIZON_DAYS: number;
213
243
  */
214
244
  export const RING_DAYS: readonly number[];
215
245
  /**
216
- * One hop of a journey: a bearing and, for a route, its days.
246
+ * The horizon of the chart from a place when none is asked for, in days: the
247
+ * end of the scale, so the whole of what the notes state fits on the page.
248
+ *
249
+ * @type {number}
217
250
  */
218
- export type Hop = {
219
- /**
220
- * - Where the far end lies from the near end.
221
- */
222
- bearing: string;
223
- /**
224
- * - The route's marker; absent for a border.
225
- */
226
- days?: number | undefined;
227
- };
251
+ export const CHART_HORIZON_DAYS: number;
228
252
  /**
229
253
  * A place as the map reads it. The shape {@link module :engine/map-places}
230
254
  * builds from the content index; only the relation fields matter here.
@@ -265,6 +289,35 @@ export type Relation = {
265
289
  */
266
290
  stated: boolean;
267
291
  };
292
+ /**
293
+ * The layout of the map from a place or of the chart from one.
294
+ */
295
+ export type FromLayout = {
296
+ centre: string;
297
+ nodes: FromNode[];
298
+ edges: FromEdge[];
299
+ rings: Array<{
300
+ days: number;
301
+ radius: number;
302
+ }>;
303
+ /**
304
+ * - The rim's radius, in points.
305
+ */
306
+ rim: number;
307
+ /**
308
+ * - The horizon, in days.
309
+ */
310
+ horizon: number;
311
+ /**
312
+ * - Whether a place past the horizon is named at
313
+ * the rim; false, it is omitted and the rim holds only the unknown.
314
+ */
315
+ beyond: boolean;
316
+ unresolved: Array<{
317
+ from: string;
318
+ to: string;
319
+ }>;
320
+ };
268
321
  /**
269
322
  * One edge of the whole route graph.
270
323
  */
@@ -283,13 +336,27 @@ export type TravelEdge = {
283
336
  */
284
337
  len: number;
285
338
  };
339
+ /**
340
+ * One hop of a journey: a bearing and, for a route, its days.
341
+ */
342
+ export type Hop = {
343
+ /**
344
+ * - Where the far end lies from the near end.
345
+ */
346
+ bearing: string;
347
+ /**
348
+ * - The route's marker; absent for a border.
349
+ */
350
+ days?: number | undefined;
351
+ };
286
352
  /**
287
353
  * One place on the map from a place.
288
354
  */
289
355
  export type FromNode = {
290
356
  shortcode: string;
291
357
  /**
292
- * - 0 for the centre, 1 for a neighbour, 2 beyond.
358
+ * - 0 for the centre, 1 for a neighbour, 2 and up
359
+ * beyond — the map from a place stops at 2, the chart goes on.
293
360
  */
294
361
  hop: number;
295
362
  /**
@@ -321,7 +388,8 @@ export type FromNode = {
321
388
  */
322
389
  unknown: boolean;
323
390
  /**
324
- * - The neighbour a second hop is reached through.
391
+ * - The place a hop beyond the neighbours is reached
392
+ * through.
325
393
  */
326
394
  via?: string | undefined;
327
395
  };
@@ -353,7 +421,7 @@ export type FromEdge = {
353
421
  days: number | undefined;
354
422
  }>;
355
423
  /**
356
- * - 1 from the centre, 2 onward.
424
+ * - 1 from the centre, 2 and up onward.
357
425
  */
358
426
  hop: number;
359
427
  };