@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/strength.mjs
CHANGED
|
@@ -26,7 +26,7 @@ const options = (what, o, example) => { if (o == null || typeof o !== 'object' |
|
|
|
26
26
|
|
|
27
27
|
// A material from what a function was handed: a kit set's name ('PLA'), the workspace's set of that name (sets), or a
|
|
28
28
|
// rule set itself. Its class is told by its stiffness: under 20 GPa a plastic, under 100 GPa an aluminium, else a steel.
|
|
29
|
-
function materialOf(what, material, sets) {
|
|
29
|
+
export function materialOf(what, material, sets) {
|
|
30
30
|
if (material == null) throw new Error(`${what}: give a material, what the thread is in or the head sits on: ${MATERIALS.join(', ')}, or a rule set with a strength ({ name, rules })`);
|
|
31
31
|
let set = null;
|
|
32
32
|
if (typeof material === 'object' && material.rules && typeof material.rules === 'object') set = material;
|
|
@@ -36,10 +36,10 @@ function materialOf(what, material, sets) {
|
|
|
36
36
|
if (!set) throw new Error(`${what}: no material "${material}". There are: ${MATERIALS.join(', ')}. For another, hand in its rule set ({ name, rules: { strength, modulus } }), or the workspace's sets with it in`);
|
|
37
37
|
} else throw new Error(`${what}: material is a material's name (${MATERIALS.join(', ')}) or its rule set ({ name, rules }), not ${shown(material)}`);
|
|
38
38
|
const name = set.name ?? 'the material', num = (k) => { const f = set.rules[k]; if (f && !(isNum(f.value) && f.value > 0)) throw new Error(`${what}: ${name}.${k} is a number above 0 (got ${shown(f.value)})`); return f ? { ...f, name: `${name}.${k}` } : null; };
|
|
39
|
-
const strength = num('strength'), across = num('strength_z'), modulus = num('modulus');
|
|
39
|
+
const strength = num('strength'), across = num('strength_z'), modulus = num('modulus'), density = num('density'), poisson = num('poisson');
|
|
40
40
|
if (!strength) throw new Error(`${what}: ${name} has no strength in its rule set: a tensile or yield strength in MPa is needed`);
|
|
41
41
|
if (!modulus) throw new Error(`${what}: ${name} has no modulus in its rule set, which tells a plastic from a metal`);
|
|
42
|
-
return { name, cls: modulus.value < 20000 ? 'plastic' : modulus.value < 100000 ? 'aluminium' : 'steel', strength, across, modulus };
|
|
42
|
+
return { name, cls: modulus.value < 20000 ? 'plastic' : modulus.value < 100000 ? 'aluminium' : 'steel', strength, across, modulus, density, poisson };
|
|
43
43
|
}
|
|
44
44
|
// The class of material an engagement rule is read by: a class by name, or a material's
|
|
45
45
|
function classOf(what, material, sets) {
|
|
@@ -48,14 +48,21 @@ function classOf(what, material, sets) {
|
|
|
48
48
|
return materialOf(what, material, sets);
|
|
49
49
|
}
|
|
50
50
|
// The weaker of a printed material's two strengths, with what it says about itself
|
|
51
|
-
function weakest(mat) {
|
|
51
|
+
export function weakest(mat) {
|
|
52
52
|
const f = mat.across && mat.across.value < mat.strength.value ? mat.across : mat.strength;
|
|
53
53
|
const note = mat.cls !== 'plastic' ? '' : mat.across ? ` (${f.name}, the weaker way of the print)` : ` (${mat.name} has no strength across its layers, strength_z: the strength along them is used, and a screw standing across the layers may hold less)`;
|
|
54
54
|
return { f, note };
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
// A screw's own strength: its tensile stress area, and its proof load from its property class
|
|
58
|
+
// A printed bolt (a screw named with the word printed) is refused by name: it has no property class, so no proof load,
|
|
59
|
+
// preload or torque. A printed nut is let through: the screw in it is a bought one
|
|
60
|
+
function notPrinted(what, fx) {
|
|
61
|
+
if (fx.printed && fx.item !== 'nut') throw new Error(`${what}: ${fx.name} is a printed bolt, with no property class and no proof load: it is plastic, done up by hand, and breaks at its plastic's strength. Its breaking load and the margin on a pull are printedBoltModel('${fx.name}', { material, load })${what === 'seating' ? '; the pressure under its head is seating with a force (N) given' : ''}`);
|
|
62
|
+
return fx;
|
|
63
|
+
}
|
|
58
64
|
function proofOf(what, fx, o) {
|
|
65
|
+
notPrinted(what, fx);
|
|
59
66
|
if (fx.form === 'plastic') throw new Error(`${what}: ${fx.thread} is a thread-forming screw for plastic, with no property class in its rule set (${fx.set}): its maker's sheet gives what it holds`);
|
|
60
67
|
const kind = oneOf(what, 'screw', o.screw ?? 'steel', ['steel', 'stainless']), name = kind === 'steel' ? 'proof_stress' : 'stainless_proof_stress';
|
|
61
68
|
if (o.proof != null) positive(what, 'proof (the screw\'s proof stress, in MPa)', o.proof);
|
|
@@ -141,6 +148,7 @@ export function preload(m, o = {}) {
|
|
|
141
148
|
export function torqueFor(m, o = {}) {
|
|
142
149
|
options('torqueFor', o, '{ force: 500 }');
|
|
143
150
|
if (o.torque != null) throw new Error('torqueFor: give force (N), the clamp force wanted: for the force a torque gives, use preload');
|
|
151
|
+
notPrinted('torqueFor', fixingOf('torqueFor', m, o));
|
|
144
152
|
return preload(m, o);
|
|
145
153
|
}
|
|
146
154
|
|
|
@@ -163,7 +171,7 @@ export function seating(m, o = {}) {
|
|
|
163
171
|
if (form === 'set') throw new Error(`${what}: a set screw has no head to bear on anything: it presses with its point`);
|
|
164
172
|
const head = headOf(what, fx, form), mat = materialOf(what, o.material, o.sets), kind = oneOf(what, 'hole', o.hole ?? 'clearance', ['clearance', 'close', 'loose']), h = holeModel(fx, { kind, printer: o.printer });
|
|
165
173
|
if (o.force != null && o.torque != null) throw new Error(`${what}: give force (N) or torque (N·m), not both`);
|
|
166
|
-
const K = o.K ?? DEFAULTS.nut_factor.value, screw = proofOf(what, fx, o)
|
|
174
|
+
const K = o.K ?? DEFAULTS.nut_factor.value, given = o.force != null || o.torque != null, screw = given ? null : proofOf(what, fx, o); // (the screw's proof load sets the force only when none is given)
|
|
167
175
|
if (!(isNum(K) && K > 0)) throw new Error(`${what}: K is the nut factor, a number above 0 (got ${shown(o.K)})`);
|
|
168
176
|
const force = o.force != null ? positive(what, 'force (in N)', o.force) : o.torque != null ? (positive(what, 'torque (in N·m)', o.torque) * 1000) / (K * fx.major) : DEFAULTS.preload_share.value * screw.load;
|
|
169
177
|
const across = head.flats ?? head.diameter, ring = (D) => (Math.PI / 4) * (D * D - h.diameter ** 2), area = ring(across), { f } = weakest(mat), limit = f.value, pressure = force / area, within = pressure <= limit + 1e-9;
|
|
@@ -241,10 +249,10 @@ export function lengthFor(stack, m, o = {}) {
|
|
|
241
249
|
let washer = 0; if (o.washer) { if (!fx.made.washer) throw new Error(`${what}: ${fx.thread} has no washer in its rule set (${fx.set})`); washer = figure(what, fx, 'washer_thickness'); rests.push(rest(cite(fx, 'washer_thickness'), fx.figures.washer_thickness)); }
|
|
242
250
|
const total = parts.reduce((s, t) => s + t, 0), grip = r3(total + washer - (o.sunk ?? 0));
|
|
243
251
|
if (!(grip > 0)) throw new Error(`${what}: a seat sunk ${mm(o.sunk)} mm is deeper than the ${mm(total)} mm stack it is in: nothing is left under the head`);
|
|
244
|
-
const sold = fx.figures.lengths?.value;
|
|
252
|
+
const sold = fx.printed ? Array.from({ length: 300 }, (_, i) => i + 1) : fx.figures.lengths?.value; // (a printed screw is printed to any whole millimetre)
|
|
245
253
|
if (!Array.isArray(sold) || !sold.every(isNum)) throw new Error(`${what}: ${fx.thread} lists no lengths in its rule set (${fx.set}), so none can be chosen: the length wanted is between ${mm(r3(grip + end.need))} mm${Number.isFinite(end.room) ? ` and ${mm(r3(grip + end.room - end.tip))} mm` : ' and as long as you like'}`);
|
|
246
|
-
rests.push(rest(cite(fx, 'lengths'), fx.figures.lengths));
|
|
247
|
-
const most = end.room - end.tip, verdict = (L) => (L - grip < end.need - 1e-9 ? 'short' : L - grip > most + 1e-9 ? 'long' : 'fits'), name = (L) => screwName(fx, L, form)
|
|
254
|
+
if (!fx.printed) rests.push(rest(cite(fx, 'lengths'), fx.figures.lengths));
|
|
255
|
+
const most = end.room - end.tip, verdict = (L) => (L - grip < end.need - 1e-9 ? 'short' : L - grip > most + 1e-9 ? 'long' : 'fits'), name = (L) => `${screwName(fx, L, form)}${fx.printed ? ' printed' : ''}`;
|
|
248
256
|
const lengths = sold.map((L) => ({ length: L, name: name(L), engaged: r3(Math.max(L - grip, 0)), fits: verdict(L) })), pick = lengths.find((l) => l.fits === 'fits'), below = lengths.filter((l) => l.fits === 'short').at(-1), above = lengths.find((l) => l.fits === 'long');
|
|
249
257
|
if (most < end.need - 1e-9) throw new Error(`${what}: ${end.says} leaves ${mm(r3(most))} mm of room for the screw (${end.why}) where ${mm(end.need)} mm of thread is asked: no length can do both. Deepen the far end to ${mm(r3(end.need + end.tip))} mm or more`);
|
|
250
258
|
const short = (l) => (l.length <= grip ? `${l.name} does not reach through the ${mm(grip)} mm stack` : `${l.name} would engage ${mm(l.engaged)} mm where ${mm(end.need)} mm is asked`), long = (l) => `${l.name} would ${end.ends}: ${mm(l.engaged)} mm into ${mm(r3(most))} mm of room (${end.why})`;
|
|
@@ -326,7 +334,7 @@ export function screwGroup(places, o = {}) {
|
|
|
326
334
|
export function screwLoad(m, o = {}) {
|
|
327
335
|
const what = 'screwLoad';
|
|
328
336
|
options(what, o, '{ tension: 20, depth: 5, material: \'pla\' }');
|
|
329
|
-
const fx = fixingOf(what, m, o), num = (k, v) => { if (v != null && !(isNum(v) && v >= 0)) throw new Error(`${what}: ${k} is a number of N, 0 or more (got ${shown(v)})`); return v ?? 0; };
|
|
337
|
+
const fx = notPrinted(what, fixingOf(what, m, o)), num = (k, v) => { if (v != null && !(isNum(v) && v >= 0)) throw new Error(`${what}: ${k} is a number of N, 0 or more (got ${shown(v)})`); return v ?? 0; };
|
|
330
338
|
const T = Math.max(0, isNum(o.tension) ? o.tension : num('tension', o.tension)), S = num('shear', o.shear), mu = o.friction ?? DEFAULTS.clamp_friction.value;
|
|
331
339
|
if (!(isNum(mu) && mu > 0)) throw new Error(`${what}: friction is a number above 0 (got ${shown(o.friction)})`);
|
|
332
340
|
if (o.most != null) positive(what, 'most (the clamp force the seat takes, in N)', o.most);
|