@rulecad/fixings 0.1.9 → 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/CHANGELOG.md CHANGED
@@ -4,6 +4,36 @@ What changed in each release, for someone upgrading a workspace. A **printed siz
4
4
  print (a hole's diameter, a seat's depth, a part's outline). Each release says whether any printed size moved, and
5
5
  why.
6
6
 
7
+ ## 0.2.0: a boss diameter for threads formed in plastic; an unused figure removed; the long findings and comments are written in short lines; needs Node 22.13 or later, the version the kit is tested on
8
+
9
+ ### Added
10
+
11
+ - `DEFAULTS.boss_diameter`: plastic a screw forms or cuts its own thread in stands at least twice the screw's
12
+ diameter across round the hole, a community figure from TR Fastenings' guide for thread-forming screws. `cad check`
13
+ holds a pilot's, a tapped or a printed thread's wall to it (`fasten.wall`).
14
+
15
+ Upgrading: nothing changes in what this package draws or returns, besides the new figure. No printed size moves.
16
+
17
+ ### Changed
18
+
19
+ - A constant the code never read is gone. No printed size moves, and nothing a design or a check does changes.
20
+
21
+ - No line of the package's code runs past 120 columns any more: each long finding, error message and comment is
22
+ written in pieces of a line or so, joined, and a long pattern is built from two. Every finding, every message and
23
+ every figure is word for word as before; nothing the package draws or works out has changed.
24
+
25
+ Upgrading: nothing to do. cad keys its cached builds on the code of the packages a design uses, so a design that uses
26
+ fixings is built afresh once, with the same results. No printed size moves.
27
+
28
+ - @rulecad/fixings now states Node 22.13 or later in its `engines`, the same lowest Node as every rulecad package, and
29
+ the tests run on exactly Node 22.13.0 as well as the newest Node 24. Node 20 reached the end of its support on 30
30
+ April 2026, and the kit's packages stated five different lowest versions, some of them too low: on Node 20.6 to 20.9
31
+ `cad` stopped at start-up with "Unexpected token 'with'", and on Node 22.0 to 22.12 every `cad` command that runs a
32
+ design stops, because the sandbox designs run in cannot start there. npm gave no warning at install for either.
33
+
34
+ Upgrading: on a Node older than 22.13, npm now warns at install that this package needs Node 22.13; install Node 22.13
35
+ or later (24 recommended). Nothing else changes, and no printed size moves.
36
+
7
37
  ## 0.1.9: screwLoad's torque to tighten to keeps a plastic thread to half its stripping load
8
38
 
9
39
  ### Fixed
package/bolts.d.mts CHANGED
@@ -1,23 +1,28 @@
1
1
  /**
2
- * @typedef {{ kind: 'printed-bolt', name: string, thread: string, head: string, length: number, nut: 'printed' | 'steel', axis: 'x' | 'y' | 'z', material: string,
3
- * root: number, rootArea: number, engaged: number, tension: { strength: number, load: number, rule: string }, strip: { area: number, shear: number, load: number, nutArea: number | null },
4
- * headShear: number | null, breaking: number, governs: 'tension' | 'strip' | 'head', load: number | null, margin: number | null, grams: number, threaded: object, rests: object[], findings: object[] }} PrintedBolt
5
- * root: the bolt's root diameter as drawn, mm; rootArea: its section there (less its flat, lying), mm²; engaged: thread in the nut, mm;
6
- * tension: the plastic's strength the root is pulled at (across its layers standing, along them lying) and the load it breaks at, N;
7
- * strip: the shear area of the bolt's teeth in the nut (and of a printed nut's own), the shear strength and the load they shear at;
8
- * headShear: the load that shears the head off the shank; breaking: the least of the three, N, governs: which
2
+ * @typedef {{ kind: 'printed-bolt', name: string, thread: string, head: string, length: number,
3
+ * nut: 'printed' | 'steel', axis: 'x' | 'y' | 'z', material: string,
4
+ * root: number, rootArea: number, engaged: number, tension: { strength: number, load: number, rule: string }, strip:
5
+ * { area: number, shear: number, load: number, nutArea: number | null }, headShear: number | null, breaking: number,
6
+ * governs: 'tension' | 'strip' | 'head', load: number | null, margin: number | null, grams: number, threaded: object,
7
+ * rests: object[], findings: object[] }} PrintedBolt root: the bolt's root diameter as drawn, mm; rootArea: its
8
+ * section there (less its flat, lying), mm²; engaged: thread in the nut, mm; tension: the plastic's strength the root
9
+ * is pulled at (across its layers standing, along them lying) and the load it breaks at, N; strip: the shear area of
10
+ * the bolt's teeth in the nut (and of a printed nut's own), the shear strength and the load they shear at; headShear:
11
+ * the load that shears the head off the shank; breaking: the least of the three, N, governs: which
9
12
  */
10
13
  /**
11
14
  * A printed bolt's strength: the load along it that breaks it, from the plastic's strength by how it prints, and that
12
15
  * load against the one it carries. Standing on its head (axis z, the way it prints with no support), the pull goes
13
16
  * across its layers; lying on a flat (axis x or y), along them.
14
- * @param {string | object} m a screw's name or model ('M8x20 hex printed', or 'M8x20 hex'), or a thread with { length, head }
15
- * @param {{ material?: string | object, printer?: object, nut?: 'printed' | 'steel', depth?: number, axis?: 'x' | 'y' | 'z', load?: number, length?: number, head?: string,
17
+ * @param {string | object} m a screw's name or model ('M8x20 hex printed', or 'M8x20 hex'), or a thread with
18
+ * { length, head }
19
+ * @param {{ material?: string | object, printer?: object, nut?: 'printed' | 'steel', depth?: number,
20
+ * axis?: 'x' | 'y' | 'z', load?: number, length?: number, head?: string,
16
21
  * gap?: number, sets?: object }} [o]
17
22
  * material: the plastic (default PLA); nut: printed (a printed nut or a thread printed in the part, the default) or
18
- * steel (a standard thread: a bought nut, a heat-set insert or a tapped hole); depth: thread engaged in the nut, mm (default the thread's hex nut height); axis: how it
19
- * prints, z standing on its head (the default), or x or y lying on a flat; load: the pull along it, N, held to
20
- * fixings.load_margin; gap: in place of the printer's thread_gap
23
+ * steel (a standard thread: a bought nut, a heat-set insert or a tapped hole); depth: thread engaged in the nut, mm
24
+ * (default the thread's hex nut height); axis: how it prints, z standing on its head (the default), or x or y lying
25
+ * on a flat; load: the pull along it, N, held to fixings.load_margin; gap: in place of the printer's thread_gap
21
26
  * @returns {PrintedBolt}
22
27
  */
23
28
  export function printedBoltModel(m: string | object, o?: {
@@ -35,20 +40,23 @@ export function printedBoltModel(m: string | object, o?: {
35
40
  /**
36
41
  * A printed bolt's solid: the screw with its thread drawn (screw's display: 'thread'), turned over to stand on its head
37
42
  * as it prints: the head's top on the bed at z = 0, its tip up.
38
- * @param {string | object} m as printedBoltModel @param {object} [o] as printedBoltModel @param {{ union: Function, subtract: Function }} [ops]
43
+ * @param {string | object} m as printedBoltModel @param {object} [o] as
44
+ * printedBoltModel @param {{ union: Function, subtract: Function }} [ops]
39
45
  * @returns {object} a JSCAD geom3 with .model holding printedBoltModel's numbers
40
46
  */
41
47
  export function printedBolt(m: string | object, o?: object, ops?: {
42
48
  union: Function;
43
49
  subtract: Function;
44
50
  }): object;
45
- /** What a printed bolt can go in: a printed nut or a thread printed in the part (half the gap each), or a standard thread, 'steel': a bought nut, a heat-set insert or a tapped hole (the bolt takes the whole gap). */
51
+ /** What a printed bolt can go in: a printed nut or a thread printed in the part (half the gap each), or a standard
52
+ * thread, 'steel': a bought nut, a heat-set insert or a tapped hole (the bolt takes the whole gap). */
46
53
  export const BOLT_NUTS: string[];
47
54
  /**
48
- * root: the bolt's root diameter as drawn, mm; rootArea: its section there (less its flat, lying), mm²; engaged: thread in the nut, mm;
49
- * tension: the plastic's strength the root is pulled at (across its layers standing, along them lying) and the load it breaks at, N;
50
- * strip: the shear area of the bolt's teeth in the nut (and of a printed nut's own), the shear strength and the load they shear at;
51
- * headShear: the load that shears the head off the shank; breaking: the least of the three, N, governs: which
55
+ * root: the bolt's root diameter as drawn, mm; rootArea: its
56
+ * section there (less its flat, lying), mm²; engaged: thread in the nut, mm; tension: the plastic's strength the root
57
+ * is pulled at (across its layers standing, along them lying) and the load it breaks at, N; strip: the shear area of
58
+ * the bolt's teeth in the nut (and of a printed nut's own), the shear strength and the load they shear at; headShear:
59
+ * the load that shears the head off the shank; breaking: the least of the three, N, governs: which
52
60
  */
53
61
  export type PrintedBolt = {
54
62
  kind: "printed-bolt";
package/bolts.mjs CHANGED
@@ -13,94 +13,246 @@ import { screwModel, screw } from './hardware.mjs';
13
13
 
14
14
  const { translate, rotateX } = jscad.transforms;
15
15
 
16
- const an = (w) => `${/^[aeiou]/i.test(w) ? 'an' : 'a'} ${w}`; // (a plain word's article: model's a() is for thread names)
17
- const n1 = (x) => +x.toFixed(1), n2 = (x) => +x.toFixed(2);
18
- /** What a printed bolt can go in: a printed nut or a thread printed in the part (half the gap each), or a standard thread, 'steel': a bought nut, a heat-set insert or a tapped hole (the bolt takes the whole gap). */
16
+ // (a plain word's article: model's a() is for thread names)
17
+ const an = (w) => `${/^[aeiou]/i.test(w) ? 'an' : 'a'} ${w}`;
18
+ const n1 = (x) => +x.toFixed(1),
19
+ n2 = (x) => +x.toFixed(2);
20
+ /** What a printed bolt can go in: a printed nut or a thread printed in the part (half the gap each), or a standard
21
+ * thread, 'steel': a bought nut, a heat-set insert or a tapped hole (the bolt takes the whole gap). */
19
22
  export const BOLT_NUTS = ['printed', 'steel'];
20
23
 
21
- // The area of a circle of radius r less the segment past a chord f from its centre (a bolt lying on its side, on its flat)
22
- const segmentless = (r, f) => (f == null || f >= r ? Math.PI * r * r : Math.PI * r * r - (r * r * Math.acos(f / r) - f * Math.sqrt(r * r - f * f)));
24
+ // The area of a circle of radius r less the segment past a chord f from its centre (a bolt lying on its side, on its
25
+ // flat)
26
+ const segmentless = (r, f) =>
27
+ f == null || f >= r ? Math.PI * r * r : Math.PI * r * r - (r * r * Math.acos(f / r) - f * Math.sqrt(r * r - f * f));
23
28
 
24
29
  /**
25
- * @typedef {{ kind: 'printed-bolt', name: string, thread: string, head: string, length: number, nut: 'printed' | 'steel', axis: 'x' | 'y' | 'z', material: string,
26
- * root: number, rootArea: number, engaged: number, tension: { strength: number, load: number, rule: string }, strip: { area: number, shear: number, load: number, nutArea: number | null },
27
- * headShear: number | null, breaking: number, governs: 'tension' | 'strip' | 'head', load: number | null, margin: number | null, grams: number, threaded: object, rests: object[], findings: object[] }} PrintedBolt
28
- * root: the bolt's root diameter as drawn, mm; rootArea: its section there (less its flat, lying), mm²; engaged: thread in the nut, mm;
29
- * tension: the plastic's strength the root is pulled at (across its layers standing, along them lying) and the load it breaks at, N;
30
- * strip: the shear area of the bolt's teeth in the nut (and of a printed nut's own), the shear strength and the load they shear at;
31
- * headShear: the load that shears the head off the shank; breaking: the least of the three, N, governs: which
30
+ * @typedef {{ kind: 'printed-bolt', name: string, thread: string, head: string, length: number,
31
+ * nut: 'printed' | 'steel', axis: 'x' | 'y' | 'z', material: string,
32
+ * root: number, rootArea: number, engaged: number, tension: { strength: number, load: number, rule: string }, strip:
33
+ * { area: number, shear: number, load: number, nutArea: number | null }, headShear: number | null, breaking: number,
34
+ * governs: 'tension' | 'strip' | 'head', load: number | null, margin: number | null, grams: number, threaded: object,
35
+ * rests: object[], findings: object[] }} PrintedBolt root: the bolt's root diameter as drawn, mm; rootArea: its
36
+ * section there (less its flat, lying), mm²; engaged: thread in the nut, mm; tension: the plastic's strength the root
37
+ * is pulled at (across its layers standing, along them lying) and the load it breaks at, N; strip: the shear area of
38
+ * the bolt's teeth in the nut (and of a printed nut's own), the shear strength and the load they shear at; headShear:
39
+ * the load that shears the head off the shank; breaking: the least of the three, N, governs: which
32
40
  */
33
41
 
34
42
  /**
35
43
  * A printed bolt's strength: the load along it that breaks it, from the plastic's strength by how it prints, and that
36
44
  * load against the one it carries. Standing on its head (axis z, the way it prints with no support), the pull goes
37
45
  * across its layers; lying on a flat (axis x or y), along them.
38
- * @param {string | object} m a screw's name or model ('M8x20 hex printed', or 'M8x20 hex'), or a thread with { length, head }
39
- * @param {{ material?: string | object, printer?: object, nut?: 'printed' | 'steel', depth?: number, axis?: 'x' | 'y' | 'z', load?: number, length?: number, head?: string,
46
+ * @param {string | object} m a screw's name or model ('M8x20 hex printed', or 'M8x20 hex'), or a thread with
47
+ * { length, head }
48
+ * @param {{ material?: string | object, printer?: object, nut?: 'printed' | 'steel', depth?: number,
49
+ * axis?: 'x' | 'y' | 'z', load?: number, length?: number, head?: string,
40
50
  * gap?: number, sets?: object }} [o]
41
51
  * material: the plastic (default PLA); nut: printed (a printed nut or a thread printed in the part, the default) or
42
- * steel (a standard thread: a bought nut, a heat-set insert or a tapped hole); depth: thread engaged in the nut, mm (default the thread's hex nut height); axis: how it
43
- * prints, z standing on its head (the default), or x or y lying on a flat; load: the pull along it, N, held to
44
- * fixings.load_margin; gap: in place of the printer's thread_gap
52
+ * steel (a standard thread: a bought nut, a heat-set insert or a tapped hole); depth: thread engaged in the nut, mm
53
+ * (default the thread's hex nut height); axis: how it prints, z standing on its head (the default), or x or y lying
54
+ * on a flat; load: the pull along it, N, held to fixings.load_margin; gap: in place of the printer's thread_gap
45
55
  * @returns {PrintedBolt}
46
56
  */
47
57
  export function printedBoltModel(m, o = {}) {
48
58
  const what = 'printedBoltModel';
49
- optionsOf(what, o, '{ material: \'pla\', load: 100 }');
59
+ optionsOf(what, o, "{ material: 'pla', load: 100 }");
50
60
  const fx = fixingOf(what, m, { ...o, anyLength: true });
51
- if (!['screw', 'thread'].includes(fx.item)) throw new Error(`${what}: ${fx.name} is ${an(fx.item)}, not a bolt: name a screw ('${fx.thread}x20 hex printed')`);
52
- const nut = oneOf(what, 'nut', o.nut ?? 'printed', BOLT_NUTS), axis = oneOf(what, 'axis', o.axis ?? 'z', ['x', 'y', 'z']), mat = materialOf(what, o.material ?? 'pla', o.sets);
53
- if (mat.cls !== 'plastic') throw new Error(`${what}: ${mat.name} is ${an(mat.cls)}, not a plastic: a printed bolt is printed in a plastic (pla, petg, or a plastic's rule set)`);
54
- const form = o.head ?? fx.head?.form ?? (fx.made.heads.includes('hex') ? 'hex' : fx.made.heads[0]), sc = screwModel(fx, { length: o.length ?? fx.length ?? undefined, head: form, anyLength: true, ...(fx.printed ? { material: o.material ?? 'pla', sets: o.sets } : {}) }); // (a printed name is weighed in its plastic by screwModel)
55
- const out = [], rests = [];
56
- // Its thread, as it prints: refused where the printer cannot resolve the pitch, naming the smallest thread that prints
57
- const shank = r3(sc.length - sc.sink), t = threadModel(fx, { what, length: shank, printer: o.printer, sets: o.sets, mate: nut === 'printed' ? 'printed' : 'bought', gap: o.gap, top: '-z', axis, flat: axis !== 'z' ? true : undefined });
58
- rests.push(...t.rests); out.push(...t.findings.filter((f) => f.code !== 'thread.overlap'));
59
- const depth = o.depth != null ? positive(what, 'depth (thread engaged in the nut)', o.depth) : nutOf(what, fx, 'hex').height;
61
+ if (!['screw', 'thread'].includes(fx.item))
62
+ throw new Error(`${what}: ${fx.name} is ${an(fx.item)}, not a bolt: name a screw ('${fx.thread}x20 hex printed')`);
63
+ const nut = oneOf(what, 'nut', o.nut ?? 'printed', BOLT_NUTS),
64
+ axis = oneOf(what, 'axis', o.axis ?? 'z', ['x', 'y', 'z']),
65
+ mat = materialOf(what, o.material ?? 'pla', o.sets);
66
+ if (mat.cls !== 'plastic')
67
+ throw new Error(
68
+ `${what}: ${mat.name} is ${an(mat.cls)}, not a plastic: a printed bolt is printed in a plastic (pla, ` +
69
+ `petg, or a plastic's rule set)`,
70
+ );
71
+ const form = o.head ?? fx.head?.form ?? (fx.made.heads.includes('hex') ? 'hex' : fx.made.heads[0]),
72
+ sc = screwModel(fx, {
73
+ length: o.length ?? fx.length ?? undefined,
74
+ head: form,
75
+ anyLength: true,
76
+ ...(fx.printed ? { material: o.material ?? 'pla', sets: o.sets } : {}),
77
+ }); // (a printed name is weighed in its plastic by screwModel)
78
+ const out = [],
79
+ rests = [];
80
+ // Its thread, as it prints: refused where the printer cannot resolve the pitch, naming the smallest thread that
81
+ // prints
82
+ const shank = r3(sc.length - sc.sink),
83
+ t = threadModel(fx, {
84
+ what,
85
+ length: shank,
86
+ printer: o.printer,
87
+ sets: o.sets,
88
+ mate: nut === 'printed' ? 'printed' : 'bought',
89
+ gap: o.gap,
90
+ top: '-z',
91
+ axis,
92
+ flat: axis !== 'z' ? true : undefined,
93
+ });
94
+ rests.push(...t.rests);
95
+ out.push(...t.findings.filter((f) => f.code !== 'thread.overlap'));
96
+ const depth =
97
+ o.depth != null ? positive(what, 'depth (thread engaged in the nut)', o.depth) : nutOf(what, fx, 'hex').height;
60
98
  if (o.depth == null) rests.push(rest(cite(fx, 'nut_height'), fx.figures.nut_height));
61
99
  // Tension across the root as drawn: standing, the pull goes across the layers; lying, along them
62
- const root = t.drawn.minor, rootArea = segmentless(root / 2, t.flat), w = weakest(mat), sTension = axis === 'z' ? w.f : mat.strength, tensionLoad = sTension.value * rootArea;
100
+ const root = t.drawn.minor,
101
+ rootArea = segmentless(root / 2, t.flat),
102
+ w = weakest(mat),
103
+ sTension = axis === 'z' ? w.f : mat.strength,
104
+ tensionLoad = sTension.value * rootArea;
63
105
  rests.push(rest(sTension.name, sTension));
64
- // The teeth in the nut, on the basic profile: the bolt's at the nut's minor diameter D1 = d - 1.0825 P, a tooth 0.75 P
65
- // wide there (the nut's crest flat is P/4); a printed nut's own at the bolt's major d, 0.875 P wide (the bolt's crest is P/8)
66
- const P = fx.pitch, d = fx.major, D1 = d - (5 / 8) * Math.sqrt(3) * P, ratio = DEFAULTS.shear_ratio.value, tau = w.f.value * ratio;
67
- const boltArea = 0.75 * Math.PI * D1 * depth, nutArea = nut === 'printed' ? 0.875 * Math.PI * d * depth : null, stripArea = Math.min(boltArea, nutArea ?? Infinity), stripLoad = tau * stripArea;
106
+ // The teeth in the nut, on the basic profile: the bolt's at the nut's minor diameter D1 = d - 1.0825 P, a tooth 0.75
107
+ // P wide there (the nut's crest flat is P/4); a printed nut's own at the bolt's major d, 0.875 P wide (the bolt's
108
+ // crest is P/8)
109
+ const P = fx.pitch,
110
+ d = fx.major,
111
+ D1 = d - (5 / 8) * Math.sqrt(3) * P,
112
+ ratio = DEFAULTS.shear_ratio.value,
113
+ tau = w.f.value * ratio;
114
+ const boltArea = 0.75 * Math.PI * D1 * depth,
115
+ nutArea = nut === 'printed' ? 0.875 * Math.PI * d * depth : null,
116
+ stripArea = Math.min(boltArea, nutArea ?? Infinity),
117
+ stripLoad = tau * stripArea;
68
118
  rests.push(rest(w.f.name, w.f), rest('fixings.shear_ratio', DEFAULTS.shear_ratio));
69
119
  // The head off its shank: a cylinder the bolt's diameter, the head's height tall, across the layers
70
120
  const headShear = form === 'set' ? null : tau * Math.PI * d * Math.max(sc.headHeight, 1e-9);
71
121
  const caps = { tension: tensionLoad, strip: stripLoad, ...(headShear != null ? { head: headShear } : {}) };
72
- const governs = /** @type {'tension' | 'strip' | 'head'} */ (Object.entries(caps).sort((x, y) => x[1] - y[1])[0][0]), breaking = caps[governs];
73
- const across = axis === 'z' ? `across its layers (it prints standing on its head)${w.note}` : 'along its layers (it prints lying on a flat)';
74
- out.push(finding('info', `${a(fx.thread)} printed bolt in ${mat.name} breaks at about ${mm(n1(breaking))} N, ${governs === 'tension' ? 'pulled apart across its root' : governs === 'strip' ? 'its teeth sheared off in the nut' : 'its head sheared off'}: its ${mm(root)} mm root, ${mm(n2(rootArea))} mm², pulled ${across} at ${sTension.name} ${mm(sTension.value)} MPa, ${mm(n1(tensionLoad))} N; ${mm(depth)} mm of thread in a ${nut} nut shears its ${nut === 'printed' ? 'weaker teeth' : 'teeth'} over ${mm(n2(stripArea))} mm² (0.75 π D1 Le${nut === 'printed' ? ', the nut\'s own 0.875 π d Le' : ''}) at ${mm(n2(tau))} MPa, ${mm(n1(stripLoad))} N${headShear != null ? `; its ${mm(sc.headHeight)} mm head shears off at ${mm(n1(headShear))} N` : ''}. Every strength is an estimate: test one that matters`,
75
- 'bolt.strength', { values: { breaking: n1(breaking), tension: n1(tensionLoad), strip: n1(stripLoad), head: headShear != null ? n1(headShear) : null, governs }, refs: { thread: fx.thread, material: mat.name, nut, axis, kind: 'estimate' } }));
76
- const load = o.load != null ? positive(what, 'load (the pull along the bolt, in N)', o.load) : null, want = DEFAULTS.load_margin.value;
122
+ const governs = /** @type {'tension' | 'strip' | 'head'} */ (Object.entries(caps).sort((x, y) => x[1] - y[1])[0][0]),
123
+ breaking = caps[governs];
124
+ const across =
125
+ axis === 'z'
126
+ ? `across its layers (it prints standing on its head)${w.note}`
127
+ : 'along its layers (it prints lying on a flat)';
128
+ out.push(
129
+ finding(
130
+ 'info',
131
+ `${a(fx.thread)} printed bolt in ${mat.name} breaks at about ${mm(n1(breaking))} N, ` +
132
+ (governs === 'tension'
133
+ ? 'pulled apart across its root'
134
+ : governs === 'strip'
135
+ ? 'its teeth sheared off in the nut'
136
+ : 'its head sheared off') +
137
+ `: its ${mm(root)} mm root, ${mm(n2(rootArea))} mm², pulled ${across} at ${sTension.name} ` +
138
+ `${mm(sTension.value)} MPa, ${mm(n1(tensionLoad))} N; ${mm(depth)} mm of thread in a ${nut} nut shears ` +
139
+ `its ` +
140
+ (nut === 'printed' ? 'weaker teeth' : 'teeth') +
141
+ ` over ${mm(n2(stripArea))} mm² (0.75 π D1 Le` +
142
+ (nut === 'printed' ? ", the nut's own 0.875 π d Le" : '') +
143
+ `) at ${mm(n2(tau))} MPa, ${mm(n1(stripLoad))} N` +
144
+ (headShear != null ? `; its ${mm(sc.headHeight)} mm head shears off at ${mm(n1(headShear))} N` : '') +
145
+ `. Every strength is an estimate: test one that matters`,
146
+ 'bolt.strength',
147
+ {
148
+ values: {
149
+ breaking: n1(breaking),
150
+ tension: n1(tensionLoad),
151
+ strip: n1(stripLoad),
152
+ head: headShear != null ? n1(headShear) : null,
153
+ governs,
154
+ },
155
+ refs: { thread: fx.thread, material: mat.name, nut, axis, kind: 'estimate' },
156
+ },
157
+ ),
158
+ );
159
+ const load = o.load != null ? positive(what, 'load (the pull along the bolt, in N)', o.load) : null,
160
+ want = DEFAULTS.load_margin.value;
77
161
  let margin = null;
78
162
  if (load != null) {
79
- margin = n2(breaking / load); rests.push(rest('fixings.load_margin', DEFAULTS.load_margin));
80
- out.push(finding(margin >= want ? 'pass' : margin >= 1 ? 'warn' : 'fail', `a pull of ${mm(load)} N on the printed bolt is held ${mm(margin)} times over${margin >= want ? '' : margin >= 1 ? `, under the ${mm(want)} times fixings.load_margin asks` : ': it breaks'} (${governs} first). Do it up by hand: a printed thread takes no wrench's torque`, 'bolt.load', { values: { load, margin, breaking: n1(breaking) } }));
163
+ margin = n2(breaking / load);
164
+ rests.push(rest('fixings.load_margin', DEFAULTS.load_margin));
165
+ out.push(
166
+ finding(
167
+ margin >= want ? 'pass' : margin >= 1 ? 'warn' : 'fail',
168
+ `a pull of ${mm(load)} N on the printed bolt is held ${mm(margin)} times over` +
169
+ (margin >= want
170
+ ? ''
171
+ : margin >= 1
172
+ ? `, under the ${mm(want)} times fixings.load_margin asks`
173
+ : ': it breaks') +
174
+ ` (${governs} first). Do it up by hand: a printed thread takes no wrench's torque`,
175
+ 'bolt.load',
176
+ { values: { load, margin, breaking: n1(breaking) } },
177
+ ),
178
+ );
81
179
  }
82
- if (nut === 'steel') out.push(finding('info', `in a standard thread (a bought steel nut, a heat-set insert or a tapped hole), the printed bolt takes the whole of the thread's gap and the nut's teeth hold: the bolt's teeth shear first`, 'bolt.nut', { values: { nut } }));
180
+ if (nut === 'steel')
181
+ out.push(
182
+ finding(
183
+ 'info',
184
+ `in a standard thread (a bought steel nut, a heat-set insert or a tapped hole), the printed bolt ` +
185
+ `takes the whole of the thread's gap and the nut's teeth hold: the bolt's teeth shear first`,
186
+ 'bolt.nut',
187
+ { values: { nut } },
188
+ ),
189
+ );
83
190
  // Its mass: the outline screwModel weighs, at the plastic's density
84
- if (!mat.density) throw new Error(`${what}: ${mat.name} has no density in its rule set, so the bolt cannot be weighed`);
191
+ if (!mat.density)
192
+ throw new Error(`${what}: ${mat.name} has no density in its rule set, so the bolt cannot be weighed`);
85
193
  const grams = fx.printed ? sc.mass : r3((sc.mass / DEFAULTS.steel_density.value) * mat.density.value);
86
194
  rests.push(rest(mat.density.name, mat.density));
87
195
  const name = fx.printed ? sc.name : `${sc.name} printed`;
88
- out.push(finding('info', `${name} weighs ${mm(grams)} g of ${mat.name}, an estimate from its outline`, 'bolt.mass', { values: { grams } }));
89
- return { kind: 'printed-bolt', name, thread: fx.thread, head: form, length: sc.length, nut, axis, material: mat.name, root, rootArea: n2(rootArea), engaged: depth,
90
- tension: { strength: sTension.value, load: n1(tensionLoad), rule: sTension.name }, strip: { area: n2(stripArea), shear: n2(tau), load: n1(stripLoad), nutArea: nutArea != null ? n2(nutArea) : null },
91
- headShear: headShear != null ? n1(headShear) : null, breaking: n1(breaking), governs, load, margin, grams, threaded: t, rests, findings: out };
196
+ out.push(
197
+ finding('info', `${name} weighs ${mm(grams)} g of ${mat.name}, an estimate from its outline`, 'bolt.mass', {
198
+ values: { grams },
199
+ }),
200
+ );
201
+ return {
202
+ kind: 'printed-bolt',
203
+ name,
204
+ thread: fx.thread,
205
+ head: form,
206
+ length: sc.length,
207
+ nut,
208
+ axis,
209
+ material: mat.name,
210
+ root,
211
+ rootArea: n2(rootArea),
212
+ engaged: depth,
213
+ tension: { strength: sTension.value, load: n1(tensionLoad), rule: sTension.name },
214
+ strip: { area: n2(stripArea), shear: n2(tau), load: n1(stripLoad), nutArea: nutArea != null ? n2(nutArea) : null },
215
+ headShear: headShear != null ? n1(headShear) : null,
216
+ breaking: n1(breaking),
217
+ governs,
218
+ load,
219
+ margin,
220
+ grams,
221
+ threaded: t,
222
+ rests,
223
+ findings: out,
224
+ };
92
225
  }
93
226
 
94
227
  /**
95
228
  * A printed bolt's solid: the screw with its thread drawn (screw's display: 'thread'), turned over to stand on its head
96
229
  * as it prints: the head's top on the bed at z = 0, its tip up.
97
- * @param {string | object} m as printedBoltModel @param {object} [o] as printedBoltModel @param {{ union: Function, subtract: Function }} [ops]
230
+ * @param {string | object} m as printedBoltModel @param {object} [o] as
231
+ * printedBoltModel @param {{ union: Function, subtract: Function }} [ops]
98
232
  * @returns {object} a JSCAD geom3 with .model holding printedBoltModel's numbers
99
233
  */
100
234
  export function printedBolt(m, o = {}, ops) {
101
- const b = printedBoltModel(m, o), fx = fixingOf('printedBolt', m, { ...o, anyLength: true });
102
- if (b.axis !== 'z') throw new Error('printedBolt: the solid is drawn standing on its head (axis z); a bolt lying on its flat is thread(..., { axis, flat: true }) with a head of your own');
103
- const g = screw(fx, { length: b.length, head: b.head, anyLength: true, display: 'thread', printer: o.printer, sets: o.sets, mate: b.nut === 'printed' ? 'printed' : 'bought', gap: o.gap }, ...(ops ? [ops] : []));
235
+ const b = printedBoltModel(m, o),
236
+ fx = fixingOf('printedBolt', m, { ...o, anyLength: true });
237
+ if (b.axis !== 'z')
238
+ throw new Error(
239
+ 'printedBolt: the solid is drawn standing on its head (axis z); a bolt lying on its flat is ' +
240
+ 'thread(..., { axis, flat: true }) with a head of your own',
241
+ );
242
+ const g = screw(
243
+ fx,
244
+ {
245
+ length: b.length,
246
+ head: b.head,
247
+ anyLength: true,
248
+ display: 'thread',
249
+ printer: o.printer,
250
+ sets: o.sets,
251
+ mate: b.nut === 'printed' ? 'printed' : 'bought',
252
+ gap: o.gap,
253
+ },
254
+ ...(ops ? [ops] : []),
255
+ );
104
256
  // (turned over onto its head, the head's top on the bed at z = 0 and its tip up)
105
257
  return Object.assign(translate([0, 0, g.model.top], rotateX(Math.PI, g)), { model: b, screw: g.model });
106
258
  }
package/draw.d.mts CHANGED
@@ -8,7 +8,8 @@ export function along(g: any, into: any, at?: number[]): any;
8
8
  * @returns {object} a JSCAD geom3
9
9
  */
10
10
  export function lathe(profile: number[][], n?: number, phase?: number): object;
11
- /** The volume a profile turns into, with true circles: each edge a frustum (mm³). @param {number[][]} profile @returns {number} */
11
+ /** The volume a profile turns into, with true circles: each edge a frustum
12
+ * (mm³). @param {number[][]} profile @returns {number} */
12
13
  export function turnedVolume(profile: number[][]): number;
13
14
  /**
14
15
  * A round cutter going down from z = 0, from its steps: [radius, depth] pairs from the mouth inwards, the radius
@@ -22,7 +23,8 @@ export function bore(steps: number[][], { through }?: {
22
23
  * A cutter lying on its side, going down from z = 0 in its own drawing, from its steps as bore takes them: at every
23
24
  * depth its section is a teardrop, a circle with a 45° pointed roof on the up side, so it prints with no support. One
24
25
  * closed solid with no joins in it, for the stepped and coned cutters @rulecad/shapes has no helper for.
25
- * @param {number[][]} steps [radius, depth] pairs from the mouth inwards @param {number[]} up which way is up in the drawing: [1, 0], [0, 1] …
26
+ * @param {number[][]} steps [radius, depth] pairs from the mouth inwards @param {number[]} up which way is up in the
27
+ * drawing: [1, 0], [0, 1] …
26
28
  * @param {{ through?: boolean }} [o] @returns {object} a JSCAD geom3 to subtract
27
29
  */
28
30
  export function teardrop(steps: number[][], up: number[], { through }?: {
package/draw.mjs CHANGED
@@ -3,7 +3,8 @@
3
3
  // triangles. Nothing here knows a thread: sizes come in as plain numbers.
4
4
  import jscad from '@jscad/modeling';
5
5
 
6
- const { translate, rotateX, rotateY } = jscad.transforms, { geom3, poly3 } = jscad.geometries;
6
+ const { translate, rotateX, rotateY } = jscad.transforms,
7
+ { geom3, poly3 } = jscad.geometries;
7
8
 
8
9
  export const OUT = 0.1; // how far a cutter starts outside the face it enters by, so no faces lie on each other
9
10
  export const SEGMENTS = 48; // round cutters
@@ -16,8 +17,14 @@ export const booleans = { union: jscad.booleans.union, subtract: jscad.booleans.
16
17
 
17
18
  /** A cutter drawn going down from z = 0 (into -z), turned to go along `into` from the origin, then moved to `at`. */
18
19
  export function along(g, into, at = [0, 0, 0]) {
19
- const turn = { '-z': (x) => x, '+z': (x) => rotateX(Math.PI, x), '+x': (x) => rotateY(-Math.PI / 2, x), '-x': (x) => rotateY(Math.PI / 2, x),
20
- '+y': (x) => rotateX(Math.PI / 2, x), '-y': (x) => rotateX(-Math.PI / 2, x) }[into];
20
+ const turn = {
21
+ '-z': (x) => x,
22
+ '+z': (x) => rotateX(Math.PI, x),
23
+ '+x': (x) => rotateY(-Math.PI / 2, x),
24
+ '-x': (x) => rotateY(Math.PI / 2, x),
25
+ '+y': (x) => rotateX(Math.PI / 2, x),
26
+ '-y': (x) => rotateX(-Math.PI / 2, x),
27
+ }[into];
21
28
  return translate(at, turn(g));
22
29
  }
23
30
 
@@ -29,26 +36,41 @@ export function along(g, into, at = [0, 0, 0]) {
29
36
  * @returns {object} a JSCAD geom3
30
37
  */
31
38
  export function lathe(profile, n = SEGMENTS, phase = 0) {
32
- const ring = (r, z) => Array.from({ length: n }, (_, i) => { const a = phase + (2 * Math.PI * i) / n; return [r * Math.cos(a), r * Math.sin(a), z]; });
33
- const pts = profile.filter((p, i) => i === 0 || Math.abs(p[0] - profile[i - 1][0]) > 1e-9 || Math.abs(p[1] - profile[i - 1][1]) > 1e-9);
34
- const rings = pts.map(([r, z]) => (r > 1e-9 ? ring(r, z) : null)), polys = [], closed = !!rings[0] && !!rings.at(-1);
39
+ const ring = (r, z) =>
40
+ Array.from({ length: n }, (_, i) => {
41
+ const a = phase + (2 * Math.PI * i) / n;
42
+ return [r * Math.cos(a), r * Math.sin(a), z];
43
+ });
44
+ const pts = profile.filter(
45
+ (p, i) => i === 0 || Math.abs(p[0] - profile[i - 1][0]) > 1e-9 || Math.abs(p[1] - profile[i - 1][1]) > 1e-9,
46
+ );
47
+ const rings = pts.map(([r, z]) => (r > 1e-9 ? ring(r, z) : null)),
48
+ polys = [],
49
+ closed = !!rings[0] && !!rings.at(-1);
35
50
  for (let e = 0; e < (closed ? pts.length : pts.length - 1); e++) {
36
- const b = (e + 1) % pts.length, P = rings[e], Q = rings[b];
51
+ const b = (e + 1) % pts.length,
52
+ P = rings[e],
53
+ Q = rings[b];
37
54
  if (!P && !Q) continue;
38
55
  for (let i = 0; i < n; i++) {
39
56
  const j = (i + 1) % n;
40
- polys.push(!P ? [[0, 0, pts[e][1]], Q[j], Q[i]] : !Q ? [P[i], P[j], [0, 0, pts[b][1]]] : [P[i], P[j], Q[j], Q[i]]);
57
+ polys.push(
58
+ !P ? [[0, 0, pts[e][1]], Q[j], Q[i]] : !Q ? [P[i], P[j], [0, 0, pts[b][1]]] : [P[i], P[j], Q[j], Q[i]],
59
+ );
41
60
  }
42
61
  }
43
62
  return geom3.create(polys.map((p) => poly3.create(p)));
44
63
  }
45
64
 
46
- /** The volume a profile turns into, with true circles: each edge a frustum (mm³). @param {number[][]} profile @returns {number} */
65
+ /** The volume a profile turns into, with true circles: each edge a frustum
66
+ * (mm³). @param {number[][]} profile @returns {number} */
47
67
  export function turnedVolume(profile) {
48
68
  let v = 0;
49
69
  for (let i = 0; i < profile.length; i++) {
50
- const [r0, z0] = profile[i], [r1, z1] = profile[(i + 1) % profile.length];
51
- v += (Math.PI / 3) * (z0 - z1) * (r0 * r0 + r0 * r1 + r1 * r1); // (the shoelace sum of a turned outline: edges going down the outside add, going up take away)
70
+ const [r0, z0] = profile[i],
71
+ [r1, z1] = profile[(i + 1) % profile.length];
72
+ // (the shoelace sum of a turned outline: edges going down the outside add, going up take away)
73
+ v += (Math.PI / 3) * (z0 - z1) * (r0 * r0 + r0 * r1 + r1 * r1);
52
74
  }
53
75
  return Math.abs(v);
54
76
  }
@@ -59,7 +81,8 @@ export function turnedVolume(profile) {
59
81
  * @param {number[][]} steps @param {{ through?: boolean }} [o] @returns {object} a JSCAD geom3 to subtract
60
82
  */
61
83
  export function bore(steps, { through = false } = {}) {
62
- const last = steps.at(-1), end = last[1] + (through ? OUT : 0);
84
+ const last = steps.at(-1),
85
+ end = last[1] + (through ? OUT : 0);
63
86
  const side = [[steps[0][0], OUT], ...steps.map(([r, d]) => [r, -d])];
64
87
  if (through) side.push([last[0], -end]);
65
88
  return lathe([[0, -end], ...side.reverse(), [0, OUT]]);
@@ -69,17 +92,35 @@ export function bore(steps, { through = false } = {}) {
69
92
  * A cutter lying on its side, going down from z = 0 in its own drawing, from its steps as bore takes them: at every
70
93
  * depth its section is a teardrop, a circle with a 45° pointed roof on the up side, so it prints with no support. One
71
94
  * closed solid with no joins in it, for the stepped and coned cutters @rulecad/shapes has no helper for.
72
- * @param {number[][]} steps [radius, depth] pairs from the mouth inwards @param {number[]} up which way is up in the drawing: [1, 0], [0, 1] …
95
+ * @param {number[][]} steps [radius, depth] pairs from the mouth inwards @param {number[]} up which way is up in the
96
+ * drawing: [1, 0], [0, 1] …
73
97
  * @param {{ through?: boolean }} [o] @returns {object} a JSCAD geom3 to subtract
74
98
  */
75
99
  export function teardrop(steps, up, { through = false } = {}) {
76
100
  // 35 steps round: no corner then lies level with the axis or 30° off it, the only places a corner's height is a round
77
101
  // number of mm, where it could sit exactly in the plane a slicer (or printcheck) cuts a layer at
78
- const turn = Math.atan2(up[1], up[0]), n = 35, last = steps.at(-1);
102
+ const turn = Math.atan2(up[1], up[0]),
103
+ n = 35,
104
+ last = steps.at(-1);
79
105
  // the point of the roof, then the circle from 45° past it round to 45° short of it
80
- const section = (r, z) => [[r * Math.SQRT2 * Math.cos(turn), r * Math.SQRT2 * Math.sin(turn), z], ...Array.from({ length: n + 1 }, (_, i) => { const t = turn + Math.PI / 4 + (1.5 * Math.PI * i) / n; return [r * Math.cos(t), r * Math.sin(t), z]; })];
81
- const rings = [[steps[0][0], OUT], ...steps.map(([r, d]) => [r, -d]), ...(through ? [[last[0], -last[1] - OUT]] : [])].map(([r, z]) => section(r, z)), polys = [rings[0]];
82
- for (let k = 0; k < rings.length - 1; k++) for (let i = 0; i < n + 2; i++) { const j = (i + 1) % (n + 2); polys.push([rings[k][i], rings[k + 1][i], rings[k + 1][j], rings[k][j]]); }
106
+ const section = (r, z) => [
107
+ [r * Math.SQRT2 * Math.cos(turn), r * Math.SQRT2 * Math.sin(turn), z],
108
+ ...Array.from({ length: n + 1 }, (_, i) => {
109
+ const t = turn + Math.PI / 4 + (1.5 * Math.PI * i) / n;
110
+ return [r * Math.cos(t), r * Math.sin(t), z];
111
+ }),
112
+ ];
113
+ const rings = [
114
+ [steps[0][0], OUT],
115
+ ...steps.map(([r, d]) => [r, -d]),
116
+ ...(through ? [[last[0], -last[1] - OUT]] : []),
117
+ ].map(([r, z]) => section(r, z)),
118
+ polys = [rings[0]];
119
+ for (let k = 0; k < rings.length - 1; k++)
120
+ for (let i = 0; i < n + 2; i++) {
121
+ const j = (i + 1) % (n + 2);
122
+ polys.push([rings[k][i], rings[k + 1][i], rings[k + 1][j], rings[k][j]]);
123
+ }
83
124
  polys.push([...rings.at(-1)].reverse());
84
125
  return geom3.create(polys.map((p) => poly3.create(p)));
85
126
  }
package/fixings.d.mts CHANGED
@@ -2,12 +2,15 @@
2
2
  * Every function of this package with a workspace's rule sets and printer already in hand, so a design writes
3
3
  * `fixings.hole('M3', { kind: 'pilot' })` and gets its own project's figures. This is the hook a host such as
4
4
  * @rulecad/cad calls once per design: the package itself reads no files.
5
- * @param {{ sets?: object, printer?: object, ops?: { union: Function, subtract: Function }, display?: 'thread' | 'plain' }} [workspace]
6
- * sets: the workspace's rule sets, by name ({ m3: { name, rules } }) or as a list: one for a thread is used before the
7
- * kit's; printer: the printer's rule set ({ name, rules }, so each figure keeps its kind and source) or its values;
8
- * ops: the design's booleans (v.ops); display: how a printed thread is drawn where a call does not say (thread and a
9
- * hole of kind 'thread'): 'plain' for a viewer or a link, where a real thread's thousands of triangles are not wanted
10
- * @returns {Record<string, Function>} fixingModel(name, change, opts) and the rest, each taking (fixing, options); lengthFor takes (stack, fixing, options)
5
+ * @param {{ sets?: object, printer?: object, ops?: { union: Function, subtract: Function },
6
+ * display?: 'thread' | 'plain' }} [workspace]
7
+ * sets: the workspace's rule sets, by name ({ m3: { name, rules } }) or as a list: one for a thread is used before
8
+ * the kit's; printer: the printer's rule set ({ name, rules }, so each figure keeps its kind and source) or its
9
+ * values; ops: the design's booleans (v.ops); display: how a printed thread is drawn where a call does not say
10
+ * (thread and a hole of kind 'thread'): 'plain' for a viewer or a link, where a real thread's thousands of triangles
11
+ * are not wanted
12
+ * @returns {Record<string, Function>} fixingModel(name, change, opts) and the rest, each taking (fixing, options);
13
+ * lengthFor takes (stack, fixing, options)
11
14
  */
12
15
  export function fixingsFor({ sets, printer, ops, display }?: {
13
16
  sets?: object;