@rulecad/fixings 0.1.8 → 0.2.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/strength.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  // Strength and length: whether enough thread is engaged, the load that strips it, the clamp force a tightening torque
2
2
  // gives, the pressure under a head, and the sold length that fits a stack of parts. Each returns its numbers, what
3
3
  // they rest on, and findings in the kit's one shape. The strengths of materials come from the kit's material rule
4
- // sets (pla, petg, abs, asa, pa_cf, al6061, al7075, s275, ss304), or one handed in. These are first sums for a printed joint, with
5
- // their estimates named: a joint that matters is tested. Units: mm, N, N·m, MPa.
4
+ // sets (pla, petg, abs, asa, pa_cf, al6061, al7075, s275, ss304), or one handed in. These are first sums for a printed
5
+ // joint, with their estimates named: a joint that matters is tested. Units: mm, N, N·m, MPa.
6
6
  import pla from '@rulecad/rules/pla.json' with { type: 'json' };
7
7
  import petg from '@rulecad/rules/petg.json' with { type: 'json' };
8
8
  import abs from '@rulecad/rules/abs.json' with { type: 'json' };
@@ -12,7 +12,26 @@ import al6061 from '@rulecad/rules/al6061.json' with { type: 'json' };
12
12
  import al7075 from '@rulecad/rules/al7075.json' with { type: 'json' };
13
13
  import s275 from '@rulecad/rules/s275.json' with { type: 'json' };
14
14
  import ss304 from '@rulecad/rules/ss304.json' with { type: 'json' };
15
- import { DEFAULTS, ENGAGEMENT, fixingOf, fixingModel, headOf, nutOf, screwName, figure, cite, rest, finding, positive, oneOf, isNum, shown, mm, r3, a } from './model.mjs';
15
+ import {
16
+ DEFAULTS,
17
+ ENGAGEMENT,
18
+ fixingOf,
19
+ fixingModel,
20
+ headOf,
21
+ nutOf,
22
+ screwName,
23
+ figure,
24
+ cite,
25
+ rest,
26
+ finding,
27
+ positive,
28
+ oneOf,
29
+ isNum,
30
+ shown,
31
+ mm,
32
+ r3,
33
+ a,
34
+ } from './model.mjs';
16
35
  import { holeModel } from './holes.mjs';
17
36
 
18
37
  /**
@@ -24,36 +43,85 @@ const KIT = { pla, petg, abs, asa, pa_cf, al6061, al7075, s275, ss304 };
24
43
  export const MATERIALS = Object.keys(KIT);
25
44
  /** The classes of material the engagement rules know. */
26
45
  export const MATERIAL_CLASSES = ['plastic', 'aluminium', 'steel'];
27
- const n1 = (x) => +x.toFixed(1), n2 = (x) => +x.toFixed(2);
28
- const options = (what, o, example) => { if (o == null || typeof o !== 'object' || Array.isArray(o)) throw new Error(`${what}: the second argument is its options (${example}), not ${shown(o)}`); return o; };
46
+ const n1 = (x) => +x.toFixed(1),
47
+ n2 = (x) => +x.toFixed(2);
48
+ const options = (what, o, example) => {
49
+ if (o == null || typeof o !== 'object' || Array.isArray(o))
50
+ throw new Error(`${what}: the second argument is its options (${example}), not ${shown(o)}`);
51
+ return o;
52
+ };
29
53
 
30
54
  // A material from what a function was handed: a kit set's name ('PLA'), the workspace's set of that name (sets), or a
31
- // rule set itself. Its class is told by its stiffness: under 20 GPa a plastic, under 100 GPa an aluminium, else a steel.
55
+ // rule set itself. Its class is told by its stiffness: under 20 GPa a plastic, under 100 GPa an aluminium, else a
56
+ // steel.
32
57
  export function materialOf(what, material, sets) {
33
- if (material == null) throw new Error(`${what}: give a material, what the thread is in or the head sits on: ${MATERIALS.join(', ')}, or a rule set with a strength ({ name, rules })`);
58
+ if (material == null)
59
+ throw new Error(
60
+ `${what}: give a material, what the thread is in or the head sits on: ${MATERIALS.join(', ')}, or a ` +
61
+ `rule set with a strength ({ name, rules })`,
62
+ );
34
63
  let set = null;
35
64
  if (typeof material === 'object' && material.rules && typeof material.rules === 'object') set = material;
36
65
  else if (typeof material === 'string') {
37
- const key = material.trim().toLowerCase(), own = sets && typeof sets === 'object' ? (Array.isArray(sets) ? sets.find((s) => s?.name === key) : sets[key]) : null;
38
- set = own?.rules ? { name: key, ...own } : KIT[key] ?? null;
39
- if (!set) throw new Error(`${what}: no material "${material}". There are: ${MATERIALS.join(', ')}. For another, hand in its rule set ({ name, rules: { strength, modulus } }), or the workspace's sets with it in`);
40
- } else throw new Error(`${what}: material is a material's name (${MATERIALS.join(', ')}) or its rule set ({ name, rules }), not ${shown(material)}`);
41
- const name = set.name ?? 'the material', num = (k) => { const f = set.rules[k]; if (f && !(isNum(f.value) && f.value > 0)) throw new Error(`${what}: ${name}.${k} is a number above 0 (got ${shown(f.value)})`); return f ? { ...f, name: `${name}.${k}` } : null; };
42
- const strength = num('strength'), across = num('strength_z'), modulus = num('modulus'), density = num('density'), poisson = num('poisson');
43
- if (!strength) throw new Error(`${what}: ${name} has no strength in its rule set: a tensile or yield strength in MPa is needed`);
66
+ const key = material.trim().toLowerCase(),
67
+ own =
68
+ sets && typeof sets === 'object' ? (Array.isArray(sets) ? sets.find((s) => s?.name === key) : sets[key]) : null;
69
+ set = own?.rules ? { name: key, ...own } : (KIT[key] ?? null);
70
+ if (!set)
71
+ throw new Error(
72
+ `${what}: no material "${material}". There are: ${MATERIALS.join(', ')}. For another, hand in its ` +
73
+ `rule set ({ name, rules: { strength, modulus } }), or the workspace's sets with it in`,
74
+ );
75
+ } else
76
+ throw new Error(
77
+ `${what}: material is a material's name (${MATERIALS.join(', ')}) or its rule set ({ name, rules }), ` +
78
+ `not ${shown(material)}`,
79
+ );
80
+ const name = set.name ?? 'the material',
81
+ num = (k) => {
82
+ const f = set.rules[k];
83
+ if (f && !(isNum(f.value) && f.value > 0))
84
+ throw new Error(`${what}: ${name}.${k} is a number above 0 (got ${shown(f.value)})`);
85
+ return f ? { ...f, name: `${name}.${k}` } : null;
86
+ };
87
+ const strength = num('strength'),
88
+ across = num('strength_z'),
89
+ modulus = num('modulus'),
90
+ density = num('density'),
91
+ poisson = num('poisson');
92
+ if (!strength)
93
+ throw new Error(`${what}: ${name} has no strength in its rule set: a tensile or yield strength in MPa is needed`);
44
94
  if (!modulus) throw new Error(`${what}: ${name} has no modulus in its rule set, which tells a plastic from a metal`);
45
- return { name, cls: modulus.value < 20000 ? 'plastic' : modulus.value < 100000 ? 'aluminium' : 'steel', strength, across, modulus, density, poisson };
95
+ return {
96
+ name,
97
+ cls: modulus.value < 20000 ? 'plastic' : modulus.value < 100000 ? 'aluminium' : 'steel',
98
+ strength,
99
+ across,
100
+ modulus,
101
+ density,
102
+ poisson,
103
+ };
46
104
  }
47
105
  // The class of material an engagement rule is read by: a class by name, or a material's
48
106
  function classOf(what, material, sets) {
49
- if (typeof material === 'string' && MATERIAL_CLASSES.includes(material.trim().toLowerCase())) return { cls: material.trim().toLowerCase(), name: null };
50
- if (material == null) throw new Error(`${what}: give a material: a class (${MATERIAL_CLASSES.join(', ')}) or a material (${MATERIALS.join(', ')})`);
107
+ if (typeof material === 'string' && MATERIAL_CLASSES.includes(material.trim().toLowerCase()))
108
+ return { cls: material.trim().toLowerCase(), name: null };
109
+ if (material == null)
110
+ throw new Error(
111
+ `${what}: give a material: a class (${MATERIAL_CLASSES.join(', ')}) or a material (${MATERIALS.join(', ')})`,
112
+ );
51
113
  return materialOf(what, material, sets);
52
114
  }
53
115
  // The weaker of a printed material's two strengths, with what it says about itself
54
116
  export function weakest(mat) {
55
117
  const f = mat.across && mat.across.value < mat.strength.value ? mat.across : mat.strength;
56
- const note = mat.cls !== 'plastic' ? '' : mat.across ? ` (${f.name}, the weaker way of the print)` : ` (${mat.name} has no strength across its layers, strength_z: the strength along them is used, and a screw standing across the layers may hold less)`;
118
+ const note =
119
+ mat.cls !== 'plastic'
120
+ ? ''
121
+ : mat.across
122
+ ? ` (${f.name}, the weaker way of the print)`
123
+ : ` (${mat.name} has no strength across its layers, strength_z: the strength along them is used, and a ` +
124
+ `screw standing across the layers may hold less)`;
57
125
  return { f, note };
58
126
  }
59
127
 
