@rulecad/cad 0.7.97 → 0.9.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.
Files changed (86) hide show
  1. package/AGENTS.md +26 -10
  2. package/CHANGELOG.md +442 -2
  3. package/EXAMPLES.md +48 -42
  4. package/README.md +226 -73
  5. package/TUTORIAL.md +2 -2
  6. package/bin/cad.mjs +2253 -514
  7. package/lib/animate.mjs +173 -49
  8. package/lib/assembly.mjs +1854 -437
  9. package/lib/beams.mjs +256 -52
  10. package/lib/belts.mjs +66 -15
  11. package/lib/board-work.mjs +12 -0
  12. package/lib/bought.mjs +309 -53
  13. package/lib/buildpage.mjs +179 -29
  14. package/lib/carried.mjs +201 -0
  15. package/lib/clone.mjs +194 -42
  16. package/lib/design.mjs +734 -113
  17. package/lib/drive.mjs +187 -63
  18. package/lib/edit.mjs +900 -191
  19. package/lib/errors.mjs +16 -3
  20. package/lib/explain.mjs +62 -13
  21. package/lib/fasten.mjs +2710 -502
  22. package/lib/fittings.mjs +715 -121
  23. package/lib/fixings.mjs +21 -9
  24. package/lib/framebuild.mjs +792 -176
  25. package/lib/framecheck.mjs +1901 -368
  26. package/lib/framegen.mjs +100 -22
  27. package/lib/frameheat.mjs +225 -42
  28. package/lib/frameprint.mjs +513 -108
  29. package/lib/frames.mjs +81 -17
  30. package/lib/framesize.mjs +792 -120
  31. package/lib/frametip.mjs +235 -0
  32. package/lib/gait.mjs +135 -23
  33. package/lib/grip.mjs +62 -13
  34. package/lib/guides.mjs +1403 -230
  35. package/lib/host.mjs +149 -18
  36. package/lib/inplace.mjs +171 -36
  37. package/lib/jigs.mjs +360 -78
  38. package/lib/joins.mjs +697 -118
  39. package/lib/jsonedit.mjs +88 -26
  40. package/lib/kept.mjs +84 -0
  41. package/lib/kit.mjs +438 -68
  42. package/lib/layout.mjs +3 -1
  43. package/lib/links.mjs +149 -42
  44. package/lib/list.mjs +326 -64
  45. package/lib/live-guard.mjs +68 -0
  46. package/lib/live-shape.mjs +96 -24
  47. package/lib/live.mjs +189 -59
  48. package/lib/loads.mjs +579 -130
  49. package/lib/machine.mjs +372 -74
  50. package/lib/magnets.mjs +162 -44
  51. package/lib/measured.mjs +417 -94
  52. package/lib/mesh.mjs +526 -119
  53. package/lib/meshcmd.mjs +215 -60
  54. package/lib/motors.mjs +1022 -212
  55. package/lib/motorsvg.mjs +114 -32
  56. package/lib/names.mjs +41 -0
  57. package/lib/optimise.mjs +979 -283
  58. package/lib/order.mjs +519 -112
  59. package/lib/panels.mjs +482 -94
  60. package/lib/parts.mjs +78 -23
  61. package/lib/pins.mjs +163 -44
  62. package/lib/plates.mjs +224 -36
  63. package/lib/player.mjs +37 -9
  64. package/lib/power.mjs +64 -13
  65. package/lib/preview.mjs +83 -16
  66. package/lib/profilemeasure.mjs +572 -129
  67. package/lib/rules.mjs +38 -4
  68. package/lib/sandbox-hooks.mjs +154 -12
  69. package/lib/sandbox-preload.mjs +2 -2
  70. package/lib/sandbox-run.mjs +127 -12
  71. package/lib/sandbox.mjs +632 -35
  72. package/lib/schema.mjs +43 -11
  73. package/lib/seats.mjs +227 -49
  74. package/lib/services.mjs +261 -52
  75. package/lib/sheet.mjs +851 -178
  76. package/lib/slotnuts.mjs +213 -34
  77. package/lib/targets/gist.mjs +4 -1
  78. package/lib/targets.mjs +42 -6
  79. package/lib/task.mjs +376 -79
  80. package/lib/versions.mjs +113 -28
  81. package/lib/wires.mjs +228 -45
  82. package/lib/workspace.mjs +216 -17
  83. package/package.json +19 -19
  84. package/schemas/assembly.schema.json +2 -2
  85. package/schemas/object.schema.json +1 -1
  86. package/schemas/project.schema.json +1 -1
package/lib/joins.mjs CHANGED
@@ -5,30 +5,62 @@
5
5
  // fasten's are. Once built, the checks: join.geometry (the end meets the face square and flush, where the join says,
6
6
  // on a slot where the kind needs one), join.end (every beam end is joined or capped), join.stiffness (each join's
7
7
  // spring for a frame's solve, saying whether it was measured on the joint rig, and when, or is an estimate),
8
- // join.fitting (a kind whose fitting comes later), and join.drop (a beam held by one join with a mass on it, as on the
9
- // joint rig: its drop, a prediction cad measured turns into the join's spring).
8
+ // join.fitting (a kind whose fitting comes later), and join.drop (a beam held by one join and nothing else, a mass on it:
9
+ // its drop, from the frame's own solve or on the joint rig, a prediction cad measured turns into the join's spring).
10
10
  import { JOINS, JOIN_SCALE, joinModel } from '@rulecad/frames';
11
11
  import { placeItems } from '@rulecad/model-link';
12
12
  import { beamOf, beamPlace, framesContext } from './beams.mjs';
13
13
  import { joinFitting, fittedStiffness } from './fittings.mjs';
14
+ import { joinDropOf } from './framecheck.mjs';
14
15
 
15
16
  const KEYS = ['kind', 'a', 'b', 'fitting', 'screw', 'brace', 'load', 'nut', 'face', 'shape', 'note'];
16
17
  const shown = (v) => (v === undefined ? 'nothing' : JSON.stringify(v));
17
- const mm = (x) => String(+Number(x).toFixed(2)), r3 = (x) => +x.toFixed(3);
18
- const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2], sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
18
+ const mm = (x) => String(+Number(x).toFixed(2)),
19
+ r3 = (x) => +x.toFixed(3);
20
+ const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2],
21
+ sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
19
22
  const cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
20
23
 
21
24
  /** The working figures of the join checks, each with what it rests on. */
22
25
  export const JOIN_CHECK = {
23
- flush: { value: 0.05, unit: 'mm', rule: 'An end meets a face flush when it stands off it, or runs into it, by no more than this: far under a cut\'s tolerance, so a gap a person can see is a failure', kind: 'default', source: 'A working figure of @rulecad/cad, the same as fasten\'s holes on one axis', checked: '2026-11-16' },
24
- place: { value: 0.05, unit: 'mm', rule: 'An end is where its join says, on the face, when its centre is within this of the address', kind: 'default', source: 'A working figure of @rulecad/cad', checked: '2026-11-16' },
25
- square: { value: 0.5, unit: '°', rule: 'An end meets a face square when its axis is within this of the face\'s normal: a beam cut square to ±0.5 mm across 20 mm is about 1.4° out, so this holds the drawing, not the saw', kind: 'default', source: 'A working figure of @rulecad/cad', checked: '2026-11-16' },
26
+ flush: {
27
+ value: 0.05,
28
+ unit: 'mm',
29
+ rule: "An end meets a face flush when it stands off it, or runs into it, by no more than this: far under a cut's tolerance, so a gap a person can see is a failure",
30
+ kind: 'default',
31
+ source: "A working figure of @rulecad/cad, the same as fasten's holes on one axis",
32
+ checked: '2026-11-16',
33
+ },
34
+ place: {
35
+ value: 0.05,
36
+ unit: 'mm',
37
+ rule: 'An end is where its join says, on the face, when its centre is within this of the address',
38
+ kind: 'default',
39
+ source: 'A working figure of @rulecad/cad',
40
+ checked: '2026-11-16',
41
+ },
42
+ square: {
43
+ value: 0.5,
44
+ unit: '°',
45
+ rule: "An end meets a face square when its axis is within this of the face's normal: a beam cut square to ±0.5 mm across 20 mm is about 1.4° out, so this holds the drawing, not the saw",
46
+ kind: 'default',
47
+ source: 'A working figure of @rulecad/cad',
48
+ checked: '2026-11-16',
49
+ },
26
50
  };
27
51
 
28
52
  // "y1.a" into its item and the rest
29
- const split = (n) => { const s = String(n).trim(), i = s.indexOf('.'); return i < 0 ? [s, ''] : [s.slice(0, i), s.slice(i + 1)]; };
53
+ const split = (n) => {
54
+ const s = String(n).trim(),
55
+ i = s.indexOf('.');
56
+ return i < 0 ? [s, ''] : [s.slice(0, i), s.slice(i + 1)];
57
+ };
30
58
  // (one place written two ways: a face's first slot with or without its number, top@250 and top.1@250, a and a.1)
31
- const placeOf = (p) => String(p).trim().replace(/\s+/g, '').replace(/\.1(?=@|$)/, '');
59
+ const placeOf = (p) =>
60
+ String(p)
61
+ .trim()
62
+ .replace(/\s+/g, '')
63
+ .replace(/\.1(?=@|$)/, '');
32
64
  const sameAt = (p, q) => placeOf(p) === placeOf(q);
33
65
 
