@mylasertools/kerfscript 0.6.0 → 0.8.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 (83) hide show
  1. package/CHANGELOG.md +201 -1
  2. package/LANGUAGE.md +169 -30
  3. package/README.md +8 -2
  4. package/THIRD-PARTY-NOTICES.md +113 -0
  5. package/dist/analysis.d.cts +20 -0
  6. package/dist/analysis.d.ts +20 -0
  7. package/dist/assembly.d.cts +28 -1
  8. package/dist/assembly.d.ts +28 -1
  9. package/dist/ast.d.cts +9 -0
  10. package/dist/ast.d.ts +9 -0
  11. package/dist/cli.js +10333 -4650
  12. package/dist/diff.d.cts +18 -0
  13. package/dist/diff.d.ts +18 -0
  14. package/dist/evaluator.d.cts +34 -0
  15. package/dist/evaluator.d.ts +34 -0
  16. package/dist/functions.d.cts +1 -0
  17. package/dist/functions.d.ts +1 -0
  18. package/dist/geometry.d.cts +22 -0
  19. package/dist/geometry.d.ts +22 -0
  20. package/dist/hardware.d.cts +13 -0
  21. package/dist/hardware.d.ts +13 -0
  22. package/dist/highlight.cjs +2 -2
  23. package/dist/highlight.js +2 -2
  24. package/dist/index.cjs +2278 -52
  25. package/dist/index.d.cts +11 -2
  26. package/dist/index.d.ts +11 -2
  27. package/dist/index.js +2278 -52
  28. package/dist/instructions.d.cts +3 -0
  29. package/dist/instructions.d.ts +3 -0
  30. package/dist/language.cjs +2235 -50
  31. package/dist/language.js +2235 -50
  32. package/dist/libraries.cjs +2211 -26
  33. package/dist/libraries.d.cts +3 -0
  34. package/dist/libraries.d.ts +3 -0
  35. package/dist/libraries.js +2211 -26
  36. package/dist/png.d.cts +9 -0
  37. package/dist/png.d.ts +9 -0
  38. package/dist/render.d.cts +22 -1
  39. package/dist/render.d.ts +22 -1
  40. package/dist/signatures.cjs +269 -11
  41. package/dist/signatures.js +269 -11
  42. package/dist/slots.d.cts +8 -0
  43. package/dist/slots.d.ts +8 -0
  44. package/dist/values.d.cts +6 -1
  45. package/dist/values.d.ts +6 -1
  46. package/dist/verify/command.d.cts +1 -0
  47. package/dist/verify/command.d.ts +1 -0
  48. package/dist/verify/geometry.d.cts +25 -0
  49. package/dist/verify/geometry.d.ts +25 -0
  50. package/dist/verify/index.d.cts +10 -0
  51. package/dist/verify/index.d.ts +10 -0
  52. package/dist/verify/joints.d.cts +7 -0
  53. package/dist/verify/joints.d.ts +7 -0
  54. package/dist/verify/mechanics.d.cts +11 -0
  55. package/dist/verify/mechanics.d.ts +11 -0
  56. package/dist/verify/motion.d.cts +8 -0
  57. package/dist/verify/motion.d.ts +8 -0
  58. package/dist/verify/pose.d.cts +5 -0
  59. package/dist/verify/pose.d.ts +5 -0
  60. package/dist/verify/relations.d.cts +8 -0
  61. package/dist/verify/relations.d.ts +8 -0
  62. package/dist/verify/snapshot.d.cts +11 -0
  63. package/dist/verify/snapshot.d.ts +11 -0
  64. package/dist/verify/solids.d.cts +40 -0
  65. package/dist/verify/solids.d.ts +40 -0
  66. package/dist/verify/spec.d.cts +9 -0
  67. package/dist/verify/spec.d.ts +9 -0
  68. package/dist/verify/summary.d.cts +17 -0
  69. package/dist/verify/summary.d.ts +17 -0
  70. package/dist/verify/types.d.cts +301 -0
  71. package/dist/verify/types.d.ts +301 -0
  72. package/docs/cli.md +87 -15
  73. package/docs/javascript.md +57 -25
  74. package/docs/layers.md +42 -2
  75. package/docs/library.md +501 -3
  76. package/docs/parts-and-sheets.md +199 -1
  77. package/docs/shared-libraries.md +8 -1
  78. package/docs/specification.md +78 -23
  79. package/docs/verification.md +363 -0
  80. package/docs/versions.md +2 -2
  81. package/package.json +2 -1
  82. package/dist/import/dbg.d.cts +0 -1
  83. package/dist/import/dbg.d.ts +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,205 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.8.0 (2026-11-08)
