@rulecad/cad 0.8.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/AGENTS.md +45 -16
  2. package/CHANGELOG.md +724 -0
  3. package/EXAMPLES.md +61 -54
  4. package/README.md +376 -98
  5. package/TUTORIAL.md +2 -2
  6. package/bin/cad.mjs +2664 -541
  7. package/lib/animate.mjs +173 -49
  8. package/lib/assembly.mjs +1883 -435
  9. package/lib/beams.mjs +256 -52
  10. package/lib/belts.mjs +66 -15
  11. package/lib/board-work.mjs +12 -0
  12. package/lib/bought.mjs +309 -53
  13. package/lib/buildpage.mjs +179 -29
  14. package/lib/cache-file.mjs +105 -0
  15. package/lib/carried.mjs +201 -0
  16. package/lib/clone.mjs +194 -42
  17. package/lib/code-text.mjs +28 -0
  18. package/lib/design-imports.mjs +127 -0
  19. package/lib/design.mjs +871 -147
  20. package/lib/designshapes.mjs +142 -0
  21. package/lib/drive.mjs +187 -63
  22. package/lib/edit.mjs +922 -192
  23. package/lib/errors.mjs +16 -3
  24. package/lib/estimates.mjs +51 -0
  25. package/lib/explain.mjs +62 -13
  26. package/lib/fasten.mjs +2708 -507
  27. package/lib/fe-key.mjs +29 -0
  28. package/lib/fittings.mjs +721 -122
  29. package/lib/fixings.mjs +38 -13
  30. package/lib/framebuild.mjs +790 -175
  31. package/lib/framecheck.mjs +1901 -368
  32. package/lib/framegen.mjs +108 -22
  33. package/lib/frameheat.mjs +225 -42
  34. package/lib/frameprint.mjs +513 -108
  35. package/lib/frames.mjs +86 -18
  36. package/lib/framesize.mjs +719 -120
  37. package/lib/frametip.mjs +235 -0
  38. package/lib/gait.mjs +135 -23
  39. package/lib/grip.mjs +62 -13
  40. package/lib/guides.mjs +1403 -230
  41. package/lib/host.mjs +129 -23
  42. package/lib/inplace.mjs +171 -36
  43. package/lib/jigs.mjs +360 -78
  44. package/lib/joins.mjs +697 -118
  45. package/lib/jsonedit.mjs +88 -26
  46. package/lib/kept.mjs +84 -0
  47. package/lib/kit.mjs +439 -69
  48. package/lib/layout.mjs +2 -1
  49. package/lib/links.mjs +149 -42
  50. package/lib/list.mjs +334 -64
  51. package/lib/live-guard.mjs +68 -0
  52. package/lib/live-shape.mjs +96 -24
  53. package/lib/live.mjs +189 -59
  54. package/lib/loads.mjs +597 -136
  55. package/lib/machine.mjs +372 -74
  56. package/lib/magnets.mjs +162 -44
  57. package/lib/measured.mjs +1080 -117
  58. package/lib/mesh.mjs +526 -119
  59. package/lib/meshcmd.mjs +215 -60
  60. package/lib/motors.mjs +1002 -214
  61. package/lib/motorsvg.mjs +114 -32
  62. package/lib/names.mjs +18 -1
  63. package/lib/optimise.mjs +991 -287
  64. package/lib/order.mjs +515 -114
  65. package/lib/panels.mjs +482 -94
  66. package/lib/parts.mjs +81 -23
  67. package/lib/pins.mjs +163 -44
  68. package/lib/plates.mjs +223 -35
  69. package/lib/player.mjs +37 -9
  70. package/lib/power.mjs +64 -13
  71. package/lib/preview.mjs +83 -16
  72. package/lib/profilemeasure.mjs +572 -129
  73. package/lib/rules.mjs +17 -6
  74. package/lib/sandbox-hooks.mjs +179 -27
  75. package/lib/sandbox-lock.mjs +225 -0
  76. package/lib/sandbox-preload.mjs +2 -2
  77. package/lib/sandbox-run.mjs +122 -25
  78. package/lib/sandbox.mjs +667 -75
  79. package/lib/schema.mjs +42 -11
  80. package/lib/seats.mjs +227 -49
  81. package/lib/services.mjs +261 -52
  82. package/lib/sheet.mjs +963 -179
  83. package/lib/slotnuts.mjs +213 -34
  84. package/lib/targets/gist.mjs +4 -1
  85. package/lib/targets.mjs +22 -4
  86. package/lib/task.mjs +376 -79
  87. package/lib/versions.mjs +285 -39
  88. package/lib/wires.mjs +228 -45
  89. package/lib/workspace.mjs +200 -14
  90. package/package.json +19 -19
  91. package/schemas/assembly.schema.json +2 -2
  92. package/schemas/project.schema.json +6 -0
  93. package/templates/coupons/MEASURE.md +109 -0
  94. package/templates/coupons/assemblies/fixings-test.json +20 -0
  95. package/templates/coupons/assemblies/slot-test.json +11 -0
  96. package/templates/coupons/objects/fixings-coupon.js +88 -0
  97. package/templates/coupons/objects/fixings-coupon.json +26 -0
  98. package/templates/coupons/objects/holds-coupon.js +130 -0
  99. package/templates/coupons/objects/holds-coupon.json +42 -0
  100. package/templates/coupons/objects/slot-coupon.js +89 -0
  101. package/templates/coupons/objects/slot-coupon.json +29 -0
  102. package/templates/coupons/project.json +10 -0
