@rulecad/cad 0.9.0 → 0.11.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 (68) hide show
  1. package/AGENTS.md +29 -10
  2. package/CHANGELOG.md +604 -0
  3. package/EXAMPLES.md +122 -105
  4. package/README.md +292 -63
  5. package/bin/cad.mjs +500 -87
  6. package/lib/assembly.mjs +486 -134
  7. package/lib/bays.mjs +124 -0
  8. package/lib/cache-file.mjs +148 -0
  9. package/lib/clone.mjs +93 -11
  10. package/lib/code-text.mjs +28 -0
  11. package/lib/design-imports.mjs +127 -0
  12. package/lib/design.mjs +291 -59
  13. package/lib/designshapes.mjs +142 -0
  14. package/lib/edit.mjs +29 -5
  15. package/lib/estimates.mjs +51 -0
  16. package/lib/fasten.mjs +11 -5
  17. package/lib/fe-key.mjs +29 -0
  18. package/lib/fittings.mjs +20 -15
  19. package/lib/fixings.mjs +17 -4
  20. package/lib/framebuild.mjs +73 -92
  21. package/lib/framecheck.mjs +154 -77
  22. package/lib/framegen.mjs +9 -1
  23. package/lib/frames.mjs +6 -2
  24. package/lib/framesize.mjs +45 -82
  25. package/lib/gait.mjs +17 -7
  26. package/lib/guides.mjs +84 -50
  27. package/lib/host.mjs +7 -3
  28. package/lib/kit.mjs +5 -5
  29. package/lib/list.mjs +29 -21
  30. package/lib/live-guard.mjs +18 -8
  31. package/lib/loads.mjs +35 -23
  32. package/lib/measured.mjs +740 -99
  33. package/lib/mesh.mjs +156 -56
  34. package/lib/motors.mjs +26 -33
  35. package/lib/names.mjs +15 -0
  36. package/lib/node-version.mjs +52 -0
  37. package/lib/optimise.mjs +34 -25
  38. package/lib/order.mjs +5 -12
  39. package/lib/parts.mjs +3 -0
  40. package/lib/picture-servers.mjs +66 -0
  41. package/lib/power.mjs +14 -7
  42. package/lib/preview.mjs +12 -25
  43. package/lib/programs.mjs +113 -0
  44. package/lib/rules.mjs +2 -1
  45. package/lib/sandbox-guard.mjs +43 -0
  46. package/lib/sandbox-hooks.mjs +109 -15
  47. package/lib/sandbox-lock.mjs +225 -0
  48. package/lib/sandbox-preload.mjs +2 -2
  49. package/lib/sandbox-run.mjs +22 -24
  50. package/lib/sandbox.mjs +345 -42
  51. package/lib/sheet.mjs +114 -3
  52. package/lib/targets/gist.mjs +9 -6
  53. package/lib/versions.mjs +294 -35
  54. package/lib/workspace.mjs +6 -3
  55. package/package.json +14 -14
  56. package/schemas/assembly.schema.json +6 -5
  57. package/schemas/object.schema.json +1 -1
  58. package/schemas/project.schema.json +6 -0
  59. package/templates/coupons/MEASURE.md +109 -0
  60. package/templates/coupons/assemblies/fixings-test.json +20 -0
  61. package/templates/coupons/assemblies/slot-test.json +11 -0
  62. package/templates/coupons/objects/fixings-coupon.js +88 -0
  63. package/templates/coupons/objects/fixings-coupon.json +26 -0
  64. package/templates/coupons/objects/holds-coupon.js +130 -0
  65. package/templates/coupons/objects/holds-coupon.json +42 -0
  66. package/templates/coupons/objects/slot-coupon.js +89 -0
  67. package/templates/coupons/objects/slot-coupon.json +29 -0
  68. package/templates/coupons/project.json +10 -0
@@ -3,10 +3,11 @@
3
3
  // that a join would shut in before that join is made, measure the diagonals of each bay once it is closed, then mount
4
4
  // everything else. Each join's screws carry their key and how tight (fasten: the seat under the head, the lips of a
5
5
  // slot under a blind join's head, or the torque given).
