roamwright 0.4.0 → 0.20.1

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.
Files changed (139) hide show
  1. package/CONTRIBUTING.md +3 -1
  2. package/README.md +11 -34
  3. package/geometry/bedding.js +141 -0
  4. package/geometry/builder-cells.js +42 -0
  5. package/geometry/builder-frame.js +47 -0
  6. package/geometry/builder.js +189 -177
  7. package/geometry/cell-mask.js +25 -0
  8. package/geometry/creased-sheet.js +34 -34
  9. package/geometry/ear.js +36 -36
  10. package/geometry/erosion.js +65 -42
  11. package/geometry/face-grid.js +65 -65
  12. package/geometry/foliage.js +10 -10
  13. package/geometry/hair-gathers.js +41 -41
  14. package/geometry/hair-locks.js +41 -41
  15. package/geometry/hair-patch.js +18 -18
  16. package/geometry/hair-shell.js +31 -31
  17. package/geometry/head-profile.js +15 -15
  18. package/geometry/head-shape.js +77 -77
  19. package/geometry/heightfield.js +27 -18
  20. package/geometry/index-parts.js +2 -2
  21. package/geometry/instance-visibility.js +12 -12
  22. package/geometry/instances.js +15 -15
  23. package/geometry/outline-grid.js +7 -7
  24. package/geometry/part-ranges.js +3 -3
  25. package/geometry/path-field.js +63 -33
  26. package/geometry/placement.js +52 -52
  27. package/geometry/point-buckets.js +50 -0
  28. package/geometry/primitives.js +63 -47
  29. package/geometry/sagging-tube.js +27 -27
  30. package/geometry/sampled-surface.js +109 -77
  31. package/geometry/scatter-grid.js +46 -6
  32. package/geometry/sculpt.js +93 -93
  33. package/geometry/shore-grid.js +77 -34
  34. package/geometry/strata-field.js +92 -92
  35. package/geometry/strata-tiles.js +91 -91
  36. package/geometry/stream.js +70 -48
  37. package/geometry/terrain-chunks.js +87 -82
  38. package/geometry/terrain-extension.js +6 -6
  39. package/index.js +5 -0
  40. package/math/cell-edge.js +16 -16
  41. package/math/cell-key.js +6 -0
  42. package/math/circle-clearances.js +19 -0
  43. package/math/cloth-textures.js +6 -6
  44. package/math/cloud-textures.js +20 -20
  45. package/math/color.js +14 -14
  46. package/math/curve.js +22 -22
  47. package/math/mountain-ranges.js +216 -165
  48. package/math/noise.js +101 -49
  49. package/math/particle-noise.js +28 -28
  50. package/math/periodic.js +5 -5
  51. package/math/random.js +24 -15
  52. package/math/rectangles.js +52 -0
  53. package/math/rock-texture.js +7 -7
  54. package/math/scalar.js +5 -5
  55. package/math/surface-textures.js +54 -54
  56. package/motion/arm-reach.js +24 -24
  57. package/motion/ballistic-arc.js +11 -0
  58. package/motion/biped-cycle.js +44 -0
  59. package/motion/biped-leg.js +37 -0
  60. package/motion/biped-stride.js +98 -122
  61. package/motion/contact-transition.js +33 -0
  62. package/motion/crowd-alarms.js +39 -39
  63. package/motion/crowd-routine.js +94 -65
  64. package/motion/daily-clock.js +9 -9
  65. package/motion/deck-surface.js +38 -0
  66. package/motion/ground-lookahead.js +5 -5
  67. package/motion/instance-sight.js +8 -8
  68. package/motion/player.js +36 -28
  69. package/motion/quadruped.js +155 -155
  70. package/motion/spaces.js +32 -32
  71. package/motion/weather.js +73 -24
  72. package/motion/wind.js +32 -13
  73. package/package.json +7 -3
  74. package/rendering/caster-motion.js +5 -5
  75. package/rendering/cell-lod.js +138 -82
  76. package/rendering/cloud-dome.js +28 -28
  77. package/rendering/cloud-field.js +2 -2
  78. package/rendering/compilation-schedule.js +68 -11
  79. package/rendering/contact-shadows.js +2 -2
  80. package/rendering/context.js +12 -0
  81. package/rendering/crowd-skinning.js +13 -13
  82. package/rendering/crust.js +18 -12
  83. package/rendering/daylight.js +3 -3
  84. package/rendering/detail-range.js +28 -0
  85. package/rendering/dispose-meshes.js +18 -0
  86. package/rendering/dof.js +9 -9
  87. package/rendering/eye-adapt.js +14 -14
  88. package/rendering/far-shadow.js +8 -8
  89. package/rendering/flocks.js +78 -78
  90. package/rendering/garment-material.js +17 -17
  91. package/rendering/glow-lines.js +13 -13
  92. package/rendering/hair-strands.js +20 -20
  93. package/rendering/height-probe.js +149 -19
  94. package/rendering/label-layout.js +46 -0
  95. package/rendering/label-range.js +38 -0
  96. package/rendering/light-budget.js +52 -52
  97. package/rendering/light-shafts.js +23 -23
  98. package/rendering/local-lights.js +15 -4
  99. package/rendering/material-lod.js +49 -49
  100. package/rendering/particle-emitters.js +90 -90
  101. package/rendering/particles.js +78 -67
  102. package/rendering/piece-batch.js +17 -6
  103. package/rendering/planar-reflection.js +38 -38
  104. package/rendering/post-shaders.js +17 -13
  105. package/rendering/post.js +71 -71
  106. package/rendering/rain-streaks.js +67 -0
  107. package/rendering/road-surface.js +11 -11
  108. package/rendering/sea-shaders.js +11 -11
  109. package/rendering/shader-warmup.js +29 -16
  110. package/rendering/shadow-alignment.js +4 -4
  111. package/rendering/shadow-depth.js +7 -7
  112. package/rendering/sky-occlusion.js +16 -16
  113. package/rendering/sky.js +16 -6
  114. package/rendering/stage-lights.js +6 -6
  115. package/rendering/static-point-shadow.js +3 -3
  116. package/rendering/still-casters.js +1 -1
  117. package/rendering/strata-material.js +10 -10
  118. package/rendering/stream-flow.js +10 -10
  119. package/rendering/taa.js +26 -26
  120. package/rendering/talus.js +15 -15
  121. package/rendering/terrain-rock.js +7 -7
  122. package/rendering/texture-fills.js +8 -8
  123. package/rendering/textures.js +28 -28
  124. package/rendering/wakes.js +24 -24
  125. package/rendering/water-material.js +36 -23
  126. package/rendering/world-matrices.js +38 -38
  127. package/runtime/diagnostic-log.js +2 -2
  128. package/runtime/first-use.js +33 -28
  129. package/runtime/frame-pacing.js +33 -0
  130. package/runtime/gpu-timing.js +7 -7
  131. package/runtime/grid-cache.js +1 -1
  132. package/runtime/grid-rows.js +44 -5
  133. package/runtime/hand-over.js +41 -23
  134. package/runtime/pool.js +58 -16
  135. package/runtime/quality-fit.js +1 -1
  136. package/runtime/search.js +22 -22
  137. package/runtime/spatial-audio.js +13 -13
  138. package/runtime/withdrawable-task.js +35 -0
  139. package/runtime/worker.js +7 -0
