@rulecad/shapes 0.4.2 → 0.4.4

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/README.md CHANGED
@@ -50,6 +50,33 @@ const window = gabled([-1, 1], [-1, 4], [10, 13]);
50
50
  - `diamond(size, axis, length)`: a square hole turned 45 degrees, for small holes in upright walls.
51
51
  - `vents({ count, width, pitch, length, depth })`: slots side by side along x.
52
52
 
53
+ ## Seats for bought parts
54
+
55
+ The printed side of a bearing or a shaft. Each one prints without supports in the orientation it is drawn for, and takes
56
+ its sizes from rules: the bearing's from its rule set, the fit from the printer's (`hole_comp`, `fit`, `press`, `slip`).
57
+
58
+ ```js
59
+ import { bearingSeat, seatSize, plainBearing, shaftShoulder, clipGroove } from '@rulecad/shapes'
60
+
61
+ const seat = bearingSeat(v['608'], { fit: 'press', printer: v.x1c, at: [0, 0, 12], into: '-z', through: true, relief: 5 })
62
+ seat.seat.pocket // 22.05: the diameter as drawn; clearance -0.05 once printed
63
+ plainBearing(8, { length: 10, printer: v.x1c, at: [0, 0, 10], into: '-z', through: true }) // a bore to subtract
64
+ plainBearing(8, { length: 10, wall: 2, printer: v.x1c }) // a bush, standing up, to add
65
+ shaftShoulder(8, { shoulder: 12, height: 3, at: [0, 0, 20] }) // a collar: flat top, 45 degree underside
66
+ clipGroove(8, { width: 1, depth: 0.5, at: [0, 0, 30] }) // a groove: flat lower face, sloped top
67
+ ```
68
+
69
+ | Figure | How it is worked out |
70
+ |---|---|
71
+ | Pocket, as drawn | outer + `hole_comp` - `press` (or + `slip`, or + a clearance you give, in mm across) |
72
+ | Ledge (`lip`) | a quarter of the races' radial depth by default, so it carries the outer race only; at most half |
73
+ | Plain bore, as drawn | shaft + 2 × clearance + `hole_comp`, the clearance being the printer's `fit` each side by default |
74
+
75
+ `lm8uuPocket`, `nutTrap`, `pulleyBore` and `beltClamp` are the same idea for a linear bearing, a lead-screw nut's flange and body, a pulley on its shaft and a GT2 belt's grip.
76
+
77
+ `press` and `slip` are estimates until they are measured with the seats coupon in the bench project: print it once per
78
+ filament, press a bearing into each pocket, and write the one that holds without cracking into the printer's rules.
79
+
53
80
  ## Print-aware features
54
81
 
55
82
  Holes, pockets and ribs drawn so they print without supports with the part lying as drawn (z up from the bed).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulecad/shapes",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "description": "Shape helpers for printed JSCAD designs: text that prints cleanly, anchors on a face, clean local cuts, and enclosure pieces (shells, lids, rails, print-safe holes).",
5
5
  "type": "module",
6
6
  "exports": {
@@ -16,6 +16,8 @@
16
16
  "LICENSE",
17
17
  "features.mjs",
18
18
  "features.d.mts",
19
+ "seats.mjs",
20
+ "seats.d.mts",
19
21
  "ops.mjs",
20
22
  "ops.d.mts",
21
23
  "optimised.mjs",
@@ -38,11 +40,15 @@
38
40
  "url": "git+https://github.com/JoniBach/rulecad.git",
39
41
  "directory": "packages/shapes"
40
42
  },
43
+ "homepage": "https://github.com/JoniBach/rulecad/tree/main/packages/shapes#readme",
44
+ "bugs": {
45
+ "url": "https://github.com/JoniBach/rulecad/issues"
46
+ },
41
47
  "scripts": {
42
48
  "test": "node --test"
43
49
  },
44
50
  "dependencies": {
45
- "@rulecad/variables": "^0.2.0"
51
+ "@rulecad/variables": "^0.3.0"
46
52
  },
