@rulecad/fixings 0.1.8 → 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/seats.mjs CHANGED
@@ -5,7 +5,25 @@
5
5
  // A cutter starts at a point on a face (at) and goes into the part along a direction (into).
6
6
  import jscad from '@jscad/modeling';
7
7
  import { countersink as cone90, nutPocket as hexPocket, wallOpening } from '@rulecad/shapes';
8
- import { DEFAULTS, fixingOf, printerOf, headOf, nutOf, figure, cite, rest, finding, positive, oneOf, isNum, shown, mm, r3, a, layers } from './model.mjs';
8
+ import {
9
+ DEFAULTS,
10
+ fixingOf,
11
+ printerOf,
12
+ headOf,
13
+ nutOf,
14
+ figure,
15
+ cite,
16
+ rest,
17
+ finding,
18
+ positive,
19
+ oneOf,
20
+ isNum,
21
+ shown,
22
+ mm,
23
+ r3,
24
+ a,
25
+ layers,
26
+ } from './model.mjs';
9
27
  import { holeModel, directionOf, pointOf, optionsOf, said, inPart } from './holes.mjs';
10
28
  import { along, bore, lathe, teardrop, UP, OUT, SEGMENTS, DIRECTIONS } from './draw.mjs';
11
29
 
@@ -13,29 +31,49 @@ import { along, bore, lathe, teardrop, UP, OUT, SEGMENTS, DIRECTIONS } from './d
13
31
  * @typedef {import('./model.mjs').Fixing} Fixing a fixing's model, as fixingModel gives it
14
32
  */
15
33
 
16
- const { cuboid, cylinderElliptic, polygon } = jscad.primitives, { translate, rotateZ, transform } = jscad.transforms, { extrudeLinear } = jscad.extrusions;
34
+ const { cuboid, cylinderElliptic, polygon } = jscad.primitives,
35
+ { translate, rotateZ, transform } = jscad.transforms,
36
+ { extrudeLinear } = jscad.extrusions;
17
37
  const COS30 = Math.cos(Math.PI / 6);
18
38
  const CLEARANCES = ['clearance', 'close', 'loose'];
19
39
  // The hole a seat sits on: one of the clearances
20
40
  function through(what, fx, o) {
21
- const kind = oneOf(what, 'hole', o.hole ?? 'clearance', CLEARANCES), n = kind === 'clearance' ? kind : `clearance_${kind}`;
22
- if (!fx.figures[n]) throw new Error(`${what}: ${fx.thread} has no ${n} in its rule set (${fx.set}): a seat sits on a clearance hole, and this thread has no figure for one`);
41
+ const kind = oneOf(what, 'hole', o.hole ?? 'clearance', CLEARANCES),
42
+ n = kind === 'clearance' ? kind : `clearance_${kind}`;
43
+ if (!fx.figures[n])
44
+ throw new Error(
45
+ `${what}: ${fx.thread} has no ${n} in its rule set (${fx.set}): a seat sits on a clearance hole, and ` +
46
+ `this thread has no figure for one`,
47
+ );
23
48
  return holeModel(fx, { kind, printer: o.printer });
24
49
  }
25
50
  // A fit by name, from the printer's rules, or a clearance in mm as printed. For a nut (nut: true), snug and slip read
26
51
  // the printer's measured nut_fit and nut_slip first, where it has them (the fixings coupon measures both)
27
52
  function fitOf(what, fit, pr, nut = false) {
28
53
  if (isNum(fit)) return { name: fit, clearance: fit, rests: [] };
29
- if (!['snug', 'slip', 'press'].includes(fit)) throw new Error(`${what}: fit is snug (no clearance once printed), slip or press (the printer's), or a clearance in mm (got ${shown(fit)})`);
54
+ if (!['snug', 'slip', 'press'].includes(fit))
55
+ throw new Error(
56
+ `${what}: fit is snug (no clearance once printed), slip or press (the printer's), or a clearance in mm ` +
57
+ `(got ${shown(fit)})`,
58
+ );
30
59
  const own = nut && fit !== 'press' ? pr.figure(fit === 'snug' ? 'nut_fit' : 'nut_slip') : null;
31
- if (own) { if (!isNum(own.value)) throw new Error(`${what}: ${own.name} is a clearance in mm (got ${shown(own.value)})`); return { name: own.name.slice(own.name.lastIndexOf('.') + 1), clearance: own.value, rests: [rest(own.name, own)] }; }
32
- return fit === 'snug' ? { name: fit, clearance: 0, rests: [] } : { name: fit, clearance: fit === 'slip' ? pr.n('slip') : -pr.n('press'), rests: [pr.rest(fit)] };
60
+ if (own) {
61
+ if (!isNum(own.value)) throw new Error(`${what}: ${own.name} is a clearance in mm (got ${shown(own.value)})`);
62
+ return { name: own.name.slice(own.name.lastIndexOf('.') + 1), clearance: own.value, rests: [rest(own.name, own)] };
63
+ }
64
+ return fit === 'snug'
65
+ ? { name: fit, clearance: 0, rests: [] }
66
+ : { name: fit, clearance: fit === 'slip' ? pr.n('slip') : -pr.n('press'), rests: [pr.rest(fit)] };
33
67
  }
34
68
  const figures = (fx, names) => names.map((n) => rest(cite(fx, n), fx.figures[n]));
35
69
  const lengthOf = (what, o, least, why) => {
36
70
  if (o.length == null) return null;
37
71
  positive(what, 'length', o.length);
38
- if (o.length < least - 1e-9) throw new Error(`${what}: length is the whole hole's, from the face it starts at: ${mm(o.length)} mm is less than ${why} (${mm(least)} mm)`);
72
+ if (o.length < least - 1e-9)
73
+ throw new Error(
74
+ `${what}: length is the whole hole's, from the face it starts at: ${mm(o.length)} mm is less than ` +
75
+ `${why} (${mm(least)} mm)`,
76
+ );
39
77
  return o.length;
40
78
  };
41
79
 
