@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/threads.mjs CHANGED
@@ -7,15 +7,35 @@
7
7
  // left between it and its mate, and each end has a lead-in. Units: mm, degrees.
8
8
  import jscad from '@jscad/modeling';
9
9
  import t8screw from '@rulecad/rules/t8-screw.json' with { type: 'json' };
10
- import { DEFAULTS, fixingOf, fixingModel, printerOf, threads as threadNames, cite, rest, finding, positive, oneOf, isNum, shown, mm, r3, a, ENGAGEMENT, engagementOf } from './model.mjs';
10
+ import {
11
+ DEFAULTS,
12
+ fixingOf,
13
+ fixingModel,
14
+ printerOf,
15
+ threads as threadNames,
16
+ cite,
17
+ rest,
18
+ finding,
19
+ positive,
20
+ oneOf,
21
+ isNum,
22
+ shown,
23
+ mm,
24
+ r3,
25
+ a,
26
+ ENGAGEMENT,
27
+ engagementOf,
28
+ } from './model.mjs';
11
29
  import { along, lathe, OUT, SEGMENTS, UP } from './draw.mjs';
12
30
 
13
31
  /**
14
32
  * @typedef {import('./model.mjs').Fixing} Fixing a fixing's model, as fixingModel gives it
15
33
  */
16
34
 
17
- const { geom3, poly3 } = jscad.geometries, { rotateY, rotateZ } = jscad.transforms;
18
- const rad = (deg) => (deg * Math.PI) / 180, tan = (deg) => Math.tan(rad(deg));
35
+ const { geom3, poly3 } = jscad.geometries,
36
+ { rotateY, rotateZ } = jscad.transforms;
37
+ const rad = (deg) => (deg * Math.PI) / 180,
38
+ tan = (deg) => Math.tan(rad(deg));
19
39
  /** The lead screws of the catalogue a thread can be named by: 'T8' is the kit's t8-screw rule set. */
20
40
  const LEADSCREWS = { t8: t8screw };
21
41
  const TR = /^tr\s*(\d+(?:\.\d+)?)\s*[x×*]\s*(\d+(?:\.\d+)?)(?:\s*\(\s*p\s*(\d+(?:\.\d+)?)\s*\))?\s*(lh)?$/i;
@@ -24,7 +44,11 @@ export const THREAD_FORMS = ['metric', 'unified', 'trapezoidal'];
24
44
  // ISO 2904's crest clearance by pitch, as DIN 103 tabulates it (https://en.wikipedia.org/wiki/Trapezoidal_thread_form)
25
45
  const crestClearance = (what, P) => {
26
46
  if (P >= 1.5 - 1e-9 && P <= 12 + 1e-9) return P < 2 - 1e-9 ? 0.15 : P <= 5 + 1e-9 ? 0.25 : 0.5;
27
- throw new Error(`${what}: a trapezoidal pitch of ${mm(P)} mm is outside the crest clearances this package holds (ISO 2904, pitches from 1.5 to 12 mm): give the thread as { form: 'trapezoidal', diameter, pitch, ac } with its own`);
47
+ throw new Error(
48
+ `${what}: a trapezoidal pitch of ${mm(P)} mm is outside the crest clearances this package holds (ISO ` +
49
+ `2904, pitches from 1.5 to 12 mm): give the thread as { form: 'trapezoidal', diameter, pitch, ac } with ` +
50
+ `its own`,
51
+ );
28
52
  };
29
53
 
30
54
  // ---------- what thread is meant ----------