package/AGENTS.md CHANGED
@@ -8,7 +8,10 @@ variable says which rule it comes from. Follow these steps; they're what makes a
8
8
  1. **Rules first.** Find the facts the part depends on: standards, the thing it fits, the printer. Put shared ones in
9
9
  `rules/<set>.json` with `kind`, `source` and `checked`. Research them, don't guess. Ask the person to measure what
10
10
  can't be looked up, and record it as `"kind": "measured"`; something nobody has published goes in as
11
- `"kind": "estimate"`, and the check will flag it.
11
+ `"kind": "estimate"`, and the check will flag it. A set from the kit is copied into `rules/` the first time a design
12
+ uses it; when `npx cad rules check` notes `rules.changed` or `rules.new` (the kit has corrected or added figures
13
+ since), run `npx cad rules update <set>`: it takes the kit's figures and keeps the measured ones. Say in your report
14
+ which figures moved, and check the designs that use them.
12
15
  2. `npx cad new <project>/<object>`, then write the variables in the .json and the shape in the .js. No numbers in
13
16
  the .js other than 0, 1 and 2: `cad check` fails on any other.
14
17
  3. `npx cad check`, then `npx cad preview`, and **look at the preview image** before saying it's done. Check the views
@@ -39,6 +42,16 @@ variable says which rule it comes from. Follow these steps; they're what makes a
39
42
  ## Changing a design
40
43
  1. `npx cad history <project>/<object>` first: read the print log. A failed print is the reason for most changes:
41
44
  fix the rule or variable it points at (a measured fit beats a community rule).
45
+ A figure the person measured goes back with `npx cad measured <project>/<assembly> <name>=<value>`: report what it
46
+ says moved. `--table` (`--json`) lists what is still unmeasured and the coupon that measures each. A figure of the
47
+ other sign, or under half or over twice the old one (a tenth to ten times for an estimate; 0 passes for a figure a
48
+ kit coupon measures), is refused as a likely slip: ask the person to measure again, and add `--force` only once
49
+ they confirm it. `--strike <date> <name>` takes a mistaken row out of the ledger; set the rule file it names back
50
+ too. The kit's coupons (test prints that settle the printer's holes, nuts, pins and slot fits) come into the
51
+ workspace with `npx cad coupons`, as `projects/coupons` with a MEASURE.md that says how to read each. A coupon's
52
+ figure needs no assembly: `npx cad measured x1c.pilot_m3=<value>`, and `npx cad history` lists those.
53
+ `npx cad measured --export` prints what was measured as a diff of the kit's rule sets: offer it to the person to
54
+ send to the kit, with the printer and plastic.
42
55
  2. Change, then check, preview and look, as for a new part. Change values with `npx cad set <project>/<object>
43
56
  name=value` and assemblies with `npx cad add fit|joint|item|beam|pose|fasten|join|guide|load …`, `npx cad set
44
57
  <project>/<assembly> x1.at=… joins.0.kind=…`, `npx cad move` and `npx cad remove`: they keep the file's layout and
@@ -73,10 +86,14 @@ variable says which rule it comes from. Follow these steps; they're what makes a
73
86
  - Use the print-aware features in `v.shapes` before drawing your own: `teardropHole`, `crushRibs`, `wallOpening`