@@ -1,4 +1,8 @@
1
- // Seeded height and scree fields for elliptical uplands, branching ranges and groups of hills.
1
+ /**
2
+ * Add seeded hills, ridges and escarpments to a terrain height function.
3
+ * {@link createMountainRanges} samples relief and loose rock for the same location.
4
+ * @module
5
+ */
2
6
  import { clamp, lerp, sstep } from './scalar.js';
3
7
  import { createNoise } from './noise.js';
4
8
  import { createHash } from './random.js';
@@ -43,18 +47,61 @@ const RANGE_FROM = [0.3, 0.75], // how broken an upland must be to begin to be a
43
47
  SWELL_WARP = 0.22, // and how far that radius is pulled about
44
48
  SEG = 9; // numbers to a spur: its ends (u, v), the metres along it at each, its flanks' width at each, its ribs' phase
45
49
 
50
+ /**
51
+ * @typedef {object} EllipticalUpland
52
+ * @property {number} x - Centre X in metres.
53
+ * @property {number} z - Centre Z in metres.
54
+ * @property {number} rx - X radius in metres, or half-length along the supplied axis.
55
+ * @property {number} rz - Z radius in metres, or half-width across the supplied axis.
56
+ * @property {number} h - Height scale in metres.
57
+ * @property {number} rough - Relief roughness from 0 for a smooth swell to 1 for a broken ridge.
58
+ * @property {number} [axis] - Long-axis bearing in radians from +X toward +Z.
59
+ * @property {number} [face] - Bearing toward the steep side of an escarpment, in radians.
60
+ * @property {number} [hills] - Number of hills to scatter inside the ellipse.
61
+ */
62
+
63
+ /**
64
+ * @typedef {object} Ridge
65
+ * @property {[number, number, number][]} crest - At least two distinct consecutive points, each [x, z, height multiplier].
66
+ * @property {number} wide - Flank half-width in metres.
67
+ * @property {number} h - Height in metres before applying each crest point’s multiplier.
68
+ * @property {number} rough - Relief roughness from 0 to 1.
69
+ * @property {number} [face] - Bearing toward the steep side of an escarpment, in radians from +X toward +Z.
70
+ */
71
+
46
72
  // The long axis of an upland given as an ellipse ({ x, z, rx, rz }), as [bearing, half-length, half-width]: the longer of its
47
73
  // radii, or along `axis` (a bearing: 0 east, clockwise seen from above), with rx then its half-length and rz its half-width.
