@rulecad/fixings 0.1.9 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/snaps.mjs CHANGED
@@ -1,12 +1,12 @@
1
1
  // Annular snaps: a lid that clicks on. A bead runs round the outside of a round box's wall near its rim; the lid's
2
2
  // skirt has a groove inside it the bead's shape plus a clearance. Pushed on, the bead's lead face spreads the skirt and
3
3
  // squeezes the box's wall; past it, both spring back and the bead sits in the groove with no stress left in either.
4
- // Pulled, the bead's return face has to spread the skirt again. annularSnapModel gives the forces and the hoop strain in
5
- // each part from the Bayer snap-fit design guide's annular joint (a beam on an elastic foundation: P = y d Es X, with
6
- // X from the tube's proportions), the two parts as springs in series where both give, and the strain held to the
4
+ // Pulled, the bead's return face has to spread the skirt again. annularSnapModel gives the forces and the hoop strain
5
+ // in each part from the Bayer snap-fit design guide's annular joint (a beam on an elastic foundation: P = y d Es X,
6
+ // with X from the tube's proportions), the two parts as springs in series where both give, and the strain held to the
7
7
  // plastic's limit by the guide's rule for a brief snap. annularBead is the bead to add to the box's wall, annularGroove
8
- // the groove (and the skirt's lead-in) to cut from the lid. A whole skirt on a stiff box takes a hard push; slotted into
9
- // fingers (slots), each finger bends as a cantilever and the push falls many times over: snapSlots cuts the slots.
8
+ // the groove (and the skirt's lead-in) to cut from the lid. A whole skirt on a stiff box takes a hard push; slotted
9
+ // into fingers (slots), each finger bends as a cantilever and the push falls many times over: snapSlots cuts the slots.
10
10
  // Units: mm, N, MPa, degrees.
11
11
  import { DEFAULTS, printerOf, rest, finding, positive, oneOf, isNum, shown, mm, r3 } from './model.mjs';
12
12
  import jscad from '@jscad/modeling';
@@ -14,78 +14,130 @@ import { lathe, OUT } from './draw.mjs';
14
14
  import { optionsOf } from './holes.mjs';
15
15
  import { materialOf } from './strength.mjs';
16
16
 
17
- const { polygon } = jscad.primitives, { extrudeLinear } = jscad.extrusions, { translate, rotateY, rotateZ } = jscad.transforms, { geom3 } = jscad.geometries;
18
- const n1 = (x) => +x.toFixed(1), n2 = (x) => +x.toFixed(2), n4 = (x) => +x.toFixed(4), pc = (x) => `${mm(n2(x * 100))}%`;
17
+ const { polygon } = jscad.primitives,
18
+ { extrudeLinear } = jscad.extrusions,
19
+ { translate, rotateY, rotateZ } = jscad.transforms,
20
+ { geom3 } = jscad.geometries;
21
+ const n1 = (x) => +x.toFixed(1),
22
+ n2 = (x) => +x.toFixed(2),
23
+ n4 = (x) => +x.toFixed(4),
24
+ pc = (x) => `${mm(n2(x * 100))}%`;
19
25
  const tan = (deg) => Math.tan((deg * Math.PI) / 180);
20
- /** The uses an annular snap is sized for: opened often (a lid, the guide's 60% of the brief-snap strain) or snapped once. */
26
+ /** The uses an annular snap is sized for: opened often (a lid, the guide's 60% of the brief-snap strain) or snapped
27
+ * once. */
21
28
  export const SNAP_USES = ['often', 'once'];
22
29
 
23
30
  /**
24
31
  * The geometric factor of the Bayer guide's annular snap joint for the outer part, a tube (the hub, here the lid's
25
32
  * skirt) spread over a rigid shaft: X_N = 0.62 √((k − 1)/(k + 1)) / ((k² + 1)/(k² − 1) + ν), k = d0 / d.
26
- * @param {number} k the tube's outside diameter over its inside diameter at the joint @param {number} nu Poisson's ratio
33
+ * @param {number} k the tube's outside diameter over its inside diameter at the joint @param {number} nu Poisson's
34
+ * ratio
27
35
  * @returns {number}
28
36
  */
29
37
  export const hubFactor = (k, nu) => (0.62 * Math.sqrt((k - 1) / (k + 1))) / ((k * k + 1) / (k * k - 1) + nu);
30
38
  /**
31
39
  * The same for the inner part, a hollow shaft (here the box's wall) squeezed in a rigid tube:
32
40
  * X_W = 0.62 √((k − 1)/(k + 1)) / ((k² + 1)/(k² − 1) − ν), k = d / di.
33
- * @param {number} k the shaft's outside diameter at the joint over its inside diameter @param {number} nu Poisson's ratio
41
+ * @param {number} k the shaft's outside diameter at the joint over its inside diameter @param {number} nu Poisson's
42
+ * ratio
34
43
  * @returns {number}
35
44
  */
36
45
  export const shaftFactor = (k, nu) => (0.62 * Math.sqrt((k - 1) / (k + 1))) / ((k * k + 1) / (k * k - 1) - nu);
37
46
 
38
47
  // The force along the push to make a transverse force P over a face at deg from the axis, with friction mu: the
39
48
  // guide's W = P (μ + tan α) / (1 − μ tan α). A square face, or one friction locks, never lets go
40
- const along = (P, deg, mu) => (deg >= 90 || mu * tan(deg) >= 1 ? Infinity : (P * (mu + tan(deg))) / (1 - mu * tan(deg)));
49
+ const along = (P, deg, mu) =>
50
+ deg >= 90 || mu * tan(deg) >= 1 ? Infinity : (P * (mu + tan(deg))) / (1 - mu * tan(deg));
41
51
  const per = (deg, mu) => along(1, deg, mu);
42
52
  // How much stiffer a joint is for lying away from its tube's free end: 1 at the end, the guide's 3 once it is at least
43
53
  // 1.8 √(d t) in, and straight between (the guide gives only the ends; the line between is an estimate)
44
- const remote = (end, d, t) => { const far = 1.8 * Math.sqrt(d * t), k = DEFAULTS.snap_remote.value; return { far: n2(far), factor: 1 + (k - 1) * Math.min(1, end / far) }; };
54
+ const remote = (end, d, t) => {
55
+ const far = 1.8 * Math.sqrt(d * t),
56
+ k = DEFAULTS.snap_remote.value;
57
+ return { far: n2(far), factor: 1 + (k - 1) * Math.min(1, end / far) };
58
+ };
45
59
 
46
60
  // e^(s u) (A cos u + B sin u) and its n-th derivative in u, at u
47
- const wave = (s, A, B, u, n) => { for (let i = 0; i < n; i++) [A, B] = [s * A + B, s * B - A]; return Math.exp(s * u) * (A * Math.cos(u) + B * Math.sin(u)); };
61
+ const wave = (s, A, B, u, n) => {
62
+ for (let i = 0; i < n; i++) [A, B] = [s * A + B, s * B - A];
63
+ return Math.exp(s * u) * (A * Math.cos(u) + B * Math.sin(u));
64
+ };
48
65
  const LONG = 12; // a tube this many 1/β long is long: e^-12 of the load is left at its far end
49
66
  /**
50
67
  * A ring load on a thin tube, as Hetényi's beam on an elastic foundation (the theory the Bayer guide's annular joint is
51
68
  * built on): the tube's wall in ξ = βx, with β⁴ = 3 (1 − ν²) / (R² t²), bends as w'''' + 4 w = 0, and a ring load q
52
69
  * per mm round it puts a step of q / (D β³) in w''' (D = E t³ / (12 (1 − ν²))). The load is a from one end and b from
53
70
  * the other (each in 1/β), and each end is 'free' (no moment, no shear), 'closed' (held by an end wall: no deflection,
54
- * no slope, the stiffest an end can be) or 'long' (far enough off not to count). Gives the deflection under the load and
55
- * the curvature w'' at each end, both per q / (D β³). The free-standing checks: a long tube both ways gives w = 1/8,
56
- * a free end at the load gives 1/2 (Hetényi, Beams on Elastic Foundation, 1946: w = Pβ / 2k and 2Pβ / k).
71
+ * no slope, the stiffest an end can be) or 'long' (far enough off not to count). Gives the deflection under the load
72
+ * and the curvature w'' at each end, both per q / (D β³). The free-standing checks: a long tube both ways gives w =
73
+ * 1/8, a free end at the load gives 1/2 (Hetényi, Beams on Elastic Foundation, 1946: w = Pβ / 2k and 2Pβ / k).
57
74
  * @param {number} a the load's distance from end A, in 1/β @param {number} b from end B
58
75
  * @param {{ A?: 'free' | 'closed' | 'long', B?: 'free' | 'closed' | 'long' }} [ends] (default both long)
59
76
  * @returns {{ w: number, bendA: number, bendB: number }}
60
77
  */
61
78
  export function tubeRing(a, b, ends = {}) {
62
- const what = 'tubeRing', kinds = ['free', 'closed', 'long'];
63
- for (const [k, v] of [['a', a], ['b', b]]) if (!(isNum(v) && v >= 0)) throw new Error(`${what}: ${k} is the load's distance from an end, in 1/β, 0 or more (got ${shown(v)})`);
64
- if (ends == null || typeof ends !== 'object' || Array.isArray(ends)) throw new Error(`${what}: ends is { A, B }, each free, closed or long (got ${shown(ends)})`);
79
+ const what = 'tubeRing',
80
+ kinds = ['free', 'closed', 'long'];
81
+ for (const [k, v] of [
82
+ ['a', a],
83
+ ['b', b],
84
+ ])
85
+ if (!(isNum(v) && v >= 0))
86
+ throw new Error(`${what}: ${k} is the load's distance from an end, in 1/β, 0 or more (got ${shown(v)})`);
87
+ if (ends == null || typeof ends !== 'object' || Array.isArray(ends))
88
+ throw new Error(`${what}: ends is { A, B }, each free, closed or long (got ${shown(ends)})`);
65
89
  // An end more than twice LONG away is long whatever it is: e^-24 of the load reaches it, and its e^u waves would
66
90
  // overflow a double past about 709/β (its curvature there is then 0 to that precision)
67
- const A0 = oneOf(what, 'ends.A', ends.A ?? 'long', kinds), B0 = oneOf(what, 'ends.B', ends.B ?? 'long', kinds);
68
- const A = a > 2 * LONG ? 'long' : A0, B = b > 2 * LONG ? 'long' : B0, la = A === 'long' ? LONG : a, lb = B === 'long' ? LONG : b;
91
+ const A0 = oneOf(what, 'ends.A', ends.A ?? 'long', kinds),
92
+ B0 = oneOf(what, 'ends.B', ends.B ?? 'long', kinds);
93
+ const A = a > 2 * LONG ? 'long' : A0,
94
+ B = b > 2 * LONG ? 'long' : B0,
95
+ la = A === 'long' ? LONG : a,
96
+ lb = B === 'long' ? LONG : b;
69
97
  // Each side of the load has its own four waves, from its start: e^-u cos u, e^-u sin u, e^u cos u, e^u sin u
70
- const row = (side, u, n, sign = 1) => { const r = Array(8).fill(0); [[-1, 1, 0], [-1, 0, 1], [1, 1, 0], [1, 0, 1]].forEach(([s, c, si], i) => { r[side * 4 + i] = sign * wave(s, c, si, u, n); }); return r; };
98
+ const row = (side, u, n, sign = 1) => {
99
+ const r = Array(8).fill(0);
100
+ [
101
+ [-1, 1, 0],
102
+ [-1, 0, 1],
103
+ [1, 1, 0],
104
+ [1, 0, 1],
105
+ ].forEach(([s, c, si], i) => {
106
+ r[side * 4 + i] = sign * wave(s, c, si, u, n);
107
+ });
108
+ return r;
109
+ };
71
110
  const end = (side, u, kind) => (kind === 'closed' ? [0, 1] : [2, 3]).map((n) => [row(side, u, n), 0]);
72
111
  const eqs = [...end(0, 0, A), ...end(1, lb, B)];
73
- for (const n of [0, 1, 2, 3]) { const l = row(0, la, n, -1), r = row(1, 0, n); eqs.push([l.map((x, i) => x + r[i]), n === 3 ? 1 : 0]); }
112
+ for (const n of [0, 1, 2, 3]) {
113
+ const l = row(0, la, n, -1),
114
+ r = row(1, 0, n);
115
+ eqs.push([l.map((x, i) => x + r[i]), n === 3 ? 1 : 0]);
116
+ }
74
117
  // Gauss with partial pivoting
75
118
  const M = eqs.map(([r, v]) => [...r, v]);
76
119
  for (let c = 0; c < 8; c++) {
77
- let p = c; for (let r = c + 1; r < 8; r++) if (Math.abs(M[r][c]) > Math.abs(M[p][c])) p = r;
120
+ let p = c;
121
+ for (let r = c + 1; r < 8; r++) if (Math.abs(M[r][c]) > Math.abs(M[p][c])) p = r;
78
122
  [M[c], M[p]] = [M[p], M[c]];
79
- for (let r = 0; r < 8; r++) if (r !== c) { const k = M[r][c] / M[c][c]; for (let j = c; j < 9; j++) M[r][j] -= k * M[c][j]; }
123
+ for (let r = 0; r < 8; r++)
124
+ if (r !== c) {
125
+ const k = M[r][c] / M[c][c];
126
+ for (let j = c; j < 9; j++) M[r][j] -= k * M[c][j];
127
+ }
80
128
  }
81
- const x = M.map((r, i) => r[8] / r[i]), at = (side, u, n) => row(side, u, n).reduce((t, v, i) => t + v * x[i], 0);
129
+ const x = M.map((r, i) => r[8] / r[i]),
130
+ at = (side, u, n) => row(side, u, n).reduce((t, v, i) => t + v * x[i], 0);
82
131
  return { w: at(1, 0, 0), bendA: A === A0 ? at(0, 0, 2) : 0, bendB: B === B0 ? at(1, lb, 2) : 0 };
83
132
  }
