@rulecad/cad 0.7.69 → 0.7.75

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 CHANGED
@@ -5,6 +5,49 @@ print (a hole's diameter, a seat's depth, a part's outline). Each release lists
5
5
  its reason. A **fasten** is an entry in an assembly's `"fasten"` list: one screwed joint, naming the screw by thread
6
6
  and head, the parts it passes through and the part it ends in.
7
7
 
8
+ ## 0.7.75: parts milled, cast or printed in a powder bed
9
+ ### Added
10
+
11
+ - Problems take how the part is made: `"mill": "+z"` (milled from that side, no undercuts), `"cast": "+z"` or
12
+ `"cast": { "draw": "z", "parting": 6 }` (a mould drawn off one way, or two halves from a parting plane), with
13
+ `"symmetry": { "mirror": "y", "turns": 4, "axis": "z" }` and `"extrude": "x"` for any process, and
14
+ `"voids": "refused"` for a metal powder bed print. The problem schema has each field.
15
+ - `cad optimise` says how a milled or cast part is made and counts its undercuts (none unless an avoid region sits
16
+ behind material), says what is mirrored or extruded, and fails on a problem that refuses voids with each enclosed
17
+ void's volume and centre. `--json` gives `process`, `undercuts`, `symmetry`, `extrude`, `grey` and `voids`.
18
+ - `cad optimise` warns when more than a tenth of a milled, cast, symmetric or extruded result is grey (neither empty
19
+ nor solid), and refuses a symmetry that swaps the side the part is made from for its opposite.
20
+ - Rule sets `mill-3axis`, `mould-injection` and `dmls` (from @rulecad/rules) to read the processes' limits from.
21
+
22
+ ### Changed
23
+
24
+ - Every optimised result is made again once, since topopt's solver file changed; a problem without the new fields
25
+ gets the same densities as before. No printed size moved.
26
+
27
+ ## 0.7.70: printed bolts into slot nuts, a slotted snap pot
28
+ ### Fixed
29
+
30
+ - **A printed bolt into a slot nut** (issue 305): its length is now any whole millimetre between the nut's thread and
31
+ the slot's floor, as a printed bolt's is everywhere else, and `fasten.length` says "the shortest that fits (a printed
32
+ bolt is printed to any whole millimetre)", not "the shortest sold". A 10 mm plate on a 3030's slot, where no M6 is
33
+ sold from 16.4 to 18.7 mm, takes an M6x17 printed bolt.
34
+ - **A torque given for a printed bolt** is worded as a turn by hand, not a tightening: `fasten.seat` says "turned by
35
+ hand to 1 N m, it clamps with about 833.3 N (T = K d F, fixings.nut_factor 0.2 for steel threads: an estimate for a
36
+ printed one)", and `cad order` says "to 1 N m and no further (a printed bolt, turned by hand, not tightened)". A new
37
+ finding, `fasten.torque`, holds that clamp against what the bolt breaks at, about twice over: an M6 printed bolt in
38
+ PLA breaks at 625.2 N, so 1 N m fails and names 0.37 N m as the most (rounded down, so it passes its own check). The seat's values no longer carry a
39
+ tightening torque for a printed bolt.
40
+
41
+ - **Pins lying on their side** (issue 306): a pin in teardrop holes, as `v.fixings.pinHole` draws one lying on its
42
+ side, is found and checked as a round one is. It already was: `holesIn` leaves a teardrop's roof out of the round
43
+ it fits. A test now holds it (press, slip and snap sockets, along x and along y, blind, and the failures by name),
44
+ and the README says so.
45
+
46
+ ### Added
47
+
48
+ - The bench project `enclosures` has a `slotted` variant of `snap-pot`, its lid's skirt in 16 fingers (issue 309), and
49
+ the assembly `snap-pot-slotted-closed`.
50
+
8
51
  ## 0.7.69: --dry-run never writes
9
52
 
10
53
  ### Fixed
package/README.md CHANGED
@@ -472,6 +472,7 @@ starts and stops. From that the check says:
472
472
  | `fasten.length` | The length chosen where none is given: the shortest sold length that fits the stack as measured (into a motor, the longest that stops short of the end of its thread). A given length is checked for reaching the far end, bottoming out in a blind hole (1 mm is kept at the tip) and standing more than a diameter proud |
473
473
  | `fasten.engagement` | The thread engaged at the far end against the rule for what it is in: the thread's `pilot_depth` or the engagement rule for the project's material, an insert's length, a nut's height; into a motor, its own thread's depth, and at least one diameter (`engagement.steel`, as `motor.mount` holds it). A short one names the length or the depth that would do |
474
474
  | `fasten.seat` | The head (or its washer) has a flat seat as wide as itself and square to the screw, read under the head from the part; a countersunk head has a countersink of its angle. It says the force and torque the seat takes on the project's material, and with `torque` holds the pressure against the material's strength and names the washer that would bring it within |
