@rulecad/fixings 0.1.3 → 0.1.5

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
@@ -26,7 +26,7 @@ const options = (what, o, example) => { if (o == null || typeof o !== 'object' |
26
26
 
27
27
  // A material from what a function was handed: a kit set's name ('PLA'), the workspace's set of that name (sets), or a
28
28
  // rule set itself. Its class is told by its stiffness: under 20 GPa a plastic, under 100 GPa an aluminium, else a steel.
29
- function materialOf(what, material, sets) {
29
+ export function materialOf(what, material, sets) {
30
30
  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 })`);
31
31
  let set = null;
32
32
  if (typeof material === 'object' && material.rules && typeof material.rules === 'object') set = material;
@@ -36,10 +36,10 @@ function materialOf(what, material, sets) {
36
36
  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`);
37
37
  } else throw new Error(`${what}: material is a material's name (${MATERIALS.join(', ')}) or its rule set ({ name, rules }), not ${shown(material)}`);
38
38
  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; };
39
- const strength = num('strength'), across = num('strength_z'), modulus = num('modulus');
39
+ const strength = num('strength'), across = num('strength_z'), modulus = num('modulus'), density = num('density'), poisson = num('poisson');
40
40
  if (!strength) throw new Error(`${what}: ${name} has no strength in its rule set: a tensile or yield strength in MPa is needed`);
41
41
  if (!modulus) throw new Error(`${what}: ${name} has no modulus in its rule set, which tells a plastic from a metal`);
42
- return { name, cls: modulus.value < 20000 ? 'plastic' : modulus.value < 100000 ? 'aluminium' : 'steel', strength, across, modulus };
42
+ return { name, cls: modulus.value < 20000 ? 'plastic' : modulus.value < 100000 ? 'aluminium' : 'steel', strength, across, modulus, density, poisson };
43
43
  }
44
44
  // The class of material an engagement rule is read by: a class by name, or a material's
45
45
  function classOf(what, material, sets) {
@@ -48,14 +48,21 @@ function classOf(what, material, sets) {
48
48
  return materialOf(what, material, sets);
49
49
  }
50
50
  // The weaker of a printed material's two strengths, with what it says about itself
51
- function weakest(mat) {
51
+ export function weakest(mat) {
52
52
  const f = mat.across && mat.across.value < mat.strength.value ? mat.across : mat.strength;
53
53
  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)`;
54
54
  return { f, note };
55
55
  }
56
56
 
57
57
  // A screw's own strength: its tensile stress area, and its proof load from its property class
58
+ // A printed bolt (a screw named with the word printed) is refused by name: it has no property class, so no proof load,
59
+ // preload or torque. A printed nut is let through: the screw in it is a bought one
60
+ function notPrinted(what, fx) {
61
+ 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' : ''}`);
62
+ return fx;
63
+ }
58
64
  function proofOf(what, fx, o) {
65
+ notPrinted(what, fx);
59
66
  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`);
60
67
  const kind = oneOf(what, 'screw', o.screw ?? 'steel', ['steel', 'stainless']), name = kind === 'steel' ? 'proof_stress' : 'stainless_proof_stress';
61
68
  if (o.proof != null) positive(what, 'proof (the screw\'s proof stress, in MPa)', o.proof);
@@ -141,6 +148,7 @@ export function preload(m, o = {}) {
141
148
  export function torqueFor(m, o = {}) {
142
149
  options('torqueFor', o, '{ force: 500 }');
143
150
  if (o.torque != null) throw new Error('torqueFor: give force (N), the clamp force wanted: for the force a torque gives, use preload');
151
+ notPrinted('torqueFor', fixingOf('torqueFor', m, o));
144
152
  return preload(m, o);
145
153
  }
146
154
 
@@ -163,7 +171,7 @@ export function seating(m, o = {}) {
163
171
  if (form === 'set') throw new Error(`${what}: a set screw has no head to bear on anything: it presses with its point`);
164
172
  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 });
165
173
  if (o.force != null && o.torque != null) throw new Error(`${what}: give force (N) or torque (N·m), not both`);
166
- const K = o.K ?? DEFAULTS.nut_factor.value, screw = proofOf(what, fx, o), given = o.force != null || o.torque != null;
174
+ 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)
167
175
  if (!(isNum(K) && K > 0)) throw new Error(`${what}: K is the nut factor, a number above 0 (got ${shown(o.K)})`);
168
176
  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;
169
177
  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;
@@ -241,10 +249,10 @@ export function lengthFor(stack, m, o = {}) {
241
249
  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)); }
242
250
  const total = parts.reduce((s, t) => s + t, 0), grip = r3(total + washer - (o.sunk ?? 0));
243
251
  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`);
244
- const sold = fx.figures.lengths?.value;
252
+ const sold = fx.printed ? Array.from({ length: 300 }, (_, i) => i + 1) : fx.figures.lengths?.value; // (a printed screw is printed to any whole millimetre)
245
253
  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'}`);
246
- rests.push(rest(cite(fx, 'lengths'), fx.figures.lengths));
247
- 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);
254
+ if (!fx.printed) rests.push(rest(cite(fx, 'lengths'), fx.figures.lengths));
255
+ 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' : ''}`;
248
256
  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');
249
257
  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`);
250
258
  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})`;
@@ -280,7 +288,7 @@ const crossed = (p, q) => [p[1] * q[2] - p[2] * q[1], p[2] * q[0] - p[0] * q[2],
280
288
  * @returns {{ count: number, centroid: number[], polar: number, line: boolean, screws: { at: number[], shear: number, tension: number, across: number[] }[], turns: number | null, rests: object[] }}
281
289
  * polar: the sum of the squared distances from the centroid, mm²; screws: each one's shear (N, across the joint) and
282
290
  * tension (N, along it: under 0, the load presses that screw's parts together); turns: a twist one screw alone
283
- * cannot hold by shear, in N·m (it holds by friction only)
291
+ * cannot hold by shear, in N·m (it holds by friction only), null when it rounds to 0 at the thousandth
284
292
  */
285
293
  export function screwGroup(places, o = {}) {
286
294
  const what = 'screwGroup';
@@ -302,7 +310,8 @@ export function screwGroup(places, o = {}) {
302
310
  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));
303
311
  }
304
312
  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)
305
- return { count: n, centroid: [r3(c[0]), r3(c[1])], polar: r3(polar), line, screws, turns: polar > 1e-9 || Math.abs(M[2]) < 1e-9 ? null : r3(Math.abs(M[2]) / 1000),
313
+ const twist = r3(Math.abs(M[2]) / 1000); // N·m, as said: a twist that rounds to nothing is none
314
+ return { count: n, centroid: [r3(c[0]), r3(c[1])], polar: r3(polar), line, screws, turns: polar > 1e-9 || !twist ? null : twist,
306
315
  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)' },
307
316
  { 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' }] };
308
317
  }
@@ -325,7 +334,7 @@ export function screwGroup(places, o = {}) {
325
334
  export function screwLoad(m, o = {}) {
326
335
  const what = 'screwLoad';
327
336
  options(what, o, '{ tension: 20, depth: 5, material: \'pla\' }');
328
- const fx = 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; };
337
+ 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; };
329
338
  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;
330
339
  if (!(isNum(mu) && mu > 0)) throw new Error(`${what}: friction is a number above 0 (got ${shown(o.friction)})`);
331
340
  if (o.most != null) positive(what, 'most (the clamp force the seat takes, in N)', o.most);