@rulecad/cad 0.7.57 → 0.7.59

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/lib/fittings.mjs CHANGED
@@ -27,6 +27,7 @@ const MORE = {
27
27
  'device-mount': ['deviceMountModel', 'deviceMount'], 'fan-mount': ['fanMountModel', 'fanMount'], 'drag-chain-end': ['dragChainEndModel', 'dragChainEnd'], 'din-rail': ['dinRailAdapterModel', 'dinRailAdapter'],
28
28
  'cable-clip': ['cableClipModel', 'cableClip'], 'tie-anchor': ['tieAnchorModel', 'tieAnchor'], 'spool-holder': ['spoolHolderModel', 'spoolHolder'],
29
29
  'rail-jig': ['railJigModel', 'railJig'], 'wheel-plate': ['wheelsModel', 'wheelPlate'], slider: ['sliderModel', 'slider'],
30
+ 'nut-carrier': ['carrierModel', 'carrier', { pose: { fit: 'slot', print: 'print' } }],
30
31
  'rod-holder': ['rodHolderModel', 'rodHolder'], 'rod-carriage': ['rodCarriageModel', 'rodCarriage'], 'motor-plate': ['motorPlateModel', 'motorPlate'], 'endstop-mount': ['endstopMountModel', 'endstopMount'],
31
32
  };
32
33
  // the kinds whose tongue or stem stands in the slot, inside the beam's envelope: the overlap check measures them without it
@@ -69,6 +70,25 @@ export function plasticOf(project) {
69
70
  throw new Error(`project ${project}: its material is ${JSON.stringify(raw)}, and printed fittings are sized from their plastic's strength, modulus and density: ${set ? `rules/${m}.json gives no ${lacks.join(', ')}` : `the kit has pla and petg, and there is no rules/${m}.json`}. Give rules/${m}.json with all three, or set the material to pla or petg`);
70
71
  }
71
72
 