74
87
  print without supports as drawn (and `countersink` and `nutPocket` for a size that is no screw's). Use `v.ops.union/subtract/intersect` for booleans: the
75
88
  workspace can switch them to Manifold (faster, watertight) without touching the design.
76
- - Designs run sandboxed: they may import only `@jscad/modeling`, `@rulecad/shapes`, `@rulecad/flexures`,
77
- `@rulecad/gears`, `@rulecad/motors`, `@rulecad/fixings` and files in their project, and can't write files or start
78
- programs. To see a value while designing, `console.log` it: it comes
89
+ - Designs run sandboxed: they may import only <!-- ALLOWED -->`@jscad/modeling`, `@rulecad/shapes`,
90
+ `@rulecad/flexures`, `@rulecad/gears`, `@rulecad/motors`, `@rulecad/frames`, `@rulecad/fixings`<!-- /ALLOWED --> and
91
+ files in their project, and can't write files or start programs. To see a value while designing, `console.log` it: it comes
79
92
  out with the command's output. A misspelt `v.name` stops the build and says which name was meant.
93
+ A design may run for an hour (3600 s) and hold 4096 MB: `design.time` or `design.memory` means it was stopped
94
+ there, most often by a loop that never ends. Fix the loop; raise `designTimeout` or `designMemory` in
95
+ cad.config.json only for a design that is truly that slow (a raise above the defaults counts once the user has
96
+ run `cad trust`).
80
97
  - Something printed under the part and removed afterwards is a named `support` part (`return { cap, pillar }`, both
81
98
  described in the .json's `parts`), not part of the shape. Look at `cad preview --explode` too.
82
99
 
@@ -104,7 +121,9 @@ variable says which rule it comes from. Follow these steps; they're what makes a
104
121
  and name the screw by thread and head with no length: the check chooses one. It reads the holes from the parts as
105
122
  drawn: one axis through the stack, a clearance hole in each part passed, a pilot, insert or nut at the far end, the
106
123
  length chosen from what is sold, thread engaged, the seat under the head and the key's way to it, and `cad list`
107
- counts the screws. Report what it finds with its numbers, and fix the part, never the relation, to make it pass.
124
+ counts the screws. `fasten.stack` fails where the parts do not meet along the screw (a part placed wrong: move it,
125
+ never lengthen the screw), and `fasten.wall` warns where too little plastic is left round the far hole (move the
126
+ hole in or thicken the part). Report what it finds with its numbers, and fix the part, never the relation, to make it pass.
108
127
  - **A frame is beams and joins, never loose boxes.** Each beam is a `"beam"` item of a profile from a rule set (the
109
128
  kit's or one in `rules/`, never sizes typed into an object), placed by its ends; each meeting of two beams is a
110
129
  declared join, and its drilling, tapping, screws and nuts follow from it: never draw a join's holes or type its
@@ -123,33 +142,42 @@ variable says which rule it comes from. Follow these steps; they're what makes a
123
142
  or slot: choose another set, never edit the set to pass. The other kinds are checked where they meet and say their
124
143
  fitting comes later (`join.fitting`). Move the beam to fix `join.geometry`, never the address, unless the
125
144
  address is what was wrong; `join.stiffness` says whether it rests on an estimate or on the joint rig's
126
- measurement (and its date): report it as it says. A `join.drop` is a prediction for a beam held by one join, to
127
- measure and write back with `cad measured`, never a figure to tune. `frame.deflection` gives each sag twice, on
145
+ measurement (and its date): report it as it says. A `join.drop` is a prediction for a beam held by one join and nothing
146
+ else, from the frame's solve on the supports it is given (or, on the joint rig, its base beam held along its
147
+ length), to measure and write back with `cad measured`, never a figure to tune. `frame.deflection` gives each sag twice, on
128
148
  the joins' springs and with the joins rigid: report the first with what it rests on (`refs.restsOn`), never the
129
149
  rigid one alone. Say where the frame stands with `"frame": { "supports" }` or fitted feet, not by moving beams. A `frame.solve` warning that its supports are guessed means neither is given.
130
150
  `frame.rack` gives the racking stiffness each way and the gain each change (gussets, a brace, a panel) solves to:
131
151
  report the stiffness, the gain and the change it advises, and say the push and the joins' springs are estimates.
152
+ `frame.tip` fails a frame standing free on its feet that its load, or that push at its top, tips over: report the
153
+ push that tips it (`values.tips`) and the feet it lifts (`refs.lifts`), then widen its base or carry the load nearer
154
+ the middle or lower. Say it is bolted down with `"frame": { "supports" }` only where it really is; never lower the
155
+ push to make it pass.
132
156
  `frame.frequency` gives the lowest mode against what the machine excites: report it with its pose, and look at
133
157
  `<assembly>.frame-mode.svg` from `cad beams` to see what moves. To choose profiles, give `"frame": { "size": {
134
158
  "profiles": [...] } }` and read `frame.size` (or `npx cad frame <project>/<assembly> --size`): report each group's
135
159
  profile with the limit that set it (or the join a lighter profile could not make) and its margin, never pick a
136
160
  profile by hand where the sizing can; give `"rack"` to hold racking too; write it with
137
- `--size --write` and check again, as its joins and lengths change. A task on a guide counts the beam's sag (the
161
+ `--size --write`, which checks the design it would write and writes nothing that fails (it names the checks: fix
162
+ what they say, or leave out the profile that breaks them), then check again. A task on a guide counts the beam's sag (the
138
163
  frame's own figure where the frame is solved), straightness and twist in `task.accuracy`: report the biggest term
139
164
  as it is named. `frame.heat` (given `"frame": { "heat": { "air": 45 } }`) says how much the frame grows and holds
140
- each printed fitting to its plastic's softening point: move a failing fitting from the heat or print it in a plastic
141
- that softens higher, never raise the softening figure. `beam.printable` (given `"frame": { "printed": "petg" }`)
165
+ each printed fitting and printed beam to its plastic's softening point: move a failing part from the heat or print it
166
+ in a plastic that softens higher (a beam can be metal), never raise the softening figure. `beam.printable` (given `"frame": { "printed": "petg" }`)
142
167
  says which beams could be printed and the margin each misses by: report the margin and what governs it, say it
143
168
  rests on estimates (the printed section, creep) until the beam coupon is measured, and name the joins it says need
144
169
  changing. A `beam.coupon` sag or break is a prediction to measure on the bench and write back with `cad measured`,
145
170
  never a figure to tune; `beam.creep` fails a printed beam held too hard for months: a deeper section or aluminium.
146
171
  A beam that needs slots in more than its top face prints standing up from the metal's profile
147
172
  (`"printed": { "pose": "standing", "end": "nut" }`): its tapped end takes the thread `beam.end` names, and a foot
148
- under it takes that `"thread"`. Report each printed beam's pose, grams and the sag `frame.deflection` gives.
173
+ under it takes that `"thread"`. Report each printed beam's pose, grams and the sag `frame.deflection` gives, after creep too where it says so (an
174
+ estimate).
149
175
  - **A frame for a size starts from a generator**: `"frame": { "kind": "box", "inside": [w, d, h], "profile",
150
176
  "join": "blind" }` (also portal, table, gantry, shelf) expands into beams, joins, feet and caps before anything is
151
- checked. Ask by `inside` for what it must enclose, `outside` for what it must fit in; never work the lengths out by
152
- hand. Make it with `npx cad new <project>/<assembly> --assembly --frame box --inside 300,300,350 --profile …
177
+ checked. Ask by `inside` for what it must enclose, `outside` for what it must fit in (its feet and end caps with
178
+ it); never work the lengths out by hand. A join the kit cannot build yet (cube; bracket, gusset, hidden or anchor
179
+ with no fitting) is refused unless it says `"estimate": true`. Make it with
180
+ `npx cad new <project>/<assembly> --assembly --frame box --inside 300,300,350 --profile …
153
181
  --join blind`, which says what it expands into before it writes. Read `frame.generated` for what it made, and
154
182
  `npx cad frame <project>/<assembly> --expand` to write it out when it needs changes a generator cannot make, then
155
183
  change the beams and joins with `cad set`, `cad move`, `cad add` and `cad remove` as a hand-drawn frame's.
@@ -196,7 +224,8 @@ variable says which rule it comes from. Follow these steps; they're what makes a
196
224
  - **A part screwed onto a beam is a `fasten` into a slot**: `"into": "x1.top"` (or `x1.top.2`, or `x1.top@120`, the
197
225
  middle of its screws), the
198
226
  part's holes drawn with `v.fixings` at the slot's spacing, `"nut"` the slot nut's kind. `fasten.slot` fails a hole off
199
- a slot's centre line, with the distance: move the hole. `frame.nut` fails slide-in nuts in a slot that joins close
227
+ a slot's centre line, with the distance: move the hole. It fails a nut that runs past the beam's end, and
228
+ `frame.nut` two nuts that crowd one stretch of slot: move the part along the beam. `frame.nut` fails slide-in nuts in a slot that joins close
200
229
  at both ends: use the kind it names (`"nut": "drop-in"`). `frame.preload` lists nuts to load before a join; tell
201
230
  the user, and `cad order` shows them on the step.
202
231
  - **A frame's build is `cad order`**: from bars to a square frame in numbered steps (cut, drill and tap, sides built
@@ -254,8 +283,8 @@ variable says which rule it comes from. Follow these steps; they're what makes a
254
283
  region is never emptied: if `cad optimise` says part of one has nothing holding it up, give the part more material
255
284
  to stand it on, or keep less. `cad check` tests the part for one piece and nothing starting in mid-air.
256
285
  - Before reporting numbers for a final shape, verify them: give the `analysis` a smaller `cell` (solids: about a
257
- third of the problem's) and check the stiffness has settled (`fea.settled`). Report the verified numbers, the safety
258
- factor, and where the peak stress is.
286
+ third of the problem's) and check it has settled (`fea.settled`: the stiffness, and with `min_safety` the peak
287
+ stress too). Report the verified numbers, the safety factor, and where the peak stress is.
259
288
  - For a part that must not break (a lever, a pedal), give its problem a `"stress"` limit (the material's strength
260
289
  over a safety factor) instead of a `"volume"`: the lightest layout under it. Then verify it on finer cells.
261
290
  Add `"robust": true` so it holds made a little thin and a little thick too (`cad optimise` prints both copies'