@@ -61,96 +129,274 @@ export function weakest(mat) {
61
129
  // A printed bolt (a screw named with the word printed) is refused by name: it has no property class, so no proof load,
62
130
  // preload or torque. A printed nut is let through: the screw in it is a bought one
63
131
  function notPrinted(what, fx) {
64
- if (fx.printed && fx.item !== 'nut') throw new Error(`${what}: ${fx.name} is a printed bolt, with no property class and no proof load: it is plastic, done up by hand, and breaks at its plastic's strength. Its breaking load and the margin on a pull are printedBoltModel('${fx.name}', { material, load })${what === 'seating' ? '; the pressure under its head is seating with a force (N) given' : ''}`);
132
+ if (fx.printed && fx.item !== 'nut')
133
+ throw new Error(
134
+ `${what}: ${fx.name} is a printed bolt, with no property class and no proof load: it is plastic, done ` +
135
+ `up by hand, and breaks at its plastic's strength. Its breaking load and the margin on a pull are ` +
136
+ `printedBoltModel('${fx.name}', { material, load })` +
137
+ (what === 'seating' ? '; the pressure under its head is seating with a force (N) given' : ''),
138
+ );
65
139
  return fx;
66
140
  }
67
141
  function proofOf(what, fx, o) {
68
142
  notPrinted(what, fx);
69
- if (fx.form === 'plastic') throw new Error(`${what}: ${fx.thread} is a thread-forming screw for plastic, with no property class in its rule set (${fx.set}): its maker's sheet gives what it holds`);
70
- const kind = oneOf(what, 'screw', o.screw ?? 'steel', ['steel', 'stainless']), name = kind === 'steel' ? 'proof_stress' : 'stainless_proof_stress';
71
- if (o.proof != null) positive(what, 'proof (the screw\'s proof stress, in MPa)', o.proof);
72
- const k = fx.form === 'unified' ? 0.9743 : 0.9382, area = (Math.PI / 4) * (fx.major - k * fx.pitch) ** 2, stress = o.proof ?? figure(what, fx, name);
73
- const cls = o.proof != null ? 'the proof stress given' : kind === 'steel' ? (fx.figures.property_class ? `class ${fx.figures.property_class.value}` : 'alloy steel') : String(fx.figures.stainless_class?.value ?? 'stainless');
74
- return { area, stress, load: area * stress, says: cls, rests: [rest(cite(fx, 'major_diameter'), fx.figures.major_diameter), rest(cite(fx, 'pitch'), fx.figures.pitch), ...(o.proof != null ? [] : [rest(cite(fx, name), fx.figures[name])])] };
143
+ if (fx.form === 'plastic')
144
+ throw new Error(
145
+ `${what}: ${fx.thread} is a thread-forming screw for plastic, with no property class in its rule set (` +
146
+ `${fx.set}): its maker's sheet gives what it holds`,
147
+ );
148
+ const kind = oneOf(what, 'screw', o.screw ?? 'steel', ['steel', 'stainless']),
149
+ name = kind === 'steel' ? 'proof_stress' : 'stainless_proof_stress';
150
+ if (o.proof != null) positive(what, "proof (the screw's proof stress, in MPa)", o.proof);
151
+ const k = fx.form === 'unified' ? 0.9743 : 0.9382,
152
+ area = (Math.PI / 4) * (fx.major - k * fx.pitch) ** 2,
153
+ stress = o.proof ?? figure(what, fx, name);
154
+ const cls =
155
+ o.proof != null
156
+ ? 'the proof stress given'
157
+ : kind === 'steel'
158
+ ? fx.figures.property_class
159
+ ? `class ${fx.figures.property_class.value}`
160
+ : 'alloy steel'
161
+ : String(fx.figures.stainless_class?.value ?? 'stainless');
162
+ return {
163
+ area,
164
+ stress,
165
+ load: area * stress,
166
+ says: cls,
167
+ rests: [
168
+ rest(cite(fx, 'major_diameter'), fx.figures.major_diameter),
169
+ rest(cite(fx, 'pitch'), fx.figures.pitch),
170
+ ...(o.proof != null ? [] : [rest(cite(fx, name), fx.figures[name])]),
171
+ ],
172
+ };
75
173
  }
76
174
 
77
175
  /**
78
176
  * Whether enough thread is engaged, against the engagement rule for what the thread is in: 1 diameter in steel, 2 in
79
177
  * aluminium, 2.5 in plastic (the engagement rule set of @rulecad/rules).
80
- * @param {Fixing | string} m a fixing's model or name @param {{ depth: number, material: string | object, sets?: object }} o
178
+ * @param {Fixing | string} m a fixing's model or
179
+ * name @param {{ depth: number, material: string | object, sets?: object }} o
81
180
  * depth: the length of thread engaged, in mm; material: a class (plastic, aluminium, steel), a material of the kit
82
181
  * (pla, petg, abs, asa, pa_cf, al6061, al7075, s275, ss304) or a material's rule set
83
- * @returns {{ thread: string, depth: number, need: number, turns: number, diameters: number, class: string, material: string | null, enough: boolean, rests: object[], findings: object[] }}
182
+ * @returns {{ thread: string, depth: number, need: number, turns: number, diameters: number, class: string,
183
+ * material: string | null, enough: boolean, rests: object[], findings: object[] }}
84
184
  * need: the depth that would do; turns: threads engaged; diameters: the depth in diameters of the screw
85
185
  */
86
186
  export function engagement(m, o = {}) {
87
187
  const what = 'engagement';
88
- options(what, o, '{ depth: 6, material: \'pla\' }');
89
- const fx = fixingOf(what, m, o), depth = positive(what, 'depth', o.depth), mat = classOf(what, o.material, o.sets), rule = ENGAGEMENT[mat.cls];
90
- const need = r3(rule.value * fx.major), turns = n1(depth / fx.pitch), enough = depth >= need - 1e-9, into = mat.name ? `${mat.name} (a${mat.cls === 'aluminium' ? 'n' : ''} ${mat.cls})` : mat.cls;
91
- return { thread: fx.thread, depth, need, turns, diameters: n2(depth / fx.major), class: mat.cls, material: mat.name, enough, rests: [rest(`engagement.${mat.cls}`, rule), rest(cite(fx, 'major_diameter'), fx.figures.major_diameter), rest(cite(fx, 'pitch'), fx.figures.pitch)],
92
- findings: [finding(enough ? 'pass' : 'warn', `${a(fx.thread)} screw ${mm(depth)} mm into ${into} engages ${mm(turns)} threads, ${mm(n2(depth / fx.major))} diameters: engagement.${mat.cls} asks ${mm(rule.value)} (${mm(need)} mm)${enough ? '' : `, so ${mm(need)} mm would do`}`,
93
- 'engagement.depth', { values: { depth, need, turns }, refs: { thread: fx.thread, rule: `engagement.${mat.cls}`, kind: rule.kind } })] };
188
+ options(what, o, "{ depth: 6, material: 'pla' }");
189
+ const fx = fixingOf(what, m, o),
190
+ depth = positive(what, 'depth', o.depth),
191
+ mat = classOf(what, o.material, o.sets),
192
+ rule = ENGAGEMENT[mat.cls];
193
+ const need = r3(rule.value * fx.major),
194
+ turns = n1(depth / fx.pitch),
195
+ enough = depth >= need - 1e-9,
196
+ into = mat.name ? `${mat.name} (a${mat.cls === 'aluminium' ? 'n' : ''} ${mat.cls})` : mat.cls;
197
+ return {
198
+ thread: fx.thread,
199
+ depth,
200
+ need,
201
+ turns,
202
+ diameters: n2(depth / fx.major),
203
+ class: mat.cls,
204
+ material: mat.name,
205
+ enough,
206
+ rests: [
207
+ rest(`engagement.${mat.cls}`, rule),
208
+ rest(cite(fx, 'major_diameter'), fx.figures.major_diameter),
209
+ rest(cite(fx, 'pitch'), fx.figures.pitch),
210
+ ],
211
+ findings: [
212
+ finding(
213
+ enough ? 'pass' : 'warn',
214
+ `${a(fx.thread)} screw ${mm(depth)} mm into ${into} engages ${mm(turns)} threads, ` +
215
+ `${mm(n2(depth / fx.major))} diameters: engagement.${mat.cls} asks ${mm(rule.value)} (${mm(need)} mm)` +
216
+ (enough ? '' : `, so ${mm(need)} mm would do`),
217
+ 'engagement.depth',
218
+ { values: { depth, need, turns }, refs: { thread: fx.thread, rule: `engagement.${mat.cls}`, kind: rule.kind } },
219
+ ),
220
+ ],
221
+ };
94
222
  }
95
223
 
96
224
  /**
97
225
  * The load that strips an internal thread, from its shear area and the strength of what it is cut or formed in,
98
226
  * against the screw's own proof load. The shear area is the handbook's for a 60° thread at its basic sizes,
99
227
  * 0.875 π d Le; the shear strength is the material's strength over √3, an estimate.
100
- * @param {Fixing | string} m @param {{ depth: number, material: string | object, screw?: 'steel' | 'stainless', proof?: number, load?: number, sets?: object }} o
101
- * depth: the length of thread engaged; material: what the internal thread is in; screw: steel (its property class, the
102
- * default) or stainless; proof: another screw's proof stress in MPa (830 for class 10.9); load: the load the joint
103
- * carries along the screw, in N, to hold with twice the margin
104
- * @returns {{ thread: string, depth: number, material: string, area: number, shear: number, strip: number, stressArea: number, proof: number, margin: number, depthFor: number, load: number | null, rests: object[], findings: object[] }}
105
- * area: the internal thread's shear area, mm²; shear: the shear strength taken, MPa; strip: the load that strips the thread, N;
106
- * proof: the screw's proof load, N; margin: strip over proof (under 1: the thread goes first); depthFor: the depth at which the thread is as strong as the screw
228
+ * @param {Fixing | string} m @param {{ depth: number, material: string | object, screw?: 'steel' | 'stainless',
229
+ * proof?: number, load?: number, sets?: object }} o
230
+ * depth: the length of thread engaged; material: what the internal thread is in; screw: steel (its property class,
231
+ * the default) or stainless; proof: another screw's proof stress in MPa (830 for class 10.9); load: the load the
232
+ * joint carries along the screw, in N, to hold with twice the margin
233
+ * @returns {{ thread: string, depth: number, material: string, area: number, shear: number, strip: number,
234
+ * stressArea: number, proof: number, margin: number, depthFor: number, load: number | null, rests: object[], findings:
235
+ * object[] }}
236
+ * area: the internal thread's shear area, mm²; shear: the shear strength taken, MPa; strip: the load that strips the
237
+ * thread, N; proof: the screw's proof load, N; margin: strip over proof (under 1: the thread goes first); depthFor:
238
+ * the depth at which the thread is as strong as the screw
107
239
  */
108
240
  export function stripping(m, o = {}) {
109
241
  const what = 'stripping';
110
- options(what, o, '{ depth: 6, material: \'pla\' }');
111
- const fx = fixingOf(what, m, o), depth = positive(what, 'depth', o.depth), mat = materialOf(what, o.material, o.sets), screw = proofOf(what, fx, o);
242
+ options(what, o, "{ depth: 6, material: 'pla' }");
243
+ const fx = fixingOf(what, m, o),
244
+ depth = positive(what, 'depth', o.depth),
245
+ mat = materialOf(what, o.material, o.sets),
246
+ screw = proofOf(what, fx, o);
112
247
  if (o.load != null) positive(what, 'load (in N)', o.load);
113
- const { f, note } = weakest(mat), ratio = DEFAULTS.shear_ratio, shear = ratio.value * f.value, area = 0.875 * Math.PI * fx.major * depth, strip = shear * area, margin = strip / screw.load, depthFor = depth / margin;
114
- const out = [finding('info', `${a(fx.thread)} screw ${mm(depth)} mm into ${mat.name} strips its thread at about ${mm(n1(strip))} N: a shear area of ${mm(n2(area))} mm² (0.875 π d Le) at ${mm(n2(shear))} MPa, ${mm(f.value)} MPa over √3${note}. The shear strength is an estimate from the tensile strength, so halve it for a load that matters, or test it`,
115
- 'stripping.load', { values: { strip: n1(strip), area: n2(area), shear: n2(shear) }, refs: { thread: fx.thread, material: mat.name, kind: 'estimate' } })];
116
- out.push(finding(margin >= 1 ? 'pass' : 'info', margin >= 1 ? `the thread outlasts the screw: its ${mm(n1(strip))} N is ${mm(n2(margin))} times the screw's proof load of ${mm(n1(screw.load))} N (${screw.says}, ${mm(n2(screw.area))} mm² at ${mm(screw.stress)} MPa)`
117
- : `the thread strips before the screw yields: ${mm(n1(strip))} N is ${mm(n2(margin))} of the screw's proof load, ${mm(n1(screw.load))} N (${screw.says}, ${mm(n2(screw.area))} mm² at ${mm(screw.stress)} MPa). ${mm(n1(depthFor))} mm of thread would match the screw`,
118
- 'stripping.margin', { values: { strip: n1(strip), proof: n1(screw.load), margin: n2(margin), depthFor: n1(depthFor) } }));
119
- if (o.load != null) { const k = strip / o.load, want = DEFAULTS.load_margin.value; out.push(finding(k >= want ? 'pass' : k >= 1 ? 'warn' : 'fail', `a load of ${mm(o.load)} N is held ${mm(n2(k))} times over by the thread, where the kit asks ${want} times${k >= want ? '' : `: ${mm(n1(depth * (want / k)))} mm of thread would do`}`, 'stripping.held', { values: { load: o.load, margin: n2(k), want } })); }
120
- return { thread: fx.thread, depth, material: mat.name, area: n2(area), shear: n2(shear), strip: n1(strip), stressArea: n2(screw.area), proof: n1(screw.load), margin: n2(margin), depthFor: n1(depthFor), load: o.load ?? null,
121
- rests: [rest(f.name, f), rest('fixings.shear_ratio', ratio), ...screw.rests], findings: out };
248
+ const { f, note } = weakest(mat),
249
+ ratio = DEFAULTS.shear_ratio,
250
+ shear = ratio.value * f.value,
251
+ area = 0.875 * Math.PI * fx.major * depth,
252
+ strip = shear * area,
253
+ margin = strip / screw.load,
254
+ depthFor = depth / margin;
255
+ const out = [
256
+ finding(
257
+ 'info',
258
+ `${a(fx.thread)} screw ${mm(depth)} mm into ${mat.name} strips its thread at about ${mm(n1(strip))} N: ` +
259
+ `a shear area of ${mm(n2(area))} mm² (0.875 π d Le) at ${mm(n2(shear))} MPa, ${mm(f.value)} MPa over √3` +
260
+ `${note}. The shear strength is an estimate from the tensile strength, so halve it for a load that ` +
261
+ `matters, or test it`,
262
+ 'stripping.load',
263
+ {
264
+ values: { strip: n1(strip), area: n2(area), shear: n2(shear) },
265
+ refs: { thread: fx.thread, material: mat.name, kind: 'estimate' },
266
+ },
267
+ ),
268
+ ];
269
+ out.push(
270
+ finding(
271
+ margin >= 1 ? 'pass' : 'info',
272
+ margin >= 1
273
+ ? `the thread outlasts the screw: its ${mm(n1(strip))} N is ${mm(n2(margin))} times the screw's proof ` +
274
+ `load of ${mm(n1(screw.load))} N (${screw.says}, ${mm(n2(screw.area))} mm² at ${mm(screw.stress)} ` +
275
+ `MPa)`
276
+ : `the thread strips before the screw yields: ${mm(n1(strip))} N is ${mm(n2(margin))} of the screw's ` +
277
+ `proof load, ${mm(n1(screw.load))} N (${screw.says}, ${mm(n2(screw.area))} mm² at ${mm(screw.stress)}` +
278
+ ` MPa). ${mm(n1(depthFor))} mm of thread would match the screw`,
279
+ 'stripping.margin',
280
+ { values: { strip: n1(strip), proof: n1(screw.load), margin: n2(margin), depthFor: n1(depthFor) } },
281
+ ),
282
+ );
283
+ if (o.load != null) {
284
+ const k = strip / o.load,
285
+ want = DEFAULTS.load_margin.value;
286
+ out.push(
287
+ finding(
288
+ k >= want ? 'pass' : k >= 1 ? 'warn' : 'fail',
289
+ `a load of ${mm(o.load)} N is held ${mm(n2(k))} times over by the thread, where the kit asks ${want} ` +
290
+ `times` +
291
+ (k >= want ? '' : `: ${mm(n1(depth * (want / k)))} mm of thread would do`),
292
+ 'stripping.held',
293
+ { values: { load: o.load, margin: n2(k), want } },
294
+ ),
295
+ );
296
+ }
297
+ return {
298
+ thread: fx.thread,
299
+ depth,
300
+ material: mat.name,
301
+ area: n2(area),
302
+ shear: n2(shear),
303
+ strip: n1(strip),
304
+ stressArea: n2(screw.area),
305
+ proof: n1(screw.load),
306
+ margin: n2(margin),
307
+ depthFor: n1(depthFor),
308
+ load: o.load ?? null,
309
+ rests: [rest(f.name, f), rest('fixings.shear_ratio', ratio), ...screw.rests],
310
+ findings: out,
311
+ };
122
312
  }
123
313
 
124
314
  /**
125
315
  * The clamp force a tightening torque gives, or the torque for a clamp force: T = K d F, with the nut factor K an
126
316
  * estimate (0.2 unless given). Give torque or force.
127
- * @param {Fixing | string} m @param {{ torque?: number, force?: number, K?: number, screw?: 'steel' | 'stainless', proof?: number, sets?: object }} o
128
- * torque: in N·m; force: the clamp force (preload) wanted, in N; K: another nut factor (a lubricated thread's is lower)
129
- * @returns {{ thread: string, torque: number, force: number, K: number, proof: number, share: number, full: { force: number, torque: number }, rests: object[], findings: object[] }}
130
- * share: the force as a share of the screw's proof load; full: the force and torque of a screw tightened to three quarters of its proof load
317
+ * @param {Fixing | string} m @param {{ torque?: number, force?: number, K?: number, screw?: 'steel' | 'stainless',
318
+ * proof?: number, sets?: object }} o
319
+ * torque: in N·m; force: the clamp force (preload) wanted, in N; K: another nut factor (a lubricated thread's is
320
+ * lower)
321
+ * @returns {{ thread: string, torque: number, force: number, K: number, proof: number, share: number,
322
+ * full: { force: number, torque: number }, rests: object[], findings: object[] }}
323
+ * share: the force as a share of the screw's proof load; full: the force and torque of a screw tightened to three
324
+ * quarters of its proof load
131
325
  */
132
326
  export function preload(m, o = {}) {
133
327
  const what = 'preload';
134
328
  options(what, o, '{ torque: 0.5 }');
135
- const fx = fixingOf(what, m, o), rule = DEFAULTS.nut_factor, K = o.K ?? rule.value;
136
- if ((o.torque == null) === (o.force == null)) throw new Error(`${what}: give torque (N·m), to get the clamp force, or force (N), to get the torque for it: one of the two (got ${shown({ torque: o.torque, force: o.force })})`);
137
- if (!(isNum(K) && K > 0)) throw new Error(`${what}: K is the nut factor, a number above 0 (0.2 for plain steel threads) (got ${shown(o.K)})`);
138
- const screw = proofOf(what, fx, o), d = fx.major, torque = o.torque != null ? positive(what, 'torque (in N·m)', o.torque) : (K * d * positive(what, 'force (in N)', o.force)) / 1000, force = o.force ?? (torque * 1000) / (K * d), share = force / screw.load;
139
- const full = DEFAULTS.preload_share.value * screw.load, out = [finding('info', `${mm(r3(torque))} N·m on ${a(fx.thread)} screw gives a clamp force of about ${mm(n1(force))} N (T = K d F, K = ${mm(K)}${o.K == null ? ', an estimate: a torque wrench scatters the force by a quarter to a third' : ', as given'})`,
140
- 'preload.force', { values: { torque: r3(torque), force: n1(force), K }, refs: { thread: fx.thread, kind: o.K == null ? 'estimate' : 'given' } })];
141
- out.push(finding(share <= 0.9 + 1e-9 ? 'pass' : share <= 1 + 1e-9 ? 'warn' : 'fail', `that is ${mm(n1(share * 100))}% of the screw's proof load, ${mm(n1(screw.load))} N (${screw.says})${share > 1 ? ': the screw yields first' : share > 0.9 ? ': past the 90% a permanent joint is taken to' : ''}. A screw tightened fully, to ${mm(DEFAULTS.preload_share.value * 100)}% of proof, carries ${mm(n1(full))} N at ${mm(r3((K * d * full) / 1000))} N·m`,
142
- 'preload.proof', { values: { share: r3(share), proof: n1(screw.load) } }));
143
- return { thread: fx.thread, torque: r3(torque), force: n1(force), K, proof: n1(screw.load), share: r3(share), full: { force: n1(full), torque: r3((K * d * full) / 1000) },
144
- rests: [...(o.K == null ? [rest('fixings.nut_factor', rule)] : []), rest('fixings.preload_share', DEFAULTS.preload_share), ...screw.rests], findings: out };
329
+ const fx = fixingOf(what, m, o),
330
+ rule = DEFAULTS.nut_factor,
331
+ K = o.K ?? rule.value;
332
+ if ((o.torque == null) === (o.force == null))
333
+ throw new Error(
334
+ `${what}: give torque (N·m), to get the clamp force, or force (N), to get the torque for it: one of ` +
335
+ `the two (got ${shown({ torque: o.torque, force: o.force })})`,
336
+ );
337
+ if (!(isNum(K) && K > 0))
338
+ throw new Error(`${what}: K is the nut factor, a number above 0 (0.2 for plain steel threads) (got ${shown(o.K)})`);
339
+ const screw = proofOf(what, fx, o),
340
+ d = fx.major,
341
+ torque =
342
+ o.torque != null
343
+ ? positive(what, 'torque (in N·m)', o.torque)
344
+ : (K * d * positive(what, 'force (in N)', o.force)) / 1000,
345
+ force = o.force ?? (torque * 1000) / (K * d),
346
+ share = force / screw.load;
347
+ const full = DEFAULTS.preload_share.value * screw.load,
348
+ out = [
349
+ finding(
350
+ 'info',
351
+ `${mm(r3(torque))} N·m on ${a(fx.thread)} screw gives a clamp force of about ${mm(n1(force))} N (T = ` +
352
+ `K d F, K = ${mm(K)}` +
353
+ (o.K == null ? ', an estimate: a torque wrench scatters the force by a quarter to a third' : ', as given') +
354
+ `)`,
355
+ 'preload.force',
356
+ {
357
+ values: { torque: r3(torque), force: n1(force), K },
358
+ refs: { thread: fx.thread, kind: o.K == null ? 'estimate' : 'given' },
359
+ },
360
+ ),
361
+ ];
362
+ out.push(
363
+ finding(
364
+ share <= 0.9 + 1e-9 ? 'pass' : share <= 1 + 1e-9 ? 'warn' : 'fail',
365
+ `that is ${mm(n1(share * 100))}% of the screw's proof load, ${mm(n1(screw.load))} N (${screw.says})` +
366
+ (share > 1 ? ': the screw yields first' : share > 0.9 ? ': past the 90% a permanent joint is taken to' : '') +
367
+ `. A screw tightened fully, to ${mm(DEFAULTS.preload_share.value * 100)}% of proof, carries ` +
368
+ `${mm(n1(full))} N at ${mm(r3((K * d * full) / 1000))} N·m`,
369
+ 'preload.proof',
370
+ { values: { share: r3(share), proof: n1(screw.load) } },
371
+ ),
372
+ );
373
+ return {
374
+ thread: fx.thread,
375
+ torque: r3(torque),
376
+ force: n1(force),
377
+ K,
378
+ proof: n1(screw.load),
379
+ share: r3(share),
380
+ full: { force: n1(full), torque: r3((K * d * full) / 1000) },
381
+ rests: [
382
+ ...(o.K == null ? [rest('fixings.nut_factor', rule)] : []),
383
+ rest('fixings.preload_share', DEFAULTS.preload_share),
384
+ ...screw.rests,
385
+ ],
386
+ findings: out,
387
+ };
145
388
  }
146
389
  /**
147
390
  * The tightening torque for a clamp force: preload the other way round.
148
- * @param {Fixing | string} m @param {{ force: number, K?: number, screw?: 'steel' | 'stainless', proof?: number, sets?: object }} o
149
- * @returns {{ thread: string, torque: number, force: number, K: number, proof: number, share: number, full: { force: number, torque: number }, rests: object[], findings: object[] }}
391
+ * @param {Fixing | string} m @param {{ force: number, K?: number, screw?: 'steel' | 'stainless', proof?: number,
392
+ * sets?: object }} o
393
+ * @returns {{ thread: string, torque: number, force: number, K: number, proof: number, share: number,
394
+ * full: { force: number, torque: number }, rests: object[], findings: object[] }}
150
395
  */
151
396
  export function torqueFor(m, o = {}) {
152
397
  options('torqueFor', o, '{ force: 500 }');
153
- if (o.torque != null) throw new Error('torqueFor: give force (N), the clamp force wanted: for the force a torque gives, use preload');
398
+ if (o.torque != null)
399
+ throw new Error('torqueFor: give force (N), the clamp force wanted: for the force a torque gives, use preload');
154
400
  notPrinted('torqueFor', fixingOf('torqueFor', m, o));
155
401
  return preload(m, o);
156
402
  }
@@ -158,38 +404,128 @@ export function torqueFor(m, o = {}) {
158
404
  /**
159
405
  * The pressure under a screw's head against what it sits on, and the washer that would bring it within. The head
160
406
  * bears on the ring between its own diameter and the clearance hole as drawn; the limit is the material's strength.
161
- * @param {Fixing | string} m @param {{ head?: string, material: string | object, force?: number, torque?: number, K?: number, hole?: string, printer?: object, screw?: 'steel' | 'stainless', proof?: number, sets?: object }} o
407
+ * @param {Fixing | string} m @param {{ head?: string, material: string | object, force?: number, torque?: number,
408
+ * K?: number, hole?: string, printer?: object, screw?: 'steel' | 'stainless', proof?: number, sets?: object }} o
162
409
  * head: cap, button, hex, countersunk or pan (default the model's, else cap); material: what the head sits on;
163
410
  * force: the clamp force in N, or torque: the tightening torque in N·m (default a screw tightened fully, to three
164
411
  * quarters of its proof load); hole: clearance (the default), close or loose
165
- * @returns {{ thread: string, head: string, material: string, force: number, area: number, pressure: number, limit: number, within: boolean,
166
- * washer: { diameter: number, area: number, pressure: number, within: boolean } | null, most: { force: number, torque: number, washerForce: number | null, washerTorque: number | null }, rests: object[], findings: object[] }}
167
- * area: the bearing ring under the head, mm²; pressure and limit in MPa; washer: the same under the thread's plain washer;
168
- * most: the greatest clamp force the seat takes and the torque for it, bare and on the washer
412
+ * @returns {{ thread: string, head: string, material: string, force: number, area: number, pressure: number,
413
+ * limit: number, within: boolean,
414
+ * washer: { diameter: number, area: number, pressure: number, within: boolean } | null, most:
415
+ * { force: number, torque: number, washerForce: number | null, washerTorque: number | null }, rests: object[],
416
+ * findings: object[] }} area: the bearing ring under the head, mm²; pressure and limit in MPa; washer: the same under
417
+ * the thread's plain washer; most: the greatest clamp force the seat takes and the torque for it, bare and on the
418
+ * washer
169
419
  */
170
420
  export function seating(m, o = {}) {
171
421
  const what = 'seating';
172
- options(what, o, '{ head: \'cap\', material: \'pla\' }');
173
- const fx = fixingOf(what, m, o), form = o.head ?? fx.head?.form ?? (fx.made.heads.includes('cap') ? 'cap' : fx.made.heads[0]);
174
- if (form === 'set') throw new Error(`${what}: a set screw has no head to bear on anything: it presses with its point`);
175
- const head = headOf(what, fx, form), mat = materialOf(what, o.material, o.sets), kind = oneOf(what, 'hole', o.hole ?? 'clearance', ['clearance', 'close', 'loose']), h = holeModel(fx, { kind, printer: o.printer });
422
+ options(what, o, "{ head: 'cap', material: 'pla' }");
423
+ const fx = fixingOf(what, m, o),
424
+ form = o.head ?? fx.head?.form ?? (fx.made.heads.includes('cap') ? 'cap' : fx.made.heads[0]);
425
+ if (form === 'set')
426
+ throw new Error(`${what}: a set screw has no head to bear on anything: it presses with its point`);
427
+ const head = headOf(what, fx, form),
428
+ mat = materialOf(what, o.material, o.sets),
429
+ kind = oneOf(what, 'hole', o.hole ?? 'clearance', ['clearance', 'close', 'loose']),
430
+ h = holeModel(fx, { kind, printer: o.printer });
176
431
  if (o.force != null && o.torque != null) throw new Error(`${what}: give force (N) or torque (N·m), not both`);
177
- const K = o.K ?? DEFAULTS.nut_factor.value, given = o.force != null || o.torque != null, screw = given ? null : proofOf(what, fx, o); // (the screw's proof load sets the force only when none is given)
432
+ const K = o.K ?? DEFAULTS.nut_factor.value,
433
+ given = o.force != null || o.torque != null,
434
+ screw = given ? null : proofOf(what, fx, o); // (the screw's proof load sets the force only when none is given)
178
435
  if (!(isNum(K) && K > 0)) throw new Error(`${what}: K is the nut factor, a number above 0 (got ${shown(o.K)})`);
179
- const force = o.force != null ? positive(what, 'force (in N)', o.force) : o.torque != null ? (positive(what, 'torque (in N·m)', o.torque) * 1000) / (K * fx.major) : DEFAULTS.preload_share.value * screw.load;
180
- const across = head.flats ?? head.diameter, ring = (D) => (Math.PI / 4) * (D * D - h.diameter ** 2), area = ring(across), { f } = weakest(mat), limit = f.value, pressure = force / area, within = pressure <= limit + 1e-9;
181
- if (!(area > 0)) throw new Error(`${what}: ${a(fx.thread)} ${form} head ${mm(across)} mm across has no seat round a ${mm(h.diameter)} mm hole`);
182
- const torqueOf = (F) => r3((K * fx.major * F) / 1000), w = fx.made.washer ? { diameter: figure(what, fx, 'washer_diameter') } : null;
183
- if (w) { w.area = n2(ring(w.diameter)); w.pressure = n1(force / ring(w.diameter)); w.within = force / ring(w.diameter) <= limit + 1e-9; }
184
- const most = { force: n1(limit * area), torque: torqueOf(limit * area), washerForce: w ? n1(limit * ring(w.diameter)) : null, washerTorque: w ? torqueOf(limit * ring(w.diameter)) : null };
185
- const load = given ? `${mm(n1(force))} N` : `${mm(n1(force))} N, a screw tightened fully (${mm(DEFAULTS.preload_share.value * 100)}% of its proof load)`;
186
- const text = `${a(fx.thread)} ${form} head, ${mm(across)} mm across${head.flats ? ' its flats' : ''} on a ${mm(h.diameter)} mm hole, bears on ${mm(n2(area))} mm²: at ${load}, ${mm(n1(pressure))} MPa on ${mat.name}, whose strength is ${mm(limit)} MPa (${f.name}, taken as what it bears: an estimate)`;
187
- const out = [within ? finding('pass', `${text}: within`, 'seating.pressure', { values: { pressure: n1(pressure), limit, force: n1(force), area: n2(area) } })
188
- : w?.within ? finding('warn', `${text}: too much for the bare seat. The ${fx.thread} washer, ${mm(w.diameter)} mm across, brings it to ${mm(w.pressure)} MPa, within`, 'seating.pressure', { values: { pressure: n1(pressure), limit, force: n1(force), area: n2(area), washer: w.pressure } })
189
- : finding('fail', `${text}: too much${w ? `, and the ${fx.thread} washer, ${mm(w.diameter)} mm across, only brings it to ${mm(w.pressure)} MPa` : ', and the thread has no washer in its rule set'}. The seat takes ${mm(most.force)} N bare (${mm(most.torque)} N·m)${w ? ` and ${mm(most.washerForce)} N on the washer (${mm(most.washerTorque)} N·m)` : ''}: tighten to that, or spread the load wider`,
190
- 'seating.pressure', { values: { pressure: n1(pressure), limit, force: n1(force), area: n2(area), ...(w ? { washer: w.pressure } : {}) } })];
191
- return { thread: fx.thread, head: form, material: mat.name, force: n1(force), area: n2(area), pressure: n1(pressure), limit, within, washer: w, most,
192
- rests: [...head.figures.map((k) => rest(cite(fx, k), fx.figures[k])), ...h.rests, rest(f.name, f), ...(w ? [rest(cite(fx, 'washer_diameter'), fx.figures.washer_diameter)] : []), ...(given ? [] : [rest('fixings.preload_share', DEFAULTS.preload_share), ...screw.rests]), ...(o.torque != null && o.K == null ? [rest('fixings.nut_factor', DEFAULTS.nut_factor)] : [])], findings: out };
436
+ const force =
437
+ o.force != null
438
+ ? positive(what, 'force (in N)', o.force)
439
+ : o.torque != null
440
+ ? (positive(what, 'torque (in N·m)', o.torque) * 1000) / (K * fx.major)
441
+ : DEFAULTS.preload_share.value * screw.load;
442
+ const across = head.flats ?? head.diameter,
443
+ ring = (D) => (Math.PI / 4) * (D * D - h.diameter ** 2),
444
+ area = ring(across),
445
+ { f } = weakest(mat),
446
+ limit = f.value,
447
+ pressure = force / area,
448
+ within = pressure <= limit + 1e-9;
449
+ if (!(area > 0))
450
+ throw new Error(
451
+ `${what}: ${a(fx.thread)} ${form} head ${mm(across)} mm across has no seat round a ${mm(h.diameter)} mm hole`,
452
+ );
453
+ const torqueOf = (F) => r3((K * fx.major * F) / 1000),
454
+ w = fx.made.washer ? { diameter: figure(what, fx, 'washer_diameter') } : null;
455
+ if (w) {
456
+ w.area = n2(ring(w.diameter));
457
+ w.pressure = n1(force / ring(w.diameter));
458
+ w.within = force / ring(w.diameter) <= limit + 1e-9;
459
+ }
460
+ const most = {
461
+ force: n1(limit * area),
462
+ torque: torqueOf(limit * area),
463
+ washerForce: w ? n1(limit * ring(w.diameter)) : null,
464
+ washerTorque: w ? torqueOf(limit * ring(w.diameter)) : null,
465
+ };
466
+ const load = given
467
+ ? `${mm(n1(force))} N`
468
+ : `${mm(n1(force))} N, a screw tightened fully (${mm(DEFAULTS.preload_share.value * 100)}% of its proof load)`;
469
+ const text =
470
+ `${a(fx.thread)} ${form} head, ${mm(across)} mm across${head.flats ? ' its flats' : ''} on a ` +
471
+ `${mm(h.diameter)} mm hole, bears on ${mm(n2(area))} mm²: at ${load}, ${mm(n1(pressure))} MPa on ` +
472
+ `${mat.name}, whose strength is ${mm(limit)} MPa (${f.name}, taken as what it bears: an estimate)`;
473
+ const out = [
474
+ within
475
+ ? finding('pass', `${text}: within`, 'seating.pressure', {
476
+ values: { pressure: n1(pressure), limit, force: n1(force), area: n2(area) },
477
+ })
478
+ : w?.within
479
+ ? finding(
480
+ 'warn',
481
+ `${text}: too much for the bare seat. The ${fx.thread} washer, ${mm(w.diameter)} mm across, ` +
482
+ `brings it to ${mm(w.pressure)} MPa, within`,
483
+ 'seating.pressure',
484
+ { values: { pressure: n1(pressure), limit, force: n1(force), area: n2(area), washer: w.pressure } },
485
+ )
486
+ : finding(
487
+ 'fail',
488
+ `${text}: too much` +
489
+ (w
490
+ ? `, and the ${fx.thread} washer, ${mm(w.diameter)} mm across, only brings it to ${mm(w.pressure)} ` +
491
+ `MPa`
492
+ : ', and the thread has no washer in its rule set') +
493
+ `. The seat takes ${mm(most.force)} N bare (${mm(most.torque)} N·m)` +
494
+ (w ? ` and ${mm(most.washerForce)} N on the washer (${mm(most.washerTorque)} N·m)` : '') +
495
+ `: tighten to that, or spread the load wider`,
496
+ 'seating.pressure',
497
+ {
498
+ values: {
499
+ pressure: n1(pressure),
500
+ limit,
501
+ force: n1(force),
502
+ area: n2(area),
503
+ ...(w ? { washer: w.pressure } : {}),
504
+ },
505
+ },
506
+ ),
507
+ ];
508
+ return {
509
+ thread: fx.thread,
510
+ head: form,
511
+ material: mat.name,
512
+ force: n1(force),
513
+ area: n2(area),
514
+ pressure: n1(pressure),
515
+ limit,
516
+ within,
517
+ washer: w,
518
+ most,
519
+ rests: [
520
+ ...head.figures.map((k) => rest(cite(fx, k), fx.figures[k])),
521
+ ...h.rests,
522
+ rest(f.name, f),
523
+ ...(w ? [rest(cite(fx, 'washer_diameter'), fx.figures.washer_diameter)] : []),
524
+ ...(given ? [] : [rest('fixings.preload_share', DEFAULTS.preload_share), ...screw.rests]),
525
+ ...(o.torque != null && o.K == null ? [rest('fixings.nut_factor', DEFAULTS.nut_factor)] : []),
526
+ ],
527
+ findings: out,
528
+ };
193
529
  }
194
530
 
195
531
  /** What a screw can end in, for lengthFor. */
@@ -197,83 +533,249 @@ export const ENDS = ['pilot', 'tap', 'thread', 'insert', 'nut'];
197
533
  // The far end of a joint: how much thread the screw must engage there, and how much room it has before it bottoms out
198
534
  function endOf(what, fx, into, o) {
199
535
  const e = typeof into === 'string' ? { kind: into } : into;
200
- if (!e || typeof e !== 'object' || Array.isArray(e)) throw new Error(`${what}: into is what the screw ends in: ${ENDS.map((k) => `'${k}'`).join(', ')}, or { kind, depth, material } (got ${shown(into)})`);
201
- const kind = oneOf(what, 'into', e.kind, ENDS), through = e.through ?? false, rests = [];
536
+ if (!e || typeof e !== 'object' || Array.isArray(e))
537
+ throw new Error(
538
+ `${what}: into is what the screw ends in: ${ENDS.map((k) => `'${k}'`).join(', ')}, or { kind, depth, ` +
539
+ `material } (got ${shown(into)})`,
540
+ );
541
+ const kind = oneOf(what, 'into', e.kind, ENDS),
542
+ through = e.through ?? false,
543
+ rests = [];
202
544
  if (typeof through !== 'boolean') throw new Error(`${what}: into.through is true or false (got ${shown(e.through)})`);
203
- if (e.depth != null) positive(what, 'into.depth', e.depth); if (e.room != null) positive(what, 'into.room', e.room);
204
- const use = (m, n) => { rests.push(rest(cite(m, n), m.figures[n])); return figure(what, m, n); };
545
+ if (e.depth != null) positive(what, 'into.depth', e.depth);
546
+ if (e.room != null) positive(what, 'into.room', e.room);
547
+ const use = (m, n) => {
548
+ rests.push(rest(cite(m, n), m.figures[n]));
549
+ return figure(what, m, n);
550
+ };
205
551
  if (kind === 'insert') {
206
- const ins = fixingModel(`${fx.thread} ${e.length != null ? `x ${positive(what, 'into.length', e.length)} mm ` : ''}insert`, {}, { sets: o.sets }), long = use(ins, 'insert_length'), rule = DEFAULTS.insert_engagement;
552
+ const ins = fixingModel(
553
+ `${fx.thread} ${e.length != null ? `x ${positive(what, 'into.length', e.length)} mm ` : ''}insert`,
554
+ {},
555
+ { sets: o.sets },
556
+ ),
557
+ long = use(ins, 'insert_length'),
558
+ rule = DEFAULTS.insert_engagement;
207
559
  rests.push(rest('fixings.insert_engagement', rule));
208
- return { kind, says: `${a(fx.thread)} insert ${mm(long)} mm long`, need: r3(Math.min(rule.value * fx.major, long)), room: through ? Infinity : e.room ?? long, tip: 0, ends: 'bottom out', why: `the insert's ${mm(long)} mm: the hole's extra millimetre under it is left for the plastic the insert pushes ahead`, rests };
560
+ return {
561
+ kind,
562
+ says: `${a(fx.thread)} insert ${mm(long)} mm long`,
563
+ need: r3(Math.min(rule.value * fx.major, long)),
564
+ room: through ? Infinity : (e.room ?? long),
565
+ tip: 0,
566
+ ends: 'bottom out',
567
+ why:
568
+ `the insert's ${mm(long)} mm: the hole's extra millimetre under it is left for the plastic the insert ` +
569
+ `pushes ahead`,
570
+ rests,
571
+ };
209
572
  }
210
573
  if (kind === 'nut') {
211
- const nut = nutOf(what, fx, e.nut ?? 'hex'); rests.push(...nut.figures.map((n) => rest(cite(fx, n), fx.figures[n])));
212
- return { kind, says: `${a(fx.thread)} ${nut.kind === 'hex' ? '' : `${nut.kind} `}nut ${mm(nut.height)} mm high`, need: nut.height, room: e.room ?? Infinity, tip: 0, ends: 'stand proud', why: 'the room given past the nut\'s seat', rests };
574
+ const nut = nutOf(what, fx, e.nut ?? 'hex');
575
+ rests.push(...nut.figures.map((n) => rest(cite(fx, n), fx.figures[n])));
576
+ return {
577
+ kind,
578
+ says: `${a(fx.thread)} ${nut.kind === 'hex' ? '' : `${nut.kind} `}nut ${mm(nut.height)} mm high`,
579
+ need: nut.height,
580
+ room: e.room ?? Infinity,
581
+ tip: 0,
582
+ ends: 'stand proud',
583
+ why: "the room given past the nut's seat",
584
+ rests,
585
+ };
213
586
  }
214
- const tip = through ? 0 : DEFAULTS.tip_room.value; let need;
587
+ const tip = through ? 0 : DEFAULTS.tip_room.value;
588
+ let need;
215
589
  if (kind === 'pilot' && fx.figures.pilot_depth) need = use(fx, 'pilot_depth');
216
- else { const cls = kind === 'pilot' ? 'plastic' : classOf(what, e.material ?? 'plastic', o.sets).cls; rests.push(rest(`engagement.${cls}`, ENGAGEMENT[cls])); need = r3(ENGAGEMENT[cls].value * fx.major); }
590
+ else {
591
+ const cls = kind === 'pilot' ? 'plastic' : classOf(what, e.material ?? 'plastic', o.sets).cls;
592
+ rests.push(rest(`engagement.${cls}`, ENGAGEMENT[cls]));
593
+ need = r3(ENGAGEMENT[cls].value * fx.major);
594
+ }
217
595
  if (!through) rests.push(rest('fixings.tip_room', DEFAULTS.tip_room));
218
- const says = kind === 'pilot' ? 'a pilot it forms its own thread in' : kind === 'tap' ? 'a tapped hole' : 'a printed thread';
219
- return { kind, says: `${says}${e.depth != null ? ` ${mm(e.depth)} mm deep` : ''}`, need, room: through ? Infinity : e.depth ?? Infinity, tip, ends: 'bottom out', why: `the hole's ${mm(e.depth ?? 0)} mm less ${mm(tip)} mm at its tip`, rests };
596
+ const says =
597
+ kind === 'pilot' ? 'a pilot it forms its own thread in' : kind === 'tap' ? 'a tapped hole' : 'a printed thread';
598
+ return {
599
+ kind,
600
+ says: `${says}${e.depth != null ? ` ${mm(e.depth)} mm deep` : ''}`,
601
+ need,
602
+ room: through ? Infinity : (e.depth ?? Infinity),
603
+ tip,
604
+ ends: 'bottom out',
605
+ why: `the hole's ${mm(e.depth ?? 0)} mm less ${mm(tip)} mm at its tip`,
606
+ rests,
607
+ };
220
608
  }
221
609
 
222
610
  /**
223
611
  * The sold length of screw that passes through a stack of parts and engages enough at the far end, without bottoming
224
612
  * out or standing proud: the shortest that does. Refused by name where no sold length fits, with the nearest.
225
- * @param {number | number[]} stack the thicknesses the screw passes through under its head, in order, in mm (a countersunk
613
+ * @param {number | number[]} stack the thicknesses the screw passes through under its head, in order, in mm (a
614
+ * countersunk
226
615
  * screw's length includes its head, so its stack does too)
227
616
  * @param {Fixing | string} m a thread or a screw ('M3', 'M3 button'): its head form is the model's, else cap
228
- * @param {{ into: string | { kind: string, depth?: number, room?: number, through?: boolean, material?: string, nut?: string, length?: number }, head?: string, washer?: boolean, sunk?: number, sets?: object }} o
617
+ * @param {{ into: string | { kind: string, depth?: number, room?: number, through?: boolean, material?: string,
618
+ * nut?: string, length?: number }, head?: string, washer?: boolean, sunk?: number, sets?: object }} o
229
619
  * into: what the screw ends in: 'pilot', 'tap', 'thread' (a printed one), 'insert' or 'nut', or the same with its
230
620
  * depth (a blind hole's), room (how far the screw may go past where its thread starts), through (it may come out
231
621
  * the far side), material (a tapped or printed thread's), nut (hex, square, lock) or length (another insert's);
232
- * washer: a plain washer under the head; sunk: how far the head's seat lies under the first face (a counterbore's depth)
233
- * @returns {{ name: string, thread: string, head: string, length: number, grip: number, engaged: number, need: number, room: number | null, spare: number | null, depth: number | null, into: string,
234
- * lengths: { length: number, name: string, engaged: number, fits: 'short' | 'fits' | 'long' }[], rests: object[], findings: object[] }}
235
- * grip: what the screw passes before its thread engages; engaged: thread in the far end; room: how far it may go (null: no limit);
236
- * spare: room left past its tip; depth: for a blind hole not given a depth, the depth to draw; lengths: every sold length with its verdict
622
+ * washer: a plain washer under the head; sunk: how far the head's seat lies under the first face (a counterbore's
623
+ * depth)
624
+ * @returns {{ name: string, thread: string, head: string, length: number, grip: number, engaged: number, need: number,
625
+ * room: number | null, spare: number | null, depth: number | null, into: string,
626
+ * lengths: { length: number, name: string, engaged: number, fits: 'short' | 'fits' | 'long' }[], rests: object[],
627
+ * findings: object[] }} grip: what the screw passes before its thread engages; engaged: thread in the far end; room:
628
+ * how far it may go (null: no limit); spare: room left past its tip; depth: for a blind hole not given a depth, the
629
+ * depth to draw; lengths: every sold length with its verdict
237
630
  */
238
631
  export function lengthFor(stack, m, o = {}) {
239
632
  const what = 'lengthFor';
240
- options(what, o, '{ into: \'insert\' }');
633
+ options(what, o, "{ into: 'insert' }");
241
634
  const parts = Array.isArray(stack) ? stack : [stack];
242
- if (!parts.length || !parts.every((t) => isNum(t) && t > 0)) throw new Error(`${what}: the stack is the thicknesses the screw passes through, each above 0 mm: 6 or [3, 6] (got ${shown(stack)})`);
635
+ if (!parts.length || !parts.every((t) => isNum(t) && t > 0))
636
+ throw new Error(
637
+ `${what}: the stack is the thicknesses the screw passes through, each above 0 mm: 6 or [3, 6] (got ` +
638
+ `${shown(stack)})`,
639
+ );
243
640
  const fx = fixingOf(what, m, { ...o, anyLength: true });
244
- if (!['thread', 'screw'].includes(fx.item)) throw new Error(`${what}: ${fx.name} is ${a(fx.item)}, not a screw: give the thread or the screw ('${fx.thread}', '${fx.thread} button')`);
641
+ if (!['thread', 'screw'].includes(fx.item))
642
+ throw new Error(
643
+ `${what}: ${fx.name} is ${a(fx.item)}, not a screw: give the thread or the screw ('${fx.thread}', '` +
644
+ `${fx.thread} button')`,
645
+ );
245
646
  const form = o.head ?? fx.head?.form ?? (fx.made.heads.includes('cap') ? 'cap' : fx.made.heads[0]);
246
- if (form === 'set') throw new Error(`${what}: a set screw clamps nothing between a head and a thread: its length is the hole's`);
647
+ if (form === 'set')
648
+ throw new Error(`${what}: a set screw clamps nothing between a head and a thread: its length is the hole's`);
247
649
  headOf(what, fx, form);
248
- if (o.into == null) throw new Error(`${what}: give into, what the screw ends in: ${ENDS.map((k) => `'${k}'`).join(', ')}, or { kind, depth, material }`);
249
- const end = endOf(what, fx, o.into, o), rests = [...end.rests];
250
- if (o.sunk != null && !(isNum(o.sunk) && o.sunk >= 0)) throw new Error(`${what}: sunk is how far the head's seat lies under the first face, 0 mm or more (got ${shown(o.sunk)})`);
251
- if (o.washer != null && typeof o.washer !== 'boolean') throw new Error(`${what}: washer is true or false (got ${shown(o.washer)})`);
252
- let washer = 0; if (o.washer) { if (!fx.made.washer) throw new Error(`${what}: ${fx.thread} has no washer in its rule set (${fx.set})`); washer = figure(what, fx, 'washer_thickness'); rests.push(rest(cite(fx, 'washer_thickness'), fx.figures.washer_thickness)); }
253
- const total = parts.reduce((s, t) => s + t, 0), grip = r3(total + washer - (o.sunk ?? 0));
254
- if (!(grip > 0)) throw new Error(`${what}: a seat sunk ${mm(o.sunk)} mm is deeper than the ${mm(total)} mm stack it is in: nothing is left under the head`);
255
- const sold = fx.printed ? Array.from({ length: 300 }, (_, i) => i + 1) : fx.figures.lengths?.value; // (a printed screw is printed to any whole millimetre)
256
- if (!Array.isArray(sold) || !sold.every(isNum)) throw new Error(`${what}: ${fx.thread} lists no lengths in its rule set (${fx.set}), so none can be chosen: the length wanted is between ${mm(r3(grip + end.need))} mm${Number.isFinite(end.room) ? ` and ${mm(r3(grip + end.room - end.tip))} mm` : ' and as long as you like'}`);
650
+ if (o.into == null)
651
+ throw new Error(
652
+ `${what}: give into, what the screw ends in: ${ENDS.map((k) => `'${k}'`).join(', ')}, or { kind, ` +
653
+ `depth, material }`,
654
+ );
655
+ const end = endOf(what, fx, o.into, o),
656
+ rests = [...end.rests];
657
+ if (o.sunk != null && !(isNum(o.sunk) && o.sunk >= 0))
658
+ throw new Error(
659
+ `${what}: sunk is how far the head's seat lies under the first face, 0 mm or more (got ${shown(o.sunk)})`,
660
+ );
661
+ if (o.washer != null && typeof o.washer !== 'boolean')
662
+ throw new Error(`${what}: washer is true or false (got ${shown(o.washer)})`);
663
+ let washer = 0;
664
+ if (o.washer) {
665
+ if (!fx.made.washer) throw new Error(`${what}: ${fx.thread} has no washer in its rule set (${fx.set})`);
666
+ washer = figure(what, fx, 'washer_thickness');
667
+ rests.push(rest(cite(fx, 'washer_thickness'), fx.figures.washer_thickness));
668
+ }
669
+ const total = parts.reduce((s, t) => s + t, 0),
670
+ grip = r3(total + washer - (o.sunk ?? 0));
671
+ if (!(grip > 0))
672
+ throw new Error(
673
+ `${what}: a seat sunk ${mm(o.sunk)} mm is deeper than the ${mm(total)} mm stack it is in: nothing is ` +
674
+ `left under the head`,
675
+ );
676
+ // (a printed screw is printed to any whole millimetre)
677
+ const sold = fx.printed ? Array.from({ length: 300 }, (_, i) => i + 1) : fx.figures.lengths?.value;
678
+ if (!Array.isArray(sold) || !sold.every(isNum))
679
+ throw new Error(
680
+ `${what}: ${fx.thread} lists no lengths in its rule set (${fx.set}), so none can be chosen: the length ` +
681
+ `wanted is between ${mm(r3(grip + end.need))} mm` +
682
+ (Number.isFinite(end.room) ? ` and ${mm(r3(grip + end.room - end.tip))} mm` : ' and as long as you like'),
683
+ );
257
684
  if (!fx.printed) rests.push(rest(cite(fx, 'lengths'), fx.figures.lengths));
258
- const most = end.room - end.tip, verdict = (L) => (L - grip < end.need - 1e-9 ? 'short' : L - grip > most + 1e-9 ? 'long' : 'fits'), name = (L) => `${screwName(fx, L, form)}${fx.printed ? ' printed' : ''}`;
259
- const lengths = sold.map((L) => ({ length: L, name: name(L), engaged: r3(Math.max(L - grip, 0)), fits: verdict(L) })), pick = lengths.find((l) => l.fits === 'fits'), below = lengths.filter((l) => l.fits === 'short').at(-1), above = lengths.find((l) => l.fits === 'long');
260
- if (most < end.need - 1e-9) throw new Error(`${what}: ${end.says} leaves ${mm(r3(most))} mm of room for the screw (${end.why}) where ${mm(end.need)} mm of thread is asked: no length can do both. Deepen the far end to ${mm(r3(end.need + end.tip))} mm or more`);
261
- const short = (l) => (l.length <= grip ? `${l.name} does not reach through the ${mm(grip)} mm stack` : `${l.name} would engage ${mm(l.engaged)} mm where ${mm(end.need)} mm is asked`), long = (l) => `${l.name} would ${end.ends}: ${mm(l.engaged)} mm into ${mm(r3(most))} mm of room (${end.why})`;
685
+ const most = end.room - end.tip,
686
+ verdict = (L) => (L - grip < end.need - 1e-9 ? 'short' : L - grip > most + 1e-9 ? 'long' : 'fits'),
687
+ name = (L) => `${screwName(fx, L, form)}${fx.printed ? ' printed' : ''}`;
688
+ const lengths = sold.map((L) => ({ length: L, name: name(L), engaged: r3(Math.max(L - grip, 0)), fits: verdict(L) })),
689
+ pick = lengths.find((l) => l.fits === 'fits'),
690
+ below = lengths.filter((l) => l.fits === 'short').at(-1),
691
+ above = lengths.find((l) => l.fits === 'long');
692
+ if (most < end.need - 1e-9)
693
+ throw new Error(
694
+ `${what}: ${end.says} leaves ${mm(r3(most))} mm of room for the screw (${end.why}) where ` +
695
+ `${mm(end.need)} mm of thread is asked: no length can do both. Deepen the far end to ` +
696
+ `${mm(r3(end.need + end.tip))} mm or more`,
697
+ );
698
+ const short = (l) =>
699
+ l.length <= grip
700
+ ? `${l.name} does not reach through the ${mm(grip)} mm stack`
701
+ : `${l.name} would engage ${mm(l.engaged)} mm where ${mm(end.need)} mm is asked`,
702
+ long = (l) => `${l.name} would ${end.ends}: ${mm(l.engaged)} mm into ${mm(r3(most))} mm of room (${end.why})`;
262
703
  const job = `${mm(grip)} mm of stack into ${end.says}`;
263
704
  if (!pick) {
264
- const miss = (l) => r3(l === below ? grip + end.need - l.length : l.length - grip - most), nearest = !below ? above : !above ? below : miss(below) <= miss(above) ? below : above;
265
- throw new Error(`${what}: no ${fx.thread} ${form} screw that is sold fits ${job}: ${[below && short(below), above && long(above)].filter(Boolean).join(', and ')}. The nearest is ${nearest.name}: change the stack or the far end by ${mm(miss(nearest))} mm, or use a length of ${mm(r3(grip + end.need))} mm${Number.isFinite(most) ? ` to ${mm(r3(grip + most))} mm` : ' or more'} from another list (fixingModel's { anyLength: true })`);
705
+ const miss = (l) => r3(l === below ? grip + end.need - l.length : l.length - grip - most),
706
+ nearest = !below ? above : !above ? below : miss(below) <= miss(above) ? below : above;
707
+ throw new Error(
708
+ `${what}: no ${fx.thread} ${form} screw that is sold fits ${job}: ` +
709
+ `${[below && short(below), above && long(above)].filter(Boolean).join(', and ')}. The nearest is ` +
710
+ `${nearest.name}: change the stack or the far end by ${mm(miss(nearest))} mm, or use a length of ` +
711
+ `${mm(r3(grip + end.need))} mm` +
712
+ (Number.isFinite(most) ? ` to ${mm(r3(grip + most))} mm` : ' or more') +
713
+ ` from another list (fixingModel's { anyLength: true })`,
714
+ );
266
715
  }
267
- const out = [finding('pass', `${pick.name} fits ${job}: it engages ${mm(pick.engaged)} mm where ${mm(end.need)} mm is asked${Number.isFinite(most) ? `, with ${mm(r3(most - pick.engaged))} mm to spare before it would ${end.ends}` : ''}`, 'lengthFor.chosen', { values: { length: pick.length, grip, engaged: pick.engaged, need: end.need }, refs: { thread: fx.thread, screw: pick.name, into: end.kind } })];
268
- if (above) out.push(finding('info', long(above), 'lengthFor.longer', { values: { length: above.length, engaged: above.engaged, room: r3(most) } }));
269
- if (below) out.push(finding('info', short(below), 'lengthFor.shorter', { values: { length: below.length, engaged: below.engaged, need: end.need } }));
270
- const blind = ['pilot', 'tap', 'thread'].includes(end.kind) && !Number.isFinite(end.room) && !(typeof o.into === 'object' && o.into.through), depth = blind ? r3(pick.engaged + DEFAULTS.tip_room.value) : null;
271
- if (blind) out.push(finding('info', `draw its blind hole ${mm(depth)} mm deep or more: the ${mm(pick.engaged)} mm the screw goes in and ${mm(DEFAULTS.tip_room.value)} mm at its tip`, 'lengthFor.depth', { values: { depth } }));
272
- return { name: pick.name, thread: fx.thread, head: form, length: pick.length, grip, engaged: pick.engaged, need: end.need, room: Number.isFinite(most) ? r3(most) : null, spare: Number.isFinite(most) ? r3(most - pick.engaged) : null, depth, into: end.kind, lengths, rests, findings: out };
716
+ const out = [
717
+ finding(
718
+ 'pass',
719
+ `${pick.name} fits ${job}: it engages ${mm(pick.engaged)} mm where ${mm(end.need)} mm is asked` +
720
+ (Number.isFinite(most) ? `, with ${mm(r3(most - pick.engaged))} mm to spare before it would ${end.ends}` : ''),
721
+ 'lengthFor.chosen',
722
+ {
723
+ values: { length: pick.length, grip, engaged: pick.engaged, need: end.need },
724
+ refs: { thread: fx.thread, screw: pick.name, into: end.kind },
725
+ },
726
+ ),
727
+ ];
728
+ if (above)
729
+ out.push(
730
+ finding('info', long(above), 'lengthFor.longer', {
731
+ values: { length: above.length, engaged: above.engaged, room: r3(most) },
732
+ }),
733
+ );
734
+ if (below)
735
+ out.push(
736
+ finding('info', short(below), 'lengthFor.shorter', {
737
+ values: { length: below.length, engaged: below.engaged, need: end.need },
738
+ }),
739
+ );
740
+ const blind =
741
+ ['pilot', 'tap', 'thread'].includes(end.kind) &&
742
+ !Number.isFinite(end.room) &&
743
+ !(typeof o.into === 'object' && o.into.through),
744
+ depth = blind ? r3(pick.engaged + DEFAULTS.tip_room.value) : null;
745
+ if (blind)
746
+ out.push(
747
+ finding(
748
+ 'info',
749
+ `draw its blind hole ${mm(depth)} mm deep or more: the ${mm(pick.engaged)} mm the screw goes in and ` +
750
+ `${mm(DEFAULTS.tip_room.value)} mm at its tip`,
751
+ 'lengthFor.depth',
752
+ { values: { depth } },
753
+ ),
754
+ );
755
+ return {
756
+ name: pick.name,
757
+ thread: fx.thread,
758
+ head: form,
759
+ length: pick.length,
760
+ grip,
761
+ engaged: pick.engaged,
762
+ need: end.need,
763
+ room: Number.isFinite(most) ? r3(most) : null,
764
+ spare: Number.isFinite(most) ? r3(most - pick.engaged) : null,
765
+ depth,
766
+ into: end.kind,
767
+ lengths,
768
+ rests,
769
+ findings: out,
770
+ };
273
771
  }
274
772
 
275
773
  // ---------- screws as a group, under a load ----------
276
- const xyz = (what, k, v, n) => { if (!(Array.isArray(v) && v.length >= 2 && v.length <= n && v.every(isNum))) throw new Error(`${what}: ${k} is ${n === 3 ? '[x, y, z]' : '[x, y]'} in numbers (got ${shown(v)})`); return [v[0], v[1], v[2] ?? 0]; };
774
+ const xyz = (what, k, v, n) => {
775
+ if (!(Array.isArray(v) && v.length >= 2 && v.length <= n && v.every(isNum)))
776
+ throw new Error(`${what}: ${k} is ${n === 3 ? '[x, y, z]' : '[x, y]'} in numbers (got ${shown(v)})`);
777
+ return [v[0], v[1], v[2] ?? 0];
778
+ };
277
779
  const crossed = (p, q) => [p[1] * q[2] - p[2] * q[1], p[2] * q[0] - p[0] * q[2], p[0] * q[1] - p[1] * q[0]];
278
780
 
279
781
  /**
@@ -288,35 +790,91 @@ const crossed = (p, q) => [p[1] * q[2] - p[2] * q[1], p[2] * q[0] - p[0] * q[2],
288
790
  * moment: [x, y, z] in N·m on that part, about `at`; at: where the force acts, [x, y] or [x, y, z] in mm, z the
289
791
  * height off the joint's face (default the centroid); pivot: for screws in a line, how far the clamped face
290
792
  * reaches past the line, in mm
291
- * @returns {{ count: number, centroid: number[], polar: number, line: boolean, screws: { at: number[], shear: number, tension: number, across: number[] }[], turns: number | null, rests: object[] }}
793
+ * @returns {{ count: number, centroid: number[], polar: number, line: boolean, screws: { at: number[], shear: number,
794
+ * tension: number, across: number[] }[], turns: number | null, rests: object[] }}
292
795
  * polar: the sum of the squared distances from the centroid, mm²; screws: each one's shear (N, across the joint) and
293
796
  * tension (N, along it: under 0, the load presses that screw's parts together); turns: a twist one screw alone
294
797
  * cannot hold by shear, in N·m (it holds by friction only), null when it rounds to 0 at the thousandth
295
798
  */
296
799
  export function screwGroup(places, o = {}) {
297
800
  const what = 'screwGroup';
298
- if (!Array.isArray(places) || !places.length) throw new Error(`${what}: places lists each screw's [x, y] across the joint, in mm (got ${shown(places)})`);
801
+ if (!Array.isArray(places) || !places.length)
802
+ throw new Error(`${what}: places lists each screw's [x, y] across the joint, in mm (got ${shown(places)})`);
299
803
  options(what, o, '{ force: [0, 0, 20], at: [12, 0] }');
300
- const P = places.map((p, i) => xyz(what, `places[${i}]`, p, 2)), n = P.length, c = [P.reduce((t, p) => t + p[0], 0) / n, P.reduce((t, p) => t + p[1], 0) / n, 0];
301
- const F = o.force != null ? xyz(what, 'force', o.force, 3) : [0, 0, 0], M0 = o.moment != null ? xyz(what, 'moment', o.moment, 3).map((m) => m * 1000) : [0, 0, 0], A = o.at != null ? xyz(what, 'at', o.at, 3) : c;
302
- if (o.pivot != null) positive(what, 'pivot (how far the clamped face reaches past the line of screws, in mm)', o.pivot);
804
+ const P = places.map((p, i) => xyz(what, `places[${i}]`, p, 2)),
805
+ n = P.length,
806
+ c = [P.reduce((t, p) => t + p[0], 0) / n, P.reduce((t, p) => t + p[1], 0) / n, 0];
807
+ const F = o.force != null ? xyz(what, 'force', o.force, 3) : [0, 0, 0],
808
+ M0 = o.moment != null ? xyz(what, 'moment', o.moment, 3).map((m) => m * 1000) : [0, 0, 0],
809
+ A = o.at != null ? xyz(what, 'at', o.at, 3) : c;
810
+ if (o.pivot != null)
811
+ positive(what, 'pivot (how far the clamped face reaches past the line of screws, in mm)', o.pivot);
303
812
  const M = crossed([A[0] - c[0], A[1] - c[1], A[2]], F).map((m, k) => m + M0[k]); // N mm about the centroid
304
- const r = P.map((p) => [p[0] - c[0], p[1] - c[1]]), Sxx = r.reduce((t, q) => t + q[0] * q[0], 0), Syy = r.reduce((t, q) => t + q[1] * q[1], 0), Sxy = r.reduce((t, q) => t + q[0] * q[1], 0), polar = Sxx + Syy;
305
- const det = Sxx * Syy - Sxy * Sxy, line = det <= 1e-9 * Math.max(polar * polar, 1);
813
+ const r = P.map((p) => [p[0] - c[0], p[1] - c[1]]),
814
+ Sxx = r.reduce((t, q) => t + q[0] * q[0], 0),
815
+ Syy = r.reduce((t, q) => t + q[1] * q[1], 0),
816
+ Sxy = r.reduce((t, q) => t + q[0] * q[1], 0),
817
+ polar = Sxx + Syy;
818
+ const det = Sxx * Syy - Sxy * Sxy,
819
+ line = det <= 1e-9 * Math.max(polar * polar, 1);
306
820
  // tension: the pull shared, and Σ P (y, -x) = (Mx, My) taken by a plane of tension through the centroid
307
821
  let tension;
308
- if (!line) { const b = (-M[1] * Syy - M[0] * Sxy) / det, cc = (M[0] * Sxx + M[1] * Sxy) / det; tension = r.map(([x, y]) => F[2] / n + b * x + cc * y); }
309
- else {
310
- const far = r.reduce((m, q) => (Math.hypot(...q) > Math.hypot(...m) ? q : m), [0, 0]), l = Math.hypot(...far), u = l > 1e-9 ? [far[0] / l, far[1] / l] : [1, 0], w = [u[1], -u[0]];
311
- const s = r.map((q) => q[0] * u[0] + q[1] * u[1]), S2 = s.reduce((t, x) => t + x * x, 0), along = M[0] * w[0] + M[1] * w[1], about = l > 1e-9 ? M[0] * u[0] + M[1] * u[1] : Math.hypot(M[0], M[1]);
312
- if (Math.abs(about) > 1e-9 && o.pivot == null) throw new Error(`${what}: the screws stand in one line${n === 1 ? ' (there is one)' : ''}, and ${mm(n1(Math.abs(about) / 1000))} N·m tips the part about it: give pivot, how far the clamped face reaches past the line in mm`);
313
- tension = s.map((x) => F[2] / n + (S2 > 1e-9 ? (along * x) / S2 : 0) + (Math.abs(about) > 1e-9 ? Math.abs(about) / (n * o.pivot) : 0));
822
+ if (!line) {
823
+ const b = (-M[1] * Syy - M[0] * Sxy) / det,
824
+ cc = (M[0] * Sxx + M[1] * Sxy) / det;
825
+ tension = r.map(([x, y]) => F[2] / n + b * x + cc * y);
826
+ } else {
827
+ const far = r.reduce((m, q) => (Math.hypot(...q) > Math.hypot(...m) ? q : m), [0, 0]),
828
+ l = Math.hypot(...far),
829
+ u = l > 1e-9 ? [far[0] / l, far[1] / l] : [1, 0],
830
+ w = [u[1], -u[0]];
831
+ const s = r.map((q) => q[0] * u[0] + q[1] * u[1]),
832
+ S2 = s.reduce((t, x) => t + x * x, 0),
833
+ along = M[0] * w[0] + M[1] * w[1],
834
+ about = l > 1e-9 ? M[0] * u[0] + M[1] * u[1] : Math.hypot(M[0], M[1]);
835
+ if (Math.abs(about) > 1e-9 && o.pivot == null)
836
+ throw new Error(
837
+ `${what}: the screws stand in one line${n === 1 ? ' (there is one)' : ''}, and ` +
838
+ `${mm(n1(Math.abs(about) / 1000))} N·m tips the part about it: give pivot, how far the clamped face ` +
839
+ `reaches past the line in mm`,
840
+ );
841
+ tension = s.map(
842
+ (x) =>
843
+ F[2] / n + (S2 > 1e-9 ? (along * x) / S2 : 0) + (Math.abs(about) > 1e-9 ? Math.abs(about) / (n * o.pivot) : 0),
844
+ );
314
845
  }
315
- const screws = r.map(([x, y], i) => { const across = polar > 1e-9 ? [F[0] / n - (M[2] * y) / polar, F[1] / n + (M[2] * x) / polar] : [F[0] / n, F[1] / n]; return { at: [P[i][0], P[i][1]], shear: Math.hypot(...across), tension: tension[i], across }; }); // (not rounded: a check rounds what it prints)
846
+ const screws = r.map(([x, y], i) => {
847
+ const across = polar > 1e-9 ? [F[0] / n - (M[2] * y) / polar, F[1] / n + (M[2] * x) / polar] : [F[0] / n, F[1] / n];
848
+ return { at: [P[i][0], P[i][1]], shear: Math.hypot(...across), tension: tension[i], across };
849
+ }); // (not rounded: a check rounds what it prints)
316
850
  const twist = r3(Math.abs(M[2]) / 1000); // N·m, as said: a twist that rounds to nothing is none
317
- return { count: n, centroid: [r3(c[0]), r3(c[1])], polar: r3(polar), line, screws, turns: polar > 1e-9 || !twist ? null : twist,
318
- rests: [{ name: 'the elastic method, in shear', value: 'P/n and M d / Σd² about the centroid', kind: 'spec', source: 'Eccentrically loaded bolt groups, the elastic method: https://steelcalculator.pages.dev/reference/bolt-group-capacity/ (read 2026-11-15)' },
319
- { name: 'the elastic method, in tension', value: 'a plane of tension through the centroid', kind: 'estimate', source: 'No source read: a moment shared as the shear is, each screw\'s pull growing with its distance from the centroid, which holds while the clamped parts stay pressed together. A joint that opens tips about its edge and loads its far screws more' }] };
851
+ return {
852
+ count: n,
853
+ centroid: [r3(c[0]), r3(c[1])],
854
+ polar: r3(polar),
855
+ line,
856
+ screws,
857
+ turns: polar > 1e-9 || !twist ? null : twist,
858
+ rests: [
859
+ {
860
+ name: 'the elastic method, in shear',
861
+ value: 'P/n and M d / Σd² about the centroid',
862
+ kind: 'spec',
863
+ source:
864
+ 'Eccentrically loaded bolt groups, the elastic method: ' +
865
+ 'https://steelcalculator.pages.dev/reference/bolt-group-capacity/ (read 2026-11-15)',
866
+ },
867
+ {
868
+ name: 'the elastic method, in tension',
869
+ value: 'a plane of tension through the centroid',
870
+ kind: 'estimate',
871
+ source:
872
+ "No source read: a moment shared as the shear is, each screw's pull growing with its distance from " +
873
+ 'the centroid, which holds while the clamped parts stay pressed together. A joint that opens tips ' +
874
+ 'about its edge and loads its far screws more',
875
+ },
876
+ ],
877
+ };
320
878
  }
321
879
 
322
880
  /**
@@ -324,43 +882,154 @@ export function screwGroup(places, o = {}) {
324
882
  * internal thread strips, and the clamped parts slip, at its preload. The screw takes its preload and the whole pull
325
883
  * on it (a printed part is far softer than a steel screw, so little of the pull goes into easing the clamp), with
326
884
  * its shear, against its proof load; the thread takes the same pull and preload against its stripping load; the clamp
327
- * is eased by the whole pull for slipping, the safe side each time. With no torque given, the preload is the most that
328
- * leaves the thread twice the pull, within the seat and three quarters of the proof load, and the torque for it is said.
329
- * @param {Fixing | string} m @param {{ tension?: number, shear?: number, depth?: number, material?: string | object, end?: string, torque?: number, most?: number, K?: number, friction?: number, screw?: 'steel' | 'stainless', proof?: number, sets?: object }} o
885
+ * is eased by the whole pull for slipping, the safe side each time. The thread's margin is its stripping load over the
886
+ * preload and the pull together. With no torque given, the preload is the most that leaves the thread
887
+ * fixings.load_margin times the preload and the pull, within the seat's take over fixings.load_margin and three
888
+ * quarters of the proof load, and the torque for it is said: a stripping load is an estimate, and the clamp a torque
889
+ * gives scatters by a quarter to a third, so the preload is held to at most half the stripping load.
890
+ * @param {Fixing | string} m @param {{ tension?: number, shear?: number, depth?: number, material?: string | object,
891
+ * end?: string, torque?: number, most?: number, K?: number, friction?: number, screw?: 'steel' | 'stainless', proof?:
892
+ * number, sets?: object }} o
330
893
  * tension, shear: the screw's share, in N; depth and material: the thread engaged and what it is in (a pilot, tap or
331
894
  * printed thread), or end: 'insert' or 'nut' where the thread is metal; torque: the tightening torque given, N·m;
332
- * most: the most clamp force the seat under the head takes, N; friction: between the clamped parts (default fixings.clamp_friction)
333
- * @returns {{ thread: string, tension: number, shear: number, preload: { force: number, torque: number, given: boolean }, proof: number, strip: number | null,
334
- * margins: { screw: number, thread: number | null, slip: number | null }, margin: number, governs: string, rests: object[], findings: object[] }}
335
- * margins: how many times the load each holds (null: not checked); margin: the least of the screw's and the thread's
895
+ * most: the most clamp force the seat under the head takes, N; friction: between the clamped parts (default
896
+ * fixings.clamp_friction)
897
+ * @returns {{ thread: string, tension: number, shear: number, preload: { force: number, torque: number,
898
+ * given: boolean }, proof: number, strip: number | null,
899
+ * margins: { screw: number, thread: number | null, slip: number | null }, margin: number, governs: string, rests:
900
+ * object[], findings: object[] }} margins: how many times the load each holds, the thread's counting the preload with
901
+ * the pull (null: not checked); margin: the least of the screw's and the thread's
336
902
  */
337
903
  export function screwLoad(m, o = {}) {
338
904
  const what = 'screwLoad';
339
- options(what, o, '{ tension: 20, depth: 5, material: \'pla\' }');
340
- const fx = notPrinted(what, fixingOf(what, m, o)), num = (k, v) => { if (v != null && !(isNum(v) && v >= 0)) throw new Error(`${what}: ${k} is a number of N, 0 or more (got ${shown(v)})`); return v ?? 0; };
341
- const T = Math.max(0, isNum(o.tension) ? o.tension : num('tension', o.tension)), S = num('shear', o.shear), mu = o.friction ?? DEFAULTS.clamp_friction.value;
905
+ options(what, o, "{ tension: 20, depth: 5, material: 'pla' }");
906
+ const fx = notPrinted(what, fixingOf(what, m, o)),
907
+ num = (k, v) => {
908
+ if (v != null && !(isNum(v) && v >= 0))
909
+ throw new Error(`${what}: ${k} is a number of N, 0 or more (got ${shown(v)})`);
910
+ return v ?? 0;
911
+ };
912
+ const T = Math.max(0, isNum(o.tension) ? o.tension : num('tension', o.tension)),
913
+ S = num('shear', o.shear),
914
+ mu = o.friction ?? DEFAULTS.clamp_friction.value;
342
915
  if (!(isNum(mu) && mu > 0)) throw new Error(`${what}: friction is a number above 0 (got ${shown(o.friction)})`);
343
916
  if (o.most != null) positive(what, 'most (the clamp force the seat takes, in N)', o.most);
344
- const threaded = o.material != null, st = threaded ? stripping(fx, { depth: o.depth, material: o.material, sets: o.sets, screw: o.screw, proof: o.proof }) : null;
917
+ const threaded = o.material != null,
918
+ st = threaded
919
+ ? stripping(fx, { depth: o.depth, material: o.material, sets: o.sets, screw: o.screw, proof: o.proof })
920
+ : null;
345
921
  if (!threaded && o.end != null) oneOf(what, 'end', o.end, ['insert', 'nut']);
346
- const pr0 = preload(fx, { force: 1, K: o.K, screw: o.screw, proof: o.proof, sets: o.sets }), P = pr0.proof, K = pr0.K, d = fx.major, want = DEFAULTS.load_margin.value;
922
+ const pr0 = preload(fx, { force: 1, K: o.K, screw: o.screw, proof: o.proof, sets: o.sets }),
923
+ P = pr0.proof,
924
+ K = pr0.K,
925
+ d = fx.major,
926
+ want = DEFAULTS.load_margin.value;
347
927
  let pre;
348
- if (o.torque != null) { const p = preload(fx, { torque: positive(what, 'torque (in N·m)', o.torque), K: o.K, screw: o.screw, proof: o.proof, sets: o.sets }); pre = { force: p.force, torque: p.torque, given: true }; }
349
- else {
350
- const F = Math.max(0, Math.min(o.most ?? Infinity, DEFAULTS.preload_share.value * P, st ? st.strip - want * T : Infinity)), t = Math.floor((K * d * F) / 1000 * 100 + 1e-9) / 100;
928
+ if (o.torque != null) {
929
+ const p = preload(fx, {
930
+ torque: positive(what, 'torque (in N·m)', o.torque),
931
+ K: o.K,
932
+ screw: o.screw,
933
+ proof: o.proof,
934
+ sets: o.sets,
935
+ });
936
+ pre = { force: p.force, torque: p.torque, given: true };
937
+ } else {
938
+ const F = Math.max(
939
+ 0,
940
+ Math.min((o.most ?? Infinity) / want, DEFAULTS.preload_share.value * P, st ? st.strip / want - T : Infinity),
941
+ ),
942
+ // (the thread left want times the preload and the pull: at most half its stripping load; the torque rounded down)
943
+ t = Math.floor(((K * d * F) / 1000) * 100 + 1e-9) / 100;
351
944
  pre = { force: n1((t * 1000) / (K * d)), torque: t, given: false };
352
945
  }
353
- const Fp = pre.force, a2 = T * T + 3 * S * S, b2 = 2 * Fp * T, c2 = Fp * Fp - P * P;
946
+ const Fp = pre.force,
947
+ a2 = T * T + 3 * S * S,
948
+ b2 = 2 * Fp * T,
949
+ c2 = Fp * Fp - P * P;
354
950
  const screwK = Fp >= P ? 0 : a2 > 0 ? (-b2 + Math.sqrt(b2 * b2 - 4 * a2 * c2)) / (2 * a2) : Infinity;
355
- const threadK = !st ? null : Fp >= st.strip ? 0 : T > 0 ? (st.strip - Fp) / T : Infinity, slipK = S > 0 ? (mu * Fp) / (S + mu * T) : null;
356
- const margin = Math.min(screwK, threadK ?? Infinity), governs = threadK != null && threadK <= screwK ? 'thread' : 'screw', k2 = (x) => (x === Infinity ? 'any number of' : mm(n2(x)));
357
- const level = margin < 1 ? 'fail' : margin < want ? 'warn' : 'pass', load = `${mm(n1(T))} N of pull and ${mm(n1(S))} N of shear`;
358
- const clamp = `clamped with ${mm(Fp)} N (${mm(pre.torque)} N·m${pre.given ? '' : ', the torque to tighten to'}, T = K d F with K = ${mm(K)}${o.K == null ? ', an estimate' : ''})`;
359
- const threadSays = st ? `its thread in ${st.material} strips at about ${mm(st.strip)} N (an estimate: ${st.shear} MPa in shear), ${Fp >= st.strip ? 'under the preload alone' : `${k2(threadK)} times this pull over the preload`}`
360
- : o.end === 'insert' ? 'its thread is in a brass insert, whose hold in the plastic is its maker\'s figure and not checked here' : o.end === 'nut' ? 'its thread is in a steel nut, not checked here: the screw\'s proof load stands for it' : 'nothing says what its thread is in, so the thread is not checked';
361
- const out = [finding(level, `${a(fx.thread)} screw with ${load}, ${clamp}: ${threadSays}; the screw yields at ${k2(screwK)} times it (proof load ${mm(P)} N). ${margin === Infinity ? 'Nothing pulls on it' : `It holds ${k2(margin)} times the load, the ${governs} first`}${level === 'pass' ? '' : `, where the kit asks ${want} times`}`,
362
- 'screwLoad.margin', { values: { tension: n1(T), shear: n1(S), preload: Fp, torque: pre.torque, proof: P, strip: st?.strip ?? null, screw: screwK === Infinity ? null : n2(screwK), thread: threadK == null || threadK === Infinity ? null : n2(threadK), margin: margin === Infinity ? null : n2(margin) } })];
363
- if (slipK != null) out.push(finding(slipK >= want ? 'pass' : 'warn', `the clamp of ${mm(Fp)} N, eased by the pull, holds the ${mm(n1(S))} N of shear by friction ${mm(n2(slipK))} times over (fixings.clamp_friction ${mm(mu)}, an estimate)${slipK >= want ? '' : `: under ${want} times the parts may slip until the screw bears on its hole`}`, 'screwLoad.slip', { values: { slip: n2(slipK), friction: mu } }));
364
- return { thread: fx.thread, tension: n1(T), shear: n1(S), preload: pre, proof: P, strip: st?.strip ?? null, margins: { screw: screwK === Infinity ? Infinity : n2(screwK), thread: threadK == null ? null : threadK === Infinity ? Infinity : n2(threadK), slip: slipK == null ? null : n2(slipK) }, margin: margin === Infinity ? Infinity : n2(margin), governs,
365
- rests: [...(st ? st.rests : []), ...pr0.rests, ...(slipK != null && o.friction == null ? [rest('fixings.clamp_friction', DEFAULTS.clamp_friction)] : []), rest('fixings.load_margin', DEFAULTS.load_margin)], findings: out };
951
+ const threadK = !st ? null : Fp + T > 0 ? st.strip / (Fp + T) : Infinity,
952
+ slipK = S > 0 ? (mu * Fp) / (S + mu * T) : null;
953
+ const margin = Math.min(screwK, threadK ?? Infinity),
954
+ governs = threadK != null && threadK <= screwK ? 'thread' : 'screw',
955
+ k2 = (x) => (x === Infinity ? 'any number of' : mm(n2(x)));
956
+ const level = margin < 1 ? 'fail' : margin < want ? 'warn' : 'pass',
957
+ load = `${mm(n1(T))} N of pull and ${mm(n1(S))} N of shear`;
958
+ const clamp =
959
+ `clamped with ${mm(Fp)} N (${mm(pre.torque)} N·m` +
960
+ (pre.given ? '' : ', the torque to tighten to') +
961
+ `, T = K d F with K = ${mm(K)}${o.K == null ? ', an estimate' : ''}; the clamp a torque gives scatters by ` +
962
+ `a quarter to a third` +
963
+ (pre.given || !st
964
+ ? ''
965
+ : ", so the preload is held to at most the thread's stripping load over fixings.load_margin") +
966
+ `)`;
967
+ const threadSays = st
968
+ ? `its thread in ${st.material} strips at about ${mm(st.strip)} N (an estimate: ${st.shear} MPa in shear), ` +
969
+ (Fp >= st.strip ? 'under the preload alone' : `${k2(threadK)} times the preload and this pull together`)
970
+ : o.end === 'insert'
971
+ ? "its thread is in a brass insert, whose hold in the plastic is its maker's figure and not checked here"
972
+ : o.end === 'nut'
973
+ ? "its thread is in a steel nut, not checked here: the screw's proof load stands for it"
974
+ : 'nothing says what its thread is in, so the thread is not checked';
975
+ const out = [
976
+ finding(
977
+ level,
978
+ `${a(fx.thread)} screw with ${load}, ${clamp}: ${threadSays}; the screw yields at ${k2(screwK)} times ` +
979
+ `it (proof load ${mm(P)} N). ` +
980
+ (margin === Infinity
981
+ ? 'Nothing pulls on it'
982
+ : `It holds ${k2(margin)} times ` +
983
+ (governs === 'thread' ? 'the preload and the load' : 'the load') +
984
+ `, the ${governs} first`) +
985
+ (level === 'pass' ? '' : `, where the kit asks ${want} times`),
986
+ 'screwLoad.margin',
987
+ {
988
+ values: {
989
+ tension: n1(T),
990
+ shear: n1(S),
991
+ preload: Fp,
992
+ torque: pre.torque,
993
+ proof: P,
994
+ strip: st?.strip ?? null,
995
+ screw: screwK === Infinity ? null : n2(screwK),
996
+ thread: threadK == null || threadK === Infinity ? null : n2(threadK),
997
+ margin: margin === Infinity ? null : n2(margin),
998
+ },
999
+ },
1000
+ ),
1001
+ ];
1002
+ if (slipK != null)
1003
+ out.push(
1004
+ finding(
1005
+ slipK >= want ? 'pass' : 'warn',
1006
+ `the clamp of ${mm(Fp)} N, eased by the pull, holds the ${mm(n1(S))} N of shear by friction ` +
1007
+ `${mm(n2(slipK))} times over (fixings.clamp_friction ${mm(mu)}, an estimate)` +
1008
+ (slipK >= want ? '' : `: under ${want} times the parts may slip until the screw bears on its hole`),
1009
+ 'screwLoad.slip',
1010
+ { values: { slip: n2(slipK), friction: mu } },
1011
+ ),
1012
+ );
1013
+ return {
1014
+ thread: fx.thread,
1015
+ tension: n1(T),
1016
+ shear: n1(S),
1017
+ preload: pre,
1018
+ proof: P,
1019
+ strip: st?.strip ?? null,
1020
+ margins: {
1021
+ screw: screwK === Infinity ? Infinity : n2(screwK),
1022
+ thread: threadK == null ? null : threadK === Infinity ? Infinity : n2(threadK),
1023
+ slip: slipK == null ? null : n2(slipK),
1024
+ },
1025
+ margin: margin === Infinity ? Infinity : n2(margin),
1026
+ governs,
1027
+ rests: [
1028
+ ...(st ? st.rests : []),
1029
+ ...pr0.rests,
1030
+ ...(slipK != null && o.friction == null ? [rest('fixings.clamp_friction', DEFAULTS.clamp_friction)] : []),
1031
+ rest('fixings.load_margin', DEFAULTS.load_margin),
1032
+ ],
1033
+ findings: out,
1034
+ };
366
1035
  }