@adatechnology/game-interactables 0.8.0 → 0.10.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/README.md CHANGED
@@ -191,6 +191,20 @@ the hand holds goes in when the access is open and it fits the inside, `fitsInVo
191
191
  and `relieve` (a basin soiled, washed by the flush whose fixture `cleans` it). `state()` says what to draw (screens on and their channel, bowl levels, soil,
192
192
  fires); `createControlsView` of game-interactables-three draws it.
193
193
 
194
+ ## Wires strung between two points (`solveSpan`)
195
+
196
+ A wire with a `span` (`ObjectSpec.wires[].span`: the conductor's material and the section that carries the pull) is strung between two points: the drop of a
197
+ service entrance runs from the pole's head to the house. `solveSpan({ span, from, to, ground?, clearance? })` gives the shape it takes between where its ends
198
+ are now, the catenary of its strung length (`polylineLength` of its points), lying on the ground where it would hang lower, and the pull at its ends. Pulled
199
+ straight past its length it stretches as its material does (E·A·strain, `elasticGPa`), and past `ultimateMPa` it snaps at the end that pulls the harder
200
+ (`snaps`; `spanStrength` is its breaking pull). The material numbers are those of game-destruction (`MaterialDef.tension`, `density`). The ends are where the
201
+ host says: a wire never holds back a falling pole, since what it takes in before it snaps is a few joules. `hangTail` gives what is left hanging from one end
202
+ after it snapped. `createSpanWire` of game-interactables-three draws it.
203
+
204
+ A wire fixed along what it runs on (a conduit strapped up a pole, an earth cable clipped down it) is laid with `wireRuns({ points, step, holderOf })`: the
205
+ runs of the wire by the part under each stretch of it, two runs that follow each other sharing the point at the seam. Whole they read as one wire; when the
206
+ parts come apart each run goes with its own and the wire is broken at the seam.
207
+
194
208
  ## Português
195
209
 
196
210
  Runtime sem renderer para objetos interativos do mundo: portas, gavetas e tampas que se movem, recipientes com itens e loot determinístico por
package/dist/index.d.ts CHANGED
@@ -492,6 +492,11 @@ type Action = {
492
492
  circuit: string;
493
493
  part?: string;
494
494
  name?: string;
495
+ }
496
+ /** Flips the building's main breaker (the service entrance's, after the meter: `World.power.setMain`): off, nothing of the building has power. `part` is a rocker that mirrors it (t = 1 when on), refused while gated (a closed meter box door). */
497
+ | {
498
+ do: 'toggle_main';
499
+ part?: string;
495
500
  } | {
496
501
  do: 'toggle_fixture';
497
502
  fixture: string;
@@ -567,6 +572,14 @@ interface ObjectSpec {
567
572
  kind: 'drop' | 'conduit' | 'cord' | 'cable';
568
573
  points: Vec3[];
569
574
  radius?: number;
575
+ /**
576
+ * A wire strung between two points (a drop from a pole to a house): it hangs as a span of its strung length (`solveSpan`) between where its ends are, and snaps
577
+ * past its material's strength. `material`: the conductor's (a game-destruction material with `tension`); `section`: the cross-section that carries the pull, m².
578
+ */
579
+ span?: {
580
+ material: string;
581
+ section: number;
582
+ };
570
583
  }>;
571
584
  }
572
585
  type InteractablesLocale = 'en' | 'pt-BR';
@@ -695,6 +708,7 @@ type WorldEvent = {
695
708
  } | {
696
709
  type: 'power';
697
710
  grid: boolean;
711
+ main: boolean;
698
712
  }
699
713
  /** A container without an access part was opened (open shelf): the host may show its contents. */
700
714
  | {
@@ -835,6 +849,9 @@ interface World {
835
849
  power: {
836
850
  grid: boolean;
837
851
  setGrid(on: boolean): void;
852
+ /** The building's main breaker (the service entrance's, after the meter): off, no device of the building is powered whatever the grid and the circuits. Default on. */
853
+ readonly main: boolean;
854
+ setMain(on: boolean): void;
838
855
  setBreaker(circuit: string, on: boolean): void;
839
856
  breaker(circuit: string): boolean;
840
857
  isPowered(objectId: string, deviceId: string): boolean;
@@ -919,6 +936,8 @@ interface WorldState {
919
936
  hp: Record<string, number>;
920
937
  }>;
921
938
  grid: boolean;
939
+ /** The main breaker (`World.power.main`); absent in a state saved before it existed, read as on. */
940
+ main?: boolean;
922
941
  breakers: Record<string, boolean>;
923
942
  seats: Record<string, {
924
943
  object: string;
@@ -1062,6 +1081,79 @@ declare function disposeChain(world: SeamWorld, chain: Chain): void;
1062
1081
  /** The two ends of every link now, as a polyline (x, y, z per point) for a host that draws the cord: the points a chain was built from, moved. */
1063
1082
  declare function chainPoints(world: SeamWorld, chain: Chain, out: Float64Array): void;
1064
1083
 
1084
+ /** What a span is made of, in real units (`MaterialDef.tension` and `density` of game-destruction). */
1085
+ type SpanMaterial = {
1086
+ /** kg/m³ of the conductor. */
1087
+ readonly density: number;
1088
+ /** Modulus of elasticity, GPa. */
1089
+ readonly elasticGPa: number;
1090
+ /** Ultimate tensile strength, MPa. */
1091
+ readonly ultimateMPa: number;
1092
+ };
1093
+ /** A wire strung between two points. */
1094
+ type Span = {
1095
+ /** Length of the wire as it was strung, metres. */
1096
+ readonly length: number;
1097
+ /** Cross-section that carries the pull, m² (the conductors, not the insulation). */
1098
+ readonly section: number;
1099
+ readonly material: SpanMaterial;
1100
+ };
1101
+ /** Where a span's ends are and how it is drawn. */
1102
+ type SolveSpanParams = {
1103
+ readonly span: Span;
1104
+ readonly from: Vec3;
1105
+ readonly to: Vec3;
1106
+ /** Points along the wire, both ends included (default 16). */
1107
+ readonly segments?: number;
1108
+ /** Height of the ground under a point (x, z): the wire lies on it where it would hang lower. */
1109
+ readonly ground?: (x: number, z: number) => number;
1110
+ /** How far above the ground the wire's axis lies (its radius). */
1111
+ readonly clearance?: number;
1112
+ };
1113
+ /** The shape a span takes and the pull at its ends. */
1114
+ type SpanShape = {
1115
+ readonly points: Vec3[];
1116
+ /** The larger pull at an end, newtons. */
1117
+ readonly tension: number;
1118
+ /** Pulled straight past its strung length. */
1119
+ readonly taut: boolean;
1120
+ /** The end where the stress passed the material's strength, else null. */
1121
+ readonly snaps: 'from' | 'to' | null;
1122
+ };
1123
+ /** Length of a polyline. */
1124
+ declare function polylineLength(points: readonly Vec3[]): number;
1125
+ /** The breaking pull of a span, newtons. */
1126
+ declare function spanStrength(span: Span): number;
1127
+ /** The shape of a span between its ends now, the pull at its ends and whether it snaps (at the end that pulls the harder). */
1128
+ declare function solveSpan(params: SolveSpanParams): SpanShape;
1129
+ /** A wire hung by one end, the other loose: what a snapped span leaves on the end that held. */
1130
+ type HangTailParams = {
1131
+ readonly anchor: Vec3;
1132
+ readonly length: number;
1133
+ /** The way the loose end lies along the ground (horizontal; default +x). */
1134
+ readonly toward?: Vec3;
1135
+ readonly segments?: number;
1136
+ readonly ground?: (x: number, z: number) => number;
1137
+ readonly clearance?: number;
1138
+ };
1139
+ /** Straight down from its anchor to the ground, and the rest of its length lying along the ground toward `toward`. */
1140
+ declare function hangTail(params: HangTailParams): Vec3[];
1141
+
1142
+ /** One stretch of a wire and what holds it. */
1143
+ type WireRun<THolder> = {
1144
+ readonly holder: THolder;
1145
+ readonly points: Vec3[];
1146
+ };
1147
+ type WireRunsParams<THolder> = {
1148
+ readonly points: readonly Vec3[];
1149
+ /** Longest step (metres) between two points the holder is read at: where the holder changes is found within it. */
1150
+ readonly step: number;
1151
+ /** What holds the wire at a point (the part it is fixed on there). */
1152
+ readonly holderOf: (point: Vec3) => THolder;
1153
+ };
1154
+ /** The runs of a wire by what holds it, in order along it; two runs that follow each other share the point half way between their last and first readings. */
1155
+ declare function wireRuns<THolder>(params: WireRunsParams<THolder>): WireRun<THolder>[];
1156
+
1065
1157
  /**
1066
1158
  * What an object does with the player's hand or on its own time (`ObjectSpec.uses`), for `createObjectControls`: a device's program that runs for its seconds, what
1067
1159
  * the hand holds put inside when it fits, a container emptied, a bowl filled from the hand, a basin soiled and washed by its flush. The rules are the data's: the
@@ -1120,4 +1212,4 @@ declare function createObjectControls(options: ObjectControlsOptions): ObjectCon
1120
1212
  /** Whether a thing of `size` (any turn of it) goes into a box of `half` sizes: each of its sides, longest first, against the box's, longest first. */
1121
1213
  declare function fitsInVolume(size: readonly [number, number, number], half: Vec3): boolean;
1122
1214
 
1123
- export { type Action, type ActiveEmitter, type BasinSpec, type BowlSpec, type BurnerSpec, CONTROLLED_OBJECT, type Chain, type ChainSpec, type ColliderOptions, type ColliderSpec, type ContainerSpec, type DamageKind, type DamageSpec, type DestructionDelegate, type DestructionJoint, type DeviceKind, type DeviceSpec, type EmitterBowl, type EmitterKind, type EmitterSpec, type EnginePartDriver, type EnginePartOptions, type EnginePartPhysics, FLUSH_RUN_SECONDS, type FixtureEmitters, type FixtureKind, type FixtureSpec, type FuelSourceSpec, type Interactable, type InteractablesLocale, type InteractionSpec, type ItemCatalog, type ItemDef, type ItemStack, type LootEntry, type LootTable, type LootTables, type MirrorSpec, type Motion, type MotionKind, type ObjectControls, type ObjectControlsOptions, type ObjectControlsState, type ObjectSpec, type PartDestruction, type PartDriver, type PartPhysics, type PartSpec, type Pose, type Rect, type RunningEmitter, type SeatPose, type SeatResult, type SeatSpec, type SlotSpec, type SocketSpec, type SoftDriver, type SoftSpec, type Soil, type Strings, type SwitchSpec, type TankSpec, type TargetOptions, type Transform, type UseSpec, type UsesState, type Vec3, type World, type WorldCollider, type WorldEvent, type WorldObject, type WorldOptions, type WorldState, alignY, buildChain, chainPoints, createEnginePartPhysics, createFixtureEmitters, createObjectControls, createWorld, disposeChain, fitsInVolume, fitsSize, fitsSlot, format, generateLoot, hashString, localToWorld, locales, mergeColliders, pickLocale, poseOf, resolveStrings, rng, rotY, rotateAxis, worldToLocal };
1215
+ export { type Action, type ActiveEmitter, type BasinSpec, type BowlSpec, type BurnerSpec, CONTROLLED_OBJECT, type Chain, type ChainSpec, type ColliderOptions, type ColliderSpec, type ContainerSpec, type DamageKind, type DamageSpec, type DestructionDelegate, type DestructionJoint, type DeviceKind, type DeviceSpec, type EmitterBowl, type EmitterKind, type EmitterSpec, type EnginePartDriver, type EnginePartOptions, type EnginePartPhysics, FLUSH_RUN_SECONDS, type FixtureEmitters, type FixtureKind, type FixtureSpec, type FuelSourceSpec, type HangTailParams, type Interactable, type InteractablesLocale, type InteractionSpec, type ItemCatalog, type ItemDef, type ItemStack, type LootEntry, type LootTable, type LootTables, type MirrorSpec, type Motion, type MotionKind, type ObjectControls, type ObjectControlsOptions, type ObjectControlsState, type ObjectSpec, type PartDestruction, type PartDriver, type PartPhysics, type PartSpec, type Pose, type Rect, type RunningEmitter, type SeatPose, type SeatResult, type SeatSpec, type SlotSpec, type SocketSpec, type SoftDriver, type SoftSpec, type Soil, type SolveSpanParams, type Span, type SpanMaterial, type SpanShape, type Strings, type SwitchSpec, type TankSpec, type TargetOptions, type Transform, type UseSpec, type UsesState, type Vec3, type WireRun, type WireRunsParams, type World, type WorldCollider, type WorldEvent, type WorldObject, type WorldOptions, type WorldState, alignY, buildChain, chainPoints, createEnginePartPhysics, createFixtureEmitters, createObjectControls, createWorld, disposeChain, fitsInVolume, fitsSize, fitsSlot, format, generateLoot, hangTail, hashString, localToWorld, locales, mergeColliders, pickLocale, polylineLength, poseOf, resolveStrings, rng, rotY, rotateAxis, solveSpan, spanStrength, wireRuns, worldToLocal };
@@ -36,16 +36,21 @@ var GameInteractables = (() => {
36
36
  fitsSlot: () => fitsSlot,
37
37
  format: () => format,
38
38
  generateLoot: () => generateLoot,
39
+ hangTail: () => hangTail,
39
40
  hashString: () => hashString,
40
41
  localToWorld: () => localToWorld,
41
42
  locales: () => locales,
42
43
  mergeColliders: () => mergeColliders,
43
44
  pickLocale: () => pickLocale,
45
+ polylineLength: () => polylineLength,
44
46
  poseOf: () => poseOf,
45
47
  resolveStrings: () => resolveStrings,
46
48
  rng: () => rng,
47
49
  rotY: () => rotY,
48
50
  rotateAxis: () => rotateAxis,
51
+ solveSpan: () => solveSpan,
52
+ spanStrength: () => spanStrength,
53
+ wireRuns: () => wireRuns,
49
54
  worldToLocal: () => worldToLocal
50
55
  });
51
56
 
@@ -234,6 +239,8 @@ var GameInteractables = (() => {
234
239
  "prompt.read": "Read",
235
240
  "prompt.breaker_on": "Switch on {circuit}",
236
241
  "prompt.breaker_off": "Switch off {circuit}",
242
+ "prompt.main_on": "Switch on the main breaker",
243
+ "prompt.main_off": "Switch off the main breaker",
237
244
  "prompt.open_valve": "Open valve",
238
245
  "prompt.close_valve": "Close valve",
239
246
  no_power: "No power",
@@ -285,6 +292,8 @@ var GameInteractables = (() => {
285
292
  "prompt.read": "Ler",
286
293
  "prompt.breaker_on": "Ligar {circuit}",
287
294
  "prompt.breaker_off": "Desligar {circuit}",
295
+ "prompt.main_on": "Ligar o disjuntor geral",
296
+ "prompt.main_off": "Desligar o disjuntor geral",
288
297
  "prompt.open_valve": "Abrir registro",
289
298
  "prompt.close_valve": "Fechar registro",
290
299
  no_power: "Sem energia",
@@ -420,6 +429,7 @@ var GameInteractables = (() => {
420
429
  let locale = options.locale ?? "en";
421
430
  let table = resolveStrings(locale, options.strings);
422
431
  let grid = options.grid ?? true;
432
+ let main = true;
423
433
  let rain = options.rain ?? 0;
424
434
  let wind = options.wind ? [options.wind[0], options.wind[1]] : [0, 0];
425
435
  let defaultTank = null;
@@ -768,7 +778,7 @@ var GameInteractables = (() => {
768
778
  }
769
779
  function devicePowered(o, d) {
770
780
  if (d.spec.electric === false) return true;
771
- if (!grid) return false;
781
+ if (!grid || !main) return false;
772
782
  if (d.spec.circuit) return breaker(d.spec.circuit);
773
783
  if (d.spec.socket === void 0) return false;
774
784
  const sid = plugs.get(gid(o, d.spec.id));
@@ -1236,6 +1246,11 @@ var GameInteractables = (() => {
1236
1246
  def = on ? "prompt.breaker_off" : "prompt.breaker_on";
1237
1247
  break;
1238
1248
  }
1249
+ case "toggle_main": {
1250
+ state = main ? "on" : "off";
1251
+ def = main ? "prompt.main_off" : "prompt.main_on";
1252
+ break;
1253
+ }
1239
1254
  case "toggle_fixture": {
1240
1255
  const on = !!o.fixtures.get(a.fixture)?.on;
1241
1256
  state = on ? "on" : "off";
@@ -1307,7 +1322,8 @@ var GameInteractables = (() => {
1307
1322
  const p = c?.access ? o.parts.get(c.access) : void 0;
1308
1323
  return p && gated(o, p) ? "requires_open" : null;
1309
1324
  }
1310
- case "toggle_breaker": {
1325
+ case "toggle_breaker":
1326
+ case "toggle_main": {
1311
1327
  const rocker = a.part ? o.parts.get(a.part) : void 0;
1312
1328
  return rocker && gated(o, rocker) ? "requires_open" : null;
1313
1329
  }
@@ -1515,6 +1531,14 @@ var GameInteractables = (() => {
1515
1531
  world.power.setBreaker(a.circuit, on);
1516
1532
  return true;
1517
1533
  }
1534
+ case "toggle_main": {
1535
+ const rocker = a.part ? o.parts.get(a.part) : void 0;
1536
+ if (rocker && gated(o, rocker)) return false;
1537
+ const on = !main;
1538
+ if (a.part) setPartTarget(o, a.part, on ? 1 : 0);
1539
+ world.power.setMain(on);
1540
+ return true;
1541
+ }
1518
1542
  case "toggle_fixture":
1519
1543
  return toggleFixture(o, a.fixture);
1520
1544
  case "toggle_burner":
@@ -1782,6 +1806,7 @@ var GameInteractables = (() => {
1782
1806
  version: 1,
1783
1807
  objects,
1784
1808
  grid,
1809
+ main,
1785
1810
  breakers: Object.fromEntries(breakers),
1786
1811
  seats: Object.fromEntries([...seats].map(([a, s]) => [a, { object: s.object, seat: s.seat }])),
1787
1812
  defaultTank
@@ -1842,6 +1867,7 @@ var GameInteractables = (() => {
1842
1867
  }
1843
1868
  }
1844
1869
  grid = state.grid;
1870
+ main = state.main ?? true;
1845
1871
  breakers.clear();
1846
1872
  for (const [k, v] of Object.entries(state.breakers)) breakers.set(k, v);
1847
1873
  seats.clear();
@@ -1883,7 +1909,17 @@ var GameInteractables = (() => {
1883
1909
  if (on === grid) return;
1884
1910
  const before = powerSnapshot();
1885
1911
  grid = on;
1886
- emit({ type: "power", grid });
1912
+ emit({ type: "power", grid, main });
1913
+ emitPowerChanges(before);
1914
+ },
1915
+ get main() {
1916
+ return main;
1917
+ },
1918
+ setMain(on) {
1919
+ if (on === main) return;
1920
+ const before = powerSnapshot();
1921
+ main = on;
1922
+ emit({ type: "power", grid, main });
1887
1923
  emitPowerChanges(before);
1888
1924
  },
1889
1925
  setBreaker(circuit, on) {
@@ -2336,6 +2372,124 @@ var GameInteractables = (() => {
2336
2372
  return createLeafDriver({ world, leaf, frame, ownsFrame, joint, onDispose: request.onDispose, drive: { isHinge, axis, pivot, centre, range, speed, base: rotation } });
2337
2373
  }
2338
2374
 
2375
+ // src/span.ts
2376
+ var GRAVITY = 9.81;
2377
+ var SHAPE_STEPS = 60;
2378
+ var VERTICAL_SPAN = 1e-4;
2379
+ function polylineLength(points) {
2380
+ let length2 = 0;
2381
+ for (let i = 1; i < points.length; i++) length2 += Math.hypot(points[i][0] - points[i - 1][0], points[i][1] - points[i - 1][1], points[i][2] - points[i - 1][2]);
2382
+ return length2;
2383
+ }
2384
+ function shapeOf(ratio) {
2385
+ let low = 1e-9;
2386
+ let high = 1;
2387
+ while (Math.sinh(high) / high < ratio && high < 700) high *= 2;
2388
+ for (let i = 0; i < SHAPE_STEPS; i++) {
2389
+ const mid = (low + high) / 2;
2390
+ if (Math.sinh(mid) / mid < ratio) low = mid;
2391
+ else high = mid;
2392
+ }
2393
+ return (low + high) / 2;
2394
+ }
2395
+ function spanStrength(span) {
2396
+ return span.material.ultimateMPa * 1e6 * span.section;
2397
+ }
2398
+ function straight(params, count, weight, chord) {
2399
+ const { span, from, to } = params;
2400
+ const pull = span.material.elasticGPa * 1e9 * span.section * ((chord - span.length) / span.length);
2401
+ const rise = to[1] - from[1];
2402
+ const points = Array.from({ length: count }, (_, i) => {
2403
+ const t = i / (count - 1);
2404
+ return [from[0] + (to[0] - from[0]) * t, from[1] + rise * t, from[2] + (to[2] - from[2]) * t];
2405
+ });
2406
+ return { points, pullFrom: pull + weight * (span.length - rise) / 2, pullTo: pull + weight * (span.length + rise) / 2 };
2407
+ }
2408
+ function loop(params, count, weight) {
2409
+ const { span, from, to } = params;
2410
+ const bottom = (from[1] + to[1] - span.length) / 2;
2411
+ const down = from[1] - bottom;
2412
+ const points = Array.from({ length: count }, (_, i) => {
2413
+ const s = i / (count - 1) * span.length;
2414
+ return s <= down ? [from[0], from[1] - s, from[2]] : [to[0], bottom + (s - down), to[2]];
2415
+ });
2416
+ return { points, pullFrom: weight * down, pullTo: weight * (to[1] - bottom) };
2417
+ }
2418
+ function hanging(params, count, weight, across) {
2419
+ const { span, from, to } = params;
2420
+ const rise = to[1] - from[1];
2421
+ const c = across / (2 * shapeOf(Math.sqrt(span.length * span.length - rise * rise) / across));
2422
+ const x0 = across / 2 - c * Math.atanh(rise / span.length);
2423
+ const base = Math.cosh(-x0 / c);
2424
+ const points = Array.from({ length: count }, (_, i) => {
2425
+ const t = i / (count - 1);
2426
+ return [from[0] + (to[0] - from[0]) * t, from[1] + c * (Math.cosh((across * t - x0) / c) - base), from[2] + (to[2] - from[2]) * t];
2427
+ });
2428
+ return { points, pullFrom: weight * c * base, pullTo: weight * c * Math.cosh((across - x0) / c) };
2429
+ }
2430
+ function solveSpan(params) {
2431
+ const { span, from, to } = params;
2432
+ const count = Math.max(2, Math.floor(params.segments ?? 16));
2433
+ const weight = span.material.density * span.section * GRAVITY;
2434
+ const across = Math.hypot(to[0] - from[0], to[2] - from[2]);
2435
+ const chord = Math.hypot(across, to[1] - from[1]);
2436
+ const taut = chord >= span.length;
2437
+ const shape = taut ? straight(params, count, weight, chord) : across < VERTICAL_SPAN ? loop(params, count, weight) : hanging(params, count, weight, across);
2438
+ const ground = params.ground;
2439
+ if (ground) for (const p of shape.points) p[1] = Math.max(p[1], ground(p[0], p[2]) + (params.clearance ?? 0));
2440
+ const tension = Math.max(shape.pullFrom, shape.pullTo);
2441
+ const snaps = tension > spanStrength(span) ? shape.pullFrom >= shape.pullTo ? "from" : "to" : null;
2442
+ return { points: shape.points, tension, taut, snaps };
2443
+ }
2444
+ function hangTail(params) {
2445
+ const { anchor, length: length2 } = params;
2446
+ const count = Math.max(2, Math.floor(params.segments ?? 16));
2447
+ const clearance = params.clearance ?? 0;
2448
+ const floorAt = (x, z) => params.ground ? params.ground(x, z) + clearance : -Infinity;
2449
+ const drop = Math.max(0, Math.min(length2, anchor[1] - floorAt(anchor[0], anchor[2])));
2450
+ const toward = params.toward ?? [1, 0, 0];
2451
+ const flat = Math.hypot(toward[0], toward[2]) || 1;
2452
+ return Array.from({ length: count }, (_, i) => {
2453
+ const s = i / (count - 1) * length2;
2454
+ if (s <= drop) return [anchor[0], anchor[1] - s, anchor[2]];
2455
+ const x = anchor[0] + toward[0] / flat * (s - drop);
2456
+ const z = anchor[2] + toward[2] / flat * (s - drop);
2457
+ return [x, Math.max(anchor[1] - drop, floorAt(x, z)), z];
2458
+ });
2459
+ }
2460
+
2461
+ // src/wire-runs.ts
2462
+ var lerp = (a, b, t) => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];
2463
+ function along(points, step) {
2464
+ const out = points.length ? [[...points[0]]] : [];
2465
+ for (let i = 1; i < points.length; i++) {
2466
+ const a = points[i - 1];
2467
+ const b = points[i];
2468
+ const steps = Math.max(1, Math.ceil(Math.hypot(b[0] - a[0], b[1] - a[1], b[2] - a[2]) / step));
2469
+ for (let k = 1; k <= steps; k++) out.push(lerp(a, b, k / steps));
2470
+ }
2471
+ return out;
2472
+ }
2473
+ function wireRuns(params) {
2474
+ const points = along(params.points, Math.max(1e-3, params.step));
2475
+ if (points.length < 2) return [];
2476
+ const holders = points.map((p) => params.holderOf(p));
2477
+ const runs = [];
2478
+ let current = { holder: holders[0], points: [points[0]] };
2479
+ for (let i = 1; i < points.length; i++) {
2480
+ if (holders[i] === current.holder) {
2481
+ current.points.push(points[i]);
2482
+ continue;
2483
+ }
2484
+ const seam = lerp(points[i - 1], points[i], 0.5);
2485
+ current.points.push(seam);
2486
+ runs.push(current);
2487
+ current = { holder: holders[i], points: [[...seam], points[i]] };
2488
+ }
2489
+ runs.push(current);
2490
+ return runs;
2491
+ }
2492
+
2339
2493
  // src/fits-volume.ts
2340
2494
  function fitsInVolume(size, half) {
2341
2495
  const thing = [...size].sort((a, b) => b - a);