@rulecad/shapes 0.4.4 → 0.4.5

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/CHANGELOG.md ADDED
@@ -0,0 +1,36 @@
1
+ # Changelog: @rulecad/shapes
2
+
3
+ What changed in each release, for someone upgrading a workspace. A **printed size** is a dimension of a part you
4
+ print (a hole's diameter, a seat's depth, a part's outline). Each release says whether any printed size moved, and
5
+ why.
6
+
7
+ ## 0.4.5: shapes holds no screw size (Fixings 3)
8
+
9
+ ### What reads fixings now
10
+
11
+ Nothing in this package imports `@rulecad/fixings`: fixings draws with this package's seats, so an import the other
12
+ way would make a dependency cycle. Instead every helper takes plain dimensions in mm, and anything named by a thread
13
+ (a hole for an M3 screw, the seat for its head, its nut or its insert) comes from fixings, which calls `countersink`,
14
+ `teardropHole`, `nutPocket` and `wallOpening` here with the thread's figures. A test holds that fixings' countersink,
15
+ nut pocket, side hole and nut slot are this package's helpers given the model's figures, to the last vertex.
16
+
17
+ ### Changed
18
+
19
+ - `nutTrap(nut, { hole, ... })`: the 3.5 mm default for the screws that hold a lead-screw nut's flange is gone. Their
20
+ hole comes in as `hole` (the hole as drawn, for example `fixings.holeModel('M3', { printer }).diameter`, which
21
+ already has the printer's compensation in it), or else from the nut's own `hole_diameter` or `mount_hole_diameter`
22
+ plus the printer's `hole_comp`. Given neither, `nutTrap` refuses by name. The result carries `.hole`, the screws'
23
+ hole as drawn.
24
+ - `nutTrap` reads `flange_width` (the name the `t8-nut` rule set uses) as `flange_thickness`.
25
+ - The README says which helpers take screw figures and why, and points to fixings for anything named by a thread.
26
+
27
+ ### Printed sizes that moved
28
+
29
+ None. Every drawn result is the same solid, vertex for vertex, for every input that worked before: the kit's
30
+ `t8-nut` set gives its own `mount_hole_diameter`, 3.5 mm, the figure the old default typed.
31
+
32
+ ### What a workspace should change
33
+
34
+ - A call to `nutTrap` with a nut that has no `hole_diameter` or `mount_hole_diameter` and no `hole` now fails. Pass the
35
+ screws' hole from fixings: `nutTrap(nut, { hole: v.fixings.holeModel('M3').diameter, printer: v.x1c, at })`, or add
36
+ the nut's own figure to its rule set.
package/README.md CHANGED
@@ -3,6 +3,13 @@
3
3
  Helpers for [JSCAD](https://github.com/jscad/OpenJSCAD.org) designs that get printed. JSCAD is a peer dependency: use
4
4
  the one you already have.
5
5
 
6
+ Every helper here takes plain dimensions in mm and holds no screw size of its own. Anything named by a thread (a hole
7
+ for an M3 screw, the seat for its head, its nut or its insert) comes from
8
+ [`@rulecad/fixings`](https://github.com/JoniBach/rulecad/tree/main/packages/fixings#readme), which reads the thread's
9
+ rule set and the printer's and calls this package's `countersink`, `teardropHole`, `nutPocket` and `wallOpening`
10
+ with the figures. So `fixings.countersink('M3', ...)` and `countersink({ hole, head, ... })` draw the same cone; the
11
+ first also says where each size came from. Shapes never imports fixings, so the two have no cycle.
12
+
6
13
  ```js
7
14
  import jscad from '@jscad/modeling';
8
15
  import { text, anchor, cut } from '@rulecad/shapes';
@@ -72,7 +79,19 @@ clipGroove(8, { width: 1, depth: 0.5, at: [0, 0, 30] })
72
79
  | Ledge (`lip`) | a quarter of the races' radial depth by default, so it carries the outer race only; at most half |
73
80
  | Plain bore, as drawn | shaft + 2 × clearance + `hole_comp`, the clearance being the printer's `fit` each side by default |
74
81
 
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.
82
+ `lm8uuPocket`, `nutTrap`, `pulleyBore` and `beltClamp` are the same idea for a linear bearing, a lead-screw nut's
83
+ flange and body, a pulley on its shaft and a GT2 belt's grip. Of these only `nutTrap` has screws, the ones that hold
84
+ the nut's flange. Their hole is a plain figure too: `hole`, the hole as drawn, from fixings (whose diameter already
85
+ has the printer's `hole_comp` in it), or else the nut's own `hole_diameter` (`mount_hole_diameter` in its rule set)
86
+ plus `hole_comp`. Given neither, `nutTrap` refuses: there is no default screw.
87
+
88
+ ```js
89
+ const screws = fixings.holeModel('M3', { printer: v.x1c }) // an M3 clearance hole, as drawn
90
+ nutTrap(v['t8-nut'], { hole: screws.diameter, printer: v.x1c, at: [0, 0, 20] }) // or leave hole out: the nut's own 3.5 mm
91
+ ```
92
+
93
+ The screws stay out of this package on purpose. Shapes cannot read a thread's rule set without depending on fixings,
94
+ and fixings already depends on shapes, so a seat takes the screw's figure and the design passes it from fixings.
76
95
 
77
96
  `press` and `slip` are estimates until they are measured with the seats coupon in the bench project: print it once per
78
97
  filament, press a bearing into each pocket, and write the one that holds without cracking into the printer's rules.
@@ -81,14 +100,17 @@ filament, press a bearing into each pocket, and write the one that holds without
81
100
 
82
101
  Holes, pockets and ribs drawn so they print without supports with the part lying as drawn (z up from the bed).
83
102
  Each starts at a point on a face (`at`) and goes into the material (`into`: `'+x'`, `'-x'`, `'+y'`, `'-y'`, `'+z'` up
84
- from the bed, `'-z'` down from a top). Sizes come from your rules; nothing is built in.
103
+ from the bed, `'-z'` down from a top). Sizes come from your rules; nothing is built in. For a screw by its thread,
104
+ call the same seats through fixings (`fixings.countersink('M3', { length: 16, at, into })`, `fixings.nutPocket('M3', ...)`,
105
+ `fixings.hole('M3', { into: '+x', depth: 20 })`): they read the thread's figures and the printer's, and draw with
106
+ these. The calls below are for sizes you have in hand.
85
107
 
86
108
  ```js
87
109
  import { countersink, teardropHole, nutPocket, crushRibs, wallOpening } from '@rulecad/shapes'
88
110
 
89
- countersink({ hole: v.hole, head: v.csk, length: 16, at: [x, y, 0], into: '+z' }) // flat head flush with the face
111
+ countersink({ hole: v.hole, head: v.head, length: 16, at: [x, y, 0], into: '+z' }) // flat head flush with the face
90
112
  teardropHole({ d: v.hole, length: 20, at: [-10, 0, 5], into: '+x' }) // across a part: a 45° pointed roof
91
- nutPocket({ flats: v.m3.nut_flats + v.x1c.hole_comp, height: v.m3.nut_height, hole: v.hole, at: [x, y, 0], into: '+z' })
113
+ nutPocket({ flats: v.flats, height: v.height, hole: v.hole, at: [x, y, 0], into: '+z' })
92
114
  crushRibs({ at: [[-9.4, 5], [9.4, 5]], into: [[1, 0], [-1, 0]], z: [3, 5], radius: 0.84, protrude: 0.5 }) // to add
93
115
  wallOpening({ width: 12.75, height: 6.9, depth: v.wall, at: [x, 0, z], into: '-y', bridge: v.x1c.bridge })
94
116
  ```
package/features.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  // Print-aware features: the holes, pockets and ribs printed parts keep needing, drawn so they print without supports
2
2
  // in the part's print orientation (z up, the bed at the bottom). Each returns a JSCAD geom3 to subtract from the part
3
- // (crushRibs: to add). Sizes come in from rules (m3.csk_head, m3.nut_flats, x1c.hole_comp …): no numbers live here.
3
+ // (crushRibs: to add). Sizes come in as plain numbers, from rules (m3.countersunk_head, m3.nut_flats, x1c.hole_comp …):
4
+ // no numbers live here. @rulecad/fixings reads a thread's rule set and the printer's and calls these with the figures.
4
5
  // Every feature starts at a point on a face (at) and goes into the material along a direction (into): '+x', '-x',
5
6
  // '+y', '-y', '+z' (up from the bed) or '-z' (down from a top face).
6
7
  // countersink({ hole, head, length, at, into, teardrop }) a flat-head screw's hole and its 90° cone, the head flush
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulecad/shapes",
3
- "version": "0.4.4",
3
+ "version": "0.4.5",
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": {
@@ -13,6 +13,7 @@
13
13
  "enclosure.mjs",
14
14
  "enclosure.d.mts",
15
15
  "README.md",
16
+ "CHANGELOG.md",
16
17
  "LICENSE",
17
18
  "features.mjs",
18
19
  "features.d.mts",
package/seats.d.mts CHANGED
@@ -114,28 +114,35 @@ export function lm8uuPocket(bearing: {
114
114
  into?: string;
115
115
  }): object;
116
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)
117
+ * A pocket for a lead-screw nut, to subtract: its flange let in from a face, its body on through, and holes for the
118
+ * screws that hold it, on their circle. Goes down from a top face; the flange sits flush. The screws' holes come in as
119
+ * plain figures, as everything here does: `hole`, the hole as drawn (a hole from @rulecad/fixings, whose diameter
120
+ * already has the printer's compensation in it: `fixings.holeModel('M3', { printer }).diameter`), or else the nut's
121
+ * own `hole_diameter` (or `mount_hole_diameter`, as its rule set names it), to which the printer's `hole_comp` is
122
+ * added. With neither, it is refused: there is no screw size here.
123
+ * @param {{ flange_diameter: number, flange_thickness?: number, flange_width?: number, body_diameter: number, length: number, hole_circle: number, hole_count: number, hole_diameter?: number, mount_hole_diameter?: number }} nut
124
+ * from its rule set; flange_width is the rule set's name for flange_thickness
125
+ * @param {{ fit?: number, hole?: number, printer: object, at?: number[], depth?: number }} o fit: clearance across the flange (default the printer's fit, each side);
126
+ * hole: the screws' holes as drawn, in mm
127
+ * @returns {object} a JSCAD geom3 to subtract, with .flange and .body the diameters as drawn, and .hole the screws' holes as drawn
121
128
  */
122
129
  export function nutTrap(nut: {
123
130
  flange_diameter: number;
124
131
  flange_thickness?: number;
132
+ flange_width?: number;
125
133
  body_diameter: number;
126
134
  length: number;
127
135
  hole_circle: number;
128
136
  hole_count: number;
129
137
  hole_diameter?: number;
130
- }, { fit, printer, at, depth }?: {
138
+ mount_hole_diameter?: number;
139
+ }, { fit, hole: hole_, printer, at, depth }?: {
131
140
  fit?: number;
141
+ hole?: number;
132
142
  printer: object;
133
143
  at?: number[];
134
144
  depth?: number;
135
- }): jscad.geometries.geom3.Geom3 & {
136
- flange: number;
137
- body: number;
138
- };
145
+ }): object;
139
146
  /**
140
147
  * 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
148
  * axle, to subtract. A pass-through with a chamfered mouth.
@@ -165,4 +172,3 @@ export function beltClamp(belt: {
165
172
  wall: number;
166
173
  at?: number[];
167
174
  }): object;
168
- import jscad from '@jscad/modeling';
package/seats.mjs CHANGED
@@ -160,18 +160,35 @@ export function lm8uuPocket(bearing, { fit = 'press', clearance = 1, through = f
160
160
  return Object.assign(along(union(cuts), into, at), { pocket: s.pocket, clearance: s.clearance });
161
161
  }
162
162
 
163
+ // The screws' holes for a bought part held by screws, as drawn: given (from fixings, already compensated), or the part's
164
+ // own figure plus the printer's hole_comp. No screw size lives here, so with neither it is refused by name
165
+ function screwHole(what, given, part, comp) {
166
+ if (given != null) return size(what, 'hole', given);
167
+ const own = part.hole_diameter ?? part.mount_hole_diameter;
168
+ if (own == null) throw new Error(`${what}: give the screws' hole as drawn ({ hole: fixings.holeModel('M3', { printer }).diameter }), or the part's own hole_diameter: there is no screw size here`);
169
+ return size(what, 'hole_diameter', own) + comp;
170
+ }
171
+
163
172
  /**
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)
173
+ * A pocket for a lead-screw nut, to subtract: its flange let in from a face, its body on through, and holes for the
174
+ * screws that hold it, on their circle. Goes down from a top face; the flange sits flush. The screws' holes come in as
175
+ * plain figures, as everything here does: `hole`, the hole as drawn (a hole from @rulecad/fixings, whose diameter
176
+ * already has the printer's compensation in it: `fixings.holeModel('M3', { printer }).diameter`), or else the nut's
177
+ * own `hole_diameter` (or `mount_hole_diameter`, as its rule set names it), to which the printer's `hole_comp` is
178
+ * added. With neither, it is refused: there is no screw size here.
179
+ * @param {{ flange_diameter: number, flange_thickness?: number, flange_width?: number, body_diameter: number, length: number, hole_circle: number, hole_count: number, hole_diameter?: number, mount_hole_diameter?: number }} nut
180
+ * from its rule set; flange_width is the rule set's name for flange_thickness
181
+ * @param {{ fit?: number, hole?: number, printer: object, at?: number[], depth?: number }} o fit: clearance across the flange (default the printer's fit, each side);
182
+ * hole: the screws' holes as drawn, in mm
183
+ * @returns {object} a JSCAD geom3 to subtract, with .flange and .body the diameters as drawn, and .hole the screws' holes as drawn
168
184
  */
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 });
185
+ export function nutTrap(nut, { fit, hole: hole_, printer, at = [0, 0, 0], depth } = {}) {
186
+ 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);
187
+ const hole = screwHole(what, hole_, nut, comp);
188
+ const t = nut.flange_thickness ?? nut.flange_width ?? 3.5, D = depth ?? length, r = (body + comp + gap) / 2, R = (flange + comp + gap) / 2;
189
+ if (circle / 2 + (hole - comp) / 2 > R + 0.01 || circle / 2 - (hole - comp) / 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`);
190
+ 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 / 2, hole / 2, 0, -D - OUT)); });
191
+ return Object.assign(translate(at, union(...cuts, ...holes)), { flange: 2 * R, body: 2 * r, hole });
175
192
  }
176
193
 
177
194
  /**