@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.
- package/AGENTS.md +26 -10
- package/CHANGELOG.md +442 -2
- package/EXAMPLES.md +48 -42
- package/README.md +226 -73
- package/TUTORIAL.md +2 -2
- package/bin/cad.mjs +2253 -514
- package/lib/animate.mjs +173 -49
- package/lib/assembly.mjs +1854 -437
- package/lib/beams.mjs +256 -52
- package/lib/belts.mjs +66 -15
- package/lib/board-work.mjs +12 -0
- package/lib/bought.mjs +309 -53
- package/lib/buildpage.mjs +179 -29
- package/lib/carried.mjs +201 -0
- package/lib/clone.mjs +194 -42
- package/lib/design.mjs +734 -113
- package/lib/drive.mjs +187 -63
- package/lib/edit.mjs +900 -191
- package/lib/errors.mjs +16 -3
- package/lib/explain.mjs +62 -13
- package/lib/fasten.mjs +2710 -502
- package/lib/fittings.mjs +715 -121
- package/lib/fixings.mjs +21 -9
- package/lib/framebuild.mjs +792 -176
- package/lib/framecheck.mjs +1901 -368
- package/lib/framegen.mjs +100 -22
- package/lib/frameheat.mjs +225 -42
- package/lib/frameprint.mjs +513 -108
- package/lib/frames.mjs +81 -17
- package/lib/framesize.mjs +792 -120
- package/lib/frametip.mjs +235 -0
- package/lib/gait.mjs +135 -23
- package/lib/grip.mjs +62 -13
- package/lib/guides.mjs +1403 -230
- package/lib/host.mjs +149 -18
- package/lib/inplace.mjs +171 -36
- package/lib/jigs.mjs +360 -78
- package/lib/joins.mjs +697 -118
- package/lib/jsonedit.mjs +88 -26
- package/lib/kept.mjs +84 -0
- package/lib/kit.mjs +438 -68
- package/lib/layout.mjs +3 -1
- package/lib/links.mjs +149 -42
- package/lib/list.mjs +326 -64
- package/lib/live-guard.mjs +68 -0
- package/lib/live-shape.mjs +96 -24
- package/lib/live.mjs +189 -59
- package/lib/loads.mjs +579 -130
- package/lib/machine.mjs +372 -74
- package/lib/magnets.mjs +162 -44
- package/lib/measured.mjs +417 -94
- package/lib/mesh.mjs +526 -119
- package/lib/meshcmd.mjs +215 -60
- package/lib/motors.mjs +1022 -212
- package/lib/motorsvg.mjs +114 -32
- package/lib/names.mjs +41 -0
- package/lib/optimise.mjs +979 -283
- package/lib/order.mjs +519 -112
- package/lib/panels.mjs +482 -94
- package/lib/parts.mjs +78 -23
- package/lib/pins.mjs +163 -44
- package/lib/plates.mjs +224 -36
- package/lib/player.mjs +37 -9
- package/lib/power.mjs +64 -13
- package/lib/preview.mjs +83 -16
- package/lib/profilemeasure.mjs +572 -129
- package/lib/rules.mjs +38 -4
- package/lib/sandbox-hooks.mjs +154 -12
- package/lib/sandbox-preload.mjs +2 -2
- package/lib/sandbox-run.mjs +127 -12
- package/lib/sandbox.mjs +632 -35
- package/lib/schema.mjs +43 -11
- package/lib/seats.mjs +227 -49
- package/lib/services.mjs +261 -52
- package/lib/sheet.mjs +851 -178
- package/lib/slotnuts.mjs +213 -34
- package/lib/targets/gist.mjs +4 -1
- package/lib/targets.mjs +42 -6
- package/lib/task.mjs +376 -79
- package/lib/versions.mjs +113 -28
- package/lib/wires.mjs +228 -45
- package/lib/workspace.mjs +216 -17
- package/package.json +19 -19
- package/schemas/assembly.schema.json +2 -2
- package/schemas/object.schema.json +1 -1
- package/schemas/project.schema.json +1 -1
package/lib/framesize.mjs
CHANGED
|
@@ -5,26 +5,68 @@
|
|
|
5
5
|
// first buckling factor and each grouped beam against Euler's load with the same margin (as frame.buckling), and the
|
|
6
6
|
// lowest mode against what the task's moves shake it at, twice over (as frame.frequency), or a floor of the assembly's
|
|
7
7
|
// own. The frame is the one frameModelOf builds, solved in every pose; only the beams' sections, alloys, mass and roll
|
|
8
|
-
// change
|
|
9
|
-
//
|
|
8
|
+
// change, and each join's spring with them: a join's stiffness follows the beams it joins (a 4040's blind join is eight
|
|
9
|
+
// times a 2020's), so every profile pair tried is given the spring the check would give it (joinSpring). The result is a table: each group's profile, the limit that set it (the one its next lighter profile breaks)
|
|
10
|
+
// and the margin, written into the assembly by cad frame --size --write. Every join a lighter profile would make must
|
|
11
|
+
// go together (joinFit), its hex key able to reach a blind join's head; and cad frame --size --write checks the design
|
|
12
|
+
// it would write, as cad check does, and writes nothing that fails.
|
|
10
13
|
// Units: mm, N, MPa, kg, Hz.
|
|
11
14
|
import { sizing, frame as solveFrame } from '@rulecad/fea/frame';
|
|
12
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
profileModel,
|
|
17
|
+
profileChoices,
|
|
18
|
+
beamModel,
|
|
19
|
+
boughtFittingModel,
|
|
20
|
+
joinStiffness,
|
|
21
|
+
boughtStiffness,
|
|
22
|
+
JOINS,
|
|
23
|
+
outline,
|
|
24
|
+
footModel,
|
|
25
|
+
levellingFootModel,
|
|
26
|
+
stackingFootModel,
|
|
27
|
+
} from '@rulecad/frames';
|
|
13
28
|
import { fixingModel } from '@rulecad/fixings';
|
|
14
|
-
import { frameModelOf, FRAME_CHECK, excitesOf, rackOf, sideways, freeSaid } from './framecheck.mjs';
|
|
29
|
+
import { frameModelOf, FRAME_CHECK, excitesOf, rackOf, sideways, freeSaid, endSprings } from './framecheck.mjs';
|
|
15
30
|
import { framesContext } from './beams.mjs';
|
|
16
31
|
import { givenFor } from './frames.mjs';
|
|
32
|
+
import { fittingModel, fittedStiffness, plasticOf } from './fittings.mjs';
|
|
33
|
+
import { peekRuleSet } from './rules.mjs';
|
|
17
34
|
|
|
18
35
|
const shown = (v) => (v === undefined ? 'nothing' : JSON.stringify(v));
|
|
19
|
-
const n3 = (x, d = 3) => String(+Number(x).toFixed(d)),
|
|
36
|
+
const n3 = (x, d = 3) => String(+Number(x).toFixed(d)),
|
|
37
|
+
r3 = (x) => +Number(x).toFixed(3);
|
|
20
38
|
|
|
21
39
|
/** The working figures of the frame's sizing, each with what it rests on. */
|
|
22
40
|
export const FRAME_SIZING = {
|
|
23
|
-
profiles: {
|
|
24
|
-
|
|
41
|
+
profiles: {
|
|
42
|
+
value: [
|
|
43
|
+
'2020-misumi-hfs5',
|
|
44
|
+
'2040-misumi-hfs5',
|
|
45
|
+
'2060-misumi-hfs5',
|
|
46
|
+
'3030-misumi-hfs6',
|
|
47
|
+
'3060-misumi-hfs6',
|
|
48
|
+
'4040-misumi-hfs8',
|
|
49
|
+
'4080-misumi-hfs8',
|
|
50
|
+
],
|
|
51
|
+
unit: '',
|
|
52
|
+
rule: "Where frame.size gives no profiles, the list each group is chosen from: one maker's series from 20 to 40 mm, so the slot nuts and fittings stay within three slot sizes. Each that is not square is tried lying as drawn and turned a quarter",
|
|
53
|
+
kind: 'default',
|
|
54
|
+
source: 'A working list of @rulecad/cad, from the profile sets in @rulecad/rules (MISUMI HFS5, HFS6 and HFS8)',
|
|
55
|
+
checked: '2026-11-20',
|
|
56
|
+
},
|
|
57
|
+
match: {
|
|
58
|
+
value: 0.5,
|
|
59
|
+
unit: 'mm',
|
|
60
|
+
rule: 'Beams not named in frame.size.groups are grouped by themselves: beams of one profile lying the same way whose lengths agree within this much must match (a pair of rails, four posts)',
|
|
61
|
+
kind: 'default',
|
|
62
|
+
source: "A working figure of @rulecad/cad: under any cut tolerance in the kit's profile sets",
|
|
63
|
+
checked: '2026-11-20',
|
|
64
|
+
},
|
|
25
65
|
};
|
|
26
66
|
|
|
27
67
|
const SIZE_KEYS = ['profiles', 'groups', 'limits', 'by'];
|
|
68
|
+
// the printed feet screwed into a beam's end, by fitting kind: each model says the tap and the screw it takes
|
|
69
|
+
const FOOT_MODELS = { foot: footModel, 'levelling-foot': levellingFootModel, 'stacking-foot': stackingFootModel };
|
|
28
70
|
const LIMIT_KEYS = ['deflection', 'stress', 'buckling', 'frequency', 'rack'];
|
|
29
71
|
|
|
30
72
|
/**
|
|
@@ -34,25 +76,56 @@ const LIMIT_KEYS = ['deflection', 'stress', 'buckling', 'frequency', 'rack'];
|
|
|
34
76
|
export function sizeOption(s) {
|
|
35
77
|
const o = s.a.frame?.size;
|
|
36
78
|
if (o == null) return null;
|
|
37
|
-
if (typeof o !== 'object' || Array.isArray(o))
|
|
38
|
-
|
|
79
|
+
if (typeof o !== 'object' || Array.isArray(o))
|
|
80
|
+
throw new Error(
|
|
81
|
+
`frame.size is { "profiles": ["2020-misumi-hfs5", "2040-misumi-hfs5"], "groups": { "legs": ["z1", "z2"] }, "limits": { "deflection": 1 } } (got ${shown(o)})`,
|
|
82
|
+
);
|
|
83
|
+
for (const k of Object.keys(o))
|
|
84
|
+
if (!SIZE_KEYS.includes(k)) throw new Error(`frame.size has no "${k}": it takes ${SIZE_KEYS.join(', ')}`);
|
|
39
85
|
const profiles = o.profiles ?? FRAME_SIZING.profiles.value;
|
|
40
|
-
if (!Array.isArray(profiles) || !profiles.length || !profiles.every((p) => typeof p === 'string' && p))
|
|
86
|
+
if (!Array.isArray(profiles) || !profiles.length || !profiles.every((p) => typeof p === 'string' && p))
|
|
87
|
+
throw new Error(
|
|
88
|
+
`frame.size.profiles is a list of profile sets by name, to choose each group's from (got ${shown(o.profiles)})`,
|
|
89
|
+
);
|
|
41
90
|
const groups = o.groups ?? {};
|
|
42
|
-
if (typeof groups !== 'object' || Array.isArray(groups))
|
|
43
|
-
|
|
91
|
+
if (typeof groups !== 'object' || Array.isArray(groups))
|
|
92
|
+
throw new Error(
|
|
93
|
+
`frame.size.groups is { "legs": ["z1", "z2", "z3", "z4"] }: beams that must take one profile, by name (got ${shown(o.groups)})`,
|
|
94
|
+
);
|
|
95
|
+
for (const [g, list] of Object.entries(groups))
|
|
96
|
+
if (!Array.isArray(list) || !list.length || !list.every((x) => typeof x === 'string'))
|
|
97
|
+
throw new Error(`frame.size.groups.${g} is a list of beams by name (got ${shown(list)})`);
|
|
44
98
|
const limits = o.limits ?? {};
|
|
45
|
-
if (typeof limits !== 'object' || Array.isArray(limits))
|
|
46
|
-
|
|
99
|
+
if (typeof limits !== 'object' || Array.isArray(limits))
|
|
100
|
+
throw new Error(
|
|
101
|
+
`frame.size.limits is { "deflection": mm, "stress": margin, "buckling": factor, "frequency": Hz, "rack": mm } (got ${shown(o.limits)})`,
|
|
102
|
+
);
|
|
103
|
+
for (const k of Object.keys(limits))
|
|
104
|
+
if (!LIMIT_KEYS.includes(k))
|
|
105
|
+
throw new Error(
|
|
106
|
+
`frame.size.limits has no "${k}": it takes deflection (mm), stress (a margin), buckling (a factor), frequency (Hz) and rack (the sway allowed at the top, mm)`,
|
|
107
|
+
);
|
|
47
108
|
const out = {};
|
|
48
|
-
for (const [k, v] of Object.entries(limits)) {
|
|
49
|
-
|
|
50
|
-
|
|
109
|
+
for (const [k, v] of Object.entries(limits)) {
|
|
110
|
+
const x = s.num(v);
|
|
111
|
+
if (!(x > 0)) throw new Error(`frame.size.limits.${k} is above 0 (got ${shown(v)})`);
|
|
112
|
+
out[k] = x;
|
|
113
|
+
}
|
|
114
|
+
if (o.by != null && !['mass', 'cost'].includes(o.by))
|
|
115
|
+
throw new Error(`frame.size.by is mass or cost (got ${shown(o.by)})`);
|
|
116
|
+
if (o.by === 'cost')
|
|
117
|
+
throw new Error('frame.size.by is cost, and no profile set in the kit gives a price per metre: size by mass');
|
|
51
118
|
return { profiles, groups, limits: out, by: o.by ?? 'mass' };
|
|
52
119
|
}
|
|
53
120
|
|
|
54
121
|
// The world direction a beam's face looks, from its section's normal: x across its width, y up its height, turned by roll
|
|
55
|
-
const faceAxes = (b, roll) => {
|
|
122
|
+
const faceAxes = (b, roll) => {
|
|
123
|
+
const X = [b.W[0], b.W[4], b.W[8]],
|
|
124
|
+
Y = [b.W[1], b.W[5], b.W[9]],
|
|
125
|
+
c = Math.cos((roll * Math.PI) / 180),
|
|
126
|
+
sn = Math.sin((roll * Math.PI) / 180);
|
|
127
|
+
return { X: X.map((v, k) => c * v + sn * Y[k]), Y: Y.map((v, k) => c * v - sn * X[k]) };
|
|
128
|
+
};
|
|
56
129
|
const looks = (ax, n) => ax.X.map((v, k) => v * n[0] + ax.Y[k] * n[1]);
|
|
57
130
|
|
|
58
131
|
/**
|
|
@@ -61,45 +134,220 @@ const looks = (ax, n) => ax.X.map((v, k) => v * n[0] + ax.Y[k] * n[1]);
|
|
|
61
134
|
* a slot in b's face whose opening passes the screw (the bore's thread) and holds its button head under the lips, the
|
|
62
135
|
* head no wider than the slot's cavity; an end-tap join a bore in a's end and, where b's far face has a slot, a cap
|
|
63
136
|
* head wider than its opening. A bought fitting must fit both profiles (its set's fitting.fit). A printed fitting is
|
|
64
|
-
* drawn for the profiles it joins, so it goes with any; a join whose fitting comes later is not held to one.
|
|
65
|
-
*
|
|
137
|
+
* drawn for the profiles it joins, so it goes with any; a join whose fitting comes later is not held to one. A blind
|
|
138
|
+
* join's hex key must also reach its head through the access hole across b (keyBlocked), as fasten.access needs it: an
|
|
139
|
+
* OpenBeam's slanted slot floor keeps the key off a head in its own slot. Null where it fits, else why not. @param {object} x a frame join (frameModelOf's joins) @param {{ model: object, roll: number }} pa a's profile as sized
|
|
66
140
|
* @param {{ model: object, roll: number }} pb b's @param {object} given the workspace's sets
|
|
141
|
+
* @param {(profile: object, length: number) => object} [beamOf] a beam's model of a profile and length (beamModel's; a caller asking often keeps them)
|
|
67
142
|
* @returns {string | null}
|
|
68
143
|
*/
|
|
69
|
-
export function joinFit(x, pa, pb, given) {
|
|
70
|
-
const kind = x.j.kind,
|
|
144
|
+
export function joinFit(x, pa, pb, given, beamOf = beamAt) {
|
|
145
|
+
const kind = x.j.kind,
|
|
146
|
+
A = pa.model,
|
|
147
|
+
Bm = pb.model,
|
|
148
|
+
name = (m) => m.name.replace(/^profile-/, '');
|
|
71
149
|
if (x.j.fitting && x.j.fitting !== 'printed' && JOINS[kind]?.bought) {
|
|
72
150
|
let fm;
|
|
73
|
-
try {
|
|
151
|
+
try {
|
|
152
|
+
fm = boughtFittingModel(x.j.fitting, { given, profile: Bm, other: A, join: kind });
|
|
153
|
+
} catch (e) {
|
|
154
|
+
return String(e.message).replace(/^\w+: /, '');
|
|
155
|
+
}
|
|
74
156
|
const bad = fm.findings.find((f) => f.code === 'fitting.fit' && f.level === 'fail');
|
|
75
157
|
return bad ? `${x.j.fitting} does not fit ${name(A)} to ${name(Bm)}: ${bad.text}` : null;
|
|
76
158
|
}
|
|
77
159
|
if (!['blind', 'end-tap'].includes(kind)) return null;
|
|
78
|
-
const
|
|
160
|
+
const bores = A.bores ?? [];
|
|
79
161
|
if (!bores.length) return `${name(A)} has no bore in its ends to tap, and a ${kind} join screws into one`;
|
|
80
162
|
// b's face where the join meets it, in the world, and the place of the new profile that looks that way
|
|
81
163
|
const drawn = x.B.m.places.find((q) => q.name === x.j.model.b.place);
|
|
82
164
|
if (!drawn) return null;
|
|
83
|
-
const n = looks(faceAxes(x.B, 0), drawn.normal),
|
|
84
|
-
|
|
165
|
+
const n = looks(faceAxes(x.B, 0), drawn.normal),
|
|
166
|
+
B = beamOf(Bm, x.B.L),
|
|
167
|
+
ax = faceAxes(x.B, pb.roll);
|
|
168
|
+
const place = B.places.filter((q) => {
|
|
169
|
+
const w = looks(ax, q.normal);
|
|
170
|
+
return w[0] * n[0] + w[1] * n[1] + w[2] * n[2] > 0.99;
|
|
171
|
+
})[0];
|
|
85
172
|
const thread = bores[0].thread;
|
|
86
173
|
if (!thread) return `${name(A)}'s bores name no thread`;
|
|
87
|
-
const head = (form) => {
|
|
174
|
+
const head = (form) => {
|
|
175
|
+
try {
|
|
176
|
+
return fixingModel(`${thread} ${form}`);
|
|
177
|
+
} catch {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
};
|
|
88
181
|
if (kind === 'blind') {
|
|
89
182
|
if (!place?.slot) return `${name(Bm)}'s face there is closed, and a blind join's head sits in a slot`;
|
|
90
|
-
const sl = Bm.slots[place.slot],
|
|
183
|
+
const sl = Bm.slots[place.slot],
|
|
184
|
+
fx = head('button');
|
|
91
185
|
if (!sl || !fx) return null;
|
|
92
|
-
if (fx.major > sl.opening)
|
|
93
|
-
|
|
94
|
-
if (fx.head.across
|
|
95
|
-
|
|
186
|
+
if (fx.major > sl.opening)
|
|
187
|
+
return `${a(thread)} ${thread} screw (${name(A)}'s bore) does not pass ${name(Bm)}'s ${sl.opening} mm slot opening`;
|
|
188
|
+
if (fx.head.across <= sl.opening)
|
|
189
|
+
return `${a(thread)} ${thread} button head, ${fx.head.across} mm across, pulls through ${name(Bm)}'s ${sl.opening} mm slot opening`;
|
|
190
|
+
if (fx.head.across > sl.cavityWidth)
|
|
191
|
+
return `${a(thread)} ${thread} button head, ${fx.head.across} mm across, does not go into ${name(Bm)}'s slot, ${sl.cavityWidth} mm wide under its lips`;
|
|
192
|
+
return keyBlocked(B, place, sl, thread, fx, name(Bm));
|
|
96
193
|
}
|
|
97
194
|
// end-tap: the screw through b, its cap head on b's far face
|
|
98
|
-
const far = place
|
|
99
|
-
|
|
195
|
+
const far = place
|
|
196
|
+
? B.places.find(
|
|
197
|
+
(q) => Math.abs(q.normal[0] + place.normal[0]) < 1e-9 && Math.abs(q.normal[1] + place.normal[1]) < 1e-9,
|
|
198
|
+
)
|
|
199
|
+
: null,
|
|
200
|
+
fx = head('cap');
|
|
201
|
+
if (far?.slot && fx && Bm.slots[far.slot] && fx.head.across <= Bm.slots[far.slot].opening)
|
|
202
|
+
return `${a(thread)} ${thread} cap head, ${fx.head.across} mm across, falls through ${name(Bm)}'s ${Bm.slots[far.slot].opening} mm slot opening on its far face`;
|
|
100
203
|
return null;
|
|
101
204
|
}
|
|
102
205
|
const a = () => 'an'; // (a metric thread's name is said em: an M5, an M3)
|
|
206
|
+
const beamAt = (profile, length) => beamModel(profile, { length });
|
|
207
|
+
|
|
208
|
+
// Where a line across a section (from p, along d) is in metal: the spans [t0, t1] along it, from the outline's loops
|
|
209
|
+
// (as @rulecad/frames' operations find a hole's walls)
|
|
210
|
+
function metalAlong(loops, p, d) {
|
|
211
|
+
const ts = [];
|
|
212
|
+
for (const loop of loops)
|
|
213
|
+
for (let i = 0; i < loop.length; i++) {
|
|
214
|
+
const q0 = loop[i],
|
|
215
|
+
q1 = loop[(i + 1) % loop.length];
|
|
216
|
+
const s0 = d[0] * (q0[1] - p[1]) - d[1] * (q0[0] - p[0]),
|
|
217
|
+
s1 = d[0] * (q1[1] - p[1]) - d[1] * (q1[0] - p[0]);
|
|
218
|
+
if (s0 > 0 === s1 > 0) continue;
|
|
219
|
+
const k = s0 / (s0 - s1);
|
|
220
|
+
ts.push((q0[0] + k * (q1[0] - q0[0]) - p[0]) * d[0] + (q0[1] + k * (q1[1] - q0[1]) - p[1]) * d[1]);
|
|
221
|
+
}
|
|
222
|
+
ts.sort((x, y) => x - y);
|
|
223
|
+
const out = [];
|
|
224
|
+
for (let i = 0; i + 1 < ts.length; i += 2) out.push([ts[i], ts[i + 1]]);
|
|
225
|
+
return out;
|
|
226
|
+
}
|
|
227
|
+
const KEY_STRIPS = 16; // (lines across the key's width the section is looked along: its corners and between)
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Whether a blind join's hex key reaches its head straight, as fasten.access looks for it: the key comes in through
|
|
231
|
+
* the access hole drilled across b from its far face (the hole @rulecad/frames drills for the join, to its own depth)
|
|
232
|
+
* and on through b's section to the head under the near slot's lips. The section is the same all along the beam, so
|
|
233
|
+
* any metal across the key's width (its corners', from the hexkey set) between the head's top and the hole's end, or
|
|
234
|
+
* in the hole wider than the hole, stands in its way: a slot floor that slants down to a narrow groove (OpenBeam's)
|
|
235
|
+
* keeps the key off the head. Null where it reaches, else why not.
|
|
236
|
+
* @param {object} B b's beam model @param {object} place the place on b the head sits under @param {object} sl its slot
|
|
237
|
+
* @param {string} thread the screw's thread @param {object} fx its button-head screw's model @param {string} bName b's profile, as said
|
|
238
|
+
* @returns {string | null}
|
|
239
|
+
*/
|
|
240
|
+
function keyBlocked(B, place, sl, thread, fx, bName) {
|
|
241
|
+
const key = fx.head.key;
|
|
242
|
+
if (!(key > 0)) return null;
|
|
243
|
+
// the place across from it on the same line, as @rulecad/frames' blind join drills its access hole (on a face with
|
|
244
|
+
// two slots, a 2040's, the one in line with the head's)
|
|
245
|
+
const far = B.places.find(
|
|
246
|
+
(q) =>
|
|
247
|
+
Math.abs(q.normal[0] + place.normal[0]) < 1e-9 &&
|
|
248
|
+
Math.abs(q.normal[1] + place.normal[1]) < 1e-9 &&
|
|
249
|
+
Math.abs(place.normal[0] * (q.at[1] - place.at[1]) - place.normal[1] * (q.at[0] - place.at[0])) < 1e-6,
|
|
250
|
+
);
|
|
251
|
+
if (!far) return null; // (the join itself refuses a face with none across it)
|
|
252
|
+
let op;
|
|
253
|
+
try {
|
|
254
|
+
op = beamModel(B.profile, {
|
|
255
|
+
length: B.length,
|
|
256
|
+
ops: [{ op: 'access', at: `${far.name}@${B.length / 2}`, thread, head: 'button', through: 'beam' }],
|
|
257
|
+
}).ops.find((o) => o.op === 'access');
|
|
258
|
+
} catch {
|
|
259
|
+
return null; // (an access hole that cannot be drilled is the join's own refusal, said when it is built)
|
|
260
|
+
}
|
|
261
|
+
let radius = key / Math.cos(Math.PI / 6) / 2;
|
|
262
|
+
try {
|
|
263
|
+
const set = peekRuleSet('hexkey').rules,
|
|
264
|
+
i = set.sizes.value.findIndex((s) => Math.abs(s - key) < 1e-6);
|
|
265
|
+
if (i >= 0) radius = set.corners.value[i] / 2;
|
|
266
|
+
} catch {
|
|
267
|
+
// (no hexkey set: the key's corners by its size)
|
|
268
|
+
}
|
|
269
|
+
const loops = outline(B.profile).loops,
|
|
270
|
+
d = [-place.normal[0], -place.normal[1]],
|
|
271
|
+
side = [place.normal[1], -place.normal[0]];
|
|
272
|
+
// depths from b's near face, inward: the head's top, and where the access hole from the far face ends
|
|
273
|
+
const T = Math.max(...loops.flat().map((q) => (q[0] - place.at[0]) * d[0] + (q[1] - place.at[1]) * d[1])),
|
|
274
|
+
top = sl.lip + fx.head.height,
|
|
275
|
+
holeEnd = T - op.depth,
|
|
276
|
+
hole = op.diameter / 2;
|
|
277
|
+
for (let k = 0; k <= KEY_STRIPS; k++) {
|
|
278
|
+
const s = radius * ((2 * k) / KEY_STRIPS - 1),
|
|
279
|
+
p = [place.at[0] + side[0] * s, place.at[1] + side[1] * s];
|
|
280
|
+
for (const [t0, t1] of metalAlong(loops, p, d)) {
|
|
281
|
+
const undrilled = t1 > top + 1e-3 && t0 < holeEnd - 1e-3,
|
|
282
|
+
outsideHole = Math.abs(s) > hole + 1e-9 && t1 > Math.max(top, holeEnd) + 1e-3 && t0 < T - 1e-3;
|
|
283
|
+
if (undrilled || outsideHole)
|
|
284
|
+
return `a ${mm1(key)} mm hex key cannot reach ${a(thread)} ${thread} button head in ${bName}'s slot: ${
|
|
285
|
+
undrilled
|
|
286
|
+
? `${bName}'s section stands in its way ${mm1(Math.max(t0, top) - top)} mm over the head, past the end of the Ø${mm1(op.diameter)} mm access hole`
|
|
287
|
+
: `the key is ${mm1(2 * radius)} mm across its corners and the access hole Ø${mm1(op.diameter)} mm`
|
|
288
|
+
}`;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
const mm1 = (x) => String(+Number(x).toFixed(2));
|
|
294
|
+
|
|
295
|
+
// a place's face as a fitting names it: the face, or the place where the face has several (a 2040's top.1)
|
|
296
|
+
const faceName = (B, q) => (B.places.filter((p) => p.face === q.face).length > 1 ? q.name : q.face);
|
|
297
|
+
// the slotted place of beam model M, turned by roll on drawn beam b, that looks the way drawn model D's named face does
|
|
298
|
+
const sameWay = (b, D, face, M, roll) => {
|
|
299
|
+
const drawn = D.places.find((q) => q.name === face) ?? D.places.find((q) => q.face === face);
|
|
300
|
+
if (!drawn) return null;
|
|
301
|
+
const n = looks(faceAxes(b, 0), drawn.normal),
|
|
302
|
+
ax = faceAxes(b, roll);
|
|
303
|
+
return (
|
|
304
|
+
M.places.find((q) => {
|
|
305
|
+
const w = looks(ax, q.normal);
|
|
306
|
+
return q.slot && w[0] * n[0] + w[1] * n[1] + w[2] * n[2] > 0.99;
|
|
307
|
+
}) ?? null
|
|
308
|
+
);
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* A join's spring with its beams given other profiles, as the check works it out for a frame drawn in them
|
|
313
|
+
* (@rulecad/frames' joinModel, and cad's joins): the kind's estimate scaled to a's profile (joinStiffness), a bought
|
|
314
|
+
* fitting's own figures (boughtStiffness), or a printed fitting drawn for the new profiles and its stiffness by
|
|
315
|
+
* finite elements (fittedStiffness). Refused where the printed fitting cannot be drawn for them, with why.
|
|
316
|
+
* @param {object} x a frame join (frameModelOf's joins) @param {{ model: object, roll: number }} pa a's profile as sized
|
|
317
|
+
* @param {{ model: object, roll: number }} pb b's @param {{ given: object, context: object, material: any, fitted: object | null }} o
|
|
318
|
+
* the workspace's sets, the frames context, the project's plastic, and the drawn printed fitting's spec (its item's "fitting")
|
|
319
|
+
* @param {(profile: object, length: number) => object} [beamOf] a beam's model of a profile and length, as joinFit takes
|
|
320
|
+
* @returns {{ bending: number, twist: number }}
|
|
321
|
+
*/
|
|
322
|
+
export function joinSpring(x, pa, pb, o, beamOf = beamAt) {
|
|
323
|
+
const kind = x.j.kind,
|
|
324
|
+
fitting = x.j.fitting,
|
|
325
|
+
A = beamOf(pa.model, x.A.L),
|
|
326
|
+
B = beamOf(pb.model, x.B.L);
|
|
327
|
+
const named = fitting != null && fitting !== 'printed' && JOINS[kind]?.bought;
|
|
328
|
+
const k = joinStiffness(kind, A, named ? {} : { ...(fitting != null ? { fitting } : {}), given: o.given });
|
|
329
|
+
if (named)
|
|
330
|
+
return boughtStiffness(
|
|
331
|
+
kind,
|
|
332
|
+
A,
|
|
333
|
+
boughtFittingModel(fitting, { given: o.given, profile: B.profile, other: A.profile, join: kind }),
|
|
334
|
+
);
|
|
335
|
+
if (fitting !== 'printed' || !o.fitted) return k;
|
|
336
|
+
// a printed fitting: drawn again for the new profiles, on the faces that look the way the drawn one's do
|
|
337
|
+
const spec = { ...o.fitted, profile: pb.model.name };
|
|
338
|
+
delete spec.other;
|
|
339
|
+
if (pa.model.name !== pb.model.name) spec.other = pa.model.name;
|
|
340
|
+
for (const [key, b, D, M, roll] of [
|
|
341
|
+
['face', x.B, x.B.m, B, pb.roll],
|
|
342
|
+
['otherFace', x.A, x.A.m, A, pa.roll],
|
|
343
|
+
]) {
|
|
344
|
+
if (spec[key] == null) continue;
|
|
345
|
+
const q = sameWay(b, D, spec[key], M, roll);
|
|
346
|
+
if (!q) throw new Error(`${pb.model.name}'s face there has no slot for the printed ${kind} to screw into`);
|
|
347
|
+
spec[key] = faceName(M, q);
|
|
348
|
+
}
|
|
349
|
+
return fittedStiffness(k, fittingModel(spec, o.context, o.material, x.j.label));
|
|
350
|
+
}
|
|
103
351
|
|
|
104
352
|
/**
|
|
105
353
|
* The frame's sizing: frameModelOf's frame, its beams grouped, each group given the lightest profile from the list that
|
|
@@ -114,123 +362,417 @@ export function frameSizing(s, helpers, given) {
|
|
|
114
362
|
const fm = frameModelOf(s, helpers);
|
|
115
363
|
if (!fm || fm.empty) return null;
|
|
116
364
|
// the groups: named ones, then the rest by direction, profile and length
|
|
117
|
-
const groups = {},
|
|
365
|
+
const groups = {},
|
|
366
|
+
taken = new Map();
|
|
118
367
|
for (const [g, list] of Object.entries(opt.groups)) {
|
|
119
368
|
for (const id of list) {
|
|
120
|
-
if (!fm.beams.has(id))
|
|
121
|
-
|
|
369
|
+
if (!fm.beams.has(id))
|
|
370
|
+
throw new Error(
|
|
371
|
+
`frame.size.groups.${g}: ${id} is not a beam of the frame (its beams: ${[...fm.beams.keys()].join(', ')})`,
|
|
372
|
+
);
|
|
373
|
+
if (taken.has(id))
|
|
374
|
+
throw new Error(`frame.size.groups: ${id} is in ${taken.get(id)} and in ${g}: a beam takes one profile`);
|
|
122
375
|
taken.set(id, g);
|
|
123
376
|
}
|
|
124
377
|
groups[g] = list;
|
|
125
378
|
}
|
|
126
|
-
const near = FRAME_SIZING.match.value,
|
|
379
|
+
const near = FRAME_SIZING.match.value,
|
|
380
|
+
auto = [];
|
|
127
381
|
for (const b of fm.beams.values()) {
|
|
128
382
|
if (taken.has(b.id)) continue;
|
|
129
|
-
const mate = auto.find(
|
|
130
|
-
|
|
383
|
+
const mate = auto.find(
|
|
384
|
+
(x) =>
|
|
385
|
+
x.profile === b.m.profile.name &&
|
|
386
|
+
Math.abs(x.L - b.L) <= near &&
|
|
387
|
+
Math.abs(Math.abs(x.u[0] * b.u[0] + x.u[1] * b.u[1] + x.u[2] * b.u[2]) - 1) < 1e-6,
|
|
388
|
+
);
|
|
389
|
+
if (mate) mate.ids.push(b.id);
|
|
390
|
+
else auto.push({ profile: b.m.profile.name, L: b.L, u: b.u, ids: [b.id] });
|
|
131
391
|
}
|
|
132
392
|
for (const x of auto) groups[x.ids.join(', ')] = x.ids;
|
|
133
393
|
// the choices, from the workspace's sets before the kit's
|
|
134
|
-
const context = framesContext(),
|
|
394
|
+
const context = framesContext(),
|
|
395
|
+
choices = [],
|
|
396
|
+
models = new Map(),
|
|
397
|
+
modelOf = (name) => {
|
|
398
|
+
if (!models.has(name)) models.set(name, profileModel(name, {}, givenFor(context, name)));
|
|
399
|
+
return models.get(name);
|
|
400
|
+
};
|
|
135
401
|
for (const name of opt.profiles) {
|
|
136
402
|
let m;
|
|
137
|
-
try {
|
|
138
|
-
|
|
403
|
+
try {
|
|
404
|
+
m = profileModel(name, {}, givenFor(context, name));
|
|
405
|
+
} catch (e) {
|
|
406
|
+
throw new Error(`frame.size.profiles: ${String(e.message).replace(/^profileModel: /, '')}`);
|
|
407
|
+
}
|
|
408
|
+
try {
|
|
409
|
+
choices.push(...profileChoices(m));
|
|
410
|
+
} catch (e) {
|
|
411
|
+
throw new Error(`frame.size.profiles: ${String(e.message).replace(/^profileChoices: /, '')}`);
|
|
412
|
+
}
|
|
139
413
|
}
|
|
140
414
|
// the limits: the frame checks' own, or the assembly's in their place
|
|
141
|
-
const margin = FRAME_CHECK.margin.value,
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
415
|
+
const margin = FRAME_CHECK.margin.value,
|
|
416
|
+
deflection = [],
|
|
417
|
+
limitRows = [];
|
|
418
|
+
const limitOf = (b, own) =>
|
|
419
|
+
opt.limits.deflection != null
|
|
420
|
+
? { value: opt.limits.deflection, from: 'frame.size.limits.deflection' }
|
|
421
|
+
: own
|
|
422
|
+
? { value: own.value, from: own.from }
|
|
423
|
+
: s.a.frame?.limit != null
|
|
424
|
+
? { value: s.num(s.a.frame.limit), from: 'frame.limit' }
|
|
425
|
+
: s.task?.accuracy != null
|
|
426
|
+
? { value: s.task.accuracy, from: "the task's accuracy" }
|
|
427
|
+
: { value: b.L / FRAME_CHECK.sag.value, from: `${b.id}'s span over ${FRAME_CHECK.sag.value} (frame.sag)` };
|
|
145
428
|
for (const l of fm.loads) {
|
|
146
|
-
const b = l.beam ?? l.mount.beam,
|
|
429
|
+
const b = l.beam ?? l.mount.beam,
|
|
430
|
+
lim = limitOf(b);
|
|
147
431
|
// a load that moves with a joint is held to its limit wherever along the beam it is; a still one at its node
|
|
148
|
-
if (l.beam || !l.mount.mover) {
|
|
149
|
-
|
|
432
|
+
if (l.beam || !l.mount.mover) {
|
|
433
|
+
const n = fm.nodeAt(b, l.beam ? l.z : fm.mountStation(l.mount, fm.cases[0].values));
|
|
434
|
+
deflection.push({ node: n, limit: lim.value, along: fm.down });
|
|
435
|
+
limitRows.push({ limit: 'deflection', where: n, what: l.where, value: lim.value, from: lim.from });
|
|
436
|
+
} else {
|
|
437
|
+
deflection.push({ member: b.id, limit: lim.value, along: fm.down });
|
|
438
|
+
limitRows.push({
|
|
439
|
+
limit: 'deflection',
|
|
440
|
+
where: b.id,
|
|
441
|
+
what: `${l.where}, anywhere it moves`,
|
|
442
|
+
value: lim.value,
|
|
443
|
+
from: lim.from,
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
for (const p of fm.points) {
|
|
448
|
+
const n = fm.nodeAt(p.beam, p.z),
|
|
449
|
+
lim = limitOf(p.beam);
|
|
450
|
+
deflection.push({ node: n, limit: lim.value, along: fm.down });
|
|
451
|
+
limitRows.push({ limit: 'deflection', where: n, what: p.where, value: lim.value, from: lim.from });
|
|
150
452
|
}
|
|
151
|
-
for (const p of fm.points) { const n = fm.nodeAt(p.beam, p.z), lim = limitOf(p.beam); deflection.push({ node: n, limit: lim.value, along: fm.down }); limitRows.push({ limit: 'deflection', where: n, what: p.where, value: lim.value, from: lim.from }); }
|
|
152
453
|
for (const g of fm.guides) {
|
|
153
|
-
const lim = limitOf(
|
|
454
|
+
const lim = limitOf(
|
|
455
|
+
g.beam,
|
|
456
|
+
g.tolerance
|
|
457
|
+
? { value: g.tolerance.value, from: `the rail's own parallelism (${g.tolerance.note ?? g.tolerance.term})` }
|
|
458
|
+
: null,
|
|
459
|
+
);
|
|
154
460
|
deflection.push({ member: g.beam.id, from: g.from, to: g.to, limit: lim.value, along: fm.down });
|
|
155
|
-
limitRows.push({
|
|
461
|
+
limitRows.push({
|
|
462
|
+
limit: 'deflection',
|
|
463
|
+
where: g.beam.id,
|
|
464
|
+
what: `under guide ${g.id}`,
|
|
465
|
+
value: lim.value,
|
|
466
|
+
from: lim.from,
|
|
467
|
+
});
|
|
156
468
|
}
|
|
157
|
-
const stress = opt.limits.stress ?? margin,
|
|
158
|
-
|
|
159
|
-
limitRows.push({
|
|
160
|
-
|
|
161
|
-
|
|
469
|
+
const stress = opt.limits.stress ?? margin,
|
|
470
|
+
factor = opt.limits.buckling ?? margin;
|
|
471
|
+
limitRows.push({
|
|
472
|
+
limit: 'stress',
|
|
473
|
+
where: 'each beam',
|
|
474
|
+
value: stress,
|
|
475
|
+
from: opt.limits.stress != null ? 'frame.size.limits.stress' : 'frame.margin',
|
|
476
|
+
});
|
|
477
|
+
limitRows.push({
|
|
478
|
+
limit: 'buckling',
|
|
479
|
+
where: 'the frame and each grouped beam (Euler, K 1)',
|
|
480
|
+
value: factor,
|
|
481
|
+
from: opt.limits.buckling != null ? 'frame.size.limits.buckling' : 'frame.margin',
|
|
482
|
+
});
|
|
483
|
+
const moves = excitesOf(s).filter((x) => x.kind === 'move'),
|
|
484
|
+
Hz = opt.limits.frequency ?? (moves.length ? Math.max(...moves.map((x) => x.Hz)) * margin : null);
|
|
485
|
+
if (Hz != null)
|
|
486
|
+
limitRows.push({
|
|
487
|
+
limit: 'frequency',
|
|
488
|
+
where: 'the frame',
|
|
489
|
+
value: Hz,
|
|
490
|
+
from: opt.limits.frequency != null ? 'frame.size.limits.frequency' : `twice the task's moves (frame.frequency)`,
|
|
491
|
+
});
|
|
162
492
|
// racking, where the assembly asks it of the frame (frame.rack) or of its sizing (limits.rack): each way across, the
|
|
163
493
|
// side push alone at the top, with no weight, held to the sway allowed at each top node; a way nothing holds the
|
|
164
494
|
// frame (one plane on pinned feet) cannot be sized against, and is said
|
|
165
495
|
const rackCases = [];
|
|
166
496
|
const rk = s.a.frame?.rack != null || opt.limits.rack != null ? rackOf(s, fm) : null;
|
|
167
497
|
if (rk) {
|
|
168
|
-
const lim = opt.limits.rack != null ? { value: opt.limits.rack, from: 'frame.size.limits.rack' } : rk.lim,
|
|
498
|
+
const lim = opt.limits.rack != null ? { value: opt.limits.rack, from: 'frame.size.limits.rack' } : rk.lim,
|
|
499
|
+
drawnFrame = solveFrame(fm.model);
|
|
169
500
|
for (const { dir, name } of sideways(fm.down)) {
|
|
170
|
-
const label = `racked ${name}`,
|
|
171
|
-
|
|
501
|
+
const label = `racked ${name}`,
|
|
502
|
+
loads = rk.top.map((n) => ({ node: n, force: dir.map((v) => (v * rk.F) / rk.top.length) }));
|
|
503
|
+
try {
|
|
504
|
+
drawnFrame.statics({ loads, gravity: [0, 0, 0] });
|
|
505
|
+
} catch (e) {
|
|
172
506
|
if (e.code !== 'fea.frame.mechanism' || !e.driven) throw e;
|
|
173
|
-
limitRows.push({
|
|
507
|
+
limitRows.push({
|
|
508
|
+
limit: 'rack',
|
|
509
|
+
where: name,
|
|
510
|
+
what: `not sized: nothing holds the frame ${name}, ${freeSaid(
|
|
511
|
+
fm,
|
|
512
|
+
(drawnFrame.mechanisms ?? []).filter((m) =>
|
|
513
|
+
e.loose.some((l) => l.node === m.node && l.freedom === m.freedom),
|
|
514
|
+
),
|
|
515
|
+
)}; a brace or fixed feet, not a profile, holds it`,
|
|
516
|
+
value: null,
|
|
517
|
+
from: rk.loadFrom,
|
|
518
|
+
});
|
|
174
519
|
continue;
|
|
175
520
|
}
|
|
176
521
|
rackCases.push({ label, loads, gravity: [0, 0, 0], limits: ['deflection'] });
|
|
177
522
|
for (const n of rk.top) deflection.push({ node: n, limit: lim.value, along: dir, cases: [label] });
|
|
178
|
-
limitRows.push({
|
|
523
|
+
limitRows.push({
|
|
524
|
+
limit: 'deflection',
|
|
525
|
+
where: rk.top.join(', '),
|
|
526
|
+
what: `the top, ${label} by ${n3(rk.F, 1)} N (${rk.loadFrom})`,
|
|
527
|
+
value: lim.value,
|
|
528
|
+
from: lim.from,
|
|
529
|
+
});
|
|
179
530
|
}
|
|
180
531
|
// the sag limits hold in the poses, not under the push
|
|
181
532
|
if (rackCases.length) for (const d of deflection) if (!d.cases) d.cases = fm.cases.map((c) => c.label);
|
|
182
533
|
}
|
|
183
|
-
const limits = {
|
|
534
|
+
const limits = {
|
|
535
|
+
...(deflection.length ? { deflection } : {}),
|
|
536
|
+
stress: { margin: stress },
|
|
537
|
+
buckling: { factor, euler: FRAME_CHECK.euler.value },
|
|
538
|
+
...(Hz != null ? { frequency: { Hz } } : {}),
|
|
539
|
+
};
|
|
184
540
|
// every beam's alloy carries its strength, so the beams outside the groups are held to it too
|
|
185
|
-
const withStrength = (model) => ({
|
|
186
|
-
|
|
541
|
+
const withStrength = (model) => ({
|
|
542
|
+
...model,
|
|
543
|
+
materials: Object.fromEntries(
|
|
544
|
+
Object.entries(model.materials).map(([k, v]) => [
|
|
545
|
+
k,
|
|
546
|
+
fm.beams.get(k)?.strength ? { ...v, strength: fm.beams.get(k).strength } : v,
|
|
547
|
+
]),
|
|
548
|
+
),
|
|
549
|
+
});
|
|
550
|
+
const cases = [
|
|
551
|
+
...fm.cases.map((c) => ({
|
|
552
|
+
label: c.label,
|
|
553
|
+
loads: fm.nodeLoads(c.values, null, c.push, c.stall),
|
|
554
|
+
inertia: fm.nodeMasses(c.values),
|
|
555
|
+
})),
|
|
556
|
+
...rackCases,
|
|
557
|
+
];
|
|
187
558
|
const byName = new Map(choices.map((c) => [c.name, c]));
|
|
188
559
|
// every join a group's beam makes must go together with the profiles chosen (joinFit): a design where one does not is
|
|
189
560
|
// never solved, and a lighter choice that breaks one is what set the group. A join as drawn is not asked again
|
|
190
|
-
const groupOf = new Map(Object.entries(groups).flatMap(([g, ids]) => ids.map((id) => [id, g]))),
|
|
191
|
-
|
|
192
|
-
|
|
561
|
+
const groupOf = new Map(Object.entries(groups).flatMap(([g, ids]) => ids.map((id) => [id, g]))),
|
|
562
|
+
sets = { sets: context?.sets ?? {} },
|
|
563
|
+
fitMemo = new Map(),
|
|
564
|
+
beams = new Map(),
|
|
565
|
+
beamOf = (m, L) => {
|
|
566
|
+
// (a beam's model works out its section, its twist by a raster, once a profile and length: a box asks often)
|
|
567
|
+
const key = `${m.name}|${L}`;
|
|
568
|
+
if (!beams.has(key)) beams.set(key, beamModel(m, { length: L }));
|
|
569
|
+
return beams.get(key);
|
|
570
|
+
};
|
|
571
|
+
const asSized = (b, design) => {
|
|
572
|
+
const g = groupOf.get(b.id),
|
|
573
|
+
c = g ? byName.get(design[g]) : null;
|
|
574
|
+
return c ? { name: c.profile, roll: c.roll ?? 0 } : { name: b.m.profile.name, roll: 0, drawn: true };
|
|
575
|
+
};
|
|
576
|
+
const pairs = fm.joins.filter(
|
|
577
|
+
(x) => fm.beams.has(x.A.id) && fm.beams.has(x.B.id) && (groupOf.has(x.A.id) || groupOf.has(x.B.id)),
|
|
578
|
+
);
|
|
579
|
+
// each join's spring follows its beams' profiles (joinSpring): worked out once a profile pair, for each design solved.
|
|
580
|
+
// A printed fitting that cannot be drawn for a pair is a join that does not go together
|
|
581
|
+
const material = plasticOf(s.project),
|
|
582
|
+
drawnFitting = (x) =>
|
|
583
|
+
x.j.fitted ? ((s.a.items || []).find((it) => it.id === x.j.fitted.item)?.fitting ?? null) : null,
|
|
584
|
+
springMemo = new Map();
|
|
585
|
+
const springOf = (x, pa, pb) => {
|
|
586
|
+
const key = `${x.j.index}|${pa.name}|${pa.roll}|${pb.name}|${pb.roll}`;
|
|
587
|
+
if (!springMemo.has(key)) {
|
|
588
|
+
let r;
|
|
589
|
+
try {
|
|
590
|
+
r = {
|
|
591
|
+
k: joinSpring(
|
|
592
|
+
x,
|
|
593
|
+
{ model: modelOf(pa.name), roll: pa.roll },
|
|
594
|
+
{ model: modelOf(pb.name), roll: pb.roll },
|
|
595
|
+
{ given: sets, context, material, fitted: drawnFitting(x) },
|
|
596
|
+
beamOf,
|
|
597
|
+
),
|
|
598
|
+
};
|
|
599
|
+
} catch (e) {
|
|
600
|
+
// (a fault in the code, not a fitting that cannot be drawn, is never said as a join that does not go together)
|
|
601
|
+
if (x.j.fitting !== 'printed' || e instanceof TypeError || e instanceof ReferenceError) throw e;
|
|
602
|
+
r = { why: String(e.message).replace(/^[^:]*: /, '') };
|
|
603
|
+
}
|
|
604
|
+
springMemo.set(key, r);
|
|
605
|
+
}
|
|
606
|
+
return springMemo.get(key);
|
|
607
|
+
};
|
|
193
608
|
const fits = (design) => {
|
|
194
609
|
const out = [];
|
|
195
610
|
for (const x of pairs) {
|
|
196
|
-
const pa = asSized(x.A, design),
|
|
611
|
+
const pa = asSized(x.A, design),
|
|
612
|
+
pb = asSized(x.B, design);
|
|
197
613
|
if (pa.drawn && pb.drawn) continue;
|
|
198
614
|
const key = `${x.j.index}|${pa.name}|${pa.roll}|${pb.name}|${pb.roll}`;
|
|
199
|
-
if (!fitMemo.has(key))
|
|
615
|
+
if (!fitMemo.has(key))
|
|
616
|
+
fitMemo.set(
|
|
617
|
+
key,
|
|
618
|
+
joinFit(
|
|
619
|
+
x,
|
|
620
|
+
{ model: modelOf(pa.name), roll: pa.roll },
|
|
621
|
+
{ model: modelOf(pb.name), roll: pb.roll },
|
|
622
|
+
sets,
|
|
623
|
+
beamOf,
|
|
624
|
+
) ??
|
|
625
|
+
springOf(x, pa, pb).why ??
|
|
626
|
+
null,
|
|
627
|
+
);
|
|
200
628
|
const why = fitMemo.get(key);
|
|
201
629
|
if (why) out.push({ where: x.j.label, why });
|
|
202
630
|
}
|
|
203
631
|
return out;
|
|
204
632
|
};
|
|
205
|
-
const
|
|
633
|
+
const springs = fm.springs.filter((p) => p.el && pairs.includes(p.x));
|
|
634
|
+
const ends = (design) => {
|
|
635
|
+
// (each element end that changes with the design, from every join at it: a brace's spring adds to its join's)
|
|
636
|
+
const at = new Map();
|
|
637
|
+
for (const p of springs) {
|
|
638
|
+
const pa = asSized(p.x.A, design),
|
|
639
|
+
pb = asSized(p.x.B, design);
|
|
640
|
+
if (pa.drawn && pb.drawn) continue;
|
|
641
|
+
if (!at.has(p.el.id)) at.set(p.el.id, []);
|
|
642
|
+
at.get(p.el.id).push(p);
|
|
643
|
+
}
|
|
644
|
+
const out = {};
|
|
645
|
+
for (const [id, list] of at) {
|
|
646
|
+
// an end kept is still held by every join there, the ones the design leaves as drawn too
|
|
647
|
+
const all = springs.filter((p) => p.el.id === id && list.some((q) => q.end === p.end));
|
|
648
|
+
out[id] = endSprings(
|
|
649
|
+
all.map((p) => ({ end: p.end, k: springOf(p.x, asSized(p.x.A, design), asSized(p.x.B, design)).k })),
|
|
650
|
+
);
|
|
651
|
+
}
|
|
652
|
+
return out;
|
|
653
|
+
};
|
|
654
|
+
const sized = sizing([withStrength(fm.model), withStrength(fm.rigid)], {
|
|
655
|
+
groups,
|
|
656
|
+
choices,
|
|
657
|
+
limits,
|
|
658
|
+
cases,
|
|
659
|
+
by: opt.by,
|
|
660
|
+
...(pairs.length ? { fits } : {}),
|
|
661
|
+
...(springs.length ? { ends } : {}),
|
|
662
|
+
});
|
|
206
663
|
const rows = sized.groups.map((g) => {
|
|
207
|
-
const c = byName.get(g.choice),
|
|
664
|
+
const c = byName.get(g.choice),
|
|
665
|
+
drawn = [...new Set(g.members.map((id) => fm.beams.get(id).m.profile.name.replace(/^profile-/, '')))];
|
|
208
666
|
const drawnKg = g.members.reduce((t, id) => t + fm.beams.get(id).grams / 1000, 0);
|
|
209
|
-
return {
|
|
210
|
-
|
|
667
|
+
return {
|
|
668
|
+
group: g.name,
|
|
669
|
+
beams: g.members,
|
|
670
|
+
profile: c.profile,
|
|
671
|
+
roll: c.roll,
|
|
672
|
+
choice: g.choice,
|
|
673
|
+
drawn,
|
|
674
|
+
length: r3(g.length),
|
|
675
|
+
kg: r3(g.mass),
|
|
676
|
+
drawnKg: r3(drawnKg),
|
|
677
|
+
lighter: g.lighter,
|
|
678
|
+
governs: g.governs
|
|
679
|
+
? g.governs.limit === 'fit'
|
|
680
|
+
? { limit: 'fit', where: g.governs.where, why: g.governs.why, lighter: g.governs.lighter, broken: null }
|
|
681
|
+
: {
|
|
682
|
+
limit: g.governs.limit,
|
|
683
|
+
where: g.governs.where,
|
|
684
|
+
value: r3(g.governs.value),
|
|
685
|
+
allowed: r3(g.governs.allowed),
|
|
686
|
+
case: g.governs.case,
|
|
687
|
+
lighter: g.governs.lighter,
|
|
688
|
+
broken: r3(g.governs.broken),
|
|
689
|
+
}
|
|
690
|
+
: null,
|
|
691
|
+
margin: g.margin == null ? null : r3(g.margin),
|
|
692
|
+
};
|
|
211
693
|
});
|
|
212
|
-
const drawn = [...fm.beams.values()]
|
|
213
|
-
|
|
694
|
+
const drawn = [...fm.beams.values()]
|
|
695
|
+
.filter((b) => sized.groups.some((g) => g.members.includes(b.id)))
|
|
696
|
+
.reduce((t, b) => t + b.grams / 1000, 0);
|
|
697
|
+
return {
|
|
698
|
+
ok: sized.ok,
|
|
699
|
+
rows,
|
|
700
|
+
limits: limitRows,
|
|
701
|
+
total: r3(sized.total),
|
|
702
|
+
drawn: r3(drawn),
|
|
703
|
+
tried: sized.tried,
|
|
704
|
+
search: sized.search,
|
|
705
|
+
worst: sized.worst,
|
|
706
|
+
unchecked: sized.unchecked,
|
|
707
|
+
sized,
|
|
708
|
+
fm,
|
|
709
|
+
};
|
|
214
710
|
}
|
|
215
711
|
|
|
216
712
|
// a limit's figure in words: what a lighter profile does there
|
|
217
|
-
const unitOf = { deflection: 'mm', stress: 'MPa', buckling: 'x', frequency: 'Hz' };
|
|
218
713
|
const sayLimit = (g) => {
|
|
219
714
|
if (!g) return 'the lightest in the list';
|
|
220
715
|
if (g.limit === 'fit') return `a join: with ${g.lighter}, ${g.where} does not go together (${g.why})`;
|
|
221
|
-
if (g.limit === 'deflection' && /^racked /.test(g.case ?? ''))
|
|
222
|
-
|
|
716
|
+
if (g.limit === 'deflection' && /^racked /.test(g.case ?? ''))
|
|
717
|
+
return `racking: with ${g.lighter}, the sway at ${g.where} ${g.case.replace(/^racked /, '')} breaks its limit ${n3(g.broken, 2)} times over`;
|
|
718
|
+
const what =
|
|
719
|
+
g.limit === 'deflection'
|
|
720
|
+
? `the sag at ${g.where}`
|
|
721
|
+
: g.limit === 'stress'
|
|
722
|
+
? `the stress in ${g.where}`
|
|
723
|
+
: g.limit === 'buckling'
|
|
724
|
+
? g.where === 'frame'
|
|
725
|
+
? "the frame's buckling factor"
|
|
726
|
+
: `${g.where.replace(' (Euler)', '')}'s Euler margin`
|
|
727
|
+
: 'the lowest mode';
|
|
223
728
|
return `${g.limit}: with ${g.lighter}, ${what} breaks its limit ${n3(g.broken, 2)} times over`;
|
|
224
729
|
};
|
|
225
730
|
|
|
731
|
+
/**
|
|
732
|
+
* The members the sizing's stress limit could not check, in words: join links, panels and braces counted (they are
|
|
733
|
+
* many, and named by number), any beam by name, each with why. Null where it checked every member.
|
|
734
|
+
* @param {{ member: string, why: string }[]} list sizing's unchecked @returns {string | null}
|
|
735
|
+
*/
|
|
736
|
+
export function uncheckedText(list) {
|
|
737
|
+
if (!list?.length) return null;
|
|
738
|
+
const kinds = [
|
|
739
|
+
['join link', 'join links', /^join /],
|
|
740
|
+
['panel', 'panels', /^panel /],
|
|
741
|
+
['brace', 'braces', /^brace /],
|
|
742
|
+
];
|
|
743
|
+
const parts = new Map();
|
|
744
|
+
for (const u of list) {
|
|
745
|
+
const k = kinds.find(([, , re]) => re.test(u.member)),
|
|
746
|
+
key = `${k ? k[0] : 'beam'}|${u.why}`;
|
|
747
|
+
if (!parts.has(key)) parts.set(key, { kind: k, ids: [], why: u.why });
|
|
748
|
+
parts.get(key).ids.push(u.member);
|
|
749
|
+
}
|
|
750
|
+
const said = [...parts.values()].map(({ kind, ids, why }) => {
|
|
751
|
+
const n = ids.length;
|
|
752
|
+
const who = kind ? `${n} ${n > 1 ? kind[1] : kind[0]}` : `${n > 1 ? 'beams' : 'beam'} ${ids.join(', ')}`;
|
|
753
|
+
return `${who} (${why})`;
|
|
754
|
+
});
|
|
755
|
+
const all = said.length > 1 ? `${said.slice(0, -1).join(', ')} and ${said.at(-1)}` : said[0];
|
|
756
|
+
return `the stress limit does not reach ${all}: their stress is not checked by the sizing`;
|
|
757
|
+
}
|
|
758
|
+
|
|
226
759
|
/**
|
|
227
760
|
* The sizing as a table, one line a group. @param {object} r frameSizing's @returns {string[]}
|
|
228
761
|
*/
|
|
229
762
|
export function sizingText(r) {
|
|
230
|
-
const lines = [
|
|
763
|
+
const lines = [
|
|
764
|
+
`${r.ok ? 'sized' : 'no profile in the list meets every limit; nearest'}: ${n3(r.total, 3)} kg of grouped beams (drawn ${n3(r.drawn, 3)} kg), ${r.tried} designs solved (${r.search === 'every' ? 'every design ranked by mass' : 'by steps'})`,
|
|
765
|
+
];
|
|
231
766
|
lines.push('group | profile | kg | set by | margin');
|
|
232
|
-
for (const x of r.rows)
|
|
233
|
-
|
|
767
|
+
for (const x of r.rows)
|
|
768
|
+
lines.push(
|
|
769
|
+
`${x.group} | ${x.choice}${x.drawn.length === 1 && x.drawn[0] === x.choice ? '' : ` (drawn ${x.drawn.join(', ')})`} | ${n3(x.kg, 3)} | ${sayLimit(x.governs)} | ${x.margin == null ? '-' : `${n3(x.margin, 2)}x`}`,
|
|
770
|
+
);
|
|
771
|
+
lines.push(
|
|
772
|
+
`limits: ${r.limits.map((l) => `${l.limit} ${l.limit === 'rack' ? `${l.where}: ${l.what}` : l.limit === 'deflection' ? `${n3(l.value, 3)} mm at ${l.what ?? l.where}` : l.limit === 'frequency' ? `${n3(l.value, 1)} Hz` : `${n3(l.value, 2)}x`} (${l.from})`).join('; ')}`,
|
|
773
|
+
);
|
|
774
|
+
const passed = uncheckedText(r.unchecked);
|
|
775
|
+
if (passed) lines.push(`not checked: ${passed}`);
|
|
234
776
|
return lines;
|
|
235
777
|
}
|
|
236
778
|
|
|
@@ -241,17 +783,48 @@ export function sizingText(r) {
|
|
|
241
783
|
export function sizeChecks(s, f, helpers) {
|
|
242
784
|
if (s.a.frame?.size == null) return;
|
|
243
785
|
let r;
|
|
244
|
-
try {
|
|
786
|
+
try {
|
|
787
|
+
r = frameSizing(s, helpers);
|
|
788
|
+
} catch (e) {
|
|
789
|
+
f('fail', `frame.size: ${e.message}`, 'frame.size: refused', { code: 'frame.size' });
|
|
790
|
+
return;
|
|
791
|
+
}
|
|
245
792
|
if (!r) return;
|
|
246
|
-
const text = r.rows
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
793
|
+
const text = r.rows
|
|
794
|
+
.map(
|
|
795
|
+
(x) =>
|
|
796
|
+
`${x.group}: ${x.choice}, ${n3(x.kg, 3)} kg, ${x.governs ? `set by ${sayLimit(x.governs)}, ${n3(x.margin, 2)} times inside ${x.governs.limit === 'fit' ? 'its nearest limit' : 'it'} as chosen` : 'the lightest in the list'}`,
|
|
797
|
+
)
|
|
798
|
+
.join('; ');
|
|
799
|
+
const broke =
|
|
800
|
+
r.worst && /^racked /.test(r.worst.case ?? '')
|
|
801
|
+
? `racking (${r.worst.case}) at ${r.worst.where}`
|
|
802
|
+
: `${r.worst?.limit} at ${r.worst?.where}`;
|
|
803
|
+
f(
|
|
804
|
+
r.ok ? 'info' : 'warn',
|
|
805
|
+
`${r.ok ? 'sized' : `no profile in the list meets every limit: the nearest breaks ${broke} ${n3(r.worst.ratio, 2)} times over`}: ${text}. ${n3(r.total, 3)} kg of grouped beams against ${n3(r.drawn, 3)} kg drawn (cad frame --size --write writes the profiles in)`,
|
|
806
|
+
r.ok ? null : 'frame.size: not met',
|
|
807
|
+
{
|
|
808
|
+
code: 'frame.size',
|
|
809
|
+
values: { kg: r.total, drawn: r.drawn, tried: r.tried },
|
|
810
|
+
refs: { groups: r.rows, limits: r.limits, search: r.search },
|
|
811
|
+
},
|
|
812
|
+
);
|
|
813
|
+
// what the stress limit passed over (a join's rigid link, a panel: no strength, no section modulus), said once, so
|
|
814
|
+
// the sizing does not read as if every member's stress had been held to it
|
|
815
|
+
const passed = uncheckedText(r.unchecked);
|
|
816
|
+
if (passed)
|
|
817
|
+
f('info', `frame.size: ${passed}`, null, {
|
|
818
|
+
code: 'frame.size.unchecked',
|
|
819
|
+
values: { members: r.unchecked.length },
|
|
820
|
+
refs: { unchecked: r.unchecked },
|
|
821
|
+
});
|
|
250
822
|
}
|
|
251
823
|
|
|
252
824
|
/**
|
|
253
825
|
* The assembly with the sizing's profiles written in: each grouped beam's profile (and a quarter roll where it was
|
|
254
|
-
* turned), and each printed end fitting on it drawn for the new profile
|
|
826
|
+
* turned), and each printed end fitting on it drawn for the new profile; a printed foot's tap in the beam's end and its
|
|
827
|
+
* fasten's screw follow the new profile's end bore (a 1515's M3, not a 2020's M5). Each beam keeps its line (its axis), so a
|
|
255
828
|
* deeper profile stands about its middle; where a beam's end butts against another's face and that face moves with
|
|
256
829
|
* the other's new size, the end moves with it (the beam's length follows). A generated frame's rings keep their outer faces (a table's top
|
|
257
830
|
* stays level with its legs' tops); a drawn beam whose new size would stand past the end of the beam it meets moves
|
|
@@ -262,27 +835,62 @@ export function sizeChecks(s, f, helpers) {
|
|
|
262
835
|
* @returns {object}
|
|
263
836
|
*/
|
|
264
837
|
export function writeSizing(raw, expanded, r) {
|
|
265
|
-
const out = structuredClone(raw.frame?.kind != null ? expanded : raw),
|
|
838
|
+
const out = structuredClone(raw.frame?.kind != null ? expanded : raw),
|
|
839
|
+
by = new Map(),
|
|
840
|
+
context = framesContext();
|
|
266
841
|
for (const x of r.rows) for (const id of x.beams) by.set(id, x);
|
|
267
|
-
const models = new Map(),
|
|
842
|
+
const models = new Map(),
|
|
843
|
+
modelOf = (name) => {
|
|
844
|
+
if (!models.has(name)) models.set(name, profileModel(name, {}, givenFor(context, name)));
|
|
845
|
+
return models.get(name);
|
|
846
|
+
};
|
|
268
847
|
// each beam's section axes in the world, as drawn and as written: x across its width, y up its height, u along it
|
|
269
|
-
const axes = (b, roll) => {
|
|
848
|
+
const axes = (b, roll) => {
|
|
849
|
+
const X = [b.W[0], b.W[4], b.W[8]],
|
|
850
|
+
Y = [b.W[1], b.W[5], b.W[9]],
|
|
851
|
+
c = Math.cos((roll * Math.PI) / 180),
|
|
852
|
+
sn = Math.sin((roll * Math.PI) / 180);
|
|
853
|
+
return { X: X.map((v, k) => c * v + sn * Y[k]), Y: Y.map((v, k) => c * v - sn * X[k]), u: b.u };
|
|
854
|
+
};
|
|
270
855
|
const dot = (p, q) => p[0] * q[0] + p[1] * q[1] + p[2] * q[2];
|
|
271
|
-
const was = (id) => {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
856
|
+
const was = (id) => {
|
|
857
|
+
const b = r.fm.beams.get(id);
|
|
858
|
+
return { b, profile: modelOf(b.m.profile.name), ax: axes(b, 0) };
|
|
859
|
+
};
|
|
860
|
+
const now = (id) => {
|
|
861
|
+
const x = by.get(id),
|
|
862
|
+
w = was(id);
|
|
863
|
+
return x ? { b: w.b, profile: modelOf(x.profile), ax: axes(w.b, x.roll) } : w;
|
|
864
|
+
};
|
|
865
|
+
const half = (q, dir) =>
|
|
866
|
+
(Math.abs(dot(dir, q.ax.X)) * q.profile.width + Math.abs(dot(dir, q.ax.Y)) * q.profile.height) / 2;
|
|
867
|
+
const items = new Map((out.items ?? []).map((it) => [it.id, it])),
|
|
868
|
+
numeric = (it) =>
|
|
869
|
+
Array.isArray(it?.from) && Array.isArray(it?.to) && [...it.from, ...it.to].every((v) => typeof v === 'number');
|
|
275
870
|
// a generated frame's rings keep their outer faces: the top ring its top (a table's top stays flat and level with its
|
|
276
871
|
// legs' tops), the bottom ring of a box its bottom, the rings between their middles; a drawn frame keeps every line
|
|
277
872
|
const lift = new Map();
|
|
278
873
|
if (raw.frame?.kind != null) {
|
|
279
|
-
const up = r.fm.down.map((v) => -v),
|
|
280
|
-
|
|
874
|
+
const up = r.fm.down.map((v) => -v),
|
|
875
|
+
flat = [...by.keys()].map((id) => r.fm.beams.get(id)).filter((b) => Math.abs(dot(b.u, up)) < 1e-6);
|
|
876
|
+
const height = (b) => dot(b.A, up),
|
|
877
|
+
all = [...r.fm.beams.values()].filter((b) => Math.abs(dot(b.u, up)) < 1e-6).map(height),
|
|
878
|
+
top = Math.max(...all),
|
|
879
|
+
low = Math.min(...all);
|
|
281
880
|
for (const b of flat) {
|
|
282
|
-
const side =
|
|
881
|
+
const side =
|
|
882
|
+
Math.abs(height(b) - top) < 1e-6
|
|
883
|
+
? 1
|
|
884
|
+
: Math.abs(height(b) - low) < 1e-6 && !['table', 'portal'].includes(raw.frame.kind)
|
|
885
|
+
? -1
|
|
886
|
+
: 0;
|
|
283
887
|
if (!side) continue;
|
|
284
888
|
const d = side * (half(was(b.id), up) - half(now(b.id), up));
|
|
285
|
-
if (Math.abs(d) > 1e-9)
|
|
889
|
+
if (Math.abs(d) > 1e-9)
|
|
890
|
+
lift.set(
|
|
891
|
+
b.id,
|
|
892
|
+
up.map((v) => v * d),
|
|
893
|
+
);
|
|
286
894
|
}
|
|
287
895
|
}
|
|
288
896
|
// a beam whose end meets another's face keeps its line, unless its new size would stand past that beam's end (a
|
|
@@ -291,33 +899,53 @@ export function writeSizing(raw, expanded, r) {
|
|
|
291
899
|
// and the guard below refuses
|
|
292
900
|
for (const id of by.keys()) {
|
|
293
901
|
if (lift.has(id) || !numeric(items.get(id))) continue;
|
|
294
|
-
const b = r.fm.beams.get(id),
|
|
902
|
+
const b = r.fm.beams.get(id),
|
|
903
|
+
ends = new Map();
|
|
295
904
|
for (const j of out.joins ?? []) {
|
|
296
|
-
const ma = /^([\w-]+)\.([ab])(?:\.\d+)?$/.exec(String(j.a ?? '')),
|
|
905
|
+
const ma = /^([\w-]+)\.([ab])(?:\.\d+)?$/.exec(String(j.a ?? '')),
|
|
906
|
+
mb = /^([\w-]+)\.[a-z]+(?:\.\d+)?@/.exec(String(j.b ?? ''));
|
|
297
907
|
if (!ma || ma[1] !== id || !mb || !r.fm.beams.has(mb[1]) || mb[1] === id) continue;
|
|
298
908
|
// where this end's line meets the other beam, along it, and how far the beam stands each way of it, as drawn and as sized
|
|
299
|
-
const post = r.fm.beams.get(mb[1]),
|
|
300
|
-
|
|
909
|
+
const post = r.fm.beams.get(mb[1]),
|
|
910
|
+
P = ma[2] === 'a' ? b.A : b.A.map((v, k) => v + b.u[k] * b.L),
|
|
911
|
+
at = dot(
|
|
912
|
+
P.map((v, k) => v - post.A[k]),
|
|
913
|
+
post.u,
|
|
914
|
+
);
|
|
915
|
+
const hw = half(was(id), post.u),
|
|
916
|
+
hn = half(now(id), post.u);
|
|
301
917
|
ends.set(`${ma[2]} ${mb[1]}`, { post, at, hn, lo: Math.min(0, at - hw), hi: Math.max(post.L, at + hw) });
|
|
302
918
|
}
|
|
303
919
|
const fits = (e, d) => e.at + d + e.hn <= e.hi + 1e-6 && e.at + d - e.hn >= e.lo - 1e-6;
|
|
304
920
|
const need = [...ends.values()].find((e) => !fits(e, 0));
|
|
305
921
|
if (!need) continue;
|
|
306
|
-
const d = need.at + need.hn > need.hi ? need.hi - (need.at + need.hn) : need.lo - (need.at - need.hn),
|
|
922
|
+
const d = need.at + need.hn > need.hi ? need.hi - (need.at + need.hn) : need.lo - (need.at - need.hn),
|
|
923
|
+
v = need.post.u.map((x) => x * d);
|
|
307
924
|
if ([...ends.values()].every((e) => fits(e, dot(v, e.post.u)))) lift.set(id, v);
|
|
308
925
|
}
|
|
309
|
-
for (const [id, v] of lift) {
|
|
926
|
+
for (const [id, v] of lift) {
|
|
927
|
+
const it = items.get(id);
|
|
928
|
+
if (numeric(it)) {
|
|
929
|
+
it.from = it.from.map((x, k) => r3(x + v[k]));
|
|
930
|
+
it.to = it.to.map((x, k) => r3(x + v[k]));
|
|
931
|
+
} else lift.delete(id);
|
|
932
|
+
}
|
|
310
933
|
for (const j of out.joins ?? []) {
|
|
311
|
-
const ma = /^([\w-]+)\./.exec(String(j.a ?? '')),
|
|
312
|
-
|
|
934
|
+
const ma = /^([\w-]+)\./.exec(String(j.a ?? '')),
|
|
935
|
+
mb = /^([\w-]+)\.([a-z]+(?:\.\d+)?)@(-?[\d.]+)$/.exec(String(j.b ?? ''));
|
|
936
|
+
if (ma && mb && lift.has(ma[1]) && r.fm.beams.has(mb[1]))
|
|
937
|
+
j.b = `${mb[1]}.${mb[2]}@${r3(Number(mb[3]) + dot(lift.get(ma[1]), r.fm.beams.get(mb[1]).u))}`;
|
|
313
938
|
}
|
|
314
939
|
// ends against faces: each moves as the face it meets moves
|
|
315
940
|
for (const j of out.joins ?? []) {
|
|
316
|
-
const ma = /^([\w-]+)\.([ab])(\.\d+)?$/.exec(String(j.a ?? '')),
|
|
941
|
+
const ma = /^([\w-]+)\.([ab])(\.\d+)?$/.exec(String(j.a ?? '')),
|
|
942
|
+
mb = /^([\w-]+)\.[a-z]+(\.\d+)?@/.exec(String(j.b ?? ''));
|
|
317
943
|
if (!ma || !mb || !r.fm.beams.has(ma[1]) || !r.fm.beams.has(mb[1]) || !by.has(mb[1])) continue;
|
|
318
944
|
const it = items.get(ma[1]);
|
|
319
945
|
if (!numeric(it)) continue;
|
|
320
|
-
const a = r.fm.beams.get(ma[1]),
|
|
946
|
+
const a = r.fm.beams.get(ma[1]),
|
|
947
|
+
out_ = ma[2] === 'a' ? a.u.map((v) => -v) : a.u,
|
|
948
|
+
shift = half(was(mb[1]), out_) - half(now(mb[1]), out_);
|
|
321
949
|
if (Math.abs(shift) < 1e-9 || it._moved?.[ma[2]]) continue;
|
|
322
950
|
const key = ma[2] === 'a' ? 'from' : 'to';
|
|
323
951
|
it[key] = it[key].map((v, k) => r3(v + out_[k] * shift));
|
|
@@ -333,21 +961,65 @@ export function writeSizing(raw, expanded, r) {
|
|
|
333
961
|
const on = typeof it.at === 'string' ? by.get(it.at.split('.')[0]) : null;
|
|
334
962
|
if (on && it.fitting?.profile) it.fitting = { ...it.fitting, profile: on.profile };
|
|
335
963
|
}
|
|
964
|
+
// a printed foot screwed into a beam's end takes the new profile's end bore: its tap on the beam and its fasten's screw
|
|
965
|
+
// are worked out again from the foot's model for that profile, as the generator works them out (a 1515's M3, not the
|
|
966
|
+
// 2020's M5 it was drawn with)
|
|
967
|
+
for (const it of out.items ?? []) {
|
|
968
|
+
const model = FOOT_MODELS[it.fitting?.kind],
|
|
969
|
+
[beamId, end] = typeof it.at === 'string' ? it.at.split('.') : [],
|
|
970
|
+
x = by.get(beamId),
|
|
971
|
+
beam = items.get(beamId);
|
|
972
|
+
if (!model || !x || !beam?.beam || !['a', 'b'].includes(end)) continue;
|
|
973
|
+
let m;
|
|
974
|
+
try {
|
|
975
|
+
m = model(modelOf(x.profile), { end });
|
|
976
|
+
} catch (e) {
|
|
977
|
+
throw new Error(
|
|
978
|
+
`the sized profiles do not fit as drawn, so nothing is written: ${it.id}, a ${it.fitting.kind} on ${beamId}'s end ${end}, cannot be drawn for ${x.profile} (${String(e.message).replace(/^\w+: /, '')}); leave ${x.profile} out of frame.size.profiles, or change the foot`,
|
|
979
|
+
);
|
|
980
|
+
}
|
|
981
|
+
const tap = m.ops.find((o) => o.op === 'tap'),
|
|
982
|
+
sc = m.screws.find((o) => o.into === 'bore');
|
|
983
|
+
if (!tap || !sc) continue;
|
|
984
|
+
const ops = beam.beam.ops ?? [];
|
|
985
|
+
beam.beam.ops = [
|
|
986
|
+
...ops.filter((o) => !(o.op === 'tap' && String(o.at ?? '').split('.')[0] === end)),
|
|
987
|
+
{ op: 'tap', at: tap.at, thread: tap.thread, depth: tap.depth },
|
|
988
|
+
];
|
|
989
|
+
for (const fa of out.fasten ?? [])
|
|
990
|
+
if (fa.into === beamId && Array.isArray(fa.through) && fa.through.includes(it.id)) {
|
|
991
|
+
fa.screw = `${sc.thread} ${sc.head}`;
|
|
992
|
+
if (typeof fa.note === 'string' && fa.note.startsWith(`${it.id} screwed into ${beamId}'s end `))
|
|
993
|
+
fa.note = `${it.id} screwed into ${beamId}'s end ${tap.at}`; // (the generator's own note, naming the bore)
|
|
994
|
+
}
|
|
995
|
+
}
|
|
336
996
|
// a blind or end-tap join at an end that now has several bores: one join a bore, each where its bore meets the face
|
|
337
|
-
if (out.joins)
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
997
|
+
if (out.joins)
|
|
998
|
+
out.joins = out.joins.flatMap((j) => {
|
|
999
|
+
const ma = /^([\w-]+)\.([ab])$/.exec(String(j.a ?? '')),
|
|
1000
|
+
mb = /^([\w-]+)\.([a-z]+(?:\.\d+)?)@(-?[\d.]+)$/.exec(String(j.b ?? ''));
|
|
1001
|
+
if (!ma || !mb || !['blind', 'end-tap'].includes(j.kind) || !by.has(ma[1]) || !r.fm.beams.has(mb[1])) return [j];
|
|
1002
|
+
const q = now(ma[1]),
|
|
1003
|
+
bores = q.profile.bores;
|
|
1004
|
+
if (bores.length < 2) return [j];
|
|
1005
|
+
const post = r.fm.beams.get(mb[1]);
|
|
1006
|
+
return bores.map((bo, k) => {
|
|
1007
|
+
const o = q.ax.X.map((v, c) => v * bo.at[0] + q.ax.Y[c] * bo.at[1]);
|
|
1008
|
+
return { ...j, a: `${ma[1]}.${ma[2]}.${k + 1}`, b: `${mb[1]}.${mb[2]}@${r3(Number(mb[3]) + dot(o, post.u))}` };
|
|
1009
|
+
});
|
|
1010
|
+
});
|
|
345
1011
|
// nothing is written that would not build: every join's place on the beam it meets lies on that beam
|
|
346
1012
|
for (const j of out.joins ?? []) {
|
|
347
1013
|
const mb = /^([\w-]+)\.[a-z]+(?:\.\d+)?@(-?[\d.]+)$/.exec(String(j.b ?? ''));
|
|
348
1014
|
if (!mb || !r.fm.beams.has(mb[1])) continue;
|
|
349
|
-
const it = items.get(mb[1]),
|
|
350
|
-
|
|
1015
|
+
const it = items.get(mb[1]),
|
|
1016
|
+
L = numeric(it) ? Math.hypot(...it.to.map((v, k) => v - it.from[k])) : r.fm.beams.get(mb[1]).L,
|
|
1017
|
+
s = Number(mb[2]),
|
|
1018
|
+
at = mb[2].startsWith('-') ? L + s : s;
|
|
1019
|
+
if (at < -1e-6 || at > L + 1e-6)
|
|
1020
|
+
throw new Error(
|
|
1021
|
+
`the sized profiles do not fit as drawn, so nothing is written: join ${j.a} would meet ${mb[1]} at ${n3(at)} mm, past its ${n3(L)} mm (a deeper beam there stands past the end of the one it meets, and its ends do not agree on a move); give that group a profile no deeper (frame.size.groups and profiles), or move the beam by hand`,
|
|
1022
|
+
);
|
|
351
1023
|
}
|
|
352
1024
|
return out;
|
|
353
1025
|
}
|