84
133
  // A closed end near the joint: how much stiffer it makes the part (the beam's deflection with the end open over that
85
134
  // with it closed, the rest of the tube as it is) and the bending strain at the closed end's root per N of P
86
135
  const closedEnd = (free, shut, Rm, t, d, E, nu) => {
87
- const beta = Math.pow((3 * (1 - nu * nu)) / (Rm * Rm * t * t), 0.25), a = free * beta, b = shut * beta;
88
- const open = tubeRing(a, LONG, { A: 'free' }), closed = tubeRing(a, b, { A: 'free', B: 'closed' });
136
+ const beta = Math.pow((3 * (1 - nu * nu)) / (Rm * Rm * t * t), 0.25),
137
+ a = free * beta,
138
+ b = shut * beta;
139
+ const open = tubeRing(a, LONG, { A: 'free' }),
140
+ closed = tubeRing(a, b, { A: 'free', B: 'closed' });
89
141
  // q = P / (π d) per mm round; M = D w''(x) = w''(ξ) q / β; the strain at the face is 6 M (1 − ν²) / (E t²)
90
142
  const perP = (6 * Math.abs(closed.bendB) * (1 - nu * nu)) / (Math.PI * d * beta * E * t * t);
91
143
  return { beta, stiffer: open.w / closed.w, perP };
@@ -102,35 +154,50 @@ const closedEnd = (free, shut, Rm, t, d, E, nu) => {
102
154
  * @param {{ count: number, width: number, reach: number, inside: number, outside: number }} f the finger count, slot
103
155
  * width, reach (from the root to where the finger is pushed, its arm L) and the skirt's radii, mm
104
156
  * @param {number} E the plastic's modulus, MPa
105
- * @returns {{ angle: number, width: number, area: number, inertia: number, fibre: number, stiffness: number, strainPerY: number }}
106
- * angle: the finger's whole angle, degrees; width: its arc at the mean radius; inertia, mm⁴; fibre: c; stiffness: N per
107
- * mm of radial push at reach; strainPerY: the root strain per mm of that push
157
+ * @returns {{ angle: number, width: number, area: number, inertia: number, fibre: number, stiffness: number,
158
+ * strainPerY: number }}
159
+ * angle: the finger's whole angle, degrees; width: its arc at the mean radius; inertia, mm⁴; fibre: c; stiffness: N
160
+ * per mm of radial push at reach; strainPerY: the root strain per mm of that push
108
161
  */
109
162
  export function skirtFinger({ count: n, width: w, reach: L, inside: ri, outside: ro }, E) {
110
- const rm = (ri + ro) / 2, phi = Math.PI / n - w / (2 * rm);
111
- const A = phi * (ro * ro - ri * ri), Ax = (2 * (ro ** 3 - ri ** 3) * Math.sin(phi)) / 3, xbar = Ax / A;
163
+ const rm = (ri + ro) / 2,
164
+ phi = Math.PI / n - w / (2 * rm);
165
+ const A = phi * (ro * ro - ri * ri),
166
+ Ax = (2 * (ro ** 3 - ri ** 3) * Math.sin(phi)) / 3,
167
+ xbar = Ax / A;
112
168
  const I = ((ro ** 4 - ri ** 4) * (phi + Math.sin(phi) * Math.cos(phi))) / 4 - A * xbar * xbar;
113
169
  const c = Math.max(ro - xbar, xbar - ri * Math.cos(phi));
114
- return { angle: (2 * phi * 180) / Math.PI, width: 2 * phi * rm, area: A, inertia: I, fibre: c, stiffness: (3 * E * I) / L ** 3, strainPerY: (3 * c) / (L * L) };
170
+ return {
171
+ angle: (2 * phi * 180) / Math.PI,
172
+ width: 2 * phi * rm,
173
+ area: A,
174
+ inertia: I,
175
+ fibre: c,
176
+ stiffness: (3 * E * I) / L ** 3,
177
+ strainPerY: (3 * c) / (L * L),
178
+ };
115
179
  }
116
180
 
117
181
  /**
118
- * @typedef {{ diameter: number, inside: number, outside: number, wall: number, end: number, far: number, factor: number,
119
- * remote: number, X: number, stiffness: number, deflection: number, strain: number, closed: number | null, stiffer?: number, decay?: number, root?: number }} SnapPart
120
- * one part of the joint: its diameters at the joint, wall, how far the joint is from its free end and the guide's
121
- * "remote" distance, the stiffening that gives (remote), and with a closed end's too (factor), the geometric factor, its stiffness (N per mm of diameter),
122
- * how much of the interference it takes (on the diameter) and the hoop strain that leaves in it; with a closed end
123
- * (closed, its distance from the joint), how much stiffer that end makes it, the length 1/β over which its wall
124
- * bends, and the bending strain at the end's root
182
+ * @typedef {{ diameter: number, inside: number, outside: number, wall: number, end: number, far: number,
183
+ * factor: number,
184
+ * remote: number, X: number, stiffness: number, deflection: number, strain: number, closed: number | null, stiffer?:
185
+ * number, decay?: number, root?: number }} SnapPart one part of the joint: its diameters at the joint, wall, how far
186
+ * the joint is from its free end and the guide's "remote" distance, the stiffening that gives (remote), and with a
187
+ * closed end's too (factor), the geometric factor, its stiffness (N per mm of diameter), how much of the interference
188
+ * it takes (on the diameter) and the hoop strain that leaves in it; with a closed end (closed, its distance from the
189
+ * joint), how much stiffer that end makes it, the length 1/β over which its wall bends, and the bending strain at the
190
+ * end's root
125
191
  */
126
192
  /**
127
- * @typedef {{ kind: 'annular snap', diameter: number, wall: number, skirt: number, clearance: number, bead: number, length: number, undercut: number,
128
- * interference: number, lead: number, back: number, land: number, sized: boolean, uses: 'often' | 'once', material: string,
129
- * lidMaterial: string, friction: number, permissible: number, box: SnapPart, lid: SnapPart, force: number, insertion: number,
130
- * removal: number, holds: boolean, pull: number | null, margin: number | null, most: { undercut: number, removal: number },
131
- * groove: { inner: number, outer: number, depth: number }, rests: object[], findings: object[] }} AnnularSnap
132
- * diameter: the box's wall outside at the joint; bead: how far the bead stands off it (radial); length: the bead's
133
- * height along the axis, return face, land and lead face; undercut: the
193
+ * @typedef {{ kind: 'annular snap', diameter: number, wall: number, skirt: number, clearance: number, bead: number,
194
+ * length: number, undercut: number,
195
+ * interference: number, lead: number, back: number, land: number, sized: boolean, uses: 'often' | 'once', material:
196
+ * string, lidMaterial: string, friction: number, permissible: number, box: SnapPart, lid: SnapPart, force: number,
197
+ * insertion: number, removal: number, holds: boolean, pull: number | null, margin: number | null, most:
198
+ * { undercut: number, removal: number }, groove: { inner: number, outer: number, depth: number }, rests: object[],
199
+ * findings: object[] }} AnnularSnap diameter: the box's wall outside at the joint; bead: how far the bead stands off
200
+ * it (radial); length: the bead's height along the axis, return face, land and lead face; undercut: the
134
201
  * bead less the clearance, the radial overlap the skirt is spread by; interference: the same on the diameter, shared
135
202
  * between the parts; force: the transverse force P that takes; insertion and removal: along the push, N;
136
203
  * permissible: the hoop strain each part may see; most: the largest undercut that strain allows and the removal
@@ -141,16 +208,44 @@ export function skirtFinger({ count: n, width: w, reach: L, inside: ri, outside:
141
208
  // that prints apart, and a reach that stays in the skirt (no further than the lid's top) and is a beam, twice the skirt
142
209
  const slotsOf = (what, v, s, lidTop, pr, d) => {
143
210
  if (v == null) return null;
144
- if (typeof v !== 'object' || Array.isArray(v)) throw new Error(`${what}: slots is { count, reach, width }: the fingers, how far the groove is from the slots' closed end and the slots' width (got ${shown(v)})`);
145
- for (const key of Object.keys(v)) if (!['count', 'reach', 'width'].includes(key)) throw new Error(`${what}: slots has no ${key}: it takes count, reach and width`);
146
- if (!(Number.isInteger(v.count) && v.count >= 3)) throw new Error(`${what}: slots.count is how many fingers the skirt is slotted into, a whole number, 3 or more (got ${shown(v.count)})`);
147
- const gap = pr.n('print_gap'), width = v.width ?? DEFAULTS.snap_slot.value;
148
- if (!(isNum(width) && width >= gap - 1e-9)) throw new Error(`${what}: slots.width is the slots' width, at least the ${pr.cite('print_gap')} ${mm(gap)} mm that prints apart (got ${shown(v.width)})`);
211
+ if (typeof v !== 'object' || Array.isArray(v))
212
+ throw new Error(
213
+ `${what}: slots is { count, reach, width }: the fingers, how far the groove is from the slots' closed ` +
214
+ `end and the slots' width (got ${shown(v)})`,
215
+ );
216
+ for (const key of Object.keys(v))
217
+ if (!['count', 'reach', 'width'].includes(key))
218
+ throw new Error(`${what}: slots has no ${key}: it takes count, reach and width`);
219
+ if (!(Number.isInteger(v.count) && v.count >= 3))
220
+ throw new Error(
221
+ `${what}: slots.count is how many fingers the skirt is slotted into, a whole number, 3 or more (got ` +
222
+ `${shown(v.count)})`,
223
+ );
224
+ const gap = pr.n('print_gap'),
225
+ width = v.width ?? DEFAULTS.snap_slot.value;
226
+ if (!(isNum(width) && width >= gap - 1e-9))
227
+ throw new Error(
228
+ `${what}: slots.width is the slots' width, at least the ${pr.cite('print_gap')} ${mm(gap)} mm that ` +
229
+ `prints apart (got ${shown(v.width)})`,
230
+ );
149
231
  const reach = positive(what, 'slots.reach', v.reach);
150
- if (reach < 2 * s - 1e-9) throw new Error(`${what}: slots.reach of ${mm(reach)} mm is under twice the ${mm(s)} mm skirt, too short to bend as a finger: give ${mm(r3(2 * s))} mm or more`);
151
- if (lidTop != null && reach > lidTop + 1e-9) throw new Error(`${what}: slots.reach of ${mm(reach)} mm runs past the lid's top, ${mm(lidTop)} mm from the groove (lidTop): the slots end in the skirt, so give ${mm(lidTop)} mm or less`);
152
- const rm = (d + 2 * pr.n('fit') + s) / 2, arc = (2 * Math.PI * rm) / v.count - width;
153
- if (arc < s - 1e-9) throw new Error(`${what}: ${v.count} fingers with ${mm(width)} mm slots leave each ${mm(r3(arc))} mm wide, under the ${mm(s)} mm skirt: give fewer, at most ${Math.floor((2 * Math.PI * rm) / (s + width))}`);
232
+ if (reach < 2 * s - 1e-9)
233
+ throw new Error(
234
+ `${what}: slots.reach of ${mm(reach)} mm is under twice the ${mm(s)} mm skirt, too short to bend as a ` +
235
+ `finger: give ${mm(r3(2 * s))} mm or more`,
236
+ );
237
+ if (lidTop != null && reach > lidTop + 1e-9)
238
+ throw new Error(
239
+ `${what}: slots.reach of ${mm(reach)} mm runs past the lid's top, ${mm(lidTop)} mm from the groove ` +
240
+ `(lidTop): the slots end in the skirt, so give ${mm(lidTop)} mm or less`,
241
+ );
242
+ const rm = (d + 2 * pr.n('fit') + s) / 2,
243
+ arc = (2 * Math.PI * rm) / v.count - width;
244
+ if (arc < s - 1e-9)
245
+ throw new Error(
246
+ `${what}: ${v.count} fingers with ${mm(width)} mm slots leave each ${mm(r3(arc))} mm wide, under the ` +
247
+ `${mm(s)} mm skirt: give fewer, at most ${Math.floor((2 * Math.PI * rm) / (s + width))}`,
248
+ );
154
249
  return { count: v.count, width, reach, given: v.width != null };
155
250
  };
156
251
 
@@ -165,12 +260,14 @@ const slotsOf = (what, v, s, lidTop, pr, d) => {
165
260
  * tube, angles outside 0° to 90°, a lead friction locks, a groove deeper than the skirt. A closed end near the joint
166
261
  * (the box's floor, the lid's top) is a beam on an elastic foundation held round there (Hetényi): the part is stiffer,
167
262
  * so its mate takes more of the interference, and the bending at that end's root is held to the same limit.
168
- * @param {{ diameter: number, wall: number, skirt: number, bead?: number, lead?: number, back?: number, land?: number, boxEnd?: number, lidEnd?: number, boxFloor?: number, lidTop?: number, slots?: { count: number, reach: number, width?: number } }} p
263
+ * @param {{ diameter: number, wall: number, skirt: number, bead?: number, lead?: number, back?: number, land?: number,
264
+ * boxEnd?: number, lidEnd?: number, boxFloor?: number, lidTop?: number, slots?: { count: number, reach: number,
265
+ * width?: number } }} p
169
266
  * diameter: the box's wall outside, at the joint, mm; wall: the box's wall thickness there; skirt: the lid's skirt
170
267
  * thickness; bead: how far the bead stands off the wall (default sized); lead: the face the lid pushes over, its
171
268
  * angle from the axis (default 30); back: the return face's (default 45: the steepest the box prints without support,
172
- * as it is the underside of the bead); land: the bead's flat top, along the axis (default two layers); boxEnd: from the
173
- * bead to the box's rim, its free end; lidEnd: from the groove to the skirt's mouth (each default 0, at the end);
269
+ * as it is the underside of the bead); land: the bead's flat top, along the axis (default two layers); boxEnd: from
270
+ * the bead to the box's rim, its free end; lidEnd: from the groove to the skirt's mouth (each default 0, at the end);
174
271
  * boxFloor: from the bead to the box's floor, its closed end; lidTop: from the groove to the underside of the lid's
175
272
  * top (each default none: far enough off not to count; each at least its part's wall, the box's wall or the skirt);
176
273
  * slots: the skirt slotted into fingers, count of them (3 or more), each reach mm from the slots' closed end to the
@@ -179,7 +276,8 @@ const slotsOf = (what, v, s, lidTop, pr, d) => {
179
276
  * round at the groove. The bead bears on each finger at the groove's bottom edge, both going on (the lip below the
180
277
  * groove rides over the bead's crest) and coming off (the groove's lower face rides up the return face), so the
181
278
  * finger's arm is reach + the bead's length + twice the clearance (slots.arm in the model)
182
- * @param {{ material?: string | object, lidMaterial?: string | object, printer?: object, sets?: object, uses?: 'often' | 'once', friction?: number, pull?: number, push?: number }} [o]
279
+ * @param {{ material?: string | object, lidMaterial?: string | object, printer?: object, sets?: object,
280
+ * uses?: 'often' | 'once', friction?: number, pull?: number, push?: number }} [o]
183
281
  * material: the box's plastic (default PLA); lidMaterial: the lid's (default the box's); printer: the printer's rule
184
282
  * set or values (default the X1C: its fit is the clearance, its overhang the steepest return face); uses: often (the
185
283
  * default, a lid) or once; friction: μ between the parts (default fixings.snap_friction); pull: the force along the
@@ -189,179 +287,614 @@ const slotsOf = (what, v, s, lidTop, pr, d) => {
189
287
  */
190
288
  export function annularSnapModel(p, o = {}) {
191
289
  const what = 'annularSnapModel';
192
- if (p == null || typeof p !== 'object' || Array.isArray(p)) throw new Error(`${what}: give the joint's figures ({ diameter: 60, wall: 1.68, skirt: 1.26 }), not ${shown(p)}`);
193
- optionsOf(what, o, '{ material: \'pla\', pull: 10 }');
194
- const d = positive(what, 'diameter', p.diameter), t = positive(what, 'wall', p.wall), s = positive(what, 'skirt', p.skirt);
195
- if (t >= d / 2) throw new Error(`${what}: a wall of ${mm(t)} mm fills a ${mm(d)} mm box: the box's wall is under half its diameter, so it is a tube that gives`);
196
- const pr = printerOf(what, o.printer), c = pr.n('fit'), layer = pr.n('layer'), overhang = pr.n('overhang');
197
- const angle = (k, v, dflt) => { const x = v ?? dflt; if (!(isNum(x) && x > 0 && x <= 90)) throw new Error(`${what}: ${k} is an angle from the axis above 0° and at most 90°, in degrees (got ${shown(v)})`); return x; };
198
- const lead = angle('lead', p.lead, 30), back = angle('back', p.back, 45);
199
- if (lead >= 90) throw new Error(`${what}: a lead of 90° is a square face the lid cannot be pushed over: give a lead under 90°, 30° to 45° is usual`);
290
+ if (p == null || typeof p !== 'object' || Array.isArray(p))
291
+ throw new Error(`${what}: give the joint's figures ({ diameter: 60, wall: 1.68, skirt: 1.26 }), not ${shown(p)}`);
292
+ optionsOf(what, o, "{ material: 'pla', pull: 10 }");
293
+ const d = positive(what, 'diameter', p.diameter),
294
+ t = positive(what, 'wall', p.wall),
295
+ s = positive(what, 'skirt', p.skirt);
296
+ if (t >= d / 2)
297
+ throw new Error(
298
+ `${what}: a wall of ${mm(t)} mm fills a ${mm(d)} mm box: the box's wall is under half its diameter, so ` +
299
+ `it is a tube that gives`,
300
+ );
301
+ const pr = printerOf(what, o.printer),
302
+ c = pr.n('fit'),
303
+ layer = pr.n('layer'),
304
+ overhang = pr.n('overhang');
305
+ const angle = (k, v, dflt) => {
306
+ const x = v ?? dflt;
307
+ if (!(isNum(x) && x > 0 && x <= 90))
308
+ throw new Error(`${what}: ${k} is an angle from the axis above 0° and at most 90°, in degrees (got ${shown(v)})`);
309
+ return x;
310
+ };
311
+ const lead = angle('lead', p.lead, 30),
312
+ back = angle('back', p.back, 45);
313
+ if (lead >= 90)
314
+ throw new Error(
315
+ `${what}: a lead of 90° is a square face the lid cannot be pushed over: give a lead under 90°, 30° to ` +
316
+ `45° is usual`,
317
+ );
200
318
  const land = p.land != null ? positive(what, 'land', p.land) : r3(2 * layer);
201
- const end = (k) => { const v = p[k] ?? 0; if (!(isNum(v) && v >= 0)) throw new Error(`${what}: ${k} is how far the joint is from that part's free end, 0 mm or more (got ${shown(p[k])})`); return v; };
319
+ const end = (k) => {
320
+ const v = p[k] ?? 0;
321
+ if (!(isNum(v) && v >= 0))
322
+ throw new Error(
323
+ `${what}: ${k} is how far the joint is from that part's free end, 0 mm or more (got ${shown(p[k])})`,
324
+ );
325
+ return v;
326
+ };
202
327
  // A closed end at the joint itself (0 mm) holds the wall rigid there, so it cannot give at all; one nearer than the
203
- // wall is thick is a solid corner, not a tube's wall that bends, which the beam on an elastic foundation (a thin-shell
204
- // theory) does not model, and its sums lose their sign to rounding as the distance goes to 0. Both refused
205
- const shut = (k, what2, wall, wallName) => { if (p[k] == null) return null; const v = p[k]; if (!(isNum(v) && v >= wall - 1e-9)) throw new Error(`${what}: ${k} is how far the joint is from ${what2}, its closed end, at least the ${mm(wall)} mm ${wallName} (got ${shown(v)}): a joint nearer its closed end than that is a solid corner that cannot give, so move it further off`); return v; };
206
- const boxFloor = shut('boxFloor', 'the box\'s floor', t, 'wall'), lidTop = shut('lidTop', 'the lid\'s top', s, 'skirt');
207
- const boxEnd = end('boxEnd'), lidEnd = end('lidEnd'), uses = oneOf(what, 'uses', o.uses ?? 'often', SNAP_USES);
328
+ // wall is thick is a solid corner, not a tube's wall that bends, which the beam on an elastic foundation (a
329
+ // thin-shell theory) does not model, and its sums lose their sign to rounding as the distance goes to 0. Both refused
330
+ const shut = (k, what2, wall, wallName) => {
331
+ if (p[k] == null) return null;
332
+ const v = p[k];
333
+ if (!(isNum(v) && v >= wall - 1e-9))
334
+ throw new Error(
335
+ `${what}: ${k} is how far the joint is from ${what2}, its closed end, at least the ${mm(wall)} mm ` +
336
+ `${wallName} (got ${shown(v)}): a joint nearer its closed end than that is a solid corner that ` +
337
+ `cannot give, so move it further off`,
338
+ );
339
+ return v;
340
+ };
341
+ const boxFloor = shut('boxFloor', "the box's floor", t, 'wall'),
342
+ lidTop = shut('lidTop', "the lid's top", s, 'skirt');
343
+ const boxEnd = end('boxEnd'),
344
+ lidEnd = end('lidEnd'),
345
+ uses = oneOf(what, 'uses', o.uses ?? 'often', SNAP_USES);
208
346
  const slots = slotsOf(what, p.slots, s, lidTop, printerOf(what, o.printer), d);
209
347
  const mu = o.friction ?? DEFAULTS.snap_friction.value;
210
- if (!(isNum(mu) && mu >= 0 && mu < 1)) throw new Error(`${what}: friction is μ between the parts, 0 or more and under 1 (got ${shown(o.friction)})`);
211
- if (mu * tan(lead) >= 1 - 1e-9) throw new Error(`${what}: a ${mm(lead)}° lead at friction ${mm(mu)} locks: μ tan α is ${mm(n2(mu * tan(lead)))}, 1 or more, so no push slides the skirt over it. Give a lead under ${mm(n1((Math.atan(1 / mu) * 180) / Math.PI))}° at that friction, 30° to 45° is usual`);
212
- const pull = o.pull != null ? positive(what, 'pull (along the axis, in N)', o.pull) : null, push = o.push != null ? positive(what, 'push (along the axis, in N)', o.push) : null;
213
- if (p.bead != null && !(isNum(p.bead) && p.bead > c + 1e-9)) throw new Error(`${what}: a bead of ${shown(p.bead)} mm is no taller than the ${pr.cite('fit')} clearance of ${mm(c)} mm round the skirt, so it never catches: give a bead over ${mm(c)} mm, or leave it out to have it sized`);
214
- if (p.bead != null && p.bead >= s - 1e-9) throw new Error(`${what}: a bead of ${mm(p.bead)} mm needs a groove as deep in the ${mm(s)} mm skirt, which cuts right through it: give a skirt thicker than the bead, by a print line or more`);
215
- const box = materialOf(what, o.material ?? 'pla', o.sets), lidMat = materialOf(what, o.lidMaterial ?? o.material ?? 'pla', o.sets);
216
- for (const m of [box, lidMat]) if (!m.poisson) throw new Error(`${what}: ${m.name} has no poisson in its rule set, which the guide's geometric factor needs`);
217
- if (box.cls !== 'plastic' || lidMat.cls !== 'plastic') throw new Error(`${what}: an annular snap is two printed plastic parts; ${box.cls !== 'plastic' ? box.name : lidMat.name} is a ${box.cls !== 'plastic' ? box.cls : lidMat.cls}`);
348
+ if (!(isNum(mu) && mu >= 0 && mu < 1))
349
+ throw new Error(`${what}: friction is μ between the parts, 0 or more and under 1 (got ${shown(o.friction)})`);
350
+ if (mu * tan(lead) >= 1 - 1e-9)
351
+ throw new Error(
352
+ `${what}: a ${mm(lead)}° lead at friction ${mm(mu)} locks: μ tan α is ${mm(n2(mu * tan(lead)))}, 1 or ` +
353
+ `more, so no push slides the skirt over it. Give a lead under ` +
354
+ `${mm(n1((Math.atan(1 / mu) * 180) / Math.PI))}° at that friction, 30° to 45° is usual`,
355
+ );
356
+ const pull = o.pull != null ? positive(what, 'pull (along the axis, in N)', o.pull) : null,
357
+ push = o.push != null ? positive(what, 'push (along the axis, in N)', o.push) : null;
358
+ if (p.bead != null && !(isNum(p.bead) && p.bead > c + 1e-9))
359
+ throw new Error(
360
+ `${what}: a bead of ${shown(p.bead)} mm is no taller than the ${pr.cite('fit')} clearance of ${mm(c)} ` +
361
+ `mm round the skirt, so it never catches: give a bead over ${mm(c)} mm, or leave it out to have it ` +
362
+ `sized`,
363
+ );
364
+ if (p.bead != null && p.bead >= s - 1e-9)
365
+ throw new Error(
366
+ `${what}: a bead of ${mm(p.bead)} mm needs a groove as deep in the ${mm(s)} mm skirt, which cuts right ` +
367
+ `through it: give a skirt thicker than the bead, by a print line or more`,
368
+ );
369
+ const box = materialOf(what, o.material ?? 'pla', o.sets),
370
+ lidMat = materialOf(what, o.lidMaterial ?? o.material ?? 'pla', o.sets);
371
+ for (const m of [box, lidMat])
372
+ if (!m.poisson)
373
+ throw new Error(`${what}: ${m.name} has no poisson in its rule set, which the guide's geometric factor needs`);
374
+ if (box.cls !== 'plastic' || lidMat.cls !== 'plastic')
375
+ throw new Error(
376
+ `${what}: an annular snap is two printed plastic parts; ` +
377
+ `${box.cls !== 'plastic' ? box.name : lidMat.name} is a ${box.cls !== 'plastic' ? box.cls : lidMat.cls}`,
378
+ );
218
379
 
219
380
  // The permissible hoop strain: the guide's share of the yield strain, the yield strain taken as strength over modulus
220
- // (a straight line to the strength, so below the real yield strain: on the safe side), and 60% of that if opened often
221
- const brief = DEFAULTS.snap_brief.value, often = uses === 'often' ? DEFAULTS.snap_often.value : 1;
222
- const limitOf = (m) => (brief * often * m.strength.value) / m.modulus.value, permissible = Math.min(limitOf(box), limitOf(lidMat));
381
+ // (a straight line to the strength, so below the real yield strain: on the safe side), and 60% of that if opened
382
+ // often
383
+ const brief = DEFAULTS.snap_brief.value,
384
+ often = uses === 'often' ? DEFAULTS.snap_often.value : 1;
385
+ const limitOf = (m) => (brief * often * m.strength.value) / m.modulus.value,
386
+ permissible = Math.min(limitOf(box), limitOf(lidMat));
223
387
 
224
388
  // Each part as a spring on the diameter: P = y d Es X, stiffened where the joint lies away from its free end
225
- const di = d - 2 * t, dh = d + 2 * c, d0 = dh + 2 * s;
226
- // A closed end (the box's floor, the lid's top) near the joint holds the tube round there: Hetényi's beam on an elastic
227
- // foundation gives how much stiffer that makes it than the same tube open, and the bending at the closed end's root
389
+ const di = d - 2 * t,
390
+ dh = d + 2 * c,
391
+ d0 = dh + 2 * s;
392
+ // A closed end (the box's floor, the lid's top) near the joint holds the tube round there: Hetényi's beam on an
393
+ // elastic foundation gives how much stiffer that makes it than the same tube open, and the bending at the closed
394
+ // end's root
228
395
  const part = (diameter, inside, outside, wall, endAt, closedAt, X, m) => {
229
- const r = remote(endAt, diameter, wall), E = m.modulus.value, nu = m.poisson.value;
230
- const ce = closedAt == null ? null : closedEnd(endAt, closedAt, (inside + outside) / 4, wall, diameter, E, nu), factor = r.factor * (ce ? ce.stiffer : 1);
231
- return { diameter: r3(diameter), inside: r3(inside), outside: r3(outside), wall, end: endAt, far: r.far, remote: n2(r.factor), factor: n2(factor), X, stiffness: factor * diameter * E * X,
232
- closed: closedAt, ...(ce ? { stiffer: n2(ce.stiffer), decay: n2(1 / ce.beta), rootPerP: ce.perP } : {}) };
396
+ const r = remote(endAt, diameter, wall),
397
+ E = m.modulus.value,
398
+ nu = m.poisson.value;
399
+ const ce = closedAt == null ? null : closedEnd(endAt, closedAt, (inside + outside) / 4, wall, diameter, E, nu),
400
+ factor = r.factor * (ce ? ce.stiffer : 1);
401
+ return {
402
+ diameter: r3(diameter),
403
+ inside: r3(inside),
404
+ outside: r3(outside),
405
+ wall,
406
+ end: endAt,
407
+ far: r.far,
408
+ remote: n2(r.factor),
409
+ factor: n2(factor),
410
+ X,
411
+ stiffness: factor * diameter * E * X,
412
+ closed: closedAt,
413
+ ...(ce ? { stiffer: n2(ce.stiffer), decay: n2(1 / ce.beta), rootPerP: ce.perP } : {}),
414
+ };
233
415
  };
234
- const B = part(d, di, d, t, boxEnd, boxFloor, shaftFactor(d / di, box.poisson.value), box), whole = part(dh, dh, d0, s, lidEnd, lidTop, hubFactor(d0 / dh, lidMat.poisson.value), lidMat);
416
+ const B = part(d, di, d, t, boxEnd, boxFloor, shaftFactor(d / di, box.poisson.value), box),
417
+ whole = part(dh, dh, d0, s, lidEnd, lidTop, hubFactor(d0 / dh, lidMat.poisson.value), lidMat);
235
418
  // The strain per N of P: a tube's hoop strain is its share over its diameter
236
- B.perP = 1 / (B.stiffness * B.diameter); whole.perP = 1 / (whole.stiffness * whole.diameter);
237
- // Slotted, the lid is its fingers side by side: P = n k y for a radial push y, so n k / 2 per mm of diameter, and each
238
- // root strains 3 c y / L² (skirtFinger), the lid's top no longer holding the groove round. The bead bears on a finger
239
- // at the groove's bottom edge, not at its top (reach's end): going on, the lip below the groove rides over the bead's
240
- // crest, and is pushed out the whole undercut until the crest reaches that edge; coming off, the groove's lower face
241
- // rides up the bead's return face, and is pushed out the whole undercut as that edge reaches the crest. So the arm is
242
- // reach + the groove's height (the bead's length and the clearance at each end), and as that grows with the bead, the
243
- // springs are worked for a given bead (a longer arm is softer: k goes as 1 / L³)
244
- const lengthOf = (b) => r3(b / tan(back) + land + b / tan(lead)), armOf = (u) => slots.reach + lengthOf(r3(u + c)) + 2 * c;
419
+ B.perP = 1 / (B.stiffness * B.diameter);
420
+ whole.perP = 1 / (whole.stiffness * whole.diameter);
421
+ // Slotted, the lid is its fingers side by side: P = n k y for a radial push y, so n k / 2 per mm of diameter, and
422
+ // each root strains 3 c y / L² (skirtFinger), the lid's top no longer holding the groove round. The bead bears on a
423
+ // finger at the groove's bottom edge, not at its top (reach's end): going on, the lip below the groove rides over the
424
+ // bead's crest, and is pushed out the whole undercut until the crest reaches that edge; coming off, the groove's
425
+ // lower face rides up the bead's return face, and is pushed out the whole undercut as that edge reaches the crest. So
426
+ // the arm is reach + the groove's height (the bead's length and the clearance at each end), and as that grows with
427
+ // the bead, the springs are worked for a given bead (a longer arm is softer: k goes as 1 / L³)
428
+ const lengthOf = (b) => r3(b / tan(back) + land + b / tan(lead)),
429
+ armOf = (u) => slots.reach + lengthOf(r3(u + c)) + 2 * c;
245
430
  const springs = (u) => {
246
431
  if (!slots) return { L: whole, finger: null, arm: null };
247
- const arm = armOf(u), finger = skirtFinger({ ...slots, reach: arm, inside: dh / 2, outside: d0 / 2 }, lidMat.modulus.value);
248
- return { arm, finger, L: { diameter: r3(dh), inside: r3(dh), outside: r3(d0), wall: s, end: lidEnd, far: null, remote: 1, factor: 1, X: null, closed: null,
249
- stiffness: (slots.count * finger.stiffness) / 2, perP: finger.strainPerY / (slots.count * finger.stiffness) } };
432
+ const arm = armOf(u),
433
+ finger = skirtFinger({ ...slots, reach: arm, inside: dh / 2, outside: d0 / 2 }, lidMat.modulus.value);
434
+ return {
435
+ arm,
436
+ finger,
437
+ L: {
438
+ diameter: r3(dh),
439
+ inside: r3(dh),
440
+ outside: r3(d0),
441
+ wall: s,
442
+ end: lidEnd,
443
+ far: null,
444
+ remote: 1,
445
+ factor: 1,
446
+ X: null,
447
+ closed: null,
448
+ stiffness: (slots.count * finger.stiffness) / 2,
449
+ perP: finger.strainPerY / (slots.count * finger.stiffness),
450
+ },
451
+ };
452
+ };
453
+ // The most force (and so interference) the strain allows: P = ε k_i d_i in each part, and at a closed end's root P =
454
+ // ε / (strain per N)
455
+ const limits = (L) => {
456
+ const k = 1 / (1 / B.stiffness + 1 / L.stiffness),
457
+ Pmost = Math.min(
458
+ permissible / B.perP,
459
+ permissible / L.perP,
460
+ ...[B, L].filter((q) => q.rootPerP).map((q) => permissible / q.rootPerP),
461
+ );
462
+ return { k, Pmost, mostUndercut: Pmost / k / 2 };
250
463
  };
251
- // The most force (and so interference) the strain allows: P = ε k_i d_i in each part, and at a closed end's root P = ε / (strain per N)
252
- const limits = (L) => { const k = 1 / (1 / B.stiffness + 1 / L.stiffness), Pmost = Math.min(permissible / B.perP, permissible / L.perP, ...[B, L].filter((q) => q.rootPerP).map((q) => permissible / q.rootPerP)); return { k, Pmost, mostUndercut: Pmost / k / 2 }; };
253
464
  // to the thousandth: the sized bead is rounded up to what the pull needs and down to what the strain allows
254
- const up = (x) => Math.ceil(x * 1000 - 1e-6) / 1000, down = (x) => Math.floor(x * 1000 + 1e-6) / 1000;
255
- const least = DEFAULTS.snap_least.value, back1 = per(back, mu), want = DEFAULTS.load_margin.value;
256
- let undercut, sized = false, sizeSays = null, sp, lim;
257
- if (p.bead != null) { undercut = p.bead - c; sp = springs(undercut); lim = limits(sp.L); }
258
- else {
465
+ const up = (x) => Math.ceil(x * 1000 - 1e-6) / 1000,
466
+ down = (x) => Math.floor(x * 1000 + 1e-6) / 1000;
467
+ const least = DEFAULTS.snap_least.value,
468
+ back1 = per(back, mu),
469
+ want = DEFAULTS.load_margin.value;
470
+ let undercut,
471
+ sized = false,
472
+ sizeSays = null,
473
+ sp,
474
+ lim;
475
+ if (p.bead != null) {
476
+ undercut = p.bead - c;
477
+ sp = springs(undercut);
478
+ lim = limits(sp.L);
479
+ } else {
259
480
  sized = true;
260
481
  // Sized against the springs of the bead it sizes: each pass works the arm from the last bead, and a bigger bead
261
482
  // only lengthens the arm (softer fingers, so a bigger bead again), so the beads rise to one that gives itself back
262
483
  let need = 0;
263
484
  undercut = least;
264
485
  for (let i = 0; i < 50; i++) {
265
- sp = springs(undercut); lim = limits(sp.L);
486
+ sp = springs(undercut);
487
+ lim = limits(sp.L);
266
488
  need = pull != null && Number.isFinite(back1) ? (want * pull) / back1 / lim.k / 2 : 0;
267
489
  let next = Math.max(least, up(need));
268
490
  if (next > lim.mostUndercut) next = Math.max(down(lim.mostUndercut), 0);
269
491
  next = r3(next);
270
- if (!slots || next === undercut) { undercut = next; break; }
492
+ if (!slots || next === undercut) {
493
+ undercut = next;
494
+ break;
495
+ }
271
496
  undercut = next;
272
497
  }
273
- sp = springs(undercut); lim = limits(sp.L);
274
- sizeSays = need > least ? `sized from the ${mm(pull)} N pull: ${mm(want)} times it over the ${mm(back)}° return face` : `sized as the smallest the print holds, fixings.snap_least ${mm(least)} mm${pull != null ? `, which already holds the ${mm(pull)} N pull ${mm(want)} times over` : ''}`;
275
- if (Math.max(least, up(need)) > lim.mostUndercut) sizeSays += `, more than the ${mm(r3(lim.mostUndercut))} mm the strain allows, so held to that`;
498
+ sp = springs(undercut);
499
+ lim = limits(sp.L);
500
+ sizeSays =
501
+ need > least
502
+ ? `sized from the ${mm(pull)} N pull: ${mm(want)} times it over the ${mm(back)}° return face`
503
+ : `sized as the smallest the print holds, fixings.snap_least ${mm(least)} mm` +
504
+ (pull != null ? `, which already holds the ${mm(pull)} N pull ${mm(want)} times over` : '');
505
+ if (Math.max(least, up(need)) > lim.mostUndercut)
506
+ sizeSays += `, more than the ${mm(r3(lim.mostUndercut))} mm the strain allows, so held to that`;
276
507
  }
277
- const { L, finger, arm } = sp, { k, Pmost, mostUndercut } = lim;
278
- // The most undercut the strain allows, worked at its own arm: slotted, the arm (and so the fingers' stiffness and root
279
- // strain per mm) follows the bead, and the box's share of the stiffness keeps the limit from simply falling or rising
280
- // with it, so the thousandths are searched over the whole range the skirt allows (a bead under the skirt's thickness)
281
- // for the largest undercut that passes at its own arm, whatever bead was given; it holds what that bead holds
508
+ const { L, finger, arm } = sp,
509
+ { k, Pmost, mostUndercut } = lim;
510
+ // The most undercut the strain allows, worked at its own arm: slotted, the arm (and so the fingers' stiffness and
511
+ // root strain per mm) follows the bead, and the box's share of the stiffness keeps the limit from simply falling or
512
+ // rising with it, so the thousandths are searched over the whole range the skirt allows (a bead under the skirt's
513
+ // thickness) for the largest undercut that passes at its own arm, whatever bead was given; it holds what that bead
514
+ // holds
282
515
  const mostAtOwnArm = () => {
283
516
  if (!slots) return { undercut: down(mostUndercut), removal: Number.isFinite(back1) ? n1(back1 * Pmost) : Infinity };
284
- const passes = (u) => { const l = limits(springs(u).L); return { ok: 2 * u * l.k <= l.Pmost * (1 + 1e-9), l }; };
517
+ const passes = (u) => {
518
+ const l = limits(springs(u).L);
519
+ return { ok: 2 * u * l.k <= l.Pmost * (1 + 1e-9), l };
520
+ };
285
521
  let best = { u: 0, l: limits(springs(0).L) };
286
- for (let m = 1; m / 1000 + c < s - 1e-9; m++) { const u = m / 1000, r = passes(u); if (r.ok) best = { u, l: r.l }; }
522
+ for (let m = 1; m / 1000 + c < s - 1e-9; m++) {
523
+ const u = m / 1000,
524
+ r = passes(u);
525
+ if (r.ok) best = { u, l: r.l };
526
+ }
287
527
  return { undercut: best.u, removal: Number.isFinite(back1) ? n1(back1 * 2 * best.u * best.l.k) : Infinity };
288
528
  };
289
529
  // (worked before the parts' figures are rounded for show below)
290
530
  const mostOwn = mostAtOwnArm();
291
- const bead = r3(undercut + c), Y = 2 * undercut, P = k * Y, length = lengthOf(bead);
292
- // The strains are judged unrounded (exact, below), and shown to 4 places: a bead held to the strain's limit could round over it
531
+ const bead = r3(undercut + c),
532
+ Y = 2 * undercut,
533
+ P = k * Y,
534
+ length = lengthOf(bead);
535
+ // The strains are judged unrounded (exact, below), and shown to 4 places: a bead held to the strain's limit could
536
+ // round over it
293
537
  const exact = new Map();
294
538
  // What a whole skirt would take for the same bead, to say what the slots save
295
539
  const Pwhole = Y / (1 / B.stiffness + 1 / whole.stiffness);
296
- for (const q of [B, L]) { const e = { strain: P * q.perP, root: q.rootPerP != null ? P * q.rootPerP : null }; exact.set(q, e);
297
- q.deflection = r3(P / q.stiffness); q.strain = n4(e.strain); if (q.rootPerP != null) { q.root = n4(e.root); delete q.rootPerP; } delete q.perP; if (q.X != null) q.X = +q.X.toPrecision(3); q.stiffness = n1(q.stiffness); }
298
- const insertion = along(P, lead, mu), removal = along(P, back, mu), holds = !Number.isFinite(removal), most = mostOwn;
540
+ for (const q of [B, L]) {
541
+ const e = { strain: P * q.perP, root: q.rootPerP != null ? P * q.rootPerP : null };
542
+ exact.set(q, e);
543
+ q.deflection = r3(P / q.stiffness);
544
+ q.strain = n4(e.strain);
545
+ if (q.rootPerP != null) {
546
+ q.root = n4(e.root);
547
+ delete q.rootPerP;
548
+ }
549
+ delete q.perP;
550
+ if (q.X != null) q.X = +q.X.toPrecision(3);
551
+ q.stiffness = n1(q.stiffness);
552
+ }
553
+ const insertion = along(P, lead, mu),
554
+ removal = along(P, back, mu),
555
+ holds = !Number.isFinite(removal),
556
+ most = mostOwn;
299
557
 
300
- const out = [], rests = [], cited = (m) => `${m.strength.name} ${mm(m.strength.value)} MPa over ${m.modulus.name} ${mm(m.modulus.value)} MPa`;
301
- rests.push(pr.rest('fit'), pr.rest('overhang'), rest(box.modulus.name, box.modulus), rest(box.strength.name, box.strength), rest(box.poisson.name, box.poisson),
302
- rest('fixings.snap_brief', DEFAULTS.snap_brief), ...(uses === 'often' ? [rest('fixings.snap_often', DEFAULTS.snap_often)] : []), rest('fixings.snap_remote', DEFAULTS.snap_remote), pr.rest('line'));
303
- if (lidMat !== box && lidMat.name !== box.name) rests.push(rest(lidMat.modulus.name, lidMat.modulus), rest(lidMat.strength.name, lidMat.strength), rest(lidMat.poisson.name, lidMat.poisson));
558
+ const out = [],
559
+ rests = [],
560
+ cited = (m) => `${m.strength.name} ${mm(m.strength.value)} MPa over ${m.modulus.name} ${mm(m.modulus.value)} MPa`;
561
+ rests.push(
562
+ pr.rest('fit'),
563
+ pr.rest('overhang'),
564
+ rest(box.modulus.name, box.modulus),
565
+ rest(box.strength.name, box.strength),
566
+ rest(box.poisson.name, box.poisson),
567
+ rest('fixings.snap_brief', DEFAULTS.snap_brief),
568
+ ...(uses === 'often' ? [rest('fixings.snap_often', DEFAULTS.snap_often)] : []),
569
+ rest('fixings.snap_remote', DEFAULTS.snap_remote),
570
+ pr.rest('line'),
571
+ );
572
+ if (lidMat !== box && lidMat.name !== box.name)
573
+ rests.push(
574
+ rest(lidMat.modulus.name, lidMat.modulus),
575
+ rest(lidMat.strength.name, lidMat.strength),
576
+ rest(lidMat.poisson.name, lidMat.poisson),
577
+ );
304
578
  if (o.friction == null) rests.push(rest('fixings.snap_friction', DEFAULTS.snap_friction));
305
579
  if (sized) rests.push(rest('fixings.snap_least', DEFAULTS.snap_least));
306
580
  if (slots && !slots.given) rests.push(rest('fixings.snap_slot', DEFAULTS.snap_slot));
307
581
  if (pull != null) rests.push(rest('fixings.load_margin', DEFAULTS.load_margin));
308
- out.push(finding('info', `a ${mm(bead)} mm bead round the ${mm(d)} mm box, in a skirt ${mm(c)} mm clear of the wall (${pr.cite('fit')}): ${mm(undercut)} mm of undercut, ${mm(r3(Y))} mm on the diameter, shared by the box's wall (${mm(B.deflection)} mm) and the lid's skirt (${mm(L.deflection)} mm)${sized ? `, ${sizeSays}` : ''}`,
309
- 'snap.undercut', { values: { bead, undercut, interference: r3(Y), box: B.deflection, lid: L.deflection } }));
310
- for (const [q, name, m] of [[B, 'the box\'s wall', box], [L, slots ? 'the lid\'s fingers' : 'the lid\'s skirt', lidMat]]) {
311
- const ok = exact.get(q).strain <= permissible * (1 + 1e-9), bent = q === L && slots;
312
- out.push(finding(ok ? 'pass' : 'fail', `${name} ${bent ? 'are' : 'is'} ${ok ? '' : 'over its limit: '}${pc(q.strain)} ${bent ? `bending strain at their root (each pushed out ${mm(r3(q.deflection / 2))} mm at ${mm(r3(arm))} mm from it, where the bead bears)` : `hoop strain (${mm(q.deflection)} mm over ${mm(q.diameter)} mm)`} where ${m.name} may see ${pc(permissible)}: ${mm(DEFAULTS.snap_brief.value)} of its yield strain, ${cited(m)}${uses === 'often' ? `, and ${mm(DEFAULTS.snap_often.value)} of that since it is opened often` : ''}${ok ? '' : `. The most undercut the strain allows is ${mm(most.undercut)} mm: a smaller bead, a thinner ${q === B ? 'wall' : 'skirt'}, ${bent ? 'longer fingers' : 'or a bigger box'}`}`,
313
- 'snap.strain', { values: { strain: q.strain, permissible: n4(permissible), deflection: q.deflection, diameter: q.diameter }, refs: { part: q === B ? 'box' : 'lid', material: m.name } }));
582
+ out.push(
583
+ finding(
584
+ 'info',
585
+ `a ${mm(bead)} mm bead round the ${mm(d)} mm box, in a skirt ${mm(c)} mm clear of the wall (` +
586
+ `${pr.cite('fit')}): ${mm(undercut)} mm of undercut, ${mm(r3(Y))} mm on the diameter, shared by the ` +
587
+ `box's wall (${mm(B.deflection)} mm) and the lid's skirt (${mm(L.deflection)} mm)` +
588
+ `${sized ? `, ${sizeSays}` : ''}`,
589
+ 'snap.undercut',
590
+ { values: { bead, undercut, interference: r3(Y), box: B.deflection, lid: L.deflection } },
591
+ ),
592
+ );
593
+ for (const [q, name, m] of [
594
+ [B, "the box's wall", box],
595
+ [L, slots ? "the lid's fingers" : "the lid's skirt", lidMat],
596
+ ]) {
597
+ const ok = exact.get(q).strain <= permissible * (1 + 1e-9),
598
+ bent = q === L && slots;
599
+ out.push(
600
+ finding(
601
+ ok ? 'pass' : 'fail',
602
+ `${name} ${bent ? 'are' : 'is'} ${ok ? '' : 'over its limit: '}${pc(q.strain)} ` +
603
+ (bent
604
+ ? `bending strain at their root (each pushed out ${mm(r3(q.deflection / 2))} mm at ${mm(r3(arm))} mm ` +
605
+ `from it, where the bead bears)`
606
+ : `hoop strain (${mm(q.deflection)} mm over ${mm(q.diameter)} mm)`) +
607
+ ` where ${m.name} may see ${pc(permissible)}: ${mm(DEFAULTS.snap_brief.value)} of its yield strain, ` +
608
+ `${cited(m)}` +
609
+ (uses === 'often' ? `, and ${mm(DEFAULTS.snap_often.value)} of that since it is opened often` : '') +
610
+ (ok
611
+ ? ''
612
+ : `. The most undercut the strain allows is ${mm(most.undercut)} mm: a smaller bead, a thinner ` +
613
+ `${q === B ? 'wall' : 'skirt'}, ` +
614
+ (bent ? 'longer fingers' : 'or a bigger box')),
615
+ 'snap.strain',
616
+ {
617
+ values: { strain: q.strain, permissible: n4(permissible), deflection: q.deflection, diameter: q.diameter },
618
+ refs: { part: q === B ? 'box' : 'lid', material: m.name },
619
+ },
620
+ ),
621
+ );
314
622
  }
315
- for (const [q, name, m, endName] of [[B, 'the box\'s wall', box, 'floor'], [L, 'the lid\'s skirt', lidMat, 'top']]) {
623
+ for (const [q, name, m, endName] of [
624
+ [B, "the box's wall", box, 'floor'],
625
+ [L, "the lid's skirt", lidMat, 'top'],
626
+ ]) {
316
627
  if (q.closed == null) continue;
317
- out.push(finding('info', `${name} meets its ${endName} ${mm(n2(q.closed))} mm from the joint, where a tube's wall bends over about 1/β = ${mm(q.decay)} mm: ${q.stiffer >= 1.01 ? `held round there, it is ${mm(q.stiffer)} times as stiff as the same tube open` : 'far enough off to make no difference to its stiffness'} (Hetényi's beam on an elastic foundation, the ${endName} taken as fully closed, the stiffest it can be)`,
318
- 'snap.closed', { values: { closed: q.closed, decay: q.decay, stiffer: q.stiffer }, refs: { part: q === B ? 'box' : 'lid' } }));
628
+ out.push(
629
+ finding(
630
+ 'info',
631
+ `${name} meets its ${endName} ${mm(n2(q.closed))} mm from the joint, where a tube's wall bends over ` +
632
+ `about 1/β = ${mm(q.decay)} mm: ` +
633
+ (q.stiffer >= 1.01
634
+ ? `held round there, it is ${mm(q.stiffer)} times as stiff as the same tube open`
635
+ : 'far enough off to make no difference to its stiffness') +
636
+ ` (Hetényi's beam on an elastic foundation, the ${endName} taken as fully closed, the stiffest it ` +
637
+ `can be)`,
638
+ 'snap.closed',
639
+ { values: { closed: q.closed, decay: q.decay, stiffer: q.stiffer }, refs: { part: q === B ? 'box' : 'lid' } },
640
+ ),
641
+ );
319
642
  const ok = exact.get(q).root <= permissible * (1 + 1e-9);
320
- out.push(finding(ok ? 'pass' : 'fail', `${name} bends where it meets its ${endName}: ${pc(q.root)} strain at the root where ${m.name} may see ${pc(permissible)}${ok ? '' : `. Move the joint further from the ${endName} (the wall bends over about 1/β, ${mm(q.decay)} mm), or a smaller bead: the most undercut the strain allows is ${mm(most.undercut)} mm`}`,
321
- 'snap.root', { values: { strain: q.root, permissible: n4(permissible), closed: q.closed }, refs: { part: q === B ? 'box' : 'lid', material: m.name } }));
643
+ out.push(
644
+ finding(
645
+ ok ? 'pass' : 'fail',
646
+ `${name} bends where it meets its ${endName}: ${pc(q.root)} strain at the root where ${m.name} may ` +
647
+ `see ${pc(permissible)}` +
648
+ (ok
649
+ ? ''
650
+ : `. Move the joint further from the ${endName} (the wall bends over about 1/β, ${mm(q.decay)} mm), or ` +
651
+ `a smaller bead: the most undercut the strain allows is ${mm(most.undercut)} mm`),
652
+ 'snap.root',
653
+ {
654
+ values: { strain: q.root, permissible: n4(permissible), closed: q.closed },
655
+ refs: { part: q === B ? 'box' : 'lid', material: m.name },
656
+ },
657
+ ),
658
+ );
322
659
  }
323
660
  // The groove is cut the bead's depth into the skirt: what is left behind it must print as a wall of at least one line
324
- const line = pr.n('line'), left = r3(s - bead), thick = left >= line - 1e-9;
325
- out.push(finding(thick ? 'pass' : 'fail', `the groove leaves ${mm(left)} mm of the ${mm(s)} mm skirt behind it${thick ? `, at least the ${pr.cite('line')} ${mm(line)} mm line` : `, under the ${pr.cite('line')} ${mm(line)} mm line, so it prints thin or not at all: a thicker skirt, or a smaller bead`}`,
326
- 'snap.skirt', { values: { left, skirt: s, line } }));
327
- if (undercut < least - 1e-9) out.push(finding('warn', `an undercut of ${mm(undercut)} mm is under fixings.snap_least, ${mm(least)} mm: the print's own error is that size, so the lid may not catch, or catch only in places`, 'snap.least', { values: { undercut, least } }));
328
- if (slots) out.push(finding('info', `the skirt is slotted into ${slots.count} fingers by ${mm(slots.width)} mm slots${slots.given ? '' : ' (fixings.snap_slot)'}, each ${mm(n2(finger.width))} mm wide and ${mm(slots.reach)} mm from the slots' closed end to the groove, and borne on by the bead at the groove's bottom edge, ${mm(r3(arm))} mm from it: ${mm(n1(finger.stiffness))} N per mm pushed out there, a cantilever (3 E I / L³, I ${mm(n2(finger.inertia))} mm⁴). A whole skirt would take ${mm(n1(Pwhole))} N of transverse force for this bead, the fingers ${mm(n1(P))} N, ${mm(n1(Pwhole / P))} times less`,
329
- 'snap.fingers', { values: { count: slots.count, width: slots.width, reach: slots.reach, arm: r3(arm), finger: n2(finger.width), stiffness: n1(finger.stiffness), force: n1(P), whole: n1(Pwhole), less: n2(Pwhole / P) } }));
330
- out.push(finding('info', `${mm(n1(insertion))} N to push the lid on square and ${holds ? 'it holds for good (a square return face)' : `${mm(n1(removal))} N to pull it off square`}: a transverse force of ${mm(n1(P))} N (${slots ? `the wall as Bayer's annular snap joint, P = y d Es X with X ${mm(B.X)}, and the skirt as ${slots.count} cantilever fingers` : `P = y d Es X, Bayer's annular snap joint, X ${mm(B.X)} for the wall and ${mm(L.X)} for the skirt`}) through the ${mm(lead)}° lead and ${mm(back)}° return faces at μ ${mm(mu)}. Pressed on at a tilt, a part of the bead at a time, it takes much less, as the guide says of a lid put on by hand`,
331
- 'snap.forces', { values: { force: n1(P), insertion: n1(insertion), removal: Number.isFinite(removal) ? n1(removal) : null, friction: mu } }));
332
- if (B.remote > 1 || L.remote > 1) out.push(finding('info', `the joint lies in from a free end (box ${mm(boxEnd)} mm of ${mm(B.far)}${slots ? '' : `, lid ${mm(lidEnd)} mm of ${mm(L.far)}`}, where 1.8 √(d t) counts as remote), so it is stiffer by ${slots ? `${mm(B.remote)} times (the fingers are cantilevers, which have no remote joint)` : `${mm(B.remote)} and ${mm(L.remote)} times`}: the guide gives 3 at a remote joint, and the line between is an estimate`, 'snap.remote', { values: { box: B.remote, lid: L.remote } }));
333
- if (push != null) { const ok = insertion <= push; out.push(finding(ok ? 'pass' : 'warn', `pushed with ${mm(push)} N, the lid goes on ${ok ? `square, ${mm(n1(insertion))} N` : `only at a tilt: square it takes ${mm(n1(insertion))} N. A shallower lead or a smaller bead lowers it`}`, 'snap.push', { values: { push, insertion: n1(insertion) } })); }
661
+ const line = pr.n('line'),
662
+ left = r3(s - bead),
663
+ thick = left >= line - 1e-9;
664
+ out.push(
665
+ finding(
666
+ thick ? 'pass' : 'fail',
667
+ `the groove leaves ${mm(left)} mm of the ${mm(s)} mm skirt behind it` +
668
+ (thick
669
+ ? `, at least the ${pr.cite('line')} ${mm(line)} mm line`
670
+ : `, under the ${pr.cite('line')} ${mm(line)} mm line, so it prints thin or not at all: a thicker skirt, ` +
671
+ `or a smaller bead`),
672
+ 'snap.skirt',
673
+ { values: { left, skirt: s, line } },
674
+ ),
675
+ );
676
+ if (undercut < least - 1e-9)
677
+ out.push(
678
+ finding(
679
+ 'warn',
680
+ `an undercut of ${mm(undercut)} mm is under fixings.snap_least, ${mm(least)} mm: the print's own ` +
681
+ `error is that size, so the lid may not catch, or catch only in places`,
682
+ 'snap.least',
683
+ { values: { undercut, least } },
684
+ ),
685
+ );
686
+ if (slots)
687
+ out.push(
688
+ finding(
689
+ 'info',
690
+ `the skirt is slotted into ${slots.count} fingers by ${mm(slots.width)} mm slots` +
691
+ (slots.given ? '' : ' (fixings.snap_slot)') +
692
+ `, each ${mm(n2(finger.width))} mm wide and ${mm(slots.reach)} mm from the slots' closed end to the ` +
693
+ `groove, and borne on by the bead at the groove's bottom edge, ${mm(r3(arm))} mm from it: ` +
694
+ `${mm(n1(finger.stiffness))} N per mm pushed out there, a cantilever (3 E I / L³, I ` +
695
+ `${mm(n2(finger.inertia))} mm⁴). A whole skirt would take ${mm(n1(Pwhole))} N of transverse force ` +
696
+ `for this bead, the fingers ${mm(n1(P))} N, ${mm(n1(Pwhole / P))} times less`,
697
+ 'snap.fingers',
698
+ {
699
+ values: {
700
+ count: slots.count,
701
+ width: slots.width,
702
+ reach: slots.reach,
703
+ arm: r3(arm),
704
+ finger: n2(finger.width),
705
+ stiffness: n1(finger.stiffness),
706
+ force: n1(P),
707
+ whole: n1(Pwhole),
708
+ less: n2(Pwhole / P),
709
+ },
710
+ },
711
+ ),
712
+ );
713
+ out.push(
714
+ finding(
715
+ 'info',
716
+ `${mm(n1(insertion))} N to push the lid on square and ` +
717
+ (holds ? 'it holds for good (a square return face)' : `${mm(n1(removal))} N to pull it off square`) +
718
+ `: a transverse force of ${mm(n1(P))} N (` +
719
+ (slots
720
+ ? `the wall as Bayer's annular snap joint, P = y d Es X with X ${mm(B.X)}, and the skirt as ` +
721
+ `${slots.count} cantilever fingers`
722
+ : `P = y d Es X, Bayer's annular snap joint, X ${mm(B.X)} for the wall and ${mm(L.X)} for the skirt`) +
723
+ `) through the ${mm(lead)}° lead and ${mm(back)}° return faces at μ ${mm(mu)}. Pressed on at a tilt, a ` +
724
+ `part of the bead at a time, it takes much less, as the guide says of a lid put on by hand`,
725
+ 'snap.forces',
726
+ {
727
+ values: {
728
+ force: n1(P),
729
+ insertion: n1(insertion),
730
+ removal: Number.isFinite(removal) ? n1(removal) : null,
731
+ friction: mu,
732
+ },
733
+ },
734
+ ),
735
+ );
736
+ if (B.remote > 1 || L.remote > 1)
737
+ out.push(
738
+ finding(
739
+ 'info',
740
+ `the joint lies in from a free end (box ${mm(boxEnd)} mm of ${mm(B.far)}` +
741
+ (slots ? '' : `, lid ${mm(lidEnd)} mm of ${mm(L.far)}`) +
742
+ `, where 1.8 √(d t) counts as remote), so it is stiffer by ` +
743
+ (slots
744
+ ? `${mm(B.remote)} times (the fingers are cantilevers, which have no remote joint)`
745
+ : `${mm(B.remote)} and ${mm(L.remote)} times`) +
746
+ `: the guide gives 3 at a remote joint, and the line between is an estimate`,
747
+ 'snap.remote',
748
+ { values: { box: B.remote, lid: L.remote } },
749
+ ),
750
+ );
751
+ if (push != null) {
752
+ const ok = insertion <= push;
753
+ out.push(
754
+ finding(
755
+ ok ? 'pass' : 'warn',
756
+ `pushed with ${mm(push)} N, the lid goes on ` +
757
+ (ok
758
+ ? `square, ${mm(n1(insertion))} N`
759
+ : `only at a tilt: square it takes ${mm(n1(insertion))} N. A shallower lead or a smaller bead lowers it`),
760
+ 'snap.push',
761
+ { values: { push, insertion: n1(insertion) } },
762
+ ),
763
+ );
764
+ }
334
765
  const margin = pull != null ? (holds ? Infinity : n2(removal / pull)) : null;
335
- if (pull != null) out.push(finding(margin >= want ? 'pass' : margin >= 1 ? 'warn' : 'fail', `pulled with ${mm(pull)} N, the lid stays on ${holds ? 'for good' : `${mm(margin)} times over (${mm(n1(removal))} N)`}${margin >= want ? '' : margin >= 1 ? `, under the ${mm(want)} times fixings.load_margin asks` : ': it comes off'}${margin >= want ? '' : `. The strain allows up to ${mm(most.undercut)} mm of undercut, which would hold ${mm(most.removal)} N`}`,
336
- 'snap.hold', { values: { pull, removal: Number.isFinite(removal) ? n1(removal) : null, margin: Number.isFinite(margin) ? margin : null, want } }));
337
- else out.push(finding('info', `give pull, the force the lid must stay on against, to have its hold checked`, 'snap.hold'));
766
+ if (pull != null)
767
+ out.push(
768
+ finding(
769
+ margin >= want ? 'pass' : margin >= 1 ? 'warn' : 'fail',
770
+ `pulled with ${mm(pull)} N, the lid stays on ` +
771
+ (holds ? 'for good' : `${mm(margin)} times over (${mm(n1(removal))} N)`) +
772
+ (margin >= want
773
+ ? ''
774
+ : margin >= 1
775
+ ? `, under the ${mm(want)} times fixings.load_margin asks`
776
+ : ': it comes off') +
777
+ (margin >= want
778
+ ? ''
779
+ : `. The strain allows up to ${mm(most.undercut)} mm of undercut, which would hold ${mm(most.removal)} ` +
780
+ `N`),
781
+ 'snap.hold',
782
+ {
783
+ values: {
784
+ pull,
785
+ removal: Number.isFinite(removal) ? n1(removal) : null,
786
+ margin: Number.isFinite(margin) ? margin : null,
787
+ want,
788
+ },
789
+ },
790
+ ),
791
+ );
792
+ else
793
+ out.push(
794
+ finding('info', `give pull, the force the lid must stay on against, to have its hold checked`, 'snap.hold'),
795
+ );
338
796
  // Printing: the box stands on its floor, so the bead's return face is an overhang; the lid is printed on its top, so
339
797
  // the groove's face nearest the mouth, the return face's mate, is a ceiling at the same angle. The lead face and the
340
798
  // skirt's lead-in lean the other way and always print
341
799
  const prints = back <= overhang + 1e-9;
342
- out.push(finding(prints ? 'pass' : 'fail', prints ? `the box printed standing on its floor and the lid on its top print with no support: the bead's ${mm(back)}° return face and the groove's mating face are within ${pr.cite('overhang')} ${mm(overhang)}°, and the ${mm(lead)}° lead face leans the way that always prints`
343
- : `the ${mm(back)}° return face is past ${pr.cite('overhang')} ${mm(overhang)}°: under the box's bead and over the lid's groove it needs support. Give back ${mm(overhang)}° or less; a steeper face holds harder, so let the bead be taller instead`, 'snap.printable', { values: { back, overhang } }));
800
+ out.push(
801
+ finding(
802
+ prints ? 'pass' : 'fail',
803
+ prints
804
+ ? `the box printed standing on its floor and the lid on its top print with no support: the bead's ` +
805
+ `${mm(back)}° return face and the groove's mating face are within ${pr.cite('overhang')} ` +
806
+ `${mm(overhang)}°, and the ${mm(lead)}° lead face leans the way that always prints`
807
+ : `the ${mm(back)}° return face is past ${pr.cite('overhang')} ${mm(overhang)}°: under the box's bead ` +
808
+ `and over the lid's groove it needs support. Give back ${mm(overhang)}° or less; a steeper face ` +
809
+ `holds harder, so let the bead be taller instead`,
810
+ 'snap.printable',
811
+ { values: { back, overhang } },
812
+ ),
813
+ );
344
814
  const groove = { inner: r3(dh / 2), outer: r3(dh / 2 + bead), depth: bead };
345
- return { kind: 'annular snap', diameter: d, wall: t, skirt: s, clearance: c, bead, length, undercut, interference: r3(Y), lead, back, land, sized, uses, material: box.name, lidMaterial: lidMat.name, friction: mu,
346
- permissible: n4(permissible), box: B, lid: L, ...(slots ? { slots: { count: slots.count, width: slots.width, reach: slots.reach, arm: r3(arm), finger: { angle: n2(finger.angle), width: n2(finger.width), inertia: n4(finger.inertia), fibre: n4(finger.fibre), stiffness: n1(finger.stiffness) }, whole: n1(Pwhole) } } : {}), force: n1(P), insertion: Number.isFinite(insertion) ? n1(insertion) : Infinity, removal: Number.isFinite(removal) ? n1(removal) : Infinity, holds, pull, margin, most, groove, rests, findings: out };
815
+ return {
816
+ kind: 'annular snap',
817
+ diameter: d,
818
+ wall: t,
819
+ skirt: s,
820
+ clearance: c,
821
+ bead,
822
+ length,
823
+ undercut,
824
+ interference: r3(Y),
825
+ lead,
826
+ back,
827
+ land,
828
+ sized,
829
+ uses,
830
+ material: box.name,
831
+ lidMaterial: lidMat.name,
832
+ friction: mu,
833
+ permissible: n4(permissible),
834
+ box: B,
835
+ lid: L,
836
+ ...(slots
837
+ ? {
838
+ slots: {
839
+ count: slots.count,
840
+ width: slots.width,
841
+ reach: slots.reach,
842
+ arm: r3(arm),
843
+ finger: {
844
+ angle: n2(finger.angle),
845
+ width: n2(finger.width),
846
+ inertia: n4(finger.inertia),
847
+ fibre: n4(finger.fibre),
848
+ stiffness: n1(finger.stiffness),
849
+ },
850
+ whole: n1(Pwhole),
851
+ },
852
+ }
853
+ : {}),
854
+ force: n1(P),
855
+ insertion: Number.isFinite(insertion) ? n1(insertion) : Infinity,
856
+ removal: Number.isFinite(removal) ? n1(removal) : Infinity,
857
+ holds,
858
+ pull,
859
+ margin,
860
+ most,
861
+ groove,
862
+ rests,
863
+ findings: out,
864
+ };
347
865
  }
348
866
 
349
867
  // The bead's outline in [radius, z] from its foot on the wall at z: up the return face, along the land, down the lead
350
868
  // face, sunk into the wall by a little so it joins it
351
869
  const beadOutline = (m, z, grow = 0) => {
352
- const R = m.diameter / 2 + grow, h = m.bead, rise = h / tan(m.back), fall = h / tan(m.lead), sink = Math.min(m.wall / 2, 0.3);
353
- const z0 = z - grow, top = z0 + rise + m.land + 2 * grow + fall;
354
- return [[R - sink - grow, z0], [R, z0], [R + h, z0 + rise], [R + h, z0 + rise + m.land + 2 * grow], [R, top], [R - sink - grow, top]];
870
+ const R = m.diameter / 2 + grow,
871
+ h = m.bead,
872
+ rise = h / tan(m.back),
873
+ fall = h / tan(m.lead),
874
+ sink = Math.min(m.wall / 2, 0.3);
875
+ const z0 = z - grow,
876
+ top = z0 + rise + m.land + 2 * grow + fall;
877
+ return [
878
+ [R - sink - grow, z0],
879
+ [R, z0],
880
+ [R + h, z0 + rise],
881
+ [R + h, z0 + rise + m.land + 2 * grow],
882
+ [R, top],
883
+ [R - sink - grow, top],
884
+ ];
355
885
  };
356
886
  /**
357
887
  * The bead to add to the box: a ring round the wall's outside, its foot (the bottom of the return face) at z = at.
358
888
  * Union it with a box whose wall's outside is the model's diameter about the z axis.
359
889
  * @param {object | AnnularSnap} p the joint's figures, as annularSnapModel takes them, or its model
360
- * @param {object} [o] as annularSnapModel, and at: the bead's foot, mm up z (default 0); segments: faces round (default 96)
890
+ * @param {object} [o] as annularSnapModel, and at: the bead's foot, mm up z (default 0); segments: faces round (default
891
+ * 96)
361
892
  * @returns {object} a JSCAD geom3 with .model
362
893
  */
363
894
  export function annularBead(p, o = {}) {
364
- const m = p?.kind === 'annular snap' ? p : annularSnapModel(p, o), at = o.at ?? 0, n = o.segments ?? 96;
895
+ const m = p?.kind === 'annular snap' ? p : annularSnapModel(p, o),
896
+ at = o.at ?? 0,
897
+ n = o.segments ?? 96;
365
898
  if (!isNum(at)) throw new Error(`annularBead: at is the bead's foot up z, in mm (got ${shown(o.at)})`);
366
899
  return Object.assign(lathe(beadOutline(m, at), n), { model: m });
367
900
  }
@@ -375,16 +908,47 @@ export function annularBead(p, o = {}) {
375
908
  * @returns {object} a JSCAD geom3 to subtract, with .model
376
909
  */
377
910
  export function annularGroove(p, o = {}) {
378
- const what = 'annularGroove', m = p?.kind === 'annular snap' ? p : annularSnapModel(p, o), at = o.at ?? 0, n = o.segments ?? 96, c = m.clearance;
911
+ const what = 'annularGroove',
912
+ m = p?.kind === 'annular snap' ? p : annularSnapModel(p, o),
913
+ at = o.at ?? 0,
914
+ n = o.segments ?? 96,
915
+ c = m.clearance;
379
916
  if (!isNum(at)) throw new Error(`${what}: at is the bead's foot up z, in mm (got ${shown(o.at)})`);
380
917
  const ring = beadOutline(m, at, c);
381
918
  if (o.mouth == null) return Object.assign(lathe(ring, n), { model: m });
382
- if (!(isNum(o.mouth) && o.mouth < at - c - 1e-9)) throw new Error(`${what}: mouth is the z of the skirt's open end, below the groove's foot at ${mm(at - c)} mm (got ${shown(o.mouth)})`);
919
+ if (!(isNum(o.mouth) && o.mouth < at - c - 1e-9))
920
+ throw new Error(
921
+ `${what}: mouth is the z of the skirt's open end, below the groove's foot at ${mm(at - c)} mm (got ` +
922
+ `${shown(o.mouth)})`,
923
+ );
383
924
  // The lead-in: from the groove's full radius at the mouth up to the skirt's inside, joined to the groove by a band at
384
925
  // the skirt's inside so the two are one cutter
385
- const R = m.diameter / 2 + c, h = m.bead, rise = h / tan(m.lead), z = o.mouth - 0.1, sink = Math.min(m.wall / 2, 0.3) + c;
926
+ const R = m.diameter / 2 + c,
927
+ h = m.bead,
928
+ rise = h / tan(m.lead),
929
+ z = o.mouth - 0.1,
930
+ sink = Math.min(m.wall / 2, 0.3) + c;
386
931
  const top = Math.min(o.mouth + rise, ring[1][1]);
387
- return Object.assign(lathe([[R - sink, z], [R + h, z], [R + h, o.mouth], [R + h - (top - o.mouth) * tan(m.lead), top], ...(top < ring[1][1] ? [[R, top], [R, ring[1][1]]] : []), ...ring.slice(1, -1), [R - sink, ring.at(-1)[1]]], n), { model: m });
932
+ return Object.assign(
933
+ lathe(
934
+ [
935
+ [R - sink, z],
936
+ [R + h, z],
937
+ [R + h, o.mouth],
938
+ [R + h - (top - o.mouth) * tan(m.lead), top],
939
+ ...(top < ring[1][1]
940
+ ? [
941
+ [R, top],
942
+ [R, ring[1][1]],
943
+ ]
944
+ : []),
945
+ ...ring.slice(1, -1),
946
+ [R - sink, ring.at(-1)[1]],
947
+ ],
948
+ n,
949
+ ),
950
+ { model: m },
951
+ );
388
952
  }
389
953
 
390
954
  /**
@@ -393,23 +957,49 @@ export function annularGroove(p, o = {}) {
393
957
  * model's reach above the groove's top edge, and ends in a full round half the slot wide, so the root that takes each
394
958
  * finger's bending has no square corner. The first slot is centred on +x.
395
959
  * @param {AnnularSnap} m a model from annularSnapModel with slots
396
- * @param {{ at?: number, mouth: number, segments?: number }} o at: the bead's foot (default 0); mouth: the z of the skirt's
960
+ * @param {{ at?: number, mouth: number, segments?: number }} o at: the bead's foot (default 0); mouth: the z of the
961
+ * skirt's
397
962
  * open end; segments: faces round the slot's end (default 24)
398
963
  * @returns {object} a JSCAD geom3 to subtract, the slots together, with .model
399
964
  */
400
965
  export function snapSlots(m, o = {}) {
401
966
  const what = 'snapSlots';
402
- if (m?.kind !== 'annular snap' || !m.slots) throw new Error(`${what}: give an annular snap's model with slots (annularSnapModel({ ..., slots: { count, reach } })), not ${shown(m?.kind ?? m)}`);
403
- const at = o.at ?? 0, n = o.segments ?? 24, { count, width: w, reach } = m.slots;
967
+ if (m?.kind !== 'annular snap' || !m.slots)
968
+ throw new Error(
969
+ `${what}: give an annular snap's model with slots (annularSnapModel({ ..., slots: { count, reach } ` +
970
+ `})), not ${shown(m?.kind ?? m)}`,
971
+ );
972
+ const at = o.at ?? 0,
973
+ n = o.segments ?? 24,
974
+ { count, width: w, reach } = m.slots;
404
975
  if (!isNum(at)) throw new Error(`${what}: at is the bead's foot up z, in mm (got ${shown(o.at)})`);
405
976
  const root = at + m.length + m.clearance + reach;
406
- if (!(isNum(o.mouth) && o.mouth < root - w)) throw new Error(`${what}: mouth is the z of the skirt's open end, below the slots' closed end at ${mm(r3(root))} mm (got ${shown(o.mouth)})`);
977
+ if (!(isNum(o.mouth) && o.mouth < root - w))
978
+ throw new Error(
979
+ `${what}: mouth is the z of the skirt's open end, below the slots' closed end at ${mm(r3(root))} mm ` +
980
+ `(got ${shown(o.mouth)})`,
981
+ );
407
982
  // The slot's outline in (z, across): up from below the mouth to its round end, drawn in the xy plane and stood up
408
- const r = w / 2, z0 = o.mouth - OUT, zc = root - r;
409
- const outline = [[z0, -r], ...Array.from({ length: n + 1 }, (_, i) => { const a = -Math.PI / 2 + (Math.PI * i) / n; return [zc + r * Math.cos(a), r * Math.sin(a)]; }), [z0, r]];
410
- const ri = m.diameter / 2 + m.clearance - OUT, ro = m.diameter / 2 + m.clearance + m.skirt + OUT;
983
+ const r = w / 2,
984
+ z0 = o.mouth - OUT,
985
+ zc = root - r;
986
+ const outline = [
987
+ [z0, -r],
988
+ ...Array.from({ length: n + 1 }, (_, i) => {
989
+ const a = -Math.PI / 2 + (Math.PI * i) / n;
990
+ return [zc + r * Math.cos(a), r * Math.sin(a)];
991
+ }),
992
+ [z0, r],
993
+ ];
994
+ const ri = m.diameter / 2 + m.clearance - OUT,
995
+ ro = m.diameter / 2 + m.clearance + m.skirt + OUT;
411
996
  // extruded along z from -ro to -ri, then turned so its x is up z and its extrusion runs out along +x
412
- const one = rotateY(-Math.PI / 2, translate([0, 0, -ro], extrudeLinear({ height: ro - ri }, polygon({ points: outline }))));
413
- const polys = Array.from({ length: count }, (_, i) => geom3.toPolygons(rotateZ((2 * Math.PI * i) / count, one))).flat();
997
+ const one = rotateY(
998
+ -Math.PI / 2,
999
+ translate([0, 0, -ro], extrudeLinear({ height: ro - ri }, polygon({ points: outline }))),
1000
+ );
1001
+ const polys = Array.from({ length: count }, (_, i) =>
1002
+ geom3.toPolygons(rotateZ((2 * Math.PI * i) / count, one)),
1003
+ ).flat();
414
1004
  return Object.assign(geom3.create(polys), { model: m });
415
1005
  }