6
- // Sides: a bay is four beams joined in a rectangle in one plane (two parallel beams joined to two others square to
7
- // them). Bays that share no beam are built flat on the bench as sides, squared, and then joined to the rest (a beam
8
- // is in one side at most, so of two bays that share a post the first found is the side, and the other is squared
9
- // once the frame is joined). Beams that are in no side go on one at a time in the assembly's order, each joined to
6
+ // Sides: a bay is four beams round a rectangle in one plane (two parallel beams joined to two others square to them,
7
+ // or meeting them through a post, as the top and bottom rings of a corner-post box do: lib/bays.mjs, the finder cad
8
+ // check shares). Bays whose beams join each other and that share no beam are built flat on the bench as sides,
9
+ // squared, and then joined to the rest (a beam is in one side at most, so of two bays that share a post the first
10
+ // found is the side, and the other is squared once the frame is joined, as is every ring joined through posts). Beams that are in no side go on one at a time in the assembly's order, each joined to
10
11
  // what is already there. A side goes on as one when a beam already there is joined to it, and only where the heads
11
12
  // of its blind joins to the frame can slide in as it does: along slots that all run one way, each with a way in from
12
13
  // the end that leads that no join already made closes. Where that fails, or a side built flat would stand a beam over
@@ -29,10 +30,10 @@ import { readOwnText } from './host.mjs';
29
30
  import { cutListOf, sheetFile } from './beams.mjs';
30
31
  import { orderOf, fastenerText } from './order.mjs';
31
32
  import { preloadOf, trappedOf, closuresOf, nutGroupsOf } from './slotnuts.mjs';
33
+ import { baysOf as findBays, joinStations } from './bays.mjs';
32
34
 
33
35
  const mm = (x) => String(+Number(x).toFixed(2));
34
36
  const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
