@rulecad/fixings 0.1.4 → 0.1.6

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/bolts.d.mts ADDED
@@ -0,0 +1,85 @@
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
9
+ */
10
+ /**
11
+ * A printed bolt's strength: the load along it that breaks it, from the plastic's strength by how it prints, and that
12
+ * load against the one it carries. Standing on its head (axis z, the way it prints with no support), the pull goes
13
+ * 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,
16
+ * gap?: number, sets?: object }} [o]
17
+ * 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
21
+ * @returns {PrintedBolt}
22
+ */
23
+ export function printedBoltModel(m: string | object, o?: {
24
+ material?: string | object;
25
+ printer?: object;
26
+ nut?: "printed" | "steel";
27
+ depth?: number;
28
+ axis?: "x" | "y" | "z";
29
+ load?: number;
30
+ length?: number;
31
+ head?: string;
32
+ gap?: number;
33
+ sets?: object;
34
+ }): PrintedBolt;
35
+ /**
36
+ * A printed bolt's solid: the screw with its thread drawn (screw's display: 'thread'), turned over to stand on its head
37
+ * 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]
39
+ * @returns {object} a JSCAD geom3 with .model holding printedBoltModel's numbers
40
+ */
41
+ export function printedBolt(m: string | object, o?: object, ops?: {
42
+ union: Function;
43
+ subtract: Function;
44
+ }): 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). */
46
+ export const BOLT_NUTS: string[];
47
+ /**
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
52
+ */
53
+ export type PrintedBolt = {
54
+ kind: "printed-bolt";
55
+ name: string;
56
+ thread: string;
57
+ head: string;
58
+ length: number;
59
+ nut: "printed" | "steel";
60
+ axis: "x" | "y" | "z";
61
+ material: string;
62
+ root: number;
63
+ rootArea: number;
64
+ engaged: number;
65
+ tension: {
66
+ strength: number;
67
+ load: number;
68
+ rule: string;
69
+ };
70
+ strip: {
71
+ area: number;
72
+ shear: number;
73
+ load: number;
74
+ nutArea: number | null;
75
+ };
76
+ headShear: number | null;
77
+ breaking: number;
78
+ governs: "tension" | "strip" | "head";
79
+ load: number | null;
80
+ margin: number | null;
81
+ grams: number;
82
+ threaded: object;
83
+ rests: object[];
84
+ findings: object[];
85
+ };
package/bolts.mjs ADDED
@@ -0,0 +1,106 @@
1
+ // Printed bolts: a screw printed with its thread, standing on its head, as a fixing with a strength of its own. Its
2
+ // thread is threadModel's (refused below the smallest pitch the printer resolves, naming the smallest that prints), and
3
+ // its strength is the plastic's: the bolt breaks in tension across its root, or its teeth shear off in the nut, or its
4
+ // head shears off its shank, whichever comes first. A printed bolt goes in a printed nut (or a thread printed in the
5
+ // part), each taking half the printer's thread_gap, or in a bought steel nut, the bolt then taking the whole gap. It is
6
+ // named as a screw with the word printed: 'M8x20 hex printed'. Units: mm, N, MPa, grams.
7
+ import jscad from '@jscad/modeling';
8
+ import { DEFAULTS, fixingOf, nutOf, cite, rest, finding, positive, oneOf, mm, r3, a } from './model.mjs';
9
+ import { optionsOf } from './holes.mjs';
10
+ import { materialOf, weakest } from './strength.mjs';
11
+ import { threadModel } from './threads.mjs';
12
+ import { screwModel, screw } from './hardware.mjs';
13
+
14
+ const { translate, rotateX } = jscad.transforms;
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). */
19
+ export const BOLT_NUTS = ['printed', 'steel'];
20
+
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)));
23
+
24
+ /**
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
32
+ */
33
+
34
+ /**
35
+ * A printed bolt's strength: the load along it that breaks it, from the plastic's strength by how it prints, and that
36
+ * load against the one it carries. Standing on its head (axis z, the way it prints with no support), the pull goes
37
+ * 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,
40
+ * gap?: number, sets?: object }} [o]
41
+ * 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
45
+ * @returns {PrintedBolt}
46
+ */
47
+ export function printedBoltModel(m, o = {}) {
48
+ const what = 'printedBoltModel';
49
+ optionsOf(what, o, '{ material: \'pla\', load: 100 }');
50
+ 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;
60
+ if (o.depth == null) rests.push(rest(cite(fx, 'nut_height'), fx.figures.nut_height));
61
+ // 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;
63
+ 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;
68
+ rests.push(rest(w.f.name, w.f), rest('fixings.shear_ratio', DEFAULTS.shear_ratio));
69
+ // The head off its shank: a cylinder the bolt's diameter, the head's height tall, across the layers
70
+ const headShear = form === 'set' ? null : tau * Math.PI * d * Math.max(sc.headHeight, 1e-9);
71
+ 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;
77
+ let margin = null;
78
+ 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) } }));
81
+ }
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 } }));
83
+ // 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`);
85
+ const grams = fx.printed ? sc.mass : r3((sc.mass / DEFAULTS.steel_density.value) * mat.density.value);
86
+ rests.push(rest(mat.density.name, mat.density));
87
+ 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 };
92
+ }
93
+
94
+ /**
95
+ * A printed bolt's solid: the screw with its thread drawn (screw's display: 'thread'), turned over to stand on its head
96
+ * 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]
98
+ * @returns {object} a JSCAD geom3 with .model holding printedBoltModel's numbers
99
+ */
100
+ 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] : []));
104
+ // (turned over onto its head, the head's top on the bed at z = 0 and its tip up)
105
+ return Object.assign(translate([0, 0, g.model.top], rotateX(Math.PI, g)), { model: b, screw: g.model });
106
+ }
package/fixings.d.mts CHANGED
@@ -33,3 +33,7 @@ export { counterboreModel, counterbore, countersinkModel, countersink, nutPocket
33
33
  export { screwModel, screw, nutModel, nut, washerModel, washer, insertModel, insert } from "./hardware.mjs";
34
34
  export { threadModel, thread, THREAD_FORMS } from "./threads.mjs";
35
35
  export { engagement, stripping, preload, torqueFor, seating, lengthFor, screwGroup, screwLoad, MATERIALS, MATERIAL_CLASSES, ENDS } from "./strength.mjs";
36
+ export { pinModel, pinHole, pin, snapPin, snapSocket, snapPinModel, parsePin, isPinName, PIN_KINDS, PIN_FITS, PIN_GRAMMAR } from "./pins.mjs";
37
+ export { printedBoltModel, printedBolt, BOLT_NUTS } from "./bolts.mjs";
38
+ export { magnetModel, magnetSeatModel, magnetSeat, magnet, parseMagnet, isMagnetName, fieldShare, MAGNET_GRADES, MAGNET_FITS, MAGNET_SIZES, MAGNET_GRAMMAR } from "./magnets.mjs";
39
+ export { annularSnapModel, annularBead, annularGroove, hubFactor, shaftFactor, tubeRing, SNAP_USES } from "./snaps.mjs";
package/fixings.mjs CHANGED
@@ -4,7 +4,11 @@
4
4
  // nutTrap, squareNutSlot, captiveNut, insertBoss), and light solids of the hardware for an assembly (screw, nut,
5
5
  // washer, insert), a real thread to print where one is wanted (thread), and first sums for a joint: thread engaged,
6
6
  // the load that strips it, clamp force from torque, pressure under a head, and the sold length that fits a stack
7
- // (engagement, stripping, preload, seating, lengthFor). Where it applies each comes as a pair: one function gives the
7
+ // (engagement, stripping, preload, seating, lengthFor), and pins that hold two parts with no thread: a printed snap pin, a
8
+ // steel dowel, a length of filament or a printed peg, each with its hole's fit from the printer's rules (pinModel, pinHole,
9
+ // pin), and magnets pressed, glued or held by crush ribs in a pocket from the printer's rules, with their pull (magnetModel,
10
+ // magnetSeatModel, magnetSeat, magnet), printed bolts with their own strength (printedBoltModel, printedBolt), and annular snaps, a
11
+ // lid that clicks on to a round box, with the forces and hoop strain from the Bayer snap-fit guide (annularSnapModel, annularBead, annularGroove). Where it applies each comes as a pair: one function gives the
8
12
  // numbers with findings (holeModel), its twin the solid (hole). Every thread's figures live in @rulecad/rules as open data: this package holds no
9
13
  // screw's numbers of its own. Units: mm, degrees, grams. The plan is https://github.com/JoniBach/rulecad/issues/212.
10
14
  import { fixingModel } from './model.mjs';
@@ -13,6 +17,10 @@ import { counterboreModel, counterbore, countersinkModel, countersink, nutPocket
13
17
  import { screwModel, screw, nutModel, nut, washerModel, washer, insertModel, insert } from './hardware.mjs';
14
18
  import { threadModel, thread } from './threads.mjs';
15
19
  import { engagement, stripping, preload, torqueFor, seating, lengthFor, screwGroup, screwLoad } from './strength.mjs';
20
+ import { pinModel, pinHole, pin, snapPin, snapSocket, snapPinModel, parsePin, isPinName } from './pins.mjs';
21
+ import { printedBoltModel, printedBolt } from './bolts.mjs';
22
+ import { magnetModel, magnetSeatModel, magnetSeat, magnet, parseMagnet, isMagnetName, fieldShare } from './magnets.mjs';
23
+ import { annularSnapModel, annularBead, annularGroove, hubFactor, shaftFactor, tubeRing } from './snaps.mjs';
16
24
 
17
25
  export { fixingModel, parseName, threads, GRAMMAR, HEADS, NUTS, DEFAULTS } from './model.mjs';
18
26
  export { holeModel, hole, HOLE_KINDS } from './holes.mjs';
@@ -20,6 +28,10 @@ export { counterboreModel, counterbore, countersinkModel, countersink, nutPocket
20
28
  export { screwModel, screw, nutModel, nut, washerModel, washer, insertModel, insert } from './hardware.mjs';
21
29
  export { threadModel, thread, THREAD_FORMS } from './threads.mjs';
22
30
  export { engagement, stripping, preload, torqueFor, seating, lengthFor, screwGroup, screwLoad, MATERIALS, MATERIAL_CLASSES, ENDS } from './strength.mjs';
31
+ export { pinModel, pinHole, pin, snapPin, snapSocket, snapPinModel, parsePin, isPinName, PIN_KINDS, PIN_FITS, PIN_GRAMMAR } from './pins.mjs';
32
+ export { printedBoltModel, printedBolt, BOLT_NUTS } from './bolts.mjs';
33
+ export { magnetModel, magnetSeatModel, magnetSeat, magnet, parseMagnet, isMagnetName, fieldShare, MAGNET_GRADES, MAGNET_FITS, MAGNET_SIZES, MAGNET_GRAMMAR } from './magnets.mjs';
34
+ export { annularSnapModel, annularBead, annularGroove, hubFactor, shaftFactor, tubeRing, SNAP_USES } from './snaps.mjs';
23
35
 
24
36
  /**
25
37
  * What this release is. `release` is `'placeholder'` until the package has functions to call (0.1.0), then `'ready'`:
@@ -28,8 +40,8 @@ export { engagement, stripping, preload, torqueFor, seating, lengthFor, screwGro
28
40
  */
29
41
  export const status = Object.freeze({ release: 'ready', plan: 'https://github.com/JoniBach/rulecad/issues/212' });
30
42
 
31
- const MODELS = { engagement, stripping, preload, torqueFor, seating, screwLoad, threadModel, holeModel, counterboreModel, countersinkModel, nutPocketModel, nutTrapModel, squareNutSlotModel, captiveNutModel, insertBossModel, screwModel, nutModel, washerModel, insertModel };
32
- const SOLIDS = { thread, hole, counterbore, countersink, nutPocket, nutTrap, squareNutSlot, captiveNut, insertBoss, nut, washer, insert }, JOINED = { screw };
43
+ const MODELS = { engagement, stripping, preload, torqueFor, seating, screwLoad, threadModel, holeModel, counterboreModel, countersinkModel, nutPocketModel, nutTrapModel, squareNutSlotModel, captiveNutModel, insertBossModel, screwModel, nutModel, washerModel, insertModel, pinModel, magnetModel, magnetSeatModel, printedBoltModel, annularSnapModel };
44
+ const SOLIDS = { thread, hole, counterbore, countersink, nutPocket, nutTrap, squareNutSlot, captiveNut, insertBoss, nut, washer, insert, pinHole, magnetSeat, magnet, annularBead, annularGroove }, JOINED = { screw, pin, printedBolt };
33
45
 
34
46
  /**
35
47
  * Every function of this package with a workspace's rule sets and printer already in hand, so a design writes
@@ -49,6 +61,8 @@ export function fixingsFor({ sets, printer, ops, display } = {}) {
49
61
  for (const [k, f] of Object.entries({ ...MODELS, ...SOLIDS })) out[k] = (m, o = {}) => f(m, with_(as(k, o)));
50
62
  out.lengthFor = (stack, m, o = {}) => lengthFor(stack, m, with_(o));
51
63
  out.screwGroup = screwGroup;
64
+ // (a snap pin from plain figures, as @rulecad/flexures draws it, built with the design's booleans)
65
+ Object.assign(out, { snapPin: (p, o) => snapPin(p, o ?? ops ?? undefined), snapSocket, snapPinModel, parsePin, isPinName, parseMagnet, isMagnetName, fieldShare, hubFactor, shaftFactor, tubeRing });
52
66
  for (const [k, f] of Object.entries(JOINED)) out[k] = (m, o = {}) => (ops ? f(m, with_(o), ops) : f(m, with_(o)));
53
67
  return out;
54
68
  }
package/hardware.d.mts CHANGED
@@ -5,13 +5,16 @@
5
5
  * A screw as numbers: its outline, the anchors an assembly places it by, and its mass.
6
6
  * It stands on the z axis with its head up: the face its head seats on is at z = 0 and its thread runs down to
7
7
  * z = -length. A countersunk screw and a set screw are measured overall, so their top is at z = 0.
8
+ * A printed bolt ('M8x20 hex printed') keeps the word printed in its name and is weighed in its plastic; its strength
9
+ * is printedBoltModel's.
8
10
  * @param {Fixing | string} m a screw's model or name ('M3x12 cap'), or a thread with { length, head }
9
- * @param {{ length?: number, head?: string, material?: 'steel' | 'stainless', anyLength?: boolean, sets?: object, display?: 'plain' | 'thread', printer?: object,
11
+ * @param {{ length?: number, head?: string, material?: string | object, anyLength?: boolean, sets?: object, display?: 'plain' | 'thread', printer?: object,
10
12
  * mate?: 'printed' | 'bought', gap?: number, flanks?: 'printed' | 'standard', hand?: 'right' | 'left', segments?: number }} [o]
11
- * length, head: where the model has none, or to change them; material: for its mass (default steel); display: plain
13
+ * length, head: where the model has none, or to change them; material: for its mass, steel (the default) or
14
+ * stainless, or for a printed bolt its plastic (default PLA); display: plain
12
15
  * (the light solid, the default) or thread (its thread drawn, to print it standing on its head: then printer, mate,
13
16
  * gap, flanks, hand and segments are threadModel's)
14
- * @returns {{ item: 'screw', name: string, thread: string, head: string, length: number, sold: boolean | null, major: number, headDiameter: number, headHeight: number, sink: number, top: number, key: number | null,
17
+ * @returns {{ item: 'screw', name: string, printed?: boolean, thread: string, head: string, length: number, sold: boolean | null, major: number, headDiameter: number, headHeight: number, sink: number, top: number, key: number | null,
15
18
  * mass: number, material: string, display: 'plain' | 'thread', threaded: object | null, anchors: { seat: Anchor, tip: Anchor, axis: Anchor, top: Anchor }, profile: number[][], rests: object[], findings: object[] }}
16
19
  * sink: how deep a countersunk head's cone goes; top: the z of the head's top; mass: grams; threaded: threadModel's numbers where its thread is drawn;
17
20
  * anchors: seat (under the head, or the flush face of a countersunk screw), tip, axis (the thread's, at the seat) and top (where a key goes in)
@@ -19,7 +22,7 @@
19
22
  export function screwModel(m: Fixing | string, o?: {
20
23
  length?: number;
21
24
  head?: string;
22
- material?: "steel" | "stainless";
25
+ material?: string | object;
23
26
  anyLength?: boolean;
24
27
  sets?: object;
25
28
  display?: "plain" | "thread";
@@ -32,6 +35,7 @@ export function screwModel(m: Fixing | string, o?: {
32
35
  }): {
33
36
  item: "screw";
34
37
  name: string;
38
+ printed?: boolean;
35
39
  thread: string;
36
40
  head: string;
37
41
  length: number;
package/hardware.mjs CHANGED
@@ -7,6 +7,7 @@ import { DEFAULTS, fixingOf, headOf, nutOf, lengthOf, screwName, figure, cite, r
7
7
  import { optionsOf } from './holes.mjs';
8
8
  import { lathe, turnedVolume, booleans, LIGHT } from './draw.mjs';
9
9
  import { threadModel, threadedScrew, threadedNut } from './threads.mjs';
10
+ import { materialOf } from './strength.mjs';
10
11
 
11
12
  /**
12
13
  * @typedef {import('./model.mjs').Fixing} Fixing a fixing's model, as fixingModel gives it
@@ -41,13 +42,16 @@ const weighed = (name, mass, material, how) => finding('info', `${name}: ${mm(ma
41
42
  * A screw as numbers: its outline, the anchors an assembly places it by, and its mass.
42
43
  * It stands on the z axis with its head up: the face its head seats on is at z = 0 and its thread runs down to
43
44
  * z = -length. A countersunk screw and a set screw are measured overall, so their top is at z = 0.
45
+ * A printed bolt ('M8x20 hex printed') keeps the word printed in its name and is weighed in its plastic; its strength
46
+ * is printedBoltModel's.
44
47
  * @param {Fixing | string} m a screw's model or name ('M3x12 cap'), or a thread with { length, head }
45
- * @param {{ length?: number, head?: string, material?: 'steel' | 'stainless', anyLength?: boolean, sets?: object, display?: 'plain' | 'thread', printer?: object,
48
+ * @param {{ length?: number, head?: string, material?: string | object, anyLength?: boolean, sets?: object, display?: 'plain' | 'thread', printer?: object,
46
49
  * mate?: 'printed' | 'bought', gap?: number, flanks?: 'printed' | 'standard', hand?: 'right' | 'left', segments?: number }} [o]
47
- * length, head: where the model has none, or to change them; material: for its mass (default steel); display: plain
50
+ * length, head: where the model has none, or to change them; material: for its mass, steel (the default) or
51
+ * stainless, or for a printed bolt its plastic (default PLA); display: plain
48
52
  * (the light solid, the default) or thread (its thread drawn, to print it standing on its head: then printer, mate,
49
53
  * gap, flanks, hand and segments are threadModel's)
50
- * @returns {{ item: 'screw', name: string, thread: string, head: string, length: number, sold: boolean | null, major: number, headDiameter: number, headHeight: number, sink: number, top: number, key: number | null,
54
+ * @returns {{ item: 'screw', name: string, printed?: boolean, thread: string, head: string, length: number, sold: boolean | null, major: number, headDiameter: number, headHeight: number, sink: number, top: number, key: number | null,
51
55
  * mass: number, material: string, display: 'plain' | 'thread', threaded: object | null, anchors: { seat: Anchor, tip: Anchor, axis: Anchor, top: Anchor }, profile: number[][], rests: object[], findings: object[] }}
52
56
  * sink: how deep a countersunk head's cone goes; top: the z of the head's top; mass: grams; threaded: threadModel's numbers where its thread is drawn;
53
57
  * anchors: seat (under the head, or the flush face of a countersunk screw), tip, axis (the thread's, at the seat) and top (where a key goes in)
@@ -59,7 +63,7 @@ export function screwModel(m, o = {}) {
59
63
  if (!['screw', 'thread'].includes(fx.item)) throw new Error(`${what}: ${fx.name} is ${a(fx.item)}, not a screw: use ${fx.item}()`);
60
64
  const form = o.head ?? fx.head?.form ?? (fx.made.heads.includes('cap') ? 'cap' : fx.made.heads[0]), head = headOf(what, fx, form);
61
65
  if (o.length == null && fx.length == null) throw new Error(`${what}: give a length, in the name ('${fx.thread}x12 ${form}') or as { length: 12 }`);
62
- const { length, sold } = o.length == null ? fx : form === 'set' ? { length: positive(what, 'length', o.length), sold: null } : lengthOf(what, fx, o.length, !!o.anyLength);
66
+ const { length, sold } = o.length == null ? fx : form === 'set' ? { length: positive(what, 'length', o.length), sold: null } : lengthOf(what, fx, o.length, !!o.anyLength || !!fx.printed); // (a printed screw is printed at any length)
63
67
  const r = fx.major / 2, R = head.across / 2, k = head.height, L = length;
64
68
  // The outline, turned about z: from the tip up the thread, out under the head and over it
65
69
  const sink = form === 'countersunk' ? Math.min(r3((R - r) / Math.tan((((head.angle ?? 90) / 2) * Math.PI) / 180)), L) : 0;
@@ -70,12 +74,16 @@ export function screwModel(m, o = {}) {
70
74
  const top = form === 'set' || form === 'countersunk' ? 0 : k, shank = L - sink;
71
75
  const headProfile = form === 'countersunk' ? [[0, -sink], [r, -sink], [R, 0], [0, 0]] : profile.filter(([, z]) => z >= 0).map((p, i) => (i === 0 ? [0, 0] : p));
72
76
  const headVolume = form === 'set' ? 0 : form === 'hex' ? (Math.sqrt(3) / 2) * head.flats ** 2 * k : turnedVolume(headProfile);
73
- const material = o.material ?? 'steel', w = massOf(what, threadArea(what, fx) * shank + headVolume, material), name = screwName(fx, L, form);
77
+ // a printed bolt ('M8x20 hex printed') is named as printed and weighed in its plastic (PLA unless material names another): its strength is printedBoltModel's
78
+ const volume = threadArea(what, fx) * shank + headVolume, plastic = fx.printed ? materialOf(what, o.material ?? 'pla', o.sets) : null;
79
+ if (plastic && plastic.cls !== 'plastic') throw new Error(`${what}: ${fx.name} is printed, and ${plastic.name} is no plastic: give a plastic as its material (pla, petg), or name a bought screw ('${screwName(fx, L, form)}'). printedBoltModel('${fx.name}') gives its strength`);
80
+ if (plastic && !plastic.density) throw new Error(`${what}: ${plastic.name} has no density in its rule set, so ${fx.name} cannot be weighed`);
81
+ const material = plastic ? plastic.name : o.material ?? 'steel', w = plastic ? { mass: r3((volume * plastic.density.value) / 1000), density: rest(plastic.density.name, plastic.density) } : massOf(what, volume, material), name = `${screwName(fx, L, form)}${fx.printed ? ' printed' : ''}`;
74
82
  const threaded = drawnThread(what, fx, o, { length: shank, top: '-z' }); // (it prints standing on its head, so its tip is up)
75
- return { item: 'screw', name, thread: fx.thread, head: form, length: L, sold, major: fx.major, headDiameter: head.across, headHeight: k, sink, top, key: head.key ?? null, mass: w.mass, material,
83
+ return { item: 'screw', name, ...(fx.printed ? { printed: true } : {}), thread: fx.thread, head: form, length: L, sold, major: fx.major, headDiameter: head.across, headHeight: k, sink, top, key: head.key ?? null, mass: w.mass, material,
76
84
  display: threaded ? 'thread' : 'plain', threaded, anchors: { seat: anchor(0), tip: anchor(-L, -1), axis: anchor(0), top: anchor(top) }, profile,
77
85
  rests: [rest(cite(fx, 'major_diameter'), fx.figures.major_diameter), rest(cite(fx, 'pitch'), fx.figures.pitch), ...head.figures.map((n) => rest(cite(fx, n), fx.figures[n])), w.density, ...(threaded ? threaded.rests : [])],
78
- findings: [weighed(name, w.mass, material, 'the thread at its pitch diameter, the head with no socket'), ...(threaded ? threaded.findings : [])] };
86
+ findings: [weighed(name, w.mass, material, 'the thread at its pitch diameter, the head with no socket'), ...(fx.printed ? [finding('info', `${name} is printed in ${material}, not bought: printedBoltModel('${name}', { material: '${material}' }) gives its strength`, 'fixing.printed', { values: { grams: w.mass }, refs: { material } })] : []), ...(threaded ? threaded.findings : [])] };
79
87
  }
80
88
 
81
89
  /**
package/magnets.d.mts ADDED
@@ -0,0 +1,188 @@
1
+ /**
2
+ * A magnet's name read by the grammar.
3
+ * @param {string} name 'disc magnet 8x3', 'magnet 6x2 N52', 'block magnet 10x5x2 N45'
4
+ * @returns {{ shape: 'disc' | 'block', diameter: number | null, length: number | null, width: number | null, thickness: number, grade: string | null }}
5
+ */
6
+ export function parseMagnet(name: string): {
7
+ shape: "disc" | "block";
8
+ diameter: number | null;
9
+ length: number | null;
10
+ width: number | null;
11
+ thickness: number;
12
+ grade: string | null;
13
+ };
14
+ /**
15
+ * The flux density on a magnet's axis at a distance from its face, over the density at its face: the formulas of
16
+ * magnets.field_formula. A pull across a gap is taken as the pull touching times this squared, an estimate.
17
+ * @param {{ shape: 'disc' | 'block', diameter?: number | null, length?: number | null, width?: number | null, thickness: number }} p @param {number} z mm
18
+ * @returns {number} B(z) / B(0)
19
+ */
20
+ export function fieldShare(p: {
21
+ shape: "disc" | "block";
22
+ diameter?: number | null;
23
+ length?: number | null;
24
+ width?: number | null;
25
+ thickness: number;
26
+ }, z: number): number;
27
+ /**
28
+ * @typedef {{ kind: 'magnet', shape: 'disc' | 'block', name: string, said: string, diameter: number | null, length: number | null, width: number | null, thickness: number,
29
+ * grade: string, made: 'bought', touching: number, gap: number, pull: number, count: number, total: number, load: number | null, margin: number | null,
30
+ * grams: number, volume: number, rests: object[], findings: object[] }} Magnet
31
+ * touching: its pull straight off thick steel it touches, N; gap: what lies between it and the steel, mm; pull: across that gap, N;
32
+ * count: how many share the load; total: their pull together; load and margin: the pull asked of them all, and total over it
33
+ */
34
+ /**
35
+ * A magnet as a model by name: its pull straight off steel, from its seller's figure (magnets.<size>_pull) scaled to
36
+ * its grade by the square of the remanence, then across a gap by the square of the field on its axis; its mass.
37
+ * Refused by name where its size has no seller's figure, unless the pull is given.
38
+ * @param {string | Magnet} p a magnet's name (see MAGNET_GRAMMAR) or its model (given back as it is, or with options
39
+ * built again from its name, its own grade, gap, count, load and given pull where the options say none)
40
+ * @param {{ grade?: string, gap?: number, count?: number, load?: number, pull?: number }} [o]
41
+ * grade: in place of the name's; gap: plastic, paint or air between it and the steel, mm (default 0); count: magnets
42
+ * sharing the load (default 1); load: the pull asked of them, N, held to fixings.load_margin; pull: a magnet's own
43
+ * pull touching steel, N, from its maker, for a size the kit holds no figure for
44
+ * @returns {Magnet}
45
+ */
46
+ export function magnetModel(p: string | Magnet, o?: {
47
+ grade?: string;
48
+ gap?: number;
49
+ count?: number;
50
+ load?: number;
51
+ pull?: number;
52
+ }): Magnet;
53
+ /**
54
+ * @typedef {{ kind: 'magnet-seat', magnet: Magnet, fit: 'press' | 'glue' | 'ribs', facing: 'open' | 'floor',
55
+ * pocket: { shape: 'round' | 'rect', diameter: number | null, size: number[] | null, nominal: number[], comp: number, clearance: number, depth: number, lead: number,
56
+ * into: string, axis: 'x' | 'y' | 'z', teardrop: boolean, ribs: { count: number, tips: number, radius: number, protrude: number } | null, relief: number | null, rules: string[] },
57
+ * floor: number | null, thickness: number | null, hold: number | null, holdMargin: number | null, rests: object[], findings: object[] }} MagnetSeat
58
+ * pocket: what to draw (diameter of a round pocket, or [length, width] of a block's, as drawn; nominal: the magnet's;
59
+ * comp: hole compensation added; clearance: added across past that, under 0 for a press; lead: the chamfer at its
60
+ * mouth; ribs: crush ribs, their tips on a circle `tips` across; relief: a block pocket's corner reliefs' radius);
61
+ * floor: what is left under it in a part `thickness` thick; hold: what the fit grips the magnet with against its pull out, N
62
+ */
63
+ /**
64
+ * A magnet's pocket as a model: its size from the printer's rules for the fit (press: the magnet plus hole_comp less
65
+ * x1c.magnet_press; glue: plus x1c.magnet_glue; ribs: a glue pocket with three crush ribs whose tips stand
66
+ * x1c.magnet_crush inside the magnet), its depth (the magnet's thickness, and any recess), the floor left under it held
67
+ * to fixings.magnet_floor, and the magnet's pull out of it against what the fit grips with. Refused by name where it
68
+ * would not print: a pocket opening on the bed wider than the printer bridges, a block's pocket or crush ribs lying on
69
+ * their side, a floor too thin.
70
+ * @param {string | Magnet} p a magnet's name or model
71
+ * @param {{ fit?: 'press' | 'glue' | 'ribs', printer?: object, material?: string | object, sets?: object, into?: string, axis?: 'x' | 'y' | 'z',
72
+ * recess?: number, thickness?: number, facing?: 'open' | 'floor', grade?: string, gap?: number, count?: number, load?: number, pull?: number }} [o]
73
+ * fit: press, glue or ribs (the default: ribs for a disc standing in its pocket; glue for a disc lying on its side,
74
+ * where ribs would hang from the roof, and for a block, whose press splits its wall); material: the part's plastic (default PLA); into or axis: the pocket's way
75
+ * (default down from a top face); recess: how far under the face the magnet sits, mm; thickness: the part's along
76
+ * the pocket, for its floor; facing: where the magnet's steel is, past the pocket's open face (the default) or
77
+ * through its floor, which is then the gap; grade, gap, count, load, pull: magnetModel's
78
+ * @returns {MagnetSeat}
79
+ */
80
+ export function magnetSeatModel(p: string | Magnet, o?: {
81
+ fit?: "press" | "glue" | "ribs";
82
+ printer?: object;
83
+ material?: string | object;
84
+ sets?: object;
85
+ into?: string;
86
+ axis?: "x" | "y" | "z";
87
+ recess?: number;
88
+ thickness?: number;
89
+ facing?: "open" | "floor";
90
+ grade?: string;
91
+ gap?: number;
92
+ count?: number;
93
+ load?: number;
94
+ pull?: number;
95
+ }): MagnetSeat;
96
+ /**
97
+ * A magnet's pocket, to subtract: round (a teardrop lying on its side) with crush ribs where asked, or a block's with
98
+ * its corners relieved, the size magnetSeatModel gives it, from the point at on the face going into the part.
99
+ * @param {string | Magnet} p @param {object} [o] as magnetSeatModel, and at: the point on the face where the pocket starts
100
+ * @returns {object} a JSCAD geom3 with .model holding magnetSeatModel's numbers
101
+ */
102
+ export function magnetSeat(p: string | Magnet, o?: object): object;
103
+ /**
104
+ * A magnet's solid, standing on z = 0, for an assembly: a disc or a block. @param {string | Magnet} p @param {object} [o] as magnetModel
105
+ * @returns {object} a JSCAD geom3 with .model
106
+ */
107
+ export function magnet(p: string | Magnet, o?: object): object;
108
+ /** The grades of NdFeB magnet there is a remanence for, weakest first. */
109
+ export const MAGNET_GRADES: string[];
110
+ /** The fits a magnet takes in its pocket: press (it grips), glue (room for a film of glue), ribs (crush ribs grip it). */
111
+ export const MAGNET_FITS: string[];
112
+ /** The sizes there is a seller's pull for: discs as diameter x thickness, blocks as length x width x thickness. */
113
+ export const MAGNET_SIZES: Readonly<{
114
+ disc: string[];
115
+ block: string[];
116
+ }>;
117
+ /**
118
+ * The grammar a magnet's name is read by. parseMagnet reads it and nothing else does.
119
+ * @type {string}
120
+ */
121
+ export const MAGNET_GRAMMAR: string;
122
+ export function isMagnetName(name: unknown): boolean;
123
+ /**
124
+ * touching: its pull straight off thick steel it touches, N; gap: what lies between it and the steel, mm; pull: across that gap, N;
125
+ * count: how many share the load; total: their pull together; load and margin: the pull asked of them all, and total over it
126
+ */
127
+ export type Magnet = {
128
+ kind: "magnet";
129
+ shape: "disc" | "block";
130
+ name: string;
131
+ said: string;
132
+ diameter: number | null;
133
+ length: number | null;
134
+ width: number | null;
135
+ thickness: number;
136
+ grade: string;
137
+ made: "bought";
138
+ touching: number;
139
+ gap: number;
140
+ pull: number;
141
+ count: number;
142
+ total: number;
143
+ load: number | null;
144
+ margin: number | null;
145
+ grams: number;
146
+ volume: number;
147
+ rests: object[];
148
+ findings: object[];
149
+ };
150
+ /**
151
+ * pocket: what to draw (diameter of a round pocket, or [length, width] of a block's, as drawn; nominal: the magnet's;
152
+ * comp: hole compensation added; clearance: added across past that, under 0 for a press; lead: the chamfer at its
153
+ * mouth; ribs: crush ribs, their tips on a circle `tips` across; relief: a block pocket's corner reliefs' radius);
154
+ * floor: what is left under it in a part `thickness` thick; hold: what the fit grips the magnet with against its pull out, N
155
+ */
156
+ export type MagnetSeat = {
157
+ kind: "magnet-seat";
158
+ magnet: Magnet;
159
+ fit: "press" | "glue" | "ribs";
160
+ facing: "open" | "floor";
161
+ pocket: {
162
+ shape: "round" | "rect";
163
+ diameter: number | null;
164
+ size: number[] | null;
165
+ nominal: number[];
166
+ comp: number;
167
+ clearance: number;
168
+ depth: number;
169
+ lead: number;
170
+ into: string;
171
+ axis: "x" | "y" | "z";
172
+ teardrop: boolean;
173
+ ribs: {
174
+ count: number;
175
+ tips: number;
176
+ radius: number;
177
+ protrude: number;
178
+ } | null;
179
+ relief: number | null;
180
+ rules: string[];
181
+ };
182
+ floor: number | null;
183
+ thickness: number | null;
184
+ hold: number | null;
185
+ holdMargin: number | null;
186
+ rests: object[];
187
+ findings: object[];
188
+ };