4
+
5
+ Language version 0.3, as in 0.7.0: programs run as before.
6
+
7
+ - `hardware(shape = "ball")` (or `sides = 0`) is a ball of diameter `size`
8
+ midway between `from` and `to`, which it may leave out: a bulb, a marble
9
+ or a bead. The 3D view draws it, and verification gives it an envelope.
10
+ New hardware kinds: `bulb`, `ball`, `tube`, `lens`, `mirror` and
11
+ `movement`.
12
+ - `measure()` also sets `$area` and `$centroid`, the area of the material
13
+ its first child cuts and its balance point.
14
+ - `offset_path(points, d, closed)` moves a path sideways with mitred
15
+ corners: the two edges of a strip along a curve.
16
+ - `train_for(ratio, stages, pinion, wheel)` gives tooth counts for a gear
17
+ train of 1 to 3 stages nearest a ratio.
18
+ - `kerf/linkage`: `circle_meet()`, `slider_crank()`, `slider_stroke()`,
19
+ `four_bar()`, `four_bar_turns()` and `link_angle()` give where a
20
+ linkage's joints are at a crank angle.
21
+ - `kerf/cones`: `cone_flat()` cuts a cone or cut-off cone flat, with a
22
+ scored glue tab, and `cone_pattern()` gives its sector.
23
+ - `kerf/sizes`: `part_size()` gives the sizes of bought parts: a music box
24
+ movement, a quartz clock movement and marbles.
25
+ - `kerf/gears`: `cam()` draws a cam from a lift curve for a knife or
26
+ roller follower, with `cam_rise()` for dwells, rises and falls,
27
+ `cam_follower()` to place the follower and `cam_pressure()` to check it
28
+ won't jam. `geneva_wheel()`, `geneva_lock()`, `geneva_crank()` and
29
+ `geneva_turn()` make a Geneva drive; `ratchet()` and `pawl()` a wheel
30
+ that turns one way only.
31
+ - `kerf/sizes`: the instant film photo sizes are now `"instant mini"`,
32
+ `"instant square"`, `"instant wide"` and `"instant classic"`. The old
33
+ names still work.
34
+ - `part(material = "red acrylic")` names a part's material without a
35
+ `material()` round it.
36
+
37
+ ## 0.7.0 (2026-11-03)
38
+
39
+ Language version 0.3. Programs for 0.2 run as before, except that a
40
+ variable no longer hides a function or built-in of the same name: after
41
+ `len = 3;`, `len([1, 2])` is 2, where it was an error. Numbers followed by
42
+ a unit, which were errors, are now lengths. New warnings and the positions
43
+ added to old ones change the text of warnings.
44
+
45
+ Records: `{kind = "armchair", x = 10}` holds values by name, read as
46
+ `s.kind` or `s["kind"]` (a missing field is `undef`), with `keys()`,
47
+ `merge()`, `is_record()` and `len()`. `kerf fmt` lays them out as lists.
48
+ `call("roses", 40, 30)` calls a module by name, so a table entry can carry
49
+ the module that draws it.
50
+
51
+ Assembly:
52
+
53
+ - `kerf verify` and the JavaScript verification API check explicit rigid fit,
54
+ shaft capture, conditional retention, material adaptation, cut invariance,
55
+ insertion/tool access, assembly support, static stability, ideal joint mobility
56
+ and continuous translation/rotation clearance. Reports distinguish pass, fail
57
+ and unverified within their stated scope and record input fingerprints.
58
+ `render(..., { analysis: true })` captures nominal cuts and native connections;
59
+ `poseAssembly()` previews the checked paths. Viewer diagnostics highlight
60
+ implicated bodies. Strength, friction and contact-driven mechanics remain
61
+ uncovered. See `docs/verification.md`.
62
+
63
+ - `place(at, rotate) { ... }` places the parts and hardware inside it, with
64
+ their own placements inside its. `box()` takes a `name` and shapes for
65
+ its front, so a box can be set anywhere.
66
+ - `part()` takes `stack = n` (glued layers), `mirror = true` (the left of a
67
+ pair, its text still reading; or one per copy, `mirror = [false, true]`,
68
+ for a pair whose art faces out on both), `bend = [x0, x1, angle]` (a living hinge
69
+ shown bent), `on = "part"` (glued to a bent part and moving with it),
70
+ `glue = "part", face = "top"` (laid on another part's face) and `slots =
71
+ ["part", ...]`: slots cut wherever those parts pass through it in the
72
+ assembly, at any angle, so tabs are drawn once.
73
+ - `step(text) { ... }` makes assembly steps, and `hardware(kind, from, to,
74
+ size)` lists dowels, screws, magnets and paper. `render()` returns
75
+ `steps` and `hardware`; `kerf check` lists them.
76
+ - `orient(x, z)`, `rotation(angles)` and `euler(matrix)` turn parts any way.
77
+ - Collisions are checked for each flat run of a bent part, and a collision
78
+ warning says where in the assembly it is.
79
+
80
+ A 3D view in the playground (the Assembled tab) and on every model page
81
+ (Build it) shows the model put together from the program, bends and
82
+ hardware included, and builds it a step at a time.
83
+
84
+ Drawing:
85
+
86
+ - `spline(points, width)` and `spline_points()`, `hatch(angle, pitch,
87
+ width)`, `pattern(spacing, stagger)` that repeats a tile cheaply,
88
+ `paint(layers)` for painter's order, `measure()` with `$bounds`,
89
+ `fill_holes(min_area)`, `close(r)`, `line(a, b, width)` as an area,
90
+ `text(fit = width)`, and `path(d, close = true)`.
91
+ - `intersection()` clips the lines of any child, not only the first, to the
92
+ area of the other children. A child of lines alone leaves no area, so
93
+ `intersection() { outline() circle(d = 20); square(40); }` gives only the
94
+ clipped arc, whichever child comes first.
95
+ - `path_length()`, `point_at()`, `heading_at()` and `path_points()` work
96
+ along paths.
97
+ - Lengths in real units, as `140cm`, `2in` or `1.2m`, divided by `$scale`.
98
+
99
+ Output:
100
+
101
+ - `engrave(side = "back")`, `score(side = "back")` and `layer(side =
102
+ "back")` mark the faces underneath, in a second job per sheet turned over
103
+ left to right (`sheet.back`, `name-back.svg`).
104
+ - Line layers come after fill layers in the files, and `layer(order = n)`
105
+ sets the order. `layer(bleed = mm)` lets a printed layer run past the
106
+ part's edge, and `$registration = true` adds print-and-cut marks.
107
+ - `$nest = true` (`--nest`, the `nest` option) packs small parts into the
108
+ holes of bigger ones.
109
+ - A project's `kerf.json` can give `"sheet": [w, h]` for every design in
110
+ it that does not set `$sheet` (the `defaultSheet` option).
111
+ - Warnings about a part in pieces, a hole narrower than the kerf and a
112
+ collision say where.
113
+ - `kerf check --stats` counts points by part and layer, and `--sweep
114
+ name=from:step:to` checks a design over every combination of settings.
115
+ - A library's own `use` looks next to it first.
116
+ - `use` takes an absolute path, as `use </home/me/lib/props>`.
117
+ - A module or function defined with a built-in's name warns that it hides
118
+ the built-in.
119
+ - A stack glued under its host (`face = "bottom"`) grows down, away from it.
120
+ - A `step()` inside a step is a sub-step ("Add the chair: Glue the seat");
121
+ `step(text, substeps = false)` takes inner steps into itself.
122
+ - `kerf verify --summary` (and `triage()`) groups what did not pass by status
123
+ and reason, with the bodies involved and their measurements.
124
+ - A slot is cut through the whole thickness of the part, so a shoulder that
125
+ flares just inside its face is covered; parts that only touch still cut
126
+ nothing.
127
+ - A stack whose layers meet different parts in slots becomes a part per
128
+ layer (`top, layer 1`), each cutting only its own slots.
129
+ - The collision check reports any overlap deeper than 0.1 mm, where it
130
+ needed a cubic millimetre, and slots need a part to reach 1 mm in,
131
+ so a part dipping 0.13 mm into a floor is reported, not slotted.
132
+ - `ring_stack()` refuses a hole that leaves its core plates or the base
133
+ between their feet thinner than `$min_width`, naming the smallest hole.
134
+ - `children(i)` used several times in one call makes the child once (when it
135
+ only makes a shape), and the point cap is on each shape kept, with ten
136
+ times that for all the work along the way.
137
+ - `pattern()` over an area of many small shapes tests and clips each tile
138
+ only against the shapes it may touch: 30 hearts on a facade take 0.2 s,
139
+ not 6.
140
+ - `$label_parts = true` engraves each part's number on its back face and
141
+ lists the numbers in `kerf check`'s parts and steps (`label` on each part).
142
+ - A `paint()` child lying wholly on an area of the same layer under it
143
+ warns that it can't be seen.
144
+ - A fill lying wholly under fills of layers stacked above it in the files
145
+ warns: printed it won't show, engraved it burns twice. Two `paint()`
146
+ calls whose later piece went on an earlier layer do this. Fills narrower
147
+ than 1 mm all along, a stroke's to cover, are left out.
148
+ - A part narrower than `$min_width` (1.5 mm unless set; 0 turns it off)
149
+ somewhere warns, saying where.
150
+ - `symbol(..., box = "grid")` sizes and places a symbol by its icon set's
151
+ grid, so a set lines up as drawn.
152
+ - `kerf render model.kerf -o model.png [--px 1200]` draws a picture of each
153
+ sheet to check by eye: material, fills in their colours, lines on top.
154
+ - `kerf instructions model.kerf` (and `instructionsHtml()`) writes printable
155
+ assembly instructions: parts, sheets, and a page per step with the model
156
+ drawn so far, that step's parts picked out.
157
+ - `kerf diff a.kerf b.kerf` (and `diffRenders()`) lists what changed between
158
+ two renders, by part and layer, with where.
159
+ - `kerf render lib.kerf --call 'roses(40, 30)'` renders one call of a
160
+ library's module, with `-D` setting variables first.
161
+ - `--sweep 'w,d=100,80;200,150'` tries settings that go together as sets,
162
+ and `--params-list sets.json` reads the sets from a file.
163
+ - Two different parts with one name warn, since slots, glue and `on` find
164
+ parts by name. A length with a unit read before the program sets `$scale`
165
+ warns. `hardware()` warns about a kind outside the documented list
166
+ (`HARDWARE_KINDS`), which adds `steel`, `felt`, `wire` and `led`.
167
+ - A setting passed to `render()` (or `-D`, `--sweep`) that the program never
168
+ assigns warns, with the nearest name.
169
+ - `hardware(sides = ...)` takes 3 to 128 sides, counted as work toward the
170
+ point limit, and the 3D view never builds more. `kerf render -o x.png`
171
+ keeps a picture to 16 million pixels, 16384 a side, drawing a long thin
172
+ sheet smaller. Redefining a layer that is already another layer's back
173
+ (`layer("score-back", ...)` after `layer("score", side = "back")`) is an
174
+ error rather than quietly moving its marks to the front.
175
+ - A bend reaching beyond its part warns, and a 3D view cuts a part's bends
176
+ into at most 2000 bands, only where there is material. `$label_parts`
177
+ warns and leaves the parts unnumbered when the program has a front layer
178
+ of its own named `engrave-back`.
179
+ - The playground's downloads include the back-face jobs: a sheet with back
180
+ marks lists back SVG and DXF files, and one such sheet downloads as a ZIP
181
+ of its front and back.
182
+ - `kerf verify`: a stability claim over several loads needs its retention
183
+ links to join them into one assembly; loads held to separate roots are
184
+ unverified rather than standing together.
185
+
186
+ New libraries:
187
+
188
+ - `kerf/gears`: spur gears, racks, lantern gears and peg wheels,
189
+ eccentrics, snail cams and tappets.
190
+ - `kerf/lock`: a lock with a key, three layers deep.
191
+ - `kerf/rings`: round things of stacked rings on a crossed core.
192
+ - `kerf/joints`: `halved_pair()`, two profiles halved into each other (a
193
+ cross on its foot, a font, a dome), checking the strips beside the slots.
194
+ - `kerf/sizes`: paper, card and photo sizes by name.
195
+ - `kerf/symbols`: 867 pictograms by name, from open icon sets (see
196
+ THIRD-PARTY-NOTICES.md).
197
+ - `kerf/geo`: the world's land from Natural Earth, `world_map()` and
198
+ `is_land()`.
199
+ - `kerf/hinge` adds `flex_strip()`, a strip that follows a profile with
200
+ hinges on its curves and tabs on its straights, `strip_bends()` and
201
+ `narrow_hinge()`; `flex_box()` now shows assembled.
202
+
3
203
  ## 0.6.0 (2026-11-02)
4
204
 
5
205
  Language version 0.2, as in 0.5.0: programs run as before.
@@ -8,7 +208,7 @@ Language version 0.2, as in 0.5.0: programs run as before.
8
208
  jewellery box, drawer cabinet, workshop holders, miniature furniture,
9
209
  radial shade, sliding puzzle, game insert, cable chain, cantilever case,
10
210
  beam balance, tilting stand, screw press, wheel calendar and laced mat.
11
- Each has an animated preview in the gallery.
211
+ Each has a 3D model in the gallery, and the mechanisms among them move.
12
212
  - `kerf import` and `importSvg()` turn an SVG drawing into a program. They
13
213
  write circles, rectangles, polygons, tabs, slots, finger joints, hanger
14
214
  holes, keyholes and hanging loops as the modules that make them, and
package/LANGUAGE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # KerfScript language reference
2
2
 
3
- Language version 0.2. Copyright (c) 2026 MyLaserTools. This document is
3
+ Language version 0.3. Copyright (c) 2026 MyLaserTools. This document is
4
4
  licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/).
5
5
  "KerfScript" is a trademark of MyLaserTools, see [TRADEMARKS.md](TRADEMARKS.md).
6
6
 
@@ -49,9 +49,23 @@ score() circle(d = size - 6);
49
49
  | list | `[1, 2]`, `[[0, 0], [10, 0], [5, 8]]` |
50
50
  | range | `[0:5]` (0 to 5 step 1), `[0:2:10]` (0 to 10 step 2) |
51
51
  | function | `function(x) x * 2` |
52
+ | record | `{kind = "armchair", x = 10, items = []}` |
52
53
 
53
54
  Points are lists `[x, y]`. `p.x` and `p.y` read the first two items.
54
55
 
56
+ A record holds values by name. `s.kind` (or `s["kind"]`) reads a field, and
57
+ a field it doesn't have reads as `undef`, so a table of scene entries can't
58
+ put a value in the wrong place:
59
+
60
+ ```kerf
61
+ chair = {kind = "armchair", x = 10, items = ["cushion"]};
62
+ echo(chair.kind, chair.y); // armchair, undef
63
+ moved = merge(chair, {x = 40}); // the same with x = 40
64
+ echo(keys(moved), len(moved)); // ["kind", "x", "items"], 3
65
+ ```
66
+
67
+ Records are equal when they have the same fields with equal values.
68
+
55
69
  ## Expressions
56
70
 
57
71
  Operators are listed from lowest to highest precedence. Use parentheses
@@ -111,6 +125,19 @@ include <path> // run another file in place
111
125
 
112
126
  Arguments can be positional or named: `rect([20, 10], r = 2)`.
113
127
 
128
+ A library's own `use <path>` and `include <path>` look next to that
129
+ library first, then where the main program's would: `lib/props.kerf`
130
+ saying `use <finish.kerf>` finds `lib/finish.kerf`.
131
+
132
+ ### Lengths in real units
133
+
134
+ A number written with a unit, as `140cm`, `2.5in`, `1.2m`, `30mm` or `3ft`,
135
+ is a length in the real world: it comes out in millimetres divided by
136
+ `$scale`. With `$scale = 12`, `140cm` is 116.67 mm, so a dollhouse and a
137
+ book-nook version come from one model. Plain numbers are millimetres on
138
+ the sheet and never scale: keep `$thickness`, `$kerf` and joint sizes
139
+ plain. A setting written with a unit is not shown in the customizer.
140
+
114
141
  ### Scope
115
142
 
116
143
  - Assignments run **in order**. A later assignment to the same name replaces
@@ -118,6 +145,9 @@ Arguments can be positional or named: `rect([20, 10], r = 2)`.
118
145
  - `module` and `function` definitions are visible in their whole block, so you
119
146
  can call them before they are defined.
120
147
  - Blocks, loops and module bodies have their own scope.
148
+ - Variables, functions and modules have separate names. A variable that
149
+ does not hold a function never hides a function or built-in: after
150
+ `len = 3;`, `len([1, 2])` is still 2.
121
151
  - **Special variables** (`$name`) are dynamically scoped: a value set by a
122
152
  caller is seen by everything it calls. Pass them as arguments too:
123
153
  `circle(5, $fn = 6)`.
@@ -144,16 +174,25 @@ module hang_hole(d = 5) {
144
174
 
145
175
  ## Special variables
146
176
 
147
- | Name | Default | Meaning |
148
- | ----------------- | ------------- | -------------------------------------------------------------------------- |
149
- | `$thickness` | `3` | material thickness, used by joinery and stored on parts |
150
- | `$kerf` | `0` | beam width; cut outlines are offset by half of it |
151
- | `$material` | `"material"` | material name; parts are packed per material and thickness |
152
- | `$sheet` | `[600, 400]` | sheet size for packing |
153
- | `$gap` | `3` | space between packed parts and around the sheet edge |
154
- | `$layout` | `"pack"` | `"pack"` packs parts onto sheets, `"none"` keeps your placement |
155
- | `$fn` `$fa` `$fs` | `0` `2` `0.2` | curve resolution: fixed segment count, or max angle and max segment length |
156
- | `$font` | | default font name for `text()` |
177
+ | Name | Default | Meaning |
178
+ | ----------------- | ------------- | --------------------------------------------------------------------------- |
179
+ | `$thickness` | `3` | material thickness, used by joinery and stored on parts |
180
+ | `$kerf` | `0` | beam width; cut outlines are offset by half of it |
181
+ | `$material` | `"material"` | material name; parts are packed per material and thickness |
182
+ | `$sheet` | `[600, 400]` | sheet size for packing |
183
+ | `$gap` | `3` | space between packed parts and around the sheet edge |
184
+ | `$layout` | `"pack"` | `"pack"` packs parts onto sheets, `"none"` keeps your placement |
185
+ | `$fn` `$fa` `$fs` | `0` `2` `0.2` | curve resolution: fixed segment count, or max angle and max segment length |
186
+ | `$font` | | default font name for `text()` |
187
+ | `$mirrored` | `false` | set inside a mirrored part and on the back face: `text()` reads right |
188
+ | `$scale` | `1` | the model's scale: `140cm` is 1400 mm divided by `$scale` |
189
+ | `$nest` | `false` | pack small parts into the holes of bigger ones |
190
+ | `$registration` | `false` | print-and-cut marks in three corners of every sheet |
191
+ | `$label_parts` | `false` | engrave each part's number on its back face, as in the parts list and steps |
192
+ | `$min_width` | `1.5` | warn where a part's material is narrower than this; `0` turns it off |
193
+ | `$bounds` | | set by `measure()` for the children after the one it measures |
194
+ | `$area` | | set by `measure()`: the area of material the measured child cuts |
195
+ | `$centroid` | | set by `measure()`: the measured child's balance point `[x, y]` |
157
196
 
158
197
  ## Layers
159
198
 
@@ -174,7 +213,23 @@ layer("pocket", mode = "fill", color = "#00aa00") ...
174
213
  Use `layer(name, mode, color)` to define a custom layer. Its mode is
175
214
  `"cut"`, `"line"`, `"fill"` or `"guide"`.
176
215
 
177
- Files list layers in this order: engrave, custom layers, score, cut, guide.
216
+ Marks can go on a part's **back face** too: `engrave(side = "back")`,
217
+ `score(side = "back")` or `layer(name, side = "back")`. Draw them where
218
+ they are on the part seen from the top, as everything else; text on the
219
+ back reads the right way round on the back. Each sheet with back marks
220
+ gets a second job (`sheet.back`, or `name-back.svg` from the command line),
221
+ the sheet turned over left to right: cut the sheet, turn it over without
222
+ moving the parts, line it up on the same corner and run the back job.
223
+
224
+ Files list layers in this order: engrave, custom fill layers, custom line
225
+ and cut layers, score, cut, guide, so a line is never covered by a fill.
226
+ `layer(name, order = n)` moves a custom layer among the others, lowest
227
+ first; at the same order fills still go under lines.
228
+
229
+ For printing on the parts before cutting, `layer(name, bleed = 2)` lets
230
+ that layer run 2 mm past the part's edge instead of being clipped to it,
231
+ and `$registration = true` puts marks in three corners of every sheet on
232
+ a `registration` layer, for a print-and-cut machine to line up on.
178
233
  Set the actual operation order, power and speed in your laser software.
179
234
  See [Laser software](docs/compatibility.md) for import details.
180
235
 
@@ -206,12 +261,64 @@ material(thickness = 4, kerf = 0.12, name = "birch") {
206
261
  rotated first, then moved, with its thickness along +Z. A part with copies
207
262
  takes one placement or a list with one per copy. `render()` returns the
208
263
  placed parts as `assembly` and warns when two of them collide.
264
+ `rotate = orient(x, z)` turns the part's own x and z axes onto two
265
+ directions; `euler(rotation(a) * rotation(b))` turns by `b`, then by `a`.
266
+ - More about a part, all named:
267
+ - `material = "red acrylic"`: the part's material, as `material(name =
268
+ ...)` would set `$material` round it.
269
+ - `stack = n`: n layers glued at each placement, one thickness apart
270
+ along the part's z. The parts list says how many make a stack.
271
+ - `mirror = true`: the part is cut mirrored left to right (x becomes
272
+ -x), and its text still reads the right way round. Make the left of a
273
+ pair by mirroring the right. A list with one `true` or `false` per
274
+ copy mirrors only those copies, `qty = 2, mirror = [false, true]`, so
275
+ a pair of sides shows its art on the outside of both; the mirrored
276
+ copies are listed as a part of their own, `(mirrored)`.
277
+ - `bend = [x0, x1, angle]`, or a list of them: a living hinge from x0 to
278
+ x1 along the part's x bends it by `angle` degrees in the assembled
279
+ view, folding the far end up towards its top face (down for a negative
280
+ angle). The hinge's middle layer keeps its length.
281
+ - `on = "name"`: the part is glued to that bent part, and moves with the
282
+ run of it under its centre.
283
+ - `glue = "name"`, `face = "top"`: the part is glued flat on that part's
284
+ top (or bottom) face; its `at` and `rotate` are measured on the face,
285
+ and the parts list says what it is glued to. With as many copies as
286
+ the part it is glued on, one goes on each.
287
+ - `slots = ["name", ...]`: where the named parts' material passes through
288
+ this part in the assembly, slots are cut through it the shape of their
289
+ cross-section, at any angle, `clearance = 0.1` wider. Draw tabs on one
290
+ part and let the parts they go into cut their own slots. A name may
291
+ have `*` for any run of characters, and `"!name"` leaves out parts the
292
+ names before it took: `slots = ["*", "!back"]` cuts a slot for every
293
+ part that passes through except the back. A slot clears every layer,
294
+ marks included, and a part that only touches the edge leaves no notch.
295
+ - `place(at, rotate) { ... }` places the parts and hardware inside in the
296
+ assembled view, as part()'s `at` and `rotate` do; their own placements
297
+ are inside it. A library module wrapped in `place()` can be set anywhere.
298
+ - `step(text) { ... }`: an assembly step. Parts and hardware inside are
299
+ added in it, in the order steps first run; `render()` returns the steps'
300
+ text as `steps` and each placed part's `step`. The 3D view shows the
301
+ model built up a step at a time. A step inside a step is a sub-step,
302
+ `"outer: inner"`; `step(text, substeps = false)` takes inner steps in.
303
+ - `hardware(kind, from, to, size = 6, up, sides = 24, shape = "rod", label)`
304
+ lists hardware the assembly needs, from one point to another: a dowel, a
305
+ screw, a magnet, paper. `size` is a diameter, or `[w, h]` for a flat
306
+ section whose `h` points along `up` (by default up, or along y for
307
+ something standing upright). A round one is drawn with `sides` sides, 3
308
+ to 128. `shape = "ball"` (or `sides = 0`) is a ball of diameter `size`
309
+ midway between `from` and `to`; `to` may be left out. It comes back with
310
+ `sides = 0` and `from` and `to` both at its centre. `render()` returns it
311
+ as `hardware`, and `kerf check` lists it.
209
312
  - Shapes outside any part form one part named `part`.
210
313
  - `material(thickness, kerf, name) { ... }` sets those special variables for
211
314
  its children.
212
315
  - With `$layout = "pack"`, parts are grouped by material and thickness and
213
316
  repeated `qty` times. They are arranged in rows on sheets of `$sheet` and
214
317
  may be rotated 90° to fit. Parts larger than the sheet produce a warning.
318
+ A project's `kerf.json` can give `"sheet": [w, h]`, the laser's bed, for
319
+ every design in it that does not set `$sheet`.
320
+ - With `$nest = true`, small parts are packed inside the holes of bigger
321
+ ones, as rings inside rings.
215
322
 
216
323
  See [Parts and sheets](docs/parts-and-sheets.md) for spacing, layout and
217
324
  export examples.
@@ -228,9 +335,12 @@ export examples.
228
335
  | `regular_polygon(n, r)` | corner radius `r` |
229
336
  | `star(n, r, inner)` | |
230
337
  | `polygon(points, paths)` | even-odd fill, `paths` lists point indexes per outline |
231
- | `path(d, fill = "evenodd")` | SVG path data; closed subpaths become shapes, open ones lines |
338
+ | `path(d, fill = "evenodd", close = false)` | SVG path data; closed subpaths become shapes, open ones lines unless `close` |
232
339
  | `text(text, size = 10, font, halign, valign, spacing = 1)` | `halign`: left, center, right; `valign`: baseline, top, center, bottom |
340
+ | `text(text, size, fit = width)` | no wider than `fit`: the size shrinks to fit, never above `size` if given |
233
341
  | `line(from, to)` | a line, not an area |
342
+ | `line(from, to, width)` | a strip `width` wide between the points, an area |
343
+ | `spline(points, width, steps = 8, closed = false)` | a smooth curve through the points; with `width`, an area along it |
234
344
  | `polyline(points, closed = false)` | |
235
345
  | `arc(r, start = 0, end = 90)` | arc line, angles in degrees |
236
346
 
@@ -253,15 +363,21 @@ playground, the command line and `kerfscript.wasm` have `Atkinson`
253
363
 
254
364
  ### Combining
255
365
 
256
- | Module | Notes |
257
- | ---------------------------------------------- | -------------------------------------------------------------------------- |
258
- | `union()` / `group()` | joins children |
259
- | `difference()` | removes every later child's area from every layer of the first child |
260
- | `intersection()` | keeps only the area common to all children, layers of the first child kept |
261
- | `hull()` | convex hull; each named part inside gets its own hull |
262
- | `offset(r)` / `offset(delta, chamfer = false)` | grow (positive) or shrink areas; `r` rounds corners |
263
- | `stroke(width)` | turns lines into areas of that width, for cutting single line art |
264
- | `outline()` | turns areas into their outline lines |
366
+ | Module | Notes |
367
+ | ---------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
368
+ | `union()` / `group()` | joins children |
369
+ | `difference()` | removes every later child's area from every layer of the first child |
370
+ | `intersection()` | keeps the area common to all children; lines of any child are clipped to the others' area, and a child of lines alone leaves only lines |
371
+ | `fill_holes(min_area)` | fills holes smaller than `min_area` mm², or all of them |
372
+ | `close(r = 0.5)` | closes gaps and notches narrower than `2 r`, keeping the outline |
373
+ | `pattern(spacing, stagger = 0)` | repeats its first child over the area of the others, clipped at the edge |
374
+ | `hatch(angle = 45, pitch = 5, width)` | parallel lines across the children's area, or stripes `width` wide |
375
+ | `paint(layers)` | each child loses the area of every later one; child i goes on `layers[i]`. A child wholly on an area of its own layer warns |
376
+ | `measure(draw = false)` | `$bounds` = `[x0, y0, x1, y1]`, `$area` and `$centroid` = `[x, y]` of the first child, for the children after |
377
+ | `hull()` | convex hull; each named part inside gets its own hull |
378
+ | `offset(r)` / `offset(delta, chamfer = false)` | grow (positive) or shrink areas; `r` rounds corners |
379
+ | `stroke(width)` | turns lines into areas of that width, for cutting single line art |
380
+ | `outline()` | turns areas into their outline lines |
265
381
 
266
382
  ### Joinery
267
383
 
@@ -274,11 +390,12 @@ playground, the command line and `kerfscript.wasm` have `Atkinson`
274
390
 
275
391
  ### Other
276
392
 
277
- | Module | Effect |
278
- | ---------------------------- | -------------------------------------------------------------------------------- |
279
- | `echo(...)` | Report values without creating geometry |
280
- | `assert(condition, message)` | Stop with `message` when `condition` is false |
281
- | `children(index)` | Render a child passed to the current module; omit `index` to render all children |
393
+ | Module | Effect |
394
+ | ---------------------------- | ---------------------------------------------------------------------------------------------------------------- |
395
+ | `echo(...)` | Report values without creating geometry |
396
+ | `assert(condition, message)` | Stop with `message` when `condition` is false |
397
+ | `children(index)` | Render a child passed to the current module; omit `index` to render all children |
398
+ | `call(name, ...)` | Call the module named by the string `name` with the other arguments and the children: `call(entry.draw, 40, 30)` |
282
399
 
283
400
  ## Built-in functions
284
401
 
@@ -301,14 +418,33 @@ arguments.
301
418
  | `min(values)`, `max(values)` | Minimum or maximum of a list; also accept separate values |
302
419
  | `clamp(x, low, high)` | Limit x to the given interval |
303
420
  | `lerp(a, b, t)` | Interpolate between numbers or vectors; t = 0 gives a, t = 1 gives b |
421
+ | `train_for(ratio, stages = 2, pinion, wheel)` | Tooth counts for a gear train nearest `ratio`; see kerf/gears |
304
422
  | `norm(v)` | Length of a vector |
305
423
  | `cross(a, b)` | Cross product; a scalar for 2D vectors or a vector for 3D vectors |
306
424
 
425
+ ### Paths and rotations
426
+
427
+ A path is a list of `[x, y]` points.
428
+
429
+ | Function | Result |
430
+ | -------------------------------------------------- | -------------------------------------------------------------------- |
431
+ | `path_length(points)` | Length along the path |
432
+ | `point_at(points, s)` | The point `s` along the path; past either end it carries on straight |
433
+ | `heading_at(points, s)` | The path's direction `s` along it, in degrees from +x |
434
+ | `offset_path(points, d, closed = false)` | The path moved `d` to its left (right for `d < 0`), corners mitred |
435
+ | `path_points(d, tolerance)` | The points of SVG path data, a list of points for each subpath |
436
+ | `rotation(angles)` | The 3 × 3 matrix of `[x, y, z]` degrees as `part()` turns; use `*` |
437
+ | `euler(matrix)` | The `[x, y, z]` angles of a rotation matrix, for `rotate` |
438
+ | `orient(x, z = [0, 0, 1])` | The angles that turn a part's own x and z axes onto two directions |
439
+ | `spline_points(points, steps = 8, closed = false)` | The points of the smooth curve `spline()` draws |
440
+
307
441
  ### Lists and strings
308
442
 
309
443
  | Function | Result |
310
444
  | ------------------------------ | -------------------------------------------------------------------------------------------- |
311
- | `len(value)` | Number of items in a list or characters in a string |
445
+ | `len(value)` | Number of items in a list, characters in a string or fields in a record |
446
+ | `keys(record)` | A record's field names, in the order they were written |
447
+ | `merge(a, b)` | A record with the fields of both, `b`'s winning |
312
448
  | `concat(...)` | Join lists and individual values into one list |
313
449
  | `reverse(value)` | Reverse a list or string |
314
450
  | `sum(values)` | Sum a list of numbers |
@@ -325,7 +461,7 @@ arguments.
325
461
  ### Types
326
462
 
327
463
  `is_num(value)`, `is_string(value)`, `is_bool(value)`, `is_list(value)`,
328
- `is_undef(value)` and `is_function(value)` return a boolean.
464
+ `is_undef(value)`, `is_function(value)` and `is_record(value)` return a boolean.
329
465
  `type_of(value)` returns the type name as a string.
330
466
 
331
467
  ### Random values
@@ -339,6 +475,8 @@ bounds. The same seed gives the same sequence.
339
475
  spacing. `text_metrics(text, size, font)` returns
340
476
  `[advance, [[x0, y0], [x1, y1]], ascent, descent]`.
341
477
 
478
+ With `fit = width` they measure the text at the size `text()` would fit it to.
479
+
342
480
  Both require the font to be available to the renderer, just like `text()`.
343
481
 
344
482
  ### Joint dimensions
@@ -397,6 +535,7 @@ module and its parameters. Libraries others publish are installed with
397
535
  | `kerf/hanging` | `keyhole()`, `keyholes()`, `hanging_hole()`, `hanging_loop()` |
398
536
  | `kerf/enclosure` | `enclosure()`, `enclosure_cutouts()`, `vents()`: boxes with a screwed lid |
399
537
  | `kerf/calibration` | `kerf_gauge()`, `slot_gauge()`, `joint_test()`: test pieces |
538
+ | `kerf/joints` | `halved_pair()`: two profiles halved into each other |
400
539
 
401
540
  `box()` makes the six (or five) panels of a finger-jointed box as parts
402
541
  `bottom`, `lid`, `front`, `back`, `left`, `right`, from the outer size.
@@ -433,7 +572,7 @@ Programs are also limited in how much memory they can ask for:
433
572
  | `maxListLength` | 1,000,000 | items in one list or range, or characters in one string, including the text `echo()` writes in one call |
434
573
  | `maxListItems` | 3,000,000 | items in all lists the program builds, plus 4 for each list, one for every 8 characters of the strings it builds or echoes |
435
574
  | `maxTextLength` | 2,000 | characters in one `text()` |
436
- | `maxPoints` | 2,000,000 | points in all shapes the modules make, plus 100 for each shape |
575
+ | `maxPoints` | 2,000,000 | points in any one shape a module makes; all the shapes made along the way, plus 100 for each, may add up to ten times this |
437
576
  | `maxOutputPoints` | 1,000,000 | points in the exported files, counting every copy |
438
577
  | `maxSheets` | 200 | sheets in the layout |
439
578
  | `maxCollisionPairs` | 20,000 | pairs of touching placed parts checked for collisions; past it the check stops with a warning |
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  <p align="center">
6
6
  <a href="https://www.npmjs.com/package/@mylasertools/kerfscript"><img src="https://img.shields.io/npm/v/@mylasertools/kerfscript?color=d8361f&label=npm" alt="npm version"></a>
7
7
  <a href="COMMERCIAL-LICENSE.md"><img src="https://img.shields.io/badge/licence-AGPL--3.0%20or%20free%20commercial-1f1a17" alt="Licence: AGPL-3.0 or free commercial"></a>
8
- <a href="LANGUAGE.md"><img src="https://img.shields.io/badge/language-0.2-e3c69a" alt="Language version 0.2"></a>
8
+ <a href="LANGUAGE.md"><img src="https://img.shields.io/badge/language-0.3-e3c69a" alt="Language version 0.3"></a>
9
9
  <a href="https://kerfscript.mylasertools.com/playground/"><img src="https://img.shields.io/badge/try%20it-playground-5a3519" alt="Try it in the playground"></a>
10
10
  </p>
11
11
 
@@ -161,6 +161,10 @@ it as the start of your own design.
161
161
  cuts come before outer ones, and the whole part is offset by half the kerf.
162
162
  - **Parts, not just shapes.** `part("lid", qty = 2)` names a piece; the
163
163
  renderer packs parts by material and thickness onto sheets.
164
+ - **Assembled in 3D, step by step.** Give parts a place and they are
165
+ checked for collisions, shown put together, bent where a living hinge
166
+ bends, and built one `step()` at a time; tabs drawn on one part cut
167
+ their own slots in the parts they go into (`slots = [...]`).
164
168
  - **Joinery that follows the material.** `finger_rect`, `finger_holes`,
165
169
  `tslot` and `living_hinge` use `$thickness`, so the joints resize when the
166
170
  material changes. Measure your kerf and cut a test piece for a snug fit.
@@ -234,10 +238,12 @@ Errors are thrown as `KerfError` with `line` and `col`.
234
238
  [parts and sheets](docs/parts-and-sheets.md), [settings](docs/customizer.md),
235
239
  the [desktop app](docs/desktop.md), the [command line](docs/cli.md), the
236
240
  [JavaScript API](docs/javascript.md),
241
+ [assembly verification](docs/verification.md),
237
242
  [WebAssembly](docs/webassembly.md) for other languages and
238
243
  [AI assistants](docs/mcp.md)
239
244
  - [Standard library](docs/library.md): joints, hinges, dividers, hanging
240
- holes, enclosures and test pieces, with a picture and an example of each
245
+ holes, boxes, enclosures, test pieces, gears and cams, a lock, stacked
246
+ rings, paper sizes, 867 symbols and a world map
241
247
  - [Shared libraries](docs/shared-libraries.md): use and publish `.kerf`
242
248
  libraries, pinned in `kerf.lock` so a design cuts the same everywhere
243
249
  - [Importing SVG drawings](docs/import.md): turn a drawing into a program,