73
+ /**
74
+ * The printed parts that come with a fitting the assembly places one part of: a printed levelling foot's pad, where an
75
+ * item places its body and none its pad at the same address (a generated frame's feet). The pad is printed and screwed
76
+ * in by hand once the body is on, so it goes on a plate and on the list, and is not placed in the model.
77
+ * @param {object} s a built assembly @returns {{ id: string, of: string, fitting: object, grams: number }[]}
78
+ */
79
+ export function companions(s) {
80
+ const items = s.items ?? [], out = [];
81
+ for (const o of s.objects) {
82
+ if (o.unplaced || o.fitting?.fitting !== 'levelling-foot' || !o.fitting.printed) continue;
83
+ const it = items.find((x) => x.id === o.id);
84
+ if (!it?.fitting || (it.fitting.part ?? 'body') !== 'body') continue;
85
+ if (items.some((x) => x.fitting?.kind === 'levelling-foot' && x.fitting.part === 'pad' && JSON.stringify(x.at) === JSON.stringify(it.at))) continue;
86
+ const { pose, ...spec } = it.fitting;
87
+ out.push({ id: `${o.id}-pad`, of: o.id, fitting: { ...spec, part: 'pad' }, grams: o.fitting.padGrams });
88
+ }
89
+ return out;
90
+ }
91
+
72
92
  /**
73
93
  * A fitting's model from an item's "fitting" (or a join's), refused by name where a key is not one it takes.
74
94
  * @param {object} spec { kind: bracket | gusset | splice, profile, other, face, otherFace, shape, brace, load, count, thread, head, nut }
@@ -83,7 +103,7 @@ export function fittingModel(spec, context, material = 'pla', what = 'fitting')
83
103
  for (const k of ['thread', 'head', 'nut', 'load']) if (spec[k] != null) o[k] = spec[k];
84
104
  try {
85
105
  if (spec.kind === 'bracket') return bracketModel(spec.profile, { ...o, ...(spec.other ? { other: spec.other } : {}), ...(spec.face ? { face: spec.face } : {}), ...(spec.otherFace ? { otherFace: spec.otherFace } : {}), ...(spec.brace != null ? { brace: spec.brace } : {}) });
86
- return plateModel(spec.profile, { ...o, shape: spec.kind === 'splice' ? 'splice' : spec.shape ?? 'L', ...(spec.face ? { face: spec.face } : {}), ...(spec.count != null ? { count: spec.count } : {}) });
106
+ return plateModel(spec.profile, { ...o, shape: spec.kind === 'splice' ? 'splice' : spec.shape ?? 'L', ...(spec.other ? { other: spec.other } : {}), ...(spec.face ? { face: spec.face } : {}), ...(spec.count != null ? { count: spec.count } : {}) });
87
107
  } catch (e) { throw new Error(`${what}: ${strip(e)}`); }
88
108
  }
89
109
 
@@ -99,8 +119,12 @@ function moreModel(spec, context, material, what) {
99
119
  if (o.profile !== false && typeof profile !== 'string') throw new Error(`${what}: a ${kind} is drawn for a profile: give "profile", as 2020-misumi-hfs5 (got ${shown(profile)})`);
100
120
  if (o.profile === false && profile != null) throw new Error(`${what}: a ${kind} is drawn for no profile: leave profile out`);
101
121
  // (a gasket strip is PETG, which springs back, unless the item says otherwise; the rest take the project's plastic)
102
- try { return o.profile === false ? frames[model]({ ...(kind === 'gasket-strip' ? {} : { material }), ...rest }) : frames[model](profile, { given: givenFor(context, profile), material, ...rest }); }
103
- catch (e) { throw new Error(`${what}: ${String(e?.message ?? e).replace(/^\w+: /, '')}`); }
122
+ try {
123
+ const m = o.profile === false ? frames[model]({ ...(kind === 'gasket-strip' ? {} : { material }), ...rest }) : frames[model](profile, { given: givenFor(context, profile), material, ...rest });
124
+ // (a printed carrier in a slot is its own kind of model: named here as a fitting, with the nut or insert it holds to buy)
125
+ if (kind === 'nut-carrier') return { ...m, fitting: 'nut-carrier', hardware: [{ kind: m.holds === 'insert' ? 'insert' : 'nut', name: `${m.thread} ${m.holds === 'insert' ? 'heat-set insert' : 'hex nut'}`, thread: m.thread, count: m.count ?? 1, why: `held in the carrier, ${m.holds === 'insert' ? 'pressed in from below' : 'slid in from the side'}` }] };
126
+ return m;
127
+ } catch (e) { throw new Error(`${what}: ${String(e?.message ?? e).replace(/^\w+: /, '')}`); }
104
128
  }
105
129
 
106
130
  /**
@@ -136,7 +160,7 @@ export async function fittingBuilt(it, id, context, material = 'pla') {
136
160
  // door leaf's, through the door); a hinge's door leaf and a levelling foot's pad carry no findings or hardware of their own
137
161
  function moreBuilt(it, id, m, ops, pose = 'fit') {
138
162
  const [, solid, o = {}] = MORE[it.fitting.kind], part = it.fitting.part ?? o.parts?.[0], second = o.parts && part !== o.parts[0];
139
- const draw = (x) => { const f = (y) => frames[solid](m, { pose, ...(part ? { part } : {}), ...x, ...y }); try { return f(ops ? { ops } : {}); } catch { return f({}); } };
163
+ const drawn = o.pose?.[pose] ?? pose, draw = (x) => { const f = (y) => frames[solid](m, { pose: drawn, ...(part ? { part } : {}), ...x, ...y }); try { return f(ops ? { ops } : {}); } catch { return f({}); } };
140
164
  const parts = named({ body: draw({}) }, { body: { label: `${m.title}${part ? `, ${part}` : ''}` } });
141
165
  if (TONGUED.includes(m.fitting) && pose === 'fit') parts[0].collide = named({ body: draw({ tongues: false }) }, {})[0].geometry;
142
166
  if (IN_SLOT.includes(m.fitting) && pose === 'fit') { const { intersect } = jscad.booleans, { cuboid } = jscad.primitives, above = intersect(parts[0].geometry, cuboid({ size: [1e4, 1e4, 1e3], center: [0, 0, 500] })); parts[0].collide = above; }
@@ -220,11 +244,23 @@ export function joinFitting(j, i, { ia, ib, A, B, m, ends, place: placeOf }, num
220
244
  shapeAt = { room };
221
245
  x = ub.map((c) => (room.b >= room.a ? c : -c)); y = ua; n = cross(x, y);
222
246
  }
247
+ // a gusset on the other face of b (j.face): the same L turned over its diagonal, its arm drawn for b along a and its
248
+ // arm drawn for a along b, so it lies on the faces looking along -n (a mirror image of the L is itself turned so)
249
+ let flip = false;
250
+ if (j.face != null) {
251
+ const want = B.places.find((q) => q.slot && (q.name === j.face || (q.face === j.face && q.name.endsWith('.1'))));
252
+ const along = want ? dot(turn(fb, [...want.normal, 0]), n) : 0;
253
+ if (!want || Math.abs(Math.abs(along) - 1) > 1e-6) {
254
+ const can = B.places.filter((q) => q.slot && Math.abs(Math.abs(dot(turn(fb, [...q.normal, 0]), n)) - 1) < 1e-6).map((q) => faceOf(B, q));
255
+ throw new Error(`${what}: face is the face of ${ib.id} a printed gusset lies on, square to ${ia.id}: ${[...new Set(can)].join(' or ') || 'none of its slotted faces is'} (got ${JSON.stringify(j.face)})`);
256
+ }
257
+ if (along < 0) { flip = true; n = n.map((c) => -c); }
258
+ }
223
259
  const bq = B.places.find((q) => q.slot && dot(turn(fb, [...q.normal, 0]), n) > 1 - 1e-6), aq = A.places.find((q) => q.slot && dot(turn(fa, [...q.normal, 0]), n) > 1 - 1e-6);
224
260
  if (!bq || !aq) throw new Error(`${what}: a printed ${splice ? 'splice plate' : 'gusset'} lies on a slotted face of both beams that looks the same way, and ${!bq ? ib.id : ia.id} has none that does: turn it with roll`);
225
261
  const Pb = world(fb, [bq.at[0], bq.at[1], d]), Qa = world(fa, [aq.at[0], aq.at[1], 0]), apart = dot(sub(Qa, Pb), n);
226
262
  if (Math.abs(apart) > 0.05) throw new Error(`${what}: a printed ${splice ? 'splice plate' : 'gusset'} lies flat on both beams, and ${ia.id}'s ${aq.face} face stands ${mm(Math.abs(apart))} mm ${apart > 0 ? 'proud of' : 'below'} ${ib.id}'s ${bq.face} face`);
227
- const spec0 = { kind: splice ? 'splice' : 'gusset', profile: B.profile.name, face: faceOf(B, bq), ...(j.load != null ? { load: j.load } : {}), ...(j.nut ? { nut: j.nut } : {}) };
263
+ const spec0 = { kind: splice ? 'splice' : 'gusset', profile: B.profile.name, ...(A.profile.name !== B.profile.name ? { other: A.profile.name } : {}), face: faceOf(B, bq), ...(j.load != null ? { load: j.load } : {}), ...(j.nut ? { nut: j.nut } : {}) };
228
264
  let fm = bm ?? fittingModel({ ...spec0, ...(splice ? {} : { shape: 'L' }) }, context, material, what), shape = bm?.shape ?? 'L';
229
265
  if (bm) {
230
266
  // a bought plate's shape is its set's: a T needs room along b both sides of a, an L on one
@@ -234,17 +270,23 @@ export function joinFitting(j, i, { ia, ib, A, B, m, ends, place: placeOf }, num
234
270
  const item = { id, bought: bm.set, at: `${ib.id}.${bq.name}@${r3(d)}`, ...(along ? {} : { rotate: [0, 0, 180] }), join: i };
235
271
  return { item, fasten: boughtFasten(id, [['b', ib.id, bq.name], ['a', ia.id, aq.name]]), model: bm };
236
272
  }
273
+ if (flip && (A.profile.name !== B.profile.name || aq.slot !== bq.slot)) throw new Error(`${what}: a printed gusset turned onto ${ib.id}'s ${j.face} face puts the arm drawn for ${ib.id}'s slot in ${ia.id}'s, and ${ia.id}'s ${aq.face} face (${aq.slot}) and ${ib.id}'s ${bq.face} face (${bq.slot}) differ: leave face out, or join with a bracket`);
237
274
  if (!splice) {
238
275
  const reach = fm.width / 2 + fm.arm, { room } = shapeAt;
239
- if (Math.min(room.a, room.b) + fm.width / 2 >= reach) { shape = 'T'; fm = fittingModel({ ...spec0, shape }, context, material, what); }
276
+ const fits = Math.min(room.a, room.b) + fm.width / 2 >= reach;
277
+ if (j.shape === 'T' && flip) throw new Error(`${what}: shape T: a printed gusset turned onto ${ib.id}'s ${j.face} face is an L only (a T's bar would lie along ${ia.id}): give shape L, or leave face out`);
278
+ if (j.shape === 'T' && !fits) throw new Error(`${what}: shape T: a printed T gusset's bar runs ${mm(fm.arm)} mm along ${ib.id} on both sides of ${ia.id}, and there is ${mm(Math.min(room.a, room.b))} mm on one side: give shape L, or leave shape out`);
279
+ if (!flip && fits && j.shape !== 'L') { shape = 'T'; fm = fittingModel({ ...spec0, shape }, context, material, what); } // (an L only, turned over: a T's bar would lie along a)
240
280
  else if (Math.max(room.a, room.b) + fm.width / 2 < reach - 1e-6) throw new Error(`${what}: a printed gusset's ${mm(fm.arm)} mm arm runs past ${ib.id}'s ends: there is ${mm(Math.max(room.a, room.b))} mm beside ${ia.id}, and it needs ${mm(fm.arm)}. A bracket will do`);
241
281
  if (A.length < fm.arm - 1e-6) throw new Error(`${what}: a printed gusset's ${mm(fm.arm)} mm arm is longer than ${ia.id} (${mm(A.length)} mm)`);
242
282
  } else if (Math.min(A.length, B.length) < fm.arm - 1e-6) throw new Error(`${what}: a printed splice plate's ${mm(fm.arm)} mm arms are longer than ${A.length < B.length ? ia.id : ib.id}`);
243
283
  if (A.profile.name !== B.profile.name && faceOf(A, aq) !== faceOf(B, bq)) throw new Error(`${what}: a printed plate is drawn for one profile's slots, and ${ia.id} (${A.profile.name}) and ${ib.id} (${B.profile.name}) differ: a bracket takes two`);
244
284
  const id = free(`${ia.id}-${ib.id}-${splice ? 'splice' : 'gusset'}`), along = dot(x, ub) > 0;
245
285
  const spec = { ...spec0, ...(splice ? {} : { shape }) };
246
- const item = { id, fitting: spec, at: `${ib.id}.${bq.name}@${r3(d)}`, ...(along ? {} : { rotate: [0, 0, 180] }), join: i };
247
- const anchorsOf = (leg) => fm.screws.map((sc, k) => [sc, k]).filter(([sc]) => sc.leg === leg).map((_, k) => `${id}.${leg}${k + 1}`);
286
+ // (at b's face's anchor the item's x runs along b and its z out of the face; turned over, its x runs along a: a
287
+ // quarter turn about z, the way that keeps its arm drawn for b along a away from b)
288
+ const item = { id, fitting: spec, at: `${ib.id}.${bq.name}@${r3(d)}`, ...(flip ? { rotate: [0, 0, along ? -90 : 90] } : along ? {} : { rotate: [0, 0, 180] }), join: i };
289
+ const anchorsOf = (leg) => fm.screws.map((sc, k) => [sc, k]).filter(([sc]) => sc.leg === (flip ? (leg === 'a' ? 'b' : 'a') : leg)).map((_, k) => `${id}.${flip ? (leg === 'a' ? 'b' : 'a') : leg}${k + 1}`);
248
290
  const fasten = [{ screw: `${fm.thread} ${fm.head}`, through: [id], into: `${ib.id}.${bq.name}`, at: anchorsOf('b'), note: `${label}: the ${splice ? 'splice plate' : 'gusset'} into ${ib.id}`, join: i, nut: j.nut ?? fm.screws[0].nutKind },
249
291
  { screw: `${fm.thread} ${fm.head}`, through: [id], into: `${ia.id}.${aq.name}`, at: anchorsOf('a'), note: `${label}: the ${splice ? 'splice plate' : 'gusset'} into ${ia.id}`, join: i, nut: j.nut ?? fm.screws[0].nutKind }];
250
292
  return { item, fasten, model: fm };
@@ -21,9 +21,11 @@
21
21
  // The steps of the parts that are not beams (and not a join's fitting) follow the assembly's order (lib/order.mjs); a
22
22
  // part a beam would stand over the screws of goes on before that beam. Every screw is held to what the assembly order
23
23
  // found stands over it (its covers): where no build reaches one, the build is refused with that reason.
24
- import { squareness, CUT_DEFAULTS } from '@rulecad/frames';
24
+ import { squareness, CUT_DEFAULTS, JOIN_PLAY } from '@rulecad/frames';
25
25
  import { placeItems } from '@rulecad/model-link';
26
+ import fs from 'node:fs';
26
27
  import path from 'node:path';
28
+ import { paths } from './workspace.mjs';
27
29
  import { cutListOf, sheetFile } from './beams.mjs';
28
30
  import { orderOf, fastenerText } from './order.mjs';
29
31
  import { preloadOf, trappedOf, closuresOf, nutGroupsOf } from './slotnuts.mjs';
@@ -34,13 +36,35 @@ const cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a
34
36
  const norm = (a) => { const l = Math.hypot(...a); return a.map((x) => x / l); };
35
37
  const list = (xs) => (xs.length < 2 ? xs.join('') : `${xs.slice(0, -1).join(', ')} and ${xs.at(-1)}`);
36
38
 
39
+ // A beam's cut tolerance and what it rests on: the assembly's frame.cut.tolerance (the workshop's own saw), else the
40
+ // profile's cut_tolerance, else CUT_DEFAULTS'
41
+ /** The assembly's own cut tolerance (frame.cut.tolerance), mm, or null: refused by name where it is not one. @param {object} s a built assembly */
42
+ export function cutToleranceOf(s) {
43
+ const c = s.a.frame?.cut;
44
+ if (c == null) return null;
45
+ if (typeof c !== 'object' || Array.isArray(c)) throw new Error(`frame.cut is { "tolerance": 0.5 }: how far this workshop's cuts may be from the length asked, in mm (got ${JSON.stringify(c)})`);
46
+ for (const k of Object.keys(c)) if (k !== 'tolerance') throw new Error(`frame.cut has no "${k}": it takes tolerance (mm)`);
47
+ if (c.tolerance == null) return null;
48
+ const t = s.num(c.tolerance);
49
+ if (!(Number.isFinite(t) && t >= 0)) throw new Error(`frame.cut.tolerance is how far a cut may be from the length asked, either way, a number of mm, 0 or more (got ${JSON.stringify(c.tolerance)})`);
50
+ return t;
51
+ }
52
+ function tolOf(s, p, printed = false) {
53
+ // (a printed beam is not cut: its length comes off the printer, held here to a saw cut's tolerance, an estimate)
54
+ if (printed) return { tol: CUT_DEFAULTS.tolerance.value, tolKind: 'estimate', tolFrom: 'frames.cut.tolerance, taken for a printed length', printed: true };
55
+ const given = cutToleranceOf(s);
56
+ if (given != null) return { tol: given, tolKind: 'given', tolFrom: 'the assembly\'s frame.cut.tolerance' };
57
+ if (p.supply?.cutTolerance != null) return { tol: p.supply.cutTolerance, tolKind: p.figures?.cut_tolerance?.kind ?? 'spec', tolFrom: `${p.name}.cut_tolerance` };
58
+ return { tol: CUT_DEFAULTS.tolerance.value, tolKind: CUT_DEFAULTS.tolerance.kind, tolFrom: 'frames.cut.tolerance' };
59
+ }
60
+
37
61
  // Each beam as a line in the world: end a, its axis, its section's two axes and sizes, its length, its cut tolerance
