@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/holes.d.mts CHANGED
@@ -17,35 +17,39 @@ export function pointOf(what: any, at?: number[]): number[];
17
17
  export function optionsOf(what: any, o: any, example: any): any;
18
18
  /**
19
19
  * A hole or a seat held to the part it is in: refused by name where it is deeper than the part is thick there.
20
- * @param {string} what @param {{ thickness?: number }} o thickness: the part's, along the hole, in mm @param {number} deep how deep the cut goes @param {string} says what the cut is
20
+ * @param {string} what @param {{ thickness?: number }} o thickness: the part's, along the hole, in
21
+ * mm @param {number} deep how deep the cut goes @param {string} says what the cut is
21
22
  * @returns {number | null} the thickness, where one was given
22
23
  */
23
24
  export function inPart(what: string, o: {
24
25
  thickness?: number;
25
26
  }, deep: number, says: string): number | null;
26
27
  /**
27
- * @typedef {{ thread: string, kind: string, diameter: number, nominal: number, comp: number, depth: number | null, through: boolean, into: string,
28
- * axis: 'x' | 'y' | 'z', teardrop: boolean, lead: number, point: number, basis: { rule: string, kind: string, source: string },
29
- * rests: object[], findings: object[] }} Hole
30
- * diameter: as drawn; nominal: the rule's figure; comp: the hole compensation added across it (0 where the figure is as drawn);
31
- * depth: null for a clearance hole not told the thickness it passes; teardrop: it lies on its side and gets a 45° roof;
32
- * lead: the lead-in chamfer at its mouth; point: the height of the 45° point a blind hole going up from the bed ends in;
33
- * basis: the rule the diameter rests on, and how far to trust it; rests: every figure used
28
+ * @typedef {{ thread: string, kind: string, diameter: number, nominal: number, comp: number, depth: number | null,
29
+ * through: boolean, into: string,
30
+ * axis: 'x' | 'y' | 'z', teardrop: boolean, lead: number, point: number, basis:
31
+ * { rule: string, kind: string, source: string }, rests: object[], findings: object[] }} Hole
32
+ * diameter: as drawn; nominal: the rule's figure; comp: the hole compensation added across it (0 where the figure is
33
+ * as drawn); depth: null for a clearance hole not told the thickness it passes; teardrop: it lies on its side and
34
+ * gets a 45° roof; lead: the lead-in chamfer at its mouth; point: the height of the 45° point a blind hole going up
35
+ * from the bed ends in; basis: the rule the diameter rests on, and how far to trust it; rests: every figure used
34
36
  */
35
37
  /**
36
38
  * A hole for a fixing, as numbers, sized by what it is for.
37
39
  * @param {Fixing | string} m a fixing's model, or its name ('M3')
38
- * @param {{ kind?: string, depth?: number, through?: boolean, thickness?: number, printer?: object, material?: string, axis?: 'x' | 'y' | 'z', into?: string, lead?: number, sets?: object,
39
- * mate?: 'printed' | 'bought', gap?: number, flanks?: 'printed' | 'standard', hand?: 'right' | 'left', starts?: number, pitch?: number, segments?: number, display?: 'thread' | 'plain', flat?: boolean }} [o]
40
- * kind: clearance (the normal hole a screw passes through, the default), close, loose, pilot (the screw forms its own
41
- * thread in the plastic), tap (the tap drill), insert (a heat-set insert; a pilot and an insert read the
42
- * printer's measured pilot_<set> or insert_<set>, as x1c.pilot_m3, before the thread's starting figure), or thread (a thread modelled to print, which
43
- * also takes threadModel's mate, gap, flanks, hand, starts, pitch, segments, display and flat);
44
- * depth: how deep, or the thickness passed through; through: out of the far face (the default for the clearances);
40
+ * @param {{ kind?: string, depth?: number, through?: boolean, thickness?: number, printer?: object, material?: string,
41
+ * axis?: 'x' | 'y' | 'z', into?: string, lead?: number, sets?: object,
42
+ * mate?: 'printed' | 'bought', gap?: number, flanks?: 'printed' | 'standard', hand?: 'right' | 'left', starts?:
43
+ * number, pitch?: number, segments?: number, display?: 'thread' | 'plain', flat?: boolean }} [o] kind: clearance (the
44
+ * normal hole a screw passes through, the default), close, loose, pilot (the screw forms its own thread in the
45
+ * plastic), tap (the tap drill), insert (a heat-set insert; a pilot and an insert read the printer's measured
46
+ * pilot_<set> or insert_<set>, as x1c.pilot_m3, before the thread's starting figure), or thread (a thread modelled to
47
+ * print, which also takes threadModel's mate, gap, flanks, hand, starts, pitch, segments, display and flat); depth:
48
+ * how deep, or the thickness passed through; through: out of the far face (the default for the clearances);
45
49
  * thickness: the part's, along the hole: a hole through it is that deep, and a blind one deeper than it is refused;
46
50
  * printer: the printer's rule set, or its values (default the kit's X1C); material: the plastic, for a pilot ('PLA',
47
- * 'PETG'), or what a tapped hole is in ('aluminium'); axis: z for a hole standing up, x or y for one on its side
48
- * (or into, a direction: '+x', '-z'); lead: the lead-in chamfer; sets: the workspace's rule sets, where m is a name
51
+ * 'PETG'), or what a tapped hole is in ('aluminium'); axis: z for a hole standing up, x or y for one on its side (or
52
+ * into, a direction: '+x', '-z'); lead: the lead-in chamfer; sets: the workspace's rule sets, where m is a name
49
53
  * @returns {Hole}
50
54
  */