34
66
  /**
@@ -41,89 +73,249 @@ const sameAt = (p, q) => placeOf(p) === placeOf(q);
41
73
  export function expandJoins(a, num, context = framesContext(), material = 'pla') {
42
74
  const list = a.joins;
43
75
  if (list == null) return { a, joins: [] };
44
- if (!Array.isArray(list)) throw new Error(`joins is a list: [{ "kind": "blind", "a": "y1.a", "b": "x1.back@120" }] (got ${shown(list)})`);
76
+ if (!Array.isArray(list))
77
+ throw new Error(`joins is a list: [{ "kind": "blind", "a": "y1.a", "b": "x1.back@120" }] (got ${shown(list)})`);
45
78
  if (!list.length) return { a, joins: [] };
46
79
  const given = { sets: context?.sets ?? {} }; // (a bought fitting of the workspace's own, beside the kit's)
47
- const items = a.items || [], beams = new Map(items.filter((it) => it.beam).map((it) => [it.id, it])), models = new Map();
48
- const modelOf = (id) => { if (!models.has(id)) models.set(id, beamOf(beams.get(id), num, context).model); return models.get(id); };
49
- const extra = new Map(), fasten = [], joins = [], first = (a.fasten || []).length, added = [], ids = new Set(items.map((it) => it.id));
80
+ const items = a.items || [],
81
+ beams = new Map(items.filter((it) => it.beam).map((it) => [it.id, it])),
82
+ models = new Map();
83
+ const modelOf = (id) => {
84
+ if (!models.has(id)) models.set(id, beamOf(beams.get(id), num, context).model);
85
+ return models.get(id);
86
+ };
87
+ const extra = new Map(),
88
+ fasten = [],
89
+ joins = [],
90
+ first = (a.fasten || []).length,
91
+ added = [],
92
+ ids = new Set(items.map((it) => it.id));
50
93
  list.forEach((j, i) => {
51
94
  const what = `join ${i + 1}`;
52
- if (!j || typeof j !== 'object' || Array.isArray(j)) throw new Error(`${what} is { "kind", "a", "b" } (got ${shown(j)})`);
53
- for (const k of Object.keys(j)) if (!KEYS.includes(k)) throw new Error(`${what}: a join has no "${k}": it takes ${KEYS.join(', ')}`);
54
- if (!JOINS[j.kind]) throw new Error(`${what}: kind is one of ${Object.keys(JOINS).join(', ')} (got ${shown(j.kind)})`);
95
+ if (!j || typeof j !== 'object' || Array.isArray(j))
96
+ throw new Error(`${what} is { "kind", "a", "b" } (got ${shown(j)})`);
97
+ for (const k of Object.keys(j))
98
+ if (!KEYS.includes(k)) throw new Error(`${what}: a join has no "${k}": it takes ${KEYS.join(', ')}`);
99
+ if (!JOINS[j.kind])
100
+ throw new Error(`${what}: kind is one of ${Object.keys(JOINS).join(', ')} (got ${shown(j.kind)})`);
55
101
  const ends = {};
56
102
  for (const side of ['a', 'b']) {
57
- if (typeof j[side] !== 'string' || !j[side].includes('.')) throw new Error(`${what}: ${side} is ${side === 'a' ? 'a beam\'s end, as y1.a' : 'a place on a beam, as x1.back@120 (or an end, x1.b)'} (got ${shown(j[side])})`);
103
+ if (typeof j[side] !== 'string' || !j[side].includes('.'))
104
+ throw new Error(
105
+ `${what}: ${side} is ${side === 'a' ? "a beam's end, as y1.a" : 'a place on a beam, as x1.back@120 (or an end, x1.b)'} (got ${shown(j[side])})`,
106
+ );
58
107
  const [id, rest] = split(j[side]);
59
- if (!beams.has(id)) throw new Error(`${what}: ${side} is on a beam item of this assembly, and ${id} is ${items.some((it) => it.id === id) ? 'not a beam' : 'not an item'} (beams: ${[...beams.keys()].join(', ') || 'none'})`);
108
+ if (!beams.has(id))
109
+ throw new Error(
110
+ `${what}: ${side} is on a beam item of this assembly, and ${id} is ${items.some((it) => it.id === id) ? 'not a beam' : 'not an item'} (beams: ${[...beams.keys()].join(', ') || 'none'})`,
111
+ );
60
112
  ends[side] = { id, rest };
61
113
  }
62
- if (ends.a.id === ends.b.id) throw new Error(`${what}: a and b are on one beam, ${ends.a.id}: a join is between two beams`);
63
- const mitre = j.kind === 'mitre' ? mitreOf(what, beams.get(ends.a.id), ends.a.rest, beams.get(ends.b.id), ends.b.rest, num) : null;
114
+ if (ends.a.id === ends.b.id)
115
+ throw new Error(`${what}: a and b are on one beam, ${ends.a.id}: a join is between two beams`);
116
+ const mitre =
117
+ j.kind === 'mitre'
118
+ ? mitreOf(what, beams.get(ends.a.id), ends.a.rest, beams.get(ends.b.id), ends.b.rest, num)
119
+ : null;
64
120
  let m;
65
- try { m = joinModel(j.kind, { beam: modelOf(ends.a.id), end: ends.a.rest }, { beam: modelOf(ends.b.id), address: ends.b.rest }, { ...(j.screw != null ? { screw: j.screw } : {}), ...(j.fitting != null ? { fitting: j.fitting } : {}), ...(mitre ? { mitre } : {}), given }); }
66
- catch (e) { throw new Error(`${what}: ${String(e.message).replace(/^(joinModel|beamAnchor): /, '')}`); }
67
- for (const [side, ops] of [['a', m.a.ops], ['b', m.b.ops]]) { const id = ends[side].id; if (ops.length) extra.set(id, [...(extra.get(id) || []), ...ops]); }
68
- const label = j.note || `${j.kind} join of ${j.a} to ${j.b}`, mine = [];
69
- if (j.face != null && !(j.kind === 'gusset' && j.fitting === 'printed')) throw new Error(`${what}: face names the face of b a printed gusset lies on: give it on a gusset join with "fitting": "printed", or leave face out`);
70
- if (j.shape != null && !(j.kind === 'gusset' && j.fitting === 'printed')) throw new Error(`${what}: shape names a printed gusset's shape (L or T): give it on a gusset join with "fitting": "printed", or leave shape out`);
71
- if (j.shape != null && !['L', 'T'].includes(j.shape)) throw new Error(`${what}: shape is a printed gusset's shape, L or T (got ${JSON.stringify(j.shape)})`);
72
- for (const k of ['brace', 'load', 'nut']) if (j[k] != null && !(m.fitting?.printed && j.fitting === 'printed')) throw new Error(`${what}: ${k} is for a printed fitting: give "fitting": "printed" on a ${Object.keys(JOINS).filter((x) => JOINS[x].printed).join(', ')} join, or leave ${k} out`);
121
+ try {
122
+ m = joinModel(
123
+ j.kind,
124
+ { beam: modelOf(ends.a.id), end: ends.a.rest },
125
+ { beam: modelOf(ends.b.id), address: ends.b.rest },
126
+ {
127
+ ...(j.screw != null ? { screw: j.screw } : {}),
128
+ ...(j.fitting != null ? { fitting: j.fitting } : {}),
129
+ ...(mitre ? { mitre } : {}),
130
+ given,
131
+ },
132
+ );
133
+ } catch (e) {
134
+ throw new Error(`${what}: ${String(e.message).replace(/^(joinModel|beamAnchor): /, '')}`);
135
+ }
136
+ for (const [side, ops] of [
137
+ ['a', m.a.ops],
138
+ ['b', m.b.ops],
139
+ ]) {
140
+ const id = ends[side].id;
141
+ if (ops.length) extra.set(id, [...(extra.get(id) || []), ...ops]);
142
+ }
143
+ const label = j.note || `${j.kind} join of ${j.a} to ${j.b}`,
144
+ mine = [];
145
+ if (j.face != null && !(j.kind === 'gusset' && j.fitting === 'printed'))
146
+ throw new Error(
147
+ `${what}: face names the face of b a printed gusset lies on: give it on a gusset join with "fitting": "printed", or leave face out`,
148
+ );
149
+ if (j.shape != null && !(j.kind === 'gusset' && j.fitting === 'printed'))
150
+ throw new Error(
151
+ `${what}: shape names a printed gusset's shape (L or T): give it on a gusset join with "fitting": "printed", or leave shape out`,
152
+ );
153
+ if (j.shape != null && !['L', 'T'].includes(j.shape))
154
+ throw new Error(`${what}: shape is a printed gusset's shape, L or T (got ${JSON.stringify(j.shape)})`);
155
+ for (const k of ['brace', 'load', 'nut'])
156
+ if (j[k] != null && !(m.fitting?.printed && j.fitting === 'printed'))
157
+ throw new Error(
158
+ `${what}: ${k} is for a printed fitting: give "fitting": "printed" on a ${Object.keys(JOINS)
159
+ .filter((x) => JOINS[x].printed)
160
+ .join(', ')} join, or leave ${k} out`,
161
+ );
73
162
  // a printed fitting: its item, placed from where the beams are, and a fasten for each leg into its beam's slot
74
163
  let fitted = null;
75
164
  if (m.fitting?.printed && j.fitting === 'printed') {
76
- fitted = joinFitting(j, i, { ia: beams.get(ends.a.id), ib: beams.get(ends.b.id), A: modelOf(ends.a.id), B: modelOf(ends.b.id), m, ends, place: beamPlace }, num, context, material, ids);
165
+ fitted = joinFitting(
166
+ j,
167
+ i,
168
+ {
169
+ ia: beams.get(ends.a.id),
170
+ ib: beams.get(ends.b.id),
171
+ A: modelOf(ends.a.id),
172
+ B: modelOf(ends.b.id),
173
+ m,
174
+ ends,
175
+ place: beamPlace,
176
+ },
177
+ num,
178
+ context,
179
+ material,
180
+ ids,
181
+ );
77
182
  added.push(fitted.item);
78
- for (const x of fitted.fasten) { mine.push(first + fasten.length); fasten.push(x); }
183
+ for (const x of fitted.fasten) {
184
+ mine.push(first + fasten.length);
185
+ fasten.push(x);
186
+ }
79
187
  m.stiffness = fittedStiffness(m.stiffness, fitted.model);
80
188
  } else if (m.fitting?.bought && m.fitting.fits) {
81
189
  // a bought one: its set's item placed the same way, its screws into the set's nuts (an inner or anchor connector's
82
190
  // are part of it), its stiffness its set's (joinModel's)
83
- fitted = joinFitting(j, i, { ia: beams.get(ends.a.id), ib: beams.get(ends.b.id), A: modelOf(ends.a.id), B: modelOf(ends.b.id), m, ends, place: beamPlace }, num, context, material, ids);
191
+ fitted = joinFitting(
192
+ j,
193
+ i,
194
+ {
195
+ ia: beams.get(ends.a.id),
196
+ ib: beams.get(ends.b.id),
197
+ A: modelOf(ends.a.id),
198
+ B: modelOf(ends.b.id),
199
+ m,
200
+ ends,
201
+ place: beamPlace,
202
+ },
203
+ num,
204
+ context,
205
+ material,
206
+ ids,
207
+ );
84
208
  added.push(fitted.item);
85
- for (const x of fitted.fasten) { mine.push(first + fasten.length); fasten.push(x); }
209
+ for (const x of fitted.fasten) {
210
+ mine.push(first + fasten.length);
211
+ fasten.push(x);
212
+ }
86
213
  }
87
214
  // the head: inside b's slot under its lips (blind), or on the lips of the slot across b (end-tap), or on a plain face
88
- const lips = j.kind === 'blind' ? { item: ends.b.id, slot: m.b.slot, inside: true } : m.b.across?.slot ? { item: ends.b.id, slot: m.b.across.slot, inside: false } : null;
89
- for (const sc of m.screws) { mine.push(first + fasten.length); fasten.push({ screw: sc.screw, through: [ends.b.id], into: ends.a.id, at: [`${ends.a.id}.${sc.bore}`], note: label, join: i, ...(lips ? { lips } : {}) }); }
90
- joins.push({ index: i, kind: j.kind, a: j.a, b: j.b, items: [ends.a.id, ends.b.id], end: ends.a.rest, address: ends.b.rest, label, fitting: j.fitting ?? null, model: m, fasten: mine, ...(fitted ? { fitted: { item: fitted.item.id, model: fitted.model } } : {}) });
215
+ const lips =
216
+ j.kind === 'blind'
217
+ ? { item: ends.b.id, slot: m.b.slot, inside: true }
218
+ : m.b.across?.slot
219
+ ? { item: ends.b.id, slot: m.b.across.slot, inside: false }
220
+ : null;
221
+ for (const sc of m.screws) {
222
+ mine.push(first + fasten.length);
223
+ fasten.push({
224
+ screw: sc.screw,
225
+ through: [ends.b.id],
226
+ into: ends.a.id,
227
+ at: [`${ends.a.id}.${sc.bore}`],
228
+ note: label,
229
+ join: i,
230
+ ...(lips ? { lips } : {}),
231
+ });
232
+ }
233
+ joins.push({
234
+ index: i,
235
+ kind: j.kind,
236
+ a: j.a,
237
+ b: j.b,
238
+ items: [ends.a.id, ends.b.id],
239
+ end: ends.a.rest,
240
+ address: ends.b.rest,
241
+ label,
242
+ fitting: j.fitting ?? null,
243
+ model: m,
244
+ fasten: mine,
245
+ ...(fitted ? { fitted: { item: fitted.item.id, model: fitted.model } } : {}),
246
+ });
91
247
  });
92
248
  // each beam's own ops first; a join's op where the beam has none like it at that place (a tap of the whole end a
93
249
  // covers a tap at a.1; a tap at a.1 does not cover one at a.2, a 20 x 40's other bore)
94
250
  const withOps = items.map((it) => {
95
251
  const add = extra.get(it.id);
96
252
  if (!add) return it;
97
- const own = it.beam.ops || [], ops = [...own];
98
- for (const op of add) if (!ops.some((g) => g?.op === op.op && (sameAt(g.at, op.at) || (op.op === 'tap' && (String(g.at).trim() === op.at[0] || (op.at.length === 1 && String(g.at).trim()[0] === op.at)))))) ops.push(op);
253
+ const own = it.beam.ops || [],
254
+ ops = [...own];
255
+ for (const op of add)
256
+ if (
257
+ !ops.some(
258
+ (g) =>
259
+ g?.op === op.op &&
260
+ (sameAt(g.at, op.at) ||
261
+ (op.op === 'tap' &&
262
+ (String(g.at).trim() === op.at[0] || (op.at.length === 1 && String(g.at).trim()[0] === op.at)))),
263
+ )
264
+ )
265
+ ops.push(op);
99
266
  return { ...it, beam: { ...it.beam, ops } };
100
267
  });
101
- return { a: { ...a, items: [...withOps, ...added], ...(fasten.length ? { fasten: [...(a.fasten || []), ...fasten] } : {}) }, joins };
268
+ return {
269
+ a: { ...a, items: [...withOps, ...added], ...(fasten.length ? { fasten: [...(a.fasten || []), ...fasten] } : {}) },
270
+ joins,
271
+ };
102
272
  }
103
273
 
104
274
  // A mitre's cuts from where the two beams are: the angle from square that halves the corner, the face each sees the
105
275
  // corner on, and the outside of the corner, where each beam's length is measured. Both beams placed by their ends.
106
276
  function mitreOf(what, ia, ea, ib, eb, num) {
107
- const fa = beamPlace(ia, num), fb = beamPlace(ib, num);
108
- if (!fa || !fb) throw new Error(`${what}: a mitre join is cut from where the beams meet: place ${!fa ? ia.id : ib.id} by its ends (from, to)`);
109
- if (!/^[ab]$/.test(ea)) throw new Error(`${what}: a mitre join cuts a whole end: a is ${ia.id}.a or ${ia.id}.b (got ${ia.id}.${ea})`);
110
- const col = (f, k) => [f[k], f[4 + k], f[8 + k]], body = (f, e) => col(f, 2).map((c) => (e === 'a' ? c : -c)); // (along the beam, away from the corner)
111
- const da = body(fa, ea), db = body(fb, eb), n = cross(da, db), nl = Math.hypot(...n), phi = (Math.acos(Math.max(-1, Math.min(1, dot(da, db)))) * 180) / Math.PI;
112
- if (nl < 1e-9) throw new Error(`${what}: ${ia.id} and ${ib.id} lie along one line, so there is no corner to mitre: a splice joins them end to end`);
277
+ const fa = beamPlace(ia, num),
278
+ fb = beamPlace(ib, num);
279
+ if (!fa || !fb)
280
+ throw new Error(
281
+ `${what}: a mitre join is cut from where the beams meet: place ${!fa ? ia.id : ib.id} by its ends (from, to)`,
282
+ );
283
+ if (!/^[ab]$/.test(ea))
284
+ throw new Error(`${what}: a mitre join cuts a whole end: a is ${ia.id}.a or ${ia.id}.b (got ${ia.id}.${ea})`);
285
+ const col = (f, k) => [f[k], f[4 + k], f[8 + k]],
286
+ body = (f, e) => col(f, 2).map((c) => (e === 'a' ? c : -c)); // (along the beam, away from the corner)
287
+ const da = body(fa, ea),
288
+ db = body(fb, eb),
289
+ n = cross(da, db),
290
+ nl = Math.hypot(...n),
291
+ phi = (Math.acos(Math.max(-1, Math.min(1, dot(da, db)))) * 180) / Math.PI;
292
+ if (nl < 1e-9)
293
+ throw new Error(
294
+ `${what}: ${ia.id} and ${ib.id} lie along one line, so there is no corner to mitre: a splice joins them end to end`,
295
+ );
113
296
  const side = (f, other) => {
114
- const back = col(f, 0), top = col(f, 1), u = n.map((c) => c / nl);
115
- if (Math.abs(Math.abs(dot(u, top)) - 1) < 1e-6) return { about: 'top', long: dot(back, other) > 0 ? 'front' : 'back' };
116
- if (Math.abs(Math.abs(dot(u, back)) - 1) < 1e-6) return { about: 'back', long: dot(top, other) > 0 ? 'bottom' : 'top' };
297
+ const back = col(f, 0),
298
+ top = col(f, 1),
299
+ u = n.map((c) => c / nl);
300
+ if (Math.abs(Math.abs(dot(u, top)) - 1) < 1e-6)
301
+ return { about: 'top', long: dot(back, other) > 0 ? 'front' : 'back' };
302
+ if (Math.abs(Math.abs(dot(u, back)) - 1) < 1e-6)
303
+ return { about: 'back', long: dot(top, other) > 0 ? 'bottom' : 'top' };
117
304
  return null;
118
305
  };
119
- const a = side(fa, db), b = side(fb, da);
120
- if (!a || !b) throw new Error(`${what}: the corner of ${ia.id} and ${ib.id} lies across ${!a ? ia.id : ib.id}'s faces, not square to one: turn it with roll so a face lies in the corner's plane`);
306
+ const a = side(fa, db),
307
+ b = side(fb, da);
308
+ if (!a || !b)
309
+ throw new Error(
310
+ `${what}: the corner of ${ia.id} and ${ib.id} lies across ${!a ? ia.id : ib.id}'s faces, not square to one: turn it with roll so a face lies in the corner's plane`,
311
+ );
121
312
  return { angle: +(90 - phi / 2).toFixed(6), a, b };
122
313
  }
123
314
 
124
315
  // What a join's spring rests on, in words: the joint rig's measurement and its date, or an estimate until it is measured
125
316
  function restsOn(k) {
126
- const b = k.measured?.bending, t = k.measured?.twist;
317
+ const b = k.measured?.bending,
318
+ t = k.measured?.twist;
127
319
  if (b && t) return `measured on the joint rig on ${b}${t !== b ? ` (twist on ${t})` : ''}`;
128
320
  if (b) return `bending measured on the joint rig on ${b}; twist an estimate until the rig measures it`;
129
321
  if (t) return `twist measured on the joint rig on ${t}; bending an estimate until the rig measures it`;
@@ -137,7 +329,11 @@ function covered(s) {
137
329
  out.add(`${j.items[0]}.${j.end[0]}`);
138
330
  if (/^[ab]$/.test(j.address)) out.add(`${j.items[1]}.${j.address}`);
139
331
  }
140
- for (const it of s.a.items || []) if (typeof it.at === 'string') { const m = /^([\w-]+)\.([ab])(\.|$)/.exec(it.at.trim()); if (m) out.add(`${m[1]}.${m[2]}`); }
332
+ for (const it of s.a.items || [])
333
+ if (typeof it.at === 'string') {
334
+ const m = /^([\w-]+)\.([ab])(\.|$)/.exec(it.at.trim());
335
+ if (m) out.add(`${m[1]}.${m[2]}`);
336
+ }
141
337
  return out;
142
338
  }
143
339
 
@@ -150,114 +346,497 @@ export function joinChecks(s, f) {
150
346
  const worlds = placeItems(s.motion, s.jointValues);
151
347
  const ids = s.motion.items.map((x) => x[0]);
152
348
  const world = (n, what) => {
153
- const { item, frame: r } = s.motion.address(n, what), W = worlds[item];
349
+ const { item, frame: r } = s.motion.address(n, what),
350
+ W = worlds[item];
154
351
  const pt = (p) => [0, 1, 2].map((k) => W[4 * k] * p[0] + W[4 * k + 1] * p[1] + W[4 * k + 2] * p[2] + W[4 * k + 3]);
155
352
  const dir = (v) => [0, 1, 2].map((k) => W[4 * k] * v[0] + W[4 * k + 1] * v[1] + W[4 * k + 2] * v[2]);
156
353
  return { at: pt([r[3], r[7], r[11]]), axis: dir([r[2], r[6], r[10]]), ref: dir([r[0], r[4], r[8]]) };
157
354
  };
158
355
  const { flush, place, square } = Object.fromEntries(Object.entries(JOIN_CHECK).map(([k, v]) => [k, v.value]));
159
356
  for (const j of s.joins) {
160
- const m = j.model, [ai, bi] = j.items, refs = { join: j.index, kind: j.kind, a: j.a, b: j.b };
161
- for (const x of m.findings) f(x.level, `${j.label}: ${x.text.startsWith(`${m.says}: `) ? x.text.slice(m.says.length + 2) : x.text}`, x.level === 'fail' || x.level === 'warn' ? `${j.label}: ${x.code.split('.')[1]}` : null, { code: x.code, refs: { ...refs, ...x.refs } });
357
+ const m = j.model,
358
+ [ai, bi] = j.items,
359
+ refs = { join: j.index, kind: j.kind, a: j.a, b: j.b };
360
+ for (const x of m.findings)
361
+ f(
362
+ x.level,
363
+ `${j.label}: ${x.text.startsWith(`${m.says}: `) ? x.text.slice(m.says.length + 2) : x.text}`,
364
+ x.level === 'fail' || x.level === 'warn' ? `${j.label}: ${x.code.split('.')[1]}` : null,
365
+ { code: x.code, refs: { ...refs, ...x.refs } },
366
+ );
162
367
  // where it meets: from the bore the screw goes in where there is one, else the end's centre
163
- const A = world(`${ai}.${m.a.bores[0] ?? j.end[0]}`, `join ${j.index + 1}`), B = world(`${bi}.${j.address}`, `join ${j.index + 1}`);
368
+ const A = world(`${ai}.${m.a.bores[0] ?? j.end[0]}`, `join ${j.index + 1}`),
369
+ B = world(`${bi}.${j.address}`, `join ${j.index + 1}`);
164
370
  if (m.b.end == null) {
165
- const n = B.axis, gap = dot(sub(A.at, B.at), n), off = sub(sub(A.at, B.at), n.map((c) => c * gap)), along = dot(off, B.ref), aside = Math.hypot(...off.map((c, k) => c - B.ref[k] * along));
166
- const angle = (Math.acos(Math.max(-1, Math.min(1, -dot(A.axis, n)))) * 180) / Math.PI, wrong = [];
371
+ const n = B.axis,
372
+ gap = dot(sub(A.at, B.at), n),
373
+ off = sub(
374
+ sub(A.at, B.at),
375
+ n.map((c) => c * gap),
376
+ ),
377
+ along = dot(off, B.ref),
378
+ aside = Math.hypot(...off.map((c, k) => c - B.ref[k] * along));
379
+ const angle = (Math.acos(Math.max(-1, Math.min(1, -dot(A.axis, n)))) * 180) / Math.PI,
380
+ wrong = [];
167
381
  const values = { gap: r3(gap), along: r3(along), across: r3(aside), angle: +angle.toFixed(2) };
168
- const face = `${bi}'s ${m.b.place} face`, end = `${ai}'s end ${j.end}`;
169
- if (Math.abs(gap) > flush) wrong.push(gap > 0 ? `${end} stands ${mm(gap)} mm off ${face}: a gap of ${mm(gap)} mm, where it meets flush. Move ${ai} ${mm(gap)} mm toward ${bi}` : `${end} runs ${mm(-gap)} mm into ${face}: move ${ai} ${mm(-gap)} mm back, so it meets the face flush`);
382
+ const face = `${bi}'s ${m.b.place} face`,
383
+ end = `${ai}'s end ${j.end}`;
384
+ if (Math.abs(gap) > flush)
385
+ wrong.push(
386
+ gap > 0
387
+ ? `${end} stands ${mm(gap)} mm off ${face}: a gap of ${mm(gap)} mm, where it meets flush. Move ${ai} ${mm(gap)} mm toward ${bi}`
388
+ : `${end} runs ${mm(-gap)} mm into ${face}: move ${ai} ${mm(-gap)} mm back, so it meets the face flush`,
389
+ );
170
390
  if (angle > square) wrong.push(`${end} meets ${face} ${mm(+angle.toFixed(2))}° from square`);
171
- if (Math.hypot(along, aside) > place) wrong.push(`${end} is ${along ? `${mm(Math.abs(along))} mm ${along > 0 ? 'toward' : 'away from'} ${bi}'s end b` : ''}${along && aside > place ? ' and ' : ''}${aside > place ? `${mm(aside)} mm across ${m.b.slot ? 'the slot\'s centre line' : 'the face'}` : ''} from ${j.b}${aside <= place && m.b.distance != null ? `: it meets ${bi} ${mm(m.b.distance + along)} mm from its end a, so the join says ${bi}.${m.b.place.split('.')[0]}@${mm(m.b.distance + along)}, or ${ai} moves` : ''}`);
172
- if (wrong.length) f('fail', `${j.label}: ${wrong.join('; ')}`, `${j.label}: geometry`, { code: 'join.geometry', at: A.at.map(r3), between: [A.at.map(r3), B.at.map(r3)], values, refs });
173
- else if (!m.findings.some((x) => x.code === 'join.geometry')) f('pass', `${j.label}: ${end} meets ${face} square and flush at ${mm(m.b.distance)} mm from ${bi}'s end a${m.b.slot && JOINS[j.kind].slot ? ', on the slot\'s centre line' : ''}`, null, { code: 'join.geometry', at: A.at.map(r3), values, refs });
391
+ if (Math.hypot(along, aside) > place)
392
+ wrong.push(
393
+ `${end} is ${along ? `${mm(Math.abs(along))} mm ${along > 0 ? 'toward' : 'away from'} ${bi}'s end b` : ''}${along && aside > place ? ' and ' : ''}${aside > place ? `${mm(aside)} mm across ${m.b.slot ? "the slot's centre line" : 'the face'}` : ''} from ${j.b}${aside <= place && m.b.distance != null ? `: it meets ${bi} ${mm(m.b.distance + along)} mm from its end a, so the join says ${bi}.${m.b.place.split('.')[0]}@${mm(m.b.distance + along)}, or ${ai} moves` : ''}`,
394
+ );
395
+ if (wrong.length)
396
+ f('fail', `${j.label}: ${wrong.join('; ')}`, `${j.label}: geometry`, {
397
+ code: 'join.geometry',
398
+ at: A.at.map(r3),
399
+ between: [A.at.map(r3), B.at.map(r3)],
400
+ values,
401
+ refs,
402
+ });
403
+ else if (!m.findings.some((x) => x.code === 'join.geometry'))
404
+ f(
405
+ 'pass',
406
+ `${j.label}: ${end} meets ${face} square and flush at ${mm(m.b.distance)} mm from ${bi}'s end a${m.b.slot && JOINS[j.kind].slot ? ", on the slot's centre line" : ''}`,
407
+ null,
408
+ { code: 'join.geometry', at: A.at.map(r3), values, refs },
409
+ );
174
410
  } else {
175
411
  // end to end (a splice): the ends meet face to face on one axis; at a corner (mitre, cube, a node): the axes meet
176
- const gap = Math.hypot(...sub(A.at, B.at)), angle = (Math.acos(Math.max(-1, Math.min(1, -dot(A.axis, B.axis)))) * 180) / Math.PI;
412
+ const gap = Math.hypot(...sub(A.at, B.at)),
413
+ angle = (Math.acos(Math.max(-1, Math.min(1, -dot(A.axis, B.axis)))) * 180) / Math.PI;
177
414
  if (j.kind === 'splice') {
178
- const ok = gap <= flush && angle <= square, values = { gap: r3(gap), angle: +angle.toFixed(2) };
179
- f(ok ? 'pass' : 'fail', `${j.label}: ${ok ? `${ai}'s end ${j.end} meets ${bi}'s end ${j.address} face to face on one axis` : `${ai}'s end ${j.end} and ${bi}'s end ${j.address} are ${mm(gap)} mm apart${angle > square ? ` and ${mm(+angle.toFixed(2))}° off one axis` : ''}, where a splice meets end to end`}`, ok ? null : `${j.label}: geometry`, { code: 'join.geometry', at: A.at.map(r3), between: [A.at.map(r3), B.at.map(r3)], values, refs });
415
+ const ok = gap <= flush && angle <= square,
416
+ values = { gap: r3(gap), angle: +angle.toFixed(2) };
417
+ f(
418
+ ok ? 'pass' : 'fail',
419
+ `${j.label}: ${ok ? `${ai}'s end ${j.end} meets ${bi}'s end ${j.address} face to face on one axis` : `${ai}'s end ${j.end} and ${bi}'s end ${j.address} are ${mm(gap)} mm apart${angle > square ? ` and ${mm(+angle.toFixed(2))}° off one axis` : ''}, where a splice meets end to end`}`,
420
+ ok ? null : `${j.label}: geometry`,
421
+ { code: 'join.geometry', at: A.at.map(r3), between: [A.at.map(r3), B.at.map(r3)], values, refs },
422
+ );
180
423
  } else {
181
- const w = cross(A.axis, B.axis), wl = Math.hypot(...w), d = sub(B.at, A.at), miss = wl < 1e-9 ? Math.hypot(...cross(d, A.axis)) : Math.abs(dot(d, w)) / wl;
182
- const reach = Math.max(...[ai, bi].map((id) => { const o = s.objects.find((x) => x.id === id)?.beam; return o ? Math.hypot(o.profile.width, o.profile.height) : 0; }));
183
- const ok = wl > 1e-9 && miss <= place && gap <= reach + flush, values = { miss: r3(miss), gap: r3(gap), angle: +angle.toFixed(2) };
184
- f(ok ? 'pass' : 'fail', `${j.label}: ${ok ? `the axes of ${ai} and ${bi} meet at the corner, their ends ${mm(gap)} mm apart` : wl <= 1e-9 ? `${ai} and ${bi} lie along one line, where a ${j.kind} join meets at a corner` : miss > place ? `the axes of ${ai} and ${bi} pass ${mm(miss)} mm apart, where a ${j.kind} join's meet at the corner` : `${ai}'s end ${j.end} and ${bi}'s end ${j.address} are ${mm(gap)} mm apart, more than the beams' ${mm(reach)} mm across: they do not meet`}`, ok ? null : `${j.label}: geometry`, { code: 'join.geometry', at: A.at.map(r3), between: [A.at.map(r3), B.at.map(r3)], values, refs });
424
+ const w = cross(A.axis, B.axis),
425
+ wl = Math.hypot(...w),
426
+ d = sub(B.at, A.at),
427
+ miss = wl < 1e-9 ? Math.hypot(...cross(d, A.axis)) : Math.abs(dot(d, w)) / wl;
428
+ const reach = Math.max(
429
+ ...[ai, bi].map((id) => {
430
+ const o = s.objects.find((x) => x.id === id)?.beam;
431
+ return o ? Math.hypot(o.profile.width, o.profile.height) : 0;
432
+ }),
433
+ );
434
+ const ok = wl > 1e-9 && miss <= place && gap <= reach + flush,
435
+ values = { miss: r3(miss), gap: r3(gap), angle: +angle.toFixed(2) };
436
+ f(
437
+ ok ? 'pass' : 'fail',
438
+ `${j.label}: ${ok ? `the axes of ${ai} and ${bi} meet at the corner, their ends ${mm(gap)} mm apart` : wl <= 1e-9 ? `${ai} and ${bi} lie along one line, where a ${j.kind} join meets at a corner` : miss > place ? `the axes of ${ai} and ${bi} pass ${mm(miss)} mm apart, where a ${j.kind} join's meet at the corner` : `${ai}'s end ${j.end} and ${bi}'s end ${j.address} are ${mm(gap)} mm apart, more than the beams' ${mm(reach)} mm across: they do not meet`}`,
439
+ ok ? null : `${j.label}: geometry`,
440
+ { code: 'join.geometry', at: A.at.map(r3), between: [A.at.map(r3), B.at.map(r3)], values, refs },
441
+ );
185
442
  }
186
443
  }
187
444
  // the spring this join puts at a's end in a frame's solve: measured on the joint rig with its date, or an estimate
188
445
  // until it is, and it says which
189
446
  const k = m.stiffness;
190
447
  if (k.bought) {
191
- const set = k.bought.set, own = k.bought.own;
192
- f('info', `${j.label}: taken as ${(k.bending / 1e6).toFixed(3)} N·m/mrad in bending and ${(k.twist / 1e6).toFixed(2)} N·m/mrad in twist at ${ai}'s end ${j.end}, ${own ? `${set}'s own figures from its rule set (${k.kind}: ${k.bought.rule})` : `the ${j.kind} join's ${k.measured?.bending ? 'figures' : 'estimate'}, as ${set} gives none`}: ${restsOn(k)}`, null,
193
- { code: 'join.stiffness', values: { bending: k.bending, twist: k.twist }, refs: { ...refs, ...(j.fitted ? { item: j.fitted.item } : {}), set, kind_of_value: k.kind, measured: k.measured, end: k.end, rests: k.rests } });
448
+ const set = k.bought.set,
449
+ own = k.bought.own;
450
+ f(
451
+ 'info',
452
+ `${j.label}: taken as ${(k.bending / 1e6).toFixed(3)} N·m/mrad in bending and ${(k.twist / 1e6).toFixed(2)} N·m/mrad in twist at ${ai}'s end ${j.end}, ${own ? `${set}'s own figures from its rule set (${k.kind}: ${k.bought.rule})` : `the ${j.kind} join's ${k.measured?.bending ? 'figures' : 'estimate'}, as ${set} gives none`}: ${restsOn(k)}`,
453
+ null,
454
+ {
455
+ code: 'join.stiffness',
456
+ values: { bending: k.bending, twist: k.twist },
457
+ refs: {
458
+ ...refs,
459
+ ...(j.fitted ? { item: j.fitted.item } : {}),
460
+ set,
461
+ kind_of_value: k.kind,
462
+ measured: k.measured,
463
+ end: k.end,
464
+ rests: k.rests,
465
+ },
466
+ },
467
+ );
194
468
  continue;
195
469
  }
196
470
  if (k.fitting) {
197
- const fm = k.fitting, shared = fm.shareKind === 'measured';
198
- f('info', `${j.label}: taken as ${(k.bending / 1e6).toFixed(3)} N·m/mrad in bending, ${shared ? `${j.fitted.item}'s own by finite elements (${(fm.fe / 1e6).toFixed(3)}) times the ${+fm.share.toFixed(3)} a printed ${j.kind} join keeps of it, measured on the joint rig on ${k.measured.bending}` : `${j.fitted.item}'s own by finite elements`} (${fm.linear} N/mm at its screw under ${fm.load} N, ${fm.margin} times under its plastic's strength, ${fm.grams} g), and ${(k.twist / 1e6).toFixed(2)} N·m/mrad in twist at ${ai}'s end ${j.end}: ${shared ? `twist ${k.measured.twist ? `measured on the joint rig on ${k.measured.twist}` : 'an estimate until the rig measures it'}` : 'the slot nuts and lips are not in either, so both are an estimate of the joint until the joint rig (issue 264) measures it'}`, null,
199
- { code: 'join.stiffness', values: { bending: k.bending, twist: k.twist }, refs: { ...refs, item: j.fitted.item, kind_of_value: shared && k.measured.twist ? 'measured' : 'estimate', measured: k.measured, end: k.end, rests: k.rests } });
471
+ const fm = k.fitting,
472
+ shared = fm.shareKind === 'measured';
473
+ f(
474
+ 'info',
475
+ `${j.label}: taken as ${(k.bending / 1e6).toFixed(3)} N·m/mrad in bending, ${shared ? `${j.fitted.item}'s own by finite elements (${(fm.fe / 1e6).toFixed(3)}) times the ${+fm.share.toFixed(3)} a printed ${j.kind} join keeps of it, measured on the joint rig on ${k.measured.bending}` : `${j.fitted.item}'s own by finite elements`} (${fm.linear} N/mm at its screw under ${fm.load} N, ${fm.margin} times under its plastic's strength, ${fm.grams} g), and ${(k.twist / 1e6).toFixed(2)} N·m/mrad in twist at ${ai}'s end ${j.end}: ${shared ? `twist ${k.measured.twist ? `measured on the joint rig on ${k.measured.twist}` : 'an estimate until the rig measures it'}` : 'the slot nuts and lips are not in either, so both are an estimate of the joint until the joint rig (issue 264) measures it'}`,
476
+ null,
477
+ {
478
+ code: 'join.stiffness',
479
+ values: { bending: k.bending, twist: k.twist },
480
+ refs: {
481
+ ...refs,
482
+ item: j.fitted.item,
483
+ kind_of_value: shared && k.measured.twist ? 'measured' : 'estimate',
484
+ measured: k.measured,
485
+ end: k.end,
486
+ rests: k.rests,
487
+ },
488
+ },
489
+ );
200
490
  continue;
201
491
  }
202
- f('info', `${j.label}: taken as ${(k.bending / 1e6).toFixed(2)} N·m/mrad in bending and ${(k.twist / 1e6).toFixed(2)} N·m/mrad in twist at ${ai}'s end ${j.end}${k.printed ? ', a printed fitting\'s share of a bought one\'s' : ''}${k.scale !== 1 ? `, scaled ${+k.scale.toFixed(2)}× for the profile's size` : ''}: ${restsOn(k)}`, null,
203
- { code: 'join.stiffness', values: { bending: k.bending, twist: k.twist }, refs: { ...refs, kind_of_value: k.kind, measured: k.measured, end: k.end, rests: k.rests } });
492
+ f(
493
+ 'info',
494
+ `${j.label}: taken as ${(k.bending / 1e6).toFixed(2)} N·m/mrad in bending and ${(k.twist / 1e6).toFixed(2)} N·m/mrad in twist at ${ai}'s end ${j.end}${k.printed ? ", a printed fitting's share of a bought one's" : ''}${k.scale !== 1 ? `, scaled ${+k.scale.toFixed(2)}× for the profile's size` : ''}: ${restsOn(k)}`,
495
+ null,
496
+ {
497
+ code: 'join.stiffness',
498
+ values: { bending: k.bending, twist: k.twist },
499
+ refs: { ...refs, kind_of_value: k.kind, measured: k.measured, end: k.end, rests: k.rests },
500
+ },
501
+ );
204
502
  }
205
- dropChecks(s, f, worlds);
206
503
  // every beam end joined or capped
207
- const ends = covered(s), beams = s.objects.filter((o) => o.beam && !o.unplaced && ids.includes(o.id)), open = [];
504
+ const ends = covered(s),
505
+ beams = s.objects.filter((o) => o.beam && !o.unplaced && ids.includes(o.id)),
506
+ open = [];
208
507
  for (const o of beams) for (const e of ['a', 'b']) if (!ends.has(`${o.id}.${e}`)) open.push(`${o.id}.${e}`);
209
- if (open.length) f('warn', `${open.length} beam end${open.length > 1 ? 's are' : ' is'} neither joined nor capped: ${open.join(', ')}. Give each a join, or an item at the end (an end cap or a foot, ${'"at": "' + open[0] + '"'})`, `${open.length} open end${open.length > 1 ? 's' : ''}`, { code: 'join.end', values: { open: open.length }, refs: { ends: open } });
508
+ if (open.length)
509
+ f(
510
+ 'warn',
511
+ `${open.length} beam end${open.length > 1 ? 's are' : ' is'} neither joined nor capped: ${open.join(', ')}. Give each a join, or an item at the end (an end cap or a foot, ${'"at": "' + open[0] + '"'})`,
512
+ `${open.length} open end${open.length > 1 ? 's' : ''}`,
513
+ { code: 'join.end', values: { open: open.length }, refs: { ends: open } },
514
+ );
210
515
  else f('pass', `every beam end is joined or capped (${beams.length * 2} ends)`, null, { code: 'join.end' });
211
516
  }
212
517
 
518
+ // what a beam carries: items placed on it, and on those, and so on
519
+ function carriedBy(items, id) {
520
+ const on = new Set([id]);
521
+ for (let grew = true; grew;) {
522
+ grew = false;
523
+ for (const it of items) {
524
+ const at = typeof it.at === 'string' ? it.at.trim().split('.')[0] : null;
525
+ if (at && on.has(at) && !on.has(it.id)) {
526
+ on.add(it.id);
527
+ grew = true;
528
+ }
529
+ }
530
+ }
531
+ return on;
532
+ }
533
+
534
+ // a support said on the beam, or a foot fitted to one of its ends
535
+ function supportsOn(a, id, mine) {
536
+ const out = [];
537
+ for (const addr of Object.keys(a.frame?.supports ?? {})) if (mine(addr)) out.push(`the support at ${addr}`);
538
+ for (const it of a.items || []) {
539
+ const kind = it.fitting?.kind ?? (it.bought && /foot|castor/i.test(it.bought) ? 'foot' : null),
540
+ m = typeof it.at === 'string' ? /^([\w-]+)\.([ab])(\.\d+)?$/.exec(it.at.trim()) : null;
541
+ if (m && m[1] === id && /foot|castor/.test(kind ?? '')) out.push(`${it.id}, a ${kind}`);
542
+ }
543
+ return out;
544
+ }
545
+
546
+ // a fasten, a fit or a joint between what the beam carries (mine) and a part it does not (off), leaving out the joins'
547
+ // own screws and a fasten's own fits (its screw's and its nut's: the fasten's)
548
+ function partsHolding(s, mine, off) {
549
+ const out = [],
550
+ a = s.a,
551
+ joins = new Set(s.joins.flatMap((x) => x.fasten ?? []));
552
+ (a.fasten || []).forEach((x, i) => {
553
+ if (joins.has(i) || !x) return;
554
+ const parts = [x.into, ...(Array.isArray(x.through) ? x.through : [])];
555
+ if (parts.some(mine) && parts.some(off)) out.push(x.note ?? `the fasten of ${parts.filter(Boolean).join(', ')}`);
556
+ });
557
+ for (const x of s.fits || [])
558
+ if (x.fasten == null && ((mine(x.a) && off(x.b)) || (mine(x.b) && off(x.a))))
559
+ out.push(x.label ?? `the fit of ${x.a} and ${x.b}`);
560
+ for (const x of a.joints || []) if (mine(x.child) && off(x.parent)) out.push(`joint ${x.id}`);
561
+ return out;
562
+ }
563
+
213
564
  /**
214
- * join.drop: a beam held by one join at one end and by nothing else, a mass hung on it (on the beam, or on an item placed
215
- * on it), is a cantilever from that join, as on the joint rig. Its drop under the mass is the beam's own bending and the
216
- * join's turning: d = F L³ / (3 E I) + F L² / k, L from b's face to the load along the beam, E I the beam's across the
217
- * load, k the join's bending spring. Each is a prediction cad measured takes (<beam>.drop=<mm>): the measured drop less
218
- * the beam's own gives the join's spring, F L² / (d - F L³ / 3 E I), written to the rule the spring came from.
219
- * @param {object} s a built assembly @param {Function} f the findings' sink @param {number[][]} worlds each item's place
565
+ * What holds a beam besides one join at its end, in words: another join, a support or a foot on it, a fasten or a fit
566
+ * between it (or an item it carries) and a part it does not carry, or a joint that mounts it (or an item it carries)
567
+ * on such a part. A beam held by any of these is no cantilever from the join, so it gets no join.drop. The join's own
568
+ * screws and fitting, and the items the beam carries (a hanger, the mass's hook), hold nothing else.
569
+ * @param {object} s a built assembly @param {object} j one of s.joins @param {string} id the beam it holds at an end
570
+ * @returns {string[]} each thing that also holds it, as the assembly names it
220
571
  */
