@rulecad/cad 0.10.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.
- package/AGENTS.md +8 -4
- package/CHANGELOG.md +285 -1
- package/EXAMPLES.md +101 -89
- package/README.md +104 -27
- package/bin/cad.mjs +41 -13
- package/lib/assembly.mjs +418 -101
- package/lib/bays.mjs +124 -0
- package/lib/cache-file.mjs +66 -23
- package/lib/clone.mjs +93 -11
- package/lib/design.mjs +40 -4
- package/lib/edit.mjs +5 -3
- package/lib/framebuild.mjs +72 -91
- package/lib/framecheck.mjs +154 -77
- package/lib/framesize.mjs +37 -1
- package/lib/gait.mjs +17 -7
- package/lib/guides.mjs +84 -50
- package/lib/live-guard.mjs +18 -8
- package/lib/measured.mjs +2 -1
- package/lib/mesh.mjs +156 -56
- package/lib/motors.mjs +17 -4
- package/lib/node-version.mjs +52 -0
- package/lib/order.mjs +1 -2
- package/lib/picture-servers.mjs +66 -0
- package/lib/power.mjs +14 -7
- package/lib/preview.mjs +12 -25
- package/lib/programs.mjs +113 -0
- package/lib/sandbox-guard.mjs +43 -0
- package/lib/sandbox.mjs +172 -12
- package/lib/targets/gist.mjs +9 -6
- package/lib/versions.mjs +106 -10
- package/lib/workspace.mjs +3 -1
- package/package.json +13 -13
- package/schemas/assembly.schema.json +5 -4
- package/schemas/object.schema.json +1 -1
package/lib/framebuild.mjs
CHANGED
|
@@ -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
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
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
|
|
110
|
-
*
|
|
111
|
-
*
|
|
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
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
}
|
package/lib/framecheck.mjs
CHANGED
|
@@ -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
|
|
189
|
-
//
|
|
190
|
-
//
|
|
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
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
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
|
-
|
|
2418
|
-
|
|
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/framesize.mjs
CHANGED
|
@@ -26,7 +26,16 @@ import {
|
|
|
26
26
|
stackingFootModel,
|
|
27
27
|
} from '@rulecad/frames';
|
|
28
28
|
import { fixingModel } from '@rulecad/fixings';
|
|
29
|
-
import {
|
|
29
|
+
import {
|
|
30
|
+
frameModelOf,
|
|
31
|
+
FRAME_CHECK,
|
|
32
|
+
excitesOf,
|
|
33
|
+
rackOf,
|
|
34
|
+
sideways,
|
|
35
|
+
freeSaid,
|
|
36
|
+
endSprings,
|
|
37
|
+
heldAlong,
|
|
38
|
+
} from './framecheck.mjs';
|
|
30
39
|
import { framesContext } from './beams.mjs';
|
|
31
40
|
import { givenFor } from './frames.mjs';
|
|
32
41
|
import { fittingModel, fittedStiffness, plasticOf } from './fittings.mjs';
|
|
@@ -393,6 +402,33 @@ export function frameSizing(s, helpers, given) {
|
|
|
393
402
|
from: lim.from,
|
|
394
403
|
});
|
|
395
404
|
}
|
|
405
|
+
// every beam's own sag along its length (its bending, from where it is held), held to its span over frame.sag (or
|
|
406
|
+
// frame.limit) as frame.deflection holds it, so cad check does not fail a sized design whose long rail sags past it,
|
|
407
|
+
// loaded or not; limits.deflection, where given, in its place as at the loads
|
|
408
|
+
if (fm.beams.size) {
|
|
409
|
+
const asked = opt.limits.deflection != null,
|
|
410
|
+
frameLimit = asked ? opt.limits.deflection : s.a.frame?.limit != null ? s.num(s.a.frame.limit) : null;
|
|
411
|
+
for (const b of fm.beams.values()) {
|
|
412
|
+
const held = heldAlong(fm, b);
|
|
413
|
+
deflection.push({
|
|
414
|
+
member: b.id,
|
|
415
|
+
limit: frameLimit ?? b.L / FRAME_CHECK.sag.value,
|
|
416
|
+
along: fm.down,
|
|
417
|
+
...(held.length ? { held } : {}),
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
const shortest = [...fm.beams.values()].reduce((p, q) => (q.L < p.L ? q : p));
|
|
421
|
+
limitRows.push({
|
|
422
|
+
limit: 'deflection',
|
|
423
|
+
where: 'each beam',
|
|
424
|
+
what:
|
|
425
|
+
frameLimit != null
|
|
426
|
+
? 'each beam along its length'
|
|
427
|
+
: `each beam along its length (${shortest.id}'s the least, its span over ${FRAME_CHECK.sag.value})`,
|
|
428
|
+
value: frameLimit ?? shortest.L / FRAME_CHECK.sag.value,
|
|
429
|
+
from: asked ? 'frame.size.limits.deflection' : frameLimit != null ? 'frame.limit' : 'frame.sag',
|
|
430
|
+
});
|
|
431
|
+
}
|
|
396
432
|
const stress = opt.limits.stress ?? margin,
|
|
397
433
|
factor = opt.limits.buckling ?? margin;
|
|
398
434
|
limitRows.push({
|
package/lib/gait.mjs
CHANGED
|
@@ -62,7 +62,7 @@ export const frameValues = (s, frame, jointValues) => {
|
|
|
62
62
|
};
|
|
63
63
|
export const framesOf = (s) => (s.gaitRun ??= gait(s.gait));
|
|
64
64
|
|
|
65
|
-
export function gaitChecks(s, f, { jointValues, sweepOne }) {
|
|
65
|
+
export function gaitChecks(s, f, { jointValues, sweepOne, seamAdvice }) {
|
|
66
66
|
if (!s.gait) return;
|
|
67
67
|
const r = framesOf(s);
|
|
68
68
|
for (const x of r.findings)
|
|
@@ -111,24 +111,34 @@ export function gaitChecks(s, f, { jointValues, sweepOne }) {
|
|
|
111
111
|
}
|
|
112
112
|
// Leg against leg, leg against body: the cycle as a sweep
|
|
113
113
|
const every = Math.max(1, Math.floor(r.frames.length / 12));
|
|
114
|
+
// (a clash whose fourth entry, its seam, is set is JSCAD's small measure, in doubt, as the overlap check's is of
|
|
115
|
+
// the same pair standing still: the first pose with a sure clash fails; with none, the first with a doubtful one warns)
|
|
114
116
|
let clashes = null,
|
|
117
|
+
sure = false,
|
|
115
118
|
first = null;
|
|
116
119
|
for (const [k, frame] of r.frames.entries()) {
|
|
117
120
|
if (k % every) continue;
|
|
118
|
-
const c = sweepOne(frameValues(s, frame, jointValues))
|
|
119
|
-
|
|
121
|
+
const c = sweepOne(frameValues(s, frame, jointValues)),
|
|
122
|
+
real = c.filter((x) => !x[3]);
|
|
123
|
+
if (real.length && !sure) {
|
|
124
|
+
clashes = real;
|
|
125
|
+
sure = true;
|
|
126
|
+
first = frame.t;
|
|
127
|
+
} else if (c.length && !clashes) {
|
|
120
128
|
clashes = c;
|
|
121
129
|
first = frame.t;
|
|
122
130
|
}
|
|
123
131
|
}
|
|
124
132
|
if (clashes)
|
|
125
133
|
f(
|
|
126
|
-
'fail',
|
|
134
|
+
sure ? 'fail' : 'warn',
|
|
127
135
|
`gait: at ${n3(first * 100, 0)}% of the cycle ${clashes
|
|
128
136
|
.slice(0, 3)
|
|
129
|
-
.map(([a, b]) => `${a} hits ${b}`)
|
|
130
|
-
.join(
|
|
131
|
-
|
|
137
|
+
.map(([a, b]) => `${a} ${sure ? 'hits' : 'may hit'} ${b}`)
|
|
138
|
+
.join(
|
|
139
|
+
', ',
|
|
140
|
+
)}${sure ? '' : `: a small amount, measured by JSCAD, which can read the seams its unions and cuts leave as that much overlap. ${seamAdvice()}`}`,
|
|
141
|
+
sure ? 'gait: clash' : 'gait: may clash',
|
|
132
142
|
{ code: 'gait.sweep', refs: { at: first } },
|
|
133
143
|
);
|
|
134
144
|
else
|