@rulecad/fixings 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +641 -2
- package/draw.d.mts +46 -0
- package/draw.mjs +85 -0
- package/fixings.d.mts +35 -0
- package/fixings.mjs +53 -0
- package/hardware.d.mts +215 -0
- package/hardware.mjs +181 -0
- package/holes.d.mts +135 -0
- package/holes.mjs +157 -0
- package/model.d.mts +253 -0
- package/model.mjs +382 -0
- package/package.json +56 -4
- package/seats.d.mts +353 -0
- package/seats.mjs +334 -0
- package/strength.d.mts +221 -0
- package/strength.mjs +262 -0
- package/threads.d.mts +216 -0
- package/threads.mjs +411 -0
package/holes.d.mts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which way a cutter goes, from `into` (a direction) or `axis` (a hole standing up, z, or lying along x or y).
|
|
3
|
+
* @param {string} what @param {{ into?: string, axis?: string }} o @param {string} [fallback]
|
|
4
|
+
* @returns {{ into: string, axis: 'x' | 'y' | 'z', across: boolean }} across: it lies on its side
|
|
5
|
+
*/
|
|
6
|
+
export function directionOf(what: string, { into, axis }?: {
|
|
7
|
+
into?: string;
|
|
8
|
+
axis?: string;
|
|
9
|
+
}, fallback?: string): {
|
|
10
|
+
into: string;
|
|
11
|
+
axis: "x" | "y" | "z";
|
|
12
|
+
across: boolean;
|
|
13
|
+
};
|
|
14
|
+
/** A point [x, y, z] in mm, refused by name where it is not one. */
|
|
15
|
+
export function pointOf(what: any, at?: number[]): number[];
|
|
16
|
+
/** The options object every function here takes, refused where it is not one. */
|
|
17
|
+
export function optionsOf(what: any, o: any, example: any): any;
|
|
18
|
+
/**
|
|
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
|
|
21
|
+
* @returns {number | null} the thickness, where one was given
|
|
22
|
+
*/
|
|
23
|
+
export function inPart(what: string, o: {
|
|
24
|
+
thickness?: number;
|
|
25
|
+
}, deep: number, says: string): number | null;
|
|
26
|
+
/**
|
|
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
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* A hole for a fixing, as numbers, sized by what it is for.
|
|
37
|
+
* @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), or thread (a thread modelled to print, which
|
|
42
|
+
* also takes threadModel's mate, gap, flanks, hand, starts, pitch, segments, display and flat);
|
|
43
|
+
* depth: how deep, or the thickness passed through; through: out of the far face (the default for the clearances);
|
|
44
|
+
* thickness: the part's, along the hole: a hole through it is that deep, and a blind one deeper than it is refused;
|
|
45
|
+
* printer: the printer's rule set, or its values (default the kit's X1C); material: the plastic, for a pilot ('PLA',
|
|
46
|
+
* 'PETG'), or what a tapped hole is in ('aluminium'); axis: z for a hole standing up, x or y for one on its side
|
|
47
|
+
* (or into, a direction: '+x', '-z'); lead: the lead-in chamfer; sets: the workspace's rule sets, where m is a name
|
|
48
|
+
* @returns {Hole}
|
|
49
|
+
*/
|
|
50
|
+
export function holeModel(m: Fixing | string, o?: {
|
|
51
|
+
kind?: string;
|
|
52
|
+
depth?: number;
|
|
53
|
+
through?: boolean;
|
|
54
|
+
thickness?: number;
|
|
55
|
+
printer?: object;
|
|
56
|
+
material?: string;
|
|
57
|
+
axis?: "x" | "y" | "z";
|
|
58
|
+
into?: string;
|
|
59
|
+
lead?: number;
|
|
60
|
+
sets?: object;
|
|
61
|
+
mate?: "printed" | "bought";
|
|
62
|
+
gap?: number;
|
|
63
|
+
flanks?: "printed" | "standard";
|
|
64
|
+
hand?: "right" | "left";
|
|
65
|
+
starts?: number;
|
|
66
|
+
pitch?: number;
|
|
67
|
+
segments?: number;
|
|
68
|
+
display?: "thread" | "plain";
|
|
69
|
+
flat?: boolean;
|
|
70
|
+
}): Hole;
|
|
71
|
+
/**
|
|
72
|
+
* A hole for a fixing, to subtract: round standing up, a teardrop lying on its side (through @rulecad/shapes'
|
|
73
|
+
* teardropHole), with its lead-in where it has one, and a 45° point where it ends going up from the bed.
|
|
74
|
+
* @param {Fixing | string} m
|
|
75
|
+
* @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[],
|
|
76
|
+
* mate?: 'printed' | 'bought', gap?: number, flanks?: 'printed' | 'standard', hand?: 'right' | 'left', starts?: number, pitch?: number, segments?: number, display?: 'thread' | 'plain', flat?: boolean }} [o]
|
|
77
|
+
* as holeModel, and at: the point on the face where the hole starts. A clearance hole needs depth: the thickness it passes
|
|
78
|
+
* @returns {object} a JSCAD geom3 to subtract, with .model holding holeModel's numbers
|
|
79
|
+
*/
|
|
80
|
+
export function hole(m: Fixing | string, o?: {
|
|
81
|
+
kind?: string;
|
|
82
|
+
depth?: number;
|
|
83
|
+
through?: boolean;
|
|
84
|
+
thickness?: number;
|
|
85
|
+
printer?: object;
|
|
86
|
+
material?: string;
|
|
87
|
+
axis?: "x" | "y" | "z";
|
|
88
|
+
into?: string;
|
|
89
|
+
lead?: number;
|
|
90
|
+
sets?: object;
|
|
91
|
+
at?: number[];
|
|
92
|
+
mate?: "printed" | "bought";
|
|
93
|
+
gap?: number;
|
|
94
|
+
flanks?: "printed" | "standard";
|
|
95
|
+
hand?: "right" | "left";
|
|
96
|
+
starts?: number;
|
|
97
|
+
pitch?: number;
|
|
98
|
+
segments?: number;
|
|
99
|
+
display?: "thread" | "plain";
|
|
100
|
+
flat?: boolean;
|
|
101
|
+
}): object;
|
|
102
|
+
/** The kinds of hole: what each is for. `thread` is a thread modelled to print (threadModel), for a screw of about M6 or more. */
|
|
103
|
+
export const HOLE_KINDS: string[];
|
|
104
|
+
export function said(into: any): any;
|
|
105
|
+
/**
|
|
106
|
+
* diameter: as drawn; nominal: the rule's figure; comp: the hole compensation added across it (0 where the figure is as drawn);
|
|
107
|
+
* depth: null for a clearance hole not told the thickness it passes; teardrop: it lies on its side and gets a 45° roof;
|
|
108
|
+
* 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;
|
|
109
|
+
* basis: the rule the diameter rests on, and how far to trust it; rests: every figure used
|
|
110
|
+
*/
|
|
111
|
+
export type Hole = {
|
|
112
|
+
thread: string;
|
|
113
|
+
kind: string;
|
|
114
|
+
diameter: number;
|
|
115
|
+
nominal: number;
|
|
116
|
+
comp: number;
|
|
117
|
+
depth: number | null;
|
|
118
|
+
through: boolean;
|
|
119
|
+
into: string;
|
|
120
|
+
axis: "x" | "y" | "z";
|
|
121
|
+
teardrop: boolean;
|
|
122
|
+
lead: number;
|
|
123
|
+
point: number;
|
|
124
|
+
basis: {
|
|
125
|
+
rule: string;
|
|
126
|
+
kind: string;
|
|
127
|
+
source: string;
|
|
128
|
+
};
|
|
129
|
+
rests: object[];
|
|
130
|
+
findings: object[];
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* a fixing's model, as fixingModel gives it
|
|
134
|
+
*/
|
|
135
|
+
export type Fixing = import("./model.mjs").Fixing;
|
package/holes.mjs
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// Holes by purpose: a design says what a hole is for (a screw passes through it, a screw forms its thread in it, it
|
|
2
|
+
// is tapped, an insert melts into it) and the thread's rules and the printer's size it. holeModel gives the numbers
|
|
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
|
+
// part along a direction (into), as the features of @rulecad/shapes do.
|
|
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';
|
|
7
|
+
import { along, bore, DIRECTIONS } from './draw.mjs';
|
|
8
|
+
import { threadedHoleModel, threadedHole } from './threads.mjs';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {import('./model.mjs').Fixing} Fixing a fixing's model, as fixingModel gives it
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
// What each kind of hole is drawn to. printed: the figure is the size the hole must come out, so the printer's hole
|
|
15
|
+
// compensation is added once across the diameter; where it is false the rule's own text says the figure is as drawn
|
|
16
|
+
// (already sized for printing), and nothing is added. blind: the hole ends in the part unless told it goes through.
|
|
17
|
+
const HOLES = {
|
|
18
|
+
clearance: { figure: 'clearance', printed: true, blind: false, says: 'clearance hole' },
|
|
19
|
+
close: { figure: 'clearance_close', printed: true, blind: false, says: 'close clearance hole' },
|
|
20
|
+
loose: { figure: 'clearance_loose', printed: true, blind: false, says: 'loose clearance hole' },
|
|
21
|
+
tap: { figure: 'tap_drill', printed: true, blind: true, says: 'hole to tap' },
|
|
22
|
+
pilot: { figure: 'pilot', printed: false, blind: true, says: 'pilot' },
|
|
23
|
+
insert: { figure: 'insert_hole', printed: false, blind: true, says: 'insert hole' }
|
|
24
|
+
};
|
|
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. */
|
|
26
|
+
export const HOLE_KINDS = [...Object.keys(HOLES), 'thread'];
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Which way a cutter goes, from `into` (a direction) or `axis` (a hole standing up, z, or lying along x or y).
|
|
30
|
+
* @param {string} what @param {{ into?: string, axis?: string }} o @param {string} [fallback]
|
|
31
|
+
* @returns {{ into: string, axis: 'x' | 'y' | 'z', across: boolean }} across: it lies on its side
|
|
32
|
+
*/
|
|
33
|
+
export function directionOf(what, { into, axis } = {}, fallback = '-z') {
|
|
34
|
+
if (into != null) oneOf(what, 'into', into, DIRECTIONS);
|
|
35
|
+
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`);
|
|
37
|
+
const dir = into ?? (axis == null ? fallback : axis === 'z' ? '-z' : `+${axis}`);
|
|
38
|
+
return { into: dir, axis: /** @type {'x' | 'y' | 'z'} */ (dir[1]), across: dir[1] !== 'z' };
|
|
39
|
+
}
|
|
40
|
+
/** A point [x, y, z] in mm, refused by name where it is not one. */
|
|
41
|
+
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)})`);
|
|
43
|
+
return at;
|
|
44
|
+
}
|
|
45
|
+
/** The options object every function here takes, refused where it is not one. */
|
|
46
|
+
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)}`);
|
|
48
|
+
return o;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 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
|
|
53
|
+
* @returns {number | null} the thickness, where one was given
|
|
54
|
+
*/
|
|
55
|
+
export function inPart(what, o, deep, says) {
|
|
56
|
+
if (o.thickness == null) return null;
|
|
57
|
+
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`);
|
|
59
|
+
return o.thickness;
|
|
60
|
+
}
|
|
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' };
|
|
62
|
+
/** How a direction is said in a finding. */
|
|
63
|
+
export const said = (into) => HOW[into];
|
|
64
|
+
|
|
65
|
+
/**
|
|
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
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* A hole for a fixing, as numbers, sized by what it is for.
|
|
77
|
+
* @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), or thread (a thread modelled to print, which
|
|
82
|
+
* also takes threadModel's mate, gap, flanks, hand, starts, pitch, segments, display and flat);
|
|
83
|
+
* depth: how deep, or the thickness passed through; through: out of the far face (the default for the clearances);
|
|
84
|
+
* thickness: the part's, along the hole: a hole through it is that deep, and a blind one deeper than it is refused;
|
|
85
|
+
* printer: the printer's rule set, or its values (default the kit's X1C); material: the plastic, for a pilot ('PLA',
|
|
86
|
+
* 'PETG'), or what a tapped hole is in ('aluminium'); axis: z for a hole standing up, x or y for one on its side
|
|
87
|
+
* (or into, a direction: '+x', '-z'); lead: the lead-in chamfer; sets: the workspace's rule sets, where m is a name
|
|
88
|
+
* @returns {Hole}
|
|
89
|
+
*/
|
|
90
|
+
export function holeModel(m, o = {}) {
|
|
91
|
+
const what = 'hole';
|
|
92
|
+
optionsOf(what, o, '{ kind: \'pilot\', depth: 8 }');
|
|
93
|
+
const fx = fixingOf(what, m, o), kind = oneOf(what, 'kind', o.kind ?? 'clearance', HOLE_KINDS);
|
|
94
|
+
if (kind === 'thread') return threadedHoleModel(what, fx, o, directionOf(what, o));
|
|
95
|
+
const spec = HOLES[kind], pr = printerOf(what, o.printer), dir = directionOf(what, o), out = [], rests = [];
|
|
96
|
+
// The figure the diameter rests on: for a pilot, the printer's measured rule for this thread (and plastic) before the thread's starting figure
|
|
97
|
+
let basis = null;
|
|
98
|
+
const plastic = o.material == null ? null : String(o.material).toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
99
|
+
if (kind === 'pilot') basis = [plastic && `pilot_${fx.set}_${plastic}`, `pilot_${fx.set}`].filter(Boolean).map((k) => pr.figure(k)).find(Boolean) ?? null;
|
|
100
|
+
const own = !!basis;
|
|
101
|
+
if (!basis) {
|
|
102
|
+
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'}`);
|
|
103
|
+
basis = { ...fx.figures[spec.figure], name: cite(fx, spec.figure) };
|
|
104
|
+
}
|
|
105
|
+
if (!(isNum(basis.value) && basis.value > 0)) throw new Error(`${what}: ${basis.name} is a diameter above 0 mm (got ${shown(basis.value)})`);
|
|
106
|
+
const nominal = basis.value, comp = spec.printed ? pr.n('hole_comp') : 0, diameter = r3(nominal + comp);
|
|
107
|
+
rests.push(rest(basis.name, basis));
|
|
108
|
+
if (comp) rests.push(pr.rest('hole_comp'));
|
|
109
|
+
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`;
|
|
110
|
+
let text = `${a(fx.thread)} ${spec.says} drawn ${mm(diameter)} mm: it rests on ${basis.name} (${mm(nominal)} mm), ${trust}`;
|
|
111
|
+
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)';
|
|
112
|
+
if (kind === 'pilot' && !own) text += `. That is the thread's starting figure: ${pr.name} has no measured pilot_${fx.set}, so measure it on this printer`;
|
|
113
|
+
out.push(finding('info', text, 'hole.drawn', { values: { diameter, nominal, comp }, refs: { thread: fx.thread, set: fx.set, rule: basis.name, kind: basis.kind } }));
|
|
114
|
+
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 } }));
|
|
115
|
+
// a figure that names one plastic, asked for another
|
|
116
|
+
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 } }));
|
|
117
|
+
|
|
118
|
+
const through = o.through ?? !spec.blind;
|
|
119
|
+
if (typeof through !== 'boolean') throw new Error(`${what}: through is true or false (got ${shown(o.through)})`);
|
|
120
|
+
let depth = o.depth ?? null, need = null;
|
|
121
|
+
const depthFrom = (n) => { rests.push(rest(cite(fx, n), fx.figures[n])); return figure(what, fx, n); };
|
|
122
|
+
if (kind === 'insert') need = depthFrom(through ? 'insert_length' : 'insert_depth');
|
|
123
|
+
else if (kind === 'pilot' && fx.figures.pilot_depth) need = depthFrom('pilot_depth');
|
|
124
|
+
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); }
|
|
125
|
+
if (depth != null) positive(what, 'depth', depth); else depth = through && o.thickness != null ? positive(what, 'thickness', o.thickness) : need;
|
|
126
|
+
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 } }));
|
|
127
|
+
|
|
128
|
+
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)})`);
|
|
129
|
+
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})`);
|
|
130
|
+
let lead = o.lead ?? (spec.blind && !dir.across ? pr.n('chamfer') : 0);
|
|
131
|
+
if (lead && depth != null) lead = Math.min(lead, depth / 2);
|
|
132
|
+
const point = !through && dir.into === '+z' ? r3(diameter / 2) : 0;
|
|
133
|
+
if (!through && depth != null) inPart(what, o, depth + point, `a blind ${spec.says} ${mm(depth)} mm deep${point ? ` with its ${mm(point)} mm point` : ''}`);
|
|
134
|
+
out.push(finding('pass', dir.across ? `${said(dir.into)}, the hole is a teardrop: a 45° roof, so it prints with no support`
|
|
135
|
+
: 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 } }));
|
|
136
|
+
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'));
|
|
137
|
+
return { thread: fx.thread, kind, diameter, nominal, comp, depth, through, into: dir.into, axis: dir.axis, teardrop: dir.across, lead: r3(lead), point,
|
|
138
|
+
basis: { rule: basis.name, kind: basis.kind, source: basis.source }, rests, findings: out };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* A hole for a fixing, to subtract: round standing up, a teardrop lying on its side (through @rulecad/shapes'
|
|
143
|
+
* teardropHole), with its lead-in where it has one, and a 45° point where it ends going up from the bed.
|
|
144
|
+
* @param {Fixing | string} m
|
|
145
|
+
* @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[],
|
|
146
|
+
* mate?: 'printed' | 'bought', gap?: number, flanks?: 'printed' | 'standard', hand?: 'right' | 'left', starts?: number, pitch?: number, segments?: number, display?: 'thread' | 'plain', flat?: boolean }} [o]
|
|
147
|
+
* as holeModel, and at: the point on the face where the hole starts. A clearance hole needs depth: the thickness it passes
|
|
148
|
+
* @returns {object} a JSCAD geom3 to subtract, with .model holding holeModel's numbers
|
|
149
|
+
*/
|
|
150
|
+
export function hole(m, o = {}) {
|
|
151
|
+
const h = holeModel(m, o), at = pointOf('hole', o.at);
|
|
152
|
+
if (h.kind === 'thread') return threadedHole(h, at);
|
|
153
|
+
if (h.depth == null) throw new Error(`hole: ${a(h.thread)} ${h.kind} hole needs depth, the thickness it passes through, in mm`);
|
|
154
|
+
if (h.teardrop) return Object.assign(teardropHole({ d: h.diameter, length: h.depth, at, into: h.into, through: h.through }), { model: h });
|
|
155
|
+
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]] : [])];
|
|
156
|
+
return Object.assign(along(bore(steps, { through: h.through }), h.into, at), { model: h });
|
|
157
|
+
}
|
package/model.d.mts
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
export function positive(what: any, k: any, v: any): any;
|
|
2
|
+
export function oneOf(what: any, k: any, v: any, list: any): any;
|
|
3
|
+
/**
|
|
4
|
+
* A fixing's name read by the grammar, before any rule set is looked at.
|
|
5
|
+
* @param {string} name 'M3', 'M3x12 cap', '1/4-20 x 1/2 cap', 'M4 lock nut', 'K30x10 pan torx'
|
|
6
|
+
* @returns {{ thread: string, form: 'metric' | 'unified' | 'plastic', length: number | null, unit: 'mm' | 'in' | null, item: 'thread' | 'screw' | 'nut' | 'washer' | 'insert', head: string | null, nut: string | null, extra: string[] }}
|
|
7
|
+
* length: as written, in unit (null: the thread's own, mm or inches); extra: words left for the rule set's variants
|
|
8
|
+
*/
|
|
9
|
+
export function parseName(name: string): {
|
|
10
|
+
thread: string;
|
|
11
|
+
form: "metric" | "unified" | "plastic";
|
|
12
|
+
length: number | null;
|
|
13
|
+
unit: "mm" | "in" | null;
|
|
14
|
+
item: "thread" | "screw" | "nut" | "washer" | "insert";
|
|
15
|
+
head: string | null;
|
|
16
|
+
nut: string | null;
|
|
17
|
+
extra: string[];
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* The threads there are rule sets for, as each is written: the kit's, and a workspace's own first.
|
|
21
|
+
* @param {{ sets?: object }} [opts] @returns {string[]}
|
|
22
|
+
*/
|
|
23
|
+
export function threads(opts?: {
|
|
24
|
+
sets?: object;
|
|
25
|
+
}): string[];
|
|
26
|
+
/**
|
|
27
|
+
* A figure of a fixing as a number, refused by name where the thread has none or it is not a number.
|
|
28
|
+
* @param {string} what @param {Fixing} m @param {string} n @returns {number}
|
|
29
|
+
*/
|
|
30
|
+
export function figure(what: string, m: Fixing, n: string): number;
|
|
31
|
+
/**
|
|
32
|
+
* A head form of a thread, from its figures: refused by name where that size is not made with it.
|
|
33
|
+
* @param {string} what @param {Fixing} m @param {string} form cap, button, countersunk, hex, set or pan
|
|
34
|
+
* @returns {Head}
|
|
35
|
+
*/
|
|
36
|
+
export function headOf(what: string, m: Fixing, form: string): Head;
|
|
37
|
+
/**
|
|
38
|
+
* A nut on a thread, from its figures: refused by name where that size has none.
|
|
39
|
+
* @param {string} what @param {Fixing} m @param {string} kind hex, square or lock
|
|
40
|
+
* @returns {{ kind: string, flats: number, height: number, across: number, figures: string[] }} across: over the corners
|
|
41
|
+
*/
|
|
42
|
+
export function nutOf(what: string, m: Fixing, kind: string): {
|
|
43
|
+
kind: string;
|
|
44
|
+
flats: number;
|
|
45
|
+
height: number;
|
|
46
|
+
across: number;
|
|
47
|
+
figures: string[];
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* A screw's length held to the lengths it is sold in: refused, naming the nearest sold, unless the caller allows it.
|
|
51
|
+
* @param {string} what @param {Fixing} m @param {number} length mm @param {boolean} [allow]
|
|
52
|
+
* @returns {{ length: number, sold: boolean | null }} sold: null where the thread's rule set lists no lengths
|
|
53
|
+
*/
|
|
54
|
+
export function lengthOf(what: string, m: Fixing, length: number, allow?: boolean): {
|
|
55
|
+
length: number;
|
|
56
|
+
sold: boolean | null;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* @typedef {{ value: number | string | number[], unit?: string, kind: string, source: string, rule?: string, checked?: string, from?: 'workspace' | 'kit' }} Figure
|
|
60
|
+
* one figure of a thread: its value, how far to trust it (kind: spec, measured, community, estimate, default, derived or given) and where it comes from
|
|
61
|
+
* @typedef {{ form: string, diameter: number, height: number, across: number, key?: number, flats?: number, angle?: number, point?: number, drive?: string, figures: string[] }} Head
|
|
62
|
+
* a head: its diameter (0 for a hexagon head, which has flats, and for a set screw), its height (0 for a set screw), across: the widest it is; figures: the rules it was read from
|
|
63
|
+
* @typedef {{ kind: 'fixing', item: 'thread' | 'screw' | 'nut' | 'washer' | 'insert', name: string, said: string, set: string, thread: string,
|
|
64
|
+
* form: 'metric' | 'unified' | 'plastic', major: number, pitch: number, length: number | null, sold: boolean | null, head: Head | null,
|
|
65
|
+
* nut: { kind: string, flats: number, height: number, across: number, figures: string[] } | null, variant: string | null,
|
|
66
|
+
* made: { heads: string[], nuts: string[], washer: boolean, insert: boolean }, figures: Record<string, Figure> }} Fixing
|
|
67
|
+
* name: the name in its one spelling; said: as it was asked for; set: the rule set's name; major, pitch: the thread, mm;
|
|
68
|
+
* length: a screw's, from under its head (a countersunk screw's and a set screw's: overall), or an insert's; sold: whether that length
|
|
69
|
+
* is in the thread's list (null: it lists none); made: the head forms, nuts, washer and insert this size has figures for
|
|
70
|
+
*/
|
|
71
|
+
/**
|
|
72
|
+
* A fixing by name, from its thread's rule set: a thread ('M3', '1/4-20'), or a whole screw ('M3x12 cap'), nut
|
|
73
|
+
* ('M4 lock nut'), washer or insert on it. See GRAMMAR for what a name may say.
|
|
74
|
+
* @param {string} name
|
|
75
|
+
* @param {Record<string, number | string | number[] | Partial<Figure>>} [change] a different or measured figure, by its rule's name:
|
|
76
|
+
* { clearance: 3.3 } or { pilot: { value: 2.8, kind: 'measured', source: 'my coupon, 2026-11-20' } }
|
|
77
|
+
* @param {{ sets?: object, anyLength?: boolean, variant?: string }} [opts] sets: the workspace's rule sets, by name or as a
|
|
78
|
+
* list, where a set for this thread is used before the kit's (its figures first, the kit's for what it lacks);
|
|
79
|
+
* anyLength: take a length the thread's list does not have; variant: a variant of the rule set, by its name
|
|
80
|
+
* @returns {Fixing}
|
|
81
|
+
*/
|
|
82
|
+
export function fixingModel(name: string, change?: Record<string, number | string | number[] | Partial<Figure>>, opts?: {
|
|
83
|
+
sets?: object;
|
|
84
|
+
anyLength?: boolean;
|
|
85
|
+
variant?: string;
|
|
86
|
+
}): Fixing;
|
|
87
|
+
/**
|
|
88
|
+
* A fixing from what a function was handed: its model as it is, or a name read with the caller's rule sets.
|
|
89
|
+
* @param {string} what the function asking, for its refusals @param {Fixing | string} m @param {{ sets?: object, anyLength?: boolean }} [o]
|
|
90
|
+
* @returns {Fixing}
|
|
91
|
+
*/
|
|
92
|
+
export function fixingOf(what: string, m: Fixing | string, o?: {
|
|
93
|
+
sets?: object;
|
|
94
|
+
anyLength?: boolean;
|
|
95
|
+
}): Fixing;
|
|
96
|
+
/**
|
|
97
|
+
* @typedef {{ name: string, figure: (k: string) => (Figure & { name: string, borrowed?: boolean }) | null, n: (k: string) => number, cite: (k: string) => string, rest: (k: string) => object }} Printer
|
|
98
|
+
* figure: a rule of the printer's own (never borrowed); n: a basic clearance as a number, the printer's own or, where it
|
|
99
|
+
* has none, the X1C's; cite: the name that number is cited by
|
|
100
|
+
*/
|
|
101
|
+
/**
|
|
102
|
+
* The printer's rules as fixings reads them. Handed nothing, the kit's X1C. Handed a rule set ({ name, rules }), its
|
|
103
|
+
* figures with their kinds and sources. Handed plain numbers (a design's v.x1c), those, marked as given. A basic
|
|
104
|
+
* clearance the printer lacks (hole_comp, fit, layer, line, chamfer, bridge, overhang, slip, press, thread_gap) is borrowed from the X1C
|
|
105
|
+
* and cited as the X1C's; a measured figure (pilot_m3) is never borrowed, since it was measured on that machine.
|
|
106
|
+
* @param {string} what @param {object} [p] @returns {Printer}
|
|
107
|
+
*/
|
|
108
|
+
export function printerOf(what: string, p?: object): Printer;
|
|
109
|
+
/**
|
|
110
|
+
* The rules this package adds to the threads' and the printer's own, each with what it comes from.
|
|
111
|
+
* @type {Record<string, { value: number, unit: string, rule: string, kind: string, source: string, checked: string }>}
|
|
112
|
+
*/
|
|
113
|
+
export const DEFAULTS: Record<string, {
|
|
114
|
+
value: number;
|
|
115
|
+
unit: string;
|
|
116
|
+
rule: string;
|
|
117
|
+
kind: string;
|
|
118
|
+
source: string;
|
|
119
|
+
checked: string;
|
|
120
|
+
}>;
|
|
121
|
+
export function r3(x: any): number;
|
|
122
|
+
export function mm(x: any): string;
|
|
123
|
+
export function isNum(x: any): boolean;
|
|
124
|
+
export function shown(v: any): string;
|
|
125
|
+
export function near(a: any, b: any): any;
|
|
126
|
+
export function finding(level: any, text: any, code: any, extra?: {}): {
|
|
127
|
+
level: any;
|
|
128
|
+
text: any;
|
|
129
|
+
code: any;
|
|
130
|
+
};
|
|
131
|
+
export function rest(name: any, f: any): {
|
|
132
|
+
kind: any;
|
|
133
|
+
source: any;
|
|
134
|
+
unit?: any;
|
|
135
|
+
name: any;
|
|
136
|
+
value: any;
|
|
137
|
+
};
|
|
138
|
+
export function a(thread: any): string;
|
|
139
|
+
/**
|
|
140
|
+
* The one grammar a fixing's name is read by. parseName reads it and nothing else does.
|
|
141
|
+
* @type {string}
|
|
142
|
+
*/
|
|
143
|
+
export const GRAMMAR: string;
|
|
144
|
+
/** The head forms a screw's name can say. */
|
|
145
|
+
export const HEADS: string[];
|
|
146
|
+
/** The kinds of nut a name can say. */
|
|
147
|
+
export const NUTS: string[];
|
|
148
|
+
export function cite(m: Fixing, n: string): string;
|
|
149
|
+
export function screwName(m: Fixing, length: number | null, form: string): string;
|
|
150
|
+
/** How much thread a screw needs in a material, in diameters: the engagement rule set's figures. */
|
|
151
|
+
export const ENGAGEMENT: {
|
|
152
|
+
steel: {
|
|
153
|
+
value: number;
|
|
154
|
+
unit: string;
|
|
155
|
+
rule: string;
|
|
156
|
+
kind: string;
|
|
157
|
+
source: string;
|
|
158
|
+
checked: string;
|
|
159
|
+
};
|
|
160
|
+
aluminium: {
|
|
161
|
+
value: number;
|
|
162
|
+
unit: string;
|
|
163
|
+
rule: string;
|
|
164
|
+
kind: string;
|
|
165
|
+
source: string;
|
|
166
|
+
checked: string;
|
|
167
|
+
};
|
|
168
|
+
plastic: {
|
|
169
|
+
value: number;
|
|
170
|
+
unit: string;
|
|
171
|
+
rule: string;
|
|
172
|
+
kind: string;
|
|
173
|
+
source: string;
|
|
174
|
+
checked: string;
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
export function engagementOf(material: any): "plastic" | "steel" | "aluminium";
|
|
178
|
+
export function layers(h: any, layer: any): number;
|
|
179
|
+
/**
|
|
180
|
+
* one figure of a thread: its value, how far to trust it (kind: spec, measured, community, estimate, default, derived or given) and where it comes from
|
|
181
|
+
*/
|
|
182
|
+
export type Figure = {
|
|
183
|
+
value: number | string | number[];
|
|
184
|
+
unit?: string;
|
|
185
|
+
kind: string;
|
|
186
|
+
source: string;
|
|
187
|
+
rule?: string;
|
|
188
|
+
checked?: string;
|
|
189
|
+
from?: "workspace" | "kit";
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* a head: its diameter (0 for a hexagon head, which has flats, and for a set screw), its height (0 for a set screw), across: the widest it is; figures: the rules it was read from
|
|
193
|
+
*/
|
|
194
|
+
export type Head = {
|
|
195
|
+
form: string;
|
|
196
|
+
diameter: number;
|
|
197
|
+
height: number;
|
|
198
|
+
across: number;
|
|
199
|
+
key?: number;
|
|
200
|
+
flats?: number;
|
|
201
|
+
angle?: number;
|
|
202
|
+
point?: number;
|
|
203
|
+
drive?: string;
|
|
204
|
+
figures: string[];
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* name: the name in its one spelling; said: as it was asked for; set: the rule set's name; major, pitch: the thread, mm;
|
|
208
|
+
* length: a screw's, from under its head (a countersunk screw's and a set screw's: overall), or an insert's; sold: whether that length
|
|
209
|
+
* is in the thread's list (null: it lists none); made: the head forms, nuts, washer and insert this size has figures for
|
|
210
|
+
*/
|
|
211
|
+
export type Fixing = {
|
|
212
|
+
kind: "fixing";
|
|
213
|
+
item: "thread" | "screw" | "nut" | "washer" | "insert";
|
|
214
|
+
name: string;
|
|
215
|
+
said: string;
|
|
216
|
+
set: string;
|
|
217
|
+
thread: string;
|
|
218
|
+
form: "metric" | "unified" | "plastic";
|
|
219
|
+
major: number;
|
|
220
|
+
pitch: number;
|
|
221
|
+
length: number | null;
|
|
222
|
+
sold: boolean | null;
|
|
223
|
+
head: Head | null;
|
|
224
|
+
nut: {
|
|
225
|
+
kind: string;
|
|
226
|
+
flats: number;
|
|
227
|
+
height: number;
|
|
228
|
+
across: number;
|
|
229
|
+
figures: string[];
|
|
230
|
+
} | null;
|
|
231
|
+
variant: string | null;
|
|
232
|
+
made: {
|
|
233
|
+
heads: string[];
|
|
234
|
+
nuts: string[];
|
|
235
|
+
washer: boolean;
|
|
236
|
+
insert: boolean;
|
|
237
|
+
};
|
|
238
|
+
figures: Record<string, Figure>;
|
|
239
|
+
};
|
|
240
|
+
/**
|
|
241
|
+
* figure: a rule of the printer's own (never borrowed); n: a basic clearance as a number, the printer's own or, where it
|
|
242
|
+
* has none, the X1C's; cite: the name that number is cited by
|
|
243
|
+
*/
|
|
244
|
+
export type Printer = {
|
|
245
|
+
name: string;
|
|
246
|
+
figure: (k: string) => (Figure & {
|
|
247
|
+
name: string;
|
|
248
|
+
borrowed?: boolean;
|
|
249
|
+
}) | null;
|
|
250
|
+
n: (k: string) => number;
|
|
251
|
+
cite: (k: string) => string;
|
|
252
|
+
rest: (k: string) => object;
|
|
253
|
+
};
|