221
- function dropChecks(s, f, worlds) {
222
- const loads = (s.motion.loads || []).map((l, i) => ({ ...l, at: s.a.loads?.[i]?.at })).filter((l) => l.mass != null), ids = s.motion.items.map((x) => x[0]);
572
+ export function heldElsewhere(s, j, id) {
573
+ const on = carriedBy(s.a.items || [], id),
574
+ first = (n) => (typeof n === 'string' ? n.trim().split('.')[0] : null),
575
+ mine = (n) => on.has(first(n)),
576
+ off = (n) => first(n) != null && !on.has(first(n));
577
+ const out = [
578
+ ...s.joins.filter((x) => x !== j && x.items.includes(id)).map((x) => x.label),
579
+ ...supportsOn(s.a, id, mine),
580
+ ...partsHolding(s, mine, off),
581
+ ];
582
+ return [...new Set(out)];
583
+ }
584
+
585
+ const at4 = (W, p) => [0, 1, 2].map((r) => W[4 * r] * p[0] + W[4 * r + 1] * p[1] + W[4 * r + 2] * p[2] + W[4 * r + 3]),
586
+ along4 = (W, v) => [0, 1, 2].map((r) => W[4 * r] * v[0] + W[4 * r + 1] * v[1] + W[4 * r + 2] * v[2]);
587
+
588
+ // whether a beam lies along the bench, as the joint rig's base beam does: both its ends at the assembly's lowest
589
+ function benchOf(s, worlds, ids, down) {
590
+ const height = new Map();
591
+ for (const o of s.objects) {
592
+ const W = worlds[ids.indexOf(o.id)];
593
+ if (!o.beam || o.unplaced || !W) continue;
594
+ height.set(
595
+ o.id,
596
+ [at4(W, [0, 0, 0]), at4(W, [0, 0, o.beam.length])].map((p) => -dot(p, down)),
597
+ );
598
+ }
599
+ const lowest = Math.min(...[...height.values()].flat());
600
+ return (id) => height.has(id) && height.get(id).every((h) => h <= lowest + 1);
601
+ }
602
+
603
+ // a load on a beam held out from a join: where it is, how far out along the beam, the force across it, and which of
604
+ // the section's axes it bends about (dx, dy: its share along the section's x and y); null where it is not out along it
605
+ function loadOut(W, len, e, P, l, down) {
606
+ const root = at4(W, [0, 0, e === 'a' ? 0 : len]),
607
+ tip = at4(W, [0, 0, e === 'a' ? len : 0]);
608
+ const u = [0, 1, 2].map((c) => (tip[c] - root[c]) / len),
609
+ sx = along4(W, [1, 0, 0]),
610
+ sy = along4(W, [0, 1, 0]);
611
+ const L = dot(sub(P, root), u),
612
+ across = down.map((c, q) => c - u[q] * dot(down, u)),
613
+ share = Math.hypot(...across);
614
+ if (!(L > 0) || !(share > 1e-6)) return null;
615
+ return { L, F: l.mass * 9.80665 * share, dx: dot(across, sx) / share, dy: dot(across, sy) / share };
616
+ }
617
+
618
+ // the frame's own solve of a load on the beam a join holds out, where the solve has both beams and the load on it; the
619
+ // joins whose spring comes from the same rule move with it (together: each one's spring as a multiple of this one's)
620
+ function solvedFor(fm, j, l, together) {
621
+ const [id, host] = j.items;
622
+ if (!fm.beams.has(id) || !fm.beams.has(host)) return null;
623
+ const fl = fm.loads.find((x) => x.index === l.index);
624
+ return fl && (fl.beam ?? fl.mount?.beam)?.id === id ? joinDropOf(fm, j.index, fl, together) : null;
625
+ }
626
+
627
+ // the other joins whose bending spring is written to the same rule as j's, each with its spring as a multiple of j's:
628
+ // a figure written back moves them all, so the spring is worked out with them all moving
629
+ function sameRule(s, j, rule) {
630
+ const out = new Map();
631
+ for (const q of s.joins) {
632
+ if (q === j) continue;
633
+ const r = writesTo(q);
634
+ if (r.rule === rule.rule && r.per > 0) out.set(q.index, rule.per / r.per);
635
+ }
636
+ return out;
637
+ }
638
+
639
+ // the drop from the frame's own solve: with the join's spring, and with the join held rigid; null where it is not solved
640
+ function frameDrop(at, k) {
641
+ let drop, rigid;
642
+ try {
643
+ drop = at.dropAt(k);
644
+ rigid = at.dropAt(Infinity);
645
+ } catch {
646
+ return null; // (the solve refused the load alone: the drop is not predicted, and the finding says so)
647
+ }
648
+ return Number.isFinite(drop) && Number.isFinite(rigid) ? { drop, rigid } : null;
649
+ }
650
+
651
+ /**
652
+ * join.drop: a beam held by one join at one end and by nothing else (heldElsewhere), a mass hung on it (on the beam, or
653
+ * on an item placed on it). Its drop under the mass is a prediction cad measured takes (<beam>.drop=<mm>) and works back
654
+ * to the join's bending spring, written to the rule the spring came from.
655
+ *
656
+ * Where the frame is solved on supports it is given (frame.supports, or its feet), the drop is the frame's own: the load
657
+ * alone (the dial set to 0 with the hook on), with the join's spring, and with the join held rigid, the difference
658
+ * being the join's turning. Every other join whose spring is written to the same rule moves with it in that solve
659
+ * (sameRule), since a figure written back moves them all: so the spring found gives the drop read once it is written. So a post the join hangs from bends and turns in it too, and cad measured finds the spring
660
+ * that gives the drop read by solving the frame again (joinDropOf, springFor).
661
+ *
662
+ * Where it is not (no supports said: the joint rig, whose base beam is clamped to the bench), the beam it hangs from is
663
+ * taken as held along its length, and only where it lies along the bench, its whole length at the assembly's lowest:
664
+ * d = F L³ / (3 E I) + F L² / k, L from b's face to the load along the beam, E I the beam's across the load, k the
665
+ * join's bending spring. Anywhere else the drop is not predicted, and the finding says how to have it predicted.
666
+ * @param {object} s a built assembly @param {Function} f the findings' sink
667
+ * @param {{ model: object } | null} frame what frameChecks gave: the frame's model where it was solved
668
+ */
669
+ export function joinDropChecks(s, f, frame) {
670
+ if (!s.joins?.length) return;
671
+ const loads = (s.motion.loads || [])
672
+ .map((l, i) => ({ ...l, index: i, at: s.a.loads?.[i]?.at }))
673
+ .filter((l) => l.mass != null),
674
+ ids = s.motion.items.map((x) => x[0]);
223
675
  if (!loads.length) return;
224
- const items = s.a.items || [], G = s.motion.gravity, g = Math.hypot(...G) || 1, down = G.map((c) => c / g);
225
- const pt = (W, p) => [0, 1, 2].map((r) => W[4 * r] * p[0] + W[4 * r + 1] * p[1] + W[4 * r + 2] * p[2] + W[4 * r + 3]);
226
- const dir = (W, v) => [0, 1, 2].map((r) => W[4 * r] * v[0] + W[4 * r + 1] * v[1] + W[4 * r + 2] * v[2]);
676
+ const worlds = placeItems(s.motion, s.jointValues),
677
+ G = s.motion.gravity,
678
+ g = Math.hypot(...G) || 1,
679
+ down = G.map((c) => c / g);
680
+ // the frame's solve, where it rests on supports given (not guessed at its lowest ends)
681
+ const fm = frame?.model,
682
+ solved = fm?.supports?.length && fm.supports.every((x) => !x.why.startsWith('a lowest end')) ? fm : null,
683
+ onBench = benchOf(s, worlds, ids, down);
227
684
  for (const j of s.joins) {
228
- const [id] = j.items, e = j.end[0], other = e === 'a' ? 'b' : 'a';
229
- // held by this join alone: in no other join, as a or b
230
- if (s.joins.some((x) => x !== j && x.items.includes(id))) continue;
231
- const on = new Set([id, ...items.filter((it) => typeof it.at === 'string' && it.at.trim().startsWith(`${id}.`)).map((it) => it.id)]);
232
- const mine = loads.filter((l) => on.has(ids[l.item]));
233
- if (!mine.length) continue;
234
- const beam = s.objects.find((o) => o.id === id)?.beam, W = worlds[ids.indexOf(id)], fig = beam?.figures, mat = beam?.material;
235
- const E = mat?.modulus, Ix = fig?.inertiaX?.value, Iy = fig?.inertiaY?.value, k = j.model.stiffness.bending;
236
- if (!(E > 0 && Ix > 0 && Iy > 0 && W)) { f('info', `${j.label}: ${id} hangs from this join alone, but its profile gives no second moments or its material no modulus, so its drop is not predicted`, null, { code: 'join.drop', refs: { join: j.index, beam: id } }); continue; }
237
- const len = beam.length, root = pt(W, [0, 0, e === 'a' ? 0 : len]), tip = pt(W, [0, 0, e === 'a' ? len : 0]);
238
- const u = [0, 1, 2].map((c) => (tip[c] - root[c]) / len), sx = dir(W, [1, 0, 0]), sy = dir(W, [0, 1, 0]);
239
- for (const l of mine) {
240
- const P = pt(worlds[l.item], [l.frame[3], l.frame[7], l.frame[11]]), L = [0, 1, 2].reduce((a, c) => a + (P[c] - root[c]) * u[c], 0);
241
- const across = down.map((c, q) => c - u[q] * [0, 1, 2].reduce((a, r) => a + down[r] * u[r], 0)), share = Math.hypot(...across);
242
- const F = l.mass * 9.80665 * share, dx = [0, 1, 2].reduce((a, c) => a + across[c] * sx[c], 0) / (share || 1), dy = [0, 1, 2].reduce((a, c) => a + across[c] * sy[c], 0) / (share || 1);
243
- if (!(L > 0) || !(share > 1e-6)) continue;
244
- const beamDrop = ((F * L ** 3) / (3 * E)) * (dx * dx / Iy + dy * dy / Ix), joinDrop = (F * L * L) / k, drop = beamDrop + joinDrop;
245
- const rule = writesTo(j), name = `${id}.drop`, where = l.at ?? `${id}`;
246
- const trust = restsOn(j.model.stiffness);
247
- f('info', `${j.label}: ${id} hangs from it alone, so ${l.mass} kg at ${where}, ${mm(L)} mm out from ${j.items[1]}'s face, drops it ${n3(drop)} mm: ${n3(beamDrop)} mm the beam's own bending (E ${E} MPa, I ${Math.round(dx * dx > 0.5 ? Iy : Ix)} mm⁴) and ${n3(joinDrop)} mm the join turning on its ${(k / 1e6).toFixed(3)} N·m/mrad spring (${trust}). Measure it with a dial indicator and write it back: cad measured ${s.project}/${s.name} ${name}=<mm>, and the spring goes to ${rule.rule}`, null,
248
- { code: 'join.drop', at: P.map(r3), values: { drop: n3(drop), beam: n3(beamDrop), join: n3(joinDrop), force: n3(F), arm: n3(L), bending: k },
249
- predict: { name, figure: `drop of ${id} at ${where} under ${l.mass} kg`, value: n3(drop), unit: 'mm', rig: { force: F, arm: L, beam: beamDrop, spring: k, rule: rule.rule, per: rule.per, unit: rule.unit, what: rule.what, join: j.label } },
250
- refs: { join: j.index, kind: j.kind, beam: id, rule: rule.rule } });
685
+ const [id] = j.items;
686
+ if (heldElsewhere(s, j, id).length) continue;
687
+ const on = carriedBy(s.a.items || [], id),
688
+ mine = loads.filter((l) => on.has(ids[l.item]));
689
+ if (mine.length) dropOfJoin(s, f, j, mine, { worlds, ids, down, solved, onBench });
690
+ }
691
+ }
692
+
693
+ // one join's join.drop findings, a load at a time
694
+ function dropOfJoin(s, f, j, mine, { worlds, ids, down, solved, onBench }) {
695
+ const [id, host] = j.items,
696
+ beam = s.objects.find((o) => o.id === id)?.beam,
697
+ W = worlds[ids.indexOf(id)],
698
+ E = beam?.material?.modulus,
699
+ Ix = beam?.figures?.inertiaX?.value,
700
+ Iy = beam?.figures?.inertiaY?.value,
701
+ k = j.model.stiffness.bending;
702
+ if (!(E > 0 && Ix > 0 && Iy > 0 && W)) {
703
+ f(
704
+ 'info',
705
+ `${j.label}: ${id} hangs from this join alone, but its profile gives no second moments or its material no modulus, so its drop is not predicted`,
706
+ null,
707
+ { code: 'join.drop', refs: { join: j.index, beam: id } },
708
+ );
709
+ return;
710
+ }
711
+ const rule = writesTo(j),
712
+ name = `${id}.drop`,
713
+ spring = `${(k / 1e6).toFixed(3)} N·m/mrad spring (${restsOn(j.model.stiffness)})`,
714
+ back = `Measure it with a dial indicator and write it back: cad measured ${s.project}/${s.name} ${name}=<mm>, and the spring goes to ${rule.rule}`,
715
+ together = solved ? sameRule(s, j, rule) : new Map(),
716
+ others = together.size,
717
+ held = others
718
+ ? `this join and the ${others} other${others > 1 ? 's' : ''} whose spring is ${rule.rule} held rigid`
719
+ : 'this join held rigid',
720
+ turns = others
721
+ ? `the joins turning on that rule's figure (this one's ${spring})`
722
+ : `the join turning on its ${spring}`;
723
+ let unsaid = false;
724
+ for (const l of mine) {
725
+ const P = at4(worlds[l.item], [l.frame[3], l.frame[7], l.frame[11]]),
726
+ out = loadOut(W, beam.length, j.end[0], P, l, down);
727
+ if (!out) continue;
728
+ const { L, F, dx, dy } = out,
729
+ where = l.at ?? `${id}`,
730
+ said = `${j.label}: ${id} hangs from it alone, so ${l.mass} kg at ${where}, ${mm(L)} mm out from ${host}'s face, drops it`,
731
+ rig = { force: F, arm: L, rule: rule.rule, per: rule.per, unit: rule.unit, what: rule.what, join: j.label };
732
+ // the frame's own solve: the load alone, with the join's spring and with the join rigid
733
+ const at = solved && solvedFor(solved, j, l, together),
734
+ fd = at && frameDrop(at, k);
735
+ let drop, values, text;
736
+ if (fd) {
737
+ const turning = fd.drop - fd.rigid;
738
+ drop = fd.drop;
739
+ values = { drop: n3(drop), rigid: n3(fd.rigid), join: n3(turning), force: n3(F), arm: n3(L), bending: k };
740
+ Object.assign(rig, { rigid: fd.rigid, from: 'frame', spring: k, others });
741
+ Object.defineProperty(rig, 'dropAt', { value: at.dropAt, enumerable: false });
742
+ text = `${said} ${n3(drop)} mm in the frame's own solve, held at ${solved.supports.map((x) => x.where).join(', ')}: ${n3(fd.rigid)} mm with ${held} (the beam's own bending and all the frame gives under it) and ${n3(turning)} mm more from ${turns}. ${back}, worked out from the same solve`;
743
+ } else if (!at && onBench(host)) {
744
+ const beamDrop = ((F * L ** 3) / (3 * E)) * ((dx * dx) / Iy + (dy * dy) / Ix),
745
+ joinDrop = (F * L * L) / k,
746
+ I = Math.round(dx * dx > 0.5 ? Iy : Ix);
747
+ drop = beamDrop + joinDrop;
748
+ values = { drop: n3(drop), beam: n3(beamDrop), join: n3(joinDrop), force: n3(F), arm: n3(L), bending: k };
749
+ Object.assign(rig, { beam: beamDrop, rigid: beamDrop, from: 'rig', spring: k });
750
+ Object.defineProperty(rig, 'dropAt', { value: (q) => beamDrop + (F * L * L) / q, enumerable: false });
751
+ text = `${said} ${n3(drop)} mm: ${n3(beamDrop)} mm the beam's own bending (E ${E} MPa, I ${I} mm⁴) and ${n3(joinDrop)} mm the join turning on its ${spring}. This takes ${host} as held along its length, clamped to the bench as the joint rig's base beam is, since the frame is not solved on supports it is given; on any other frame say how it is held ("frame": { "supports" }) and the drop is taken from the frame's solve. ${back}`;
752
+ } else {
753
+ unsaid = true;
754
+ continue;
755
+ }
756
+ f('info', text, null, {
757
+ code: 'join.drop',
758
+ at: P.map(r3),
759
+ values,
760
+ predict: { name, figure: `drop of ${id} at ${where} under ${l.mass} kg`, value: n3(drop), unit: 'mm', rig },
761
+ refs: { join: j.index, kind: j.kind, beam: id, rule: rule.rule, from: rig.from },
762
+ });
763
+ }
764
+ if (unsaid)
765
+ f(
766
+ 'info',
767
+ `${j.label}: ${id} hangs from this join alone, but its drop is not predicted: ${solved ? `the frame's solve does not reach ${id} and ${host}, or does not hold under the load alone` : `the frame is not solved on supports it is given, and ${host} does not lie along the bench as the joint rig's base beam does, so how much it gives under the load is not known`}. Say how the frame is held ("frame": { "supports": { "${host}.a": "fixed" } }, or fit its feet) and the drop is taken from the frame's solve`,
768
+ null,
769
+ { code: 'join.drop', refs: { join: j.index, beam: id } },
770
+ );
771
+ }
772
+
773
+ /**
774
+ * The bending spring that makes a join.drop prediction's drop the one measured: a bisection over the spring's give (one
775
+ * over the spring), solving the drop afresh each step (the frame's solve, or the rig's closed form), at most `steps`
776
+ * times. Refused, with why, where no spring can give it: a drop no more than the beam with the join rigid, or more than
777
+ * the join gives at its softest.
778
+ * @param {{ dropAt: (bending: number) => number, rigid: number, spring: number }} rig the prediction's rig
779
+ * @param {number} drop the drop measured, mm @param {number} [steps]
780
+ * @returns {{ spring: number } | { refused: 'stiff' | 'soft' | 'unsolved', most?: number }}
781
+ */
782
+ export function springFor(rig, drop, steps = 80) {
783
+ if (!(drop > rig.rigid)) return { refused: 'stiff' };
784
+ const at = (give) => {
785
+ try {
786
+ const d = rig.dropAt(1 / give);
787
+ return Number.isFinite(d) ? d : NaN;
788
+ } catch {
789
+ return NaN;
251
790
  }
791
+ };
792
+ // the give that drops it at least as far: from the spring as it is, four times softer each step, to a millionth of it
793
+ let lo = 0,
794
+ hi = 1 / rig.spring,
795
+ most = at(hi),
796
+ n = 0;
797
+ while (most < drop && n < 10) {
798
+ lo = hi;
799
+ hi *= 4;
800
+ most = at(hi);
801
+ n++;
802
+ }
803
+ if (Number.isNaN(most)) return { refused: 'unsolved' };
804
+ if (most < drop) return { refused: 'soft', most };
805
+ for (; n < steps && hi - lo > 1e-12 * hi; n++) {
806
+ const mid = (lo + hi) / 2,
807
+ d = at(mid);
808
+ if (Number.isNaN(d)) return { refused: 'unsolved' };
809
+ if (d < drop) lo = mid;
810
+ else hi = mid;
252
811
  }
812
+ if (hi - lo > 1e-6 * hi) return { refused: 'unsolved' };
813
+ return { spring: 2 / (lo + hi) };
253
814
  }
254
815
  const n3 = (x) => +Number(x).toFixed(3);
255
816
 
256
817
  // The rule a join's measured spring is written to, and what to multiply the spring by to get it: a bought fitting's own
257
818
  // bending_stiffness; a printed fitting's share of its finite-element figure; else the kind's figure for a 20 mm profile
258
819
  function writesTo(j) {
259
- const k = j.model.stiffness, key = j.kind.replace(/-/g, '_');
260
- if (k.bought) return { rule: `${k.bought.set}.bending_stiffness`, per: 1, unit: 'N mm/rad', what: `${k.bought.set}'s bending stiffness, holding a beam's end` };
261
- if (k.fitting) return { rule: `joins.${key}_printed_share`, per: 1 / k.fitting.fe, unit: '', what: `a ${j.kind} join with a printed fitting, as a share of the fitting's own bending stiffness by finite elements (${(k.fitting.fe / 1e6).toFixed(3)} N·m/mrad for ${k.fitting.name})` };
262
- return { rule: `joins.${key}_bending`, per: 1 / ((k.scale ?? 1) * (k.printed ? JOIN_SCALE.printed.value : 1)), unit: 'N mm/rad', what: `a ${j.kind} join's bending stiffness, for a 20 mm series profile` };
820
+ const k = j.model.stiffness,
821
+ key = j.kind.replace(/-/g, '_');
822
+ if (k.bought)
823
+ return {
824
+ rule: `${k.bought.set}.bending_stiffness`,
825
+ per: 1,
826
+ unit: 'N mm/rad',
827
+ what: `${k.bought.set}'s bending stiffness, holding a beam's end`,
828
+ };
829
+ if (k.fitting)
830
+ return {
831
+ rule: `joins.${key}_printed_share`,
832
+ per: 1 / k.fitting.fe,
833
+ unit: '',
834
+ what: `a ${j.kind} join with a printed fitting, as a share of the fitting's own bending stiffness by finite elements (${(k.fitting.fe / 1e6).toFixed(3)} N·m/mrad for ${k.fitting.name})`,
835
+ };
836
+ return {
837
+ rule: `joins.${key}_bending`,
838
+ per: 1 / ((k.scale ?? 1) * (k.printed ? JOIN_SCALE.printed.value : 1)),
839
+ unit: 'N mm/rad',
840
+ what: `a ${j.kind} join's bending stiffness, for a 20 mm series profile`,
841
+ };
263
842
  }