48
- const ellipseAxis = m => (m.axis !== undefined ? [m.axis, m.rx, m.rz] : m.rx >= m.rz ? [0, m.rx, m.rz] : [Math.PI / 2, m.rz, m.rx]);
49
- // The line of an upland's crest as its data gives it ([[x, z], ...]) and its half-width, for the map's drawing of it.
50
- export function crestOf(m) {
51
- if (m.crest) return { line: m.crest, wide: m.wide };
52
- const [bearing, a, b] = ellipseAxis(m),
53
- reach = 0.8 * a;
54
- return { line: [-reach, reach].map(u => [m.x + u * Math.cos(bearing), m.z + u * Math.sin(bearing)]), wide: b };
74
+ const ellipseAxis = landform => (landform.axis !== undefined ? [landform.axis, landform.rx, landform.rz] : landform.rx >= landform.rz ? [0, landform.rx, landform.rz] : [Math.PI / 2, landform.rz, landform.rx]);
75
+ /**
76
+ * Get the crest line and flank half-width for drawing a map. An explicit ridge
77
+ * keeps its original point array, including the third height component. An
78
+ * ellipse yields two X/Z endpoints along its long axis.
79
+ * @param {EllipticalUpland | Ridge} landform - Landform supplied to the range layout.
80
+ */
81
+ export function crestOf(landform) {
82
+ if (landform.crest) return { line: landform.crest, wide: landform.wide };
83
+ const [bearing, halfLength, halfWidth] = ellipseAxis(landform),
84
+ reach = 0.8 * halfLength;
85
+ return { line: [-reach, reach].map(u => [landform.x + u * Math.cos(bearing), landform.z + u * Math.sin(bearing)]), wide: halfWidth };
55
86
  }
56
87
 
57
- // Each field owns its layout and sampling scratch so separate terrains can be sampled independently.
88
+ /**
89
+ * Build a reusable field of mountain relief. Call `layout` with ellipses or ridgelines,
90
+ * then add `heightAt(x, z)` to the base terrain elevation in metres. Each call also
91
+ * overwrites `surface.scree`, the loose-rock amount for that sample.
92
+ * Calling `layout` again replaces the previous landforms. Keep their order stable
93
+ * when reproducing a landscape because each landform’s seed depends on its index.
94
+ * @param {number} [seed] - World seed for the ridges, spurs and surface detail.
95
+ * @example
96
+ * ```js
97
+ * import { createMountainRanges } from 'roamwright/math/mountain-ranges.js';
98
+ *
99
+ * const mountains = createMountainRanges(42);
100
+ * mountains.layout([{ crest: [[0, 0, 0.6], [120, 40, 1]], wide: 50, h: 90, rough: 0.8 }]);
101
+ * const elevation = 12 + mountains.heightAt(80, 25);
102
+ * const looseRock = mountains.surface.scree;
103
+ * ```
104
+ */
58
105
  export function createMountainRanges(seed = 0) {
59
106
  const { fbm, ridged, vnoise } = createNoise(seed);
60
107
  const hash2 = createHash(seed);
@@ -67,8 +114,8 @@ export function createMountainRanges(seed = 0) {
67
114
 
68
115
  // The swell of an ellipse ({ x, z, rx, rz, h, rough }) at (x, z), in metres: a rise that falls away smoothly all round, broken
69
116
  // by noise the more it is rough.
70
- function swellAt(m, x, z) {
71
- const r0 = ((x - m.x) / m.rx) ** 2 + ((z - m.z) / m.rz) ** 2;
117
+ function swellAt(landform, x, z) {
118
+ const r0 = ((x - landform.x) / landform.rx) ** 2 + ((z - landform.z) / landform.rz) ** 2;
72
119
  if (r0 >= SWELL_REACH + SWELL_WARP / 2) return 0;
73
120
  if (crag < 0) {
74
121
  // the noise is worked out only where a swell is near
@@ -76,72 +123,72 @@ export function createMountainRanges(seed = 0) {
76
123
  pull = SWELL_WARP * (fbm(x * 0.0021, z * 0.0021, 2, 337) - 0.5);
77
124
  }
78
125
  const r = r0 + pull;
79
- return r < SWELL_REACH ? m.h * Math.exp(-1.5 * Math.max(r, 0)) * lerp(1, 0.35 + 1.25 * crag, m.rough) : 0;
126
+ return r < SWELL_REACH ? landform.h * Math.exp(-1.5 * Math.max(r, 0)) * lerp(1, 0.35 + 1.25 * crag, landform.rough) : 0;
80
127
  }
81
128
 
82
129
  // The height of a limb's crest at u, as a share of its own: 1 along its length, falling away past each end.
83
- function crestShare(L, u) {
84
- const over = u < 0 ? -u / L.tail0 : u > L.len ? (u - L.len) / L.tail1 : 0;
85
- return (over > 0 ? Math.exp(-1.5 * over ** L.fall) : 1) * lerp(L.k0, L.k1, clamp(u / (L.len || 1), 0, 1));
130
+ function crestShare(limbData, u) {
131
+ const over = u < 0 ? -u / limbData.tail0 : u > limbData.len ? (u - limbData.len) / limbData.tail1 : 0;
132
+ return (over > 0 ? Math.exp(-1.5 * over ** limbData.fall) : 1) * lerp(limbData.k0, limbData.k1, clamp(u / (limbData.len || 1), 0, 1));
86
133
  }
87
134
  // How far a limb's crest stands off its straight line at u: it wanders, and an escarpment's rim stands toward its face.
88
- function crestOffset(L, u) {
89
- const stray = 2 * (vnoise(u / L.wave + 7.3, 0, L.seed) - L.strayAt);
90
- return L.rim + L.wander * stray * (L.line ? sstep(0, L.step, u) * sstep(L.len, L.len - L.step, u) : 1); // the stretches of a line meet end to end
135
+ function crestOffset(limbData, u) {
136
+ const stray = 2 * (vnoise(u / limbData.wave + 7.3, 0, limbData.seed) - limbData.strayAt);
137
+ return limbData.rim + limbData.wander * stray * (limbData.line ? sstep(0, limbData.step, u) * sstep(limbData.len, limbData.len - limbData.step, u) : 1); // the stretches of a line meet end to end
91
138
  }
92
139
  // How far a range leans to one side at u, -1..1: no range's two flanks are alike, and which is the steeper changes along it.
93
- const leanAt = (L, u, seed) => 2 * vnoise(u / (4 * L.step) + 3.1, 0, L.seed + seed) - 1;
94
- // The width of a limb's flank on `side` of its crest at u, where the crest stands at share E of its height: a range narrows as
140
+ const leanAt = (limbData, u, seed) => 2 * vnoise(u / (4 * limbData.step) + 3.1, 0, limbData.seed + seed) - 1;
141
+ // The width of a limb's flank on `side` of its crest at u, where the crest stands at fraction crestFraction of its height: a range narrows as
95
142
  // its crest falls, so its flanks keep their slope, and the flank it leans toward is the narrower and steeper.
96
- const flankWidth = (L, E, side, u) =>
97
- L.b * (NARROW + (1 - NARROW) * E) * (L.face ? (L.face === side ? SCARP.face : SCARP.back) : 1 - side * LOP * L.rough * leanAt(L, u, 9));
143
+ const flankWidth = (limbData, crestFraction, side, u) =>
144
+ limbData.b * (NARROW + (1 - NARROW) * crestFraction) * (limbData.face ? (limbData.face === side ? SCARP.face : SCARP.back) : 1 - side * LOP * limbData.rough * leanAt(limbData, u, 9));
98
145
  // How far a range's shape is pulled off its place at (x, z), along x (`turn` 0) or z (1), as a share of the most: at two scales.
99
- const warpAt = (L, x, z, turn) => 2 * fbm(x * L.warpOver + 31.7 * turn, z * L.warpOver + 11.3 * turn, 2, L.seed + 3 + turn) - 1;
146
+ const warpAt = (limbData, x, z, turn) => 2 * fbm(x * limbData.warpOver + 31.7 * turn, z * limbData.warpOver + 11.3 * turn, 2, limbData.seed + 3 + turn) - 1;
100
147
  // How far a crest is notched at u, as a share of the most.
101
- const notchAt = (L, u) => 2 * fbm(u / (0.7 * L.step), 0, 3, L.seed + 6) - 1;
148
+ const notchAt = (limbData, u) => 2 * fbm(u / (0.7 * limbData.step), 0, 3, limbData.seed + 6) - 1;
102
149
 
103
150
  // The peaks and saddles of a limb's crest, as [u, share of the height] in turn from a peak to a peak: a peak stands where the
104
151
  // data puts the upland (the middle of an ellipse, the points of a line), the rest a spacing apart.
105
- function crestKnots(L, spacing) {
106
- const first = L.line ? 0 : L.len / 2,
107
- step = L.line ? L.len / Math.max(1, Math.round(L.len / spacing)) : spacing,
108
- last = L.line ? Math.round(L.len / step) : 0, // the peak at a line's far point
109
- from = -Math.ceil((first + 1.3 * L.tail0) / step),
110
- to = Math.ceil((L.len + 1.3 * L.tail1 - first) / step),
111
- level = L.rough * (L.face ? SCARP.level : 1),
152
+ function crestKnots(limbData, spacing) {
153
+ const first = limbData.line ? 0 : limbData.len / 2,
154
+ step = limbData.line ? limbData.len / Math.max(1, Math.round(limbData.len / spacing)) : spacing,
155
+ last = limbData.line ? Math.round(limbData.len / step) : 0, // the peak at a line's far point
156
+ from = -Math.ceil((first + 1.3 * limbData.tail0) / step),
157
+ to = Math.ceil((limbData.len + 1.3 * limbData.tail1 - first) / step),
158
+ level = limbData.rough * (limbData.face ? SCARP.level : 1),
112
159
  knots = [];
113
160
  let before = 0;
114
161
  for (let k = from; k <= to; k++) {
115
- const given = k === 0 || (L.line && k === last),
116
- u = first + (k + (given ? 0 : 0.6 * (hash2(k, 1, L.seed) - 0.5))) * step,
117
- peak = given ? 1 : 1 - level * PEAK_DROP * Math.sqrt(hash2(k, 2, L.seed)); // a few stand near the highest, most well under it
162
+ const given = k === 0 || (limbData.line && k === last),
163
+ u = first + (k + (given ? 0 : 0.6 * (hash2(k, 1, limbData.seed) - 0.5))) * step,
164
+ peak = given ? 1 : 1 - level * PEAK_DROP * Math.sqrt(hash2(k, 2, limbData.seed)); // a few stand near the highest, most well under it
118
165
  if (k > from) {
119
- const drop = lerp(SADDLE_DROP[0], SADDLE_DROP[1], hash2(k, 4, L.seed)) + (hash2(k, 5, L.seed) < PASS[0] ? PASS[1] : 0);
120
- knots.push(lerp(knots[knots.length - 2], u, 0.35 + 0.3 * hash2(k, 3, L.seed)), Math.min(before, peak) - level * drop);
166
+ const drop = lerp(SADDLE_DROP[0], SADDLE_DROP[1], hash2(k, 4, limbData.seed)) + (hash2(k, 5, limbData.seed) < PASS[0] ? PASS[1] : 0);
167
+ knots.push(lerp(knots[knots.length - 2], u, 0.35 + 0.3 * hash2(k, 3, limbData.seed)), Math.min(before, peak) - level * drop);
121
168
  }
122
169
  knots.push(u, peak);
123
170
  before = peak;
124
171
  }
125
- L.step = step;
172
+ limbData.step = step;
126
173
  return Float64Array.from(knots);
127
174
  }
128
175
  // How high a limb's crest stands at u between its peaks and saddles, as a share: pointed at a peak, level across a saddle.
129
- function knotShare(L, u) {
130
- const K = L.knots,
131
- n = K.length / 2;
132
- if (u <= K[0]) return K[1];
133
- if (u >= K[2 * n - 2]) return K[2 * n - 1];
134
- let i = clamp(Math.floor(((u - K[0]) / L.step) * 2), 0, n - 2);
135
- while (K[2 * i] > u) i--;
136
- while (K[2 * i + 2] < u) i++;
137
- const t = (u - K[2 * i]) / (K[2 * i + 2] - K[2 * i]),
138
- a = K[2 * i + 1],
139
- b = K[2 * i + 3];
140
- return a >= b ? b + (a - b) * (1 - t) ** PEAK_POINT : a + (b - a) * t ** PEAK_POINT;
176
+ function knotShare(limbData, u) {
177
+ const knots = limbData.knots,
178
+ n = knots.length / 2;
179
+ if (u <= knots[0]) return knots[1];
180
+ if (u >= knots[2 * n - 2]) return knots[2 * n - 1];
181
+ let i = clamp(Math.floor(((u - knots[0]) / limbData.step) * 2), 0, n - 2);
182
+ while (knots[2 * i] > u) i--;
183
+ while (knots[2 * i + 2] < u) i++;
184
+ const t = (u - knots[2 * i]) / (knots[2 * i + 2] - knots[2 * i]),
185
+ startHeight = knots[2 * i + 1],
186
+ endHeight = knots[2 * i + 3];
187
+ return startHeight >= endHeight ? endHeight + (startHeight - endHeight) * (1 - t) ** PEAK_POINT : startHeight + (endHeight - startHeight) * t ** PEAK_POINT;
141
188
  }
142
189
  // The spurs that run down one side of a limb: one from each peak, with a branch or two that leave it lower down, and a short
143
190
  // one from the shoulder of most saddles. A spur is a straight line: the range's warp bends it.
144
- function limbSpurs(L, side) {
191
+ function limbSpurs(limbData, side) {
145
192
  const out = [],
146
193
  spur = (u0, v0, angle, long, tau, wide0, wide1, seed) =>
147
194
  out.push(
@@ -153,26 +200,26 @@ export function createMountainRanges(seed = 0) {
153
200
  tau + long,
154
201
  wide0,
155
202
  wide1,
156
- hash2(seed, 9, L.seed),
203
+ hash2(seed, 9, limbData.seed),
157
204
  );
158
- for (let k = 0; k < L.knots.length; k += 2) {
159
- const u = L.knots[k],
160
- E = crestShare(L, u),
205
+ for (let k = 0; k < limbData.knots.length; k += 2) {
206
+ const u = limbData.knots[k],
207
+ crestFraction = crestShare(limbData, u),
161
208
  id = k + (side > 0 ? 1 : 0),
162
- r = n => hash2(id, n, L.seed + 1),
209
+ r = n => hash2(id, n, limbData.seed + 1),
163
210
  peak = k % 4 === 0;
164
- if (E < SPUR_LEAST || (!peak && r(0) > SHOULDER)) continue;
165
- const buttress = L.face === side, // an escarpment's face is buttressed, not spurred
166
- long = flankWidth(L, E, side, u) * FOOT * (buttress ? 0.75 : peak ? 0.45 + 0.7 * r(1) : 0.3 + 0.35 * r(1)),
167
- splay = u < 0 ? -sstep(0, 1, -u / L.tail0) : u > L.len ? sstep(0, 1, (u - L.len) / L.tail1) : 0, // round a crest's end they fan out
211
+ if (crestFraction < SPUR_LEAST || (!peak && r(0) > SHOULDER)) continue;
212
+ const buttress = limbData.face === side, // an escarpment's face is buttressed, not spurred
213
+ long = flankWidth(limbData, crestFraction, side, u) * FOOT * (buttress ? 0.75 : peak ? 0.45 + 0.7 * r(1) : 0.3 + 0.35 * r(1)),
214
+ splay = u < 0 ? -sstep(0, 1, -u / limbData.tail0) : u > limbData.len ? sstep(0, 1, (u - limbData.len) / limbData.tail1) : 0, // round a crest's end they fan out
168
215
  lean = (r(2) - 0.5) * 1.1 + 0.9 * splay,
169
- v = crestOffset(L, u),
170
- girth = L.step * (0.8 + 0.4 * r(7));
216
+ v = crestOffset(limbData, u),
217
+ girth = limbData.step * (0.8 + 0.4 * r(7));
171
218
  spur(u, v, lean, long, 0, 0.42 * girth, 0.64 * girth, id);
172
219
  if (buttress || !peak) continue;
173
- for (let b = 0; b < 2; b++) {
174
- const at = (b ? 0.6 : 0.38) + 0.14 * r(3 + b),
175
- turn = lean + (b ? -1 : 1) * (r(5) < 0.5 ? -1 : 1) * (0.6 + 0.4 * r(6 + b));
220
+ for (let branchIndex = 0; branchIndex < 2; branchIndex++) {
221
+ const at = (branchIndex ? 0.6 : 0.38) + 0.14 * r(3 + branchIndex),
222
+ turn = lean + (branchIndex ? -1 : 1) * (r(5) < 0.5 ? -1 : 1) * (0.6 + 0.4 * r(6 + branchIndex));
176
223
  spur(
177
224
  u + at * long * Math.sin(lean),
178
225
  v + side * at * long * Math.cos(lean),
@@ -181,32 +228,32 @@ export function createMountainRanges(seed = 0) {
181
228
  at * long,
182
229
  0.3 * girth,
183
230
  0.42 * girth,
184
- id + 1000 * (b + 1),
231
+ id + 1000 * (branchIndex + 1),
185
232
  );
186
233
  }
187
234
  }
188
235
  // where a crest ends, a long spur runs out and away on either side of its fall, so that the end of a range is no cone
189
236
  for (const [u, away, free] of [
190
- [0, -1, L.free0],
191
- [L.len, 1, L.free1],
237
+ [0, -1, limbData.free0],
238
+ [limbData.len, 1, limbData.free1],
192
239
  ]) {
193
240
  if (!free) continue;
194
241
  const id = 5000 + (away > 0 ? 2 : 0) + (side > 0 ? 1 : 0),
195
- long = flankWidth(L, crestShare(L, u), side, u) * FOOT * (0.7 + 0.6 * hash2(id, 1, L.seed + 1)),
196
- girth = L.step * (1 + 0.4 * hash2(id, 2, L.seed + 1));
197
- spur(u, crestOffset(L, u), away * (0.6 + 0.7 * hash2(id, 3, L.seed + 1)), long, 0, 0.42 * girth, 0.64 * girth, id);
242
+ long = flankWidth(limbData, crestShare(limbData, u), side, u) * FOOT * (0.7 + 0.6 * hash2(id, 1, limbData.seed + 1)),
243
+ girth = limbData.step * (1 + 0.4 * hash2(id, 2, limbData.seed + 1));
244
+ spur(u, crestOffset(limbData, u), away * (0.6 + 0.7 * hash2(id, 3, limbData.seed + 1)), long, 0, 0.42 * girth, 0.64 * girth, id);
198
245
  }
199
- return binned(L, out);
246
+ return binned(limbData, out);
200
247
  }
201
248
  // The spurs of `list` sorted into bins along a limb's crest, a peak spacing long each: every bin holds the spurs that reach into
202
249
  // its stretch, so a place asks only the few that could lie near it.
203
- function binned(L, list) {
204
- const bins = Array.from({ length: Math.ceil((L.to - L.from) / L.step) }, () => []);
250
+ function binned(limbData, list) {
251
+ const bins = Array.from({ length: Math.ceil((limbData.to - limbData.from) / limbData.step) }, () => []);
205
252
  for (let i = 0; i < list.length; i += SEG) {
206
253
  const reach = Math.max(list[i + 6], list[i + 7]),
207
- first = Math.floor((Math.min(list[i], list[i + 2]) - reach - L.from) / L.step),
208
- last = Math.floor((Math.max(list[i], list[i + 2]) + reach - L.from) / L.step);
209
- for (let b = Math.max(first, 0); b <= Math.min(last, bins.length - 1); b++) bins[b].push(...list.slice(i, i + SEG));
254
+ first = Math.floor((Math.min(list[i], list[i + 2]) - reach - limbData.from) / limbData.step),
255
+ last = Math.floor((Math.max(list[i], list[i + 2]) + reach - limbData.from) / limbData.step);
256
+ for (let binIndex = Math.max(first, 0); binIndex <= Math.min(last, bins.length - 1); binIndex++) bins[binIndex].push(...list.slice(i, i + SEG));
210
257
  }
211
258
  return bins.map(bin => Float64Array.from(bin));
212
259
  }
@@ -217,7 +264,7 @@ export function createMountainRanges(seed = 0) {
217
264
  // swell it is where it is not broken enough to be one (none: a swell about its own crest).
218
265
  function limb(spec, seed) {
219
266
  const sharp = sstep(RANGE_FROM[0], RANGE_FROM[1], spec.rough),
220
- L = {
267
+ limbData = {
221
268
  ...spec,
222
269
  seed,
223
270
  sharp,
@@ -226,23 +273,23 @@ export function createMountainRanges(seed = 0) {
226
273
  wander: WANDER * spec.b * spec.rough * (spec.face ? SCARP.wander : 1),
227
274
  strayAt: 0.5,
228
275
  };
229
- L.knots = crestKnots(L, clamp(PEAK_SPACING * L.b, PEAK_SPAN[0], PEAK_SPAN[1]));
230
- L.wave = 3 * L.step;
231
- L.warp = WARP[0] * L.b * L.rough * sharp;
232
- L.warpOver = 1 / (WARP[1] * L.step);
233
- L.rib = clamp(0.3 * L.step, RIB_SPAN[0], RIB_SPAN[1]);
276
+ limbData.knots = crestKnots(limbData, clamp(PEAK_SPACING * limbData.b, PEAK_SPAN[0], PEAK_SPAN[1]));
277
+ limbData.wave = 3 * limbData.step;
278
+ limbData.warp = WARP[0] * limbData.b * limbData.rough * sharp;
279
+ limbData.warpOver = 1 / (WARP[1] * limbData.step);
280
+ limbData.rib = clamp(0.3 * limbData.step, RIB_SPAN[0], RIB_SPAN[1]);
234
281
  // the stretch of its frame outside which the range raises nothing, however it is pulled about (by twice its warp at the most)
235
- L.from = -TAIL_REACH * L.tail0 - 2 * L.warp;
236
- L.to = L.len + TAIL_REACH * L.tail1 + 2 * L.warp;
237
- L.far = REACH * L.b * Math.max(1 + LOP, SCARP.back) + Math.abs(L.rim) + 2 * L.wander + 2 * L.warp;
282
+ limbData.from = -TAIL_REACH * limbData.tail0 - 2 * limbData.warp;
283
+ limbData.to = limbData.len + TAIL_REACH * limbData.tail1 + 2 * limbData.warp;
284
+ limbData.far = REACH * limbData.b * Math.max(1 + LOP, SCARP.back) + Math.abs(limbData.rim) + 2 * limbData.wander + 2 * limbData.warp;
238
285
  // a summit stands where the data puts it, the middle of an ellipse or the points of a line: there the crest has not strayed
239
286
  // (crestOffset), nor been pulled about or notched, which `pin` holds for each end of the limb [warp along x, along z, notch]
240
- const mid = L.len / 2,
241
- pinAt = u => [warpAt(L, L.x + u * L.ax, L.z + u * L.az, 0), warpAt(L, L.x + u * L.ax, L.z + u * L.az, 1), notchAt(L, u)];
242
- L.pin = L.line ? [pinAt(0), pinAt(L.len)] : [pinAt(mid), pinAt(mid)];
243
- if (!L.line) L.strayAt = vnoise(mid / L.wave + 7.3, 0, seed);
244
- L.spurs = { 1: limbSpurs(L, 1), [-1]: limbSpurs(L, -1) };
245
- return L;
287
+ const mid = limbData.len / 2,
288
+ pinAt = u => [warpAt(limbData, limbData.x + u * limbData.ax, limbData.z + u * limbData.az, 0), warpAt(limbData, limbData.x + u * limbData.ax, limbData.z + u * limbData.az, 1), notchAt(limbData, u)];
289
+ limbData.pin = limbData.line ? [pinAt(0), pinAt(limbData.len)] : [pinAt(mid), pinAt(mid)];
290
+ if (!limbData.line) limbData.strayAt = vnoise(mid / limbData.wave + 7.3, 0, seed);
291
+ limbData.spurs = { 1: limbSpurs(limbData, 1), [-1]: limbSpurs(limbData, -1) };
292
+ return limbData;
246
293
  }
247
294
 
248
295
  const spurAt = { best: 0, next: 0, tau: 0, phase: 0, side: 0 }; // what spurNear found: the nearest spur's share and the next one's, how far along the nearest, its phase and which side of it
@@ -292,71 +339,75 @@ export function createMountainRanges(seed = 0) {
292
339
  }
293
340
  // Metres a limb's range raises the ground at (x, z), and the swell about its crest where it has no ellipse's (`smooth`: how
294
341
  // far it is that swell).
295
- function rangeHeight(L, x, z, smooth) {
296
- const px = x - L.x,
297
- pz = z - L.z,
298
- along = px * L.ax + pz * L.az;
299
- if (along < L.from || along > L.to || Math.abs(pz * L.ax - px * L.az) > L.far) return 0; // before any noise is worked out
300
- // a range's shape is pulled about, so that no crest, spur or foot is a ruled line; not at its summits (L.pin)
301
- const [from, to] = L.pin,
302
- held = clamp(along / (L.len || 1), 0, 1),
303
- dx = px + L.warp * (warpAt(L, x, z, 0) - lerp(from[0], to[0], held)),
304
- dz = pz + L.warp * (warpAt(L, x, z, 1) - lerp(from[1], to[1], held)),
305
- u = dx * L.ax + dz * L.az;
306
- if (u < -TAIL_REACH * L.tail0 || u > L.len + TAIL_REACH * L.tail1) return 0;
307
- const off = dz * L.ax - dx * L.az - crestOffset(L, u),
342
+ function rangeHeight(limbData, x, z, smooth) {
343
+ const px = x - limbData.x,
344
+ pz = z - limbData.z,
345
+ along = px * limbData.ax + pz * limbData.az;
346
+ if (along < limbData.from || along > limbData.to || Math.abs(pz * limbData.ax - px * limbData.az) > limbData.far) return 0; // before any noise is worked out
347
+ // a range's shape is pulled about, so that no crest, spur or foot is a ruled line; not at its summits (limbData.pin)
348
+ const [from, to] = limbData.pin,
349
+ held = clamp(along / (limbData.len || 1), 0, 1),
350
+ dx = px + limbData.warp * (warpAt(limbData, x, z, 0) - lerp(from[0], to[0], held)),
351
+ dz = pz + limbData.warp * (warpAt(limbData, x, z, 1) - lerp(from[1], to[1], held)),
352
+ u = dx * limbData.ax + dz * limbData.az;
353
+ if (u < -TAIL_REACH * limbData.tail0 || u > limbData.len + TAIL_REACH * limbData.tail1) return 0;
354
+ const off = dz * limbData.ax - dx * limbData.az - crestOffset(limbData, u),
308
355
  side = off < 0 ? -1 : 1,
309
- D = side * off,
310
- E = crestShare(L, u),
311
- crest = L.h * E * knotShare(L, u) * (1 + L.sharp * L.rough * NOTCH * (notchAt(L, u) - lerp(from[2], to[2], held))),
312
- swell = smooth > 0 ? crest * Math.exp(-1.5 * (D / L.b) ** 2) : 0,
313
- wide = flankWidth(L, E, side, u),
314
- s = D / wide;
356
+ flankDistance = side * off,
357
+ crestFraction = crestShare(limbData, u),
358
+ crest = limbData.h * crestFraction * knotShare(limbData, u) * (1 + limbData.sharp * limbData.rough * NOTCH * (notchAt(limbData, u) - lerp(from[2], to[2], held))),
359
+ swell = smooth > 0 ? crest * Math.exp(-1.5 * (flankDistance / limbData.b) ** 2) : 0,
360
+ wide = flankWidth(limbData, crestFraction, side, u),
361
+ s = flankDistance / wide;
315
362
  if (smooth >= 1 || s >= REACH) return swell * smooth;
316
- spurNear(L.spurs[side][clamp(Math.floor((u - L.from) / L.step), 0, L.spurs[side].length - 1)], u, off);
317
- const R = spurAt.best,
318
- scarp = L.face ? (L.face === side ? 1 : -1) : 0,
319
- own = sstep(0, 0.25, R - spurAt.next), // how far the place is one spur's alone: what is its own (its knobs, its gullies) fades out toward the next spur
320
- knobs = 1 - KNOB * own * vnoise(spurAt.tau / L.step + 40 * spurAt.phase, 0, L.seed + 8),
321
- floor = 1 - ((R * R) / (R + 0.15)) * 1.15 * knobs, // how far the place is a valley's floor: a spur's crest is a sharp line, the floor rounded
363
+ spurNear(limbData.spurs[side][clamp(Math.floor((u - limbData.from) / limbData.step), 0, limbData.spurs[side].length - 1)], u, off);
364
+ const spurStrength = spurAt.best,
365
+ scarp = limbData.face ? (limbData.face === side ? 1 : -1) : 0,
366
+ own = sstep(0, 0.25, spurStrength - spurAt.next), // how far the place is one spur's alone: what is its own (its knobs, its gullies) fades out toward the next spur
367
+ knobs = 1 - KNOB * own * vnoise(spurAt.tau / limbData.step + 40 * spurAt.phase, 0, limbData.seed + 8),
368
+ floor = 1 - ((spurStrength * spurStrength) / (spurStrength + 0.15)) * 1.15 * knobs, // how far the place is a valley's floor: a spur's crest is a sharp line, the floor rounded
322
369
  round = CREST_ROUND / wide,
323
- bow = 1 + side * BOW * L.rough * leanAt(L, u, 10),
370
+ bow = 1 + side * BOW * limbData.rough * leanAt(limbData, u, 10),
324
371
  body = flankBody((Math.sqrt(s * s + round * round) - round) / (1 - EMBAYED * floor * sstep(0.1, 0.5, s)), scarp, bow),
325
- deep = L.rough * CUT * sstep(0.02, 0.3, s) * (scarp < 0 ? 0.5 : 1),
326
- sides = L.rough * RIB_CUT * own * (1 - R) * sstep(0.1, 0.35, s),
327
- gully = spurAt.tau / L.rib + spurAt.phase + spurAt.side,
372
+ deep = limbData.rough * CUT * sstep(0.02, 0.3, s) * (scarp < 0 ? 0.5 : 1),
373
+ sides = limbData.rough * RIB_CUT * own * (1 - spurStrength) * sstep(0.1, 0.35, s),
374
+ gully = spurAt.tau / limbData.rib + spurAt.phase + spurAt.side,
328
375
  cut = (1 - deep * floor) * (1 - sides * Math.abs(2 * (gully - Math.floor(gully)) - 1)), // what the valleys and gullies leave of the flank
329
- broken = body > 0 ? 1 + L.rough * CRAG * sstep(0, 0.12, s) * (ridged(x * 0.009, z * 0.009, 4, 331) - 0.45) : 1,
330
- stone = bedded(crest * (1 - APRON) * body * cut * broken, x, z, BEDS.hold * L.rough),
376
+ broken = body > 0 ? 1 + limbData.rough * CRAG * sstep(0, 0.12, s) * (ridged(x * 0.009, z * 0.009, 4, 331) - 0.45) : 1,
377
+ stone = bedded(crest * (1 - APRON) * body * cut * broken, x, z, BEDS.hold * limbData.rough),
331
378
  // the apron is banked highest where a valley comes out onto it, in a fan
332
- apron = crest * APRON * Math.exp(-1.2 * s * s) * (1 + 0.5 * L.rough * (floor - 0.5) * sstep(0.6, 1, s)),
379
+ apron = crest * APRON * Math.exp(-1.2 * s * s) * (1 + 0.5 * limbData.rough * (floor - 0.5) * sstep(0.6, 1, s)),
333
380
  lies = sstep(2, 1.3, s) * Math.max(sstep(0.75, 1.05, s), 0.7 * floor * floor * sstep(0.3, 0.8, s)),
334
- loose = L.sharp * sstep(8, 30, L.h * E) * lies;
381
+ loose = limbData.sharp * sstep(8, 30, limbData.h * crestFraction) * lies;
335
382
  if (loose > range.scree) range.scree = loose;
336
383
  return lerp(stone + apron, swell, smooth);
337
384
  }
338
385
  // Metres a limb raises the ground at (x, z): its range, and where it is not broken enough to be one wholly, its swell.
339
- function limbHeight(L, x, z) {
340
- if (!L.swell) return rangeHeight(L, x, z, 1 - L.sharp);
341
- return (L.sharp < 1 ? (1 - L.sharp) * swellAt(L.swell, x, z) : 0) + (L.sharp > 0 ? L.sharp * rangeHeight(L, x, z, 0) : 0);
386
+ function limbHeight(limbData, x, z) {
387
+ if (!limbData.swell) return rangeHeight(limbData, x, z, 1 - limbData.sharp);
388
+ return (limbData.sharp < 1 ? (1 - limbData.sharp) * swellAt(limbData.swell, x, z) : 0) + (limbData.sharp > 0 ? limbData.sharp * rangeHeight(limbData, x, z, 0) : 0);
342
389
  }
343
390
  // The higher of two limbs of one upland, rounded where they meet.
344
- function joined(a, b) {
345
- const most = Math.max(a, b),
391
+ function joined(firstHeight, secondHeight) {
392
+ const most = Math.max(firstHeight, secondHeight),
346
393
  k = 0.25 * most,
347
- near = k > 0 ? Math.max(k - Math.abs(a - b), 0) / k : 0;
394
+ near = k > 0 ? Math.max(k - Math.abs(firstHeight - secondHeight), 0) / k : 0;
348
395
  return most + (near * near * k) / 4;
349
396
  }
350
- // Metres the uplands laid out raise the ground at (x, z); `range` then says what else was found there.
397
+ /**
398
+ * @param {number} x - World X in metres.
399
+ * @param {number} z - World Z in metres.
400
+ * @returns {number} Added elevation in metres. An empty layout contributes zero.
401
+ */
351
402
  function rangesAt(x, z) {
352
403
  let h = 0;
353
404
  range.scree = 0;
354
405
  crag = -1;
355
406
  for (let i = 0; i < uplands.length; i++) {
356
- const U = uplands[i];
357
- if (x < U.x0 || x > U.x1 || z < U.z0 || z > U.z1) continue;
407
+ const upland = uplands[i];
408
+ if (x < upland.x0 || x > upland.x1 || z < upland.z0 || z > upland.z1) continue;
358
409
  let top = 0;
359
- for (let j = 0; j < U.limbs.length; j++) top = joined(top, limbHeight(U.limbs[j], x, z));
410
+ for (let j = 0; j < upland.limbs.length; j++) top = joined(top, limbHeight(upland.limbs[j], x, z));
360
411
  h += top;
361
412
  }
362
413
  return h;
@@ -371,12 +422,12 @@ export function createMountainRanges(seed = 0) {
371
422
  box.z0 = Math.min(box.z0, z);
372
423
  box.z1 = Math.max(box.z1, z);
373
424
  };
374
- for (const L of limbs) {
375
- for (const u of [L.from, L.to]) for (const v of [-L.far, L.far]) hold(L.x + u * L.ax - v * L.az, L.z + u * L.az + v * L.ax);
376
- if (L.swell) {
425
+ for (const limbData of limbs) {
426
+ for (const u of [limbData.from, limbData.to]) for (const v of [-limbData.far, limbData.far]) hold(limbData.x + u * limbData.ax - v * limbData.az, limbData.z + u * limbData.az + v * limbData.ax);
427
+ if (limbData.swell) {
377
428
  const reach = Math.sqrt(SWELL_REACH + SWELL_WARP / 2);
378
- hold(L.swell.x - reach * L.swell.rx, L.swell.z - reach * L.swell.rz);
379
- hold(L.swell.x + reach * L.swell.rx, L.swell.z + reach * L.swell.rz);
429
+ hold(limbData.swell.x - reach * limbData.swell.rx, limbData.swell.z - reach * limbData.swell.rz);
430
+ hold(limbData.swell.x + reach * limbData.swell.rx, limbData.swell.z + reach * limbData.swell.rz);
380
431
  }
381
432
  }
382
433
  return box;
@@ -385,15 +436,15 @@ export function createMountainRanges(seed = 0) {
385
436
  const faceSide = (face, ax, az) => (face === undefined ? 0 : Math.cos(face) * -az + Math.sin(face) * ax < 0 ? -1 : 1);
386
437
  // An upland given as an ellipse ({ x, z, rx, rz, h, rough }): one limb along its long axis. The more broken it is, the longer
387
438
  // its crest holds its height before it falls away.
388
- function ellipseLimb(m, seed) {
389
- const [bearing, a, b] = ellipseAxis(m),
390
- held = HELD * sstep(RANGE_FROM[0], RANGE_FROM[1], m.rough) * Math.max(a - 0.5 * b, 0.2 * a), // the half-length its crest holds its height over: little of a round one's
391
- tail = a - 0.95 * held,
439
+ function ellipseLimb(landform, seed) {
440
+ const [bearing, halfLength, halfWidth] = ellipseAxis(landform),
441
+ held = HELD * sstep(RANGE_FROM[0], RANGE_FROM[1], landform.rough) * Math.max(halfLength - 0.5 * halfWidth, 0.2 * halfLength), // the half-length its crest holds its height over: little of a round one's
442
+ tail = halfLength - 0.95 * held,
392
443
  ax = Math.cos(bearing),
393
444
  az = Math.sin(bearing),
394
445
  crest = {
395
- x: m.x - held * ax,
396
- z: m.z - held * az,
446
+ x: landform.x - held * ax,
447
+ z: landform.z - held * az,
397
448
  ax,
398
449
  az,
399
450
  len: 2 * held,
@@ -405,58 +456,58 @@ export function createMountainRanges(seed = 0) {
405
456
  free1: true,
406
457
  };
407
458
  return limb(
408
- { ...crest, b, h: m.h, rough: m.rough, face: faceSide(m.face, ax, az), line: false, swell: m.axis === undefined ? m : null },
459
+ { ...crest, b: halfWidth, h: landform.h, rough: landform.rough, face: faceSide(landform.face, ax, az), line: false, swell: landform.axis === undefined ? landform : null },
409
460
  seed,
410
461
  );
411
462
  }
412
463
  // An upland given as a line ({ crest: [[x, z, share of h], ...], wide, h, rough }): a limb to each stretch, each running on a
413
464
  // little past the point where the next begins.
414
- function lineLimbs(m, seed) {
465
+ function lineLimbs(landform, seed) {
415
466
  const limbs = [],
416
- tail = end => m.wide * (end ? 0.65 : 0.7);
417
- for (let i = 0; i + 1 < m.crest.length; i++) {
418
- const [x, z, k0] = m.crest[i],
419
- [x1, z1, k1] = m.crest[i + 1],
467
+ tail = end => landform.wide * (end ? 0.65 : 0.7);
468
+ for (let i = 0; i + 1 < landform.crest.length; i++) {
469
+ const [x, z, k0] = landform.crest[i],
470
+ [x1, z1, k1] = landform.crest[i + 1],
420
471
  len = Math.hypot(x1 - x, z1 - z),
421
472
  ax = (x1 - x) / len,
422
473
  az = (z1 - z) / len,
423
474
  first = i === 0,
424
- last = i + 2 === m.crest.length,
475
+ last = i + 2 === landform.crest.length,
425
476
  crest = { x, z, ax, az, len, tail0: tail(first), tail1: tail(last), k0, k1, free0: first, free1: last };
426
477
  limbs.push(
427
- limb({ ...crest, b: m.wide, h: m.h, rough: m.rough, face: faceSide(m.face, ax, az), line: true, swell: null }, seed + i * 3),
478
+ limb({ ...crest, b: landform.wide, h: landform.h, rough: landform.rough, face: faceSide(landform.face, ax, az), line: true, swell: null }, seed + i * 3),
428
479
  );
429
480
  }
430
481
  return limbs;
431
482
  }
432
483
  // A field of hills ({ x, z, rx, rz, h, rough, hills: how many }): small ranges scattered over its ellipse, their crests near one
433
484
  // strike (`axis`, or the ellipse's long axis), on a low swell.
434
- function hillField(m, seed) {
435
- const [strike, , lesser] = ellipseAxis(m),
485
+ function hillField(landform, seed) {
486
+ const [strike, , lesser] = ellipseAxis(landform),
436
487
  r = (i, n) => hash2(i, n, seed + 2),
437
- out = [boxed([ellipseLimb({ ...m, h: m.h * HILL.base, rough: 0, axis: undefined }, seed)])];
438
- for (let i = 0; i < m.hills; i++) {
439
- const far = 0.85 * Math.sqrt((i + 0.5) / m.hills),
488
+ out = [boxed([ellipseLimb({ ...landform, h: landform.h * HILL.base, rough: 0, axis: undefined }, seed)])];
489
+ for (let i = 0; i < landform.hills; i++) {
490
+ const far = 0.85 * Math.sqrt((i + 0.5) / landform.hills),
440
491
  round = i * 2.39996 + r(i, 1), // the golden angle from one to the next, so they fill the ellipse evenly
441
492
  long = lesser * lerp(HILL.long[0], HILL.long[1], r(i, 2)),
442
493
  hill = {
443
- x: m.x + m.rx * far * Math.cos(round),
444
- z: m.z + m.rz * far * Math.sin(round),
494
+ x: landform.x + landform.rx * far * Math.cos(round),
495
+ z: landform.z + landform.rz * far * Math.sin(round),
445
496
  rx: long,
446
497
  rz: long * lerp(HILL.wide[0], HILL.wide[1], r(i, 3)),
447
- h: m.h * lerp(HILL.high[0], HILL.high[1], r(i, 4)) * (1 - 0.4 * far * far),
448
- rough: m.rough,
498
+ h: landform.h * lerp(HILL.high[0], HILL.high[1], r(i, 4)) * (1 - 0.4 * far * far),
499
+ rough: landform.rough,
449
500
  axis: strike + (r(i, 5) - 0.5) * HILL.turn,
450
501
  };
451
502
  out.push(boxed([ellipseLimb(hill, seed + 10 + i * 3)]));
452
503
  }
453
504
  return out;
454
505
  }
455
- // Lays out a land's uplands (its data's list), for rangesAt.
506
+ /** @param {(EllipticalUpland | Ridge)[]} list - Landforms in stable seed order. */
456
507
  function layOutRanges(list) {
457
- uplands = list.flatMap((m, i) => {
508
+ uplands = list.flatMap((landform, i) => {
458
509
  const seed = 400 + i * 41;
459
- return m.hills ? hillField(m, seed) : [boxed(m.crest ? lineLimbs(m, seed) : [ellipseLimb(m, seed)])];
510
+ return landform.hills ? hillField(landform, seed) : [boxed(landform.crest ? lineLimbs(landform, seed) : [ellipseLimb(landform, seed)])];
460
511
  });
461
512
  }
462
513
  return { layout: layOutRanges, heightAt: rangesAt, surface: range };