47
53
  "peerDependencies": {
48
54
  "@jscad/modeling": "^2.12.0",
package/seats.d.mts ADDED
@@ -0,0 +1,168 @@
1
+ /**
2
+ * What a seat is drawn to, in numbers. The pocket is the bearing's outside, plus the printer's hole compensation (printed
3
+ * holes come out that much small across), less the press (or plus the slip).
4
+ * @param {{ bore: number, outer_diameter: number, width: number }} bearing from its rule set
5
+ * @param {{ fit?: 'press' | 'slip' | number, lip?: number, printer: { hole_comp: number, press?: number, slip?: number } }} o
6
+ * fit: a printed clearance across the diameter, or a name for the printer's; lip: how far the ledge reaches in under the
7
+ * outer race (default a quarter of the race's depth, so it never touches the inner race)
8
+ * @returns {{ pocket: number, depth: number, relief: number, lip: number, fit: string | number, clearance: number, comp: number }}
9
+ * pocket: the diameter as drawn; relief: the diameter past the ledge; clearance: what's left across it once printed (below 0, a press)
10
+ */
11
+ export function seatSize(bearing: {
12
+ bore: number;
13
+ outer_diameter: number;
14
+ width: number;
15
+ }, { fit, lip, printer }?: {
16
+ fit?: "press" | "slip" | number;
17
+ lip?: number;
18
+ printer: {
19
+ hole_comp: number;
20
+ press?: number;
21
+ slip?: number;
22
+ };
23
+ }): {
24
+ pocket: number;
25
+ depth: number;
26
+ relief: number;
27
+ lip: number;
28
+ fit: string | number;
29
+ clearance: number;
30
+ comp: number;
31
+ };
32
+ /**
33
+ * A pocket for a ball bearing's outer race, to subtract: the fit from the printer's rules, a ledge to stop against, and
34
+ * a relief past it so the inner race runs free. Going down from a top face (-z) the ledge is flat; going up from the bed
35
+ * (+z) it is a 45° cone that takes the race on its corner; across a part (±x, ±y) the pocket has a teardrop's 45° roof.
36
+ * @param {{ bore: number, outer_diameter: number, width: number }} bearing
37
+ * @param {{ fit?: 'press' | 'slip' | number, lip?: number, relief?: number, through?: boolean, lead?: number, printer: object, at?: number[], into?: string }} o
38
+ * relief: how far past the ledge (mm); through: run the relief out of the far face; lead: the lead-in chamfer at the mouth (none across a part, where its top half would overhang)
39
+ * @returns {object} a JSCAD geom3 to subtract, with .seat holding seatSize's numbers
40
+ */
41
+ export function bearingSeat(bearing: {
42
+ bore: number;
43
+ outer_diameter: number;
44
+ width: number;
45
+ }, { fit, lip, relief, through, into, lead, printer, at }?: {
46
+ fit?: "press" | "slip" | number;
47
+ lip?: number;
48
+ relief?: number;
49
+ through?: boolean;
50
+ lead?: number;
51
+ printer: object;
52
+ at?: number[];
53
+ into?: string;
54
+ }): object;
55
+ /**
56
+ * A plain bearing for a shaft, where a ball bearing is more than the load needs. Its bore is the shaft plus the running
57
+ * clearance each side, plus the printer's hole compensation. As a bore to subtract; given a wall, a bush standing up
58
+ * from z = 0 to add (a tube lying down wouldn't print round).
59
+ * @param {number} shaft diameter
60
+ * @param {{ clearance?: number, length: number, wall?: number, through?: boolean, printer: object, at?: number[], into?: string }} o
61
+ * clearance: each side (default the printer's fit)
62
+ * @returns {object} a JSCAD geom3, with .bore the diameter as drawn and .clearance each side
63
+ */
64
+ export function plainBearing(shaft: number, { clearance, length, wall, through, printer, at, into }?: {
65
+ clearance?: number;
66
+ length: number;
67
+ wall?: number;
68
+ through?: boolean;
69
+ printer: object;
70
+ at?: number[];
71
+ into?: string;
72
+ }): object;
73
+ /**
74
+ * A collar on a printed shaft, to add, stood up as it prints: a flat top for a bearing's inner race to stop against, and
75
+ * a 45° underside so it starts from the shaft with nothing hanging.
76
+ * @param {number} shaft diameter @param {{ shoulder: number, height: number, at?: number[] }} o shoulder: the collar's diameter;
77
+ * height: from where it leaves the shaft to its flat top; at: the point on the shaft's axis at its top
78
+ * @returns {object} a JSCAD geom3 to add
79
+ */
80
+ export function shaftShoulder(shaft: number, { shoulder, height, at }?: {
81
+ shoulder: number;
82
+ height: number;
83
+ at?: number[];
84
+ }): object;
85
+ /**
86
+ * A groove round a printed shaft for a circlip or a printed clip, to subtract, stood up as it prints: a flat lower face
87
+ * for the clip to bear on, a sloped upper face so nothing bridges.
88
+ * @param {number} shaft diameter @param {{ width: number, depth: number, at?: number[] }} o width: of the flat part;
89
+ * depth: into the shaft each side; at: the point on the axis at the flat lower face
90
+ * @returns {object} a JSCAD geom3 to subtract, with .root the diameter at the groove's root
91
+ */
92
+ export function clipGroove(shaft: number, { width, depth, at }?: {
93
+ width: number;
94
+ depth: number;
95
+ at?: number[];
96
+ }): object;
97
+ /**
98
+ * A pocket for a linear bearing's outside (an LM8UU), to subtract: a straight press or slip for its whole length, and on
99
+ * through for the rod. Stood up (±z) or across (±x, ±y), with a teardrop's roof when across.
100
+ * @param {{ outer_diameter: number, length: number, bore: number }} bearing
101
+ * @param {{ fit?: 'press' | 'slip' | number, clearance?: number, through?: boolean, printer: object, at?: number[], into?: string }} o clearance: round the rod, each side
102
+ * @returns {object} a JSCAD geom3 to subtract, with .pocket the diameter as drawn
103
+ */
104
+ export function lm8uuPocket(bearing: {
105
+ outer_diameter: number;
106
+ length: number;
107
+ bore: number;
108
+ }, { fit, clearance, through, printer, at, into }?: {
109
+ fit?: "press" | "slip" | number;
110
+ clearance?: number;
111
+ through?: boolean;
112
+ printer: object;
113
+ at?: number[];
114
+ into?: string;
115
+ }): object;
116
+ /**
117
+ * A pocket for a lead-screw nut, to subtract: its flange let in from a face, its body on through, and its bolts' holes on
118
+ * their circle. Goes down from a top face; the flange sits flush.
119
+ * @param {{ flange_diameter: number, flange_thickness?: number, body_diameter: number, length: number, hole_circle: number, hole_count: number, hole_diameter?: number }} nut
120
+ * @param {{ fit?: number, printer: object, at?: number[], depth?: number }} o fit: clearance across the flange (default the printer's fit, each side)
121
+ */
122
+ export function nutTrap(nut: {
123
+ flange_diameter: number;
124
+ flange_thickness?: number;
125
+ body_diameter: number;
126
+ length: number;
127
+ hole_circle: number;
128
+ hole_count: number;
129
+ hole_diameter?: number;
130
+ }, { fit, printer, at, depth }?: {
131
+ fit?: number;
132
+ printer: object;
133
+ at?: number[];
134
+ depth?: number;
135
+ }): jscad.geometries.geom3.Geom3 & {
136
+ flange: number;
137
+ body: number;
138
+ };
139
+ /**
140
+ * A bore for a pulley on a stepper's round shaft (no flat: a pulley's grub screw bears on the shaft), or a plain idler's
141
+ * axle, to subtract. A pass-through with a chamfered mouth.
142
+ * @param {{ bore: number }} pulley @param {{ length: number, printer: object, at?: number[], into?: string, through?: boolean }} o
143
+ */
144
+ export function pulleyBore(pulley: {
145
+ bore: number;
146
+ }, { length, printer, at, into, through }?: {
147
+ length: number;
148
+ printer: object;
149
+ at?: number[];
150
+ into?: string;
151
+ through?: boolean;
152
+ }): any;
153
+ /**
154
+ * A comb that grips a GT2 belt, to add: teeth of the belt's pitch on a block, the belt pressed in face first and held by
155
+ * a plain cover. Printed teeth up, so nothing overhangs.
156
+ * @param {{ pitch: number, width: number }} belt @param {{ length: number, height: number, wall: number, at?: number[] }} o
157
+ * @returns {object} a JSCAD geom3 to add, x along the belt, z up
158
+ */
159
+ export function beltClamp(belt: {
160
+ pitch: number;
161
+ width: number;
162
+ }, { length, height, wall, at }?: {
163
+ length: number;
164
+ height: number;
165
+ wall: number;
166
+ at?: number[];
167
+ }): object;
168
+ import jscad from '@jscad/modeling';
package/seats.mjs ADDED
@@ -0,0 +1,198 @@
1
+ // Seats for bought parts: the printed side of a bearing or a shaft, drawn so it prints without supports and says what
2
+ // fit it was drawn to. As with the print-aware features, sizes come in from rules: a bearing's from its rule set, the
3
+ // fit from the printer's (hole_comp, fit, press, slip), and each cutter starts at a point on a face (at) and goes into
4
+ // the material along a direction (into): '+x', '-x', '+y', '-y', '+z' (up from the bed) or '-z' (down from a top face).
5
+ // seatSize(bearing, { fit, lip, printer }) the numbers: the pocket as drawn, its depth, the relief, the fit
6
+ // bearingSeat(bearing, { fit, lip, relief, through, lead, printer, at, into }) a pocket to subtract, for the outer race
7
+ // plainBearing(shaft, { clearance, length, wall, through, printer, at, into }) a bore to subtract, or with wall a bush to add
8
+ // shaftShoulder(shaft, { shoulder, height, at }) a collar to add to a printed shaft, stood up: flat on top, 45° below
9
+ // clipGroove(shaft, { width, depth, at }) a ring to subtract from a printed shaft, stood up: flat below, sloped above
10
+ import jscad from '@jscad/modeling';
11
+
12
+ const { cylinder, cylinderElliptic, cuboid, polygon } = jscad.primitives, { translate, rotateX, rotateY, rotateZ } = jscad.transforms;
13
+ const { hull } = jscad.hulls, { union } = jscad.booleans, { extrudeRotate } = jscad.extrusions;
14
+ const OUT = 0.1, TINY = 1e-3, EDGE = 0.05, SEGMENTS = 64;
15
+ const UP = { '+x': [1, 0], '-x': [-1, 0], '+y': [0, 1], '-y': [0, -1] };
16
+
17
+ function along(g, into, at = [0, 0, 0]) {
18
+ const turn = { '-z': (x) => x, '+z': (x) => rotateX(Math.PI, x), '+x': (x) => rotateY(-Math.PI / 2, x), '-x': (x) => rotateY(Math.PI / 2, x),
19
+ '+y': (x) => rotateX(Math.PI / 2, x), '-y': (x) => rotateX(-Math.PI / 2, x) }[into];
20
+ if (!turn) throw new Error(`into must be +x, -x, +y, -y, +z or -z (got ${into})`);
21
+ return translate(at, turn(g));
22
+ }
23
+ function size(what, name, v, { zero = false } = {}) { if (!(typeof v === 'number' && Number.isFinite(v) && (zero ? v >= 0 : v > 0))) throw new Error(`${what}: ${name} is a size ${zero ? 'of 0 mm or more' : 'above 0 mm'} (got ${v})`); return v; }
24
+ // A round cutter from z0 down to z1 (radius r0 to r1), with a 45° ridge on the up side when it goes across a part
25
+ function tear(r0, r1, z0, z1, up) {
26
+ const ridge = (r, z) => translate([up[0] * (r * Math.SQRT2 - EDGE / Math.SQRT2), up[1] * (r * Math.SQRT2 - EDGE / Math.SQRT2), z], rotateZ(Math.PI / 4, cuboid({ size: [EDGE, EDGE, TINY] })));
27
+ const round = r0 === r1 ? translate([0, 0, (z0 + z1) / 2], cylinder({ radius: r0, height: Math.abs(z0 - z1), segments: SEGMENTS }))
28
+ : translate([0, 0, (z0 + z1) / 2], cylinderElliptic({ height: Math.abs(z0 - z1), startRadius: [r1, r1], endRadius: [r0, r0], segments: SEGMENTS }));
29
+ return up ? hull(round, ridge(r0, z0), ridge(r1, z1)) : round;
30
+ }
31
+ function printerOf(what, p) {
32
+ if (!p || typeof p !== 'object') throw new Error(`${what}: give the printer's rules ({ printer: v.x1c }): the fit is theirs, so there are no numbers here`);
33
+ return p;
34
+ }
35
+ const FITS = ['press', 'slip'];
36
+ function bearingOf(what, b) {
37
+ if (!b || typeof b !== 'object') throw new Error(`${what}: give the bearing's rules ({ bore, outer_diameter, width }), not ${b}`);
38
+ const outer = b.outer_diameter ?? b.outer, bore = size(what, 'bore', b.bore);
39
+ if (!(size(what, 'outer_diameter', outer) > bore)) throw new Error(`${what}: the outer diameter (${outer}) is above the bore (${bore})`);
40
+ return { bore, outer, width: size(what, 'width', b.width) };
41
+ }
42
+
43
+ /**
44
+ * What a seat is drawn to, in numbers. The pocket is the bearing's outside, plus the printer's hole compensation (printed
45
+ * holes come out that much small across), less the press (or plus the slip).
46
+ * @param {{ bore: number, outer_diameter: number, width: number }} bearing from its rule set
47
+ * @param {{ fit?: 'press' | 'slip' | number, lip?: number, printer: { hole_comp: number, press?: number, slip?: number } }} o
48
+ * fit: a printed clearance across the diameter, or a name for the printer's; lip: how far the ledge reaches in under the
49
+ * outer race (default a quarter of the race's depth, so it never touches the inner race)
50
+ * @returns {{ pocket: number, depth: number, relief: number, lip: number, fit: string | number, clearance: number, comp: number }}
51
+ * pocket: the diameter as drawn; relief: the diameter past the ledge; clearance: what's left across it once printed (below 0, a press)
52
+ */
53
+ export function seatSize(bearing, { fit = 'press', lip, printer } = {}) {
54
+ const what = 'bearingSeat', b = bearingOf(what, bearing), p = printerOf(what, printer), comp = size(what, 'printer.hole_comp', p.hole_comp, { zero: true });
55
+ let clearance;
56
+ if (typeof fit === 'number') clearance = fit;
57
+ else if (fit === 'press') clearance = -size(what, 'printer.press', p.press, { zero: true });
58
+ else if (fit === 'slip') clearance = size(what, 'printer.slip', p.slip, { zero: true });
59
+ else throw new Error(`${what}: fit is ${FITS.join(' or ')}, or a clearance in mm (got ${fit})`);
60
+ const radial = (b.outer - b.bore) / 2, ledge = lip ?? radial / 4;
61
+ size(what, 'lip', ledge);
62
+ if (ledge > radial / 2) throw new Error(`${what}: a lip of ${ledge} mm reaches the inner race (the races are ${radial} mm deep together: ${radial / 2} mm at most)`);
63
+ const pocket = b.outer + comp + clearance;
64
+ return { pocket: +pocket.toFixed(4), depth: b.width, relief: +(pocket - 2 * ledge).toFixed(4), lip: ledge, fit, clearance, comp };
65
+ }
66
+
67
+ /**
68
+ * A pocket for a ball bearing's outer race, to subtract: the fit from the printer's rules, a ledge to stop against, and
69
+ * a relief past it so the inner race runs free. Going down from a top face (-z) the ledge is flat; going up from the bed
70
+ * (+z) it is a 45° cone that takes the race on its corner; across a part (±x, ±y) the pocket has a teardrop's 45° roof.
71
+ * @param {{ bore: number, outer_diameter: number, width: number }} bearing
72
+ * @param {{ fit?: 'press' | 'slip' | number, lip?: number, relief?: number, through?: boolean, lead?: number, printer: object, at?: number[], into?: string }} o
73
+ * relief: how far past the ledge (mm); through: run the relief out of the far face; lead: the lead-in chamfer at the mouth (none across a part, where its top half would overhang)
74
+ * @returns {object} a JSCAD geom3 to subtract, with .seat holding seatSize's numbers
75
+ */
76
+ export function bearingSeat(bearing, { fit = 'press', lip, relief = 1, through = false, into = '-z', lead = UP[into] ? 0 : 0.4, printer, at = [0, 0, 0] } = {}) {
77
+ const what = 'bearingSeat', s = seatSize(bearing, { fit, lip, printer });
78
+ size(what, 'relief', relief); size(what, 'lead', lead, { zero: true });
79
+ const R = s.pocket / 2, r = s.relief / 2, up = UP[into] ?? null, D = s.depth, past = D + relief + (through ? OUT : 0);
80
+ if (up) { // across a part, a teardrop's roof on each step
81
+ const cuts = [tear(R, R, lead ? 0 : OUT, -D, up), tear(r, r, -D + EDGE, -past, up)];
82
+ if (lead) cuts.push(tear(R + lead, R, 0, -lead, up), tear(R + lead, R + lead, OUT, 0, up));
83
+ return Object.assign(along(union(cuts), into, at), { seat: s });
84
+ }
85
+ // Going up or down, one profile turned about the axis: no seams between the steps for a boolean to leak at
86
+ const mouth = lead ? [[R + lead, OUT], [R + lead, 0], [R, -lead]] : [[R, OUT]], z0 = -D, floor = through ? Math.min(-past, -D - R) - OUT : -past;
87
+ const inner = into === '+z' ? (through ? [[R, z0], [r, z0 - (R - r)], [r, floor]] : [[R, z0], [TINY, z0 - (R - TINY)]]) : [[R, z0], [r, z0], [r, -past]];
88
+ const pts = [[0, OUT], ...mouth, ...inner, [0, inner.at(-1)[1]]].reverse();
89
+ const turned = extrudeRotate({ segments: SEGMENTS }, polygon({ points: pts }));
90
+ const g = along(turned, into, at);
91
+ return Object.assign(g, { seat: s });
92
+ }
93
+
94
+ /**
95
+ * A plain bearing for a shaft, where a ball bearing is more than the load needs. Its bore is the shaft plus the running
96
+ * clearance each side, plus the printer's hole compensation. As a bore to subtract; given a wall, a bush standing up
97
+ * from z = 0 to add (a tube lying down wouldn't print round).
98
+ * @param {number} shaft diameter
99
+ * @param {{ clearance?: number, length: number, wall?: number, through?: boolean, printer: object, at?: number[], into?: string }} o
100
+ * clearance: each side (default the printer's fit)
101
+ * @returns {object} a JSCAD geom3, with .bore the diameter as drawn and .clearance each side
102
+ */
103
+ export function plainBearing(shaft, { clearance, length, wall, through = false, printer, at = [0, 0, 0], into = '-z' } = {}) {
104
+ const what = 'plainBearing', p = printerOf(what, printer);
105
+ size(what, 'shaft', shaft); size(what, 'length', length);
106
+ const gap = clearance ?? size(what, 'printer.fit', p.fit), comp = size(what, 'printer.hole_comp', p.hole_comp, { zero: true }), bore = +(shaft + 2 * size(what, 'clearance', gap) + comp).toFixed(4);
107
+ if (wall == null) return Object.assign(along(tear(bore / 2, bore / 2, OUT, -length - (through ? OUT : 0), UP[into] ?? null), into, at), { bore, clearance: gap });
108
+ size(what, 'wall', wall);
109
+ if (UP[into]) throw new Error(`${what}: a bush with a wall prints standing up (into +z or -z): a tube on its side wouldn't print round. Bore across a part with no wall instead`);
110
+ const outer = bore / 2 + wall, inner = bore / 2, chamfer = Math.min(0.4, wall / 2);
111
+ const g = extrudeRotate({ segments: SEGMENTS }, polygon({ points: [[inner + chamfer, 0], [outer - chamfer, 0], [outer, chamfer], [outer, length], [inner, length], [inner, chamfer]] }));
112
+ return Object.assign(translate(at, g), { bore, clearance: gap });
113
+ }
114
+
115
+ /**
116
+ * A collar on a printed shaft, to add, stood up as it prints: a flat top for a bearing's inner race to stop against, and
117
+ * a 45° underside so it starts from the shaft with nothing hanging.
118
+ * @param {number} shaft diameter @param {{ shoulder: number, height: number, at?: number[] }} o shoulder: the collar's diameter;
119
+ * height: from where it leaves the shaft to its flat top; at: the point on the shaft's axis at its top
120
+ * @returns {object} a JSCAD geom3 to add
121
+ */
122
+ export function shaftShoulder(shaft, { shoulder, height, at = [0, 0, 0] } = {}) {
123
+ const what = 'shaftShoulder', a = size(what, 'shaft', shaft) / 2, b = size(what, 'shoulder', shoulder) / 2;
124
+ size(what, 'height', height);
125
+ if (b <= a) throw new Error(`${what}: the shoulder (${shoulder}) stands proud of the shaft (${shaft})`);
126
+ if (height < b - a) throw new Error(`${what}: a ${shoulder} mm collar on a ${shaft} mm shaft is ${b - a} mm of 45° underside, and ${height} mm isn't enough to draw it`);
127
+ // the solid runs in to the axis, so it joins the shaft whatever the shaft is drawn as
128
+ return translate(at, extrudeRotate({ segments: SEGMENTS }, polygon({ points: [[0, -height], [a - TINY, -height], [b, -height + (b - a) + TINY], [b, 0], [0, 0]] })));
129
+ }
130
+
131
+ /**
132
+ * A groove round a printed shaft for a circlip or a printed clip, to subtract, stood up as it prints: a flat lower face
133
+ * for the clip to bear on, a sloped upper face so nothing bridges.
134
+ * @param {number} shaft diameter @param {{ width: number, depth: number, at?: number[] }} o width: of the flat part;
135
+ * depth: into the shaft each side; at: the point on the axis at the flat lower face
136
+ * @returns {object} a JSCAD geom3 to subtract, with .root the diameter at the groove's root
137
+ */
138
+ export function clipGroove(shaft, { width, depth, at = [0, 0, 0] } = {}) {
139
+ const what = 'clipGroove', R = size(what, 'shaft', shaft) / 2;
140
+ size(what, 'width', width); size(what, 'depth', depth);
141
+ if (depth >= R / 2) throw new Error(`${what}: a groove ${depth} mm deep leaves too little of a ${shaft} mm shaft (under ${R / 2} mm)`);
142
+ const r = R - depth, over = R + 1, rise = 1.2 * (over - r);
143
+ // The upper face is a little steeper than 45° (a slope of exactly the limit is an overhang by a hair, sliced). The
144
+ // cutter's outside runs 1 mm past the shaft, with its slope carried on so the face is one line
145
+ const g = extrudeRotate({ segments: SEGMENTS }, polygon({ points: [[r, 0], [over, 0], [over, width + rise], [r, width]] }));
146
+ return Object.assign(translate(at, g), { root: 2 * r });
147
+ }
148
+
149
+ /**
150
+ * A pocket for a linear bearing's outside (an LM8UU), to subtract: a straight press or slip for its whole length, and on
151
+ * through for the rod. Stood up (±z) or across (±x, ±y), with a teardrop's roof when across.
152
+ * @param {{ outer_diameter: number, length: number, bore: number }} bearing
153
+ * @param {{ fit?: 'press' | 'slip' | number, clearance?: number, through?: boolean, printer: object, at?: number[], into?: string }} o clearance: round the rod, each side
154
+ * @returns {object} a JSCAD geom3 to subtract, with .pocket the diameter as drawn
155
+ */
156
+ export function lm8uuPocket(bearing, { fit = 'press', clearance = 1, through = false, printer, at = [0, 0, 0], into = '-z' } = {}) {
157
+ const what = 'lm8uuPocket', p = printerOf(what, printer), L = size(what, 'length', bearing?.length), s = seatSize({ bore: bearing?.bore, outer_diameter: bearing?.outer_diameter, width: L }, { fit, printer: p, lip: 0.01 }), up = UP[into] ?? null, R = s.pocket / 2, rod = bearing.bore / 2 + clearance;
158
+ const cuts = [tear(R, R, OUT, -L, up)];
159
+ if (into === '+z') { const rise = R - rod; cuts.push(tear(R, rod, -L, -L - rise)); cuts.push(tear(rod, rod, -L - rise / 2, -(L + rise + (through ? OUT : 2)))); } else cuts.push(tear(rod, rod, -L + EDGE, -(L + 2 + (through ? OUT : 0)), up));
160
+ return Object.assign(along(union(cuts), into, at), { pocket: s.pocket, clearance: s.clearance });
161
+ }
162
+
163
+ /**
164
+ * A pocket for a lead-screw nut, to subtract: its flange let in from a face, its body on through, and its bolts' holes on
165
+ * their circle. Goes down from a top face; the flange sits flush.
166
+ * @param {{ flange_diameter: number, flange_thickness?: number, body_diameter: number, length: number, hole_circle: number, hole_count: number, hole_diameter?: number }} nut
167
+ * @param {{ fit?: number, printer: object, at?: number[], depth?: number }} o fit: clearance across the flange (default the printer's fit, each side)
168
+ */
169
+ export function nutTrap(nut, { fit, printer, at = [0, 0, 0], depth } = {}) {
170
+ const what = 'nutTrap', p = printerOf(what, printer), comp = size(what, 'printer.hole_comp', p.hole_comp, { zero: true }), gap = fit ?? 2 * size(what, 'printer.fit', p.fit), flange = size(what, 'flange_diameter', nut?.flange_diameter), body = size(what, 'body_diameter', nut.body_diameter), length = size(what, 'length', nut.length), circle = size(what, 'hole_circle', nut.hole_circle), n = size(what, 'hole_count', nut.hole_count), hole = nut.hole_diameter ?? 3.5;
171
+ const t = nut.flange_thickness ?? 3.5, D = depth ?? length, r = (body + comp + gap) / 2, R = (flange + comp + gap) / 2;
172
+ if (circle / 2 + hole / 2 > R + 0.01 || circle / 2 - hole / 2 < r) throw new Error(`nutTrap: holes on a ${circle} mm circle don't fall between the ${body} mm body and the ${flange} mm flange`);
173
+ const cuts = [tear(R, R, OUT, -t), tear(r, r, -t + EDGE, -D - OUT)], holes = Array.from({ length: n }, (_, i) => { const a = (i * 2 * Math.PI) / n; return translate([(circle / 2) * Math.cos(a), (circle / 2) * Math.sin(a), 0], tear((hole + comp) / 2, (hole + comp) / 2, 0, -D - OUT)); });
174
+ return Object.assign(translate(at, union(...cuts, ...holes)), { flange: 2 * R, body: 2 * r });
175
+ }
176
+
177
+ /**
178
+ * A bore for a pulley on a stepper's round shaft (no flat: a pulley's grub screw bears on the shaft), or a plain idler's
179
+ * axle, to subtract. A pass-through with a chamfered mouth.
180
+ * @param {{ bore: number }} pulley @param {{ length: number, printer: object, at?: number[], into?: string, through?: boolean }} o
181
+ */
182
+ export function pulleyBore(pulley, { length, printer, at = [0, 0, 0], into = '-z', through = false } = {}) {
183
+ return plainBearing(size('pulleyBore', 'bore', pulley?.bore), { length, printer, at, into, through, clearance: printerOf('pulleyBore', printer).slip ?? printer.fit / 2 });
184
+ }
185
+
186
+ /**
187
+ * A comb that grips a GT2 belt, to add: teeth of the belt's pitch on a block, the belt pressed in face first and held by
188
+ * a plain cover. Printed teeth up, so nothing overhangs.
189
+ * @param {{ pitch: number, width: number }} belt @param {{ length: number, height: number, wall: number, at?: number[] }} o
190
+ * @returns {object} a JSCAD geom3 to add, x along the belt, z up
191
+ */
192
+ export function beltClamp(belt, { length, height, wall, at = [0, 0, 0] } = {}) {
193
+ const what = 'beltClamp', pitch = size(what, 'pitch', belt?.pitch), width = size(what, 'width', belt.width);
194
+ size(what, 'length', length); size(what, 'height', height); size(what, 'wall', wall);
195
+ const count = Math.floor(length / pitch), base = translate([0, 0, height / 2], cuboid({ size: [length, width + 2 * wall, height] })), teeth = [], tooth = pitch * 0.45;
196
+ for (let i = 0; i < count; i++) teeth.push(translate([-length / 2 + pitch * (i + 0.5), 0, height + 0.375], cuboid({ size: [tooth, width + 2 * wall, 0.75] })));
197
+ return translate(at, union(base, ...teeth));
198
+ }
package/shapes.d.mts CHANGED
@@ -27,4 +27,5 @@ export const scale: typeof jscad.transforms.scale;
27
27
  import jscad from '@jscad/modeling';
28
28
  export { outline, slab, shell, lid, dovetail, gabled, diamond, vents } from "./enclosure.mjs";
29
29
  export { countersink, teardropHole, nutPocket, crushRibs, wallOpening } from "./features.mjs";
30
+ export { seatSize, bearingSeat, plainBearing, shaftShoulder, clipGroove, lm8uuPocket, nutTrap, pulleyBore, beltClamp } from "./seats.mjs";
30
31
  export { fromOutlines, regionShape, optimisedOutline, solidRegion, optimisedSolid } from "./optimised.mjs";
package/shapes.mjs CHANGED
@@ -106,5 +106,6 @@ export const size = (g) => { const [lo, hi] = measureBoundingBox(g); return [hi[
106
106
  export { scale };
107
107
  export { outline, slab, shell, lid, dovetail, gabled, diamond, vents } from './enclosure.mjs';
108
108
  export { countersink, teardropHole, nutPocket, crushRibs, wallOpening } from './features.mjs';
109
+ export { seatSize, bearingSeat, plainBearing, shaftShoulder, clipGroove, lm8uuPocket, nutTrap, pulleyBore, beltClamp } from './seats.mjs';
109
110
  export { ops } from './ops.mjs';
110
111
  export { fromOutlines, regionShape, optimisedOutline, solidRegion, optimisedSolid } from './optimised.mjs';