@rulecad/fixings 0.1.4 → 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/CHANGELOG.md +50 -0
- package/README.md +251 -6
- package/bolts.d.mts +85 -0
- package/bolts.mjs +106 -0
- package/fixings.d.mts +3 -0
- package/fixings.mjs +14 -3
- package/hardware.d.mts +8 -4
- package/hardware.mjs +15 -7
- package/magnets.d.mts +188 -0
- package/magnets.mjs +279 -0
- package/model.d.mts +4 -3
- package/model.mjs +16 -10
- package/package.json +8 -2
- package/pins.d.mts +220 -0
- package/pins.mjs +300 -0
- package/seats.mjs +2 -0
- package/strength.d.mts +13 -0
- package/strength.mjs +17 -9
package/magnets.mjs
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
// Magnets: a disc or block neodymium magnet pressed or glued into a printed pocket, the seat that holds two parts
|
|
2
|
+
// together with no screw (a lid, a door's catch, a tool on a board). A magnet is a model by name (magnetModel: 'disc
|
|
3
|
+
// magnet 8x3', 'disc magnet 10x3 N52', 'block magnet 10x5x2'): its pull straight off steel from its seller's figure,
|
|
4
|
+
// scaled to its grade and across a gap, and its mass. Its pocket (magnetSeatModel) takes its fit from the printer's
|
|
5
|
+
// rules: a press, a glued fit with room for the glue, or crush ribs that take up the magnet's tolerance. The floor under
|
|
6
|
+
// the pocket is held to what prints, and the pull that tries to take the magnet out of its pocket is held to what the
|
|
7
|
+
// fit grips with. magnetSeat is the pocket to subtract, magnet the magnet's solid. Units: mm, N, MPa, grams.
|
|
8
|
+
import jscad from '@jscad/modeling';
|
|
9
|
+
import { crushRibs } from '@rulecad/shapes';
|
|
10
|
+
import magnetSet from '@rulecad/rules/magnets.json' with { type: 'json' };
|
|
11
|
+
import { DEFAULTS, printerOf, rest, finding, positive, oneOf, isNum, shown, mm, r3 } from './model.mjs';
|
|
12
|
+
import { along, bore, teardrop, UP, OUT } from './draw.mjs';
|
|
13
|
+
import { directionOf, pointOf, optionsOf, said } from './holes.mjs';
|
|
14
|
+
import { materialOf } from './strength.mjs';
|
|
15
|
+
|
|
16
|
+
const { cuboid, cylinder } = jscad.primitives, { union, subtract } = jscad.booleans, { translate } = jscad.transforms;
|
|
17
|
+
const MAGNETS = magnetSet.rules;
|
|
18
|
+
const n1 = (x) => +x.toFixed(1), n2 = (x) => +x.toFixed(2);
|
|
19
|
+
const mrest = (k) => rest(`magnets.${k}`, MAGNETS[k]);
|
|
20
|
+
|
|
21
|
+
/** The grades of NdFeB magnet there is a remanence for, weakest first. */
|
|
22
|
+
export const MAGNET_GRADES = Object.keys(MAGNETS).filter((k) => k.startsWith('remanence_')).map((k) => k.slice('remanence_'.length));
|
|
23
|
+
/** The fits a magnet takes in its pocket: press (it grips), glue (room for a film of glue), ribs (crush ribs grip it). */
|
|
24
|
+
export const MAGNET_FITS = ['press', 'glue', 'ribs'];
|
|
25
|
+
/** The sizes there is a seller's pull for: discs as diameter x thickness, blocks as length x width x thickness. */
|
|
26
|
+
export const MAGNET_SIZES = Object.freeze({
|
|
27
|
+
disc: Object.keys(MAGNETS).filter((k) => /^disc_.*_pull$/.test(k)).map((k) => k.slice(5, -5)),
|
|
28
|
+
block: Object.keys(MAGNETS).filter((k) => /^block_.*_pull$/.test(k)).map((k) => k.slice(6, -5))
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* The grammar a magnet's name is read by. parseMagnet reads it and nothing else does.
|
|
32
|
+
* @type {string}
|
|
33
|
+
*/
|
|
34
|
+
export const MAGNET_GRAMMAR = [
|
|
35
|
+
'magnet = shape size [ grade ] disc magnet 8x3, disc magnet 10x3 N52, block magnet 10x5x2',
|
|
36
|
+
'shape = "disc magnet" | "block magnet" | "magnet" (a magnet alone is a disc; "magnets" is read too)',
|
|
37
|
+
'size = diameter "x" thickness a disc, in mm, magnetised through its thickness',
|
|
38
|
+
' | length "x" width "x" thickness a block, in mm, magnetised through its thickness',
|
|
39
|
+
'grade = "N35" | "N38" | "N40" | "N42" | "N45" | "N48" | "N50" | "N52" (default magnets.grade, N35)'
|
|
40
|
+
].join('\n');
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* A magnet's name read by the grammar.
|
|
44
|
+
* @param {string} name 'disc magnet 8x3', 'magnet 6x2 N52', 'block magnet 10x5x2 N45'
|
|
45
|
+
* @returns {{ shape: 'disc' | 'block', diameter: number | null, length: number | null, width: number | null, thickness: number, grade: string | null }}
|
|
46
|
+
*/
|
|
47
|
+
export function parseMagnet(name) {
|
|
48
|
+
const what = 'magnet name', help = 'A magnet is its shape, its size in mm and its grade where it has one: \'disc magnet 8x3\', \'disc magnet 10x3 N52\', \'block magnet 10x5x2\'';
|
|
49
|
+
if (typeof name !== 'string' || !name.trim()) throw new Error(`${what}: give a name, not ${shown(name)}. ${help}`);
|
|
50
|
+
const t = /^\s*(disc\s+magnets?|block\s+magnets?|magnets?)\s+(\d*\.?\d+)\s*[x×*]\s*(\d*\.?\d+)(?:\s*[x×*]\s*(\d*\.?\d+))?\s*(?:mm\b)?\s*(.*)$/i.exec(name);
|
|
51
|
+
if (!t) throw new Error(`${what}: "${name}" is no magnet. ${help}`);
|
|
52
|
+
const block = /^block/i.test(t[1]), sizes = [t[2], t[3], t[4]].filter((x) => x != null).map(Number);
|
|
53
|
+
if (block !== (sizes.length === 3)) throw new Error(`${what}: "${name}": ${block ? 'a block magnet is length x width x thickness (block magnet 10x5x2)' : 'a disc magnet is diameter x thickness (disc magnet 8x3); a block is named "block magnet 10x5x2"'}`);
|
|
54
|
+
if (!sizes.every((x) => x > 0)) throw new Error(`${what}: "${name}": a magnet's sizes are above 0 mm`);
|
|
55
|
+
const words = t[5].trim().split(/[\s,]+/).filter(Boolean), grade = words.length === 1 && /^n\d\d$/i.test(words[0]) ? words[0].toUpperCase() : null;
|
|
56
|
+
if (words.length && !grade) throw new Error(`${what}: "${name}": nothing is called "${words.join(' ')}". After the size comes only a grade: ${MAGNET_GRADES.join(', ')}`);
|
|
57
|
+
if (grade && !MAGNET_GRADES.includes(grade)) throw new Error(`${what}: "${name}": no grade ${grade}. There are: ${MAGNET_GRADES.join(', ')}`);
|
|
58
|
+
return block ? { shape: 'block', diameter: null, length: sizes[0], width: sizes[1], thickness: sizes[2], grade } : { shape: 'disc', diameter: sizes[0], length: null, width: null, thickness: sizes[1], grade };
|
|
59
|
+
}
|
|
60
|
+
/** Whether a text is a magnet's name, by the grammar. @param {unknown} name @returns {boolean} */
|
|
61
|
+
export const isMagnetName = (name) => { try { parseMagnet(/** @type {string} */ (name)); return true; } catch { return false; } };
|
|
62
|
+
const sizeOf = (p) => (p.shape === 'disc' ? `${mm(p.diameter)}x${mm(p.thickness)}` : `${mm(p.length)}x${mm(p.width)}x${mm(p.thickness)}`);
|
|
63
|
+
const magnetName = (p, grade) => `${p.shape} magnet ${sizeOf(p)} ${grade}`;
|
|
64
|
+
const middle = (g) => { const [lo, hi] = MAGNETS[`remanence_${g}`].value; return (lo + hi) / 2; };
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The flux density on a magnet's axis at a distance from its face, over the density at its face: the formulas of
|
|
68
|
+
* magnets.field_formula. A pull across a gap is taken as the pull touching times this squared, an estimate.
|
|
69
|
+
* @param {{ shape: 'disc' | 'block', diameter?: number | null, length?: number | null, width?: number | null, thickness: number }} p @param {number} z mm
|
|
70
|
+
* @returns {number} B(z) / B(0)
|
|
71
|
+
*/
|
|
72
|
+
export function fieldShare(p, z) {
|
|
73
|
+
const D = p.thickness;
|
|
74
|
+
if (p.shape === 'disc') { const R = p.diameter / 2, B = (x) => (D + x) / Math.hypot(R, D + x) - (x > 0 ? x / Math.hypot(R, x) : 0); return B(z) / B(0); }
|
|
75
|
+
const L = p.length, W = p.width, B = (x) => (x > 0 ? Math.atan((L * W) / (2 * x * Math.sqrt(4 * x * x + L * L + W * W))) : Math.PI / 2) - Math.atan((L * W) / (2 * (D + x) * Math.sqrt(4 * (D + x) ** 2 + L * L + W * W)));
|
|
76
|
+
return B(z) / B(0);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @typedef {{ kind: 'magnet', shape: 'disc' | 'block', name: string, said: string, diameter: number | null, length: number | null, width: number | null, thickness: number,
|
|
81
|
+
* grade: string, made: 'bought', touching: number, gap: number, pull: number, count: number, total: number, load: number | null, margin: number | null,
|
|
82
|
+
* grams: number, volume: number, rests: object[], findings: object[] }} Magnet
|
|
83
|
+
* touching: its pull straight off thick steel it touches, N; gap: what lies between it and the steel, mm; pull: across that gap, N;
|
|
84
|
+
* count: how many share the load; total: their pull together; load and margin: the pull asked of them all, and total over it
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* A magnet as a model by name: its pull straight off steel, from its seller's figure (magnets.<size>_pull) scaled to
|
|
89
|
+
* its grade by the square of the remanence, then across a gap by the square of the field on its axis; its mass.
|
|
90
|
+
* Refused by name where its size has no seller's figure, unless the pull is given.
|
|
91
|
+
* @param {string | Magnet} p a magnet's name (see MAGNET_GRAMMAR) or its model (given back as it is, or with options
|
|
92
|
+
* built again from its name, its own grade, gap, count, load and given pull where the options say none)
|
|
93
|
+
* @param {{ grade?: string, gap?: number, count?: number, load?: number, pull?: number }} [o]
|
|
94
|
+
* grade: in place of the name's; gap: plastic, paint or air between it and the steel, mm (default 0); count: magnets
|
|
95
|
+
* sharing the load (default 1); load: the pull asked of them, N, held to fixings.load_margin; pull: a magnet's own
|
|
96
|
+
* pull touching steel, N, from its maker, for a size the kit holds no figure for
|
|
97
|
+
* @returns {Magnet}
|
|
98
|
+
*/
|
|
99
|
+
export function magnetModel(p, o = {}) {
|
|
100
|
+
const what = 'magnetModel';
|
|
101
|
+
optionsOf(what, o, '{ count: 2, load: 10 }');
|
|
102
|
+
if (p && typeof p === 'object' && p.kind === 'magnet') { // a model: as it is, or built again from its name with the options given, its own figures where they say none
|
|
103
|
+
if (Object.values(o).every((x) => x === undefined)) return p;
|
|
104
|
+
const given = p.findings?.find((f) => f.code === 'magnet.pull')?.refs?.kind === 'given';
|
|
105
|
+
return magnetModel(p.name, { grade: o.grade ?? p.grade, gap: o.gap ?? p.gap, count: o.count ?? p.count, load: o.load ?? p.load ?? undefined, pull: o.pull ?? (given ? p.touching : undefined) });
|
|
106
|
+
}
|
|
107
|
+
const n = parseMagnet(p), rests = [], out = [], size = sizeOf(n), key = `${n.shape}_${size}`;
|
|
108
|
+
if (o.grade != null && !MAGNET_GRADES.includes(o.grade)) throw new Error(`${what}: grade is one of ${MAGNET_GRADES.join(', ')} (got ${shown(o.grade)})`);
|
|
109
|
+
const grade = o.grade ?? n.grade ?? MAGNETS.grade.value, gap = o.gap ?? 0, count = o.count ?? 1;
|
|
110
|
+
if (!(isNum(gap) && gap >= 0)) throw new Error(`${what}: gap is what lies between the magnet and the steel, 0 mm or more (got ${shown(o.gap)})`);
|
|
111
|
+
if (!(Number.isInteger(count) && count >= 1)) throw new Error(`${what}: count is how many magnets share the load, a whole number from 1 (got ${shown(o.count)})`);
|
|
112
|
+
if (o.grade == null && n.grade == null) rests.push(mrest('grade'));
|
|
113
|
+
let touching, says;
|
|
114
|
+
if (o.pull != null) { touching = positive(what, 'pull (a magnet\'s pull touching steel, in N)', o.pull); says = `${mm(touching)} N touching steel, as given`; }
|
|
115
|
+
else {
|
|
116
|
+
const f = MAGNETS[`${key}_pull`];
|
|
117
|
+
if (!f) throw new Error(`${what}: there is no seller's pull for a ${n.shape} magnet ${size}: the kit holds ${MAGNET_SIZES[n.shape].join(', ')} (magnets.${n.shape}_<size>_pull). For another size, give its maker's pull touching steel ({ pull: 12 }, in N)`);
|
|
118
|
+
const sold = MAGNETS[`${key}_grade`].value, k = (middle(grade) / middle(sold)) ** 2;
|
|
119
|
+
touching = f.value * k; rests.push(mrest(`${key}_pull`), mrest(`${key}_grade`));
|
|
120
|
+
if (grade !== sold) rests.push(mrest(`remanence_${grade}`), mrest(`remanence_${sold}`));
|
|
121
|
+
says = grade === sold ? `${mm(f.value)} N touching steel, its seller's figure (magnets.${key}_pull, ${sold})` : `${mm(n2(touching))} N touching steel: its seller's ${mm(f.value)} N for ${sold} (magnets.${key}_pull) times (${mm(r3(middle(grade)))} / ${mm(r3(middle(sold)))} T)² for ${grade}, the middles of their remanence (magnets.remanence_${grade}, an estimate)`;
|
|
122
|
+
}
|
|
123
|
+
const share = gap > 0 ? fieldShare(n, gap) ** 2 : 1, pull = touching * share;
|
|
124
|
+
if (gap > 0) rests.push(mrest('field_formula'));
|
|
125
|
+
const volume = n.shape === 'disc' ? (Math.PI / 4) * n.diameter ** 2 * n.thickness : n.length * n.width * n.thickness, grams = r3((volume * MAGNETS.density.value) / 1000);
|
|
126
|
+
rests.push(mrest('density'));
|
|
127
|
+
const name = magnetName(n, grade);
|
|
128
|
+
out.push(finding('info', `${name} pulls ${says}${gap > 0 ? `; across a ${mm(gap)} mm gap ${mm(n2(pull))} N, ${mm(n1(share * 100))}% of that (the field on its axis squared, magnets.field_formula: an estimate)` : ''}. A seller's pull is straight off thick mild steel: a thin strike, a slide sideways or a rough face takes less`,
|
|
129
|
+
'magnet.pull', { values: { touching: n2(touching), gap, pull: n2(pull), grade }, refs: { magnet: name, kind: o.pull != null ? 'given' : grade === MAGNETS[`${key}_grade`]?.value ? 'community' : 'estimate' } }));
|
|
130
|
+
const total = pull * count, load = o.load != null ? positive(what, 'load (the pull asked of the magnets, in N)', o.load) : null, want = DEFAULTS.load_margin.value;
|
|
131
|
+
let margin = null;
|
|
132
|
+
if (load != null) {
|
|
133
|
+
margin = n2(total / load); rests.push(rest('fixings.load_margin', DEFAULTS.load_margin));
|
|
134
|
+
out.push(finding(margin >= want ? 'pass' : margin >= 1 ? 'warn' : 'fail', `${count > 1 ? `${count} × ${name} pull ${mm(n2(total))} N together` : `${name} pulls ${mm(n2(pull))} N`}: a pull of ${mm(load)} N is held ${mm(margin)} times over${margin >= want ? '' : margin >= 1 ? `, under the ${mm(want)} times fixings.load_margin asks` : ': it comes apart'}`, 'magnet.hold', { values: { total: n2(total), load, margin, count } }));
|
|
135
|
+
}
|
|
136
|
+
out.push(finding('info', `${name} weighs ${mm(grams)} g (magnets.density ${mm(MAGNETS.density.value)} g/cm³)`, 'magnet.mass', { values: { grams } }));
|
|
137
|
+
return { kind: 'magnet', shape: n.shape, name, said: String(p), diameter: n.diameter, length: n.length, width: n.width, thickness: n.thickness, grade, made: 'bought',
|
|
138
|
+
touching: n2(touching), gap, pull: n2(pull), count, total: n2(total), load, margin, grams, volume: n2(volume), rests, findings: out };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @typedef {{ kind: 'magnet-seat', magnet: Magnet, fit: 'press' | 'glue' | 'ribs', facing: 'open' | 'floor',
|
|
143
|
+
* pocket: { shape: 'round' | 'rect', diameter: number | null, size: number[] | null, nominal: number[], comp: number, clearance: number, depth: number, lead: number,
|
|
144
|
+
* into: string, axis: 'x' | 'y' | 'z', teardrop: boolean, ribs: { count: number, tips: number, radius: number, protrude: number } | null, relief: number | null, rules: string[] },
|
|
145
|
+
* floor: number | null, thickness: number | null, hold: number | null, holdMargin: number | null, rests: object[], findings: object[] }} MagnetSeat
|
|
146
|
+
* pocket: what to draw (diameter of a round pocket, or [length, width] of a block's, as drawn; nominal: the magnet's;
|
|
147
|
+
* comp: hole compensation added; clearance: added across past that, under 0 for a press; lead: the chamfer at its
|
|
148
|
+
* mouth; ribs: crush ribs, their tips on a circle `tips` across; relief: a block pocket's corner reliefs' radius);
|
|
149
|
+
* floor: what is left under it in a part `thickness` thick; hold: what the fit grips the magnet with against its pull out, N
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* A magnet's pocket as a model: its size from the printer's rules for the fit (press: the magnet plus hole_comp less
|
|
154
|
+
* x1c.magnet_press; glue: plus x1c.magnet_glue; ribs: a glue pocket with three crush ribs whose tips stand
|
|
155
|
+
* x1c.magnet_crush inside the magnet), its depth (the magnet's thickness, and any recess), the floor left under it held
|
|
156
|
+
* to fixings.magnet_floor, and the magnet's pull out of it against what the fit grips with. Refused by name where it
|
|
157
|
+
* would not print: a pocket opening on the bed wider than the printer bridges, a block's pocket or crush ribs lying on
|
|
158
|
+
* their side, a floor too thin.
|
|
159
|
+
* @param {string | Magnet} p a magnet's name or model
|
|
160
|
+
* @param {{ fit?: 'press' | 'glue' | 'ribs', printer?: object, material?: string | object, sets?: object, into?: string, axis?: 'x' | 'y' | 'z',
|
|
161
|
+
* recess?: number, thickness?: number, facing?: 'open' | 'floor', grade?: string, gap?: number, count?: number, load?: number, pull?: number }} [o]
|
|
162
|
+
* fit: press, glue or ribs (the default: ribs for a disc standing in its pocket; glue for a disc lying on its side,
|
|
163
|
+
* 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
|
|
164
|
+
* (default down from a top face); recess: how far under the face the magnet sits, mm; thickness: the part's along
|
|
165
|
+
* the pocket, for its floor; facing: where the magnet's steel is, past the pocket's open face (the default) or
|
|
166
|
+
* through its floor, which is then the gap; grade, gap, count, load, pull: magnetModel's
|
|
167
|
+
* @returns {MagnetSeat}
|
|
168
|
+
*/
|
|
169
|
+
export function magnetSeatModel(p, o = {}) {
|
|
170
|
+
const what = 'magnetSeatModel';
|
|
171
|
+
optionsOf(what, o, '{ fit: \'press\', thickness: 5 }');
|
|
172
|
+
const pr = printerOf(what, o.printer), dir = directionOf(what, o, '-z'), out = [], rests = [];
|
|
173
|
+
const model = typeof p === 'object' && p?.kind === 'magnet', n = model ? p : parseMagnet(p);
|
|
174
|
+
// The fit by default: crush ribs for a disc standing in its pocket, glue for one lying on its side (ribs would hang
|
|
175
|
+
// from its roof) and for a block. A press grips well, but its hoop stress splits a thin wall: an 8x3 disc in PLA at
|
|
176
|
+
// x1c.magnet_press is stretched 24.6 MPa round its hoop against 39 / 2, a 10x5x2 block 39.4 MPa against 39
|
|
177
|
+
const fit = oneOf(what, 'fit', o.fit ?? (n.shape === 'disc' && !dir.across ? 'ribs' : 'glue'), MAGNET_FITS), facing = oneOf(what, 'facing', o.facing ?? 'open', ['open', 'floor']);
|
|
178
|
+
const recess = o.recess ?? 0;
|
|
179
|
+
if (!(isNum(recess) && recess >= 0)) throw new Error(`${what}: recess is how far under the face the magnet sits, 0 mm or more (got ${shown(o.recess)})`);
|
|
180
|
+
const mat = materialOf(what, o.material ?? 'pla', o.sets);
|
|
181
|
+
const layer = pr.n('layer'), least = r3(DEFAULTS.magnet_floor.value * layer), depth = r3(n.thickness + recess);
|
|
182
|
+
// The floor: what the part leaves under the pocket, and (facing the floor) the gap the pull goes across
|
|
183
|
+
let floor = null, thickness = null;
|
|
184
|
+
if (o.thickness != null) {
|
|
185
|
+
thickness = positive(what, 'thickness', o.thickness); floor = r3(thickness - depth);
|
|
186
|
+
if (floor < least - 1e-9) throw new Error(`${what}: a pocket ${mm(depth)} mm deep in a part ${mm(thickness)} mm thick there leaves a floor of ${mm(floor)} mm under the magnet, under fixings.magnet_floor's ${DEFAULTS.magnet_floor.value} layers (${mm(least)} mm at ${pr.cite('layer')} ${mm(layer)} mm): too thin to print whole, and the magnet pulls through it. Make the part ${mm(r3(depth + least))} mm thick there, or the pocket shallower`);
|
|
187
|
+
rests.push(rest('fixings.magnet_floor', DEFAULTS.magnet_floor), pr.rest('layer'));
|
|
188
|
+
} else if (facing === 'floor') throw new Error(`${what}: facing 'floor' pulls through the floor under the pocket: give thickness, the part's along the pocket, so the floor is known`);
|
|
189
|
+
// (a model handed in is built again with these options, so its pull is taken across this floor and held to this load)
|
|
190
|
+
const m = magnetModel(p, { grade: o.grade, gap: (facing === 'floor' ? floor : 0) + (o.gap ?? (model ? p.gap : 0)), count: o.count, load: o.load, pull: o.pull });
|
|
191
|
+
rests.push(...m.rests); out.push(...m.findings);
|
|
192
|
+
// The pocket: the magnet, plus hole_comp as any printed hole, less magnet_press or plus magnet_glue
|
|
193
|
+
const comp = pr.n('hole_comp'), k = fit === 'press' ? 'magnet_press' : 'magnet_glue', c = pr.n(k), clearance = r3(fit === 'press' ? -c : c);
|
|
194
|
+
rests.push(pr.rest('hole_comp'), pr.rest(k));
|
|
195
|
+
const disc = m.shape === 'disc', nominal = disc ? [m.diameter] : [m.length, m.width], drawn = nominal.map((x) => r3(x + comp + clearance)), rules = [pr.cite('hole_comp'), pr.cite(k)];
|
|
196
|
+
let ribs = null, relief = null;
|
|
197
|
+
if (fit === 'ribs') {
|
|
198
|
+
if (!disc) throw new Error(`${what}: crush ribs are for a round pocket: a block magnet's pocket is pressed or glued`);
|
|
199
|
+
if (dir.across) throw new Error(`${what}: crush ribs lying on their side (${said(dir.into)}) hang from the pocket's roof: stand the pocket up, or press or glue the magnet`);
|
|
200
|
+
const crush = pr.n('magnet_crush'), tips = r3(m.diameter + comp - crush), line = pr.n('line'), protrude = r3((drawn[0] - tips) / 2);
|
|
201
|
+
ribs = { count: 3, tips, radius: r3(Math.max(line / 2, protrude)), protrude }; rules.push(pr.cite('magnet_crush')); rests.push(pr.rest('magnet_crush'), pr.rest('line'));
|
|
202
|
+
}
|
|
203
|
+
if (!disc) {
|
|
204
|
+
if (dir.across) throw new Error(`${what}: a block magnet's pocket lying on its side (${said(dir.into)}) has a flat roof hanging over it: stand the pocket up (into -z, down from a top face)`);
|
|
205
|
+
relief = r3(pr.n('line')); rests.push(pr.rest('line'));
|
|
206
|
+
}
|
|
207
|
+
if (dir.into === '+z') {
|
|
208
|
+
const span = disc ? drawn[0] : Math.min(...drawn), bridge = pr.n('bridge');
|
|
209
|
+
if (span > bridge + 1e-9) throw new Error(`${what}: a pocket going up from the bed ${mm(span)} mm across has its floor printed over it as a bridge, wider than ${pr.cite('bridge')} ${mm(bridge)} mm: print the part with the pocket opening upward (into -z)`);
|
|
210
|
+
rests.push(pr.rest('bridge'));
|
|
211
|
+
}
|
|
212
|
+
const lead = fit === 'glue' || dir.across || !disc ? 0 : r3(Math.min(pr.n('chamfer'), depth / 3));
|
|
213
|
+
if (lead) rests.push(pr.rest('chamfer'));
|
|
214
|
+
const pocket = { shape: disc ? 'round' : 'rect', diameter: disc ? drawn[0] : null, size: disc ? null : drawn, nominal, comp, clearance, depth, lead, into: dir.into, axis: dir.axis, teardrop: disc && dir.across, ribs, relief, rules };
|
|
215
|
+
const across = disc ? `${mm(drawn[0])} mm across` : `${mm(drawn[0])} x ${mm(drawn[1])} mm`;
|
|
216
|
+
out.push(finding('info', `${m.name}'s ${fit === 'ribs' ? 'ribbed' : fit} pocket drawn ${across}, ${mm(depth)} mm deep${recess ? ` (the magnet ${mm(recess)} mm under the face)` : ''}: the magnet's ${nominal.map(mm).join(' x ')} mm, plus ${pr.cite('hole_comp')} ${mm(comp)} mm since a printed hole comes out small, ${fit === 'press' ? 'less' : 'plus'} ${pr.cite(k)} ${mm(c)} mm (${pr.rest(k).kind})${ribs ? `, with ${ribs.count} crush ribs whose tips stand ${mm(ribs.tips)} mm across (${pr.cite('magnet_crush')} ${mm(pr.n('magnet_crush'))} mm inside the magnet and hole_comp)` : ''}${relief ? `, its corners relieved by ${mm(relief)} mm round cuts so the block's square corners go in and no inside corner is square` : ''}${lead ? `, a ${mm(lead)} mm lead-in at its mouth` : ''}`,
|
|
217
|
+
'magnet.pocket', { values: { diameter: pocket.diameter, size: pocket.size, depth, clearance }, refs: { magnet: m.name, fit, rule: pr.cite(k), kind: pr.rest(k).kind } }));
|
|
218
|
+
if (fit === 'press') out.push(finding('info', `a magnet is sold within ±${mm(MAGNETS.tolerance.value)} mm (magnets.tolerance), as much as the ${mm(c)} mm press: a small one may drop in loose and a large one split the pocket. Crush ribs (fit 'ribs') take up the spread`, 'magnet.tolerance', { values: { tolerance: MAGNETS.tolerance.value, press: c } }));
|
|
219
|
+
out.push(finding('pass', `${said(dir.into)}, the pocket ${dir.across ? 'is a teardrop: a 45° roof, so it prints with no support' : dir.into === '+z' ? `opens on the bed, its floor a ${mm(disc ? drawn[0] : Math.min(...drawn))} mm bridge` : 'opens upward, so it prints as drawn'}${floor != null ? `; it leaves a ${mm(floor)} mm floor, ${DEFAULTS.magnet_floor.value} layers or more (fixings.magnet_floor)` : ''}`, 'magnet.printable', { values: { into: dir.into, floor } }));
|
|
220
|
+
// The pull out of the pocket: facing the open face, the magnet's own pull on its steel draws it out against the fit
|
|
221
|
+
let hold = null, holdMargin = null;
|
|
222
|
+
const want = DEFAULTS.load_margin.value, mu = DEFAULTS.clamp_friction.value, wall = disc ? Math.PI * m.diameter * m.thickness : 2 * (m.length + m.width) * m.thickness;
|
|
223
|
+
if (facing === 'floor') out.push(finding('pass', `the steel is past the floor, so the magnet's pull holds it down in its pocket: it cannot pull out (the ${mm(floor)} mm floor is its gap)`, 'magnet.pullout', { values: { floor } }));
|
|
224
|
+
else if (fit === 'glue') out.push(finding('info', `glued, the magnet stays in its pocket by its glue, whose strength is its maker's and not checked here: it is pulled out with ${mm(m.pull)} N, so the glue must hold ${mm(n1(want * m.pull))} N (fixings.load_margin times the pull) over ${mm(n1(wall))} mm² of wall`, 'magnet.pullout', { values: { pull: m.pull, area: n1(wall) } }));
|
|
225
|
+
else {
|
|
226
|
+
let says;
|
|
227
|
+
if (fit === 'press') { // a rigid magnet in a hole in a wide plate: p = E (i / d) / (1 + ν), held by friction over its wall
|
|
228
|
+
const E = mat.modulus.value, nu = mat.poisson?.value ?? 0.35, p0 = (E * (c / (disc ? m.diameter : Math.min(m.length, m.width)))) / (1 + nu);
|
|
229
|
+
hold = n1(mu * p0 * wall); rests.push(rest(mat.modulus.name, mat.modulus), ...(mat.poisson ? [rest(mat.poisson.name, mat.poisson)] : []), rest('fixings.clamp_friction', DEFAULTS.clamp_friction));
|
|
230
|
+
says = `a ${mm(c)} mm press in ${mat.name} grips at about ${mm(n2(p0))} MPa (p = E i / d / (1 + ν), ${mat.modulus.name} ${mm(E)} MPa, ν ${mm(nu)}${mat.poisson ? '' : ', taken for a plastic with none in its rule set'}), ${mm(hold)} N over its ${mm(n1(wall))} mm² wall at fixings.clamp_friction ${mm(mu)}: an estimate, which a plastic loses some of as it creeps`;
|
|
231
|
+
} else { // crush ribs crushed: each presses at the plastic's strength over a line's width
|
|
232
|
+
const S = mat.strength.value, w = pr.n('line'), area = ribs.count * w * m.thickness;
|
|
233
|
+
hold = n1(mu * S * area); rests.push(rest(mat.strength.name, mat.strength), rest('fixings.clamp_friction', DEFAULTS.clamp_friction));
|
|
234
|
+
says = `${ribs.count} crush ribs, crushed, press at ${mat.name}'s ${mm(S)} MPa over ${mm(n2(area))} mm² (a ${mm(w)} mm line by the magnet's ${mm(m.thickness)} mm each), ${mm(hold)} N at fixings.clamp_friction ${mm(mu)}: an estimate`;
|
|
235
|
+
}
|
|
236
|
+
if (fit === 'press') { // the pocket's wall, round a rigid magnet in a wide plate, is stretched round its hoop by the same pressure
|
|
237
|
+
const p0 = (mat.modulus.value * (c / (disc ? m.diameter : Math.min(m.length, m.width)))) / (1 + (mat.poisson?.value ?? 0.35)), S = mat.strength.value;
|
|
238
|
+
out.push(finding(p0 <= S / want + 1e-9 ? 'pass' : p0 <= S + 1e-9 ? 'warn' : 'fail', `the press stretches the pocket's wall round its hoop at about ${mm(n2(p0))} MPa, against ${mat.strength.name} ${mm(S)} MPa${p0 <= S / want + 1e-9 ? '' : p0 <= S ? `: under ${mm(want)} times over, so a magnet at the top of its tolerance may split a thin wall. Crush ribs (fit 'ribs') press far less` : ': it splits the wall. Use crush ribs (fit \'ribs\') or glue'}`, 'magnet.wall', { values: { hoop: n2(p0), strength: S } }));
|
|
239
|
+
}
|
|
240
|
+
holdMargin = n2(hold / m.pull);
|
|
241
|
+
out.push(finding(holdMargin >= want ? 'pass' : holdMargin >= 1 ? 'warn' : 'fail', `the magnet is pulled out of its pocket with its own ${mm(m.pull)} N: ${says}, ${mm(holdMargin)} times the pull${holdMargin >= want ? '' : holdMargin >= 1 ? `, under the ${mm(want)} times fixings.load_margin asks: glue it as well` : ': it comes out, so glue it'}`,
|
|
242
|
+
'magnet.pullout', { values: { hold, pull: m.pull, margin: holdMargin } }));
|
|
243
|
+
}
|
|
244
|
+
return { kind: 'magnet-seat', magnet: m, fit, facing, pocket, floor, thickness, hold, holdMargin, rests, findings: out };
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* A magnet's pocket, to subtract: round (a teardrop lying on its side) with crush ribs where asked, or a block's with
|
|
249
|
+
* its corners relieved, the size magnetSeatModel gives it, from the point at on the face going into the part.
|
|
250
|
+
* @param {string | Magnet} p @param {object} [o] as magnetSeatModel, and at: the point on the face where the pocket starts
|
|
251
|
+
* @returns {object} a JSCAD geom3 with .model holding magnetSeatModel's numbers
|
|
252
|
+
*/
|
|
253
|
+
export function magnetSeat(p, o = {}) {
|
|
254
|
+
const what = 'magnetSeat', s = magnetSeatModel(p, optionsOf(what, o, '{ fit: \'ribs\', at: [0, 0, 5] }')), at = pointOf(what, o.at), q = s.pocket;
|
|
255
|
+
let g;
|
|
256
|
+
if (q.shape === 'round') {
|
|
257
|
+
const r = q.diameter / 2, steps = q.lead ? [[r + q.lead, 0], [r, q.lead], [r, q.depth]] : [[r, q.depth]];
|
|
258
|
+
g = q.teardrop ? teardrop(steps, UP[q.into]) : bore(steps);
|
|
259
|
+
if (q.ribs) {
|
|
260
|
+
const { count, radius, protrude } = q.ribs, a = Array.from({ length: count }, (_, i) => (2 * Math.PI * i) / count + Math.PI / 2);
|
|
261
|
+
g = subtract(g, crushRibs({ at: a.map((t) => [r * Math.cos(t), r * Math.sin(t)]), into: a.map((t) => [-Math.cos(t), -Math.sin(t)]), z: [-q.depth - OUT, q.lead ? -q.lead : OUT], radius, protrude }));
|
|
262
|
+
}
|
|
263
|
+
} else {
|
|
264
|
+
const [L, W] = q.size, h = q.depth + OUT, box = translate([0, 0, OUT - h / 2], cuboid({ size: [L, W, h] }));
|
|
265
|
+
const corners = [[1, 1], [-1, 1], [-1, -1], [1, -1]].map(([sx, sy]) => translate([(sx * L) / 2, (sy * W) / 2, OUT - h / 2], cylinder({ radius: q.relief, height: h, segments: 16 })));
|
|
266
|
+
g = union(box, ...corners);
|
|
267
|
+
}
|
|
268
|
+
return Object.assign(along(g, q.into, at), { model: s });
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* 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
|
|
273
|
+
* @returns {object} a JSCAD geom3 with .model
|
|
274
|
+
*/
|
|
275
|
+
export function magnet(p, o = {}) {
|
|
276
|
+
const m = magnetModel(p, o);
|
|
277
|
+
const g = m.shape === 'disc' ? cylinder({ radius: m.diameter / 2, height: m.thickness, center: [0, 0, m.thickness / 2], segments: 32 }) : cuboid({ size: [m.length, m.width, m.thickness], center: [0, 0, m.thickness / 2] });
|
|
278
|
+
return Object.assign(g, { model: m });
|
|
279
|
+
}
|
package/model.d.mts
CHANGED
|
@@ -3,8 +3,8 @@ export function oneOf(what: any, k: any, v: any, list: any): any;
|
|
|
3
3
|
/**
|
|
4
4
|
* A fixing's name read by the grammar, before any rule set is looked at.
|
|
5
5
|
* @param {string} name 'M3', 'M3x12 cap', '1/4-20 x 1/2 cap', 'M4 lock nut', 'K30x10 pan torx'
|
|
6
|
-
* @returns {{ thread: string, form: 'metric' | 'unified' | 'plastic', length: number | null, unit: 'mm' | 'in' | null, item: 'thread' | 'screw' | 'nut' | 'washer' | 'insert', head: string | null, nut: string | null, extra: string[] }}
|
|
7
|
-
* length: as written, in unit (null: the thread's own, mm or inches); extra: words left for the rule set's variants
|
|
6
|
+
* @returns {{ thread: string, form: 'metric' | 'unified' | 'plastic', length: number | null, unit: 'mm' | 'in' | null, item: 'thread' | 'screw' | 'nut' | 'washer' | 'insert', head: string | null, nut: string | null, extra: string[], printed?: boolean }}
|
|
7
|
+
* length: as written, in unit (null: the thread's own, mm or inches); extra: words left for the rule set's variants; printed: the word printed was said
|
|
8
8
|
*/
|
|
9
9
|
export function parseName(name: string): {
|
|
10
10
|
thread: string;
|
|
@@ -15,6 +15,7 @@ export function parseName(name: string): {
|
|
|
15
15
|
head: string | null;
|
|
16
16
|
nut: string | null;
|
|
17
17
|
extra: string[];
|
|
18
|
+
printed?: boolean;
|
|
18
19
|
};
|
|
19
20
|
/**
|
|
20
21
|
* The threads there are rule sets for, as each is written: the kit's, and a workspace's own first.
|
|
@@ -101,7 +102,7 @@ export function fixingOf(what: string, m: Fixing | string, o?: {
|
|
|
101
102
|
/**
|
|
102
103
|
* The printer's rules as fixings reads them. Handed nothing, the kit's X1C. Handed a rule set ({ name, rules }), its
|
|
103
104
|
* figures with their kinds and sources. Handed plain numbers (a design's v.x1c), those, marked as given. A basic
|
|
104
|
-
* clearance the printer lacks (hole_comp, fit, layer, line, chamfer, bridge, overhang, slip, press, thread_gap) is borrowed from the X1C
|
|
105
|
+
* clearance the printer lacks (hole_comp, fit, layer, line, chamfer, bridge, overhang, slip, press, thread_gap, snap_clearance, pin_press, pin_slip, magnet_press, magnet_glue, magnet_crush) is borrowed from the X1C
|
|
105
106
|
* and cited as the X1C's; a measured figure (pilot_m3) is never borrowed, since it was measured on that machine.
|
|
106
107
|
* @param {string} what @param {object} [p] @returns {Printer}
|
|
107
108
|
*/
|
package/model.mjs
CHANGED
|
@@ -54,6 +54,9 @@ export const DEFAULTS = {
|
|
|
54
54
|
tip_room: { value: 1, unit: 'mm', rule: 'A screw\'s tip stops at least this far short of the bottom of a blind hole, so it tightens on its head and not on its tip: an estimate, the millimetre an insert\'s blind hole is given past the insert', kind: 'estimate', source: 'A working figure of this package, after insert_depth in the thread rule sets (the insert\'s length and 1 mm)', checked: '2026-11-15' },
|
|
55
55
|
load_margin: { value: 2, unit: '× load', rule: 'A printed joint is sized to hold about twice the load it is given', kind: 'default', source: 'The kit\'s standard for printed parts: sized from the load with about twice the margin', checked: '2026-11-15' },
|
|
56
56
|
clamp_friction: { value: 0.3, unit: '× clamp force', rule: 'The friction between two printed parts clamped by screws, for whether a joint slips before its screws bear on their holes: an estimate. No measured figure for PLA on PLA at rest was found; the figures found are for printed PLA sliding on steel, about 0.38 to 0.57, and 0.3 is taken under them', kind: 'estimate', source: 'Sliding friction of printed PLA on steel: Pawlak, kinetic 0.49 (https://yadda.icm.edu.pl/baztech/element/bwmeta1.element.baztech-f7c60c77-2f7e-4c4f-8d4e-f962d0c503e7/c/pawlak.pdf), and Sirin et al., Rapid Prototyping Journal 2023, 0.38 to 0.57 pin on disc (https://www.emerald.com/insight/content/doi/10.1108/RPJ-03-2022-0081/full/html); to be measured on the fixings coupon', checked: '2026-11-15' },
|
|
57
|
+
snap_play: { value: 0.5, unit: 'mm', rule: 'A snap pin\'s shaft may be at most this much longer than the parts it goes through: the barb clicks out that far past the far face. Longer, and the pin rattles in its hole', kind: 'estimate', source: 'A working figure of this package: the launcher\'s pins are drawn 0.2 mm (x1c.fit) longer than their parts. No coupon row measures it, so it stays an estimate: snap pins a step longer each through one plate, the longest that does not rattle, would measure it', checked: '2026-11-21' },
|
|
58
|
+
pin_least: { value: 2, unit: 'mm', rule: 'The thinnest snap pin or printed plain pin: under this a peg is a few print lines across and breaks as it goes in. Thinner pins are filament or steel', kind: 'estimate', source: 'A working figure of this package: about five 0.42 mm lines across, the thinnest the kit draws a snap pin (2.5 mm, the tensioner\'s) less a margin. No coupon row measures it (the holds coupon\'s thinnest snap pin is 3 mm), so it stays an estimate: snap pins of 1.5, 2 and 2.5 mm pushed through their sockets, the thinnest that does not break, would measure it', checked: '2026-11-21' },
|
|
59
|
+
magnet_floor: { value: 3, unit: 'layers', rule: 'The least floor left under a magnet\'s pocket: three solid layers, so the floor prints whole and the magnet cannot be pulled through it. A floor the magnet pulls through is also its gap, so thinner pulls harder', kind: 'estimate', source: 'A working figure of this package, after Bambu Studio\'s default of three bottom shell layers. No coupon row measures it (the holds coupon\'s pockets have a hole under them), so it stays an estimate: pockets with floors of 2, 3 and 4 layers, the thinnest a magnet does not pull through or show through, would measure it', checked: '2026-11-21' },
|
|
57
60
|
brass_density: { value: 8.47, unit: 'g/cm³', rule: 'Density of free-machining brass CW614N (CuZn39Pb3), taken for a heat-set insert. The insert maker\'s sheet names no alloy, so the alloy is assumed', kind: 'estimate', source: 'Aalco, CW614N brass rod datasheet, https://www.aalco.co.uk/datasheets/Copper-and-Copper-Alloys-CW614N-Brass-Rod_31.ashx', checked: '2026-11-15' }
|
|
58
61
|
};
|
|
59
62
|
|
|
@@ -93,7 +96,8 @@ export const GRAMMAR = [
|
|
|
93
96
|
'word = "cap" | "button" | "countersunk" | "hex" | "set" | "pan" a screw\'s head form',
|
|
94
97
|
' | [ "hex" | "square" | "lock" ] "nut" a nut (hex if not said)',
|
|
95
98
|
' | "washer" | "insert" a plain washer, a heat-set insert',
|
|
96
|
-
' | a variant of the thread\'s rule set torx, on a PT screw'
|
|
99
|
+
' | a variant of the thread\'s rule set torx, on a PT screw',
|
|
100
|
+
' | "printed" a screw or nut printed with its thread, not bought'
|
|
97
101
|
].join('\n');
|
|
98
102
|
|
|
99
103
|
/** The head forms a screw's name can say. */
|
|
@@ -110,8 +114,8 @@ const inches = (text) => { const [whole, frac] = /\//.test(text) ? (/\s/.test(te
|
|
|
110
114
|
/**
|
|
111
115
|
* A fixing's name read by the grammar, before any rule set is looked at.
|
|
112
116
|
* @param {string} name 'M3', 'M3x12 cap', '1/4-20 x 1/2 cap', 'M4 lock nut', 'K30x10 pan torx'
|
|
113
|
-
* @returns {{ thread: string, form: 'metric' | 'unified' | 'plastic', length: number | null, unit: 'mm' | 'in' | null, item: 'thread' | 'screw' | 'nut' | 'washer' | 'insert', head: string | null, nut: string | null, extra: string[] }}
|
|
114
|
-
* length: as written, in unit (null: the thread's own, mm or inches); extra: words left for the rule set's variants
|
|
117
|
+
* @returns {{ thread: string, form: 'metric' | 'unified' | 'plastic', length: number | null, unit: 'mm' | 'in' | null, item: 'thread' | 'screw' | 'nut' | 'washer' | 'insert', head: string | null, nut: string | null, extra: string[], printed?: boolean }}
|
|
118
|
+
* length: as written, in unit (null: the thread's own, mm or inches); extra: words left for the rule set's variants; printed: the word printed was said
|
|
115
119
|
*/
|
|
116
120
|
export function parseName(name) {
|
|
117
121
|
const what = 'fixing name', help = `A name is a thread, then a length and what it is where it has them: 'M3', 'M3x12 cap', '1/4-20 x 1/2 button', 'M4 lock nut', 'M3 insert'`;
|
|
@@ -126,14 +130,15 @@ export function parseName(name) {
|
|
|
126
130
|
const l = /^\s*[x×*]\s*(\d+\s+\d+\/\d+|\d+\/\d+|\d*\.?\d+)\s*(mm\b|in\b|"|”)?/i.exec(tail);
|
|
127
131
|
if (l) { length = inches(l[1]); unit = l[2] ? (/mm/i.test(l[2]) ? 'mm' : 'in') : null; tail = tail.slice(l[0].length); if (!(length > 0)) throw new Error(`${what}: "${name}": a length is above 0 (got ${l[1]})`); }
|
|
128
132
|
else if (/^\s*[x×*]/.test(tail)) throw new Error(`${what}: "${name}": after the x comes a length (M3x12, 1/4-20 x 1/2). ${help}`);
|
|
129
|
-
const
|
|
133
|
+
const all = tail.toLowerCase().split(/[\s,]+/).filter(Boolean).filter((w) => !NOISE.includes(w)), printed = all.includes('printed'), words = all.filter((w) => w !== 'printed');
|
|
130
134
|
const items = words.filter((w) => ITEMS.includes(w));
|
|
131
135
|
if (items.length > 1) throw new Error(`${what}: "${name}" names ${items.join(' and ')}: one thing at a time`);
|
|
132
136
|
const item = items[0] ?? null, others = words.filter((w) => !ITEMS.includes(w)), table = item === 'nut' ? NUT_WORDS : item ? {} : HEAD_WORDS;
|
|
133
137
|
const forms = [...new Set(others.filter((w) => w in table).map((w) => table[w]))], extra = others.filter((w) => !(w in table));
|
|
134
138
|
if (forms.length > 1) throw new Error(`${what}: "${name}" says ${forms.join(' and ')}: ${item === 'nut' ? 'a nut is one of' : 'a head is one of'} ${(item === 'nut' ? NUTS : HEADS).join(', ')}`);
|
|
135
139
|
if (item === 'nut' || item === 'washer') { if (length != null) throw new Error(`${what}: "${name}": a ${item} has no length`); }
|
|
136
|
-
|
|
140
|
+
if (printed && (item === 'washer' || item === 'insert' || form === 'plastic')) throw new Error(`${what}: "${name}": only a screw or a nut is printed with its thread${form === 'plastic' ? ' (a screw for plastic forms its own thread, and is bought)' : ''}`);
|
|
141
|
+
return { thread, form, length, unit, item: item ?? (length != null || forms[0] ? 'screw' : 'thread'), head: item ? null : forms[0] ?? null, nut: item === 'nut' ? forms[0] ?? 'hex' : null, extra, ...(printed ? { printed: true } : {}) };
|
|
137
142
|
}
|
|
138
143
|
|
|
139
144
|
// ---------- rule sets by thread ----------
|
|
@@ -312,7 +317,7 @@ export function fixingModel(name, change = {}, opts = {}) {
|
|
|
312
317
|
m.head = headOf(what, m, p.head ?? (m.made.heads.includes('cap') ? 'cap' : m.made.heads[0]));
|
|
313
318
|
// (the list of lengths is the socket cap screw's: a set screw is sold shorter, so its length is not held to it)
|
|
314
319
|
if (given != null && m.head.form === 'set') m.length = positive(what, 'length', given);
|
|
315
|
-
else if (given != null) Object.assign(m, lengthOf(what, m, given, !!opts?.anyLength));
|
|
320
|
+
else if (given != null) Object.assign(m, lengthOf(what, m, given, !!opts?.anyLength || !!p.printed)); // (a printed screw is printed at any length)
|
|
316
321
|
} else if (p.item === 'nut') m.nut = nutOf(what, m, p.nut);
|
|
317
322
|
else if (p.item === 'washer') { if (!m.made.washer) throw new Error(`${what}: ${m.thread} has no washer in its rule set (${set.name})`); }
|
|
318
323
|
else if (p.item === 'insert') {
|
|
@@ -324,9 +329,10 @@ export function fixingModel(name, change = {}, opts = {}) {
|
|
|
324
329
|
}
|
|
325
330
|
m.length = figure(what, m, 'insert_length');
|
|
326
331
|
}
|
|
327
|
-
const also = m.variant ? ` ${m.variant}` : ''
|
|
332
|
+
const also = `${m.variant ? ` ${m.variant}` : ''}${p.printed ? ' printed' : ''}`;
|
|
333
|
+
if (p.printed) m.printed = true;
|
|
328
334
|
m.name = m.item === 'thread' ? `${m.thread}${also}` : m.item === 'screw' ? `${screwName(m, m.length, m.head.form)}${also}`
|
|
329
|
-
: m.item === 'nut' ? `${m.thread} ${m.nut.kind} nut` : m.item === 'washer' ? `${m.thread} washer` : form === 'unified' ? `${m.thread} x ${mm(m.length)} mm insert` : `${m.thread}x${mm(m.length)} insert`;
|
|
335
|
+
: m.item === 'nut' ? `${m.thread} ${m.nut.kind} nut${also}` : m.item === 'washer' ? `${m.thread} washer` : form === 'unified' ? `${m.thread} x ${mm(m.length)} mm insert` : `${m.thread}x${mm(m.length)} insert`;
|
|
330
336
|
return m;
|
|
331
337
|
}
|
|
332
338
|
|
|
@@ -342,7 +348,7 @@ export function fixingOf(what, m, o = {}) {
|
|
|
342
348
|
}
|
|
343
349
|
|
|
344
350
|
// ---------- the printer ----------
|
|
345
|
-
const BASICS = ['hole_comp', 'fit', 'layer', 'line', 'chamfer', 'bridge', 'overhang', 'slip', 'press', 'thread_gap'];
|
|
351
|
+
const BASICS = ['hole_comp', 'fit', 'layer', 'line', 'chamfer', 'bridge', 'overhang', 'slip', 'press', 'thread_gap', 'snap_clearance', 'pin_press', 'pin_slip', 'magnet_press', 'magnet_glue', 'magnet_crush'];
|
|
346
352
|
/**
|
|
347
353
|
* @typedef {{ name: string, figure: (k: string) => (Figure & { name: string, borrowed?: boolean }) | null, n: (k: string) => number, cite: (k: string) => string, rest: (k: string) => object }} Printer
|
|
348
354
|
* figure: a rule of the printer's own (never borrowed); n: a basic clearance as a number, the printer's own or, where it
|
|
@@ -351,7 +357,7 @@ const BASICS = ['hole_comp', 'fit', 'layer', 'line', 'chamfer', 'bridge', 'overh
|
|
|
351
357
|
/**
|
|
352
358
|
* The printer's rules as fixings reads them. Handed nothing, the kit's X1C. Handed a rule set ({ name, rules }), its
|
|
353
359
|
* figures with their kinds and sources. Handed plain numbers (a design's v.x1c), those, marked as given. A basic
|
|
354
|
-
* clearance the printer lacks (hole_comp, fit, layer, line, chamfer, bridge, overhang, slip, press, thread_gap) is borrowed from the X1C
|
|
360
|
+
* clearance the printer lacks (hole_comp, fit, layer, line, chamfer, bridge, overhang, slip, press, thread_gap, snap_clearance, pin_press, pin_slip, magnet_press, magnet_glue, magnet_crush) is borrowed from the X1C
|
|
355
361
|
* and cited as the X1C's; a measured figure (pilot_m3) is never borrowed, since it was measured on that machine.
|
|
356
362
|
* @param {string} what @param {object} [p] @returns {Printer}
|
|
357
363
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulecad/fixings",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Screws, nuts, washers and inserts from rule sets, and the holes and seats they need in printed parts: a fixing as a model with sourced figures, holes sized by what they are for, counterbores, countersinks, nut pockets and insert bosses that print without supports, light solids of the hardware for an assembly, threads cut for printing, and first sums for a joint (engagement, stripping, preload, seating, the sold length that fits).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -19,6 +19,9 @@
|
|
|
19
19
|
"threads.mjs",
|
|
20
20
|
"strength.mjs",
|
|
21
21
|
"draw.mjs",
|
|
22
|
+
"pins.mjs",
|
|
23
|
+
"magnets.mjs",
|
|
24
|
+
"bolts.mjs",
|
|
22
25
|
"fixings.d.mts",
|
|
23
26
|
"model.d.mts",
|
|
24
27
|
"holes.d.mts",
|
|
@@ -27,6 +30,9 @@
|
|
|
27
30
|
"threads.d.mts",
|
|
28
31
|
"strength.d.mts",
|
|
29
32
|
"draw.d.mts",
|
|
33
|
+
"pins.d.mts",
|
|
34
|
+
"magnets.d.mts",
|
|
35
|
+
"bolts.d.mts",
|
|
30
36
|
"README.md",
|
|
31
37
|
"CHANGELOG.md",
|
|
32
38
|
"LICENSE"
|
|
@@ -53,7 +59,7 @@
|
|
|
53
59
|
"@jscad/modeling": "^2.12.0"
|
|
54
60
|
},
|
|
55
61
|
"dependencies": {
|
|
56
|
-
"@rulecad/rules": "^0.3.
|
|
62
|
+
"@rulecad/rules": "^0.3.19",
|
|
57
63
|
"@rulecad/shapes": "^0.4.4"
|
|
58
64
|
}
|
|
59
65
|
}
|