@@ -33,174 +57,564 @@ const crestClearance = (what, P) => {
33
57
  // screw's or its nut's rule set, or its numbers ({ form, diameter, pitch, starts }).
34
58
  function basisOf(what, spec, o) {
35
59
  const given = (name, value, why) => ({ name, value, unit: 'mm', kind: 'given', source: why });
36
- const trapezoid = (said, d, P, starts, rests, ac) => ({ form: 'trapezoidal', said, d, P, starts, alpha: 15, ac: ac ?? crestClearance(what, P), rests, fx: null });
60
+ const trapezoid = (said, d, P, starts, rests, ac) => ({
61
+ form: 'trapezoidal',
62
+ said,
63
+ d,
64
+ P,
65
+ starts,
66
+ alpha: 15,
67
+ ac: ac ?? crestClearance(what, P),
68
+ rests,
69
+ fx: null,
70
+ });
37
71
  const designation = (text, rests = null) => {
38
72
  const t = TR.exec(String(text).trim());
39
73
  if (!t) return null;
40
- const d = Number(t[1]), lead = Number(t[2]), P = t[3] ? Number(t[3]) : lead, starts = lead / P;
41
- if (!(d > 0 && P > 0) || Math.abs(starts - Math.round(starts)) > 1e-9) throw new Error(`${what}: "${text}" is a trapezoidal thread as diameter x lead (P pitch), the lead a whole number of pitches: Tr8x2, Tr8x8(P2) (got a lead of ${mm(lead)} mm on a ${mm(P)} mm pitch)`);
42
- return { ...trapezoid(`Tr${mm(d)}x${mm(lead)}${starts > 1 ? `(P${mm(P)})` : ''}`, d, P, Math.round(starts), rests ?? [given('the designation', text, 'the thread as it was named: diameter x lead (P pitch), as ISO 2904 writes it')]), hand: t[4] ? 'left' : null };
74
+ const d = Number(t[1]),
75
+ lead = Number(t[2]),
76
+ P = t[3] ? Number(t[3]) : lead,
77
+ starts = lead / P;
78
+ if (!(d > 0 && P > 0) || Math.abs(starts - Math.round(starts)) > 1e-9)
79
+ throw new Error(
80
+ `${what}: "${text}" is a trapezoidal thread as diameter x lead (P pitch), the lead a whole number of ` +
81
+ `pitches: Tr8x2, Tr8x8(P2) (got a lead of ${mm(lead)} mm on a ${mm(P)} mm pitch)`,
82
+ );
83
+ return {
84
+ ...trapezoid(
85
+ `Tr${mm(d)}x${mm(lead)}${starts > 1 ? `(P${mm(P)})` : ''}`,
86
+ d,
87
+ P,
88
+ Math.round(starts),
89
+ rests ?? [
90
+ given(
91
+ 'the designation',
92
+ text,
93
+ 'the thread as it was named: diameter x lead (P pitch), as ISO 2904 writes it',
94
+ ),
95
+ ],
96
+ ),
97
+ hand: t[4] ? 'left' : null,
98
+ };
43
99
  };
44
- const fromSet = (set) => { // a lead screw's rule set, or its nut's: the thread it names, with a variant's figures over it
100
+ const fromSet = (set) => {
101
+ // a lead screw's rule set, or its nut's: the thread it names, with a variant's figures over it
45
102
  let rules = set.rules;
46
103
  if (o.variant != null) {
47
104
  const v = Object.keys(set.variants ?? {}).find((k) => k.toLowerCase() === String(o.variant).toLowerCase());
48
- if (!v) throw new Error(`${what}: ${set.name} has no variant "${o.variant}" (${Object.keys(set.variants ?? {}).join(', ') || 'none'})`);
49
- rules = { ...rules, ...Object.fromEntries(Object.entries(set.variants[v].values ?? {}).map(([k, value]) => [k, { ...rules[k], value, kind: set.variants[v].kind ?? rules[k]?.kind, source: set.variants[v].source ?? rules[k]?.source }])) };
105
+ if (!v)
106
+ throw new Error(
107
+ `${what}: ${set.name} has no variant "${o.variant}" (` +
108
+ `${Object.keys(set.variants ?? {}).join(', ') || 'none'})`,
109
+ );
110
+ rules = {
111
+ ...rules,
112
+ ...Object.fromEntries(
113
+ Object.entries(set.variants[v].values ?? {}).map(([k, value]) => [
114
+ k,
115
+ {
116
+ ...rules[k],
117
+ value,
118
+ kind: set.variants[v].kind ?? rules[k]?.kind,
119
+ source: set.variants[v].source ?? rules[k]?.source,
120
+ },
121
+ ]),
122
+ ),
123
+ };
50
124
  }
51
- const text = rules.thread?.value, b = typeof text === 'string' ? designation(text, [rest(`${set.name}.thread`, rules.thread)]) : null;
52
- if (!b) throw new Error(`${what}: ${set.name ?? 'the rule set'} names no trapezoidal thread: its thread rule is ${shown(text)}, where a lead screw's says Tr8x8(P2). For a screw thread, give its name ('M10')`);
53
- if (isNum(rules.starts?.value) && rules.starts.value !== b.starts) throw new Error(`${what}: ${set.name} says ${rules.starts.value} starts and its thread ${b.said} has ${b.starts}: one of the two rules is wrong`);
125
+ const text = rules.thread?.value,
126
+ b = typeof text === 'string' ? designation(text, [rest(`${set.name}.thread`, rules.thread)]) : null;
127
+ if (!b)
128
+ throw new Error(
129
+ `${what}: ${set.name ?? 'the rule set'} names no trapezoidal thread: its thread rule is ` +
130
+ `${shown(text)}, where a lead screw's says Tr8x8(P2). For a screw thread, give its name ('M10')`,
131
+ );
132
+ if (isNum(rules.starts?.value) && rules.starts.value !== b.starts)
133
+ throw new Error(
134
+ `${what}: ${set.name} says ${rules.starts.value} starts and its thread ${b.said} has ${b.starts}: ` +
135
+ `one of the two rules is wrong`,
136
+ );
54
137
  for (const k of ['pitch', 'lead', 'starts']) if (rules[k]) b.rests.push(rest(`${set.name}.${k}`, rules[k]));
55
138
  return b;
56
139
  };
57
- if (typeof spec === 'string' && LEADSCREWS[spec.trim().toLowerCase()]) return fromSet(LEADSCREWS[spec.trim().toLowerCase()]);
58
- if (typeof spec === 'string' && /^tr/i.test(spec.trim())) { const b = designation(spec); if (!b) throw new Error(`${what}: "${spec}" does not read as a trapezoidal thread: Tr8x2 (8 mm, 2 mm pitch), Tr8x8(P2) (8 mm lead on a 2 mm pitch: four starts)`); return b; }
59
- if (spec && typeof spec === 'object' && spec.kind !== 'fixing' && spec.rules && typeof spec.rules === 'object') return fromSet(spec);
140
+ if (typeof spec === 'string' && LEADSCREWS[spec.trim().toLowerCase()])
141
+ return fromSet(LEADSCREWS[spec.trim().toLowerCase()]);
142
+ if (typeof spec === 'string' && /^tr/i.test(spec.trim())) {
143
+ const b = designation(spec);
144
+ if (!b)
145
+ throw new Error(
146
+ `${what}: "${spec}" does not read as a trapezoidal thread: Tr8x2 (8 mm, 2 mm pitch), Tr8x8(P2) (8 mm ` +
147
+ `lead on a 2 mm pitch: four starts)`,
148
+ );
149
+ return b;
150
+ }
151
+ if (spec && typeof spec === 'object' && spec.kind !== 'fixing' && spec.rules && typeof spec.rules === 'object')
152
+ return fromSet(spec);
60
153
  if (spec && typeof spec === 'object' && spec.kind !== 'fixing' && 'form' in spec) {
61
154
  oneOf(what, 'form', spec.form, THREAD_FORMS);
62
- const d = positive(what, 'diameter', spec.diameter), P = positive(what, 'pitch', spec.pitch), starts = spec.starts ?? 1;
63
- if (spec.ac != null && !(isNum(spec.ac) && spec.ac >= 0)) throw new Error(`${what}: ac is the crest clearance of a trapezoidal thread, 0 mm or more (got ${shown(spec.ac)})`);
155
+ const d = positive(what, 'diameter', spec.diameter),
156
+ P = positive(what, 'pitch', spec.pitch),
157
+ starts = spec.starts ?? 1;
158
+ if (spec.ac != null && !(isNum(spec.ac) && spec.ac >= 0))
159
+ throw new Error(
160
+ `${what}: ac is the crest clearance of a trapezoidal thread, 0 mm or more (got ${shown(spec.ac)})`,
161
+ );
64
162
  const rests = [given('diameter', d, 'given to threadModel'), given('pitch', P, 'given to threadModel')];
65
- return spec.form === 'trapezoidal' ? trapezoid(`Tr${mm(d)}x${mm(P * starts)}${starts > 1 ? `(P${mm(P)})` : ''}`, d, P, starts, rests, spec.ac) : { form: spec.form, said: `${mm(d)} x ${mm(P)}`, d, P, starts, alpha: 30, rests, fx: null };
163
+ return spec.form === 'trapezoidal'
164
+ ? trapezoid(`Tr${mm(d)}x${mm(P * starts)}${starts > 1 ? `(P${mm(P)})` : ''}`, d, P, starts, rests, spec.ac)
165
+ : { form: spec.form, said: `${mm(d)} x ${mm(P)}`, d, P, starts, alpha: 30, rests, fx: null };
66
166
  }
67
- if (typeof spec !== 'string' && !(spec && spec.kind === 'fixing')) throw new Error(`${what}: give a thread: a fixing's name or model ('M10', '1/4-20'), a trapezoidal thread ('Tr8x2', 'Tr8x8(P2)', or 'T8' for the catalogue's lead screw), a lead screw's rule set, or { form, diameter, pitch }, not ${shown(spec)}`);
167
+ if (typeof spec !== 'string' && !(spec && spec.kind === 'fixing'))
168
+ throw new Error(
169
+ `${what}: give a thread: a fixing's name or model ('M10', '1/4-20'), a trapezoidal thread ('Tr8x2', ` +
170
+ `'Tr8x8(P2)', or 'T8' for the catalogue's lead screw), a lead screw's rule set, or { form, diameter, ` +
171
+ `pitch }, not ${shown(spec)}`,
172
+ );
68
173
  const fx = fixingOf(what, spec, o);
69
- if (fx.form === 'plastic') throw new Error(`${what}: ${fx.thread} is a thread-forming screw for plastic: it makes its own thread in a pilot (hole kind 'pilot'), and there is no thread to print for it`);
70
- let P = fx.pitch; const rests = [rest(cite(fx, 'major_diameter'), fx.figures.major_diameter)];
71
- if (o.pitch != null) { P = positive(what, 'pitch', o.pitch); rests.push(given('pitch', P, 'given to threadModel')); } else rests.push(rest(cite(fx, 'pitch'), fx.figures.pitch));
72
- return { form: fx.form, said: o.pitch != null ? `${fx.thread}x${mm(P)}` : fx.thread, d: fx.major, P, starts: 1, alpha: 30, rests, fx };
174
+ if (fx.form === 'plastic')
175
+ throw new Error(
176
+ `${what}: ${fx.thread} is a thread-forming screw for plastic: it makes its own thread in a pilot (hole ` +
177
+ `kind 'pilot'), and there is no thread to print for it`,
178
+ );
179
+ let P = fx.pitch;
180
+ const rests = [rest(cite(fx, 'major_diameter'), fx.figures.major_diameter)];
181
+ if (o.pitch != null) {
182
+ P = positive(what, 'pitch', o.pitch);
183
+ rests.push(given('pitch', P, 'given to threadModel'));
184
+ } else rests.push(rest(cite(fx, 'pitch'), fx.figures.pitch));
185
+ return {
186
+ form: fx.form,
187
+ said: o.pitch != null ? `${fx.thread}x${mm(P)}` : fx.thread,
188
+ d: fx.major,
189
+ P,
190
+ starts: 1,
191
+ alpha: 30,
192
+ rests,
193
+ fx,
194
+ };
73
195
  }
74
196
 
75
197
  // One member of a thread (the screw, or the nut) on the basic profile: where its teeth are rooted, how wide a tooth is
76
198
  // there, how high it stands and how wide its crest is. Radii in mm; out: the teeth point away from the axis.
77
199
  function basicMember(b, internal) {
78
- const { d, P, alpha } = b, t = tan(alpha);
79
- if (b.form === 'trapezoidal') { // ISO 2904: H1 = 0.5 P, h3 = H4 = H1 + ac, d3 = d - 2 h3, D1 = d - P, D4 = d + 2 ac
80
- const h = 0.5 * P + b.ac, crest = P / 2 - (P / 2) * t, root = P - crest - 2 * h * t;
81
- return internal ? { out: false, root: d / 2 + b.ac, h, crest, rootFlat: root, pitchRadius: d / 2 - 0.25 * P } : { out: true, root: d / 2 - h, h, crest, rootFlat: root, pitchRadius: d / 2 - 0.25 * P };
200
+ const { d, P, alpha } = b,
201
+ t = tan(alpha);
202
+ if (b.form === 'trapezoidal') {
203
+ // ISO 2904: H1 = 0.5 P, h3 = H4 = H1 + ac, d3 = d - 2 h3, D1 = d - P, D4 = d + 2 ac
204
+ const h = 0.5 * P + b.ac,
205
+ crest = P / 2 - (P / 2) * t,
206
+ root = P - crest - 2 * h * t;
207
+ return internal
208
+ ? { out: false, root: d / 2 + b.ac, h, crest, rootFlat: root, pitchRadius: d / 2 - 0.25 * P }
209
+ : { out: true, root: d / 2 - h, h, crest, rootFlat: root, pitchRadius: d / 2 - 0.25 * P };
82
210
  }
83
- const H = (Math.sqrt(3) / 2) * P, h = (5 / 8) * H; // ISO 68-1: the triangle's height, less an eighth at the crest and a quarter at the root
84
- return internal ? { out: false, root: d / 2, h, crest: P / 4, rootFlat: P / 8, pitchRadius: d / 2 - (3 / 8) * H } : { out: true, root: d / 2 - h, h, crest: P / 8, rootFlat: P / 4, pitchRadius: d / 2 - (3 / 8) * H };
211
+ const H = (Math.sqrt(3) / 2) * P,
212
+ h = (5 / 8) * H; // ISO 68-1: the triangle's height, less an eighth at the crest and a quarter at the root
213
+ return internal
214
+ ? { out: false, root: d / 2, h, crest: P / 4, rootFlat: P / 8, pitchRadius: d / 2 - (3 / 8) * H }
215
+ : { out: true, root: d / 2 - h, h, crest: P / 8, rootFlat: P / 4, pitchRadius: d / 2 - (3 / 8) * H };
85
216
  }
86
217
  // The same member as it is drawn: moved off the basic profile by its share of the gap, and its down-facing flank laid
87
218
  // back to the angle beta (from the axis's normal) about the tooth's root, so the tooth stays inside the standard's
88
219
  // outline. Its height is what is left under the least crest.
89
220
  function drawnMember(b, internal, shift, beta, least) {
90
- const m = basicMember(b, internal), ta = tan(b.alpha), tb = tan(beta), width = b.P - m.rootFlat, laid = beta > b.alpha + 1e-9;
91
- const h = laid ? Math.min(m.h, (width - Math.min(m.crest, least)) / (ta + tb)) : m.h, crest = width - h * (ta + tb);
221
+ const m = basicMember(b, internal),
222
+ ta = tan(b.alpha),
223
+ tb = tan(beta),
224
+ width = b.P - m.rootFlat,
225
+ laid = beta > b.alpha + 1e-9;
226
+ const h = laid ? Math.min(m.h, (width - Math.min(m.crest, least)) / (ta + tb)) : m.h,
227
+ crest = width - h * (ta + tb);
92
228
  const root = m.root + (m.out ? -shift : shift);
93
229
  return { ...m, root, h, crest, tip: m.out ? root + h : root - h, up: h * ta, down: h * tb, standard: m.h };
94
230
  }
95
231
 
96
232
  /**
97
- * @typedef {{ kind: 'thread', thread: string, form: 'metric' | 'unified' | 'trapezoidal', internal: boolean, hand: 'right' | 'left', starts: number, pitch: number, lead: number, length: number,
98
- * major: number, basic: { major: number, pitch: number, minor: number }, drawn: { major: number, minor: number }, depth: number, standardDepth: number, crest: number,
99
- * flank: { up: number, down: number }, overhang: { standard: number, drawn: number, limit: number }, clearance: number, gap: number, comp: number, mate: 'printed' | 'bought', overlap: number, standardOverlap: number,
100
- * leadIn: number, run: number, segments: number, triangles: number, display: 'thread' | 'plain', top: '+z' | '-z', axis: 'x' | 'y' | 'z', flat: number | null, engaged: number,
101
- * outline: { lo: number, hi: number, flatLo: number, rise: number, flatHi: number, fall: number }, rests: object[], findings: object[] }} Thread
102
- * thread: as it is written ('M10', 'Tr8x8(P2)'); lead: the travel in one turn, pitch times starts; major: the nominal diameter;
103
- * basic: the standard's basic diameters of this member; drawn: its diameters as drawn (an internal thread's are its cutter's);
104
- * depth: a tooth's height as drawn, and standardDepth the standard's; crest: the flat left on a tooth;
105
- * flank: each flank's angle from the axis's normal, the one facing up and the one facing down as printed;
106
- * overhang: what the down-facing flank overhangs from upright, by the standard and as drawn, and the printer's limit;
107
- * clearance: the gap between this thread and its mate, on the radius; gap: this member's share of it; comp: the hole compensation across an internal thread;
108
- * overlap: how far its flanks overlap its mate's, on the radius, and standardOverlap the standard's; leadIn: the lead-in's size on the radius, run: its length along the axis;
109
- * triangles: the most the solid has; flat: on its side, how far from the axis its flat lies; engaged: the share of a turn left with thread
233
+ * @typedef {{ kind: 'thread', thread: string, form: 'metric' | 'unified' | 'trapezoidal', internal: boolean,
234
+ * hand: 'right' | 'left', starts: number, pitch: number, lead: number, length: number,
235
+ * major: number, basic: { major: number, pitch: number, minor: number }, drawn: { major: number, minor: number },
236
+ * depth: number, standardDepth: number, crest: number, flank: { up: number, down: number }, overhang:
237
+ * { standard: number, drawn: number, limit: number }, clearance: number, gap: number, comp: number, mate: 'printed' |
238
+ * 'bought', overlap: number, standardOverlap: number, leadIn: number, run: number, segments: number, triangles:
239
+ * number, display: 'thread' | 'plain', top: '+z' | '-z', axis: 'x' | 'y' | 'z', flat: number | null, engaged: number,
240
+ * outline: { lo: number, hi: number, flatLo: number, rise: number, flatHi: number, fall: number }, rests: object[],
241
+ * findings: object[] }} Thread thread: as it is written ('M10', 'Tr8x8(P2)'); lead: the travel in one turn, pitch
242
+ * times starts; major: the nominal diameter; basic: the standard's basic diameters of this member; drawn: its
243
+ * diameters as drawn (an internal thread's are its cutter's); depth: a tooth's height as drawn, and standardDepth the
244
+ * standard's; crest: the flat left on a tooth; flank: each flank's angle from the axis's normal, the one facing up
245
+ * and the one facing down as printed; overhang: what the down-facing flank overhangs from upright, by the standard
246
+ * and as drawn, and the printer's limit; clearance: the gap between this thread and its mate, on the radius; gap:
247
+ * this member's share of it; comp: the hole compensation across an internal thread; overlap: how far its flanks
248
+ * overlap its mate's, on the radius, and standardOverlap the standard's; leadIn: the lead-in's size on the radius,
249
+ * run: its length along the axis; triangles: the most the solid has; flat: on its side, how far from the axis its
250
+ * flat lies; engaged: the share of a turn left with thread
110
251
  */
111
252
 
112
253
  /**
113
254
  * A thread to print, as numbers: its profile as drawn, the clearance to its mate, how its flanks print, and what each
114
255
  * figure rests on. Refused by name where the printer cannot resolve the pitch (with the smallest thread that would
115
256
  * print), and where it is asked for lying on its side without a flat.
116
- * @param {Fixing | string | object} spec a fixing's name or model ('M10', '1/4-20'), a trapezoidal thread ('Tr8x2', 'Tr8x8(P2)',
257
+ * @param {Fixing | string | object} spec a fixing's name or model ('M10', '1/4-20'), a trapezoidal thread ('Tr8x2',
258
+ * 'Tr8x8(P2)',
117
259
  * 'T8' for the catalogue's lead screw), a lead screw's or its nut's rule set, or { form, diameter, pitch, starts }
118
- * @param {{ length: number, internal?: boolean, printer?: object, starts?: number, hand?: 'right' | 'left', pitch?: number, mate?: 'printed' | 'bought', gap?: number,
119
- * flanks?: 'printed' | 'standard', leadIn?: number, segments?: number, display?: 'thread' | 'plain', top?: '+z' | '-z', axis?: 'x' | 'y' | 'z', flat?: boolean, variant?: string, sets?: object }} o
120
- * length: of the thread, along its axis; internal: the thread of a nut or a threaded hole (the solid is then its cutter);
121
- * starts: how many threads run side by side (default 1, or what the designation says); hand: right (the default) or left;
122
- * pitch: another pitch on a fixing's diameter (a fine thread); mate: what it screws into, printed (each takes half the
123
- * gap) or bought (this one takes all of it); gap: the gap on the radius, in place of the printer's thread_gap;
124
- * flanks: printed (the down-facing flank laid back to the printer's overhang, the default) or standard (the standard's
125
- * own form); leadIn: the size of the lead-in at each end, on the radius (default a tooth's height); segments: faces
126
- * round, a multiple of 4 from 12 to 144 (default 48): it bounds the triangle count; display: thread, or plain for a
127
- * plain cylinder; top: which end is up when it prints, +z (as drawn, the default) or -z; axis: z standing up (the
128
- * default), x or y lying on its side, which needs flat: true (a flat to lie on, or a pointed roof in a hole)
260
+ * @param {{ length: number, internal?: boolean, printer?: object, starts?: number, hand?: 'right' | 'left',
261
+ * pitch?: number, mate?: 'printed' | 'bought', gap?: number,
262
+ * flanks?: 'printed' | 'standard', leadIn?: number, segments?: number, display?: 'thread' | 'plain', top?: '+z' |
263
+ * '-z', axis?: 'x' | 'y' | 'z', flat?: boolean, variant?: string, sets?: object }} o length: of the thread, along its
264
+ * axis; internal: the thread of a nut or a threaded hole (the solid is then its cutter); starts: how many threads run
265
+ * side by side (default 1, or what the designation says); hand: right (the default) or left; pitch: another pitch on
266
+ * a fixing's diameter (a fine thread); mate: what it screws into, printed (each takes half the gap) or bought (this
267
+ * one takes all of it); gap: the gap on the radius, in place of the printer's thread_gap; flanks: printed (the
268
+ * down-facing flank laid back to the printer's overhang, the default) or standard (the standard's own form); leadIn:
269
+ * the size of the lead-in at each end, on the radius (default a tooth's height); segments: faces round, a multiple of
270
+ * 4 from 12 to 144 (default 48): it bounds the triangle count; display: thread, or plain for a plain cylinder; top:
271
+ * which end is up when it prints, +z (as drawn, the default) or -z; axis: z standing up (the default), x or y lying
272
+ * on its side, which needs flat: true (a flat to lie on, or a pointed roof in a hole)
129
273
  * @returns {Thread}
130
274
  */
131
275
  export function threadModel(spec, o = {}) {
132
276
  const what = o?.what ?? 'threadModel';
133
- if (o == null || typeof o !== 'object' || Array.isArray(o)) throw new Error(`${what}: the second argument is its options ({ length: 20, internal: true }), not ${shown(o)}`);
134
- const b = basisOf(what, spec, o), pr = printerOf(what, o.printer), out = [], rests = [...b.rests];
135
- const internal = o.internal ?? false, hand = o.hand ?? b.hand ?? 'right', starts = o.starts ?? b.starts, flanks = o.flanks ?? 'printed', mate = o.mate ?? 'printed', display = o.display ?? 'thread', top = o.top ?? '+z', axis = o.axis ?? 'z', segments = o.segments ?? SEGMENTS;
136
- if (typeof internal !== 'boolean') throw new Error(`${what}: internal is true (a nut's thread, a threaded hole) or false (a screw's) (got ${shown(o.internal)})`);
137
- oneOf(what, 'hand', hand, ['right', 'left']); oneOf(what, 'flanks', flanks, ['printed', 'standard']); oneOf(what, 'mate', mate, ['printed', 'bought']);
138
- oneOf(what, 'display', display, ['thread', 'plain']); oneOf(what, 'top', top, ['+z', '-z']); oneOf(what, 'axis', axis, ['x', 'y', 'z']);
139
- if (!(Number.isInteger(starts) && starts >= 1)) throw new Error(`${what}: starts is how many threads run side by side, a whole number of 1 or more (got ${shown(starts)})`);
140
- if (!(Number.isInteger(segments) && segments >= 12 && segments <= 144 && segments % 4 === 0)) throw new Error(`${what}: segments is how many faces go round, a multiple of 4 from 12 to 144 (got ${shown(segments)})`);
141
- if (o.flat != null && typeof o.flat !== 'boolean') throw new Error(`${what}: flat is true or false: a flat along a thread lying on its side (got ${shown(o.flat)})`);
277
+ if (o == null || typeof o !== 'object' || Array.isArray(o))
278
+ throw new Error(`${what}: the second argument is its options ({ length: 20, internal: true }), not ${shown(o)}`);
279
+ const b = basisOf(what, spec, o),
280
+ pr = printerOf(what, o.printer),
281
+ out = [],
282
+ rests = [...b.rests];
283
+ const internal = o.internal ?? false,
284
+ hand = o.hand ?? b.hand ?? 'right',
285
+ starts = o.starts ?? b.starts,
286
+ flanks = o.flanks ?? 'printed',
287
+ mate = o.mate ?? 'printed',
288
+ display = o.display ?? 'thread',
289
+ top = o.top ?? '+z',
290
+ axis = o.axis ?? 'z',
291
+ segments = o.segments ?? SEGMENTS;
292
+ if (typeof internal !== 'boolean')
293
+ throw new Error(
294
+ `${what}: internal is true (a nut's thread, a threaded hole) or false (a screw's) (got ${shown(o.internal)})`,
295
+ );
296
+ oneOf(what, 'hand', hand, ['right', 'left']);
297
+ oneOf(what, 'flanks', flanks, ['printed', 'standard']);
298
+ oneOf(what, 'mate', mate, ['printed', 'bought']);
299
+ oneOf(what, 'display', display, ['thread', 'plain']);
300
+ oneOf(what, 'top', top, ['+z', '-z']);
301
+ oneOf(what, 'axis', axis, ['x', 'y', 'z']);
302
+ if (!(Number.isInteger(starts) && starts >= 1))
303
+ throw new Error(
304
+ `${what}: starts is how many threads run side by side, a whole number of 1 or more (got ${shown(starts)})`,
305
+ );
306
+ if (!(Number.isInteger(segments) && segments >= 12 && segments <= 144 && segments % 4 === 0))
307
+ throw new Error(
308
+ `${what}: segments is how many faces go round, a multiple of 4 from 12 to 144 (got ${shown(segments)})`,
309
+ );
310
+ if (o.flat != null && typeof o.flat !== 'boolean')
311
+ throw new Error(`${what}: flat is true or false: a flat along a thread lying on its side (got ${shown(o.flat)})`);
142
312
  if (o.length == null) throw new Error(`${what}: give a length, the thread's along its axis, in mm ({ length: 20 })`);
143
- const length = positive(what, 'length', o.length), { P, d } = b, lead = P * starts;
313
+ const length = positive(what, 'length', o.length),
314
+ { P, d } = b,
315
+ lead = P * starts;
144
316
 
145
317
  // What the printer resolves: layers to a pitch, and a tooth as deep as a line is wide
146
- const layer = pr.n('layer'), line = pr.n('line'), limit = pr.n('overhang'), basicTooth = basicMember(b, false).h - (b.form === 'trapezoidal' ? b.ac : 0);
147
- const byLayers = DEFAULTS.thread_layers.value * layer, byLine = (DEFAULTS.thread_lines.value * line * P) / basicTooth, least = Math.max(byLayers, byLine);
318
+ const layer = pr.n('layer'),
319
+ line = pr.n('line'),
320
+ limit = pr.n('overhang'),
321
+ basicTooth = basicMember(b, false).h - (b.form === 'trapezoidal' ? b.ac : 0);
322
+ const byLayers = DEFAULTS.thread_layers.value * layer,
323
+ byLine = (DEFAULTS.thread_lines.value * line * P) / basicTooth,
324
+ least = Math.max(byLayers, byLine);
148
325
  if (P < least - 1e-9) {
149
- const family = b.fx ? threadNames(o).map((t) => { try { return fixingModel(t, {}, { sets: o.sets }); } catch { return null; } }).filter((m) => m && m.form === b.fx.form && m.pitch >= least - 1e-9).sort((x, y) => x.major - y.major)[0] : null;
150
- throw new Error(`${what}: ${b.said} has a ${mm(P)} mm pitch, finer than ${pr.name} prints: a thread needs ${DEFAULTS.thread_layers.value} layers to a pitch (${mm(byLayers)} mm at ${pr.cite('layer')} ${mm(layer)} mm) and a tooth a line deep (a pitch of ${mm(r3(byLine))} mm at ${pr.cite('line')} ${mm(line)} mm). `
151
- + `${family ? `The smallest ${b.fx.form} thread that would print is ${family.thread} (${mm(family.pitch)} mm pitch)` : `A pitch of ${mm(r3(least))} mm or more would print`}. ${b.fx ? `For ${b.said} use a pilot the screw forms its own thread in, an insert, or a nut (hole kind 'pilot' or 'insert', nutPocket)` : 'Use a coarser thread, or a finer layer'}`);
326
+ const family = b.fx
327
+ ? threadNames(o)
328
+ .map((t) => {
329
+ try {
330
+ return fixingModel(t, {}, { sets: o.sets });
331
+ } catch {
332
+ return null;
333
+ }
334
+ })
335
+ .filter((m) => m && m.form === b.fx.form && m.pitch >= least - 1e-9)
336
+ .sort((x, y) => x.major - y.major)[0]
337
+ : null;
338
+ throw new Error(
339
+ `${what}: ${b.said} has a ${mm(P)} mm pitch, finer than ${pr.name} prints: a thread needs ` +
340
+ `${DEFAULTS.thread_layers.value} layers to a pitch (${mm(byLayers)} mm at ${pr.cite('layer')} ` +
341
+ `${mm(layer)} mm) and a tooth a line deep (a pitch of ${mm(r3(byLine))} mm at ${pr.cite('line')} ` +
342
+ `${mm(line)} mm). ` +
343
+ ((family
344
+ ? `The smallest ${b.fx.form} thread that would print is ${family.thread} (${mm(family.pitch)} mm pitch)`
345
+ : `A pitch of ${mm(r3(least))} mm or more would print`) +
346
+ `. ` +
347
+ (b.fx
348
+ ? `For ${b.said} use a pilot the screw forms its own thread in, an insert, or a nut (hole kind 'pilot' ` +
349
+ `or 'insert', nutPocket)`
350
+ : 'Use a coarser thread, or a finer layer')),
351
+ );
152
352
  }
153
- if (!(limit > 0 && limit < 90)) throw new Error(`${what}: ${pr.cite('overhang')} is the steepest overhang from upright that prints, between 0° and 90° (got ${shown(limit)})`);
154
- if (axis !== 'z' && !o.flat) throw new Error(`${what}: a thread lying on its side (axis ${axis}) has ${internal ? 'the crests of its top turns hanging in the hole with nothing under them' : 'its lower half hanging over the bed'}: no printer lays that without support. Stand it up (axis z), or give { flat: true }: ${internal ? 'a pointed roof over the hole, as a teardrop has' : 'a flat along the thread for it to lie on'}, which leaves thread on about three quarters of each turn`);
155
- if (axis === 'z' && o.flat) throw new Error(`${what}: flat is for a thread lying on its side (axis x or y): standing up, it needs none`);
353
+ if (!(limit > 0 && limit < 90))
354
+ throw new Error(
355
+ `${what}: ${pr.cite('overhang')} is the steepest overhang from upright that prints, between 0° and 90° ` +
356
+ `(got ${shown(limit)})`,
357
+ );
358
+ if (axis !== 'z' && !o.flat)
359
+ throw new Error(
360
+ `${what}: a thread lying on its side (axis ${axis}) has ` +
361
+ (internal
362
+ ? 'the crests of its top turns hanging in the hole with nothing under them'
363
+ : 'its lower half hanging over the bed') +
364
+ `: no printer lays that without support. Stand it up (axis z), or give { flat: true }: ` +
365
+ (internal ? 'a pointed roof over the hole, as a teardrop has' : 'a flat along the thread for it to lie on') +
366
+ `, which leaves thread on about three quarters of each turn`,
367
+ );
368
+ if (axis === 'z' && o.flat)
369
+ throw new Error(`${what}: flat is for a thread lying on its side (axis x or y): standing up, it needs none`);
156
370
 
157
371
  // The gap, and this member's share of it
158
372
  const gapRule = o.gap == null;
159
- if (!gapRule && !(isNum(o.gap) && o.gap >= 0)) throw new Error(`${what}: gap is the gap between this thread and its mate on the radius, 0 mm or more (got ${shown(o.gap)})`);
160
- const clearance = gapRule ? pr.n('thread_gap') : o.gap, gap = r3(mate === 'printed' ? clearance / 2 : clearance), comp = internal ? pr.n('hole_comp') : 0;
161
- if (gapRule) rests.push(pr.rest('thread_gap')); if (comp) rests.push(pr.rest('hole_comp'));
162
- rests.push(pr.rest('layer'), pr.rest('line'), pr.rest('overhang'), rest('fixings.thread_layers', DEFAULTS.thread_layers), rest('fixings.thread_lines', DEFAULTS.thread_lines));
373
+ if (!gapRule && !(isNum(o.gap) && o.gap >= 0))
374
+ throw new Error(
375
+ `${what}: gap is the gap between this thread and its mate on the radius, 0 mm or more (got ${shown(o.gap)})`,
376
+ );
377
+ const clearance = gapRule ? pr.n('thread_gap') : o.gap,
378
+ gap = r3(mate === 'printed' ? clearance / 2 : clearance),
379
+ comp = internal ? pr.n('hole_comp') : 0;
380
+ if (gapRule) rests.push(pr.rest('thread_gap'));
381
+ if (comp) rests.push(pr.rest('hole_comp'));
382
+ rests.push(
383
+ pr.rest('layer'),
384
+ pr.rest('line'),
385
+ pr.rest('overhang'),
386
+ rest('fixings.thread_layers', DEFAULTS.thread_layers),
387
+ rest('fixings.thread_lines', DEFAULTS.thread_lines),
388
+ );
163
389
 
164
390
  // Flanks: a flank at alpha from the axis's normal overhangs 90 - alpha from upright where it faces down. Lying on
165
391
  // its side, a flank faces sideways and needs nothing.
166
- const laid = flanks === 'printed' && axis === 'z' && 90 - b.alpha > limit + 1e-9, beta = laid ? 90 - limit : b.alpha, crestLeast = DEFAULTS.thread_crest.value * P;
392
+ const laid = flanks === 'printed' && axis === 'z' && 90 - b.alpha > limit + 1e-9,
393
+ beta = laid ? 90 - limit : b.alpha,
394
+ crestLeast = DEFAULTS.thread_crest.value * P;
167
395
  if (laid) rests.push(rest('fixings.thread_crest', DEFAULTS.thread_crest));
168
- const me = drawnMember(b, internal, gap + comp / 2, beta, crestLeast), std = basicMember(b, internal);
169
- const other = mate === 'printed' ? drawnMember(b, !internal, gap + (internal ? 0 : pr.n('hole_comp') / 2), beta, crestLeast) : { tip: (() => { const x = basicMember(b, !internal); return x.out ? x.root + x.h : x.root - x.h; })() };
170
- const overlap = r3(internal ? other.tip - me.tip : me.tip - other.tip), standardOverlap = r3(b.form === 'trapezoidal' ? 0.5 * P : std.h);
171
- if (!(me.crest > 1e-9 && me.h > 1e-9)) throw new Error(`${what}: ${b.said} leaves no tooth once its flank is laid back to ${mm(limit)}° (a crest of ${mm(me.crest)} mm): use { flanks: 'standard' }, or a coarser thread`);
396
+ const me = drawnMember(b, internal, gap + comp / 2, beta, crestLeast),
397
+ std = basicMember(b, internal);
398
+ const other =
399
+ mate === 'printed'
400
+ ? drawnMember(b, !internal, gap + (internal ? 0 : pr.n('hole_comp') / 2), beta, crestLeast)
401
+ : {
402
+ tip: (() => {
403
+ const x = basicMember(b, !internal);
404
+ return x.out ? x.root + x.h : x.root - x.h;
405
+ })(),
406
+ };
407
+ const overlap = r3(internal ? other.tip - me.tip : me.tip - other.tip),
408
+ standardOverlap = r3(b.form === 'trapezoidal' ? 0.5 * P : std.h);
409
+ if (!(me.crest > 1e-9 && me.h > 1e-9))
410
+ throw new Error(
411
+ `${what}: ${b.said} leaves no tooth once its flank is laid back to ${mm(limit)}° (a crest of ` +
412
+ `${mm(me.crest)} mm): use { flanks: 'standard' }, or a coarser thread`,
413
+ );
172
414
 
173
415
  // The outline of the solid over one pitch, going up z: a flat at its low radius, a flank out, a flat at its high
174
- // radius, a flank back. On a screw the rising flank is the tooth's underside; in a cutter it is the top of the nut's tooth below.
175
- const downFirst = (top === '+z') !== internal, lo = internal ? me.tip : me.root, hi = internal ? me.root : me.tip;
176
- const outline = { lo: r3(lo), hi: r3(hi), // (to a micron: the solid is drawn from these, and the diameters below are twice them)
177
- flatLo: internal ? me.crest : me.rootFlat, rise: downFirst ? me.down : me.up, flatHi: internal ? me.rootFlat : me.crest, fall: downFirst ? me.up : me.down };
416
+ // radius, a flank back. On a screw the rising flank is the tooth's underside; in a cutter it is the top of the nut's
417
+ // tooth below.
418
+ const downFirst = (top === '+z') !== internal,
419
+ lo = internal ? me.tip : me.root,
420
+ hi = internal ? me.root : me.tip;
421
+ const outline = {
422
+ lo: r3(lo),
423
+ hi: r3(hi), // (to a micron: the solid is drawn from these, and the diameters below are twice them)
424
+ flatLo: internal ? me.crest : me.rootFlat,
425
+ rise: downFirst ? me.down : me.up,
426
+ flatHi: internal ? me.rootFlat : me.crest,
427
+ fall: downFirst ? me.up : me.down,
428
+ };
178
429
  const slope = Math.min(1, Math.tan(rad(limit)));
179
- if (o.leadIn != null && !(isNum(o.leadIn) && o.leadIn >= 0)) throw new Error(`${what}: leadIn is the lead-in's size at each end, on the radius, 0 mm or more (got ${shown(o.leadIn)})`);
180
- const leadIn = r3(o.leadIn ?? me.h), run = r3(leadIn / slope);
181
- if (length < 2 * run + P - 1e-9) throw new Error(`${what}: a ${b.said} thread ${mm(length)} mm long is shorter than its two lead-ins and one pitch (${mm(r3(2 * run + P))} mm): make it longer, or give a smaller { leadIn }`);
430
+ if (o.leadIn != null && !(isNum(o.leadIn) && o.leadIn >= 0))
431
+ throw new Error(
432
+ `${what}: leadIn is the lead-in's size at each end, on the radius, 0 mm or more (got ${shown(o.leadIn)})`,
433
+ );
434
+ const leadIn = r3(o.leadIn ?? me.h),
435
+ run = r3(leadIn / slope);
436
+ if (length < 2 * run + P - 1e-9)
437
+ throw new Error(
438
+ `${what}: a ${b.said} thread ${mm(length)} mm long is shorter than its two lead-ins and one pitch (` +
439
+ `${mm(r3(2 * run + P))} mm): make it longer, or give a smaller { leadIn }`,
440
+ );
182
441
 
183
442
  // Lying on its side: a flat where the root's underside would pass the overhang, snapped to a face of the solid
184
- let flat = null, engaged = 1;
185
- if (axis !== 'z') { const step = 360 / segments, cut = Math.ceil((90 - limit) / step - 1e-9) * step; flat = r3(me.root * (internal ? 1 : Math.cos(rad(cut)))); engaged = r3(1 - (internal ? 90 - limit : cut) / 180); }
443
+ let flat = null,
444
+ engaged = 1;
445
+ if (axis !== 'z') {
446
+ const step = 360 / segments,
447
+ cut = Math.ceil((90 - limit) / step - 1e-9) * step;
448
+ flat = r3(me.root * (internal ? 1 : Math.cos(rad(cut))));
449
+ engaged = r3(1 - (internal ? 90 - limit : cut) / 180);
450
+ }
186
451
 
187
- const rows = 4 * (Math.ceil((length + 2 * OUT + lead + (internal ? hi / slope : 0)) / P) - Math.floor(-(lead + OUT) / P) + 2), triangles = display === 'plain' ? 8 * segments : 2 * segments * (rows + 1);
188
- const dia = (r) => r3(2 * r3(r)), basic = { major: dia(internal ? std.root : std.root + std.h), pitch: dia(std.pitchRadius), minor: dia(internal ? std.root - std.h : std.root) };
189
- const says = internal ? 'an internal' : 'an external', angle = (x) => mm(r3(x));
190
- out.push(finding('info', `${says} ${b.said} thread drawn ${mm(dia(hi))} mm over its ${internal ? 'roots' : 'crests'} and ${mm(dia(lo))} mm over its ${internal ? 'crests' : 'roots'}, ${mm(length)} mm long: ${b.form === 'trapezoidal' ? 'the trapezoidal form of ISO 2904' : b.form === 'unified' ? 'the unified form, the basic profile of ISO 68-1' : 'the basic profile of ISO 68-1'} on a ${mm(P)} mm pitch${starts > 1 ? `, ${starts} starts, a lead of ${mm(lead)} mm` : ''}${hand === 'left' ? ', left hand' : ''} (basic: ${mm(basic.major)} major, ${mm(basic.pitch)} pitch, ${mm(basic.minor)} minor)`,
191
- 'thread.drawn', { values: { major: dia(hi), minor: dia(lo), pitch: P, lead, starts, length }, refs: { thread: b.said, form: b.form, internal, hand } }));
192
- out.push(finding('info', `${mm(clearance)} mm between this thread and its mate, on the radius: ${gapRule ? `${pr.cite('thread_gap')}, ${pr.rest('thread_gap').kind === 'estimate' ? 'an estimate until the fixings coupon measures it' : `a ${pr.rest('thread_gap').kind} figure`}` : 'the gap given'}. ${mate === 'printed' ? `A printed pair takes half each, so this one is drawn ${mm(gap)} mm off the basic profile` : `Its mate is bought, so this one takes all of it`}${comp ? `, and ${pr.cite('hole_comp')} ${mm(comp)} mm across as any printed hole` : ''}`,
193
- 'thread.clearance', { values: { clearance, gap, comp }, refs: { rule: gapRule ? pr.cite('thread_gap') : 'given', kind: gapRule ? pr.rest('thread_gap').kind : 'given', mate } }));
194
- if (gapRule && pr.rest('thread_gap').borrowed) out.push(finding('info', `${pr.name} has no thread_gap: the X1C's ${mm(clearance)} mm is used`, 'thread.printer', { values: { clearance } }));
452
+ const rows =
453
+ 4 * (Math.ceil((length + 2 * OUT + lead + (internal ? hi / slope : 0)) / P) - Math.floor(-(lead + OUT) / P) + 2),
454
+ triangles = display === 'plain' ? 8 * segments : 2 * segments * (rows + 1);
455
+ const dia = (r) => r3(2 * r3(r)),
456
+ basic = {
457
+ major: dia(internal ? std.root : std.root + std.h),
458
+ pitch: dia(std.pitchRadius),
459
+ minor: dia(internal ? std.root - std.h : std.root),
460
+ };
461
+ const says = internal ? 'an internal' : 'an external',
462
+ angle = (x) => mm(r3(x));
463
+ out.push(
464
+ finding(
465
+ 'info',
466
+ `${says} ${b.said} thread drawn ${mm(dia(hi))} mm over its ${internal ? 'roots' : 'crests'} and ` +
467
+ `${mm(dia(lo))} mm over its ${internal ? 'crests' : 'roots'}, ${mm(length)} mm long: ` +
468
+ (b.form === 'trapezoidal'
469
+ ? 'the trapezoidal form of ISO 2904'
470
+ : b.form === 'unified'
471
+ ? 'the unified form, the basic profile of ISO 68-1'
472
+ : 'the basic profile of ISO 68-1') +
473
+ ` on a ${mm(P)} mm pitch` +
474
+ (starts > 1 ? `, ${starts} starts, a lead of ${mm(lead)} mm` : '') +
475
+ `${hand === 'left' ? ', left hand' : ''} (basic: ${mm(basic.major)} major, ${mm(basic.pitch)} pitch, ` +
476
+ `${mm(basic.minor)} minor)`,
477
+ 'thread.drawn',
478
+ {
479
+ values: { major: dia(hi), minor: dia(lo), pitch: P, lead, starts, length },
480
+ refs: { thread: b.said, form: b.form, internal, hand },
481
+ },
482
+ ),
483
+ );
484
+ out.push(
485
+ finding(
486
+ 'info',
487
+ `${mm(clearance)} mm between this thread and its mate, on the radius: ` +
488
+ (gapRule
489
+ ? `${pr.cite('thread_gap')}, ` +
490
+ (pr.rest('thread_gap').kind === 'estimate'
491
+ ? 'an estimate until the fixings coupon measures it'
492
+ : `a ${pr.rest('thread_gap').kind} figure`)
493
+ : 'the gap given') +
494
+ `. ` +
495
+ (mate === 'printed'
496
+ ? `A printed pair takes half each, so this one is drawn ${mm(gap)} mm off the basic profile`
497
+ : `Its mate is bought, so this one takes all of it`) +
498
+ (comp ? `, and ${pr.cite('hole_comp')} ${mm(comp)} mm across as any printed hole` : ''),
499
+ 'thread.clearance',
500
+ {
501
+ values: { clearance, gap, comp },
502
+ refs: {
503
+ rule: gapRule ? pr.cite('thread_gap') : 'given',
504
+ kind: gapRule ? pr.rest('thread_gap').kind : 'given',
505
+ mate,
506
+ },
507
+ },
508
+ ),
509
+ );
510
+ if (gapRule && pr.rest('thread_gap').borrowed)
511
+ out.push(
512
+ finding('info', `${pr.name} has no thread_gap: the X1C's ${mm(clearance)} mm is used`, 'thread.printer', {
513
+ values: { clearance },
514
+ }),
515
+ );
195
516
  const overhang = { standard: 90 - b.alpha, drawn: r3(90 - beta), limit };
196
- if (axis !== 'z') out.push(finding('pass', `lying along ${axis}, ${internal ? `the hole has a pointed roof that leaves its roots, ${mm(flat)} mm from the axis, at ${angle(limit)}°, so nothing hangs` : `the thread has a flat ${mm(flat)} mm from its axis to lie on`}: thread is left on ${mm(r3(engaged * 100))}% of each turn, and its flanks face sideways, so they keep the standard's ${angle(b.alpha)}°`, 'thread.printable', { values: { axis, flat, engaged } }));
197
- else if (laid) out.push(finding('pass', `standing up, the standard's flank lies ${angle(b.alpha)}° from the axis's normal, which is a ${angle(overhang.standard)}° overhang from upright where it faces down, past ${pr.cite('overhang')} ${angle(limit)}°. The down-facing flank is laid back to ${angle(beta)}° about the tooth's root, a ${angle(overhang.drawn)}° overhang, so the tooth stays inside the standard's outline and still fits a bought mate; the up-facing flank keeps ${angle(b.alpha)}°. Each tooth is ${mm(r3(me.h))} mm high where the standard's is ${mm(r3(std.h))} mm, with a ${mm(r3(me.crest))} mm crest. Print it with ${top} up`,
198
- 'thread.printable', { values: { top, standard: overhang.standard, drawn: overhang.drawn, limit, depth: r3(me.h), standardDepth: r3(std.h) } }));
199
- else out.push(finding(overhang.standard <= limit + 1e-9 ? 'pass' : 'warn', overhang.standard <= limit + 1e-9 ? `standing up, the flank's ${angle(overhang.standard)}° overhang from upright is within ${pr.cite('overhang')} ${angle(limit)}°: the standard's form prints as it is`
200
- : `standing up, the standard's flank overhangs ${angle(overhang.standard)}° from upright where it faces down, past ${pr.cite('overhang')} ${angle(limit)}°, over a reach of ${mm(r3(std.h))} mm: the form is the standard's own, and whether the printer lays it is for a test print to say`, 'thread.printable', { values: { top, standard: overhang.standard, drawn: overhang.standard, limit } }));
201
- out.push(finding(overlap > 0 ? 'info' : 'fail', `its flanks overlap ${mate === 'printed' ? 'a printed mate drawn the same way' : 'a bought mate at its basic size'} by ${mm(overlap)} mm on the radius, where the standard's overlap ${mm(standardOverlap)} mm (${mm(r3((overlap / standardOverlap) * 100))}%)`, 'thread.overlap', { values: { overlap, standard: standardOverlap } }));
202
- return { kind: 'thread', thread: b.said, form: b.form, internal, hand, starts, pitch: P, lead, length, major: d, basic, drawn: { major: dia(hi), minor: dia(lo) }, depth: r3(me.h), standardDepth: r3(std.h), crest: r3(me.crest),
203
- flank: { up: b.alpha, down: r3(beta) }, overhang, clearance, gap, comp, mate, overlap, standardOverlap, leadIn, run, segments, triangles, display, top, axis, flat, engaged, outline, rests, findings: out };
517
+ if (axis !== 'z')
518
+ out.push(
519
+ finding(
520
+ 'pass',
521
+ `lying along ${axis}, ` +
522
+ (internal
523
+ ? `the hole has a pointed roof that leaves its roots, ${mm(flat)} mm from the axis, at ${angle(limit)}` +
524
+ `°, so nothing hangs`
525
+ : `the thread has a flat ${mm(flat)} mm from its axis to lie on`) +
526
+ `: thread is left on ${mm(r3(engaged * 100))}% of each turn, and its flanks face sideways, so they ` +
527
+ `keep the standard's ${angle(b.alpha)}°`,
528
+ 'thread.printable',
529
+ { values: { axis, flat, engaged } },
530
+ ),
531
+ );
532
+ else if (laid)
533
+ out.push(
534
+ finding(
535
+ 'pass',
536
+ `standing up, the standard's flank lies ${angle(b.alpha)}° from the axis's normal, which is a ` +
537
+ `${angle(overhang.standard)}° overhang from upright where it faces down, past ${pr.cite('overhang')} ` +
538
+ `${angle(limit)}°. The down-facing flank is laid back to ${angle(beta)}° about the tooth's root, a ` +
539
+ `${angle(overhang.drawn)}° overhang, so the tooth stays inside the standard's outline and still fits ` +
540
+ `a bought mate; the up-facing flank keeps ${angle(b.alpha)}°. Each tooth is ${mm(r3(me.h))} mm high ` +
541
+ `where the standard's is ${mm(r3(std.h))} mm, with a ${mm(r3(me.crest))} mm crest. Print it with ` +
542
+ `${top} up`,
543
+ 'thread.printable',
544
+ {
545
+ values: {
546
+ top,
547
+ standard: overhang.standard,
548
+ drawn: overhang.drawn,
549
+ limit,
550
+ depth: r3(me.h),
551
+ standardDepth: r3(std.h),
552
+ },
553
+ },
554
+ ),
555
+ );
556
+ else
557
+ out.push(
558
+ finding(
559
+ overhang.standard <= limit + 1e-9 ? 'pass' : 'warn',
560
+ overhang.standard <= limit + 1e-9
561
+ ? `standing up, the flank's ${angle(overhang.standard)}° overhang from upright is within ` +
562
+ `${pr.cite('overhang')} ${angle(limit)}°: the standard's form prints as it is`
563
+ : `standing up, the standard's flank overhangs ${angle(overhang.standard)}° from upright where it ` +
564
+ `faces down, past ${pr.cite('overhang')} ${angle(limit)}°, over a reach of ${mm(r3(std.h))} mm: ` +
565
+ `the form is the standard's own, and whether the printer lays it is for a test print to say`,
566
+ 'thread.printable',
567
+ { values: { top, standard: overhang.standard, drawn: overhang.standard, limit } },
568
+ ),
569
+ );
570
+ out.push(
571
+ finding(
572
+ overlap > 0 ? 'info' : 'fail',
573
+ `its flanks overlap ` +
574
+ (mate === 'printed' ? 'a printed mate drawn the same way' : 'a bought mate at its basic size') +
575
+ ` by ${mm(overlap)} mm on the radius, where the standard's overlap ${mm(standardOverlap)} mm (` +
576
+ `${mm(r3((overlap / standardOverlap) * 100))}%)`,
577
+ 'thread.overlap',
578
+ { values: { overlap, standard: standardOverlap } },
579
+ ),
580
+ );
581
+ return {
582
+ kind: 'thread',
583
+ thread: b.said,
584
+ form: b.form,
585
+ internal,
586
+ hand,
587
+ starts,
588
+ pitch: P,
589
+ lead,
590
+ length,
591
+ major: d,
592
+ basic,
593
+ drawn: { major: dia(hi), minor: dia(lo) },
594
+ depth: r3(me.h),
595
+ standardDepth: r3(std.h),
596
+ crest: r3(me.crest),
597
+ flank: { up: b.alpha, down: r3(beta) },
598
+ overhang,
599
+ clearance,
600
+ gap,
601
+ comp,
602
+ mate,
603
+ overlap,
604
+ standardOverlap,
605
+ leadIn,
606
+ run,
607
+ segments,
608
+ triangles,
609
+ display,
610
+ top,
611
+ axis,
612
+ flat,
613
+ engaged,
614
+ outline,
615
+ rests,
616
+ findings: out,
617
+ };
204
618
  }
205
619
 
206
620
  // ---------- the solid ----------
@@ -210,10 +624,14 @@ export function threadModel(spec, o = {}) {
210
624
  // lead-in, a roof), and place(i, r, z) may put a point somewhere of its own (a flat). Returns the triangles and the
211
625
  // two end rings.
212
626
  function sweep({ outline: o, P, lead, turn, n, z0, z1, shape, place = null, inside = false, caps = true }) {
213
- const offs = [0, o.flatLo, o.flatLo + o.rise, o.flatLo + o.rise + o.flatHi], radii = [o.lo, o.lo, o.hi, o.hi], per = 4 * Math.round(lead / P);
214
- const cos = Array.from({ length: n }, (_, i) => Math.cos((2 * Math.PI * i) / n)), sin = Array.from({ length: n }, (_, i) => Math.sin((2 * Math.PI * i) / n));
627
+ const offs = [0, o.flatLo, o.flatLo + o.rise, o.flatLo + o.rise + o.flatHi],
628
+ radii = [o.lo, o.lo, o.hi, o.hi],
629
+ per = 4 * Math.round(lead / P);
630
+ const cos = Array.from({ length: n }, (_, i) => Math.cos((2 * Math.PI * i) / n)),
631
+ sin = Array.from({ length: n }, (_, i) => Math.sin((2 * Math.PI * i) / n));
215
632
  const mod = (x, m) => ((x % m) + m) % m;
216
- const profile = (z) => { // the outline's radius at a height, on column 0
633
+ const profile = (z) => {
634
+ // the outline's radius at a height, on column 0
217
635
  const u = mod(z, P);
218
636
  if (u <= offs[1]) return o.lo;
219
637
  if (u < offs[2]) return o.lo + ((o.hi - o.lo) * (u - offs[1])) / (offs[2] - offs[1]);
@@ -221,33 +639,72 @@ function sweep({ outline: o, P, lead, turn, n, z0, z1, shape, place = null, insi
221
639
  return o.hi - ((o.hi - o.lo) * (u - offs[3])) / (P - offs[3]);
222
640
  };
223
641
  const point = (i, r, z) => place?.(i, r, z) ?? [Math.max(r, 0) * cos[i], Math.max(r, 0) * sin[i], z];
224
- const ringAt = (z) => Array.from({ length: n }, (_, i) => point(i, shape(profile(z - (turn * lead * i) / n), z, i), z));
225
- const lo = ringAt(z0), hi = ringAt(z1);
642
+ const ringAt = (z) =>
643
+ Array.from({ length: n }, (_, i) => point(i, shape(profile(z - (turn * lead * i) / n), z, i), z));
644
+ const lo = ringAt(z0),
645
+ hi = ringAt(z1);
226
646
  const at = (i, k) => {
227
- if (i === n) { i = 0; k += turn * per; }
647
+ if (i === n) {
648
+ i = 0;
649
+ k += turn * per;
650
+ }
228
651
  const z = Math.floor(k / 4) * P + offs[mod(k, 4)] + (turn * lead * i) / n;
229
652
  return z <= z0 ? lo[i] : z >= z1 ? hi[i] : point(i, shape(radii[mod(k, 4)], z, i), z);
230
653
  };
231
- const same = (p, q) => p === q || (Math.abs(p[0] - q[0]) < 1e-9 && Math.abs(p[1] - q[1]) < 1e-9 && Math.abs(p[2] - q[2]) < 1e-9);
232
- const tris = [], add = (p, q, r) => { if (!same(p, q) && !same(q, r) && !same(p, r)) tris.push(inside ? [p, r, q] : [p, q, r]); };
233
- for (let k = 4 * (Math.floor((z0 - lead) / P) - 1); k < 4 * (Math.ceil((z1 + lead) / P) + 1); k++) for (let i = 0; i < n; i++) {
234
- const p = at(i, k), q = at(i + 1, k), r = at(i + 1, k + 1), s = at(i, k + 1);
235
- // (a face is split corner to corner; where a flat cuts it, along the diagonal that lies flattest on the flat)
236
- if (place && Math.abs(place.depth(q) - place.depth(s)) < Math.abs(place.depth(p) - place.depth(r)) - 1e-9) { add(p, q, s); add(q, r, s); } else { add(p, q, r); add(p, r, s); }
654
+ const same = (p, q) =>
655
+ p === q || (Math.abs(p[0] - q[0]) < 1e-9 && Math.abs(p[1] - q[1]) < 1e-9 && Math.abs(p[2] - q[2]) < 1e-9);
656
+ const tris = [],
657
+ add = (p, q, r) => {
658
+ if (!same(p, q) && !same(q, r) && !same(p, r)) tris.push(inside ? [p, r, q] : [p, q, r]);
659
+ };
660
+ for (let k = 4 * (Math.floor((z0 - lead) / P) - 1); k < 4 * (Math.ceil((z1 + lead) / P) + 1); k++)
661
+ for (let i = 0; i < n; i++) {
662
+ const p = at(i, k),
663
+ q = at(i + 1, k),
664
+ r = at(i + 1, k + 1),
665
+ s = at(i, k + 1);
666
+ // (a face is split corner to corner; where a flat cuts it, along the diagonal that lies flattest on the flat)
667
+ if (place && Math.abs(place.depth(q) - place.depth(s)) < Math.abs(place.depth(p) - place.depth(r)) - 1e-9) {
668
+ add(p, q, s);
669
+ add(q, r, s);
670
+ } else {
671
+ add(p, q, r);
672
+ add(p, r, s);
673
+ }
674
+ }
675
+ for (let i = 0; i < n; i++) {
676
+ const j = (i + 1) % n;
677
+ if (caps === true || caps === 'low') add([0, 0, z0], lo[j], lo[i]);
678
+ if (caps === true || caps === 'high') add(hi[i], hi[j], [0, 0, z1]);
237
679
  }
238
- for (let i = 0; i < n; i++) { const j = (i + 1) % n; if (caps === true || caps === 'low') add([0, 0, z0], lo[j], lo[i]); if (caps === true || caps === 'high') add(hi[i], hi[j], [0, 0, z1]); }
239
680
  return { tris, lo, hi };
240
681
  }
241
682
  const solid = (tris) => geom3.create(tris.map((t) => poly3.create(t)));
242
683
  // The flat face between an outline and a ring inside it, both running anticlockwise round the axis: z up or down
243
684
  function annulus(outer, inner, up) {
244
- const angle = (p) => Math.atan2(p[1], p[0]), turn = (x) => ((x % (2 * Math.PI)) + 2 * Math.PI) % (2 * Math.PI), from = angle(outer[0]);
245
- const first = inner.map((p, j) => [turn(angle(p) - from + 1e-9), j]).sort((x, y) => x[0] - y[0])[0][1], ring = inner.map((_, j) => inner[(first + j) % inner.length]);
246
- const M = outer.length, N = ring.length, tris = [], next = (list, i, count) => (i + 1 >= count ? 2 * Math.PI : 0) + turn(angle(list[(i + 1) % count]) - from + 1e-9);
247
- // (a corner of the outline sees the ring only as far as its tangent: a face that would turn over waits for the next corner)
685
+ const angle = (p) => Math.atan2(p[1], p[0]),
686
+ turn = (x) => ((x % (2 * Math.PI)) + 2 * Math.PI) % (2 * Math.PI),
687
+ from = angle(outer[0]);
688
+ const first = inner.map((p, j) => [turn(angle(p) - from + 1e-9), j]).sort((x, y) => x[0] - y[0])[0][1],
689
+ ring = inner.map((_, j) => inner[(first + j) % inner.length]);
690
+ const M = outer.length,
691
+ N = ring.length,
692
+ tris = [],
693
+ next = (list, i, count) => (i + 1 >= count ? 2 * Math.PI : 0) + turn(angle(list[(i + 1) % count]) - from + 1e-9);
694
+ // (a corner of the outline sees the ring only as far as its tangent: a face that would turn over waits for the next
695
+ // corner)
248
696
  const turns = (p, q, r) => (q[0] - p[0]) * (r[1] - p[1]) - (q[1] - p[1]) * (r[0] - p[0]) > 1e-12;
249
697
  for (let i = 0, j = 0; i < M || j < N;) {
250
- if (j >= N || (i < M && (next(outer, i, M) <= next(ring, j, N) || !turns(outer[i % M], ring[(j + 1) % N], ring[j % N])))) { tris.push([outer[i % M], outer[(i + 1) % M], ring[j % N]]); i++; } else { tris.push([outer[i % M], ring[(j + 1) % N], ring[j % N]]); j++; }
698
+ if (
699
+ j >= N ||
700
+ (i < M && (next(outer, i, M) <= next(ring, j, N) || !turns(outer[i % M], ring[(j + 1) % N], ring[j % N])))
701
+ ) {
702
+ tris.push([outer[i % M], outer[(i + 1) % M], ring[j % N]]);
703
+ i++;
704
+ } else {
705
+ tris.push([outer[i % M], ring[(j + 1) % N], ring[j % N]]);
706
+ j++;
707
+ }
251
708
  }
252
709
  return up ? tris : tris.map(([p, q, r]) => [p, r, q]);
253
710
  }
@@ -255,11 +712,23 @@ function annulus(outer, inner, up) {
255
712
  // How the two ends of a thread are finished, as a function on the radius. A screw's thread is cut back by a cone at a
256
713
  // chamfered end. A cutter is flared at a face it opens on, and ends in a cone where it stops under a ceiling.
257
714
  function ends(t, { z0, z1, low, high, face0 = z0, face1 = z1 }) {
258
- const { lo, hi } = t.outline, k = t.leadIn / t.run || 1;
259
- if (!t.internal) return (r, z) => Math.min(r, low === 'chamfer' ? hi - t.leadIn + (z - z0) * k : Infinity, high === 'chamfer' ? hi - t.leadIn + (z1 - z) * k : Infinity);
715
+ const { lo, hi } = t.outline,
716
+ k = t.leadIn / t.run || 1;
717
+ if (!t.internal)
718
+ return (r, z) =>
719
+ Math.min(
720
+ r,
721
+ low === 'chamfer' ? hi - t.leadIn + (z - z0) * k : Infinity,
722
+ high === 'chamfer' ? hi - t.leadIn + (z1 - z) * k : Infinity,
723
+ );
260
724
  return (r, z) => {
261
- let x = Math.max(r, low === 'flare' ? lo + t.leadIn - (z - face0) * k : 0, high === 'flare' ? lo + t.leadIn - (face1 - z) * k : 0);
262
- if (low === 'point') x = Math.min(x, (z - z0) * k); if (high === 'point') x = Math.min(x, (z1 - z) * k);
725
+ let x = Math.max(
726
+ r,
727
+ low === 'flare' ? lo + t.leadIn - (z - face0) * k : 0,
728
+ high === 'flare' ? lo + t.leadIn - (face1 - z) * k : 0,
729
+ );
730
+ if (low === 'point') x = Math.min(x, (z - z0) * k);
731
+ if (high === 'point') x = Math.min(x, (z1 - z) * k);
263
732
  return x;
264
733
  };
265
734
  }
@@ -268,19 +737,33 @@ function ends(t, { z0, z1, low, high, face0 = z0, face1 = z1 }) {
268
737
  // the flat is true. toward: the angle the flat faces.
269
738
  function flatOf(t, n, toward) {
270
739
  if (t.flat == null || t.internal) return null;
271
- const step = (2 * Math.PI) / n, f = t.flat;
272
- return Object.assign((i, r, z) => {
273
- let d = (i * step - toward) % (2 * Math.PI); if (d > Math.PI) d -= 2 * Math.PI; if (d < -Math.PI) d += 2 * Math.PI; // the column's angle from the flat's middle
274
- if (!(Math.abs(d) < Math.PI / 2 && r * Math.cos(d) > f + 1e-9)) return null;
275
- const meets = Math.acos(f / r), last = meets - Math.abs(d) < step - 1e-9 && Math.abs(d) > 1e-9, angle = toward + (last ? Math.sign(d) * meets : d), out = last ? r : f / Math.cos(d);
276
- return [out * Math.cos(angle), out * Math.sin(angle), z];
277
- }, { depth: (p) => Math.min(f, p[0] * Math.cos(toward) + p[1] * Math.sin(toward)) }); // how far a point lies towards the flat, as far as the flat itself
740
+ const step = (2 * Math.PI) / n,
741
+ f = t.flat;
742
+ return Object.assign(
743
+ (i, r, z) => {
744
+ let d = (i * step - toward) % (2 * Math.PI);
745
+ if (d > Math.PI) d -= 2 * Math.PI;
746
+ if (d < -Math.PI) d += 2 * Math.PI; // the column's angle from the flat's middle
747
+ if (!(Math.abs(d) < Math.PI / 2 && r * Math.cos(d) > f + 1e-9)) return null;
748
+ const meets = Math.acos(f / r),
749
+ last = meets - Math.abs(d) < step - 1e-9 && Math.abs(d) > 1e-9,
750
+ angle = toward + (last ? Math.sign(d) * meets : d),
751
+ out = last ? r : f / Math.cos(d);
752
+ return [out * Math.cos(angle), out * Math.sin(angle), z];
753
+ },
754
+ { depth: (p) => Math.min(f, p[0] * Math.cos(toward) + p[1] * Math.sin(toward)) },
755
+ ); // how far a point lies towards the flat, as far as the flat itself
278
756
  }
279
757
  // A pointed roof over a threaded hole lying on its side, as a function on the radius: what lies under the roof is
280
758
  // pushed out to it. The roof leaves the circle of the roots at the overhang and rises to a point, as a teardrop's.
281
759
  function roofOf(t, n, toward) {
282
760
  if (t.flat == null || !t.internal) return (r) => r;
283
- const tangent = Math.PI / 2 - rad(t.overhang.limit), reach = Array.from({ length: n }, (_, i) => { let d = Math.abs((2 * Math.PI * i) / n - toward) % (2 * Math.PI); if (d > Math.PI) d = 2 * Math.PI - d; return d; });
761
+ const tangent = Math.PI / 2 - rad(t.overhang.limit),
762
+ reach = Array.from({ length: n }, (_, i) => {
763
+ let d = Math.abs((2 * Math.PI * i) / n - toward) % (2 * Math.PI);
764
+ if (d > Math.PI) d = 2 * Math.PI - d;
765
+ return d;
766
+ });
284
767
  return (r, z, i) => (reach[i] < tangent - 1e-9 ? Math.max(r, t.flat / Math.cos(tangent - reach[i])) : r);
285
768
  }
286
769
  const turnOf = (t) => (t.hand === 'left' ? -1 : 1);
@@ -288,14 +771,26 @@ const turnOf = (t) => (t.hand === 'left' ? -1 : 1);
288
771
  /**
289
772
  * A thread's surface between two heights, for a solid that carries a thread as part of itself (a threaded screw, a
290
773
  * threaded nut): its triangles and its two end rings, to be joined to the rest.
291
- * @param {Thread} t @param {{ z0: number, z1: number, low?: string, high?: string, inside?: boolean, caps?: boolean | 'low' | 'high' }} o
292
- * low, high: how each end is finished: chamfer or plain on a screw, flare on a nut; inside: faces turned inwards (a nut's bore);
293
- * caps: close both ends (the default), one, or neither
774
+ * @param {Thread} t @param {{ z0: number, z1: number, low?: string, high?: string, inside?: boolean,
775
+ * caps?: boolean | 'low' | 'high' }} o
776
+ * low, high: how each end is finished: chamfer or plain on a screw, flare on a nut; inside: faces turned inwards (a
777
+ * nut's bore); caps: close both ends (the default), one, or neither
294
778
  * @returns {{ tris: number[][][], lo: number[][], hi: number[][] }}
295
779
  */
296
780
  export function threadSurface(t, o) {
297
781
  const shape = ends(t, o);
298
- return sweep({ outline: t.outline, P: t.pitch, lead: t.lead, turn: turnOf(t), n: t.segments, z0: o.z0, z1: o.z1, shape, inside: !!o.inside, caps: o.caps ?? true });
782
+ return sweep({
783
+ outline: t.outline,
784
+ P: t.pitch,
785
+ lead: t.lead,
786
+ turn: turnOf(t),
787
+ n: t.segments,
788
+ z0: o.z0,
789
+ z1: o.z1,
790
+ shape,
791
+ inside: !!o.inside,
792
+ caps: o.caps ?? true,
793
+ });
299
794
  }
300
795
 
301
796
  /**
@@ -304,64 +799,222 @@ export function threadSurface(t, o) {
304
799
  * is long. Each end has its lead-in. With display: 'plain' it is a plain cylinder: a screw's at its crests, a hole's at
305
800
  * its crests too (the bore you would see).
306
801
  * @param {Fixing | string | object} spec as threadModel
307
- * @param {{ length: number, internal?: boolean, printer?: object, starts?: number, hand?: 'right' | 'left', pitch?: number, mate?: 'printed' | 'bought', gap?: number,
308
- * flanks?: 'printed' | 'standard', leadIn?: number, segments?: number, display?: 'thread' | 'plain', top?: '+z' | '-z', axis?: 'x' | 'y' | 'z', flat?: boolean, variant?: string, sets?: object }} o as threadModel
802
+ * @param {{ length: number, internal?: boolean, printer?: object, starts?: number, hand?: 'right' | 'left',
803
+ * pitch?: number, mate?: 'printed' | 'bought', gap?: number,
804
+ * flanks?: 'printed' | 'standard', leadIn?: number, segments?: number, display?: 'thread' | 'plain', top?: '+z' |
805
+ * '-z', axis?: 'x' | 'y' | 'z', flat?: boolean, variant?: string, sets?: object }} o as threadModel
309
806
  * @returns {object} a JSCAD geom3, with .model holding threadModel's numbers. Lying on its side (axis x or y) it runs
310
807
  * along that axis from the origin, its flat facing down (a screw's) or its roof up (a hole's)
311
808
  */
312
809
  export function thread(spec, o = {}) {
313
- if (o == null || typeof o !== 'object' || Array.isArray(o)) throw new Error(`thread: the second argument is its options ({ length: 20, internal: true }), not ${shown(o)}`);
810
+ if (o == null || typeof o !== 'object' || Array.isArray(o))
811
+ throw new Error(`thread: the second argument is its options ({ length: 20, internal: true }), not ${shown(o)}`);
314
812
  const t = threadModel(spec, { ...o, what: o.what ?? 'thread' });
315
- const g = t.internal ? cutter(t, { z0: -OUT, z1: t.length + OUT, face0: 0, face1: t.length, low: 'flare', high: 'flare', toward: Math.PI }) : screwThread(t);
813
+ const g = t.internal
814
+ ? cutter(t, {
815
+ z0: -OUT,
816
+ z1: t.length + OUT,
817
+ face0: 0,
818
+ face1: t.length,
819
+ low: 'flare',
820
+ high: 'flare',
821
+ toward: Math.PI,
822
+ })
823
+ : screwThread(t);
316
824
  if (t.axis === 'z') return Object.assign(g, { model: t });
317
- const laid = rotateY(Math.PI / 2, g); // z to x: the thread's own x (where a screw's flat is) turns down, its -x (a hole's roof) up
825
+ // z to x: the thread's own x (where a screw's flat is) turns down, its -x (a hole's roof) up
826
+ const laid = rotateY(Math.PI / 2, g);
318
827
  return Object.assign(t.axis === 'x' ? laid : rotateZ(Math.PI / 2, laid), { model: t });
319
828
  }
320
829
  function screwThread(t) {
321
- const { hi } = t.outline, L = t.length;
322
- if (t.display === 'plain') return lathe([[0, 0], [hi - t.leadIn, 0], [hi, t.run], [hi, L - t.run], [hi - t.leadIn, L], [0, L]], t.segments);
323
- return solid(sweep({ outline: t.outline, P: t.pitch, lead: t.lead, turn: turnOf(t), n: t.segments, z0: 0, z1: L, shape: ends(t, { z0: 0, z1: L, low: 'chamfer', high: 'chamfer' }), place: flatOf(t, t.segments, 0) }).tris);
830
+ const { hi } = t.outline,
831
+ L = t.length;
832
+ if (t.display === 'plain')
833
+ return lathe(
834
+ [
835
+ [0, 0],
836
+ [hi - t.leadIn, 0],
837
+ [hi, t.run],
838
+ [hi, L - t.run],
839
+ [hi - t.leadIn, L],
840
+ [0, L],
841
+ ],
842
+ t.segments,
843
+ );
844
+ return solid(
845
+ sweep({
846
+ outline: t.outline,
847
+ P: t.pitch,
848
+ lead: t.lead,
849
+ turn: turnOf(t),
850
+ n: t.segments,
851
+ z0: 0,
852
+ z1: L,
853
+ shape: ends(t, { z0: 0, z1: L, low: 'chamfer', high: 'chamfer' }),
854
+ place: flatOf(t, t.segments, 0),
855
+ }).tris,
856
+ );
324
857
  }
325
858
  // An internal thread's cutter between two heights of its own drawing. toward: where its roof points, lying on its side
326
859
  function cutter(t, o) {
327
- const { lo } = t.outline, end = ends(t, o), roof = roofOf(t, t.segments, o.toward ?? 0);
860
+ const { lo } = t.outline,
861
+ end = ends(t, o),
862
+ roof = roofOf(t, t.segments, o.toward ?? 0);
328
863
  if (t.display === 'plain') {
329
- const k = t.leadIn / t.run || 1, steps = [[0, o.z0]];
330
- if (o.low === 'flare') steps.push([lo + t.leadIn + (o.face0 - o.z0) * k, o.z0], [lo, o.face0 + t.run]); else if (o.low !== 'point') steps.push([lo, o.z0]);
331
- if (o.high === 'flare') steps.push([lo, o.face1 - t.run], [lo + t.leadIn + (o.z1 - o.face1) * k, o.z1]); else if (o.high !== 'point') steps.push([lo, o.z1]); else steps.push([lo, o.z1 - lo / k]);
864
+ const k = t.leadIn / t.run || 1,
865
+ steps = [[0, o.z0]];
866
+ if (o.low === 'flare') steps.push([lo + t.leadIn + (o.face0 - o.z0) * k, o.z0], [lo, o.face0 + t.run]);
867
+ else if (o.low !== 'point') steps.push([lo, o.z0]);
868
+ if (o.high === 'flare') steps.push([lo, o.face1 - t.run], [lo + t.leadIn + (o.z1 - o.face1) * k, o.z1]);
869
+ else if (o.high !== 'point') steps.push([lo, o.z1]);
870
+ else steps.push([lo, o.z1 - lo / k]);
332
871
  if (o.low === 'point') steps.splice(1, 0, [lo, o.z0 + lo / k]);
333
872
  return lathe([...steps, [0, o.z1]], t.segments);
334
873
  }
335
- return solid(sweep({ outline: t.outline, P: t.pitch, lead: t.lead, turn: turnOf(t), n: t.segments, z0: o.z0, z1: o.z1, shape: (r, z, i) => roof(end(r, z), z, i) }).tris);
874
+ return solid(
875
+ sweep({
876
+ outline: t.outline,
877
+ P: t.pitch,
878
+ lead: t.lead,
879
+ turn: turnOf(t),
880
+ n: t.segments,
881
+ z0: o.z0,
882
+ z1: o.z1,
883
+ shape: (r, z, i) => roof(end(r, z), z, i),
884
+ }).tris,
885
+ );
336
886
  }
337
887
 
338
888
  // ---------- a threaded hole ----------
339
889
  /**
340
890
  * A threaded hole, as numbers in a hole's shape: hole(m, { kind: 'thread' }) is this. The thread is modelled, so a
341
891
  * printed part takes a screw with no tap, no insert and no nut.
342
- * @param {string} what @param {Fixing} fx @param {object} o hole's options, and a thread's (mate, gap, flanks, hand, starts, segments, display, flat)
892
+ * @param {string} what @param {Fixing} fx @param {object} o hole's options, and a thread's (mate, gap, flanks, hand,
893
+ * starts, segments, display, flat)
343
894
  * @param {{ into: string, axis: 'x' | 'y' | 'z', across: boolean }} dir
344
895
  * @returns {object} a Hole, with thread holding threadModel's numbers
345
896
  */
346
897
  export function threadedHoleModel(what, fx, o, dir) {
347
- const pr = printerOf(what, o.printer), e = engagementOf(o.material), need = r3(ENGAGEMENT[e].value * fx.major), through = o.through ?? false;
898
+ const pr = printerOf(what, o.printer),
899
+ e = engagementOf(o.material),
900
+ need = r3(ENGAGEMENT[e].value * fx.major),
901
+ through = o.through ?? false;
348
902
  if (typeof through !== 'boolean') throw new Error(`${what}: through is true or false (got ${shown(o.through)})`);
349
- const depth = o.depth != null ? positive(what, 'depth', o.depth) : through && o.thickness != null ? positive(what, 'thickness', o.thickness) : need;
350
- if (o.lead != null && !(isNum(o.lead) && o.lead >= 0)) throw new Error(`${what}: lead is the lead-in chamfer, 0 mm or more (got ${shown(o.lead)})`);
351
- const t = threadModel(fx, { what, length: depth, internal: true, printer: o.printer, sets: o.sets, mate: o.mate, gap: o.gap, flanks: o.flanks, hand: o.hand, starts: o.starts, pitch: o.pitch, segments: o.segments, display: o.display,
352
- leadIn: o.lead, top: dir.into === '+z' ? '-z' : '+z', axis: dir.across ? dir.axis : 'z', flat: dir.across ? o.flat : undefined });
353
- const point = !through && dir.into === '+z' ? r3(t.outline.lo / (t.leadIn / t.run || 1)) : 0, out = [...t.findings];
354
- if (o.thickness != null) { positive(what, 'thickness', o.thickness); if (!through && depth + point > o.thickness - 1e-9) throw new Error(`${what}: a blind threaded hole ${mm(depth)} mm deep${point ? ` with its ${mm(point)} mm point` : ''} goes ${mm(r3(depth + point))} mm into a part ${mm(o.thickness)} mm thick there: it is deeper than the part, and would break out of its far face. Make it shallower, or the part thicker`); }
355
- if (depth < need - 1e-9) out.push(finding('warn', `${a(fx.thread)} thread ${mm(depth)} mm deep is short: engagement.${e} asks ${mm(need)} mm of thread`, 'hole.depth', { values: { depth, need } }));
356
- out.push(finding('info', `${a(fx.thread)} threaded hole drawn ${mm(t.drawn.major)} mm over its roots: it rests on ${cite(fx, 'major_diameter')} (${mm(fx.major)} mm), the ${t.mate === 'bought' ? 'whole' : 'half'} of ${t.rests.find((r) => /thread_gap$/.test(r.name))?.name ?? 'the gap given'} each side and ${pr.cite('hole_comp')} ${mm(t.comp)} mm across`, 'hole.drawn', { values: { diameter: t.drawn.major, nominal: fx.major, comp: t.comp }, refs: { thread: fx.thread, set: fx.set, rule: cite(fx, 'major_diameter'), kind: fx.figures.major_diameter.kind } }));
357
- if (point) out.push(finding('info', `going up from the bed, the hole ends in a point ${mm(point)} mm high past its thread, so its end needs no bridge`, 'hole.point', { values: { point } }));
358
- return { thread: fx.thread, kind: 'thread', diameter: t.drawn.major, nominal: fx.major, comp: t.comp, depth, through, into: dir.into, axis: dir.axis, teardrop: dir.across, lead: t.leadIn, point,
359
- basis: { rule: cite(fx, 'major_diameter'), kind: fx.figures.major_diameter.kind, source: fx.figures.major_diameter.source }, rests: [...t.rests, rest(`engagement.${e}`, ENGAGEMENT[e])], findings: out, threaded: t };
903
+ const depth =
904
+ o.depth != null
905
+ ? positive(what, 'depth', o.depth)
906
+ : through && o.thickness != null
907
+ ? positive(what, 'thickness', o.thickness)
908
+ : need;
909
+ if (o.lead != null && !(isNum(o.lead) && o.lead >= 0))
910
+ throw new Error(`${what}: lead is the lead-in chamfer, 0 mm or more (got ${shown(o.lead)})`);
911
+ const t = threadModel(fx, {
912
+ what,
913
+ length: depth,
914
+ internal: true,
915
+ printer: o.printer,
916
+ sets: o.sets,
917
+ mate: o.mate,
918
+ gap: o.gap,
919
+ flanks: o.flanks,
920
+ hand: o.hand,
921
+ starts: o.starts,
922
+ pitch: o.pitch,
923
+ segments: o.segments,
924
+ display: o.display,
925
+ leadIn: o.lead,
926
+ top: dir.into === '+z' ? '-z' : '+z',
927
+ axis: dir.across ? dir.axis : 'z',
928
+ flat: dir.across ? o.flat : undefined,
929
+ });
930
+ const point = !through && dir.into === '+z' ? r3(t.outline.lo / (t.leadIn / t.run || 1)) : 0,
931
+ out = [...t.findings];
932
+ if (o.thickness != null) {
933
+ positive(what, 'thickness', o.thickness);
934
+ if (!through && depth + point > o.thickness - 1e-9)
935
+ throw new Error(
936
+ `${what}: a blind threaded hole ${mm(depth)} mm deep` +
937
+ (point ? ` with its ${mm(point)} mm point` : '') +
938
+ ` goes ${mm(r3(depth + point))} mm into a part ${mm(o.thickness)} mm thick there: it is deeper than ` +
939
+ `the part, and would break out of its far face. Make it shallower, or the part thicker`,
940
+ );
941
+ }
942
+ if (depth < need - 1e-9)
943
+ out.push(
944
+ finding(
945
+ 'warn',
946
+ `${a(fx.thread)} thread ${mm(depth)} mm deep is short: engagement.${e} asks ${mm(need)} mm of thread`,
947
+ 'hole.depth',
948
+ { values: { depth, need } },
949
+ ),
950
+ );
951
+ out.push(
952
+ finding(
953
+ 'info',
954
+ `${a(fx.thread)} threaded hole drawn ${mm(t.drawn.major)} mm over its roots: it rests on ` +
955
+ `${cite(fx, 'major_diameter')} (${mm(fx.major)} mm), the ${t.mate === 'bought' ? 'whole' : 'half'} of ` +
956
+ `${t.rests.find((r) => /thread_gap$/.test(r.name))?.name ?? 'the gap given'} each side and ` +
957
+ `${pr.cite('hole_comp')} ${mm(t.comp)} mm across`,
958
+ 'hole.drawn',
959
+ {
960
+ values: { diameter: t.drawn.major, nominal: fx.major, comp: t.comp },
961
+ refs: {
962
+ thread: fx.thread,
963
+ set: fx.set,
964
+ rule: cite(fx, 'major_diameter'),
965
+ kind: fx.figures.major_diameter.kind,
966
+ },
967
+ },
968
+ ),
969
+ );
970
+ if (point)
971
+ out.push(
972
+ finding(
973
+ 'info',
974
+ `going up from the bed, the hole ends in a point ${mm(point)} mm high past its thread, so its end ` +
975
+ `needs no bridge`,
976
+ 'hole.point',
977
+ { values: { point } },
978
+ ),
979
+ );
980
+ return {
981
+ thread: fx.thread,
982
+ kind: 'thread',
983
+ diameter: t.drawn.major,
984
+ nominal: fx.major,
985
+ comp: t.comp,
986
+ depth,
987
+ through,
988
+ into: dir.into,
989
+ axis: dir.axis,
990
+ teardrop: dir.across,
991
+ lead: t.leadIn,
992
+ point,
993
+ basis: {
994
+ rule: cite(fx, 'major_diameter'),
995
+ kind: fx.figures.major_diameter.kind,
996
+ source: fx.figures.major_diameter.source,
997
+ },
998
+ rests: [...t.rests, rest(`engagement.${e}`, ENGAGEMENT[e])],
999
+ findings: out,
1000
+ threaded: t,
1001
+ };
360
1002
  }
361
- /** A threaded hole's cutter, from its model: drawn going down from the face, then turned to go along `into` from `at`. */
1003
+ /** A threaded hole's cutter, from its model: drawn going down from the face, then turned to go along `into` from
1004
+ * `at`. */
362
1005
  export function threadedHole(h, at) {
363
- const t = h.threaded, L = h.depth, up = h.into === '+z';
364
- const g = cutter(t, { z0: h.through ? -L - OUT : up ? -L - h.point : -L, z1: OUT, face0: -L, face1: 0, low: h.through ? 'flare' : up ? 'point' : 'flat', high: 'flare', toward: h.teardrop ? Math.atan2(UP[h.into][1], UP[h.into][0]) : 0 });
1006
+ const t = h.threaded,
1007
+ L = h.depth,
1008
+ up = h.into === '+z';
1009
+ const g = cutter(t, {
1010
+ z0: h.through ? -L - OUT : up ? -L - h.point : -L,
1011
+ z1: OUT,
1012
+ face0: -L,
1013
+ face1: 0,
1014
+ low: h.through ? 'flare' : up ? 'point' : 'flat',
1015
+ high: 'flare',
1016
+ toward: h.teardrop ? Math.atan2(UP[h.into][1], UP[h.into][0]) : 0,
1017
+ });
365
1018
  return Object.assign(along(g, h.into, at), { model: h });
366
1019
  }
367
1020
 
@@ -369,24 +1022,62 @@ export function threadedHole(h, at) {
369
1022
  /**
370
1023
  * A screw with its thread drawn, as one closed solid, in a screw's own place: the face its head seats on at z = 0, the
371
1024
  * thread down to z = -length. It prints standing on its head, so the model it is given is a thread with top: '-z'.
372
- * @param {{ head: string, length: number, headDiameter: number, headHeight: number, flats?: number, sink?: number }} s a screw's numbers @param {Thread} t
1025
+ * @param {{ head: string, length: number, headDiameter: number, headHeight: number, flats?: number, sink?: number }} s
1026
+ * a screw's numbers @param {Thread} t
373
1027
  * @returns {object} a JSCAD geom3
374
1028
  */
375
1029
  export function threadedScrew(s, t) {
376
- const n = t.segments, L = s.length, R = s.headDiameter / 2, k = s.headHeight, sink = s.head === 'countersunk' ? s.sink : 0;
1030
+ const n = t.segments,
1031
+ L = s.length,
1032
+ R = s.headDiameter / 2,
1033
+ k = s.headHeight,
1034
+ sink = s.head === 'countersunk' ? s.sink : 0;
377
1035
  if (s.head === 'set') return solid(threadSurface(t, { z0: -L, z1: 0, low: 'chamfer', high: 'chamfer' }).tris);
378
- const { tris: out, hi: neck } = threadSurface(t, { z0: -L, z1: -sink, low: 'chamfer', high: 'plain', caps: 'low' }); // the thread and its tip, open under the head
379
- const ring = (r, z) => Array.from({ length: n }, (_, i) => [r * Math.cos((2 * Math.PI * i) / n), r * Math.sin((2 * Math.PI * i) / n), z]);
380
- const band = (p, q) => { for (let i = 0; i < n; i++) { const j = (i + 1) % n; out.push([p[i], p[j], q[j]], [p[i], q[j], q[i]]); } };
381
- const lid = (p, z) => { for (let i = 0; i < n; i++) out.push([p[i], p[(i + 1) % n], [0, 0, z]]); };
1036
+ // the thread and its tip, open under the head
1037
+ const { tris: out, hi: neck } = threadSurface(t, { z0: -L, z1: -sink, low: 'chamfer', high: 'plain', caps: 'low' });
1038
+ const ring = (r, z) =>
1039
+ Array.from({ length: n }, (_, i) => [r * Math.cos((2 * Math.PI * i) / n), r * Math.sin((2 * Math.PI * i) / n), z]);
1040
+ const band = (p, q) => {
1041
+ for (let i = 0; i < n; i++) {
1042
+ const j = (i + 1) % n;
1043
+ out.push([p[i], p[j], q[j]], [p[i], q[j], q[i]]);
1044
+ }
1045
+ };
1046
+ const lid = (p, z) => {
1047
+ for (let i = 0; i < n; i++) out.push([p[i], p[(i + 1) % n], [0, 0, z]]);
1048
+ };
382
1049
  if (s.head === 'hex') {
383
- const hex = (z) => Array.from({ length: 6 }, (_, i) => [R * Math.cos((Math.PI * i) / 3), R * Math.sin((Math.PI * i) / 3), z]), lower = hex(0), upper = hex(k);
1050
+ const hex = (z) =>
1051
+ Array.from({ length: 6 }, (_, i) => [R * Math.cos((Math.PI * i) / 3), R * Math.sin((Math.PI * i) / 3), z]),
1052
+ lower = hex(0),
1053
+ upper = hex(k);
384
1054
  out.push(...annulus(lower, neck, false));
385
- for (let i = 0; i < 6; i++) { const j = (i + 1) % 6; out.push([lower[i], lower[j], upper[j]], [lower[i], upper[j], upper[i]], [upper[i], upper[j], [0, 0, k]]); }
386
- } else if (s.head === 'countersunk') { const rim = ring(R, 0); band(neck, rim); lid(rim, 0); }
387
- else {
388
- const steps = s.head === 'button' ? [[R, 0], [R, 0.3 * k], [0.55 * R, k]] : [[R, 0], [R, k]];
389
- let last = neck; for (const [r, z] of steps) { const next = ring(r, z); band(last, next); last = next; }
1055
+ for (let i = 0; i < 6; i++) {
1056
+ const j = (i + 1) % 6;
1057
+ out.push([lower[i], lower[j], upper[j]], [lower[i], upper[j], upper[i]], [upper[i], upper[j], [0, 0, k]]);
1058
+ }
1059
+ } else if (s.head === 'countersunk') {
1060
+ const rim = ring(R, 0);
1061
+ band(neck, rim);
1062
+ lid(rim, 0);
1063
+ } else {
1064
+ const steps =
1065
+ s.head === 'button'
1066
+ ? [
1067
+ [R, 0],
1068
+ [R, 0.3 * k],
1069
+ [0.55 * R, k],
1070
+ ]
1071
+ : [
1072
+ [R, 0],
1073
+ [R, k],
1074
+ ];
1075
+ let last = neck;
1076
+ for (const [r, z] of steps) {
1077
+ const next = ring(r, z);
1078
+ band(last, next);
1079
+ last = next;
1080
+ }
390
1081
  lid(last, k);
391
1082
  }
392
1083
  return solid(out);
@@ -395,17 +1086,43 @@ export function threadedScrew(s, t) {
395
1086
  /**
396
1087
  * A nut with its thread drawn, as one closed solid in a nut's own place: on z from 0 to its height, a hexagon's
397
1088
  * corner on x. It prints as it stands.
398
- * @param {{ kind: string, across: number, height: number }} nut a nut's numbers @param {Thread} t an internal thread as long as the nut is high
1089
+ * @param {{ kind: string, across: number, height: number }} nut a nut's numbers @param {Thread} t an internal thread as
1090
+ * long as the nut is high
399
1091
  * @returns {object} a JSCAD geom3
400
1092
  */
401
1093
  export function threadedNut(nut, t) {
402
- const sides = nut.kind === 'square' ? 4 : 6, R = nut.across / 2, h = nut.height;
403
- const outline = (z) => Array.from({ length: sides }, (_, i) => { const th = (2 * Math.PI * (i + (sides === 4 ? 0.5 : 0))) / sides; return [R * Math.cos(th), R * Math.sin(th), z]; });
404
- const bore = t.display === 'plain' ? null : threadSurface(t, { z0: 0, z1: h, low: 'flare', high: 'flare', inside: true, caps: false });
405
- const ringAt = (r, z) => Array.from({ length: t.segments }, (_, i) => [r * Math.cos((2 * Math.PI * i) / t.segments), r * Math.sin((2 * Math.PI * i) / t.segments), z]);
406
- const lower = outline(0), upper = outline(h), lo = bore ? bore.lo : ringAt(t.outline.lo, 0), hi = bore ? bore.hi : ringAt(t.outline.lo, h), out = bore ? bore.tris : [];
407
- if (!bore) for (let i = 0; i < t.segments; i++) { const j = (i + 1) % t.segments; out.push([lo[i], hi[j], lo[j]], [lo[i], hi[i], hi[j]]); }
1094
+ const sides = nut.kind === 'square' ? 4 : 6,
1095
+ R = nut.across / 2,
1096
+ h = nut.height;
1097
+ const outline = (z) =>
1098
+ Array.from({ length: sides }, (_, i) => {
1099
+ const th = (2 * Math.PI * (i + (sides === 4 ? 0.5 : 0))) / sides;
1100
+ return [R * Math.cos(th), R * Math.sin(th), z];
1101
+ });
1102
+ const bore =
1103
+ t.display === 'plain'
1104
+ ? null
1105
+ : threadSurface(t, { z0: 0, z1: h, low: 'flare', high: 'flare', inside: true, caps: false });
1106
+ const ringAt = (r, z) =>
1107
+ Array.from({ length: t.segments }, (_, i) => [
1108
+ r * Math.cos((2 * Math.PI * i) / t.segments),
1109
+ r * Math.sin((2 * Math.PI * i) / t.segments),
1110
+ z,
1111
+ ]);
1112
+ const lower = outline(0),
1113
+ upper = outline(h),
1114
+ lo = bore ? bore.lo : ringAt(t.outline.lo, 0),
1115
+ hi = bore ? bore.hi : ringAt(t.outline.lo, h),
1116
+ out = bore ? bore.tris : [];
1117
+ if (!bore)
1118
+ for (let i = 0; i < t.segments; i++) {
1119
+ const j = (i + 1) % t.segments;
1120
+ out.push([lo[i], hi[j], lo[j]], [lo[i], hi[i], hi[j]]);
1121
+ }
408
1122
  out.push(...annulus(lower, lo, false), ...annulus(upper, hi, true));
409
- for (let i = 0; i < sides; i++) { const j = (i + 1) % sides; out.push([lower[i], lower[j], upper[j]], [lower[i], upper[j], upper[i]]); }
1123
+ for (let i = 0; i < sides; i++) {
1124
+ const j = (i + 1) % sides;
1125
+ out.push([lower[i], lower[j], upper[j]], [lower[i], upper[j], upper[i]]);
1126
+ }
410
1127
  return solid(out);
411
1128
  }