35
- 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]];
36
37
  const norm = (a) => {
37
38
  const l = Math.hypot(...a);
38
39
  return a.map((x) => x / l);
@@ -106,93 +107,72 @@ function linesOf(s) {
106
107
  const reach = (b, e) => (Math.abs(dot(b.X, e)) * b.w + Math.abs(dot(b.Y, e)) * b.h) / 2;
107
108
 
108
109
  /**
109
- * A frame's bays: four beams joined in a rectangle in one plane, each with its opening (inside face to inside face)
110
- * and its diagonals. @param {object} s a built assembly
111
- * @returns {{ beams: string[], name: string, width: number, height: number, square: object }[]}
110
+ * A frame's bays (lib/bays.mjs, the finder cad check's solve shares): four beams round a rectangle in one plane, each
111
+ * neighbouring pair joined to each other or both joined to one beam there (the posts of a corner-post box's top and
112
+ * bottom rings), each with its opening (inside face to inside face) and its diagonals. @param {object} s a built assembly
113
+ * @returns {{ beams: string[], name: string, width: number, height: number, square: object, joins: number[], tolFrom: string[], through: string[] }[]}
114
+ * beams: the two parallel beams first, then the two square to them; through: the beams its corners are joined through
112
115
  */
113
116
  export function baysOf(s) {
114
- const L = linesOf(s),
115
- ids = [...L.keys()],
116
- joined = new Set();
117
- for (const j of s.joins ?? []) {
118
- joined.add(`${j.items[0]}|${j.items[1]}`);
119
- joined.add(`${j.items[1]}|${j.items[0]}`);
117
+ const L = linesOf(s);
118
+ const found = findBays(
119
+ [...L.values()].map((b) => ({ id: b.id, A: b.O, u: b.d, L: b.L, reach: Math.max(b.w, b.h) })),
120
+ joinStations(s.joins, (id) => L.get(id)?.L),
121
+ );
122
+ const par = (a, b) => Math.abs(Math.abs(dot(a.d, b.d)) - 1) < 1e-3;
123
+ const out = [];
124
+ for (const bay of found) {
125
+ // (round the bay: a and c parallel, b and d; said as a, c, b and d, the order this list has always given)
126
+ const [A, C, B, D] = bay.beams.map((id) => L.get(id));
127
+ const v = C.d,
128
+ u = A.d,
129
+ width = Math.abs(dot(A.O, v) - dot(B.O, v)) - reach(A, v) - reach(B, v),
130
+ height = Math.abs(dot(C.O, u) - dot(D.O, u)) - reach(C, u) - reach(D, u);
131
+ if (!(width > 0 && height > 0)) continue;
132
+ // what squares it: each beam whose end butts a beam of the bay, or the beam its corner is joined through (a post),
133
+ // sets the opening along it by its cut length; each join of the bay's beams to each other lets a's end sit off by its
134
+ // play along b (JOIN_PLAY), stacked worst case (a join to a post slips along the post, out of the bay's plane)
135
+ const bay4 = [A, B, C, D],
136
+ ids4 = bay4.map((x) => x.id),
137
+ along = (x) => (par(x, C) ? 'width' : 'height');
138
+ const inBay = (s.joins ?? []).filter(
139
+ (j) => ids4.includes(j.items[0]) && ids4.includes(j.items[1]) && j.items[0] !== j.items[1],
140
+ ),
141
+ toPosts = (s.joins ?? []).filter((j) => ids4.includes(j.items[0]) && bay.through.includes(j.items[1]));
142
+ const cuts = bay4
143
+ .filter((x) => [...inBay, ...toPosts].some((j) => j.items[0] === x.id))
144
+ .map((x) => ({
145
+ name: x.id,
146
+ along: along(x),
147
+ tolerance: x.tol,
148
+ kind: x.tolKind,
149
+ ...(x.printed ? { printed: true } : {}),
150
+ }));
151
+ const plays = inBay
152
+ .map((j) => {
153
+ const r = JOIN_PLAY[j.kind];
154
+ return r
155
+ ? {
156
+ name: `join ${j.index + 1} (${j.kind})`,
157
+ along: along(L.get(j.items[1])),
158
+ slip: r.value,
159
+ kind: r.kind,
160
+ }
161
+ : null;
162
+ })
163
+ .filter(Boolean);
164
+ const sq = squareness(width, height, { tolerance: Math.max(...bay4.map((x) => x.tol)), cuts, plays });
165
+ out.push({
166
+ beams: ids4,
167
+ name: `${A.id}, ${B.id}, ${C.id} and ${D.id}`,
168
+ width: +width.toFixed(2),
169
+ height: +height.toFixed(2),
170
+ square: sq,
171
+ joins: [...inBay, ...toPosts].map((j) => j.index),
172
+ tolFrom: [...new Set(bay4.map((x) => x.tolFrom))],
173
+ through: bay.through,
174
+ });
120
175
  }
121
- const J = (a, b) => joined.has(`${a}|${b}`),
122
- par = (a, b) => Math.abs(Math.abs(dot(a.d, b.d)) - 1) < 1e-6,
123
- perp = (a, b) => Math.abs(dot(a.d, b.d)) < 1e-6;
124
- const out = [],
125
- seen = new Set();
126
- for (let i = 0; i < ids.length; i++)
127
- for (let k = i + 1; k < ids.length; k++) {
128
- const A = L.get(ids[i]),
129
- B = L.get(ids[k]);
130
- if (!par(A, B)) continue;
131
- const cross_ = ids.filter((id) => id !== A.id && id !== B.id && perp(L.get(id), A) && J(id, A.id) && J(id, B.id));
132
- for (let m = 0; m < cross_.length; m++)
133
- for (let q = m + 1; q < cross_.length; q++) {
134
- const C = L.get(cross_[m]),
135
- D = L.get(cross_[q]);
136
- if (!par(C, D)) continue;
137
- const n = norm(cross(A.d, C.d)),
138
- on = (b) =>
139
- Math.abs(
140
- dot(
141
- b.O.map((x, t) => x - A.O[t]),
142
- n,
143
- ),
144
- ) < 1e-3;
145
- if (![B, C, D].every(on)) continue;
146
- const key = [A.id, B.id, C.id, D.id].sort().join('|');
147
- if (seen.has(key)) continue;
148
- seen.add(key);
149
- const v = C.d,
150
- u = A.d,
151
- width = Math.abs(dot(A.O, v) - dot(B.O, v)) - reach(A, v) - reach(B, v),
152
- height = Math.abs(dot(C.O, u) - dot(D.O, u)) - reach(C, u) - reach(D, u);
153
- if (!(width > 0 && height > 0)) continue;
154
- // what squares it: each beam whose end butts a beam of the bay sets the opening along it by its cut length; each
155
- // join of the bay's beams lets a's end sit off by its play along b (JOIN_PLAY), stacked worst case
156
- const bay = [A, B, C, D],
157
- ids4 = bay.map((x) => x.id),
158
- along = (x) => (par(x, C) ? 'width' : 'height');
159
- const inBay = (s.joins ?? []).filter(
160
- (j) => ids4.includes(j.items[0]) && ids4.includes(j.items[1]) && j.items[0] !== j.items[1],
161
- );
162
- const cuts = bay
163
- .filter((x) => inBay.some((j) => j.items[0] === x.id))
164
- .map((x) => ({
165
- name: x.id,
166
- along: along(x),
167
- tolerance: x.tol,
168
- kind: x.tolKind,
169
- ...(x.printed ? { printed: true } : {}),
170
- }));
171
- const plays = inBay
172
- .map((j) => {
173
- const r = JOIN_PLAY[j.kind];
174
- return r
175
- ? {
176
- name: `join ${j.index + 1} (${j.kind})`,
177
- along: along(L.get(j.items[1])),
178
- slip: r.value,
179
- kind: r.kind,
180
- }
181
- : null;
182
- })
183
- .filter(Boolean);
184
- const sq = squareness(width, height, { tolerance: Math.max(...bay.map((x) => x.tol)), cuts, plays });
185
- out.push({
186
- beams: ids4,
187
- name: `${A.id}, ${B.id}, ${C.id} and ${D.id}`,
188
- width: +width.toFixed(2),
189
- height: +height.toFixed(2),
190
- square: sq,
191
- joins: inBay.map((j) => j.index),
192
- tolFrom: [...new Set(bay.map((x) => x.tolFrom))],
193
- });
194
- }
195
- }
196
176
  return out;
197
177
  }
198
178
 
@@ -313,11 +293,12 @@ function buildFrame(s) {
313
293
  key = (b) => b.beams.join('|');
314
294
  for (;;) {
315
295
  // sides: bays that share no beam with a side already chosen, in the order they are found; a bay that shares one is
316
- // squared once the frame is joined
296
+ // squared once the frame is joined, and so is a bay whose beams meet only through others (a corner-post box's ring:
297
+ // its rails join the posts, so it can't be built flat)
317
298
  const sides = [],
318
299
  used = new Set();
319
300
  for (const bay of bays)
320
- if (!barred.has(key(bay)) && !bay.beams.some((b) => used.has(b))) {
301
+ if (!bay.through.length && !barred.has(key(bay)) && !bay.beams.some((b) => used.has(b))) {
321
302
  sides.push(bay);
322
303
  for (const b of bay.beams) used.add(b);
323
304
  }
@@ -353,7 +334,7 @@ function buildFrame(s) {
353
334
  kind: 'cut',
354
335
  text: `Cut the beams: ${c.marks.map((m) => `${m.count} × ${m.mark} at ${mm(m.length)} mm`).join(', ')} (kerf ${c.rules.kerf.value} mm, ${c.rules.trim.value} mm off each bar's first end; cut each mark against one stop)`,
355
336
  lines: c.stock.flatMap((st) => [
356
- `${st.profile}: buy ${st.buy.map((x) => `${x.count} × ${mm(x.length)} mm`).join(', ')}`,
337
+ `${st.label ?? st.profile}: buy ${st.buy.map((x) => `${x.count} × ${mm(x.length)} mm`).join(', ')}`,
357
338
  ...st.bars.map(
358
339
  (b, i) =>
359
340
  `bar ${i + 1}, ${mm(b.length)} mm: ${b.cuts.map((q) => `${q.mark} ${mm(q.length)} (${q.item})`).join(', ')}; offcut ${mm(b.offcut)}`,
@@ -28,6 +28,7 @@ import { axisOf, workingSpeed, trainFrom, atCurrent, mountTorque } from './motor
28
28
  import { joinStiffness, PANEL_DEFAULTS } from '@rulecad/frames';
29
29
  import { printableCheck, couponChecks, printedOption } from './frameprint.mjs';
30
30
  import { tipOf, tipCheck, tipsWay } from './frametip.mjs';
31
+ import { baysOf as findBays } from './bays.mjs';
31
32
 
32
33
  const G = 9.80665;
33
34
  const FEET = ['foot', 'levelling-foot', 'castor-plate', 'stacking-foot'];
@@ -185,81 +186,50 @@ const unitv = (v) => {
185
186
  return v.map((c) => c / l);
186
187
  };
187
188
 
188
- // The bays of a frame: four beams round a rectangle in one plane, two each way, each neighbouring pair joined to each
189
- // other or both joined to one beam at one place (the top of a corner-post box: its rails join the posts, not each
190
- // other). Each corner is the node nearest where two neighbouring beams' axes cross, on either of them or on the beam
191
- // both join (a join puts a station on the beam it lands on there).
189
+ // The bays of a frame (lib/bays.mjs, the finder cad order and the build page share), each corner snapped to the node
190
+ // nearest where its two beams' axes cross, on either of them or on the beam both join there (a join puts a station on
191
+ // the beam it lands on there). A bay with a corner that has no node within a profile's width is left out.
192
192
  function baysOf(beams, joins, nodes, nodeAt) {
193
- const direct = (p, q) => joins.some((x) => (x.A.id === p && x.B.id === q) || (x.A.id === q && x.B.id === p));
194
- const reachOf = (id) => {
195
- const m = beams.get(id).m.profile;
196
- return Math.max(m.width, m.height);
197
- };
198
- // the beams p and q both join at one place: a's end on b's axis within a profile's width of the other's
199
- const memo = new Map(),
200
- via = (p, q) => {
201
- const key = `${p}|${q}`;
202
- if (!memo.has(key)) memo.set(key, through(p, q));
203
- return memo.get(key);
204
- };
205
- const through = (p, q) => {
206
- const out = new Set();
207
- for (const x of joins)
208
- for (const y of joins) {
209
- if (x === y) continue;
210
- const [xo, xr, xz] = x.A.id === p ? [p, x.B.id, x.zb] : x.B.id === p ? [p, x.A.id, x.za] : [];
211
- const [yo, yr, yz] = y.A.id === q ? [q, y.B.id, y.zb] : y.B.id === q ? [q, y.A.id, y.za] : [];
212
- if (xo && yo && xr === yr && xr !== p && xr !== q && Math.abs(xz - yz) <= reachOf(xr)) out.add(xr);
213
- }
214
- return [...out];
215
- };
216
- const linked = (p, q) => direct(p, q) || via(p, q).length > 0;
217
- const ids = [...beams.keys()],
218
- out = [],
219
- seen = new Set();
220
- const par = (p, q) => Math.abs(Math.abs(dot(p.u, q.u)) - 1) < 1e-3,
221
- square = (p, q) => Math.abs(dot(p.u, q.u)) < 1e-3;
222
- for (const a of ids)
223
- for (const b of ids)
224
- if (b !== a && linked(a, b))
225
- for (const c of ids)
226
- if (c !== a && c !== b && linked(b, c))
227
- for (const d of ids) {
228
- if ([a, b, c].includes(d) || !linked(c, d) || !linked(d, a)) continue;
229
- const key = [a, b, c, d].sort().join(',');
230
- if (seen.has(key)) continue;
231
- const B = [a, b, c, d].map((id) => beams.get(id));
232
- if (!(par(B[0], B[2]) && par(B[1], B[3]) && square(B[0], B[1]))) continue;
233
- const n = unitv(cross(B[0].u, B[1].u));
234
- if (B.some((q) => Math.abs(dot(sub(q.A, B[0].A), n)) > 1)) continue;
235
- const reach = Math.max(...B.map((q) => Math.max(q.m.profile.width, q.m.profile.height)));
236
- const corners = B.map((p, i) => {
237
- const q = B[(i + 1) % 4],
238
- X = add(p.A, scale(p.u, dot(sub(q.A, p.A), p.u)));
239
- let best = null,
240
- gap = Infinity;
241
- for (const r of [p, q, ...via(p.id, q.id).map((id) => beams.get(id))])
242
- for (const z of r.stations) {
243
- const nm = nodeAt(r, z),
244
- g = Math.hypot(...sub(nodes[nm], X));
245
- if (g < gap) {
246
- gap = g;
247
- best = nm;
248
- }
249
- }
250
- return gap <= reach ? best : null;
251
- });
252
- if (corners.some((x) => !x) || new Set(corners).size < 4) continue;
253
- seen.add(key);
254
- const P = corners.map((x) => nodes[x]);
255
- out.push({
256
- beams: [a, b, c, d],
257
- n,
258
- corners,
259
- size: [Math.hypot(...sub(P[1], P[0])), Math.hypot(...sub(P[2], P[1]))],
260
- name: [a, b, c, d].join('-'),
261
- });
262
- }
193
+ const lines = [...beams.values()].map((b) => ({
194
+ id: b.id,
195
+ A: b.A,
196
+ u: b.u,
197
+ L: b.L,
198
+ reach: Math.max(b.m.profile.width, b.m.profile.height),
199
+ }));
200
+ const out = [];
201
+ for (const bay of findBays(
202
+ lines,
203
+ joins.map((x) => ({ a: x.A.id, b: x.B.id, za: x.za, zb: x.zb })),
204
+ )) {
205
+ const B = bay.beams.map((id) => beams.get(id)),
206
+ reach = Math.max(...B.map((q) => Math.max(q.m.profile.width, q.m.profile.height)));
207
+ const corners = B.map((p, i) => {
208
+ const q = B[(i + 1) % 4],
209
+ X = bay.corners[i].at;
210
+ let best = null,
211
+ gap = Infinity;
212
+ for (const r of [p, q, ...bay.corners[i].through.map((id) => beams.get(id))])
213
+ for (const z of r.stations) {
214
+ const nm = nodeAt(r, z),
215
+ g = Math.hypot(...sub(nodes[nm], X));
216
+ if (g < gap) {
217
+ gap = g;
218
+ best = nm;
219
+ }
220
+ }
221
+ return gap <= reach ? best : null;
222
+ });
223
+ if (corners.some((x) => !x) || new Set(corners).size < 4) continue;
224
+ const P = corners.map((x) => nodes[x]);
225
+ out.push({
226
+ beams: bay.beams,
227
+ n: bay.n,
228
+ corners,
229
+ size: [Math.hypot(...sub(P[1], P[0])), Math.hypot(...sub(P[2], P[1]))],
230
+ name: bay.name,
231
+ });
232
+ }
263
233
  return out;
264
234
  }
265
235
 
@@ -1300,6 +1270,70 @@ function sagAlong(r, beam, from, to, down) {
1300
1270
  return { sag: most, z: where };
1301
1271
  }
1302
1272
 
1273
+ /**
1274
+ * Where a beam of a frame is held: each support on it, and each join's end on it (a's end, or where it lands on b) whose
1275
+ * other beam reaches a support without passing through this one, in mm from its end a, least first. A beam that only
1276
+ * hangs from it (a stub on a cantilever arm) is carried, not holding: it does not count, so the arm keeps its tip's whole
1277
+ * drop. @param {object} fm frameModelOf's @param {object} beam one of fm.beams
1278
+ * @returns {number[]}
1279
+ */
1280
+ export function heldAlong(fm, beam) {
1281
+ const grounded = new Set(fm.supports.map((x) => x.beam).filter((b) => b !== beam)),
1282
+ reaches = new Set(grounded),
1283
+ todo = [...grounded];
1284
+ while (todo.length) {
1285
+ const b = todo.pop();
1286
+ for (const x of fm.joins)
1287
+ for (const [p, q] of [
1288
+ [x.A, x.B],
1289
+ [x.B, x.A],
1290
+ ])
1291
+ if (p === b && q !== beam && !reaches.has(q)) {
1292
+ reaches.add(q);
1293
+ todo.push(q);
1294
+ }
1295
+ }
1296
+ const joined = (holding) =>
1297
+ fm.joins.flatMap((x) => [
1298
+ ...(x.A === beam && (!holding || reaches.has(x.B)) ? [x.za] : []),
1299
+ ...(x.B === beam && (!holding || reaches.has(x.A)) ? [x.zb] : []),
1300
+ ]);
1301
+ const own = fm.supports.filter((x) => x.beam === beam).map((x) => x.z),
1302
+ held = [...own, ...joined(true)],
1303
+ // held through nothing that reaches a support (a part on its own): every join, as before
1304
+ at = held.length ? held : joined(false);
1305
+ return [...new Set(at)].sort((p, q) => p - q);
1306
+ }
1307
+
1308
+ // A beam's own sag along its length: its movement down, less the line through its movement where it is held first and
1309
+ // last (or, held at one place, less that place's movement), so that a short beam hanging from a long rail is not
1310
+ // failed for the rail's sag, and a cantilever is still held to its tip's drop. Held nowhere: its movement as it is.
1311
+ function ownSagAlong(r, beam, held, down) {
1312
+ const pts = [];
1313
+ for (const e of r.elements)
1314
+ if (e.of === beam.id) e.along.x.forEach((x, i) => pts.push({ z: (e._from ?? 0) + x, d: e.along.d[i] }));
1315
+ if (!pts.length) return { sag: -Infinity, z: 0 };
1316
+ const near = (z) => pts.reduce((p, q) => (Math.abs(q.z - z) < Math.abs(p.z - z) ? q : p));
1317
+ const h0 = held.length ? near(held[0]) : null,
1318
+ h1 = held.length > 1 ? near(held.at(-1)) : h0;
1319
+ const base = (z) => {
1320
+ if (!h0) return [0, 0, 0];
1321
+ if (h1 === h0 || Math.abs(h1.z - h0.z) < 1e-9) return h0.d.slice(0, 3);
1322
+ const t = (z - h0.z) / (h1.z - h0.z);
1323
+ return [0, 1, 2].map((c) => h0.d[c] + (h1.d[c] - h0.d[c]) * t);
1324
+ };
1325
+ let most = -Infinity,
1326
+ where = 0;
1327
+ for (const p of pts) {
1328
+ const v = dot(sub(p.d, base(p.z)), down);
1329
+ if (v > most) {
1330
+ most = v;
1331
+ where = p.z;
1332
+ }
1333
+ }
1334
+ return { sag: most, z: where };
1335
+ }
1336
+
1303
1337
  /**
1304
1338
  * frame.deflection, frame.stress and frame.buckling on a built assembly, and frame.solve saying what the frame's model
1305
1339
  * holds and what it leaves out. @param {object} s a built assembly @param {Function} f the findings' sink
@@ -1554,6 +1588,40 @@ export function frameChecks(s, f, helpers) {
1554
1588
  beam: g.beam.id,
1555
1589
  });
1556
1590
  }
1591
+ // every beam's own sag, the worst along its length (each element's stations, not its nodes alone), held to its span
1592
+ // over frame.sag (or the assembly's frame.limit, where given; never the task's accuracy, which is the tool's): a long
1593
+ // rail that carries nothing but itself is held too. Its own sag is its bending, from the line through where it is held
1594
+ // (ownSagAlong), not the movement of what carries it. Each beam over its limit fails; where none is, the one nearest
1595
+ // its limit is said as the pass
1596
+ const spans = [];
1597
+ for (const b of fm.beams.values()) {
1598
+ const holds = heldAlong(fm, b),
1599
+ w = worst((r) => ownSagAlong(r, b, holds, down));
1600
+ if (!w || !Number.isFinite(w.sag)) continue;
1601
+ const own =
1602
+ s.a.frame?.limit != null
1603
+ ? { value: s.num(s.a.frame.limit), from: "the assembly's frame.limit" }
1604
+ : {
1605
+ value: b.L / FRAME_CHECK.sag.value,
1606
+ from: `${b.id}'s span, ${n3(b.L, 1)} mm, over ${FRAME_CHECK.sag.value} (frame.sag)`,
1607
+ },
1608
+ kept = w.creep && w.creep.sag > w.sag ? w.creep.sag : w.sag;
1609
+ spans.push({ b, w, own, ratio: kept / own.value });
1610
+ }
1611
+ const spanOver = spans.filter((x) => x.ratio > 1),
1612
+ nearest = spans.reduce((p, q) => (!p || q.ratio > p.ratio ? q : p), null);
1613
+ for (const { b, w, own } of spanOver.length ? spanOver : nearest ? [nearest] : [])
1614
+ report(
1615
+ spanOver.length
1616
+ ? `${b.id} along its length (its own bending, from where it is held), at its worst ${n3(w.z, 1)} mm from its end a,`
1617
+ : `of the ${spans.length} beam${spans.length > 1 ? 's' : ''}, the nearest its limit is ${b.id}: along its length (its own bending, from where it is held), at its worst ${n3(w.z, 1)} mm from its end a, it`,
1618
+ `${b.id} along its length`,
1619
+ b,
1620
+ w,
1621
+ own,
1622
+ null,
1623
+ add(b.A, scale(b.u, w.z)),
1624
+ );
1557
1625
 
1558
1626
  // ---- frame.stress: the worst in each beam against its alloy; the moment at each join against its fitting ----
1559
1627
  const beamRows = [];
@@ -2414,13 +2482,22 @@ export function frameShape(s, helpers, o = {}) {
2414
2482
  if (!fm || fm.empty) return null;
2415
2483
  const solved = solveAll(fm);
2416
2484
  if (solved.error) return null;
2417
- const r = solved.results.reduce((p, q) => (q.spring.deflection.most > p.spring.deflection.most ? q : p)).spring,
2418
- most = r.deflection.most;
2485
+ // the largest movement anywhere along a beam: each element's stations, where the middle of a long rail moves most,
2486
+ // not its nodes alone (its ends and joins)
2487
+ const mostOf = (res) =>
2488
+ Math.max(
2489
+ res.deflection.most,
2490
+ ...res.elements.filter((e) => e.of != null).flatMap((e) => e.along.d.map((d) => Math.hypot(d[0], d[1], d[2]))),
2491
+ );
2492
+ const r = solved.results
2493
+ .map((q) => ({ res: q.spring, most: mostOf(q.spring) }))
2494
+ .reduce((p, q) => (q.most > p.most ? q : p)),
2495
+ most = r.most;
2419
2496
  const pts = Object.values(fm.nodes),
2420
2497
  size = Math.max(...[0, 1, 2].map((c) => Math.max(...pts.map((p) => p[c])) - Math.min(...pts.map((p) => p[c]))));
2421
2498
  const k = o.scale ?? (most > 0 ? size / 20 / most : 1);
2422
2499
  const beams = [...fm.beams.values()].map((b) => {
2423
- const els = r.elements.filter((e) => e.of === b.id),
2500
+ const els = r.res.elements.filter((e) => e.of === b.id),
2424
2501
  drawn = [],
2425
2502
  moved = [];
2426
2503
  for (const e of els) {
package/lib/framegen.mjs CHANGED
@@ -177,13 +177,21 @@ export function frameText(m) {
177
177
  `inside ${size(m.inside)} mm, outside ${size(m.outside)} mm${m.shelves ? `; ${m.shelves} shelves, each bay ${+m.bay.toFixed(2)} mm clear` : ''}${m.lift ? `; the bottom ring stands ${+m.lift.toFixed(2)} mm up the uprights, so its joins' holes clear the feet's tapped ends` : ''}`,
178
178
  ];
179
179
  for (const l of m.lengths) lines.push(` ${l.count} x ${+l.length.toFixed(2)} mm: ${l.ids.join(', ')}`);
180
+ // the whole frame with its feet and end caps (an outside asked for is this envelope's), where it is more than the beams
181
+ const env = m.envelope;
182
+ const overall = !env
183
+ ? "overall: not known, as a castor plate's castor is bought and not drawn: add its height from its maker's drawing"
184
+ : env.size.some((v, k) => Math.abs(v - m.outside[k]) > 1e-6)
185
+ ? `overall, its feet and end caps fitted: ${size(env.size)} mm${env.from[2] < 0 ? `, standing ${+(-env.from[2]).toFixed(2)} mm below the beams on its ${m.ends.some((e) => e.role === 'foot') ? 'feet' : 'end caps'}` : ''}`
186
+ : null;
180
187
  // (a brace is a printed bracket added beside the join asked for at each corner of a braced side, or, where the join is
181
188
  // a printed bracket already, its web)
182
189
  const braced = m.braced ?? 0,
183
190
  webbed = m.join.kind === 'bracket' && m.join.fitting === 'printed',
184
191
  asked = m.joins.length - (webbed ? 0 : braced);
185
192
  lines.push(
186
- `${asked} joins (${m.join.kind})${braced ? (webbed ? `, ${braced} of them braced: their brackets drawn with a web across the inside corner` : `, ${braced} braced with printed brackets`) : ''}; ${m.ends.length} end fittings${m.ends.length ? ` (${[...new Set(m.ends.map((e) => e.fitting ?? e.bought))].join(', ')})` : ''}${m.panels.length ? `; ${m.panels.length} panels` : ''}${m.moving ? `; g rides ${m.moving.track} through ${m.moving.travel} mm on the joint gantry` : ''}`,
193
+ `${asked} joins (${m.join.kind}${m.join.estimate ? ', taken by their estimate' : ''})${braced ? (webbed ? `, ${braced} of them braced: their brackets drawn with a web across the inside corner` : `, ${braced} braced with printed brackets`) : ''}; ${m.ends.length} end fittings${m.ends.length ? ` (${[...new Set(m.ends.map((e) => e.fitting ?? e.bought))].join(', ')})` : ''}${m.panels.length ? `; ${m.panels.length} panels` : ''}${m.moving ? `; g rides ${m.moving.track} through ${m.moving.travel} mm on the joint gantry` : ''}`,
187
194
  );
195
+ if (overall) lines.push(overall);
188
196
  return lines;
189
197
  }
package/lib/frames.mjs CHANGED
@@ -14,7 +14,8 @@ let seen = null;
14
14
  /**
15
15
  * What @rulecad/frames is handed from a workspace: its own rule sets by name, and the measured outlines beside them.
16
16
  * @param {string} dir the workspace's rules/ folder
17
- * @returns {{ sets: Record<string, object>, outlines: Record<string, object>, hash: string }}
17
+ * @returns {{ sets: Record<string, object>, outlines: Record<string, object>, hash: string, files: string[] }} files: the
18
+ * paths of the files those sets and outlines were read from
18
19
  */
19
20
  export function framesContext(dir) {
20
21
  const out = path.join(dir, 'outlines');
@@ -34,7 +35,8 @@ export function framesContext(dir) {
34
35
  if (seen?.key === key) return seen.context;
35
36
  const sets = {},
36
37
  outlines = {},
37
- text = [];
38
+ text = [],
39
+ from = [];
38
40
  for (const [d, into] of [
39
41
  [dir, sets],
40
42
  [out, outlines],
@@ -63,6 +65,7 @@ export function framesContext(dir) {
63
65
  ) {
64
66
  into[s.name ?? f.slice(0, -5)] = s;
65
67
  text.push(raw);
68
+ from.push(path.join(d, f));
66
69
  }
67
70
  } catch {
68
71
  // (a broken set is cad rules check's to name)
@@ -73,6 +76,7 @@ export function framesContext(dir) {
73
76
  sets,
74
77
  outlines,
75
78
  hash: crypto.createHash('sha256').update(text.join('\n')).digest('hex').slice(0, 24),
79
+ files: from, // (the files of those sets and outlines: a release records them, lib/versions.mjs)
76
80
  };
77
81
  seen = { key, context };
78
82
  return context;