51
55
  export function holeModel(m: Fixing | string, o?: {
@@ -73,9 +77,11 @@ export function holeModel(m: Fixing | string, o?: {
73
77
  * A hole for a fixing, to subtract: round standing up, a teardrop lying on its side (through @rulecad/shapes'
74
78
  * teardropHole), with its lead-in where it has one, and a 45° point where it ends going up from the bed.
75
79
  * @param {Fixing | string} m
76
- * @param {{ kind?: string, depth?: number, through?: boolean, thickness?: number, printer?: object, material?: string, axis?: 'x' | 'y' | 'z', into?: string, lead?: number, sets?: object, at?: number[],
77
- * mate?: 'printed' | 'bought', gap?: number, flanks?: 'printed' | 'standard', hand?: 'right' | 'left', starts?: number, pitch?: number, segments?: number, display?: 'thread' | 'plain', flat?: boolean }} [o]
78
- * as holeModel, and at: the point on the face where the hole starts. A clearance hole needs depth: the thickness it passes
80
+ * @param {{ kind?: string, depth?: number, through?: boolean, thickness?: number, printer?: object, material?: string,
81
+ * axis?: 'x' | 'y' | 'z', into?: string, lead?: number, sets?: object, at?: number[],
82
+ * mate?: 'printed' | 'bought', gap?: number, flanks?: 'printed' | 'standard', hand?: 'right' | 'left', starts?:
83
+ * number, pitch?: number, segments?: number, display?: 'thread' | 'plain', flat?: boolean }} [o] as holeModel, and
84
+ * at: the point on the face where the hole starts. A clearance hole needs depth: the thickness it passes
79
85
  * @returns {object} a JSCAD geom3 to subtract, with .model holding holeModel's numbers
80
86
  */
81
87
  export function hole(m: Fixing | string, o?: {
@@ -100,14 +106,15 @@ export function hole(m: Fixing | string, o?: {
100
106
  display?: "thread" | "plain";
101
107
  flat?: boolean;
102
108
  }): object;
103
- /** The kinds of hole: what each is for. `thread` is a thread modelled to print (threadModel), for a screw of about M6 or more. */
109
+ /** The kinds of hole: what each is for. `thread` is a thread modelled to print (threadModel), for a screw of about M6
110
+ * or more. */
104
111
  export const HOLE_KINDS: string[];
105
112
  export function said(into: any): any;
106
113
  /**
107
- * diameter: as drawn; nominal: the rule's figure; comp: the hole compensation added across it (0 where the figure is as drawn);
108
- * depth: null for a clearance hole not told the thickness it passes; teardrop: it lies on its side and gets a 45° roof;
109
- * lead: the lead-in chamfer at its mouth; point: the height of the 45° point a blind hole going up from the bed ends in;
110
- * basis: the rule the diameter rests on, and how far to trust it; rests: every figure used
114
+ * diameter: as drawn; nominal: the rule's figure; comp: the hole compensation added across it (0 where the figure is
115
+ * as drawn); depth: null for a clearance hole not told the thickness it passes; teardrop: it lies on its side and
116
+ * gets a 45° roof; lead: the lead-in chamfer at its mouth; point: the height of the 45° point a blind hole going up
117
+ * from the bed ends in; basis: the rule the diameter rests on, and how far to trust it; rests: every figure used
111
118
  */
112
119
  export type Hole = {
113
120
  thread: string;
package/holes.mjs CHANGED
@@ -3,7 +3,23 @@
3
3
  // with what they rest on; hole gives the solid to subtract, which starts at a point on a face (at) and goes into the
4
4
  // part along a direction (into), as the features of @rulecad/shapes do.
5
5
  import { teardropHole } from '@rulecad/shapes';
6
- import { fixingOf, printerOf, figure, cite, rest, finding, positive, oneOf, isNum, shown, mm, r3, a, ENGAGEMENT, engagementOf } from './model.mjs';
6
+ import {
7
+ fixingOf,
8
+ printerOf,
9
+ figure,
10
+ cite,
11
+ rest,
12
+ finding,
13
+ positive,
14
+ oneOf,
15
+ isNum,
16
+ shown,
17
+ mm,
18
+ r3,
19
+ a,
20
+ ENGAGEMENT,
21
+ engagementOf,
22
+ } from './model.mjs';
7
23
  import { along, bore, DIRECTIONS } from './draw.mjs';
8
24
  import { threadedHoleModel, threadedHole } from './threads.mjs';
9
25
 
@@ -20,9 +36,10 @@ const HOLES = {
20
36
  loose: { figure: 'clearance_loose', printed: true, blind: false, says: 'loose clearance hole' },
21
37
  tap: { figure: 'tap_drill', printed: true, blind: true, says: 'hole to tap' },
22
38
  pilot: { figure: 'pilot', printed: false, blind: true, says: 'pilot' },
23
- insert: { figure: 'insert_hole', printed: false, blind: true, says: 'insert hole' }
39
+ insert: { figure: 'insert_hole', printed: false, blind: true, says: 'insert hole' },
24
40
  };
25
- /** The kinds of hole: what each is for. `thread` is a thread modelled to print (threadModel), for a screw of about M6 or more. */
41
+ /** The kinds of hole: what each is for. `thread` is a thread modelled to print (threadModel), for a screw of about M6
42
+ * or more. */
26
43
  export const HOLE_KINDS = [...Object.keys(HOLES), 'thread'];
27
44
 
28
45
  /**
@@ -33,126 +50,291 @@ export const HOLE_KINDS = [...Object.keys(HOLES), 'thread'];
33
50
  export function directionOf(what, { into, axis } = {}, fallback = '-z') {
34
51
  if (into != null) oneOf(what, 'into', into, DIRECTIONS);
35
52
  if (axis != null) oneOf(what, 'axis', axis, ['x', 'y', 'z']);
36
- if (into != null && axis != null && into[1] !== axis) throw new Error(`${what}: into ${into} runs along ${into[1]} and axis says ${axis}: give one, or make them agree`);
53
+ if (into != null && axis != null && into[1] !== axis)
54
+ throw new Error(`${what}: into ${into} runs along ${into[1]} and axis says ${axis}: give one, or make them agree`);
37
55
  const dir = into ?? (axis == null ? fallback : axis === 'z' ? '-z' : `+${axis}`);
38
56
  return { into: dir, axis: /** @type {'x' | 'y' | 'z'} */ (dir[1]), across: dir[1] !== 'z' };
39
57
  }
40
58
  /** A point [x, y, z] in mm, refused by name where it is not one. */
41
59
  export function pointOf(what, at = [0, 0, 0]) {
42
- if (!Array.isArray(at) || at.length !== 3 || !at.every(isNum)) throw new Error(`${what}: at is a point on the part's face, [x, y, z] in mm (got ${shown(at)})`);
60
+ if (!Array.isArray(at) || at.length !== 3 || !at.every(isNum))
61
+ throw new Error(`${what}: at is a point on the part's face, [x, y, z] in mm (got ${shown(at)})`);
43
62
  return at;
44
63
  }
45
64
  /** The options object every function here takes, refused where it is not one. */
46
65
  export function optionsOf(what, o, example) {
47
- if (o == null || typeof o !== 'object' || Array.isArray(o)) throw new Error(`${what}: the second argument is its options (${example}), not ${shown(o)}`);
66
+ if (o == null || typeof o !== 'object' || Array.isArray(o))
67
+ throw new Error(`${what}: the second argument is its options (${example}), not ${shown(o)}`);
48
68
  return o;
49
69
  }
50
70
  /**
51
71
  * A hole or a seat held to the part it is in: refused by name where it is deeper than the part is thick there.
52
- * @param {string} what @param {{ thickness?: number }} o thickness: the part's, along the hole, in mm @param {number} deep how deep the cut goes @param {string} says what the cut is
72
+ * @param {string} what @param {{ thickness?: number }} o thickness: the part's, along the hole, in
73
+ * mm @param {number} deep how deep the cut goes @param {string} says what the cut is
53
74
  * @returns {number | null} the thickness, where one was given
54
75
  */
55
76
  export function inPart(what, o, deep, says) {
56
77
  if (o.thickness == null) return null;
57
78
  positive(what, 'thickness', o.thickness);
58
- if (deep > o.thickness - 1e-9) throw new Error(`${what}: ${says} goes ${mm(deep)} 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`);
79
+ if (deep > o.thickness - 1e-9)
80
+ throw new Error(
81
+ `${what}: ${says} goes ${mm(deep)} mm into a part ${mm(o.thickness)} mm thick there: it is deeper than ` +
82
+ `the part, and would break out of its far face. Make it shallower, or the part thicker`,
83
+ );
59
84
  return o.thickness;
60
85
  }
61
- const HOW = { '-z': 'going down from a top face', '+z': 'going up from the bed', '+x': 'lying along x', '-x': 'lying along x', '+y': 'lying along y', '-y': 'lying along y' };
86
+ const HOW = {
87
+ '-z': 'going down from a top face',
88
+ '+z': 'going up from the bed',
89
+ '+x': 'lying along x',
90
+ '-x': 'lying along x',
91
+ '+y': 'lying along y',
92
+ '-y': 'lying along y',
93
+ };
62
94
  /** How a direction is said in a finding. */
63
95
  export const said = (into) => HOW[into];
64
96
 
65
97
  /**
66
- * @typedef {{ thread: string, kind: string, diameter: number, nominal: number, comp: number, depth: number | null, through: boolean, into: string,
67
- * axis: 'x' | 'y' | 'z', teardrop: boolean, lead: number, point: number, basis: { rule: string, kind: string, source: string },
68
- * rests: object[], findings: object[] }} Hole
69
- * diameter: as drawn; nominal: the rule's figure; comp: the hole compensation added across it (0 where the figure is as drawn);
70
- * depth: null for a clearance hole not told the thickness it passes; teardrop: it lies on its side and gets a 45° roof;
71
- * lead: the lead-in chamfer at its mouth; point: the height of the 45° point a blind hole going up from the bed ends in;
72
- * basis: the rule the diameter rests on, and how far to trust it; rests: every figure used
98
+ * @typedef {{ thread: string, kind: string, diameter: number, nominal: number, comp: number, depth: number | null,
99
+ * through: boolean, into: string,
100
+ * axis: 'x' | 'y' | 'z', teardrop: boolean, lead: number, point: number, basis:
101
+ * { rule: string, kind: string, source: string }, rests: object[], findings: object[] }} Hole
102
+ * diameter: as drawn; nominal: the rule's figure; comp: the hole compensation added across it (0 where the figure is
103
+ * as drawn); depth: null for a clearance hole not told the thickness it passes; teardrop: it lies on its side and
104
+ * gets a 45° roof; lead: the lead-in chamfer at its mouth; point: the height of the 45° point a blind hole going up
105
+ * from the bed ends in; basis: the rule the diameter rests on, and how far to trust it; rests: every figure used
73
106
  */
74
107
 
75
108
  /**
76
109
  * A hole for a fixing, as numbers, sized by what it is for.
77
110
  * @param {Fixing | string} m a fixing's model, or its name ('M3')
78
- * @param {{ kind?: string, depth?: number, through?: boolean, thickness?: number, printer?: object, material?: string, axis?: 'x' | 'y' | 'z', into?: string, lead?: number, sets?: object,
79
- * mate?: 'printed' | 'bought', gap?: number, flanks?: 'printed' | 'standard', hand?: 'right' | 'left', starts?: number, pitch?: number, segments?: number, display?: 'thread' | 'plain', flat?: boolean }} [o]
80
- * kind: clearance (the normal hole a screw passes through, the default), close, loose, pilot (the screw forms its own
81
- * thread in the plastic), tap (the tap drill), insert (a heat-set insert; a pilot and an insert read the
82
- * printer's measured pilot_<set> or insert_<set>, as x1c.pilot_m3, before the thread's starting figure), or thread (a thread modelled to print, which
83
- * also takes threadModel's mate, gap, flanks, hand, starts, pitch, segments, display and flat);
84
- * depth: how deep, or the thickness passed through; through: out of the far face (the default for the clearances);
111
+ * @param {{ kind?: string, depth?: number, through?: boolean, thickness?: number, printer?: object, material?: string,
112
+ * axis?: 'x' | 'y' | 'z', into?: string, lead?: number, sets?: object,
113
+ * mate?: 'printed' | 'bought', gap?: number, flanks?: 'printed' | 'standard', hand?: 'right' | 'left', starts?:
114
+ * number, pitch?: number, segments?: number, display?: 'thread' | 'plain', flat?: boolean }} [o] kind: clearance (the
115
+ * normal hole a screw passes through, the default), close, loose, pilot (the screw forms its own thread in the
116
+ * plastic), tap (the tap drill), insert (a heat-set insert; a pilot and an insert read the printer's measured
117
+ * pilot_<set> or insert_<set>, as x1c.pilot_m3, before the thread's starting figure), or thread (a thread modelled to
118
+ * print, which also takes threadModel's mate, gap, flanks, hand, starts, pitch, segments, display and flat); depth:
119
+ * how deep, or the thickness passed through; through: out of the far face (the default for the clearances);
85
120
  * thickness: the part's, along the hole: a hole through it is that deep, and a blind one deeper than it is refused;
86
121
  * printer: the printer's rule set, or its values (default the kit's X1C); material: the plastic, for a pilot ('PLA',
87
- * 'PETG'), or what a tapped hole is in ('aluminium'); axis: z for a hole standing up, x or y for one on its side
88
- * (or into, a direction: '+x', '-z'); lead: the lead-in chamfer; sets: the workspace's rule sets, where m is a name
122
+ * 'PETG'), or what a tapped hole is in ('aluminium'); axis: z for a hole standing up, x or y for one on its side (or
123
+ * into, a direction: '+x', '-z'); lead: the lead-in chamfer; sets: the workspace's rule sets, where m is a name
89
124
  * @returns {Hole}
90
125
  */
91
126
  export function holeModel(m, o = {}) {
92
127
  const what = 'hole';
93
- optionsOf(what, o, '{ kind: \'pilot\', depth: 8 }');
94
- const fx = fixingOf(what, m, o), kind = oneOf(what, 'kind', o.kind ?? 'clearance', HOLE_KINDS);
128
+ optionsOf(what, o, "{ kind: 'pilot', depth: 8 }");
129
+ const fx = fixingOf(what, m, o),
130
+ kind = oneOf(what, 'kind', o.kind ?? 'clearance', HOLE_KINDS);
95
131
  if (kind === 'thread') return threadedHoleModel(what, fx, o, directionOf(what, o));
96
- const spec = HOLES[kind], pr = printerOf(what, o.printer), dir = directionOf(what, o), out = [], rests = [];
97
- // The figure the diameter rests on: for a pilot or an insert, the printer's measured rule for this thread (and plastic) before the thread's starting figure
132
+ const spec = HOLES[kind],
133
+ pr = printerOf(what, o.printer),
134
+ dir = directionOf(what, o),
135
+ out = [],
136
+ rests = [];
137
+ // The figure the diameter rests on: for a pilot or an insert, the printer's measured rule for this thread (and
138
+ // plastic) before the thread's starting figure
98
139
  let basis = null;
99
- const plastic = o.material == null ? null : String(o.material).toLowerCase().replace(/[^a-z0-9]/g, '');
100
- if (kind === 'pilot' || kind === 'insert') basis = [plastic && `${kind}_${fx.set}_${plastic}`, `${kind}_${fx.set}`].filter(Boolean).map((k) => pr.figure(k)).find(Boolean) ?? null;
140
+ const plastic =
141
+ o.material == null
142
+ ? null
143
+ : String(o.material)
144
+ .toLowerCase()
145
+ .replace(/[^a-z0-9]/g, '');
146
+ if (kind === 'pilot' || kind === 'insert')
147
+ basis =
148
+ [plastic && `${kind}_${fx.set}_${plastic}`, `${kind}_${fx.set}`]
149
+ .filter(Boolean)
150
+ .map((k) => pr.figure(k))
151
+ .find(Boolean) ?? null;
101
152
  const own = !!basis;
102
153
  if (!basis) {
103
- if (!fx.figures[spec.figure]) throw new Error(`${what}: ${fx.thread} has no ${spec.figure} in its rule set (${fx.set}), so no ${kind} hole: it has figures for ${Object.keys(HOLES).filter((k) => fx.figures[HOLES[k].figure]).join(', ') || 'none'}`);
154
+ if (!fx.figures[spec.figure])
155
+ throw new Error(
156
+ `${what}: ${fx.thread} has no ${spec.figure} in its rule set (${fx.set}), so no ${kind} hole: it has ` +
157
+ `figures for ` +
158
+ `${
159
+ Object.keys(HOLES)
160
+ .filter((k) => fx.figures[HOLES[k].figure])
161
+ .join(', ') || 'none'
162
+ }`,
163
+ );
104
164
  basis = { ...fx.figures[spec.figure], name: cite(fx, spec.figure) };
105
165
  }
106
- if (!(isNum(basis.value) && basis.value > 0)) throw new Error(`${what}: ${basis.name} is a diameter above 0 mm (got ${shown(basis.value)})`);
107
- const nominal = basis.value, comp = spec.printed ? pr.n('hole_comp') : 0, diameter = r3(nominal + comp);
166
+ if (!(isNum(basis.value) && basis.value > 0))
167
+ throw new Error(`${what}: ${basis.name} is a diameter above 0 mm (got ${shown(basis.value)})`);
168
+ const nominal = basis.value,
169
+ comp = spec.printed ? pr.n('hole_comp') : 0,
170
+ diameter = r3(nominal + comp);
108
171
  rests.push(rest(basis.name, basis));
109
172
  if (comp) rests.push(pr.rest('hole_comp'));
110
- const trust = { measured: 'a measured rule', spec: 'a standard\'s figure', community: 'a community figure', estimate: 'an estimate', given: 'a figure given by hand', default: 'a default', derived: 'a derived figure' }[basis.kind] ?? `a ${basis.kind} figure`;
111
- let text = `${a(fx.thread)} ${spec.says} drawn ${mm(diameter)} mm: it rests on ${basis.name} (${mm(nominal)} mm), ${trust}`;
112
- text += spec.printed ? `, plus ${pr.cite('hole_comp')} ${mm(comp)} mm across, since a printed hole comes out small` : ', as drawn (the figure is already sized for printing, so no hole compensation is added)';
113
- if ((kind === 'pilot' || kind === 'insert') && !own) text += `. That is the thread's starting figure: ${pr.name} has no measured ${kind}_${fx.set}, so measure it on this printer`;
114
- out.push(finding('info', text, 'hole.drawn', { values: { diameter, nominal, comp }, refs: { thread: fx.thread, set: fx.set, rule: basis.name, kind: basis.kind } }));
115
- if (comp && pr.rest('hole_comp').borrowed) out.push(finding('info', `${pr.name} has no hole_comp: the X1C's ${mm(comp)} mm is used`, 'hole.printer', { values: { comp } }));
173
+ const trust =
174
+ {
175
+ measured: 'a measured rule',
176
+ spec: "a standard's figure",
177
+ community: 'a community figure',
178
+ estimate: 'an estimate',
179
+ given: 'a figure given by hand',
180
+ default: 'a default',
181
+ derived: 'a derived figure',
182
+ }[basis.kind] ?? `a ${basis.kind} figure`;
183
+ let text =
184
+ `${a(fx.thread)} ${spec.says} drawn ${mm(diameter)} mm: it rests on ${basis.name} (${mm(nominal)} mm), ` +
185
+ `${trust}`;
186
+ text += spec.printed
187
+ ? `, plus ${pr.cite('hole_comp')} ${mm(comp)} mm across, since a printed hole comes out small`
188
+ : ', as drawn (the figure is already sized for printing, so no hole compensation is added)';
189
+ if ((kind === 'pilot' || kind === 'insert') && !own)
190
+ text +=
191
+ `. That is the thread's starting figure: ${pr.name} has no measured ${kind}_${fx.set}, so measure it on ` +
192
+ `this printer`;
193
+ out.push(
194
+ finding('info', text, 'hole.drawn', {
195
+ values: { diameter, nominal, comp },
196
+ refs: { thread: fx.thread, set: fx.set, rule: basis.name, kind: basis.kind },
197
+ }),
198
+ );
199
+ if (comp && pr.rest('hole_comp').borrowed)
200
+ out.push(
201
+ finding('info', `${pr.name} has no hole_comp: the X1C's ${mm(comp)} mm is used`, 'hole.printer', {
202
+ values: { comp },
203
+ }),
204
+ );
116
205
  // a figure that names one plastic, asked for another
117
- if (kind === 'pilot' && plastic && typeof basis.rule === 'string' && !new RegExp(`\\b${plastic}\\b`, 'i').test(basis.rule) && !basis.name.endsWith(`_${plastic}`)) out.push(finding('warn', `${basis.name} does not name ${o.material}: the pilot was sized in another plastic, so try it before trusting it`, 'hole.material', { refs: { rule: basis.name, material: o.material } }));
206
+ if (
207
+ kind === 'pilot' &&
208
+ plastic &&
209
+ typeof basis.rule === 'string' &&
210
+ !new RegExp(`\\b${plastic}\\b`, 'i').test(basis.rule) &&
211
+ !basis.name.endsWith(`_${plastic}`)
212
+ )
213
+ out.push(
214
+ finding(
215
+ 'warn',
216
+ `${basis.name} does not name ${o.material}: the pilot was sized in another plastic, so try it before ` +
217
+ `trusting it`,
218
+ 'hole.material',
219
+ { refs: { rule: basis.name, material: o.material } },
220
+ ),
221
+ );
118
222
 
119
223
  const through = o.through ?? !spec.blind;
120
224
  if (typeof through !== 'boolean') throw new Error(`${what}: through is true or false (got ${shown(o.through)})`);
121
- let depth = o.depth ?? null, need = null;
122
- const depthFrom = (n) => { rests.push(rest(cite(fx, n), fx.figures[n])); return figure(what, fx, n); };
225
+ let depth = o.depth ?? null,
226
+ need = null;
227
+ const depthFrom = (n) => {
228
+ rests.push(rest(cite(fx, n), fx.figures[n]));
229
+ return figure(what, fx, n);
230
+ };
123
231
  if (kind === 'insert') need = depthFrom(through ? 'insert_length' : 'insert_depth');
124
232
  else if (kind === 'pilot' && fx.figures.pilot_depth) need = depthFrom('pilot_depth');
125
- else if (kind === 'pilot' || kind === 'tap') { const e = engagementOf(kind === 'pilot' ? 'plastic' : o.material); rests.push(rest(`engagement.${e}`, ENGAGEMENT[e])); need = r3(ENGAGEMENT[e].value * fx.major); }
126
- if (depth != null) positive(what, 'depth', depth); else depth = through && o.thickness != null ? positive(what, 'thickness', o.thickness) : need;
127
- if (need != null && depth < need - 1e-9) out.push(finding('warn', `${a(fx.thread)} ${spec.says} ${mm(depth)} mm deep is short: ${rests.at(-1).name} asks ${mm(need)} mm${kind === 'insert' && !through ? ' of blind hole' : ' of thread'}`, 'hole.depth', { values: { depth, need } }));
233
+ else if (kind === 'pilot' || kind === 'tap') {
234
+ const e = engagementOf(kind === 'pilot' ? 'plastic' : o.material);
235
+ rests.push(rest(`engagement.${e}`, ENGAGEMENT[e]));
236
+ need = r3(ENGAGEMENT[e].value * fx.major);
237
+ }
238
+ if (depth != null) positive(what, 'depth', depth);
239
+ else depth = through && o.thickness != null ? positive(what, 'thickness', o.thickness) : need;
240
+ if (need != null && depth < need - 1e-9)
241
+ out.push(
242
+ finding(
243
+ 'warn',
244
+ `${a(fx.thread)} ${spec.says} ${mm(depth)} mm deep is short: ${rests.at(-1).name} asks ${mm(need)} mm` +
245
+ (kind === 'insert' && !through ? ' of blind hole' : ' of thread'),
246
+ 'hole.depth',
247
+ { values: { depth, need } },
248
+ ),
249
+ );
128
250
 
129
- 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)})`);
130
- if (o.lead > 0 && dir.across) throw new Error(`${what}: a lead-in on a hole lying on its side would overhang at its top: leave lead out (into ${dir.into})`);
251
+ if (o.lead != null && !(isNum(o.lead) && o.lead >= 0))
252
+ throw new Error(`${what}: lead is the lead-in chamfer, 0 mm or more (got ${shown(o.lead)})`);
253
+ if (o.lead > 0 && dir.across)
254
+ throw new Error(
255
+ `${what}: a lead-in on a hole lying on its side would overhang at its top: leave lead out (into ${dir.into})`,
256
+ );
131
257
  let lead = o.lead ?? (spec.blind && !dir.across ? pr.n('chamfer') : 0);
132
258
  if (lead && depth != null) lead = Math.min(lead, depth / 2);
133
259
  const point = !through && dir.into === '+z' ? r3(diameter / 2) : 0;
134
- if (!through && depth != null) inPart(what, o, depth + point, `a blind ${spec.says} ${mm(depth)} mm deep${point ? ` with its ${mm(point)} mm point` : ''}`);
135
- out.push(finding('pass', dir.across ? `${said(dir.into)}, the hole is a teardrop: a 45° roof, so it prints with no support`
136
- : point ? `${said(dir.into)}, the hole ends in a 45° point ${mm(point)} mm high, so its end needs no bridge` : `${said(dir.into)}, a round hole prints as drawn`, 'hole.printable', { values: { into: dir.into } }));
137
- if (kind === 'pilot' && dir.across) out.push(finding('warn', `a pilot lying on its side has a teardrop's roof, and ${basis.name} is for a hole standing upright: the screw has less to bite, so try it`, 'hole.side'));
138
- return { thread: fx.thread, kind, diameter, nominal, comp, depth, through, into: dir.into, axis: dir.axis, teardrop: dir.across, lead: r3(lead), point,
139
- basis: { rule: basis.name, kind: basis.kind, source: basis.source }, rests, findings: out };
260
+ if (!through && depth != null)
261
+ inPart(
262
+ what,
263
+ o,
264
+ depth + point,
265
+ `a blind ${spec.says} ${mm(depth)} mm deep${point ? ` with its ${mm(point)} mm point` : ''}`,
266
+ );
267
+ out.push(
268
+ finding(
269
+ 'pass',
270
+ dir.across
271
+ ? `${said(dir.into)}, the hole is a teardrop: a 45° roof, so it prints with no support`
272
+ : point
273
+ ? `${said(dir.into)}, the hole ends in a 45° point ${mm(point)} mm high, so its end needs no bridge`
274
+ : `${said(dir.into)}, a round hole prints as drawn`,
275
+ 'hole.printable',
276
+ { values: { into: dir.into } },
277
+ ),
278
+ );
279
+ if (kind === 'pilot' && dir.across)
280
+ out.push(
281
+ finding(
282
+ 'warn',
283
+ `a pilot lying on its side has a teardrop's roof, and ${basis.name} is for a hole standing upright: ` +
284
+ `the screw has less to bite, so try it`,
285
+ 'hole.side',
286
+ ),
287
+ );
288
+ return {
289
+ thread: fx.thread,
290
+ kind,
291
+ diameter,
292
+ nominal,
293
+ comp,
294
+ depth,
295
+ through,
296
+ into: dir.into,
297
+ axis: dir.axis,
298
+ teardrop: dir.across,
299
+ lead: r3(lead),
300
+ point,
301
+ basis: { rule: basis.name, kind: basis.kind, source: basis.source },
302
+ rests,
303
+ findings: out,
304
+ };
140
305
  }
141
306
 
142
307
  /**
143
308
  * A hole for a fixing, to subtract: round standing up, a teardrop lying on its side (through @rulecad/shapes'
144
309
  * teardropHole), with its lead-in where it has one, and a 45° point where it ends going up from the bed.
145
310
  * @param {Fixing | string} m
146
- * @param {{ kind?: string, depth?: number, through?: boolean, thickness?: number, printer?: object, material?: string, axis?: 'x' | 'y' | 'z', into?: string, lead?: number, sets?: object, at?: number[],
147
- * mate?: 'printed' | 'bought', gap?: number, flanks?: 'printed' | 'standard', hand?: 'right' | 'left', starts?: number, pitch?: number, segments?: number, display?: 'thread' | 'plain', flat?: boolean }} [o]
148
- * as holeModel, and at: the point on the face where the hole starts. A clearance hole needs depth: the thickness it passes
311
+ * @param {{ kind?: string, depth?: number, through?: boolean, thickness?: number, printer?: object, material?: string,
312
+ * axis?: 'x' | 'y' | 'z', into?: string, lead?: number, sets?: object, at?: number[],
313
+ * mate?: 'printed' | 'bought', gap?: number, flanks?: 'printed' | 'standard', hand?: 'right' | 'left', starts?:
314
+ * number, pitch?: number, segments?: number, display?: 'thread' | 'plain', flat?: boolean }} [o] as holeModel, and
315
+ * at: the point on the face where the hole starts. A clearance hole needs depth: the thickness it passes
149
316
  * @returns {object} a JSCAD geom3 to subtract, with .model holding holeModel's numbers
150
317
  */
151
318
  export function hole(m, o = {}) {
152
- const h = holeModel(m, o), at = pointOf('hole', o.at);
319
+ const h = holeModel(m, o),
320
+ at = pointOf('hole', o.at);
153
321
  if (h.kind === 'thread') return threadedHole(h, at);
154
- if (h.depth == null) throw new Error(`hole: ${a(h.thread)} ${h.kind} hole needs depth, the thickness it passes through, in mm`);
155
- if (h.teardrop) return Object.assign(teardropHole({ d: h.diameter, length: h.depth, at, into: h.into, through: h.through }), { model: h });
156
- const r = h.diameter / 2, steps = [...(h.lead ? [[r + h.lead, 0], [r, h.lead]] : []), [r, h.depth], ...(h.point ? [[0, h.depth + h.point]] : [])];
322
+ if (h.depth == null)
323
+ throw new Error(`hole: ${a(h.thread)} ${h.kind} hole needs depth, the thickness it passes through, in mm`);
324
+ if (h.teardrop)
325
+ return Object.assign(teardropHole({ d: h.diameter, length: h.depth, at, into: h.into, through: h.through }), {
326
+ model: h,
327
+ });
328
+ const r = h.diameter / 2,
329
+ steps = [
330
+ ...(h.lead
331
+ ? [
332
+ [r + h.lead, 0],
333
+ [r, h.lead],
334
+ ]
335
+ : []),
336
+ [r, h.depth],
337
+ ...(h.point ? [[0, h.depth + h.point]] : []),
338
+ ];
157
339
  return Object.assign(along(bore(steps, { through: h.through }), h.into, at), { model: h });
158
340
  }