38
62
  function linesOf(s) {
39
63
  const placed = placeItems(s.motion, s.jointValues), worlds = Object.fromEntries(s.motion.items.map((x, i) => [x[0], placed[i]])), out = new Map(); // (placeItems: by the order of the motion's items)
40
64
  for (const o of s.objects) {
41
65
  if (!o.beam || o.unplaced || !worlds[o.id]) continue;
42
66
  const W = worlds[o.id], p = o.beam.profile;
43
- out.set(o.id, { id: o.id, O: [W[3], W[7], W[11]], d: norm([W[2], W[6], W[10]]), X: [W[0], W[4], W[8]], Y: [W[1], W[5], W[9]], w: p.width, h: p.height, L: o.beam.length, tol: p.supply?.cutTolerance ?? CUT_DEFAULTS.tolerance.value });
67
+ out.set(o.id, { id: o.id, O: [W[3], W[7], W[11]], d: norm([W[2], W[6], W[10]]), X: [W[0], W[4], W[8]], Y: [W[1], W[5], W[9]], w: p.width, h: p.height, L: o.beam.length, ...tolOf(s, p, !!o.beam.printed) });
44
68
  }
45
69
  return out;
46
70
  }
@@ -71,8 +95,14 @@ export function baysOf(s) {
71
95
  seen.add(key);
72
96
  const v = C.d, u = A.d, width = Math.abs(dot(A.O, v) - dot(B.O, v)) - reach(A, v) - reach(B, v), height = Math.abs(dot(C.O, u) - dot(D.O, u)) - reach(C, u) - reach(D, u);
73
97
  if (!(width > 0 && height > 0)) continue;
74
- const sq = squareness(width, height, { tolerance: Math.max(A.tol, B.tol, C.tol, D.tol) });
75
- out.push({ beams: [A.id, B.id, C.id, D.id], name: `${A.id}, ${B.id}, ${C.id} and ${D.id}`, width: +width.toFixed(2), height: +height.toFixed(2), square: sq });
98
+ // what squares it: each beam whose end butts a beam of the bay sets the opening along it by its cut length; each
99
+ // join of the bay's beams lets a's end sit off by its play along b (JOIN_PLAY), stacked worst case
100
+ const bay = [A, B, C, D], ids4 = bay.map((x) => x.id), along = (x) => (par(x, C) ? 'width' : 'height');
101
+ const inBay = (s.joins ?? []).filter((j) => ids4.includes(j.items[0]) && ids4.includes(j.items[1]) && j.items[0] !== j.items[1]);
102
+ const cuts = bay.filter((x) => inBay.some((j) => j.items[0] === x.id)).map((x) => ({ name: x.id, along: along(x), tolerance: x.tol, kind: x.tolKind, ...(x.printed ? { printed: true } : {}) }));
103
+ const plays = inBay.map((j) => { const r = JOIN_PLAY[j.kind]; return r ? { name: `join ${j.index + 1} (${j.kind})`, along: along(L.get(j.items[1])), slip: r.value, kind: r.kind } : null; }).filter(Boolean);
104
+ const sq = squareness(width, height, { tolerance: Math.max(...bay.map((x) => x.tol)), cuts, plays });
105
+ out.push({ beams: ids4, name: `${A.id}, ${B.id}, ${C.id} and ${D.id}`, width: +width.toFixed(2), height: +height.toFixed(2), square: sq, joins: inBay.map((j) => j.index), tolFrom: [...new Set(bay.map((x) => x.tolFrom))] });
76
106
  }