@@ -44,47 +82,147 @@ const lengthOf = (what, o, least, why) => {
44
82
  * A counterbore for a screw's head, as numbers: wide enough for the head with the printer's fit round it, and deep
45
83
  * enough to hide it.
46
84
  * @param {Fixing | string} m
47
- * @param {{ head?: string, depth?: number, diameter?: number, length?: number, thickness?: number, hole?: string, printer?: object, into?: string, axis?: string, sets?: object }} [o]
85
+ * @param {{ head?: string, depth?: number, diameter?: number, length?: number, thickness?: number, hole?: string,
86
+ * printer?: object, into?: string, axis?: string, sets?: object }} [o]
48
87
  * head: cap, button, hex or pan (default the model's, else cap); depth: of the seat (default the head's height, up to
49
88
  * a whole layer); diameter: of the seat, for a socket's room; length: the whole hole's, from the face, to cut the
50
- * screw's hole as well; thickness: the part's there (a seat deeper than the part is refused); hole: clearance, close or loose
51
- * @returns {{ thread: string, head: string, diameter: number, depth: number, sunk: number, hole: number, length: number | null, cone: number, into: string, teardrop: boolean, rests: object[], findings: object[] }}
52
- * sunk: how far the head's top lies under the face (below 0: it stands proud); cone: the height of the 45° cone the seat ends in where it goes up from the bed
89
+ * screw's hole as well; thickness: the part's there (a seat deeper than the part is refused); hole: clearance, close
90
+ * or loose
91
+ * @returns {{ thread: string, head: string, diameter: number, depth: number, sunk: number, hole: number,
92
+ * length: number | null, cone: number, into: string, teardrop: boolean, rests: object[], findings: object[] }}
93
+ * sunk: how far the head's top lies under the face (below 0: it stands proud); cone: the height of the 45° cone the
94
+ * seat ends in where it goes up from the bed
53
95
  */
54
96
  export function counterboreModel(m, o = {}) {
55
97
  const what = 'counterbore';
56
- optionsOf(what, o, '{ head: \'cap\', length: 8 }');
57
- const fx = fixingOf(what, m, o), pr = printerOf(what, o.printer), dir = directionOf(what, o), out = [];
98
+ optionsOf(what, o, "{ head: 'cap', length: 8 }");
99
+ const fx = fixingOf(what, m, o),
100
+ pr = printerOf(what, o.printer),
101
+ dir = directionOf(what, o),
102
+ out = [];
58
103
  const form = o.head ?? fx.head?.form ?? (fx.made.heads.includes('cap') ? 'cap' : 'pan');
59
- if (form === 'countersunk') throw new Error(`${what}: a countersunk head sits in a cone, not a counterbore: use countersink`);
104
+ if (form === 'countersunk')
105
+ throw new Error(`${what}: a countersunk head sits in a cone, not a counterbore: use countersink`);
60
106
  if (form === 'set') throw new Error(`${what}: a set screw has no head to seat: it goes into its hole whole`);
61
- const head = headOf(what, fx, form), h = through(what, fx, o), fit = pr.n('fit'), comp = pr.n('hole_comp'), layer = pr.n('layer');
62
- const least = r3(head.across + comp), diameter = o.diameter == null ? r3(head.across + 2 * fit + comp) : positive(what, 'diameter', o.diameter);
63
- const depth = o.depth == null ? layers(head.height, layer) : positive(what, 'depth', o.depth), sunk = r3(depth - head.height);
64
- const cone = dir.into === '+z' ? r3((diameter - h.diameter) / 2) : 0, length = lengthOf(what, o, depth + cone, 'the seat\'s depth');
65
- inPart(what, o, depth + cone, `a seat ${mm(depth)} mm deep for ${a(fx.thread)} ${form} head${cone ? ` with its ${mm(cone)} mm cone` : ''}`);
66
- out.push(finding('info', `a counterbore for ${a(fx.thread)} ${form} head drawn ${mm(diameter)} mm across and ${mm(depth)} mm deep: the head is ${mm(head.across)} mm across${head.flats ? ' its corners' : ''} and ${mm(head.height)} mm high (${head.figures.map((n) => cite(fx, n)).join(', ')})${o.diameter == null ? `, with ${pr.cite('fit')} ${mm(fit)} mm each side and ${pr.cite('hole_comp')} ${mm(comp)} mm across` : ''}; its top lies ${sunk > 1e-9 ? `${mm(sunk)} mm under the face` : sunk < -1e-9 ? `${mm(-sunk)} mm proud of the face` : 'flush with the face'}`,
67
- 'counterbore.drawn', { values: { diameter, depth, sunk, hole: h.diameter }, refs: { thread: fx.thread, set: fx.set, head: form } }));
68
- if (diameter < least - 1e-9) out.push(finding('fail', `a ${mm(diameter)} mm seat is smaller than the ${mm(head.across)} mm head once printed: ${mm(least)} mm at least`, 'counterbore.diameter', { values: { diameter, least } }));
69
- if (sunk < -1e-9) out.push(finding('warn', `the head stands ${mm(-sunk)} mm proud of a ${mm(depth)} mm seat: ${mm(head.height)} mm hides it`, 'counterbore.proud', { values: { depth, head: head.height } }));
70
- if (form === 'hex' && o.diameter == null) out.push(finding('warn', `a hexagon head is turned by a socket or a spanner, and this seat clears the head's corners by the printer's fit and no more: give { diameter } for your socket's outside`, 'counterbore.socket'));
71
- out.push(finding('pass', dir.across ? `${said(dir.into)}, the seat and its hole are teardrops: 45° roofs, no support`
72
- : cone ? `${said(dir.into)}, the seat ends in a 45° cone ${mm(cone)} mm high from the bore to the hole: nothing spans, and the head bears on the cone's rim` : `${said(dir.into)}, a counterbore prints as drawn`, 'counterbore.printable', { values: { into: dir.into } }));
73
- return { thread: fx.thread, head: form, diameter, depth, sunk, hole: h.diameter, length, cone, into: dir.into, teardrop: dir.across,
74
- rests: [...figures(fx, head.figures), pr.rest('fit'), pr.rest('hole_comp'), pr.rest('layer'), ...h.rests], findings: [...out, ...h.findings.filter((f) => f.code === 'hole.drawn')] };
107
+ const head = headOf(what, fx, form),
108
+ h = through(what, fx, o),
109
+ fit = pr.n('fit'),
110
+ comp = pr.n('hole_comp'),
111
+ layer = pr.n('layer');
112
+ const least = r3(head.across + comp),
113
+ diameter = o.diameter == null ? r3(head.across + 2 * fit + comp) : positive(what, 'diameter', o.diameter);
114
+ const depth = o.depth == null ? layers(head.height, layer) : positive(what, 'depth', o.depth),
115
+ sunk = r3(depth - head.height);
116
+ const cone = dir.into === '+z' ? r3((diameter - h.diameter) / 2) : 0,
117
+ length = lengthOf(what, o, depth + cone, "the seat's depth");
118
+ inPart(
119
+ what,
120
+ o,
121
+ depth + cone,
122
+ `a seat ${mm(depth)} mm deep for ${a(fx.thread)} ${form} head${cone ? ` with its ${mm(cone)} mm cone` : ''}`,
123
+ );
124
+ out.push(
125
+ finding(
126
+ 'info',
127
+ `a counterbore for ${a(fx.thread)} ${form} head drawn ${mm(diameter)} mm across and ${mm(depth)} mm ` +
128
+ `deep: the head is ${mm(head.across)} mm across${head.flats ? ' its corners' : ''} and ` +
129
+ `${mm(head.height)} mm high (${head.figures.map((n) => cite(fx, n)).join(', ')})` +
130
+ (o.diameter == null
131
+ ? `, with ${pr.cite('fit')} ${mm(fit)} mm each side and ${pr.cite('hole_comp')} ${mm(comp)} mm across`
132
+ : '') +
133
+ `; its top lies ` +
134
+ (sunk > 1e-9
135
+ ? `${mm(sunk)} mm under the face`
136
+ : sunk < -1e-9
137
+ ? `${mm(-sunk)} mm proud of the face`
138
+ : 'flush with the face'),
139
+ 'counterbore.drawn',
140
+ { values: { diameter, depth, sunk, hole: h.diameter }, refs: { thread: fx.thread, set: fx.set, head: form } },
141
+ ),
142
+ );
143
+ if (diameter < least - 1e-9)
144
+ out.push(
145
+ finding(
146
+ 'fail',
147
+ `a ${mm(diameter)} mm seat is smaller than the ${mm(head.across)} mm head once printed: ${mm(least)} ` +
148
+ `mm at least`,
149
+ 'counterbore.diameter',
150
+ { values: { diameter, least } },
151
+ ),
152
+ );
153
+ if (sunk < -1e-9)
154
+ out.push(
155
+ finding(
156
+ 'warn',
157
+ `the head stands ${mm(-sunk)} mm proud of a ${mm(depth)} mm seat: ${mm(head.height)} mm hides it`,
158
+ 'counterbore.proud',
159
+ { values: { depth, head: head.height } },
160
+ ),
161
+ );
162
+ if (form === 'hex' && o.diameter == null)
163
+ out.push(
164
+ finding(
165
+ 'warn',
166
+ `a hexagon head is turned by a socket or a spanner, and this seat clears the head's corners by the ` +
167
+ `printer's fit and no more: give { diameter } for your socket's outside`,
168
+ 'counterbore.socket',
169
+ ),
170
+ );
171
+ out.push(
172
+ finding(
173
+ 'pass',
174
+ dir.across
175
+ ? `${said(dir.into)}, the seat and its hole are teardrops: 45° roofs, no support`
176
+ : cone
177
+ ? `${said(dir.into)}, the seat ends in a 45° cone ${mm(cone)} mm high from the bore to the hole: ` +
178
+ `nothing spans, and the head bears on the cone's rim`
179
+ : `${said(dir.into)}, a counterbore prints as drawn`,
180
+ 'counterbore.printable',
181
+ { values: { into: dir.into } },
182
+ ),
183
+ );
184
+ return {
185
+ thread: fx.thread,
186
+ head: form,
187
+ diameter,
188
+ depth,
189
+ sunk,
190
+ hole: h.diameter,
191
+ length,
192
+ cone,
193
+ into: dir.into,
194
+ teardrop: dir.across,
195
+ rests: [...figures(fx, head.figures), pr.rest('fit'), pr.rest('hole_comp'), pr.rest('layer'), ...h.rests],
196
+ findings: [...out, ...h.findings.filter((f) => f.code === 'hole.drawn')],
197
+ };
75
198
  }
76
199
 
77
200
  /**
78
201
  * A counterbore for a screw's head, to subtract, with the screw's hole on through the part where length is given.
79
202
  * On its side, the seat and the hole are one teardrop cutter: a 45° roof over each.
80
203
  * @param {Fixing | string} m
81
- * @param {{ head?: string, depth?: number, diameter?: number, length?: number, hole?: string, printer?: object, into?: string, axis?: string, sets?: object, at?: number[] }} [o] as counterboreModel; at: the point on the face
204
+ * @param {{ head?: string, depth?: number, diameter?: number, length?: number, hole?: string, printer?: object,
205
+ * into?: string, axis?: string, sets?: object, at?: number[] }} [o] as counterboreModel; at: the point on the face
82
206
  * @returns {object} a JSCAD geom3 to subtract, with .model
83
207
  */
84
208
  export function counterbore(m, o = {}) {
85
- const c = counterboreModel(m, o), at = pointOf('counterbore', o.at), R = c.diameter / 2, r = c.hole / 2;
86
- const steps = [[R, c.depth], ...(c.cone ? [[r, c.depth + c.cone]] : c.length ? [[r, c.depth]] : []), ...(c.length ? [[r, c.length]] : [])];
87
- return Object.assign(along(c.teardrop ? teardrop(steps, UP[c.into], { through: !!c.length }) : bore(steps, { through: !!c.length }), c.into, at), { model: c });
209
+ const c = counterboreModel(m, o),
210
+ at = pointOf('counterbore', o.at),
211
+ R = c.diameter / 2,
212
+ r = c.hole / 2;
213
+ const steps = [
214
+ [R, c.depth],
215
+ ...(c.cone ? [[r, c.depth + c.cone]] : c.length ? [[r, c.depth]] : []),
216
+ ...(c.length ? [[r, c.length]] : []),
217
+ ];
218
+ return Object.assign(
219
+ along(
220
+ c.teardrop ? teardrop(steps, UP[c.into], { through: !!c.length }) : bore(steps, { through: !!c.length }),
221
+ c.into,
222
+ at,
223
+ ),
224
+ { model: c },
225
+ );
88
226
  }
89
227
 
90
228
  // ---------- countersink ----------
@@ -92,122 +230,365 @@ export function counterbore(m, o = {}) {
92
230
  * A countersink for a flat-head screw, as numbers: a cone to the head's angle, as wide as the head's sharp edge, so
93
231
  * any head sits flush.
94
232
  * @param {Fixing | string} m
95
- * @param {{ length?: number, thickness?: number, hole?: string, printer?: object, into?: string, axis?: string, sets?: object }} [o] length: the whole hole's, from the face (default the cone and no more);
233
+ * @param {{ length?: number, thickness?: number, hole?: string, printer?: object, into?: string, axis?: string,
234
+ * sets?: object }} [o] length: the whole hole's, from the face (default the cone and no more);
96
235
  * thickness: the part's there (a cone deeper than the part is refused)
97
- * @returns {{ thread: string, diameter: number, angle: number, depth: number, hole: number, length: number, into: string, teardrop: boolean, rests: object[], findings: object[] }}
236
+ * @returns {{ thread: string, diameter: number, angle: number, depth: number, hole: number, length: number,
237
+ * into: string, teardrop: boolean, rests: object[], findings: object[] }}
98
238
  * diameter: of the cone at the face, as drawn; depth: of the cone
99
239
  */
100
240
  export function countersinkModel(m, o = {}) {
101
241
  const what = 'countersink';
102
242
  optionsOf(what, o, '{ length: 8 }');
103
- const fx = fixingOf(what, m, o), pr = printerOf(what, o.printer), dir = directionOf(what, o), head = headOf(what, fx, 'countersunk'), h = through(what, fx, o), comp = pr.n('hole_comp');
104
- const angle = head.angle ?? 90, diameter = r3(head.diameter + comp), depth = r3((diameter - h.diameter) / 2 / Math.tan((angle * Math.PI) / 360));
105
- if (!(angle > 0 && angle < 180)) throw new Error(`${what}: ${cite(fx, 'countersunk_angle')} is the cone's whole angle, between 0° and 180° (got ${shown(angle)})`);
106
- const length = lengthOf(what, o, depth, 'the cone\'s depth') ?? depth, slope = angle / 2, limit = pr.n('overhang'), out = [];
243
+ const fx = fixingOf(what, m, o),
244
+ pr = printerOf(what, o.printer),
245
+ dir = directionOf(what, o),
246
+ head = headOf(what, fx, 'countersunk'),
247
+ h = through(what, fx, o),
248
+ comp = pr.n('hole_comp');
249
+ const angle = head.angle ?? 90,
250
+ diameter = r3(head.diameter + comp),
251
+ depth = r3((diameter - h.diameter) / 2 / Math.tan((angle * Math.PI) / 360));
252
+ if (!(angle > 0 && angle < 180))
253
+ throw new Error(
254
+ `${what}: ${cite(fx, 'countersunk_angle')} is the cone's whole angle, between 0° and 180° (got ${shown(angle)})`,
255
+ );
256
+ const length = lengthOf(what, o, depth, "the cone's depth") ?? depth,
257
+ slope = angle / 2,
258
+ limit = pr.n('overhang'),
259
+ out = [];
107
260
  inPart(what, o, depth, `a countersink ${mm(depth)} mm deep for ${a(fx.thread)} flat head`);
108
- out.push(finding('info', `a countersink for ${a(fx.thread)} flat head drawn ${mm(diameter)} mm across at ${mm(angle)}°, ${mm(depth)} mm deep on a ${mm(h.diameter)} mm hole: ${cite(fx, 'countersunk_head')} ${mm(head.diameter)} mm, the head's sharp-edge diameter, so any head sits flush, plus ${pr.cite('hole_comp')} ${mm(comp)} mm across`,
109
- 'countersink.drawn', { values: { diameter, angle, depth, hole: h.diameter }, refs: { thread: fx.thread, set: fx.set } }));
110
- out.push(dir.across ? finding('pass', `${said(dir.into)}, the cone and its hole are teardrops: 45° roofs, no support`, 'countersink.printable', { values: { into: dir.into } })
111
- : dir.into === '+z' ? finding(slope <= limit + 1e-9 ? 'pass' : 'warn', `${said(dir.into)}, the cone opens on to the bed and its wall overhangs ${mm(slope)}° from upright, ${slope <= limit + 1e-9 ? 'within' : 'past'} the printer's ${mm(limit)}°`, 'countersink.printable', { values: { into: dir.into, slope, limit } })
112
- : finding('pass', `${said(dir.into)}, a countersink prints as drawn`, 'countersink.printable', { values: { into: dir.into } }));
113
- return { thread: fx.thread, diameter, angle, depth, hole: h.diameter, length, into: dir.into, teardrop: dir.across,
114
- rests: [...figures(fx, head.figures), pr.rest('hole_comp'), ...h.rests], findings: [...out, ...h.findings.filter((f) => f.code === 'hole.drawn')] };
261
+ out.push(
262
+ finding(
263
+ 'info',
264
+ `a countersink for ${a(fx.thread)} flat head drawn ${mm(diameter)} mm across at ${mm(angle)}°, ` +
265
+ `${mm(depth)} mm deep on a ${mm(h.diameter)} mm hole: ${cite(fx, 'countersunk_head')} ` +
266
+ `${mm(head.diameter)} mm, the head's sharp-edge diameter, so any head sits flush, plus ` +
267
+ `${pr.cite('hole_comp')} ${mm(comp)} mm across`,
268
+ 'countersink.drawn',
269
+ { values: { diameter, angle, depth, hole: h.diameter }, refs: { thread: fx.thread, set: fx.set } },
270
+ ),
271
+ );
272
+ out.push(
273
+ dir.across
274
+ ? finding(
275
+ 'pass',
276
+ `${said(dir.into)}, the cone and its hole are teardrops: 45° roofs, no support`,
277
+ 'countersink.printable',
278
+ { values: { into: dir.into } },
279
+ )
280
+ : dir.into === '+z'
281
+ ? finding(
282
+ slope <= limit + 1e-9 ? 'pass' : 'warn',
283
+ `${said(dir.into)}, the cone opens on to the bed and its wall overhangs ${mm(slope)}° from ` +
284
+ `upright, ` +
285
+ (slope <= limit + 1e-9 ? 'within' : 'past') +
286
+ ` the printer's ${mm(limit)}°`,
287
+ 'countersink.printable',
288
+ { values: { into: dir.into, slope, limit } },
289
+ )
290
+ : finding('pass', `${said(dir.into)}, a countersink prints as drawn`, 'countersink.printable', {
291
+ values: { into: dir.into },
292
+ }),
293
+ );
294
+ return {
295
+ thread: fx.thread,
296
+ diameter,
297
+ angle,
298
+ depth,
299
+ hole: h.diameter,
300
+ length,
301
+ into: dir.into,
302
+ teardrop: dir.across,
303
+ rests: [...figures(fx, head.figures), pr.rest('hole_comp'), ...h.rests],
304
+ findings: [...out, ...h.findings.filter((f) => f.code === 'hole.drawn')],
305
+ };
115
306
  }
116
307
 
117
308
  /**
118
309
  * A countersink and its hole, to subtract, the head flush with the face at `at`. A 90° head goes through
119
310
  * @rulecad/shapes' countersink; another angle (an inch screw's 82°) is drawn here in the same form.
120
311
  * @param {Fixing | string} m
121
- * @param {{ length?: number, hole?: string, printer?: object, into?: string, axis?: string, sets?: object, at?: number[] }} [o] as countersinkModel
312
+ * @param {{ length?: number, hole?: string, printer?: object, into?: string, axis?: string, sets?: object,
313
+ * at?: number[] }} [o] as countersinkModel
122
314
  * @returns {object} a JSCAD geom3 to subtract, with .model
123
315
  */
124
316
  export function countersink(m, o = {}) {
125
- const c = countersinkModel(m, o), at = pointOf('countersink', o.at), through = o.length != null, R = c.diameter / 2, r = c.hole / 2;
126
- if (c.angle === 90) return Object.assign(cone90({ hole: c.hole, head: c.diameter, length: c.length + (through ? OUT : 0), at, into: c.into }), { model: c });
317
+ const c = countersinkModel(m, o),
318
+ at = pointOf('countersink', o.at),
319
+ through = o.length != null,
320
+ R = c.diameter / 2,
321
+ r = c.hole / 2;
322
+ if (c.angle === 90)
323
+ return Object.assign(
324
+ cone90({ hole: c.hole, head: c.diameter, length: c.length + (through ? OUT : 0), at, into: c.into }),
325
+ { model: c },
326
+ );
127
327
  const steps = [[R, 0], [r, c.depth], ...(c.length > c.depth ? [[r, c.length]] : [])];
128
- return Object.assign(along(c.teardrop ? teardrop(steps, UP[c.into], { through }) : bore(steps, { through }), c.into, at), { model: c });
328
+ return Object.assign(
329
+ along(c.teardrop ? teardrop(steps, UP[c.into], { through }) : bore(steps, { through }), c.into, at),
330
+ { model: c },
331
+ );
129
332
  }
130
333
 
131
334
  // ---------- nuts ----------
132
335
  // What every nut seat starts from: the nut, the fit, the drawn size across its flats and the screw's hole
133
336
  function nutSeat(what, m, o, fit) {
134
- optionsOf(what, o, '{ kind: \'hex\' }');
135
- const fx = fixingOf(what, m, o), pr = printerOf(what, o.printer), nut = nutOf(what, fx, o.kind ?? fx.nut?.kind ?? 'hex'), f = fitOf(what, o.fit ?? fit, pr, true), comp = pr.n('hole_comp'), h = through(what, fx, o);
136
- const flats = r3(nut.flats + comp + f.clearance), corner = r3(nut.kind === 'square' ? flats * Math.SQRT2 : flats / COS30);
137
- const how = `${cite(fx, nut.figures[0])} ${mm(nut.flats)} mm plus ${pr.cite('hole_comp')} ${mm(comp)} mm${f.clearance ? ` and ${isNum(f.name) ? 'the fit given' : pr.cite(f.name)} ${mm(f.clearance)} mm` : ''}`;
138
- return { fx, pr, nut, f, comp, h, flats, corner, how, rests: [...figures(fx, nut.figures), pr.rest('hole_comp'), ...f.rests, ...h.rests] };
337
+ optionsOf(what, o, "{ kind: 'hex' }");
338
+ const fx = fixingOf(what, m, o),
339
+ pr = printerOf(what, o.printer),
340
+ nut = nutOf(what, fx, o.kind ?? fx.nut?.kind ?? 'hex'),
341
+ f = fitOf(what, o.fit ?? fit, pr, true),
342
+ comp = pr.n('hole_comp'),
343
+ h = through(what, fx, o);
344
+ const flats = r3(nut.flats + comp + f.clearance),
345
+ corner = r3(nut.kind === 'square' ? flats * Math.SQRT2 : flats / COS30);
346
+ const how =
347
+ `${cite(fx, nut.figures[0])} ${mm(nut.flats)} mm plus ${pr.cite('hole_comp')} ${mm(comp)} mm` +
348
+ (f.clearance ? ` and ${isNum(f.name) ? 'the fit given' : pr.cite(f.name)} ${mm(f.clearance)} mm` : '');
349
+ return {
350
+ fx,
351
+ pr,
352
+ nut,
353
+ f,
354
+ comp,
355
+ h,
356
+ flats,
357
+ corner,
358
+ how,
359
+ rests: [...figures(fx, nut.figures), pr.rest('hole_comp'), ...f.rests, ...h.rests],
360
+ };
139
361
  }
140
362
  const nutName = (s) => `${a(s.fx.thread)} ${s.nut.kind === 'hex' ? '' : `${s.nut.kind} `}nut`;
141
363
  // A pocket for a nut along the screw's axis, drawn going down from z = 0: a hexagon through shapes, a square drawn here
142
364
  function pocket(s, flats, depth, hole, at, into) {
143
365
  if (s.nut.kind !== 'square') return hexPocket({ flats, height: depth, hole, at, into });
144
366
  const box = translate([0, 0, -depth / 2], cuboid({ size: [flats, flats, depth] }));
145
- if (into === '+z') { // a 45° roof from the corners to the hole, as the hexagon's
146
- const rise = (flats * Math.SQRT2 - hole) / 2, roof = translate([0, 0, -depth - rise / 2], rotateZ(Math.PI / 4, cylinderElliptic({ height: rise, startRadius: [hole / 2, hole / 2], endRadius: [flats / Math.SQRT2, flats / Math.SQRT2], segments: 4 })));
367
+ if (into === '+z') {
368
+ // a 45° roof from the corners to the hole, as the hexagon's
369
+ const rise = (flats * Math.SQRT2 - hole) / 2,
370
+ roof = translate(
371
+ [0, 0, -depth - rise / 2],
372
+ rotateZ(
373
+ Math.PI / 4,
374
+ cylinderElliptic({
375
+ height: rise,
376
+ startRadius: [hole / 2, hole / 2],
377
+ endRadius: [flats / Math.SQRT2, flats / Math.SQRT2],
378
+ segments: 4,
379
+ }),
380
+ ),
381
+ );
147
382
  return along(jscad.booleans.union(box, roof), into, at);
148
383
  }
149
- return along(into in UP ? rotateZ(Math.PI / 4, box) : box, into, at); // across a part: turned corner up, its two upper faces at 45°
384
+ // across a part: turned corner up, its two upper faces at 45°
385
+ return along(into in UP ? rotateZ(Math.PI / 4, box) : box, into, at);
150
386
  }
151
387
 
152
388
  /**
153
389
  * A pocket for a nut, let in from a face along the screw's axis, as numbers.
154
390
  * @param {Fixing | string} m
155
- * @param {{ kind?: string, depth?: number, thickness?: number, fit?: string | number, hole?: string, printer?: object, into?: string, axis?: string, sets?: object }} [o]
391
+ * @param {{ kind?: string, depth?: number, thickness?: number, fit?: string | number, hole?: string, printer?: object,
392
+ * into?: string, axis?: string, sets?: object }} [o]
156
393
  * kind: hex, square or lock (default the model's, else hex); depth: of the pocket (default the nut's height and two
157
- * layers); thickness: the part's there (a pocket deeper than the part is refused); fit: snug (the default: the printer's measured nut_fit where it has one, else no clearance once printed, so the nut cannot turn), slip, press, or a clearance in mm
158
- * @returns {{ thread: string, kind: string, flats: number, nominal: number, corner: number, depth: number, height: number, hole: number, clearance: number, roof: number, into: string, rests: object[], findings: object[] }}
159
- * flats: across the flats, as drawn; nominal: the nut's; corner: across the pocket's corners; roof: the height of the 45° roof, going up from the bed
394
+ * layers); thickness: the part's there (a pocket deeper than the part is refused); fit: snug (the default: the
395
+ * printer's measured nut_fit where it has one, else no clearance once printed, so the nut cannot turn), slip, press,
396
+ * or a clearance in mm
397
+ * @returns {{ thread: string, kind: string, flats: number, nominal: number, corner: number, depth: number,
398
+ * height: number, hole: number, clearance: number, roof: number, into: string, rests: object[], findings: object[] }}
399
+ * flats: across the flats, as drawn; nominal: the nut's; corner: across the pocket's corners; roof: the height of the
400
+ * 45° roof, going up from the bed
160
401
  */
161
402
  export function nutPocketModel(m, o = {}) {
162
- const what = 'nutPocket', s = nutSeat(what, m, o, 'snug'), { fx, pr, nut, h } = s, dir = directionOf(what, o), layer = pr.n('layer'), out = [];
163
- const depth = o.depth == null ? r3(nut.height + DEFAULTS.nut_sink.value * layer) : positive(what, 'depth', o.depth), roof = dir.into === '+z' ? r3((s.corner - h.diameter) / 2) : 0;
164
- inPart(what, o, depth + roof, `a pocket ${mm(depth)} mm deep for ${nutName(s)}${roof ? ` with its ${mm(roof)} mm roof` : ''}`);
165
- out.push(finding('info', `a pocket for ${nutName(s)} drawn ${mm(s.flats)} mm across the flats and ${mm(depth)} mm deep: ${s.how}; the nut is ${mm(nut.height)} mm high (${cite(fx, nut.figures[1])})${o.depth == null ? `, sunk ${DEFAULTS.nut_sink.value} layers of ${pr.cite('layer')}` : ''}`,
166
- 'nutPocket.drawn', { values: { flats: s.flats, depth, hole: h.diameter, clearance: s.f.clearance }, refs: { thread: fx.thread, set: fx.set, nut: nut.kind } }));
167
- if (depth < nut.height - 1e-9) out.push(finding('warn', `the nut stands ${mm(nut.height - depth)} mm proud of a ${mm(depth)} mm pocket`, 'nutPocket.proud', { values: { depth, height: nut.height } }));
168
- const side = r3(s.flats / Math.sqrt(3)), bridge = pr.n('bridge');
169
- out.push(!dir.across ? finding('pass', roof ? `${said(dir.into)}, the pocket has a 45° roof ${mm(roof)} mm high from its corners to the hole: nothing spans` : `${said(dir.into)}, the pocket is open above: it prints as drawn`, 'nutPocket.printable', { values: { into: dir.into } })
170
- : nut.kind === 'square' ? finding('pass', `${said(dir.into)}, the square is turned corner up: its two upper faces lie at 45°`, 'nutPocket.printable', { values: { into: dir.into } })
171
- : finding(side <= bridge + 1e-9 ? 'pass' : 'warn', `${said(dir.into)}, the hexagon has a flat on top: a ${mm(side)} mm bridge, ${side <= bridge + 1e-9 ? 'within' : 'past'} the printer's ${mm(bridge)} mm`, 'nutPocket.printable', { values: { into: dir.into, bridge: side, limit: bridge } }));
172
- return { thread: fx.thread, kind: nut.kind, flats: s.flats, nominal: nut.flats, corner: s.corner, depth, height: nut.height, hole: h.diameter, clearance: s.f.clearance, roof, into: dir.into, rests: [...s.rests, pr.rest('layer')], findings: out };
403
+ const what = 'nutPocket',
404
+ s = nutSeat(what, m, o, 'snug'),
405
+ { fx, pr, nut, h } = s,
406
+ dir = directionOf(what, o),
407
+ layer = pr.n('layer'),
408
+ out = [];
409
+ const depth = o.depth == null ? r3(nut.height + DEFAULTS.nut_sink.value * layer) : positive(what, 'depth', o.depth),
410
+ roof = dir.into === '+z' ? r3((s.corner - h.diameter) / 2) : 0;
411
+ inPart(
412
+ what,
413
+ o,
414
+ depth + roof,
415
+ `a pocket ${mm(depth)} mm deep for ${nutName(s)}${roof ? ` with its ${mm(roof)} mm roof` : ''}`,
416
+ );
417
+ out.push(
418
+ finding(
419
+ 'info',
420
+ `a pocket for ${nutName(s)} drawn ${mm(s.flats)} mm across the flats and ${mm(depth)} mm deep: ${s.how}` +
421
+ `; the nut is ${mm(nut.height)} mm high (${cite(fx, nut.figures[1])})` +
422
+ (o.depth == null ? `, sunk ${DEFAULTS.nut_sink.value} layers of ${pr.cite('layer')}` : ''),
423
+ 'nutPocket.drawn',
424
+ {
425
+ values: { flats: s.flats, depth, hole: h.diameter, clearance: s.f.clearance },
426
+ refs: { thread: fx.thread, set: fx.set, nut: nut.kind },
427
+ },
428
+ ),
429
+ );
430
+ if (depth < nut.height - 1e-9)
431
+ out.push(
432
+ finding(
433
+ 'warn',
434
+ `the nut stands ${mm(nut.height - depth)} mm proud of a ${mm(depth)} mm pocket`,
435
+ 'nutPocket.proud',
436
+ { values: { depth, height: nut.height } },
437
+ ),
438
+ );
439
+ const side = r3(s.flats / Math.sqrt(3)),
440
+ bridge = pr.n('bridge');
441
+ out.push(
442
+ !dir.across
443
+ ? finding(
444
+ 'pass',
445
+ roof
446
+ ? `${said(dir.into)}, the pocket has a 45° roof ${mm(roof)} mm high from its corners to the hole: ` +
447
+ `nothing spans`
448
+ : `${said(dir.into)}, the pocket is open above: it prints as drawn`,
449
+ 'nutPocket.printable',
450
+ { values: { into: dir.into } },
451
+ )
452
+ : nut.kind === 'square'
453
+ ? finding(
454
+ 'pass',
455
+ `${said(dir.into)}, the square is turned corner up: its two upper faces lie at 45°`,
456
+ 'nutPocket.printable',
457
+ { values: { into: dir.into } },
458
+ )
459
+ : finding(
460
+ side <= bridge + 1e-9 ? 'pass' : 'warn',
461
+ `${said(dir.into)}, the hexagon has a flat on top: a ${mm(side)} mm bridge, ` +
462
+ (side <= bridge + 1e-9 ? 'within' : 'past') +
463
+ ` the printer's ${mm(bridge)} mm`,
464
+ 'nutPocket.printable',
465
+ { values: { into: dir.into, bridge: side, limit: bridge } },
466
+ ),
467
+ );
468
+ return {
469
+ thread: fx.thread,
470
+ kind: nut.kind,
471
+ flats: s.flats,
472
+ nominal: nut.flats,
473
+ corner: s.corner,
474
+ depth,
475
+ height: nut.height,
476
+ hole: h.diameter,
477
+ clearance: s.f.clearance,
478
+ roof,
479
+ into: dir.into,
480
+ rests: [...s.rests, pr.rest('layer')],
481
+ findings: out,
482
+ };
173
483
  }
174
484
 
175
485
  /**
176
486
  * A pocket for a nut, to subtract: open at the face at `at`, going in along the screw's axis. A hexagon goes through
177
487
  * @rulecad/shapes' nutPocket. The screw's hole is a hole() of its own.
178
488
  * @param {Fixing | string} m
179
- * @param {{ kind?: string, depth?: number, fit?: string | number, hole?: string, printer?: object, into?: string, axis?: string, sets?: object, at?: number[] }} [o] as nutPocketModel
489
+ * @param {{ kind?: string, depth?: number, fit?: string | number, hole?: string, printer?: object, into?: string,
490
+ * axis?: string, sets?: object, at?: number[] }} [o] as nutPocketModel
180
491
  * @returns {object} a JSCAD geom3 to subtract, with .model
181
492
  */
182
493
  export function nutPocket(m, o = {}) {
183
- const p = nutPocketModel(m, o), s = { nut: { kind: p.kind } };
494
+ const p = nutPocketModel(m, o),
495
+ s = { nut: { kind: p.kind } };
184
496
  return Object.assign(pocket(s, p.flats, p.depth, p.hole, pointOf('nutPocket', o.at), p.into), { model: p });
185
497
  }
186
498
 
187
499
  /**
188
500
  * A slot a nut slides into from the side, across the screw's axis, as numbers.
189
501
  * @param {Fixing | string} m
190
- * @param {{ kind?: string, axis?: 'x' | 'y' | 'z', into?: string, depth: number, fit?: string | number, hole?: string, printer?: object, sets?: object }} o
502
+ * @param {{ kind?: string, axis?: 'x' | 'y' | 'z', into?: string, depth: number, fit?: string | number, hole?: string,
503
+ * printer?: object, sets?: object }} o
191
504
  * axis: the screw's (default z, standing up); into: the way the nut slides in, square to the axis (default +x for a
192
505
  * screw standing up, -z, dropped in from the top, for one lying down); depth: from the face to the screw's axis;
193
- * fit: slip (the default: the nut slides in by hand; the printer's measured nut_slip where it has one, else its slip), snug, press, or a clearance in mm
194
- * @returns {{ thread: string, kind: string, width: number, gap: number, depth: number, reach: number, hole: number, clearance: number, axis: string, into: string, span: number, rise: number, rests: object[], findings: object[] }}
195
- * width: across the nut's flats, as drawn; clearance: the fit's, across the flats; gap: along the screw, for the nut's height; reach: how far the slot goes
196
- * in from the face; span: what its roof bridges; rise: how far the roof rises at 45° where that is wider than the printer bridges
506
+ * fit: slip (the default: the nut slides in by hand; the printer's measured nut_slip where it has one, else its
507
+ * slip), snug, press, or a clearance in mm
508
+ * @returns {{ thread: string, kind: string, width: number, gap: number, depth: number, reach: number, hole: number,
509
+ * clearance: number, axis: string, into: string, span: number, rise: number, rests: object[], findings: object[] }}
510
+ * width: across the nut's flats, as drawn; clearance: the fit's, across the flats; gap: along the screw, for the
511
+ * nut's height; reach: how far the slot goes in from the face; span: what its roof bridges; rise: how far the roof
512
+ * rises at 45° where that is wider than the printer bridges
197
513
  */
198
514
  export function nutTrapModel(m, o = {}) {
199
- const what = o?.slot ?? 'nutTrap', s = nutSeat(what, m, o, 'slip'), { fx, pr, nut, h } = s, layer = pr.n('layer'), bridge = pr.n('bridge'), out = [];
200
- const axis = oneOf(what, 'axis', o.axis ?? 'z', ['x', 'y', 'z']), into = oneOf(what, 'into', o.into ?? (axis === 'z' ? '+x' : '-z'), DIRECTIONS);
201
- if (into[1] === axis) throw new Error(`${what}: the nut slides in across the screw, so into is square to axis (got into ${into} with the screw along ${axis}). A pocket along the screw is nutPocket`);
202
- if (into === '+z') throw new Error(`${what}: a slot open to the bed has the nut's width to bridge over its whole length: turn it so the nut goes in from the top (-z) or from a side (+x, -x, +y, -y)`);
203
- const depth = positive(what, 'depth (from the face to the screw\'s axis)', o.depth), raw = nut.height + s.comp + s.f.clearance, gap = axis === 'z' ? layers(raw, 2 * layer) : r3(raw); // (an even number of layers, so the slot's floor and roof both fall on layers when its middle does)
204
- const reach = r3(depth + (nut.kind === 'square' ? s.flats / 2 : s.flats / (2 * COS30))), span = into === '-z' ? 0 : axis === 'z' ? s.flats : gap, rise = span > bridge ? r3((span - bridge) / 2) : 0;
205
- out.push(finding('info', `a slot for ${nutName(s)} drawn ${mm(s.flats)} mm across the flats and ${mm(gap)} mm along the screw, ${mm(reach)} mm in from the face: ${s.how}; the nut is ${mm(nut.height)} mm high (${cite(fx, nut.figures[1])})${axis === 'z' ? ', its gap an even number of layers' : ''}`,
206
- 'nutTrap.drawn', { values: { width: s.flats, gap, reach, hole: h.diameter, clearance: s.f.clearance }, refs: { thread: fx.thread, set: fx.set, nut: nut.kind } }));
207
- out.push(finding('pass', into === '-z' ? 'dropped in from the top, the slot is open above: nothing spans' : rise ? `from the side, the slot's roof spans ${mm(span)} mm, more than the printer's ${mm(bridge)} mm bridge: it rises ${mm(rise)} mm at 45° to a flat ${mm(bridge)} mm wide`
208
- : `from the side, the slot's roof is a ${mm(span)} mm bridge, within the printer's ${mm(bridge)} mm`, 'nutTrap.printable', { values: { into, span, limit: bridge, rise } }));
209
- if (rise) out.push(finding('info', 'the slot\'s floor is flat and its roof is not: bring the screw in through the floor, so it pulls the nut down on to the flat', 'nutTrap.side'));
210
- return { thread: fx.thread, kind: nut.kind, width: s.flats, gap, depth, reach, hole: h.diameter, clearance: s.f.clearance, axis, into, span, rise, rests: [...s.rests, pr.rest('layer'), pr.rest('bridge')], findings: out };
515
+ const what = o?.slot ?? 'nutTrap',
516
+ s = nutSeat(what, m, o, 'slip'),
517
+ { fx, pr, nut, h } = s,
518
+ layer = pr.n('layer'),
519
+ bridge = pr.n('bridge'),
520
+ out = [];
521
+ const axis = oneOf(what, 'axis', o.axis ?? 'z', ['x', 'y', 'z']),
522
+ into = oneOf(what, 'into', o.into ?? (axis === 'z' ? '+x' : '-z'), DIRECTIONS);
523
+ if (into[1] === axis)
524
+ throw new Error(
525
+ `${what}: the nut slides in across the screw, so into is square to axis (got into ${into} with the ` +
526
+ `screw along ${axis}). A pocket along the screw is nutPocket`,
527
+ );
528
+ if (into === '+z')
529
+ throw new Error(
530
+ `${what}: a slot open to the bed has the nut's width to bridge over its whole length: turn it so the ` +
531
+ `nut goes in from the top (-z) or from a side (+x, -x, +y, -y)`,
532
+ );
533
+ const depth = positive(what, "depth (from the face to the screw's axis)", o.depth),
534
+ raw = nut.height + s.comp + s.f.clearance,
535
+ // (an even number of layers, so the slot's floor and roof both fall on layers when its middle does)
536
+ gap = axis === 'z' ? layers(raw, 2 * layer) : r3(raw);
537
+ const reach = r3(depth + (nut.kind === 'square' ? s.flats / 2 : s.flats / (2 * COS30))),
538
+ span = into === '-z' ? 0 : axis === 'z' ? s.flats : gap,
539
+ rise = span > bridge ? r3((span - bridge) / 2) : 0;
540
+ out.push(
541
+ finding(
542
+ 'info',
543
+ `a slot for ${nutName(s)} drawn ${mm(s.flats)} mm across the flats and ${mm(gap)} mm along the screw, ` +
544
+ `${mm(reach)} mm in from the face: ${s.how}; the nut is ${mm(nut.height)} mm high (` +
545
+ `${cite(fx, nut.figures[1])})` +
546
+ (axis === 'z' ? ', its gap an even number of layers' : ''),
547
+ 'nutTrap.drawn',
548
+ {
549
+ values: { width: s.flats, gap, reach, hole: h.diameter, clearance: s.f.clearance },
550
+ refs: { thread: fx.thread, set: fx.set, nut: nut.kind },
551
+ },
552
+ ),
553
+ );
554
+ out.push(
555
+ finding(
556
+ 'pass',
557
+ into === '-z'
558
+ ? 'dropped in from the top, the slot is open above: nothing spans'
559
+ : rise
560
+ ? `from the side, the slot's roof spans ${mm(span)} mm, more than the printer's ${mm(bridge)} mm ` +
561
+ `bridge: it rises ${mm(rise)} mm at 45° to a flat ${mm(bridge)} mm wide`
562
+ : `from the side, the slot's roof is a ${mm(span)} mm bridge, within the printer's ${mm(bridge)} mm`,
563
+ 'nutTrap.printable',
564
+ { values: { into, span, limit: bridge, rise } },
565
+ ),
566
+ );
567
+ if (rise)
568
+ out.push(
569
+ finding(
570
+ 'info',
571
+ "the slot's floor is flat and its roof is not: bring the screw in through the floor, so it pulls the " +
572
+ 'nut down on to the flat',
573
+ 'nutTrap.side',
574
+ ),
575
+ );
576
+ return {
577
+ thread: fx.thread,
578
+ kind: nut.kind,
579
+ width: s.flats,
580
+ gap,
581
+ depth,
582
+ reach,
583
+ hole: h.diameter,
584
+ clearance: s.f.clearance,
585
+ axis,
586
+ into,
587
+ span,
588
+ rise,
589
+ rests: [...s.rests, pr.rest('layer'), pr.rest('bridge')],
590
+ findings: out,
591
+ };
211
592
  }
212
593
 
213
594
  /**
@@ -215,62 +596,169 @@ export function nutTrapModel(m, o = {}) {
215
596
  * From a side it goes through @rulecad/shapes' wallOpening (a roof that bridges, rising at 45° where it is too wide);
216
597
  * dropped in from the top, the slot ends in the nut's own outline, so the nut sits on the screw's axis.
217
598
  * @param {Fixing | string} m
218
- * @param {{ kind?: string, axis?: 'x' | 'y' | 'z', into?: string, depth: number, fit?: string | number, hole?: string, printer?: object, sets?: object, at?: number[] }} o as nutTrapModel
599
+ * @param {{ kind?: string, axis?: 'x' | 'y' | 'z', into?: string, depth: number, fit?: string | number, hole?: string,
600
+ * printer?: object, sets?: object, at?: number[] }} o as nutTrapModel
219
601
  * @returns {object} a JSCAD geom3 to subtract, with .model
220
602
  */
221
603
  export function nutTrap(m, o = {}) {
222
- const t = nutTrapModel(m, o), at = pointOf(o?.slot ?? 'nutTrap', o.at), pr = printerOf('nutTrap', o.printer), w = t.width / 2;
223
- if (t.into !== '-z') return Object.assign(wallOpening(t.axis === 'z' ? { width: t.width, height: t.gap, depth: t.reach, at, into: t.into, bridge: pr.n('bridge') } : { width: t.gap, height: t.width, depth: t.reach, at, into: t.into, bridge: pr.n('bridge') }), { model: t });
604
+ const t = nutTrapModel(m, o),
605
+ at = pointOf(o?.slot ?? 'nutTrap', o.at),
606
+ pr = printerOf('nutTrap', o.printer),
607
+ w = t.width / 2;
608
+ if (t.into !== '-z')
609
+ return Object.assign(
610
+ wallOpening(
611
+ t.axis === 'z'
612
+ ? { width: t.width, height: t.gap, depth: t.reach, at, into: t.into, bridge: pr.n('bridge') }
613
+ : { width: t.gap, height: t.width, depth: t.reach, at, into: t.into, bridge: pr.n('bridge') },
614
+ ),
615
+ { model: t },
616
+ );
224
617
  // from the top: the slot's outline seen along the screw (across, then up), ending in the lower half of the nut
225
- const end = t.kind === 'square' ? [[-w, -t.depth - w], [w, -t.depth - w]] : [[-w, -t.depth - w * Math.tan(Math.PI / 6)], [0, -t.reach], [w, -t.depth - w * Math.tan(Math.PI / 6)]];
226
- const slab = translate([0, 0, -t.gap / 2], extrudeLinear({ height: t.gap }, polygon({ points: [[-w, OUT], ...end, [w, OUT]] })));
618
+ const end =
619
+ t.kind === 'square'
620
+ ? [
621
+ [-w, -t.depth - w],
622
+ [w, -t.depth - w],
623
+ ]
624
+ : [
625
+ [-w, -t.depth - w * Math.tan(Math.PI / 6)],
626
+ [0, -t.reach],
627
+ [w, -t.depth - w * Math.tan(Math.PI / 6)],
628
+ ];
629
+ const slab = translate(
630
+ [0, 0, -t.gap / 2],
631
+ extrudeLinear({ height: t.gap }, polygon({ points: [[-w, OUT], ...end, [w, OUT]] })),
632
+ );
227
633
  // (across, up, along the screw) to the part's x, y, z
228
- const turn = t.axis === 'x' ? [0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1] : [-1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1];
634
+ const turn =
635
+ t.axis === 'x'
636
+ ? [0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1]
637
+ : [-1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1];
229
638
  return Object.assign(translate(at, transform(turn, slab)), { model: t });
230
639
  }
231
640
 
232
- /** A slot for a thin square nut, as numbers: nutTrapModel for a square nut, dropped in from the top across a screw lying along x unless told otherwise. */
233
- export function squareNutSlotModel(m, o = {}) { optionsOf('squareNutSlot', o, '{ depth: 6 }'); return nutTrapModel(m, { axis: 'x', ...o, kind: 'square', slot: 'squareNutSlot' }); }
641
+ /** A slot for a thin square nut, as numbers: nutTrapModel for a square nut, dropped in from the top across a screw
642
+ * lying along x unless told otherwise. */
643
+ export function squareNutSlotModel(m, o = {}) {
644
+ optionsOf('squareNutSlot', o, '{ depth: 6 }');
645
+ return nutTrapModel(m, { axis: 'x', ...o, kind: 'square', slot: 'squareNutSlot' });
646
+ }
234
647
  /**
235
- * A slot for a thin square nut (DIN 562), to subtract: the nut drops in from the top and the screw comes in from the side.
648
+ * A slot for a thin square nut (DIN 562), to subtract: the nut drops in from the top and the screw comes in from the
649
+ * side.
236
650
  * @param {Fixing | string} m
237
- * @param {{ axis?: 'x' | 'y' | 'z', into?: string, depth: number, fit?: string | number, printer?: object, sets?: object, at?: number[] }} o as nutTrap
651
+ * @param {{ axis?: 'x' | 'y' | 'z', into?: string, depth: number, fit?: string | number, printer?: object,
652
+ * sets?: object, at?: number[] }} o as nutTrap
238
653
  * @returns {object} a JSCAD geom3 to subtract, with .model
239
654
  */
240
- export function squareNutSlot(m, o = {}) { optionsOf('squareNutSlot', o, '{ depth: 6 }'); return nutTrap(m, { axis: 'x', ...o, kind: 'square', slot: 'squareNutSlot' }); }
655
+ export function squareNutSlot(m, o = {}) {
656
+ optionsOf('squareNutSlot', o, '{ depth: 6 }');
657
+ return nutTrap(m, { axis: 'x', ...o, kind: 'square', slot: 'squareNutSlot' });
658
+ }
241
659
 
242
660
  /**
243
661
  * A nut closed inside the part, put in while the print is paused, as numbers: a pocket with a flat floor at `at`, as
244
662
  * high as the nut and a layer, and a 45° roof over it to the screw's hole. The pause height is where the pocket's
245
663
  * walls end: the printer stops there, the nut goes in, and the next layers close the roof.
246
664
  * @param {Fixing | string} m
247
- * @param {{ kind?: string, fit?: string | number, hole?: string, thickness?: number, printer?: object, sets?: object, at?: number[] }} [o] at: the middle of the pocket's floor, its z measured from the bed; fit: slip by default;
665
+ * @param {{ kind?: string, fit?: string | number, hole?: string, thickness?: number, printer?: object, sets?: object,
666
+ * at?: number[] }} [o] at: the middle of the pocket's floor, its z measured from the bed; fit: slip by default;
248
667
  * thickness: the part's height there, from the bed (a pocket whose roof would break out of the top is refused)
249
- * @returns {{ thread: string, kind: string, flats: number, height: number, pause: number, layer: number, roof: number, top: number, hole: number, rests: object[], findings: object[] }}
250
- * height: of the pocket's upright walls; pause: the z to pause at; layer: the number of the last layer laid before the pause; top: the z where the roof meets the hole
668
+ * @returns {{ thread: string, kind: string, flats: number, height: number, pause: number, layer: number, roof: number,
669
+ * top: number, hole: number, rests: object[], findings: object[] }}
670
+ * height: of the pocket's upright walls; pause: the z to pause at; layer: the number of the last layer laid before
671
+ * the pause; top: the z where the roof meets the hole
251
672
  */
252
673
  export function captiveNutModel(m, o = {}) {
253
- const what = 'captiveNut', s = nutSeat(what, m, o, 'slip'), { fx, pr, nut, h } = s, at = pointOf(what, o.at), layer = pr.n('layer'), out = [];
674
+ const what = 'captiveNut',
675
+ s = nutSeat(what, m, o, 'slip'),
676
+ { fx, pr, nut, h } = s,
677
+ at = pointOf(what, o.at),
678
+ layer = pr.n('layer'),
679
+ out = [];
254
680
  if (!(layer > 0)) throw new Error(`${what}: the printer's layer is above 0 mm (got ${shown(layer)})`);
255
- const height = layers(nut.height + DEFAULTS.nut_slack.value * layer, layer), pause = r3(at[2] + height), n = Math.round(pause / layer), roof = r3((s.corner - h.diameter) / 2);
256
- if (o.thickness != null) { positive(what, 'thickness', o.thickness); if (pause + roof > o.thickness - 1e-9) throw new Error(`${what}: a closed pocket for ${nutName(s)} from z = ${mm(at[2])} mm ends its roof at z = ${mm(r3(pause + roof))} mm, and the part is ${mm(o.thickness)} mm high there: it is deeper than the part, and would break out of its top. Start it lower, or make the part taller`); }
257
- out.push(finding('info', `a closed pocket for ${nutName(s)} drawn ${mm(s.flats)} mm across the flats and ${mm(height)} mm high: ${s.how}; the nut is ${mm(nut.height)} mm high (${cite(fx, nut.figures[1])}), with ${DEFAULTS.nut_slack.value} layer over it`,
258
- 'captiveNut.drawn', { values: { flats: s.flats, height, hole: h.diameter, clearance: s.f.clearance }, refs: { thread: fx.thread, set: fx.set, nut: nut.kind } }));
259
- out.push(finding('info', `pause the print at z = ${mm(pause)} mm, once layer ${n} is down (${mm(layer)} mm layers, the bed at z = 0), drop the ${fx.thread} ${nut.kind === 'hex' ? '' : `${nut.kind} `}nut in, and carry on: the next ${mm(roof)} mm closes a roof over it`, 'captiveNut.pause', { values: { pause, layer: n, height: layer } }));
260
- out.push(finding('info', 'the nut lies on the pocket\'s flat floor and its roof is a cone: bring the screw in from below, through the floor, so it pulls the nut on to the flat', 'captiveNut.side'));
261
- out.push(finding('pass', `closed in the part, the pocket has a flat floor and a 45° roof ${mm(roof)} mm high from its corners to the hole: nothing spans`, 'captiveNut.printable', { values: { into: '+z' } }));
262
- return { thread: fx.thread, kind: nut.kind, flats: s.flats, height, pause, layer: n, roof, top: r3(pause + roof), hole: h.diameter, rests: [...s.rests, pr.rest('layer'), rest('fixings.nut_slack', DEFAULTS.nut_slack)], findings: out };
681
+ const height = layers(nut.height + DEFAULTS.nut_slack.value * layer, layer),
682
+ pause = r3(at[2] + height),
683
+ n = Math.round(pause / layer),
684
+ roof = r3((s.corner - h.diameter) / 2);
685
+ if (o.thickness != null) {
686
+ positive(what, 'thickness', o.thickness);
687
+ if (pause + roof > o.thickness - 1e-9)
688
+ throw new Error(
689
+ `${what}: a closed pocket for ${nutName(s)} from z = ${mm(at[2])} mm ends its roof at z = ` +
690
+ `${mm(r3(pause + roof))} mm, and the part is ${mm(o.thickness)} mm high there: it is deeper than the ` +
691
+ `part, and would break out of its top. Start it lower, or make the part taller`,
692
+ );
693
+ }
694
+ out.push(
695
+ finding(
696
+ 'info',
697
+ `a closed pocket for ${nutName(s)} drawn ${mm(s.flats)} mm across the flats and ${mm(height)} mm high: ` +
698
+ `${s.how}; the nut is ${mm(nut.height)} mm high (${cite(fx, nut.figures[1])}), with ` +
699
+ `${DEFAULTS.nut_slack.value} layer over it`,
700
+ 'captiveNut.drawn',
701
+ {
702
+ values: { flats: s.flats, height, hole: h.diameter, clearance: s.f.clearance },
703
+ refs: { thread: fx.thread, set: fx.set, nut: nut.kind },
704
+ },
705
+ ),
706
+ );
707
+ out.push(
708
+ finding(
709
+ 'info',
710
+ `pause the print at z = ${mm(pause)} mm, once layer ${n} is down (${mm(layer)} mm layers, the bed at z ` +
711
+ `= 0), drop the ${fx.thread} ${nut.kind === 'hex' ? '' : `${nut.kind} `}nut in, and carry on: the next ` +
712
+ `${mm(roof)} mm closes a roof over it`,
713
+ 'captiveNut.pause',
714
+ { values: { pause, layer: n, height: layer } },
715
+ ),
716
+ );
717
+ out.push(
718
+ finding(
719
+ 'info',
720
+ "the nut lies on the pocket's flat floor and its roof is a cone: bring the screw in from below, " +
721
+ 'through the floor, so it pulls the nut on to the flat',
722
+ 'captiveNut.side',
723
+ ),
724
+ );
725
+ out.push(
726
+ finding(
727
+ 'pass',
728
+ `closed in the part, the pocket has a flat floor and a 45° roof ${mm(roof)} mm high from its corners ` +
729
+ `to the hole: nothing spans`,
730
+ 'captiveNut.printable',
731
+ { values: { into: '+z' } },
732
+ ),
733
+ );
734
+ return {
735
+ thread: fx.thread,
736
+ kind: nut.kind,
737
+ flats: s.flats,
738
+ height,
739
+ pause,
740
+ layer: n,
741
+ roof,
742
+ top: r3(pause + roof),
743
+ hole: h.diameter,
744
+ rests: [...s.rests, pr.rest('layer'), rest('fixings.nut_slack', DEFAULTS.nut_slack)],
745
+ findings: out,
746
+ };
263
747
  }
264
748
 
265
749
  /**
266
750
  * A nut closed inside the part, to subtract: the pocket and its roof, from the floor at `at` upwards. The screw's hole
267
751
  * is a hole() of its own, through the floor.
268
- * @param {Fixing | string} m @param {{ kind?: string, fit?: string | number, hole?: string, printer?: object, sets?: object, at?: number[] }} [o] as captiveNutModel
752
+ * @param {Fixing | string} m @param {{ kind?: string, fit?: string | number, hole?: string, printer?: object,
753
+ * sets?: object, at?: number[] }} [o] as captiveNutModel
269
754
  * @returns {object} a JSCAD geom3 to subtract, with .model
270
755
  */
271
756
  export function captiveNut(m, o = {}) {
272
757
  const c = captiveNutModel(m, o);
273
- return Object.assign(pocket({ nut: { kind: c.kind } }, c.flats, c.height, c.hole, pointOf('captiveNut', o.at), '+z'), { model: c });
758
+ return Object.assign(
759
+ pocket({ nut: { kind: c.kind } }, c.flats, c.height, c.hole, pointOf('captiveNut', o.at), '+z'),
760
+ { model: c },
761
+ );
274
762
  }
275
763
 
276
764
  // ---------- insert boss ----------
@@ -279,44 +767,147 @@ export function captiveNut(m, o = {}) {
279
767
  * from the insert's rules. Refused where the wall is thinner than the insert's rule allows, or the part shorter than
280
768
  * the insert.
281
769
  * @param {Fixing | string} m
282
- * @param {{ height?: number, outer?: number, wall?: number, through?: boolean, root?: number, printer?: object, sets?: object }} [o]
770
+ * @param {{ height?: number, outer?: number, wall?: number, through?: boolean, root?: number, printer?: object,
771
+ * sets?: object }} [o]
283
772
  * height: of the boss, or the part's thickness there (default the blind hole's depth, up to a whole layer); outer:
284
773
  * the boss's diameter, or wall: the plastic round the hole (default the insert's least wall); through: the hole runs
285
774
  * out of the far side; root: the 45° flare where the boss meets what it stands on (default the printer's chamfer)
286
- * @returns {{ thread: string, hole: number, depth: number, through: boolean, outer: number, wall: number, least: number, height: number, root: number, lead: number, below: number, insert: { diameter: number, length: number }, rests: object[], findings: object[] }}
775
+ * @returns {{ thread: string, hole: number, depth: number, through: boolean, outer: number, wall: number,
776
+ * least: number, height: number, root: number, lead: number, below: number, insert: { diameter: number,
777
+ * length: number }, rests: object[], findings: object[] }}
287
778
  * hole: as drawn; least: the wall the insert's rule asks; below: how far a blind hole runs on under the boss's foot
288
779
  */
289
780
  export function insertBossModel(m, o = {}) {
290
781
  const what = 'insertBoss';
291
782
  optionsOf(what, o, '{ height: 8 }');
292
- const fx = fixingOf(what, m, o), pr = printerOf(what, o.printer), out = [];
783
+ const fx = fixingOf(what, m, o),
784
+ pr = printerOf(what, o.printer),
785
+ out = [];
293
786
  if (!fx.made.insert) throw new Error(`${what}: ${fx.thread} has no heat-set insert in its rule set (${fx.set})`);
294
- const through = o.through ?? false, h = holeModel(fx, { kind: 'insert', through, printer: o.printer }), least = figure(what, fx, 'insert_wall'), long = figure(what, fx, 'insert_length'), blind = figure(what, fx, 'insert_depth');
295
- if (o.outer != null && o.wall != null) throw new Error(`${what}: give outer (the boss's diameter) or wall (the plastic round the hole), not both`);
296
- const outer = o.outer != null ? positive(what, 'outer', o.outer) : r3(h.diameter + 2 * (o.wall != null ? positive(what, 'wall', o.wall) : least)), wall = r3((outer - h.diameter) / 2);
297
- if (wall < least - 1e-9) throw new Error(`${what}: ${mm(wall)} mm of wall round ${a(fx.thread)} insert's ${mm(h.diameter)} mm hole is thinner than the insert allows: ${cite(fx, 'insert_wall')} asks ${mm(least)} mm, so a boss ${mm(h.diameter + 2 * least)} mm across or more`);
787
+ const through = o.through ?? false,
788
+ h = holeModel(fx, { kind: 'insert', through, printer: o.printer }),
789
+ least = figure(what, fx, 'insert_wall'),
790
+ long = figure(what, fx, 'insert_length'),
791
+ blind = figure(what, fx, 'insert_depth');
792
+ if (o.outer != null && o.wall != null)
793
+ throw new Error(`${what}: give outer (the boss's diameter) or wall (the plastic round the hole), not both`);
794
+ const outer =
795
+ o.outer != null
796
+ ? positive(what, 'outer', o.outer)
797
+ : r3(h.diameter + 2 * (o.wall != null ? positive(what, 'wall', o.wall) : least)),
798
+ wall = r3((outer - h.diameter) / 2);
799
+ if (wall < least - 1e-9)
800
+ throw new Error(
801
+ `${what}: ${mm(wall)} mm of wall round ${a(fx.thread)} insert's ${mm(h.diameter)} mm hole is thinner ` +
802
+ `than the insert allows: ${cite(fx, 'insert_wall')} asks ${mm(least)} mm, so a boss ` +
803
+ `${mm(h.diameter + 2 * least)} mm across or more`,
804
+ );
298
805
  const height = o.height == null ? layers(through ? long : blind, pr.n('layer')) : positive(what, 'height', o.height);
299
- if (height < long - 1e-9) throw new Error(`${what}: the part is ${mm(height)} mm thick there and ${a(fx.thread)} insert ${mm(long)} mm long (${cite(fx, 'insert_length')}): it would stand proud. ${mm(long)} mm or more with { through: true }, ${mm(blind)} mm for a blind hole`);
300
- const depth = through ? height : blind, below = !through && height < blind - 1e-9 ? r3(blind - height) : 0, root = o.root == null ? pr.n('chamfer') : o.root;
301
- if (!(isNum(root) && root >= 0)) throw new Error(`${what}: root is the flare at the boss's foot, 0 mm or more (got ${shown(o.root)})`);
302
- out.push(finding('info', `a boss for ${a(fx.thread)} insert drawn ${mm(outer)} mm across and ${mm(height)} mm high round a ${mm(h.diameter)} mm hole ${through ? 'right through' : `${mm(depth)} mm deep`}: ${h.basis.rule}, as drawn (no hole compensation), with ${mm(wall)} mm of wall where ${cite(fx, 'insert_wall')} asks ${mm(least)} mm`,
303
- 'insertBoss.drawn', { values: { hole: h.diameter, depth, outer, wall, least, height }, refs: { thread: fx.thread, set: fx.set } }));
304
- if (below) out.push(finding('warn', `the blind hole runs ${mm(below)} mm on under the boss's foot (${cite(fx, 'insert_depth')} asks ${mm(blind)} mm): what it stands on must be thicker than that there`, 'insertBoss.depth', { values: { below, depth, height } }));
305
- out.push(finding('pass', 'standing up, the boss is a plain column with its hole open above: it prints as drawn, and the insert goes in from the top', 'insertBoss.printable', { values: { into: '-z' } }));
306
- return { thread: fx.thread, hole: h.diameter, depth, through, outer, wall, least, height, root, lead: h.lead, below, insert: { diameter: figure(what, fx, 'insert_diameter'), length: long },
307
- rests: [...figures(fx, ['insert_hole', 'insert_wall', 'insert_length', 'insert_depth']), pr.rest('layer'), pr.rest('chamfer')], findings: out };
806
+ if (height < long - 1e-9)
807
+ throw new Error(
808
+ `${what}: the part is ${mm(height)} mm thick there and ${a(fx.thread)} insert ${mm(long)} mm long (` +
809
+ `${cite(fx, 'insert_length')}): it would stand proud. ${mm(long)} mm or more with { through: true }, ` +
810
+ `${mm(blind)} mm for a blind hole`,
811
+ );
812
+ const depth = through ? height : blind,
813
+ below = !through && height < blind - 1e-9 ? r3(blind - height) : 0,
814
+ root = o.root == null ? pr.n('chamfer') : o.root;
815
+ if (!(isNum(root) && root >= 0))
816
+ throw new Error(`${what}: root is the flare at the boss's foot, 0 mm or more (got ${shown(o.root)})`);
817
+ out.push(
818
+ finding(
819
+ 'info',
820
+ `a boss for ${a(fx.thread)} insert drawn ${mm(outer)} mm across and ${mm(height)} mm high round a ` +
821
+ `${mm(h.diameter)} mm hole ` +
822
+ (through ? 'right through' : `${mm(depth)} mm deep`) +
823
+ `: ${h.basis.rule}, as drawn (no hole compensation), with ${mm(wall)} mm of wall where ` +
824
+ `${cite(fx, 'insert_wall')} asks ${mm(least)} mm`,
825
+ 'insertBoss.drawn',
826
+ { values: { hole: h.diameter, depth, outer, wall, least, height }, refs: { thread: fx.thread, set: fx.set } },
827
+ ),
828
+ );
829
+ if (below)
830
+ out.push(
831
+ finding(
832
+ 'warn',
833
+ `the blind hole runs ${mm(below)} mm on under the boss's foot (${cite(fx, 'insert_depth')} asks ` +
834
+ `${mm(blind)} mm): what it stands on must be thicker than that there`,
835
+ 'insertBoss.depth',
836
+ { values: { below, depth, height } },
837
+ ),
838
+ );
839
+ out.push(
840
+ finding(
841
+ 'pass',
842
+ 'standing up, the boss is a plain column with its hole open above: it prints as drawn, and the insert ' +
843
+ 'goes in from the top',
844
+ 'insertBoss.printable',
845
+ { values: { into: '-z' } },
846
+ ),
847
+ );
848
+ return {
849
+ thread: fx.thread,
850
+ hole: h.diameter,
851
+ depth,
852
+ through,
853
+ outer,
854
+ wall,
855
+ least,
856
+ height,
857
+ root,
858
+ lead: h.lead,
859
+ below,
860
+ insert: { diameter: figure(what, fx, 'insert_diameter'), length: long },
861
+ rests: [
862
+ ...figures(fx, ['insert_hole', 'insert_wall', 'insert_length', 'insert_depth']),
863
+ pr.rest('layer'),
864
+ pr.rest('chamfer'),
865
+ ],
866
+ findings: out,
867
+ };
308
868
  }
309
869
 
310
870
  /**
311
871
  * A boss for a heat-set insert: the column to add, standing up from `at` (the middle of its foot), and the hole to
312
872
  * subtract once the boss is joined to what it stands on.
313
- * @param {Fixing | string} m @param {{ height?: number, outer?: number, wall?: number, through?: boolean, root?: number, printer?: object, sets?: object, at?: number[] }} [o] as insertBossModel
873
+ * @param {Fixing | string} m @param {{ height?: number, outer?: number, wall?: number, through?: boolean,
874
+ * root?: number, printer?: object, sets?: object, at?: number[] }} [o] as insertBossModel
314
875
  * @returns {{ boss: object, hole: object, model: object }} boss: a JSCAD geom3 to add; hole: one to subtract
315
876
  */
316
877
  export function insertBoss(m, o = {}) {
317
- const b = insertBossModel(m, o), at = pointOf('insertBoss', o.at), R = b.outer / 2, r = b.hole / 2;
318
- const boss = translate(at, lathe([[0, 0], [R + b.root, 0], [R, b.root], [R, b.height], [0, b.height]], SEGMENTS));
319
- const cut = along(bore([...(b.lead ? [[r + b.lead, 0], [r, b.lead]] : []), [r, b.depth]], { through: b.through }), '-z', [at[0], at[1], at[2] + b.height]);
878
+ const b = insertBossModel(m, o),
879
+ at = pointOf('insertBoss', o.at),
880
+ R = b.outer / 2,
881
+ r = b.hole / 2;
882
+ const boss = translate(
883
+ at,
884
+ lathe(
885
+ [
886
+ [0, 0],
887
+ [R + b.root, 0],
888
+ [R, b.root],
889
+ [R, b.height],
890
+ [0, b.height],
891
+ ],
892
+ SEGMENTS,
893
+ ),
894
+ );
895
+ const cut = along(
896
+ bore(
897
+ [
898
+ ...(b.lead
899
+ ? [
900
+ [r + b.lead, 0],
901
+ [r, b.lead],
902
+ ]
903
+ : []),
904
+ [r, b.depth],
905
+ ],
906
+ { through: b.through },
907
+ ),
908
+ '-z',
909
+ [at[0], at[1], at[2] + b.height],
910
+ );
320
911
  return { boss, hole: cut, model: b };
321
912
  }
322
913
 
@@ -324,16 +915,51 @@ export function insertBoss(m, o = {}) {
324
915
  * What a printer can make of it, as findings. A fixing is bought, so it fails, and so does a screw, a nut, a washer
325
916
  * or an insert drawn as a light solid; a hole's, a seat's or a printed thread's model (or the solid made from one)
326
917
  * gives its finding on how it prints in the direction it was drawn for, and so does hardware with its thread drawn.
327
- * @param {object} x a fixing's model, a model from holeModel, threadModel, a seat's twin or a piece of hardware's, or a solid one of them made
918
+ * @param {object} x a fixing's model, a model from holeModel, threadModel, a seat's twin or a piece of hardware's, or a
919
+ * solid one of them made
328
920
  * @returns {object[]} findings
329
921
  */
330
922
  export function printable(x) {
331
- const bought = (thread, item) => [finding('fail', `${a(thread)} ${item === 'thread' ? 'fixing' : item} is bought and fitted, not printed: its hole and its seat are what print (hole, counterbore, nutPocket)${['screw', 'nut'].includes(item) ? `, or draw it with its thread to print it ({ display: 'thread' })` : ''}`, 'fixing.printable')];
332
- if (x?.kind === 'fixing' && x.printed) return [finding('info', `${x.name} is printed with its thread: printedBoltModel('${x.name}') says how its thread prints and what it holds`, 'fixing.printable')];
923
+ const bought = (thread, item) => [
924
+ finding(
925
+ 'fail',
926
+ `${a(thread)} ${item === 'thread' ? 'fixing' : item} is bought and fitted, not printed: its hole and ` +
927
+ `its seat are what print (hole, counterbore, nutPocket)` +
928
+ (['screw', 'nut'].includes(item) ? `, or draw it with its thread to print it ({ display: 'thread' })` : ''),
929
+ 'fixing.printable',
930
+ ),
931
+ ];
932
+ if (x?.kind === 'fixing' && x.printed)
933
+ return [
934
+ finding(
935
+ 'info',
936
+ `${x.name} is printed with its thread: printedBoltModel('${x.name}') says how its thread prints and ` +
937
+ `what it holds`,
938
+ 'fixing.printable',
939
+ ),
940
+ ];
333
941
  if (x?.kind === 'fixing') return bought(x.thread, x.item);
334
- const model = x?.model && Array.isArray(x.model.findings) ? x.model : x?.model?.model && Array.isArray(x.model.model.findings) ? x.model.model : x;
335
- if (model?.kind === 'magnet') return [finding('fail', `${model.name} is bought and fitted, not printed: its pocket is what prints (magnetSeat)`, 'magnet.printable')];
336
- if (!model || !Array.isArray(model.findings)) throw new Error(`printable: give a fixing's model, or a hole's, a seat's or a thread's (holeModel, counterboreModel, nutPocketModel, threadModel), not ${shown(x)}`);
942
+ const model =
943
+ x?.model && Array.isArray(x.model.findings)
944
+ ? x.model
945
+ : x?.model?.model && Array.isArray(x.model.model.findings)
946
+ ? x.model.model
947
+ : x;
948
+ if (model?.kind === 'magnet')
949
+ return [
950
+ finding(
951
+ 'fail',
952
+ `${model.name} is bought and fitted, not printed: its pocket is what prints (magnetSeat)`,
953
+ 'magnet.printable',
954
+ ),
955
+ ];
956
+ if (!model || !Array.isArray(model.findings))
957
+ throw new Error(
958
+ `printable: give a fixing's model, or a hole's, a seat's or a thread's (holeModel, counterboreModel, ` +
959
+ `nutPocketModel, threadModel), not ${shown(x)}`,
960
+ );
337
961
  const found = model.findings.filter((f) => typeof f.code === 'string' && f.code.endsWith('.printable'));
338
- return !found.length && ['screw', 'nut', 'washer', 'insert'].includes(model.item) ? bought(model.thread, model.item) : found;
962
+ return !found.length && ['screw', 'nut', 'washer', 'insert'].includes(model.item)
963
+ ? bought(model.thread, model.item)
964
+ : found;
339
965
  }