475
+ | `fasten.torque` | A printed bolt given a `torque`: the clamp it is turned to (T = K d F with steel's nut factor, an estimate for a printed thread) held against what the bolt breaks at, about twice over (`fixings.load_margin`); a turn that would break it fails, naming the most to turn it to |
475
476
  | `fasten.access` | A key or driver reaches the head along its axis, in the build pose: a cylinder as wide as the key across its corners, as long as its long arm (both from the `hexkey` set, ISO 2936; a hexagon head's socket adds `hexkey.socket_wall`, an estimate), clear of every other part. A part over the head that goes on after the screw passes, with the step it goes on at: `cad order` puts it after. One that must be there first (it comes earlier in the order, it is one of the joined parts, or it is no step at all) fails by name with how far over the head it is; where a ball-end key tilted up to `hexkey.ball_end_tilt` (25°) clears it, it warns instead |
476
477
  | `fasten.load` | With `loads` or a motor's torque on the joint: what it holds up (the parts left with no other way to the first item, their masses, the loads hung on them, under the assembly's `gravity`, and the torque of a motor among them), shared between the screws as a group (`screwGroup` of `@rulecad/fixings`: shear by distance from the centroid, pull by a plane through it). The screw that takes the most is held against its proof load, the thread it is in against stripping, and the clamp against slipping, at its preload (`screwLoad`); the margin is how many times the load it holds, and under 2 it warns. With no `torque`, it says the torque that leaves the thread twice the load, within the seat, and `cad order` tightens to that. It names the estimates it rests on (the nut factor, a plastic's shear strength, the friction) |
477
478
 
@@ -514,7 +515,7 @@ draws its hole or pocket from the printer's rules:
514
515
  ```
515
516
 
516
517
  - **Pins** (`fit.pin`): a snap pin, a steel dowel, a length of filament or a printed pin. `cad check` finds round holes
517
- in part a whose axis goes on into part b, holds each to the hole fixings draws for that pin (a snap pin's socket, a
518
+ in part a, standing or lying on their side as teardrops (the roof is left out of the round), whose axis goes on into part b, holds each to the hole fixings draws for that pin (a snap pin's socket, a
518
519
  plain pin's press or slip hole), and measures the parts along the axis: a pin too long or too short for its parts
519
520
  fails by name, and so do fewer holes than `count`. `load` (across the joint) and `pull` (along the pins) are held
520
521
  to about twice the margin.
@@ -523,7 +524,9 @@ draws its hole or pocket from the printer's rules:
523
524
  their pull, across `gap` where something lies between.
524
525
  - **Printed bolts** are a fasten's: `"screw": "M8x20 hex printed"`. Below the printer's smallest thread it is refused
525
526
  by name (M5 at 0.2 mm layers names M6); its load is held to the plastic's strength by how it prints, and no wrench
526
- torque is said, since a printed thread is done up by hand.
527
+ torque is said, since a printed thread is done up by hand. Its length is any whole millimetre that fits, into a
528
+ slot nut too, where a bought screw is held to the lengths sold. A `torque` given for it is a turn by hand, held to
529
+ what the bolt breaks at (`fasten.torque`), and `cad order` says it as a turn to that torque and no further.
527
530
 
528
531
  `cad list` lists pins (printed, cut or bought) and magnets (bought) with their grams, and printed bolts among the
529
532
  printed parts; `cad order` names each on its step. A fastener given as text (`"fastener": "push pin"`) is listed as
@@ -1519,6 +1522,24 @@ A problem whose regions have a z is solid. It has no thickness, and takes more k
1519
1522
  Supports and loads can be any region; a force has x, y and z. `"overhang": "+z"` keeps only material that prints
1520
1523
  without supports standing that way up (a variable holding `"+z"` or `"none"` works too, so a variant can switch it).
1521
1524
 
1525
+ A part made another way says so in place of `overhang` (one process to a problem; two are refused by name):
1526
+ - **Milled:** `"mill": "+z"` (the tool cuts down from above). No undercuts: a cell is as solid as every cell
1527
+ between it and the tool. `cad optimise` says `milled from +z: no undercuts`, or counts the cells an avoid region
1528
+ or the space's own edge hides behind material. The `mill-3axis` rule set holds the walls, corners and pockets a 3-axis machine manages.
1529
+ - **Cast or moulded:** `"cast": "+z"` for a mould drawn off one way, or `"cast": { "draw": "z", "parting": 6 }` for
1530
+ two halves drawn off both ways from a parting plane (mm along the axis; the space's middle when left out). Draft
1531
+ (`mould-injection`: a degree or so) is less than a cell, so it is left to the drawing.
1532
+ - **Printed in a metal powder bed:** `"overhang": "+z"` with `"voids": "refused"`. Powder left in an enclosed void
1533
+ can't be got out, so `cad optimise` fails with each void's volume and centre: open it with an avoid region (an
1534
+ escape hole, `dmls.escape_hole` wide) or allow voids. The `dmls` rule set holds the process's limits.
1535
+
1536
+ Any of them can also be `"symmetry": { "mirror": "y" }` (mirrored across the grid's middle planes; `"turns": 2` or
1537
+ `4` about `"axis"` for half or quarter turns) or `"extrude": "x"` (one section all along x, a part cut from a bar).
1538
+ A mirror or turn that would swap the side the part is made from for its opposite is refused by name (a mould in two
1539
+ halves parted at the middle may be mirrored across its draw). With a process or a tie, `cad optimise` warns when more
1540
+ than a tenth of the design is grey (neither empty nor solid): the outline drawn is then a guess. A 2D section milled
1541
+ or cast across its own plane often comes out so; give the problem in 3D or make it from another side.
1542
+
1522
1543
  `cad optimise` draws the result's four views in `.preview/`. A design builds the result with
1523
1544
  `v.shapes.optimisedSolid(v.problems[v.problem], { ops: v.ops })`, which adds the keep regions and cuts the avoid
1524
1545
  regions exactly. The surface is a big mesh, so set the object's `"engine": "manifold"`. With `"overhang"` set, the
package/bin/cad.mjs CHANGED
@@ -255,7 +255,8 @@ async function optimiseProblem(ref) {
255
255
  const p = await readProblem(project, name), cells = r.dim === 3 ? `${r.grid.nx} × ${r.grid.ny} × ${r.grid.nz}` : `${r.grid.nx} × ${r.grid.ny}`;
256
256
  const lines = [`${p.material.name}${r.dim === 2 ? `, ${fmt(r.thickness)} mm thick` : ''}: ${r.cases.map((c) => c.moment ? `${c.name} ${sig(c.angle * 180 / Math.PI)}° (${sig(c.torsion / 1000 * Math.PI / 180)} N·m/°)` : `${c.name} ${sig(c.deflection)} mm (${sig(c.stiffness)} N/mm)`).join(', ')}`,
257
257
  `${fmt(r.volume * 100)}% of the space, ${cells} cells of ${fmt(r.grid.h)} mm, ${r.steps} steps${r.converged ? '' : ' (stopped: not settled)'}${r.overhang ? `, printable built ${r.overhang}` : ''}${r.stress ? `, peak stress ${sig(r.stress.peak)} MPa (limit ${sig(r.stress.limit)})` : ''}${r.dropped ? `; ${r.dropped.length} loose ${r.dropped.length === 1 ? 'piece' : 'pieces'} dropped (${sig(r.dropped.reduce((t, v) => t + v, 0))} mm³)` : ''}${r.emptied ? `; ${r.emptied} ${r.emptied === 1 ? 'cell' : 'cells'} that wouldn't print emptied` : ''}${r.cleared ? `; sliced as the printer will, ${r.cleared} ${r.cleared === 1 ? 'cell' : 'cells'} under islands emptied` : ''}`,
258
- ...(r.unsupported > 0.01 ? [`${fmt(r.unsupported * 100)}% of the kept regions has nothing holding it up (at ${r.overhang ? 'the printer\'s overhang limit' : '45°'} or less): give the part more material to stand them on, or keep less`] : [])];
258
+ ...(r.unsupported > 0.01 ? [`${fmt(r.unsupported * 100)}% of the kept regions has nothing holding it up (at ${r.overhang ? 'the printer\'s overhang limit' : '45°'} or less): give the part more material to stand them on, or keep less`] : []),
259
+ ...(r.process ? [processLine(r)] : []), ...(r.voids?.length ? [voidsLine(r)] : [])];
259
260
  let out;
260
261
  if (r.dim === 3) {
261
262
  out = paths.preview(project, `${name.replace(':', '-')}-optimised.png`);
@@ -274,8 +275,28 @@ async function optimiseProblem(ref) {
274
275
  if (r.dim === 3) console.log(` ${fmt(r.volume * 100)}% of the space filled: ${fmt(r.solid / 1000)} cm³ (${fmt(r.solid / 1000 * (p.material.density || 0))} g of ${p.material.name})${r.overhang ? `, printable built ${r.overhang}` : ''}`);
275
276
  else console.log(` ${fmt(r.volume * 100)}% of the space filled, outline ${fmt(r.area)} mm² (${fmt(r.area * r.thickness / 1000)} cm³ before bosses and holes are made exact)`);
276
277
  console.log(` ${cells} cells of ${fmt(r.grid.h)} mm, ${r.steps} steps${r.converged ? ', settled' : ': stopped before it settled (raise steps)'}`);
278
+ if (r.process) console.log(` ${processLine(r)}`);
279
+ if (r.symmetry || r.extrude) console.log(` ${[r.symmetry?.mirror ? `mirrored across ${[...r.symmetry.mirror].join(' and ')}` : '', r.symmetry?.turns ? `the same each ${r.symmetry.turns === 4 ? 'quarter' : 'half'} turn about ${r.symmetry.axis || 'z'}` : '', r.extrude ? `one section along ${r.extrude}` : ''].filter(Boolean).join(', ')}`);
280
+ if (r.grey > 0.1) console.log(` warning: ${greyLine(r)}`);
281
+ if (r.voids?.length) { console.log(` error: ${voidsLine(r)}`); process.exitCode = 1; }
277
282
  console.log(out);
278
283
  }
284
+ // How a milled or cast result is made, and its undercuts (none, unless an avoid region or the space's own shape sits
285
+ // behind material: the optimiser keeps every cell as solid as those on its way out, but can't fill a cell it mustn't)
286
+ function processLine(r) {
287
+ const how = r.process.mill ? `milled from ${r.process.mill}` : typeof r.process.cast === 'string' ? `cast, drawn off ${r.process.cast}` : `cast in two halves drawn off along ${r.process.cast.draw} from ${fmt(r.process.cast.parting)} mm`;
288
+ return r.undercuts ? `${how}: ${r.undercuts} ${r.undercuts === 1 ? 'cell is' : 'cells are'} undercut (an avoid region, or the edge of the space, with material between it and the ${r.process.mill ? 'tool' : 'draw'}: move it, or make it from that side)` : `${how}: no undercuts`;
289
+ }
290
+ // A grey result (warned of above a tenth): its design cells between a tenth and nine tenths solid. A clear design has
291
+ // a few per cent, on its surfaces (the 3D cantilever milled from above 5.3%, free 2D cantilevers 1 to 3%): a tenth
292
+ // is a choice from those, an estimate
293
+ function greyLine(r) {
294
+ return `${fmt(r.grey * 100)}% of the design is grey (neither empty nor solid): the outline drawn at half density is a guess, not a part. A section milled, cast or extruded across its own plane often comes out so; give the problem in 3D, make it from another side, or allow more steps`;
295
+ }
296
+ // Enclosed voids, refused by the problem (powder that can't get out, a trapped core)
297
+ function voidsLine(r) {
298
+ return `${r.voids.length} enclosed ${r.voids.length === 1 ? 'void' : 'voids'} (${r.voids.map((v) => `${sig(v.volume)} ${r.dim === 3 ? 'mm³' : 'mm²'} at ${v.at.map(fmt).join(', ')}`).join('; ')}): powder or a core can't get out: open ${r.voids.length === 1 ? 'it' : 'each'} to the outside with an avoid region (an escape hole), or allow voids`;
299
+ }
279
300
 
280
301
  // An object's analyses for cad check: each problem's load cases on the part, and its volume against a target
281
302
  function place(triangles, [rx, ry, rz], move) {
package/lib/fasten.mjs CHANGED
@@ -767,11 +767,14 @@ export function fastenOf(s, worlds, opts = {}) {
767
767
  sc.grip = r3(grip);
768
768
  let pick = null, none = null, need = null;
769
769
  if (end.slot) { // the shortest sold length with a hex nut's height of thread in the slot nut, its tip short of the slot's floor
770
- const sold = fx.figures.lengths?.value || [], hexH = fx.figures.nut_height?.value;
770
+ const hexH = fx.figures.nut_height?.value;
771
771
  need = r3(hexH ? Math.min(end.thread, hexH) : end.thread);
772
- const lo = end.zThr + need - zHead, hi = end.floor - FASTEN.floor.value - zHead, L0 = sold.find((l) => l >= lo - EPS && l <= hi + EPS);
772
+ const lo = end.zThr + need - zHead, hi = end.floor - FASTEN.floor.value - zHead;
773
+ // (a printed bolt is printed to any whole millimetre: every one from the shortest up is "sold")
774
+ const sold = fx.printed ? Array.from({ length: Math.max(0, Math.floor(hi + EPS) - Math.ceil(lo - EPS) + 1) }, (_, i) => Math.ceil(lo - EPS) + i) : fx.figures.lengths?.value || [], L0 = sold.find((l) => l >= lo - EPS && l <= hi + EPS);
773
775
  end.need = need; end.window = [r3(lo), r3(hi)];
774
776
  if (L0) pick = { name: F.screwModel(fx, { length: L0, head: form }).name, length: L0, engaged: r3(Math.min(end.thread, zHead + L0 - end.zThr)), spare: r3(end.floor - zHead - L0) };
777
+ else if (fx.printed) none = `no whole millimetre from ${mm2(lo)} to ${mm2(hi)} mm is a length for the printed bolt: ${mm2(grip)} mm under its head (${end.slot.part}${washer ? ', the washer' : ''} and ${lipSays(end.slot)}) leaves ${mm2(hi - lo)} mm between ${mm2(need)} mm in the nut and ${mm2(FASTEN.floor.value)} mm kept off the slot's floor. A part of another thickness, or a washer under the head`;
775
778
  else none = `no ${fx.thread} ${form} screw is sold from ${mm2(lo)} to ${mm2(hi)} mm long, what ${mm2(grip)} mm under its head (${end.slot.part}${washer ? ', the washer' : ''} and ${lipSays(end.slot)}) leaves: ${mm2(need)} mm in the nut and ${mm2(FASTEN.floor.value)} mm kept off the slot's floor (${(sold.filter((l) => l < lo - EPS).at(-1) ?? null) != null ? `${fx.thread}x${sold.filter((l) => l < lo - EPS).at(-1)} engages too little, ` : ''}${sold.find((l) => l > hi + EPS) != null ? `${fx.thread}x${sold.find((l) => l > hi + EPS)} reaches the floor` : 'none is that long'}). A part of another thickness, or a washer under the head`;
776
779
  } else if (end.motor && form !== 'set') { // the longest sold length that stops short of the motor's thread's end, as motor.mount chooses
777
780
  const sold = fx.figures.lengths?.value || [], room = end.depth - (end.motor.reach ? 0 : tipRoom), L0 = [...sold].reverse().find((l) => l > grip + EPS && l - grip <= room + (end.motor.reach ? READ : EPS)); // (a maker's reach is the limit itself: no room kept past it, the mesh's grid allowed)
@@ -801,7 +804,7 @@ export function fastenOf(s, worlds, opts = {}) {
801
804
  const lenValues = { length: L, grip: r3(grip), into: r3(inEnd) }, under = `${mm2(grip)} mm under its head${washer ? ' (its washer with it)' : ''}`;
802
805
  const wouldDo = pick && pick.length !== L ? `${pick.name} would do` : null;
803
806
  if (given == null) {
804
- if (pick && end.slot) say('fasten.length', 'pass', `${pick.name} chosen, the shortest sold that fits: ${under} (${end.slot.part}${washer ? ', the washer' : ''} and ${lipSays(end.slot)}), ${mm2(pick.engaged)} mm into its nut, its tip ${mm2(zTip - end.mouth)} mm into the slot and ${mm2(pick.spare)} mm short of its floor`, { ...lenValues, floor: r3(pick.spare) });
807
+ if (pick && end.slot) say('fasten.length', 'pass', `${pick.name} chosen, the shortest ${fx.printed ? 'that fits (a printed bolt is printed to any whole millimetre)' : 'sold that fits'}: ${under} (${end.slot.part}${washer ? ', the washer' : ''} and ${lipSays(end.slot)}), ${mm2(pick.engaged)} mm into its nut, its tip ${mm2(zTip - end.mouth)} mm into the slot and ${mm2(pick.spare)} mm short of its floor`, { ...lenValues, floor: r3(pick.spare) });
805
808
  else if (pick) say('fasten.length', 'pass', `${pick.name} chosen, the ${end.motor ? (end.motor.reach ? 'longest sold that goes no further than its maker allows' : 'longest sold that stops short of the end of the thread') : fx.printed ? 'shortest that fits (a printed bolt is printed to any whole millimetre)' : 'shortest sold that fits'}: ${under} and ${mm2(pick.engaged)} mm into ${x.into}${end.kind === 'nut' ? '\'s nut' : ''}${pick.spare != null ? `, ${mm2(pick.spare)} mm short of bottoming out` : ''}`, lenValues);
806
809
  else if (none) say('fasten.length', 'fail', `no length chosen: ${none}`, lenValues);
807
810
  else if (form !== 'set') say('fasten.length', 'info', `no length chosen until the far end is one a screw holds in: ${model.name} is drawn`, lenValues);
@@ -872,14 +875,22 @@ export function fastenOf(s, worlds, opts = {}) {
872
875
  if (!st) say('fasten.seat', 'pass', `${where}${seatMat.name ? ` (no strength is known for ${seatMat.name}, so the pressure under it is not checked)` : ''}`, values);
873
876
  else {
874
877
  const D2 = st.head === 'hex' ? head.across * Math.cos(Math.PI / 6) : head.across, area = (d) => (Math.PI / 4) * (d * d - (2 * boreR) ** 2), bare = area(D2), onWasher = st.washer ? area(st.washer.diameter) : null, mine = washer ? onWasher : bare;
875
- const takes = st.limit * mine, K = DEFAULTS.nut_factor.value, torqueOf = (N) => (K * fx.major * N) / 1000, v2 = { ...values, area: +mine.toFixed(2), limit: st.limit, force: +takes.toFixed(1), torque: +torqueOf(takes).toFixed(3) };
878
+ const takes = st.limit * mine, K = DEFAULTS.nut_factor.value, torqueOf = (N) => (K * fx.major * N) / 1000, v2 = { ...values, area: +mine.toFixed(2), limit: st.limit, force: +takes.toFixed(1), ...(fx.printed ? {} : { torque: +torqueOf(takes).toFixed(3) }) }; // (a printed bolt: no tightening torque)
876
879
  if (!fx.printed) { sc.most = +torqueOf(takes).toFixed(2); sc.seatForce = takes; } // (a printed bolt is done up by hand: no torque to tighten to)
877
880
  if (torque == null && fx.printed) say('fasten.seat', 'pass', `${where}; on ${st.material} (${mm(st.limit)} MPa) its ${mm(+mine.toFixed(1))} mm² takes ${mm(+takes.toFixed(0))} N. A printed bolt is done up by hand, with no torque to tighten to`, v2);
878
881
  else if (torque == null) say('fasten.seat', 'pass', `${where}; on ${st.material} (${mm(st.limit)} MPa) its ${mm(+mine.toFixed(1))} mm² takes ${mm(+takes.toFixed(0))} N, a tightening of ${mm(+torqueOf(takes).toFixed(2))} N m${!washer && onWasher && sunk <= 0.01 ? `: the ${fx.thread} washer would raise that to ${mm(+(st.limit * onWasher).toFixed(0))} N (${mm(+torqueOf(st.limit * onWasher).toFixed(2))} N m)` : ''}`, v2);
879
882
  else {
880
883
  const p = st.force / mine, within = p <= st.limit + 1e-9, pw = onWasher ? st.force / onWasher : null;
881
- if (within) say('fasten.seat', 'pass', `${where}; at ${mm(torque)} N m the screw clamps with ${mm(st.force)} N, ${mm(+p.toFixed(1))} MPa under the ${washer ? 'washer' : 'head'} on ${st.material}, whose strength is ${mm(st.limit)} MPa`, { ...v2, pressure: +p.toFixed(1) });
882
- else say('fasten.seat', 'fail', `at ${mm(torque)} N m the screw clamps with ${mm(st.force)} N: ${mm(+p.toFixed(1))} MPa under the ${washer ? 'washer' : 'head'} on ${st.material}, whose strength is ${mm(st.limit)} MPa. ${!washer && pw != null && pw <= st.limit && sunk <= 0.01 ? `The ${fx.thread} washer, ${mm(st.washer.diameter)} mm across, brings it to ${mm(+pw.toFixed(1))} MPa, within: give "washer": true` : `The seat takes ${mm(+takes.toFixed(0))} N (${mm(+torqueOf(takes).toFixed(2))} N m): tighten to that, or spread the load wider`}`, { ...v2, pressure: +p.toFixed(1), ...(pw != null ? { washer: +pw.toFixed(1) } : {}) });
884
+ // A printed bolt turned to a torque by hand: the clamp is T = K d F with steel's nut factor, an estimate for a
885
+ // plastic thread, and held against what the bolt itself breaks at, since a printed bolt breaks long before a seat gives
886
+ const turned = fx.printed ? `turned by hand to ${mm(torque)} N m, it clamps with about ${mm(st.force)} N (T = K d F, fixings.nut_factor ${mm(K)} for steel threads: an estimate for a printed one)` : null;
887
+ if (fx.printed) {
888
+ const bolt = F.printedBoltModel(fx, { length: L, head: form, material, nut: boltMate(sc) }), want = DEFAULTS.load_margin.value, ok = st.force * want <= bolt.breaking + 1e-9, safe = Math.floor(torqueOf(bolt.breaking / want) * 100 + 1e-9) / 100; // (down to the hundredth: rounded up, the most named would fail its own check)
889
+ say('fasten.torque', ok ? 'pass' : st.force <= bolt.breaking ? 'warn' : 'fail', `${turned}: ${ok ? `${mm(+(bolt.breaking / st.force).toFixed(2))} times under the ${mm(bolt.breaking)} N it breaks at (${bolt.governs})` : `${st.force <= bolt.breaking ? `under the ${mm(bolt.breaking)} N it breaks at (${bolt.governs}), but not ${mm(want)} times (fixings.load_margin)` : `more than the ${mm(bolt.breaking)} N it breaks at (${bolt.governs}): turning it that far breaks it`}. Turn it to ${mm(safe)} N m at most, or snug by hand with no torque given`}`,
890
+ { torque, force: st.force, breaking: bolt.breaking, margin: +(bolt.breaking / st.force).toFixed(2), most: safe });
891
+ }
892
+ if (within) say('fasten.seat', 'pass', `${where}; ${turned ?? `at ${mm(torque)} N m the screw clamps with ${mm(st.force)} N`}, ${mm(+p.toFixed(1))} MPa under the ${washer ? 'washer' : 'head'} on ${st.material}, whose strength is ${mm(st.limit)} MPa`, { ...v2, pressure: +p.toFixed(1) });
893
+ else say('fasten.seat', 'fail', `${turned ?? `at ${mm(torque)} N m the screw clamps with ${mm(st.force)} N`}: ${mm(+p.toFixed(1))} MPa under the ${washer ? 'washer' : 'head'} on ${st.material}, whose strength is ${mm(st.limit)} MPa. ${!washer && pw != null && pw <= st.limit && sunk <= 0.01 ? `The ${fx.thread} washer, ${mm(st.washer.diameter)} mm across, brings it to ${mm(+pw.toFixed(1))} MPa, within: give "washer": true` : `The seat takes ${mm(+takes.toFixed(0))} N (${mm(+torqueOf(takes).toFixed(2))} N m): ${fx.printed ? 'turn it no further than that' : 'tighten to that'}, or spread the load wider`}`, { ...v2, pressure: +p.toFixed(1), ...(pw != null ? { washer: +pw.toFixed(1) } : {}) });
883
894
  }
884
895
  }
885
896
  }
@@ -920,7 +931,7 @@ export function fastenOf(s, worlds, opts = {}) {
920
931
  for (const h of hardware.filter((o) => o.fasten === k)) names.set(h.name, (names.get(h.name) ?? 0) + 1);
921
932
  // the screws' lines carry the key that turns them and how tight: the torque given, or the most the seat under the head takes
922
933
  const keys = [...new Set(rel.screws.map((sc) => sc.tool).filter(Boolean))], most = rel.screws.map((sc) => sc.most).filter((t) => t != null);
923
- const tighten = torque != null ? { torque, given: true } : most.length ? { torque: Math.min(...most), given: false } : null;
934
+ const tighten = torque != null ? { torque, given: true, ...(fx.printed ? { hand: true } : {}) } : most.length ? { torque: Math.min(...most), given: false } : null;
924
935
  const lines = [...names].map(([fastener, n]) => ({ fastener, count: n, ...(rel.screws.some((sc) => sc.model?.name === fastener) ? { ...(keys.length ? { key: keys.join(' or ') } : {}), ...(tighten ? { tighten } : {}) } : {}) }));
925
936
  through.forEach((t, j) => fits.push({ a: t, b: slotAt ? slotAt.item : x.into, fastens: true, silent: true, fasten: k, note: x.note || `${t} fastened to ${x.into}`, ...(j === 0 && lines[0] ? lines[0] : {}) }));
926
937
  if (!through.length && lines[0]) fits.push({ a: x.into, b: x.into, silent: true, fasten: k, note: label, ...lines[0] });
@@ -1026,7 +1037,7 @@ export function hardwarePart(h, hostWorld) {
1026
1037
  hardware: { kind: h.kind, name: h.name, fasten: h.fasten, screw: h.screw, thread: h.thread, grams: h.grams, from: h.label, length: h.length, head: h.head, ...(h.printed ? { printed: true } : {}) }, moves: h.hostItem, with: h.with, lift, allow: h.allow };
1027
1038
  }
1028
1039
 
1029
- const CODES = ['fasten.holes', 'fasten.slot', 'fasten.clearance', 'fasten.end', 'fasten.length', 'fasten.engagement', 'fasten.seat', 'fasten.access'];
1040
+ const CODES = ['fasten.holes', 'fasten.slot', 'fasten.clearance', 'fasten.end', 'fasten.length', 'fasten.engagement', 'fasten.seat', 'fasten.torque', 'fasten.access'];
1030
1041
  // fasten.access for one screw, with the order of assembly: a part over the head that goes on later is no trouble
1031
1042
  function accessSays(sc, rel, order, numbered = null) {
1032
1043
  const acc = sc.access, t = acc.tool, values = { key: t.size, radius: t.radius, reach: t.reach };
package/lib/optimise.mjs CHANGED
@@ -11,7 +11,7 @@ import { host, readJson } from './host.mjs';
11
11
  import { paths, printerOf } from './workspace.mjs';
12
12
  import { resolve, evaluate } from './rules.mjs';
13
13
  import { located } from './errors.mjs';
14
- import { discretise, optimise, outlines, surface, area, bounds, resultant, printable, refine, despike } from '@rulecad/topopt';
14
+ import { discretise, optimise, outlines, surface, area, bounds, resultant, printable, refine, despike, undercuts, voids, grey } from '@rulecad/topopt';
15
15
  import { islands } from '@rulecad/printcheck';
16
16
  import { threadsBackend } from '@rulecad/fea/threads'; // the solver's products shared over the machine's cores
17
17
  import { grid as makeGrid, analyse, positions } from '@rulecad/fea';
@@ -77,6 +77,9 @@ export async function readProblem(project, ref) {
77
77
  ...(p.filter != null ? { filter: ev(p.filter) } : {}), ...(p.penal != null ? { penal: ev(p.penal) } : {}),
78
78
  ...(p.projection != null ? { projection: p.projection } : {}), ...(p.steps != null ? { steps: p.steps } : {}),
79
79
  ...(overhang && overhang !== 'none' ? { overhang } : {}),
80
+ // How it's made other than printed: milled from a side, cast in a mould; symmetric, extruded (topopt's filters)
81
+ ...(p.mill ? { mill: p.mill } : {}), ...(p.cast ? { cast: typeof p.cast === 'string' ? p.cast : { draw: p.cast.draw, ...(p.cast.parting != null ? { parting: ev(p.cast.parting) } : {}) } } : {}),
82
+ ...(p.symmetry ? { symmetry: p.symmetry } : {}), ...(p.extrude ? { extrude: p.extrude } : {}),
80
83
  // A mechanism: where the output should move, along one axis, against a spring; a spring the input pushes against
81
84
  ...(p.output ? { output: { ...(await region(p.output)), direction: pt(p.output.direction), ...(p.output.spring != null ? { spring: ev(p.output.spring) } : {}) } } : {}),
82
85
  ...(p.input_spring != null ? { input_spring: ev(p.input_spring) } : {}),
@@ -87,7 +90,7 @@ export async function readProblem(project, ref) {
87
90
  // (outline.tip: faces the smoothing left steeper than the limit are tipped back to it too; off unless asked, since
88
91
  // tipped corners leave dips that slice as islands, and the layers step out no further for it)
89
92
  if (dim === 3 && problem.overhang) { const n = printerOf(project), pr = resolve({ uses: [n] }).values[n]; outline.overhang = { up: problem.overhang, angle: pr?.overhang ?? 45, bridge: pr?.bridge ?? 5, layer: pr?.layer ?? 0.2, line: pr?.line ?? 0.42, ...(p.outline?.tip ? { tip: true } : {}) }; problem.bridge = outline.overhang.bridge; } // (the optimiser bridges half that)
90
- return { ref, name, variant, file, dim, title: p.title || name, material: { name: p.material, ...m }, problem, outline, critical: !!p.critical };
93
+ return { ref, name, variant, file, dim, title: p.title || name, material: { name: p.material, ...m }, problem, outline, critical: !!p.critical, voids: p.voids || 'allowed' };
91
94
  }
92
95
 
93
96
  /**
@@ -105,6 +108,23 @@ function holdEmpty(spec) {
105
108
  for (let m = 0; m < g.nodes; m++) if (!on[m]) for (let a = 0; a < dim; a++) spec.fixed[dim * m + a] = 1;
106
109
  return spec;
107
110
  }
111
+ // How a result is made, and what that process can't make in it: for a milled or cast part, the cells a tool or mould
112
+ // half could not reach (undercuts, none by construction unless an avoid region or the space's own shape leaves material between a cell and its side), how grey it is; where enclosed voids are
113
+ // refused (a powder bed print, a trapped core), each void with its volume (mm³, or mm² in 2D) and where it is
114
+ function made(r, spec, density) {
115
+ const p = r.problem, out = {};
116
+ if (p.mill || p.cast) {
117
+ const c = spec.cast, from = p.mill || (typeof c === 'string' ? c : c.draw), u = undercuts(spec.grid, density, { from, ...(c && typeof c === 'object' ? { parting: c.parting } : {}) });
118
+ out.process = p.mill ? { mill: p.mill } : { cast: typeof c === 'string' ? c : { draw: c.draw, parting: round(c.at, 3) } };
119
+ out.undercuts = u.count;
120
+ }
121
+ if (p.symmetry) out.symmetry = p.symmetry;
122
+ if (p.extrude) out.extrude = p.extrude;
123
+ // How grey it came out: a process or a tie can leave no clear part (a 2D section milled from its side)
124
+ if (p.mill || p.cast || p.symmetry || p.extrude) out.grey = round(grey(density, spec.passive), 3);
125
+ if (r.voids === 'refused') out.voids = voids(spec.grid, density, { origin: spec.origin }).map((v) => ({ volume: round(v.volume, 3), at: v.at.map((x) => round(x, 3)) }));
126
+ return out;
127
+ }
108
128
  const digest = (x) => crypto.createHash('sha256').update(JSON.stringify(x)).digest('hex');
109
129
  /**
110
130
  * The code an optimisation's densities are made by, each piece by name: this file's VERSION, topopt's solver (its file
@@ -126,7 +146,7 @@ export async function optimised(project, ref, { onStep, onRun, fresh = false } =
126
146
  // Two keeps: the densities, by the problem and the code that decides them (the slow part), and the shape drawn from
127
147
  // them, by everything: a change to how shapes are drawn redraws them without optimising again
128
148
  // The shape's key holds this file too, so a change to how cad draws a result (anchored below) redraws it
129
- const hash = digest([VERSION, r.problem, r.outline, topopt, source('@rulecad/fea'), fs.readFileSync(new URL(import.meta.url), 'utf8')]), file = paths.cache('optimise', `${hash}.json`);
149
+ const hash = digest([VERSION, r.problem, r.outline, r.voids, topopt, source('@rulecad/fea'), fs.readFileSync(new URL(import.meta.url), 'utf8')]), file = paths.cache('optimise', `${hash}.json`);
130
150
  if (!fresh && !process.env.CAD_NO_CACHE && host.exists(file)) return { ...JSON.parse(host.readText(file)), cached: true };
131
151
  const spec = holdEmpty(discretise(r.problem)), densities = paths.cache('densities', `${densitiesKey(r.problem)}.json`);
132
152
  // A mark that this problem has been optimised before (by any solver), so a run can say whether it's the solver that changed
@@ -206,6 +226,7 @@ export async function optimised(project, ref, { onStep, onRun, fresh = false } =
206
226
  const result = {
207
227
  problem: ref, title: r.title, hash, dim: r.dim, material: r.material.name, ...(r.dim === 2 ? { thickness: r.problem.thickness } : {}),
208
228
  grid: spec.grid, origin: spec.origin, regions: { keep: named(spec.regions.keep), avoid: named(spec.regions.avoid) }, ...shape,
229
+ ...made(r, spec, o.density),
209
230
  volume: o.volume, compliance: o.compliance, cases: o.cases, ...(o.unsupported ? { unsupported: o.unsupported } : {}), ...(o.mechanism ? { mechanism: o.mechanism } : {}), ...(o.stress ? { stress: o.stress } : {}), overhang: r.problem.overhang || null,
210
231
  steps: o.steps, converged: o.converged, seconds: o.seconds, history: o.history, density: Array.from(o.density, (d) => round(d, 3)),
211
232
  supports: named(r.problem.supports), loads: named(r.problem.loads),
package/lib/order.mjs CHANGED
@@ -238,7 +238,7 @@ export function assemblyOrder(s) {
238
238
  }
239
239
 
240
240
  /** One fastening of a step as the order and the build page say it: the fit, its screws by count and name, the key and how tight. */
241
- export const fastenerText = (f) => `${f.fit}${f.fastener ? ` (${f.count != null ? `${f.count} × ` : ''}${f.fastener})` : ''}${f.key ? ` with ${/^[aeiou8]/i.test(f.key) ? 'an' : 'a'} ${f.key}` : ''}${f.tighten ? `, ${f.tighten.given ? `to ${f.tighten.torque} N m` : f.tighten.load ? `to ${f.tighten.torque} N m (what the joint's load leaves the thread)` : `to ${f.tighten.torque} N m at most (what the seat takes)`}` : ''}`;
241
+ export const fastenerText = (f) => `${f.fit}${f.fastener ? ` (${f.count != null ? `${f.count} × ` : ''}${f.fastener})` : ''}${f.key ? ` with ${/^[aeiou8]/i.test(f.key) ? 'an' : 'a'} ${f.key}` : ''}${f.tighten ? `, ${f.tighten.hand ? `to ${f.tighten.torque} N m and no further (a printed bolt, turned by hand, not tightened)` : f.tighten.given ? `to ${f.tighten.torque} N m` : f.tighten.load ? `to ${f.tighten.torque} N m (what the joint's load leaves the thread)` : `to ${f.tighten.torque} N m at most (what the seat takes)`}` : ''}`;
242
242
 
243
243
  // Cached by what the parts are and where they are, with everything else that changes the answer (a motor's screw
244
244
  // names the tool its step gives)
package/lib/pins.mjs CHANGED
@@ -70,7 +70,8 @@ export function pinFit(x, s, f) {
70
70
  const holes = segs.filter((g) => g.hole), size = (g) => (g.a.loop?.shape === 'round' && g.a.loop.d != null ? Math.min(g.a.loop.d, g.b.loop?.d ?? Infinity) : 2 * Math.min(g.a.free, g.b.free));
71
71
  return { lo: segs[0].z0, hi: segs.at(-1).z1, segs, hole: holes.length ? Math.min(...holes.map(size)) : null, solidAt: segs.find((g) => g.solid) ?? null };
72
72
  };
73
- // The pins' places: round holes in a about the pin's hole, standing on an axis that goes on into b
73
+ // The pins' places: round holes in a about the pin's hole (a teardrop lying on its side is one: holesIn leaves its
74
+ // roof out of the round), on an axis that goes on into b
74
75
  const axes = [];
75
76
  for (const q of A) for (const h of holesIn(q)) {
76
77
  if (Math.abs(h.d - m0.hole.diameter) > LOOK && !wanted.some((w) => Math.abs(h.d - w.diameter) <= LOOK)) continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulecad/cad",
3
- "version": "0.7.69",
3
+ "version": "0.7.75",
4
4
  "description": "The cad command: JSCAD designs from traceable rules, checked for printing and fit, versioned by what fits, shared as links and exported as Bambu 3MF.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -65,17 +65,17 @@
65
65
  "@rulecad/model-link": "^0.3.2",
66
66
  "@rulecad/versions": "^0.1.6",
67
67
  "@rulecad/shapes": "^0.4.6",
68
- "@rulecad/rules": "^0.3.19",
68
+ "@rulecad/rules": "^0.3.22",
69
69
  "@jscad/modeling": "^2.12.0",
70
70
  "three": "^0.186.1",
71
71
  "@rulecad/fea": "^0.2.11",
72
- "@rulecad/topopt": "^0.3.0",
72
+ "@rulecad/topopt": "^0.3.4",
73
73
  "@rulecad/flexures": "^0.5.4",
74
74
  "@rulecad/gears": "^0.3.4",
75
75
  "@rulecad/motors": "^0.1.6",
76
- "@rulecad/fixings": "^0.1.5",
76
+ "@rulecad/fixings": "^0.1.7",
77
77
  "@rulecad/robots": "^0.1.3",
78
- "@rulecad/frames": "^0.1.11"
78
+ "@rulecad/frames": "^0.1.12"
79
79
  },
80
80
  "peerDependencies": {
81
81
  "@rulecad/pcb": "^0.1.0 || ^0.2.0 || ^0.3.0 || ^0.4.0 || ^0.5.0"
@@ -174,7 +174,7 @@
174
174
  "nut": { "anyOf": [{ "type": "boolean" }, { "type": "string" }], "description": "What holds the screw where the part it ends in does not: true or hex, square, lock. It sits on that part's far face, or in a nut's seat drawn there. Into a beam's slot, the slot nut's kind: slide-in, drop-in, roll-in, hammer, square or t-bolt (left out, the strongest made for the slot). A slide-in or square nut enters only from an open end of the slot (frame.nut, frame.preload)" },
175
175
  "washer": { "type": "boolean", "description": "A plain washer under the head" },
176
176
  "length": { "$ref": "#/$defs/expr", "description": "The screw's length in mm, where the name gives none: checked for reaching, bottoming out and standing proud" },
177
- "torque": { "$ref": "#/$defs/expr", "description": "The tightening torque, N m: the pressure under the head is then held against the material it sits on (fasten.seat)" },
177
+ "torque": { "$ref": "#/$defs/expr", "description": "The tightening torque, N m: the pressure under the head is then held against the material it sits on (fasten.seat); for a printed bolt, the turn by hand, held against what the bolt breaks at (fasten.torque)" },
178
178
  "note": { "type": "string" }
179
179
  }
180
180
  },
@@ -155,6 +155,44 @@
155
155
  "type": "string",
156
156
  "description": "3D: printable this way up ('+z', '-y', …), or a variable holding it, or 'none': only material supported from below at 45° or less"
157
157
  },
158
+ "symmetry": {
159
+ "type": "object",
160
+ "additionalProperties": false,
161
+ "description": "The same either side of the grid's middle planes, and each half or quarter turn about its middle. The grid is centred on the space and keep regions (in 3D, except along an overhang's build direction). Keep and avoid regions stay as given. A mirror or turn that would swap the side a part is milled from, the way a mould is drawn off or the build direction for its opposite (or a quarter turn that moves it onto another axis) is refused by name; a mould in two halves parted at the grid's middle can be mirrored or half turned across its draw.",
162
+ "properties": {
163
+ "mirror": { "type": "string", "pattern": "^[xyz]{1,3}$", "description": "The axes mirrored across: 'x', 'xy', 'xyz' (2D: x and y)" },
164
+ "turns": { "enum": [2, 4], "description": "The same each half turn (2) or quarter turn (4) about the middle; a quarter turn needs the grid as wide both ways across its axis" },
165
+ "axis": { "enum": ["x", "y", "z"], "description": "3D: the axis turns are about (default z)" }
166
+ }
167
+ },
168
+ "extrude": {
169
+ "enum": ["x", "y", "z"],
170
+ "description": "One section all along this axis: a part cut from a bar, an extrusion or a plate of the profile"
171
+ },
172
+ "mill": {
173
+ "type": "string",
174
+ "pattern": "^[+-][xyz]$",
175
+ "description": "Milled from this side ('+z': the tool cuts down from above): no undercuts, so a cell is as solid as every cell between it and the tool. Not with overhang or cast. Rules: mill-3axis"
176
+ },
177
+ "cast": {
178
+ "description": "Cast or moulded: in a mould drawn off one way ('+z'), or in two halves drawn off both ways along an axis from a parting plane. No undercuts from the draw; draft is left to the drawing. Not with overhang or mill. Rules: mould-injection",
179
+ "oneOf": [
180
+ { "type": "string", "pattern": "^[+-][xyz]$" },
181
+ {
182
+ "type": "object",
183
+ "additionalProperties": false,
184
+ "required": ["draw"],
185
+ "properties": {
186
+ "draw": { "enum": ["x", "y", "z"], "description": "The axis the halves are drawn off along" },
187
+ "parting": { "$ref": "#/$defs/expr", "description": "The parting plane, mm along draw (default the space's middle)" }
188
+ }
189
+ }
190
+ ]
191
+ },
192
+ "voids": {
193
+ "enum": ["allowed", "refused"],
194
+ "description": "Enclosed voids in the result: allowed (the default), or refused, for metal powder bed printing (powder left inside can't be got out) or a casting's trapped core: cad optimise then reports each as an error with its volume and where it is. Rules: dmls"
195
+ },
158
196
  "output": {
159
197
  "type": "object",
160
198
  "additionalProperties": false,