77
107
  }
78
108
  return out;
@@ -400,8 +430,34 @@ export function frameBuildText(ref, b) {
400
430
  }
401
431
 
402
432
 
403
- /** frame.square for each bay of a frame, in the assembly's findings shape: the diagonals to measure and the difference to accept. */
433
+ // The latest measurement of each prediction in the project's ledger (cad measured writes it), by name
434
+ function measuredOf(s) {
435
+ let text = '';
436
+ try { text = fs.readFileSync(path.join(paths.project(s.project), 'ledger.jsonl'), 'utf8'); } catch { return new Map(); }
437
+ const out = new Map();
438
+ for (const l of text.split('\n')) { if (!l.trim()) continue; try { const e = JSON.parse(l); if (e.assembly === s.name && typeof e.measured === 'number') out.set(e.name, e); } catch {} }
439
+ return out;
440
+ }
441
+
442
+ /**
443
+ * frame.square for each bay of a frame, in the assembly's findings shape: the diagonals to measure and the difference to
444
+ * accept, each cut and join's share of it, and a prediction cad measured takes (frame.square.<beams>=<the difference
445
+ * measured, either sign, since which diagonal is the longer says only which way it leans>): once measured, it says
446
+ * whether the bay is square within what its parts allow.
447
+ */
404
448
  export function frameSquareChecks(s, f) {
405
449
  if (!s.joins?.length) return;
406
- for (const b of baysOf(s)) f('info', `the bay of ${b.name}: ${b.square.text}`, null, { code: 'frame.square', values: b.square.findings[0].values, refs: { beams: b.beams } });
450
+ const measured = measuredOf(s);
451
+ let bays;
452
+ try { bays = baysOf(s); } catch (e) { f('fail', e.message, 'frame.cut: refused', { code: 'frame.square' }); return; }
453
+ for (const b of bays) {
454
+ const q = b.square, name = `frame.square.${b.beams.join('-')}`, m = measured.get(name), soft = q.terms.filter((x) => x.kind === 'estimate');
455
+ const parts = `${q.terms.map((x) => `${x.term} ${mm(x.value)}`).join(', ')} mm`;
456
+ const rests = soft.length ? ` It rests on estimates (${soft.map((x) => x.term).join(', ')}): measure the diagonals once it is squared and tightened, and give their difference to cad measured ${s.project}/${s.name} ${name}=<mm>` : '';
457
+ let level = 'info', said = '';
458
+ if (m) { const d = Math.abs(m.measured), over = d > q.accept + 1e-9; level = over ? 'warn' : 'pass'; said = ` Measured ${mm(m.measured)} mm (${m.date}${m.measured < 0 ? `, ${mm(d)} mm either way` : ''}): ${over ? `${mm(d / q.accept)} times what its cuts and joins allow, so it leans: loosen its joins, push the long diagonal's corners together, tighten and measure again` : 'within what its cuts and joins allow'}.`; }
459
+ f(level, `the bay of ${b.name}: ${q.text}. Its share: ${parts}.${said}${m ? '' : rests}`, level === 'warn' ? `${b.beams.join('-')}: out of square` : null,
460
+ { code: 'frame.square', predict: { name, figure: `the difference between the diagonals of the bay of ${b.name}, inside corner to inside corner, squared and tightened`, value: q.accept, unit: 'mm' },
461
+ values: { ...q.findings[0].values, ...(m ? { measured: m.measured } : {}) }, refs: { beams: b.beams, joins: b.joins, tolerance: b.tolFrom } });
462
+ }
407
463
  }