@rulecad/cad 0.8.0 → 0.10.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 +45 -16
- package/CHANGELOG.md +724 -0
- package/EXAMPLES.md +61 -54
- package/README.md +376 -98
- package/TUTORIAL.md +2 -2
- package/bin/cad.mjs +2664 -541
- package/lib/animate.mjs +173 -49
- package/lib/assembly.mjs +1883 -435
- 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/cache-file.mjs +105 -0
- package/lib/carried.mjs +201 -0
- package/lib/clone.mjs +194 -42
- package/lib/code-text.mjs +28 -0
- package/lib/design-imports.mjs +127 -0
- package/lib/design.mjs +871 -147
- package/lib/designshapes.mjs +142 -0
- package/lib/drive.mjs +187 -63
- package/lib/edit.mjs +922 -192
- package/lib/errors.mjs +16 -3
- package/lib/estimates.mjs +51 -0
- package/lib/explain.mjs +62 -13
- package/lib/fasten.mjs +2708 -507
- package/lib/fe-key.mjs +29 -0
- package/lib/fittings.mjs +721 -122
- package/lib/fixings.mjs +38 -13
- package/lib/framebuild.mjs +790 -175
- package/lib/framecheck.mjs +1901 -368
- package/lib/framegen.mjs +108 -22
- package/lib/frameheat.mjs +225 -42
- package/lib/frameprint.mjs +513 -108
- package/lib/frames.mjs +86 -18
- package/lib/framesize.mjs +719 -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 +129 -23
- 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 +439 -69
- package/lib/layout.mjs +2 -1
- package/lib/links.mjs +149 -42
- package/lib/list.mjs +334 -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 +597 -136
- package/lib/machine.mjs +372 -74
- package/lib/magnets.mjs +162 -44
- package/lib/measured.mjs +1080 -117
- package/lib/mesh.mjs +526 -119
- package/lib/meshcmd.mjs +215 -60
- package/lib/motors.mjs +1002 -214
- package/lib/motorsvg.mjs +114 -32
- package/lib/names.mjs +18 -1
- package/lib/optimise.mjs +991 -287
- package/lib/order.mjs +515 -114
- package/lib/panels.mjs +482 -94
- package/lib/parts.mjs +81 -23
- package/lib/pins.mjs +163 -44
- package/lib/plates.mjs +223 -35
- 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 +17 -6
- package/lib/sandbox-hooks.mjs +179 -27
- package/lib/sandbox-lock.mjs +225 -0
- package/lib/sandbox-preload.mjs +2 -2
- package/lib/sandbox-run.mjs +122 -25
- package/lib/sandbox.mjs +667 -75
- package/lib/schema.mjs +42 -11
- package/lib/seats.mjs +227 -49
- package/lib/services.mjs +261 -52
- package/lib/sheet.mjs +963 -179
- package/lib/slotnuts.mjs +213 -34
- package/lib/targets/gist.mjs +4 -1
- package/lib/targets.mjs +22 -4
- package/lib/task.mjs +376 -79
- package/lib/versions.mjs +285 -39
- package/lib/wires.mjs +228 -45
- package/lib/workspace.mjs +200 -14
- package/package.json +19 -19
- package/schemas/assembly.schema.json +2 -2
- package/schemas/project.schema.json +6 -0
- package/templates/coupons/MEASURE.md +109 -0
- package/templates/coupons/assemblies/fixings-test.json +20 -0
- package/templates/coupons/assemblies/slot-test.json +11 -0
- package/templates/coupons/objects/fixings-coupon.js +88 -0
- package/templates/coupons/objects/fixings-coupon.json +26 -0
- package/templates/coupons/objects/holds-coupon.js +130 -0
- package/templates/coupons/objects/holds-coupon.json +42 -0
- package/templates/coupons/objects/slot-coupon.js +89 -0
- package/templates/coupons/objects/slot-coupon.json +29 -0
- package/templates/coupons/project.json +10 -0
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
|
+
blindKeyBlocked,
|
|
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,147 @@ 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
|
+
// Whether a blind join's hex key reaches its head straight (@rulecad/frames' blindKeyBlocked), the key's width across
|
|
209
|
+
// its corners from the workspace's hexkey set where it has one
|
|
210
|
+
function keyBlocked(B, place, sl, thread, fx, bName) {
|
|
211
|
+
let corners = null;
|
|
212
|
+
try {
|
|
213
|
+
const set = peekRuleSet('hexkey').rules,
|
|
214
|
+
i = set.sizes.value.findIndex((s) => Math.abs(s - fx.head.key) < 1e-6);
|
|
215
|
+
if (i >= 0) corners = set.corners.value[i];
|
|
216
|
+
} catch {
|
|
217
|
+
// (no hexkey set: the kit's)
|
|
218
|
+
}
|
|
219
|
+
return blindKeyBlocked(B, place, sl, thread, fx, bName, corners);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// a place's face as a fitting names it: the face, or the place where the face has several (a 2040's top.1)
|
|
223
|
+
const faceName = (B, q) => (B.places.filter((p) => p.face === q.face).length > 1 ? q.name : q.face);
|
|
224
|
+
// 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
|
|
225
|
+
const sameWay = (b, D, face, M, roll) => {
|
|
226
|
+
const drawn = D.places.find((q) => q.name === face) ?? D.places.find((q) => q.face === face);
|
|
227
|
+
if (!drawn) return null;
|
|
228
|
+
const n = looks(faceAxes(b, 0), drawn.normal),
|
|
229
|
+
ax = faceAxes(b, roll);
|
|
230
|
+
return (
|
|
231
|
+
M.places.find((q) => {
|
|
232
|
+
const w = looks(ax, q.normal);
|
|
233
|
+
return q.slot && w[0] * n[0] + w[1] * n[1] + w[2] * n[2] > 0.99;
|
|
234
|
+
}) ?? null
|
|
235
|
+
);
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* A join's spring with its beams given other profiles, as the check works it out for a frame drawn in them
|
|
240
|
+
* (@rulecad/frames' joinModel, and cad's joins): the kind's estimate scaled to a's profile (joinStiffness), a bought
|
|
241
|
+
* fitting's own figures (boughtStiffness), or a printed fitting drawn for the new profiles and its stiffness by
|
|
242
|
+
* finite elements (fittedStiffness). Refused where the printed fitting cannot be drawn for them, with why.
|
|
243
|
+
* @param {object} x a frame join (frameModelOf's joins) @param {{ model: object, roll: number }} pa a's profile as sized
|
|
244
|
+
* @param {{ model: object, roll: number }} pb b's @param {{ given: object, context: object, material: any, fitted: object | null }} o
|
|
245
|
+
* the workspace's sets, the frames context, the project's plastic, and the drawn printed fitting's spec (its item's "fitting")
|
|
246
|
+
* @param {(profile: object, length: number) => object} [beamOf] a beam's model of a profile and length, as joinFit takes
|
|
247
|
+
* @returns {{ bending: number, twist: number }}
|
|
248
|
+
*/
|
|
249
|
+
export function joinSpring(x, pa, pb, o, beamOf = beamAt) {
|
|
250
|
+
const kind = x.j.kind,
|
|
251
|
+
fitting = x.j.fitting,
|
|
252
|
+
A = beamOf(pa.model, x.A.L),
|
|
253
|
+
B = beamOf(pb.model, x.B.L);
|
|
254
|
+
const named = fitting != null && fitting !== 'printed' && JOINS[kind]?.bought;
|
|
255
|
+
const k = joinStiffness(kind, A, named ? {} : { ...(fitting != null ? { fitting } : {}), given: o.given });
|
|
256
|
+
if (named)
|
|
257
|
+
return boughtStiffness(
|
|
258
|
+
kind,
|
|
259
|
+
A,
|
|
260
|
+
boughtFittingModel(fitting, { given: o.given, profile: B.profile, other: A.profile, join: kind }),
|
|
261
|
+
);
|
|
262
|
+
if (fitting !== 'printed' || !o.fitted) return k;
|
|
263
|
+
// a printed fitting: drawn again for the new profiles, on the faces that look the way the drawn one's do
|
|
264
|
+
const spec = { ...o.fitted, profile: pb.model.name };
|
|
265
|
+
delete spec.other;
|
|
266
|
+
if (pa.model.name !== pb.model.name) spec.other = pa.model.name;
|
|
267
|
+
for (const [key, b, D, M, roll] of [
|
|
268
|
+
['face', x.B, x.B.m, B, pb.roll],
|
|
269
|
+
['otherFace', x.A, x.A.m, A, pa.roll],
|
|
270
|
+
]) {
|
|
271
|
+
if (spec[key] == null) continue;
|
|
272
|
+
const q = sameWay(b, D, spec[key], M, roll);
|
|
273
|
+
if (!q) throw new Error(`${pb.model.name}'s face there has no slot for the printed ${kind} to screw into`);
|
|
274
|
+
spec[key] = faceName(M, q);
|
|
275
|
+
}
|
|
276
|
+
return fittedStiffness(k, fittingModel(spec, o.context, o.material, x.j.label));
|
|
277
|
+
}
|
|
103
278
|
|
|
104
279
|
/**
|
|
105
280
|
* The frame's sizing: frameModelOf's frame, its beams grouped, each group given the lightest profile from the list that
|
|
@@ -114,123 +289,417 @@ export function frameSizing(s, helpers, given) {
|
|
|
114
289
|
const fm = frameModelOf(s, helpers);
|
|
115
290
|
if (!fm || fm.empty) return null;
|
|
116
291
|
// the groups: named ones, then the rest by direction, profile and length
|
|
117
|
-
const groups = {},
|
|
292
|
+
const groups = {},
|
|
293
|
+
taken = new Map();
|
|
118
294
|
for (const [g, list] of Object.entries(opt.groups)) {
|
|
119
295
|
for (const id of list) {
|
|
120
|
-
if (!fm.beams.has(id))
|
|
121
|
-
|
|
296
|
+
if (!fm.beams.has(id))
|
|
297
|
+
throw new Error(
|
|
298
|
+
`frame.size.groups.${g}: ${id} is not a beam of the frame (its beams: ${[...fm.beams.keys()].join(', ')})`,
|
|
299
|
+
);
|
|
300
|
+
if (taken.has(id))
|
|
301
|
+
throw new Error(`frame.size.groups: ${id} is in ${taken.get(id)} and in ${g}: a beam takes one profile`);
|
|
122
302
|
taken.set(id, g);
|
|
123
303
|
}
|
|
124
304
|
groups[g] = list;
|
|
125
305
|
}
|
|
126
|
-
const near = FRAME_SIZING.match.value,
|
|
306
|
+
const near = FRAME_SIZING.match.value,
|
|
307
|
+
auto = [];
|
|
127
308
|
for (const b of fm.beams.values()) {
|
|
128
309
|
if (taken.has(b.id)) continue;
|
|
129
|
-
const mate = auto.find(
|
|
130
|
-
|
|
310
|
+
const mate = auto.find(
|
|
311
|
+
(x) =>
|
|
312
|
+
x.profile === b.m.profile.name &&
|
|
313
|
+
Math.abs(x.L - b.L) <= near &&
|
|
314
|
+
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,
|
|
315
|
+
);
|
|
316
|
+
if (mate) mate.ids.push(b.id);
|
|
317
|
+
else auto.push({ profile: b.m.profile.name, L: b.L, u: b.u, ids: [b.id] });
|
|
131
318
|
}
|
|
132
319
|
for (const x of auto) groups[x.ids.join(', ')] = x.ids;
|
|
133
320
|
// the choices, from the workspace's sets before the kit's
|
|
134
|
-
const context = framesContext(),
|
|
321
|
+
const context = framesContext(),
|
|
322
|
+
choices = [],
|
|
323
|
+
models = new Map(),
|
|
324
|
+
modelOf = (name) => {
|
|
325
|
+
if (!models.has(name)) models.set(name, profileModel(name, {}, givenFor(context, name)));
|
|
326
|
+
return models.get(name);
|
|
327
|
+
};
|
|
135
328
|
for (const name of opt.profiles) {
|
|
136
329
|
let m;
|
|
137
|
-
try {
|
|
138
|
-
|
|
330
|
+
try {
|
|
331
|
+
m = profileModel(name, {}, givenFor(context, name));
|
|
332
|
+
} catch (e) {
|
|
333
|
+
throw new Error(`frame.size.profiles: ${String(e.message).replace(/^profileModel: /, '')}`);
|
|
334
|
+
}
|
|
335
|
+
try {
|
|
336
|
+
choices.push(...profileChoices(m));
|
|
337
|
+
} catch (e) {
|
|
338
|
+
throw new Error(`frame.size.profiles: ${String(e.message).replace(/^profileChoices: /, '')}`);
|
|
339
|
+
}
|
|
139
340
|
}
|
|
140
341
|
// the limits: the frame checks' own, or the assembly's in their place
|
|
141
|
-
const margin = FRAME_CHECK.margin.value,
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
342
|
+
const margin = FRAME_CHECK.margin.value,
|
|
343
|
+
deflection = [],
|
|
344
|
+
limitRows = [];
|
|
345
|
+
const limitOf = (b, own) =>
|
|
346
|
+
opt.limits.deflection != null
|
|
347
|
+
? { value: opt.limits.deflection, from: 'frame.size.limits.deflection' }
|
|
348
|
+
: own
|
|
349
|
+
? { value: own.value, from: own.from }
|
|
350
|
+
: s.a.frame?.limit != null
|
|
351
|
+
? { value: s.num(s.a.frame.limit), from: 'frame.limit' }
|
|
352
|
+
: s.task?.accuracy != null
|
|
353
|
+
? { value: s.task.accuracy, from: "the task's accuracy" }
|
|
354
|
+
: { value: b.L / FRAME_CHECK.sag.value, from: `${b.id}'s span over ${FRAME_CHECK.sag.value} (frame.sag)` };
|
|
145
355
|
for (const l of fm.loads) {
|
|
146
|
-
const b = l.beam ?? l.mount.beam,
|
|
356
|
+
const b = l.beam ?? l.mount.beam,
|
|
357
|
+
lim = limitOf(b);
|
|
147
358
|
// 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
|
-
|
|
359
|
+
if (l.beam || !l.mount.mover) {
|
|
360
|
+
const n = fm.nodeAt(b, l.beam ? l.z : fm.mountStation(l.mount, fm.cases[0].values));
|
|
361
|
+
deflection.push({ node: n, limit: lim.value, along: fm.down });
|
|
362
|
+
limitRows.push({ limit: 'deflection', where: n, what: l.where, value: lim.value, from: lim.from });
|
|
363
|
+
} else {
|
|
364
|
+
deflection.push({ member: b.id, limit: lim.value, along: fm.down });
|
|
365
|
+
limitRows.push({
|
|
366
|
+
limit: 'deflection',
|
|
367
|
+
where: b.id,
|
|
368
|
+
what: `${l.where}, anywhere it moves`,
|
|
369
|
+
value: lim.value,
|
|
370
|
+
from: lim.from,
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
for (const p of fm.points) {
|
|
375
|
+
const n = fm.nodeAt(p.beam, p.z),
|
|
376
|
+
lim = limitOf(p.beam);
|
|
377
|
+
deflection.push({ node: n, limit: lim.value, along: fm.down });
|
|
378
|
+
limitRows.push({ limit: 'deflection', where: n, what: p.where, value: lim.value, from: lim.from });
|
|
150
379
|
}
|
|
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
380
|
for (const g of fm.guides) {
|
|
153
|
-
const lim = limitOf(
|
|
381
|
+
const lim = limitOf(
|
|
382
|
+
g.beam,
|
|
383
|
+
g.tolerance
|
|
384
|
+
? { value: g.tolerance.value, from: `the rail's own parallelism (${g.tolerance.note ?? g.tolerance.term})` }
|
|
385
|
+
: null,
|
|
386
|
+
);
|
|
154
387
|
deflection.push({ member: g.beam.id, from: g.from, to: g.to, limit: lim.value, along: fm.down });
|
|
155
|
-
limitRows.push({
|
|
388
|
+
limitRows.push({
|
|
389
|
+
limit: 'deflection',
|
|
390
|
+
where: g.beam.id,
|
|
391
|
+
what: `under guide ${g.id}`,
|
|
392
|
+
value: lim.value,
|
|
393
|
+
from: lim.from,
|
|
394
|
+
});
|
|
156
395
|
}
|
|
157
|
-
const stress = opt.limits.stress ?? margin,
|
|
158
|
-
|
|
159
|
-
limitRows.push({
|
|
160
|
-
|
|
161
|
-
|
|
396
|
+
const stress = opt.limits.stress ?? margin,
|
|
397
|
+
factor = opt.limits.buckling ?? margin;
|
|
398
|
+
limitRows.push({
|
|
399
|
+
limit: 'stress',
|
|
400
|
+
where: 'each beam',
|
|
401
|
+
value: stress,
|
|
402
|
+
from: opt.limits.stress != null ? 'frame.size.limits.stress' : 'frame.margin',
|
|
403
|
+
});
|
|
404
|
+
limitRows.push({
|
|
405
|
+
limit: 'buckling',
|
|
406
|
+
where: 'the frame and each grouped beam (Euler, K 1)',
|
|
407
|
+
value: factor,
|
|
408
|
+
from: opt.limits.buckling != null ? 'frame.size.limits.buckling' : 'frame.margin',
|
|
409
|
+
});
|
|
410
|
+
const moves = excitesOf(s).filter((x) => x.kind === 'move'),
|
|
411
|
+
Hz = opt.limits.frequency ?? (moves.length ? Math.max(...moves.map((x) => x.Hz)) * margin : null);
|
|
412
|
+
if (Hz != null)
|
|
413
|
+
limitRows.push({
|
|
414
|
+
limit: 'frequency',
|
|
415
|
+
where: 'the frame',
|
|
416
|
+
value: Hz,
|
|
417
|
+
from: opt.limits.frequency != null ? 'frame.size.limits.frequency' : `twice the task's moves (frame.frequency)`,
|
|
418
|
+
});
|
|
162
419
|
// racking, where the assembly asks it of the frame (frame.rack) or of its sizing (limits.rack): each way across, the
|
|
163
420
|
// side push alone at the top, with no weight, held to the sway allowed at each top node; a way nothing holds the
|
|
164
421
|
// frame (one plane on pinned feet) cannot be sized against, and is said
|
|
165
422
|
const rackCases = [];
|
|
166
423
|
const rk = s.a.frame?.rack != null || opt.limits.rack != null ? rackOf(s, fm) : null;
|
|
167
424
|
if (rk) {
|
|
168
|
-
const lim = opt.limits.rack != null ? { value: opt.limits.rack, from: 'frame.size.limits.rack' } : rk.lim,
|
|
425
|
+
const lim = opt.limits.rack != null ? { value: opt.limits.rack, from: 'frame.size.limits.rack' } : rk.lim,
|
|
426
|
+
drawnFrame = solveFrame(fm.model);
|
|
169
427
|
for (const { dir, name } of sideways(fm.down)) {
|
|
170
|
-
const label = `racked ${name}`,
|
|
171
|
-
|
|
428
|
+
const label = `racked ${name}`,
|
|
429
|
+
loads = rk.top.map((n) => ({ node: n, force: dir.map((v) => (v * rk.F) / rk.top.length) }));
|
|
430
|
+
try {
|
|
431
|
+
drawnFrame.statics({ loads, gravity: [0, 0, 0] });
|
|
432
|
+
} catch (e) {
|
|
172
433
|
if (e.code !== 'fea.frame.mechanism' || !e.driven) throw e;
|
|
173
|
-
limitRows.push({
|
|
434
|
+
limitRows.push({
|
|
435
|
+
limit: 'rack',
|
|
436
|
+
where: name,
|
|
437
|
+
what: `not sized: nothing holds the frame ${name}, ${freeSaid(
|
|
438
|
+
fm,
|
|
439
|
+
(drawnFrame.mechanisms ?? []).filter((m) =>
|
|
440
|
+
e.loose.some((l) => l.node === m.node && l.freedom === m.freedom),
|
|
441
|
+
),
|
|
442
|
+
)}; a brace or fixed feet, not a profile, holds it`,
|
|
443
|
+
value: null,
|
|
444
|
+
from: rk.loadFrom,
|
|
445
|
+
});
|
|
174
446
|
continue;
|
|
175
447
|
}
|
|
176
448
|
rackCases.push({ label, loads, gravity: [0, 0, 0], limits: ['deflection'] });
|
|
177
449
|
for (const n of rk.top) deflection.push({ node: n, limit: lim.value, along: dir, cases: [label] });
|
|
178
|
-
limitRows.push({
|
|
450
|
+
limitRows.push({
|
|
451
|
+
limit: 'deflection',
|
|
452
|
+
where: rk.top.join(', '),
|
|
453
|
+
what: `the top, ${label} by ${n3(rk.F, 1)} N (${rk.loadFrom})`,
|
|
454
|
+
value: lim.value,
|
|
455
|
+
from: lim.from,
|
|
456
|
+
});
|
|
179
457
|
}
|
|
180
458
|
// the sag limits hold in the poses, not under the push
|
|
181
459
|
if (rackCases.length) for (const d of deflection) if (!d.cases) d.cases = fm.cases.map((c) => c.label);
|
|
182
460
|
}
|
|
183
|
-
const limits = {
|
|
461
|
+
const limits = {
|
|
462
|
+
...(deflection.length ? { deflection } : {}),
|
|
463
|
+
stress: { margin: stress },
|
|
464
|
+
buckling: { factor, euler: FRAME_CHECK.euler.value },
|
|
465
|
+
...(Hz != null ? { frequency: { Hz } } : {}),
|
|
466
|
+
};
|
|
184
467
|
// every beam's alloy carries its strength, so the beams outside the groups are held to it too
|
|
185
|
-
const withStrength = (model) => ({
|
|
186
|
-
|
|
468
|
+
const withStrength = (model) => ({
|
|
469
|
+
...model,
|
|
470
|
+
materials: Object.fromEntries(
|
|
471
|
+
Object.entries(model.materials).map(([k, v]) => [
|
|
472
|
+
k,
|
|
473
|
+
fm.beams.get(k)?.strength ? { ...v, strength: fm.beams.get(k).strength } : v,
|
|
474
|
+
]),
|
|
475
|
+
),
|
|
476
|
+
});
|
|
477
|
+
const cases = [
|
|
478
|
+
...fm.cases.map((c) => ({
|
|
479
|
+
label: c.label,
|
|
480
|
+
loads: fm.nodeLoads(c.values, null, c.push, c.stall),
|
|
481
|
+
inertia: fm.nodeMasses(c.values),
|
|
482
|
+
})),
|
|
483
|
+
...rackCases,
|
|
484
|
+
];
|
|
187
485
|
const byName = new Map(choices.map((c) => [c.name, c]));
|
|
188
486
|
// every join a group's beam makes must go together with the profiles chosen (joinFit): a design where one does not is
|
|
189
487
|
// 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
|
-
|
|
488
|
+
const groupOf = new Map(Object.entries(groups).flatMap(([g, ids]) => ids.map((id) => [id, g]))),
|
|
489
|
+
sets = { sets: context?.sets ?? {} },
|
|
490
|
+
fitMemo = new Map(),
|
|
491
|
+
beams = new Map(),
|
|
492
|
+
beamOf = (m, L) => {
|
|
493
|
+
// (a beam's model works out its section, its twist by a raster, once a profile and length: a box asks often)
|
|
494
|
+
const key = `${m.name}|${L}`;
|
|
495
|
+
if (!beams.has(key)) beams.set(key, beamModel(m, { length: L }));
|
|
496
|
+
return beams.get(key);
|
|
497
|
+
};
|
|
498
|
+
const asSized = (b, design) => {
|
|
499
|
+
const g = groupOf.get(b.id),
|
|
500
|
+
c = g ? byName.get(design[g]) : null;
|
|
501
|
+
return c ? { name: c.profile, roll: c.roll ?? 0 } : { name: b.m.profile.name, roll: 0, drawn: true };
|
|
502
|
+
};
|
|
503
|
+
const pairs = fm.joins.filter(
|
|
504
|
+
(x) => fm.beams.has(x.A.id) && fm.beams.has(x.B.id) && (groupOf.has(x.A.id) || groupOf.has(x.B.id)),
|
|
505
|
+
);
|
|
506
|
+
// each join's spring follows its beams' profiles (joinSpring): worked out once a profile pair, for each design solved.
|
|
507
|
+
// A printed fitting that cannot be drawn for a pair is a join that does not go together
|
|
508
|
+
const material = plasticOf(s.project),
|
|
509
|
+
drawnFitting = (x) =>
|
|
510
|
+
x.j.fitted ? ((s.a.items || []).find((it) => it.id === x.j.fitted.item)?.fitting ?? null) : null,
|
|
511
|
+
springMemo = new Map();
|
|
512
|
+
const springOf = (x, pa, pb) => {
|
|
513
|
+
const key = `${x.j.index}|${pa.name}|${pa.roll}|${pb.name}|${pb.roll}`;
|
|
514
|
+
if (!springMemo.has(key)) {
|
|
515
|
+
let r;
|
|
516
|
+
try {
|
|
517
|
+
r = {
|
|
518
|
+
k: joinSpring(
|
|
519
|
+
x,
|
|
520
|
+
{ model: modelOf(pa.name), roll: pa.roll },
|
|
521
|
+
{ model: modelOf(pb.name), roll: pb.roll },
|
|
522
|
+
{ given: sets, context, material, fitted: drawnFitting(x) },
|
|
523
|
+
beamOf,
|
|
524
|
+
),
|
|
525
|
+
};
|
|
526
|
+
} catch (e) {
|
|
527
|
+
// (a fault in the code, not a fitting that cannot be drawn, is never said as a join that does not go together)
|
|
528
|
+
if (x.j.fitting !== 'printed' || e instanceof TypeError || e instanceof ReferenceError) throw e;
|
|
529
|
+
r = { why: String(e.message).replace(/^[^:]*: /, '') };
|
|
530
|
+
}
|
|
531
|
+
springMemo.set(key, r);
|
|
532
|
+
}
|
|
533
|
+
return springMemo.get(key);
|
|
534
|
+
};
|
|
193
535
|
const fits = (design) => {
|
|
194
536
|
const out = [];
|
|
195
537
|
for (const x of pairs) {
|
|
196
|
-
const pa = asSized(x.A, design),
|
|
538
|
+
const pa = asSized(x.A, design),
|
|
539
|
+
pb = asSized(x.B, design);
|
|
197
540
|
if (pa.drawn && pb.drawn) continue;
|
|
198
541
|
const key = `${x.j.index}|${pa.name}|${pa.roll}|${pb.name}|${pb.roll}`;
|
|
199
|
-
if (!fitMemo.has(key))
|
|
542
|
+
if (!fitMemo.has(key))
|
|
543
|
+
fitMemo.set(
|
|
544
|
+
key,
|
|
545
|
+
joinFit(
|
|
546
|
+
x,
|
|
547
|
+
{ model: modelOf(pa.name), roll: pa.roll },
|
|
548
|
+
{ model: modelOf(pb.name), roll: pb.roll },
|
|
549
|
+
sets,
|
|
550
|
+
beamOf,
|
|
551
|
+
) ??
|
|
552
|
+
springOf(x, pa, pb).why ??
|
|
553
|
+
null,
|
|
554
|
+
);
|
|
200
555
|
const why = fitMemo.get(key);
|
|
201
556
|
if (why) out.push({ where: x.j.label, why });
|
|
202
557
|
}
|
|
203
558
|
return out;
|
|
204
559
|
};
|
|
205
|
-
const
|
|
560
|
+
const springs = fm.springs.filter((p) => p.el && pairs.includes(p.x));
|
|
561
|
+
const ends = (design) => {
|
|
562
|
+
// (each element end that changes with the design, from every join at it: a brace's spring adds to its join's)
|
|
563
|
+
const at = new Map();
|
|
564
|
+
for (const p of springs) {
|
|
565
|
+
const pa = asSized(p.x.A, design),
|
|
566
|
+
pb = asSized(p.x.B, design);
|
|
567
|
+
if (pa.drawn && pb.drawn) continue;
|
|
568
|
+
if (!at.has(p.el.id)) at.set(p.el.id, []);
|
|
569
|
+
at.get(p.el.id).push(p);
|
|
570
|
+
}
|
|
571
|
+
const out = {};
|
|
572
|
+
for (const [id, list] of at) {
|
|
573
|
+
// an end kept is still held by every join there, the ones the design leaves as drawn too
|
|
574
|
+
const all = springs.filter((p) => p.el.id === id && list.some((q) => q.end === p.end));
|
|
575
|
+
out[id] = endSprings(
|
|
576
|
+
all.map((p) => ({ end: p.end, k: springOf(p.x, asSized(p.x.A, design), asSized(p.x.B, design)).k })),
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
return out;
|
|
580
|
+
};
|
|
581
|
+
const sized = sizing([withStrength(fm.model), withStrength(fm.rigid)], {
|
|
582
|
+
groups,
|
|
583
|
+
choices,
|
|
584
|
+
limits,
|
|
585
|
+
cases,
|
|
586
|
+
by: opt.by,
|
|
587
|
+
...(pairs.length ? { fits } : {}),
|
|
588
|
+
...(springs.length ? { ends } : {}),
|
|
589
|
+
});
|
|
206
590
|
const rows = sized.groups.map((g) => {
|
|
207
|
-
const c = byName.get(g.choice),
|
|
591
|
+
const c = byName.get(g.choice),
|
|
592
|
+
drawn = [...new Set(g.members.map((id) => fm.beams.get(id).m.profile.name.replace(/^profile-/, '')))];
|
|
208
593
|
const drawnKg = g.members.reduce((t, id) => t + fm.beams.get(id).grams / 1000, 0);
|
|
209
|
-
return {
|
|
210
|
-
|
|
594
|
+
return {
|
|
595
|
+
group: g.name,
|
|
596
|
+
beams: g.members,
|
|
597
|
+
profile: c.profile,
|
|
598
|
+
roll: c.roll,
|
|
599
|
+
choice: g.choice,
|
|
600
|
+
drawn,
|
|
601
|
+
length: r3(g.length),
|
|
602
|
+
kg: r3(g.mass),
|
|
603
|
+
drawnKg: r3(drawnKg),
|
|
604
|
+
lighter: g.lighter,
|
|
605
|
+
governs: g.governs
|
|
606
|
+
? g.governs.limit === 'fit'
|
|
607
|
+
? { limit: 'fit', where: g.governs.where, why: g.governs.why, lighter: g.governs.lighter, broken: null }
|
|
608
|
+
: {
|
|
609
|
+
limit: g.governs.limit,
|
|
610
|
+
where: g.governs.where,
|
|
611
|
+
value: r3(g.governs.value),
|
|
612
|
+
allowed: r3(g.governs.allowed),
|
|
613
|
+
case: g.governs.case,
|
|
614
|
+
lighter: g.governs.lighter,
|
|
615
|
+
broken: r3(g.governs.broken),
|
|
616
|
+
}
|
|
617
|
+
: null,
|
|
618
|
+
margin: g.margin == null ? null : r3(g.margin),
|
|
619
|
+
};
|
|
211
620
|
});
|
|
212
|
-
const drawn = [...fm.beams.values()]
|
|
213
|
-
|
|
621
|
+
const drawn = [...fm.beams.values()]
|
|
622
|
+
.filter((b) => sized.groups.some((g) => g.members.includes(b.id)))
|
|
623
|
+
.reduce((t, b) => t + b.grams / 1000, 0);
|
|
624
|
+
return {
|
|
625
|
+
ok: sized.ok,
|
|
626
|
+
rows,
|
|
627
|
+
limits: limitRows,
|
|
628
|
+
total: r3(sized.total),
|
|
629
|
+
drawn: r3(drawn),
|
|
630
|
+
tried: sized.tried,
|
|
631
|
+
search: sized.search,
|
|
632
|
+
worst: sized.worst,
|
|
633
|
+
unchecked: sized.unchecked,
|
|
634
|
+
sized,
|
|
635
|
+
fm,
|
|
636
|
+
};
|
|
214
637
|
}
|
|
215
638
|
|
|
216
639
|
// a limit's figure in words: what a lighter profile does there
|
|
217
|
-
const unitOf = { deflection: 'mm', stress: 'MPa', buckling: 'x', frequency: 'Hz' };
|
|
218
640
|
const sayLimit = (g) => {
|
|
219
641
|
if (!g) return 'the lightest in the list';
|
|
220
642
|
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
|
-
|
|
643
|
+
if (g.limit === 'deflection' && /^racked /.test(g.case ?? ''))
|
|
644
|
+
return `racking: with ${g.lighter}, the sway at ${g.where} ${g.case.replace(/^racked /, '')} breaks its limit ${n3(g.broken, 2)} times over`;
|
|
645
|
+
const what =
|
|
646
|
+
g.limit === 'deflection'
|
|
647
|
+
? `the sag at ${g.where}`
|
|
648
|
+
: g.limit === 'stress'
|
|
649
|
+
? `the stress in ${g.where}`
|
|
650
|
+
: g.limit === 'buckling'
|
|
651
|
+
? g.where === 'frame'
|
|
652
|
+
? "the frame's buckling factor"
|
|
653
|
+
: `${g.where.replace(' (Euler)', '')}'s Euler margin`
|
|
654
|
+
: 'the lowest mode';
|
|
223
655
|
return `${g.limit}: with ${g.lighter}, ${what} breaks its limit ${n3(g.broken, 2)} times over`;
|
|
224
656
|
};
|
|
225
657
|
|
|
658
|
+
/**
|
|
659
|
+
* The members the sizing's stress limit could not check, in words: join links, panels and braces counted (they are
|
|
660
|
+
* many, and named by number), any beam by name, each with why. Null where it checked every member.
|
|
661
|
+
* @param {{ member: string, why: string }[]} list sizing's unchecked @returns {string | null}
|
|
662
|
+
*/
|
|
663
|
+
export function uncheckedText(list) {
|
|
664
|
+
if (!list?.length) return null;
|
|
665
|
+
const kinds = [
|
|
666
|
+
['join link', 'join links', /^join /],
|
|
667
|
+
['panel', 'panels', /^panel /],
|
|
668
|
+
['brace', 'braces', /^brace /],
|
|
669
|
+
];
|
|
670
|
+
const parts = new Map();
|
|
671
|
+
for (const u of list) {
|
|
672
|
+
const k = kinds.find(([, , re]) => re.test(u.member)),
|
|
673
|
+
key = `${k ? k[0] : 'beam'}|${u.why}`;
|
|
674
|
+
if (!parts.has(key)) parts.set(key, { kind: k, ids: [], why: u.why });
|
|
675
|
+
parts.get(key).ids.push(u.member);
|
|
676
|
+
}
|
|
677
|
+
const said = [...parts.values()].map(({ kind, ids, why }) => {
|
|
678
|
+
const n = ids.length;
|
|
679
|
+
const who = kind ? `${n} ${n > 1 ? kind[1] : kind[0]}` : `${n > 1 ? 'beams' : 'beam'} ${ids.join(', ')}`;
|
|
680
|
+
return `${who} (${why})`;
|
|
681
|
+
});
|
|
682
|
+
const all = said.length > 1 ? `${said.slice(0, -1).join(', ')} and ${said.at(-1)}` : said[0];
|
|
683
|
+
return `the stress limit does not reach ${all}: their stress is not checked by the sizing`;
|
|
684
|
+
}
|
|
685
|
+
|
|
226
686
|
/**
|
|
227
687
|
* The sizing as a table, one line a group. @param {object} r frameSizing's @returns {string[]}
|
|
228
688
|
*/
|
|
229
689
|
export function sizingText(r) {
|
|
230
|
-
const lines = [
|
|
690
|
+
const lines = [
|
|
691
|
+
`${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'})`,
|
|
692
|
+
];
|
|
231
693
|
lines.push('group | profile | kg | set by | margin');
|
|
232
|
-
for (const x of r.rows)
|
|
233
|
-
|
|
694
|
+
for (const x of r.rows)
|
|
695
|
+
lines.push(
|
|
696
|
+
`${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`}`,
|
|
697
|
+
);
|
|
698
|
+
lines.push(
|
|
699
|
+
`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('; ')}`,
|
|
700
|
+
);
|
|
701
|
+
const passed = uncheckedText(r.unchecked);
|
|
702
|
+
if (passed) lines.push(`not checked: ${passed}`);
|
|
234
703
|
return lines;
|
|
235
704
|
}
|
|
236
705
|
|
|
@@ -241,17 +710,48 @@ export function sizingText(r) {
|
|
|
241
710
|
export function sizeChecks(s, f, helpers) {
|
|
242
711
|
if (s.a.frame?.size == null) return;
|
|
243
712
|
let r;
|
|
244
|
-
try {
|
|
713
|
+
try {
|
|
714
|
+
r = frameSizing(s, helpers);
|
|
715
|
+
} catch (e) {
|
|
716
|
+
f('fail', `frame.size: ${e.message}`, 'frame.size: refused', { code: 'frame.size' });
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
245
719
|
if (!r) return;
|
|
246
|
-
const text = r.rows
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
720
|
+
const text = r.rows
|
|
721
|
+
.map(
|
|
722
|
+
(x) =>
|
|
723
|
+
`${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'}`,
|
|
724
|
+
)
|
|
725
|
+
.join('; ');
|
|
726
|
+
const broke =
|
|
727
|
+
r.worst && /^racked /.test(r.worst.case ?? '')
|
|
728
|
+
? `racking (${r.worst.case}) at ${r.worst.where}`
|
|
729
|
+
: `${r.worst?.limit} at ${r.worst?.where}`;
|
|
730
|
+
f(
|
|
731
|
+
r.ok ? 'info' : 'warn',
|
|
732
|
+
`${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)`,
|
|
733
|
+
r.ok ? null : 'frame.size: not met',
|
|
734
|
+
{
|
|
735
|
+
code: 'frame.size',
|
|
736
|
+
values: { kg: r.total, drawn: r.drawn, tried: r.tried },
|
|
737
|
+
refs: { groups: r.rows, limits: r.limits, search: r.search },
|
|
738
|
+
},
|
|
739
|
+
);
|
|
740
|
+
// what the stress limit passed over (a join's rigid link, a panel: no strength, no section modulus), said once, so
|
|
741
|
+
// the sizing does not read as if every member's stress had been held to it
|
|
742
|
+
const passed = uncheckedText(r.unchecked);
|
|
743
|
+
if (passed)
|
|
744
|
+
f('info', `frame.size: ${passed}`, null, {
|
|
745
|
+
code: 'frame.size.unchecked',
|
|
746
|
+
values: { members: r.unchecked.length },
|
|
747
|
+
refs: { unchecked: r.unchecked },
|
|
748
|
+
});
|
|
250
749
|
}
|
|
251
750
|
|
|
252
751
|
/**
|
|
253
752
|
* 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
|
|
753
|
+
* 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
|
|
754
|
+
* 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
755
|
* deeper profile stands about its middle; where a beam's end butts against another's face and that face moves with
|
|
256
756
|
* 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
757
|
* 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 +762,62 @@ export function sizeChecks(s, f, helpers) {
|
|
|
262
762
|
* @returns {object}
|
|
263
763
|
*/
|
|
264
764
|
export function writeSizing(raw, expanded, r) {
|
|
265
|
-
const out = structuredClone(raw.frame?.kind != null ? expanded : raw),
|
|
765
|
+
const out = structuredClone(raw.frame?.kind != null ? expanded : raw),
|
|
766
|
+
by = new Map(),
|
|
767
|
+
context = framesContext();
|
|
266
768
|
for (const x of r.rows) for (const id of x.beams) by.set(id, x);
|
|
267
|
-
const models = new Map(),
|
|
769
|
+
const models = new Map(),
|
|
770
|
+
modelOf = (name) => {
|
|
771
|
+
if (!models.has(name)) models.set(name, profileModel(name, {}, givenFor(context, name)));
|
|
772
|
+
return models.get(name);
|
|
773
|
+
};
|
|
268
774
|
// 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) => {
|
|
775
|
+
const axes = (b, roll) => {
|
|
776
|
+
const X = [b.W[0], b.W[4], b.W[8]],
|
|
777
|
+
Y = [b.W[1], b.W[5], b.W[9]],
|
|
778
|
+
c = Math.cos((roll * Math.PI) / 180),
|
|
779
|
+
sn = Math.sin((roll * Math.PI) / 180);
|
|
780
|
+
return { X: X.map((v, k) => c * v + sn * Y[k]), Y: Y.map((v, k) => c * v - sn * X[k]), u: b.u };
|
|
781
|
+
};
|
|
270
782
|
const dot = (p, q) => p[0] * q[0] + p[1] * q[1] + p[2] * q[2];
|
|
271
|
-
const was = (id) => {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
783
|
+
const was = (id) => {
|
|
784
|
+
const b = r.fm.beams.get(id);
|
|
785
|
+
return { b, profile: modelOf(b.m.profile.name), ax: axes(b, 0) };
|
|
786
|
+
};
|
|
787
|
+
const now = (id) => {
|
|
788
|
+
const x = by.get(id),
|
|
789
|
+
w = was(id);
|
|
790
|
+
return x ? { b: w.b, profile: modelOf(x.profile), ax: axes(w.b, x.roll) } : w;
|
|
791
|
+
};
|
|
792
|
+
const half = (q, dir) =>
|
|
793
|
+
(Math.abs(dot(dir, q.ax.X)) * q.profile.width + Math.abs(dot(dir, q.ax.Y)) * q.profile.height) / 2;
|
|
794
|
+
const items = new Map((out.items ?? []).map((it) => [it.id, it])),
|
|
795
|
+
numeric = (it) =>
|
|
796
|
+
Array.isArray(it?.from) && Array.isArray(it?.to) && [...it.from, ...it.to].every((v) => typeof v === 'number');
|
|
275
797
|
// 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
798
|
// legs' tops), the bottom ring of a box its bottom, the rings between their middles; a drawn frame keeps every line
|
|
277
799
|
const lift = new Map();
|
|
278
800
|
if (raw.frame?.kind != null) {
|
|
279
|
-
const up = r.fm.down.map((v) => -v),
|
|
280
|
-
|
|
801
|
+
const up = r.fm.down.map((v) => -v),
|
|
802
|
+
flat = [...by.keys()].map((id) => r.fm.beams.get(id)).filter((b) => Math.abs(dot(b.u, up)) < 1e-6);
|
|
803
|
+
const height = (b) => dot(b.A, up),
|
|
804
|
+
all = [...r.fm.beams.values()].filter((b) => Math.abs(dot(b.u, up)) < 1e-6).map(height),
|
|
805
|
+
top = Math.max(...all),
|
|
806
|
+
low = Math.min(...all);
|
|
281
807
|
for (const b of flat) {
|
|
282
|
-
const side =
|
|
808
|
+
const side =
|
|
809
|
+
Math.abs(height(b) - top) < 1e-6
|
|
810
|
+
? 1
|
|
811
|
+
: Math.abs(height(b) - low) < 1e-6 && !['table', 'portal'].includes(raw.frame.kind)
|
|
812
|
+
? -1
|
|
813
|
+
: 0;
|
|
283
814
|
if (!side) continue;
|
|
284
815
|
const d = side * (half(was(b.id), up) - half(now(b.id), up));
|
|
285
|
-
if (Math.abs(d) > 1e-9)
|
|
816
|
+
if (Math.abs(d) > 1e-9)
|
|
817
|
+
lift.set(
|
|
818
|
+
b.id,
|
|
819
|
+
up.map((v) => v * d),
|
|
820
|
+
);
|
|
286
821
|
}
|
|
287
822
|
}
|
|
288
823
|
// 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 +826,53 @@ export function writeSizing(raw, expanded, r) {
|
|
|
291
826
|
// and the guard below refuses
|
|
292
827
|
for (const id of by.keys()) {
|
|
293
828
|
if (lift.has(id) || !numeric(items.get(id))) continue;
|
|
294
|
-
const b = r.fm.beams.get(id),
|
|
829
|
+
const b = r.fm.beams.get(id),
|
|
830
|
+
ends = new Map();
|
|
295
831
|
for (const j of out.joins ?? []) {
|
|
296
|
-
const ma = /^([\w-]+)\.([ab])(?:\.\d+)?$/.exec(String(j.a ?? '')),
|
|
832
|
+
const ma = /^([\w-]+)\.([ab])(?:\.\d+)?$/.exec(String(j.a ?? '')),
|
|
833
|
+
mb = /^([\w-]+)\.[a-z]+(?:\.\d+)?@/.exec(String(j.b ?? ''));
|
|
297
834
|
if (!ma || ma[1] !== id || !mb || !r.fm.beams.has(mb[1]) || mb[1] === id) continue;
|
|
298
835
|
// 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
|
-
|
|
836
|
+
const post = r.fm.beams.get(mb[1]),
|
|
837
|
+
P = ma[2] === 'a' ? b.A : b.A.map((v, k) => v + b.u[k] * b.L),
|
|
838
|
+
at = dot(
|
|
839
|
+
P.map((v, k) => v - post.A[k]),
|
|
840
|
+
post.u,
|
|
841
|
+
);
|
|
842
|
+
const hw = half(was(id), post.u),
|
|
843
|
+
hn = half(now(id), post.u);
|
|
301
844
|
ends.set(`${ma[2]} ${mb[1]}`, { post, at, hn, lo: Math.min(0, at - hw), hi: Math.max(post.L, at + hw) });
|
|
302
845
|
}
|
|
303
846
|
const fits = (e, d) => e.at + d + e.hn <= e.hi + 1e-6 && e.at + d - e.hn >= e.lo - 1e-6;
|
|
304
847
|
const need = [...ends.values()].find((e) => !fits(e, 0));
|
|
305
848
|
if (!need) continue;
|
|
306
|
-
const d = need.at + need.hn > need.hi ? need.hi - (need.at + need.hn) : need.lo - (need.at - need.hn),
|
|
849
|
+
const d = need.at + need.hn > need.hi ? need.hi - (need.at + need.hn) : need.lo - (need.at - need.hn),
|
|
850
|
+
v = need.post.u.map((x) => x * d);
|
|
307
851
|
if ([...ends.values()].every((e) => fits(e, dot(v, e.post.u)))) lift.set(id, v);
|
|
308
852
|
}
|
|
309
|
-
for (const [id, v] of lift) {
|
|
853
|
+
for (const [id, v] of lift) {
|
|
854
|
+
const it = items.get(id);
|
|
855
|
+
if (numeric(it)) {
|
|
856
|
+
it.from = it.from.map((x, k) => r3(x + v[k]));
|
|
857
|
+
it.to = it.to.map((x, k) => r3(x + v[k]));
|
|
858
|
+
} else lift.delete(id);
|
|
859
|
+
}
|
|
310
860
|
for (const j of out.joins ?? []) {
|
|
311
|
-
const ma = /^([\w-]+)\./.exec(String(j.a ?? '')),
|
|
312
|
-
|
|
861
|
+
const ma = /^([\w-]+)\./.exec(String(j.a ?? '')),
|
|
862
|
+
mb = /^([\w-]+)\.([a-z]+(?:\.\d+)?)@(-?[\d.]+)$/.exec(String(j.b ?? ''));
|
|
863
|
+
if (ma && mb && lift.has(ma[1]) && r.fm.beams.has(mb[1]))
|
|
864
|
+
j.b = `${mb[1]}.${mb[2]}@${r3(Number(mb[3]) + dot(lift.get(ma[1]), r.fm.beams.get(mb[1]).u))}`;
|
|
313
865
|
}
|
|
314
866
|
// ends against faces: each moves as the face it meets moves
|
|
315
867
|
for (const j of out.joins ?? []) {
|
|
316
|
-
const ma = /^([\w-]+)\.([ab])(\.\d+)?$/.exec(String(j.a ?? '')),
|
|
868
|
+
const ma = /^([\w-]+)\.([ab])(\.\d+)?$/.exec(String(j.a ?? '')),
|
|
869
|
+
mb = /^([\w-]+)\.[a-z]+(\.\d+)?@/.exec(String(j.b ?? ''));
|
|
317
870
|
if (!ma || !mb || !r.fm.beams.has(ma[1]) || !r.fm.beams.has(mb[1]) || !by.has(mb[1])) continue;
|
|
318
871
|
const it = items.get(ma[1]);
|
|
319
872
|
if (!numeric(it)) continue;
|
|
320
|
-
const a = r.fm.beams.get(ma[1]),
|
|
873
|
+
const a = r.fm.beams.get(ma[1]),
|
|
874
|
+
out_ = ma[2] === 'a' ? a.u.map((v) => -v) : a.u,
|
|
875
|
+
shift = half(was(mb[1]), out_) - half(now(mb[1]), out_);
|
|
321
876
|
if (Math.abs(shift) < 1e-9 || it._moved?.[ma[2]]) continue;
|
|
322
877
|
const key = ma[2] === 'a' ? 'from' : 'to';
|
|
323
878
|
it[key] = it[key].map((v, k) => r3(v + out_[k] * shift));
|
|
@@ -333,21 +888,65 @@ export function writeSizing(raw, expanded, r) {
|
|
|
333
888
|
const on = typeof it.at === 'string' ? by.get(it.at.split('.')[0]) : null;
|
|
334
889
|
if (on && it.fitting?.profile) it.fitting = { ...it.fitting, profile: on.profile };
|
|
335
890
|
}
|
|
891
|
+
// 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
|
|
892
|
+
// are worked out again from the foot's model for that profile, as the generator works them out (a 1515's M3, not the
|
|
893
|
+
// 2020's M5 it was drawn with)
|
|
894
|
+
for (const it of out.items ?? []) {
|
|
895
|
+
const model = FOOT_MODELS[it.fitting?.kind],
|
|
896
|
+
[beamId, end] = typeof it.at === 'string' ? it.at.split('.') : [],
|
|
897
|
+
x = by.get(beamId),
|
|
898
|
+
beam = items.get(beamId);
|
|
899
|
+
if (!model || !x || !beam?.beam || !['a', 'b'].includes(end)) continue;
|
|
900
|
+
let m;
|
|
901
|
+
try {
|
|
902
|
+
m = model(modelOf(x.profile), { end });
|
|
903
|
+
} catch (e) {
|
|
904
|
+
throw new Error(
|
|
905
|
+
`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`,
|
|
906
|
+
);
|
|
907
|
+
}
|
|
908
|
+
const tap = m.ops.find((o) => o.op === 'tap'),
|
|
909
|
+
sc = m.screws.find((o) => o.into === 'bore');
|
|
910
|
+
if (!tap || !sc) continue;
|
|
911
|
+
const ops = beam.beam.ops ?? [];
|
|
912
|
+
beam.beam.ops = [
|
|
913
|
+
...ops.filter((o) => !(o.op === 'tap' && String(o.at ?? '').split('.')[0] === end)),
|
|
914
|
+
{ op: 'tap', at: tap.at, thread: tap.thread, depth: tap.depth },
|
|
915
|
+
];
|
|
916
|
+
for (const fa of out.fasten ?? [])
|
|
917
|
+
if (fa.into === beamId && Array.isArray(fa.through) && fa.through.includes(it.id)) {
|
|
918
|
+
fa.screw = `${sc.thread} ${sc.head}`;
|
|
919
|
+
if (typeof fa.note === 'string' && fa.note.startsWith(`${it.id} screwed into ${beamId}'s end `))
|
|
920
|
+
fa.note = `${it.id} screwed into ${beamId}'s end ${tap.at}`; // (the generator's own note, naming the bore)
|
|
921
|
+
}
|
|
922
|
+
}
|
|
336
923
|
// 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
|
-
|
|
924
|
+
if (out.joins)
|
|
925
|
+
out.joins = out.joins.flatMap((j) => {
|
|
926
|
+
const ma = /^([\w-]+)\.([ab])$/.exec(String(j.a ?? '')),
|
|
927
|
+
mb = /^([\w-]+)\.([a-z]+(?:\.\d+)?)@(-?[\d.]+)$/.exec(String(j.b ?? ''));
|
|
928
|
+
if (!ma || !mb || !['blind', 'end-tap'].includes(j.kind) || !by.has(ma[1]) || !r.fm.beams.has(mb[1])) return [j];
|
|
929
|
+
const q = now(ma[1]),
|
|
930
|
+
bores = q.profile.bores;
|
|
931
|
+
if (bores.length < 2) return [j];
|
|
932
|
+
const post = r.fm.beams.get(mb[1]);
|
|
933
|
+
return bores.map((bo, k) => {
|
|
934
|
+
const o = q.ax.X.map((v, c) => v * bo.at[0] + q.ax.Y[c] * bo.at[1]);
|
|
935
|
+
return { ...j, a: `${ma[1]}.${ma[2]}.${k + 1}`, b: `${mb[1]}.${mb[2]}@${r3(Number(mb[3]) + dot(o, post.u))}` };
|
|
936
|
+
});
|
|
937
|
+
});
|
|
345
938
|
// nothing is written that would not build: every join's place on the beam it meets lies on that beam
|
|
346
939
|
for (const j of out.joins ?? []) {
|
|
347
940
|
const mb = /^([\w-]+)\.[a-z]+(?:\.\d+)?@(-?[\d.]+)$/.exec(String(j.b ?? ''));
|
|
348
941
|
if (!mb || !r.fm.beams.has(mb[1])) continue;
|
|
349
|
-
const it = items.get(mb[1]),
|
|
350
|
-
|
|
942
|
+
const it = items.get(mb[1]),
|
|
943
|
+
L = numeric(it) ? Math.hypot(...it.to.map((v, k) => v - it.from[k])) : r.fm.beams.get(mb[1]).L,
|
|
944
|
+
s = Number(mb[2]),
|
|
945
|
+
at = mb[2].startsWith('-') ? L + s : s;
|
|
946
|
+
if (at < -1e-6 || at > L + 1e-6)
|
|
947
|
+
throw new Error(
|
|
948
|
+
`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`,
|
|
949
|
+
);
|
|
351
950
|
}
|
|
352
951
|
return out;
|
|
353
952
|
}
|