@mylasertools/kerfscript 0.6.0 → 0.7.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 +167 -1
  2. package/LANGUAGE.md +160 -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 +10165 -4669
  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 +17 -0
  19. package/dist/geometry.d.ts +17 -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 +1941 -52
  25. package/dist/index.d.cts +11 -2
  26. package/dist/index.d.ts +11 -2
  27. package/dist/index.js +1941 -52
  28. package/dist/instructions.d.cts +3 -0
  29. package/dist/instructions.d.ts +3 -0
  30. package/dist/language.cjs +1899 -51
  31. package/dist/language.js +1899 -51
  32. package/dist/libraries.cjs +1874 -26
  33. package/dist/libraries.d.cts +3 -0
  34. package/dist/libraries.d.ts +3 -0
  35. package/dist/libraries.js +1874 -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 +244 -11
  41. package/dist/signatures.js +244 -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 +39 -0
  65. package/dist/verify/solids.d.ts +39 -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 +299 -0
  71. package/dist/verify/types.d.ts +299 -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 +299 -3
  76. package/docs/parts-and-sheets.md +186 -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,171 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.0 (2026-11-03)
4
+
5
+ Language version 0.3. Programs for 0.2 run as before, except that a
6
+ variable no longer hides a function or built-in of the same name: after
7
+ `len = 3;`, `len([1, 2])` is 2, where it was an error. Numbers followed by
8
+ a unit, which were errors, are now lengths. New warnings and the positions
9
+ added to old ones change the text of warnings.
10
+
11
+ Records: `{kind = "armchair", x = 10}` holds values by name, read as
12
+ `s.kind` or `s["kind"]` (a missing field is `undef`), with `keys()`,
13
+ `merge()`, `is_record()` and `len()`. `kerf fmt` lays them out as lists.
14
+ `call("roses", 40, 30)` calls a module by name, so a table entry can carry
15
+ the module that draws it.
16
+
17
+ Assembly:
18
+
19
+ - `kerf verify` and the JavaScript verification API check explicit rigid fit,
20
+ shaft capture, conditional retention, material adaptation, cut invariance,
21
+ insertion/tool access, assembly support, static stability, ideal joint mobility
22
+ and continuous translation/rotation clearance. Reports distinguish pass, fail
23
+ and unverified within their stated scope and record input fingerprints.
24
+ `render(..., { analysis: true })` captures nominal cuts and native connections;
25
+ `poseAssembly()` previews the checked paths. Viewer diagnostics highlight
26
+ implicated bodies. Strength, friction and contact-driven mechanics remain
27
+ uncovered. See `docs/verification.md`.
28
+
29
+ - `place(at, rotate) { ... }` places the parts and hardware inside it, with
30
+ their own placements inside its. `box()` takes a `name` and shapes for
31
+ its front, so a box can be set anywhere.
32
+ - `part()` takes `stack = n` (glued layers), `mirror = true` (the left of a
33
+ pair, its text still reading; or one per copy, `mirror = [false, true]`,
34
+ for a pair whose art faces out on both), `bend = [x0, x1, angle]` (a living hinge
35
+ shown bent), `on = "part"` (glued to a bent part and moving with it),
36
+ `glue = "part", face = "top"` (laid on another part's face) and `slots =
37
+ ["part", ...]`: slots cut wherever those parts pass through it in the
38
+ assembly, at any angle, so tabs are drawn once.
39
+ - `step(text) { ... }` makes assembly steps, and `hardware(kind, from, to,
40
+ size)` lists dowels, screws, magnets and paper. `render()` returns
41
+ `steps` and `hardware`; `kerf check` lists them.
42
+ - `orient(x, z)`, `rotation(angles)` and `euler(matrix)` turn parts any way.
43
+ - Collisions are checked for each flat run of a bent part, and a collision
44
+ warning says where in the assembly it is.
45
+
46
+ A 3D view in the playground (the Assembled tab) and on every model page
47
+ (Build it) shows the model put together from the program, bends and
48
+ hardware included, and builds it a step at a time.
49
+
50
+ Drawing:
51
+
52
+ - `spline(points, width)` and `spline_points()`, `hatch(angle, pitch,
53
+ width)`, `pattern(spacing, stagger)` that repeats a tile cheaply,
54
+ `paint(layers)` for painter's order, `measure()` with `$bounds`,
55
+ `fill_holes(min_area)`, `close(r)`, `line(a, b, width)` as an area,
56
+ `text(fit = width)`, and `path(d, close = true)`.
57
+ - `intersection()` clips the lines of any child, not only the first, to the
58
+ area of the other children. A child of lines alone leaves no area, so
59
+ `intersection() { outline() circle(d = 20); square(40); }` gives only the
60
+ clipped arc, whichever child comes first.
61
+ - `path_length()`, `point_at()`, `heading_at()` and `path_points()` work
62
+ along paths.
63
+ - Lengths in real units, as `140cm`, `2in` or `1.2m`, divided by `$scale`.
64
+
65
+ Output:
66
+
67
+ - `engrave(side = "back")`, `score(side = "back")` and `layer(side =
68
+ "back")` mark the faces underneath, in a second job per sheet turned over
69
+ left to right (`sheet.back`, `name-back.svg`).
70
+ - Line layers come after fill layers in the files, and `layer(order = n)`
71
+ sets the order. `layer(bleed = mm)` lets a printed layer run past the
72
+ part's edge, and `$registration = true` adds print-and-cut marks.
73
+ - `$nest = true` (`--nest`, the `nest` option) packs small parts into the
74
+ holes of bigger ones.
75
+ - A project's `kerf.json` can give `"sheet": [w, h]` for every design in
76
+ it that does not set `$sheet` (the `defaultSheet` option).
77
+ - Warnings about a part in pieces, a hole narrower than the kerf and a
78
+ collision say where.
79
+ - `kerf check --stats` counts points by part and layer, and `--sweep
80
+ name=from:step:to` checks a design over every combination of settings.
81
+ - A library's own `use` looks next to it first.
82
+ - `use` takes an absolute path, as `use </home/me/lib/props>`.
83
+ - A module or function defined with a built-in's name warns that it hides
84
+ the built-in.
85
+ - A stack glued under its host (`face = "bottom"`) grows down, away from it.
86
+ - A `step()` inside a step is a sub-step ("Add the chair: Glue the seat");
87
+ `step(text, substeps = false)` takes inner steps into itself.
88
+ - `kerf verify --summary` (and `triage()`) groups what did not pass by status
89
+ and reason, with the bodies involved and their measurements.
90
+ - A slot is cut through the whole thickness of the part, so a shoulder that
91
+ flares just inside its face is covered; parts that only touch still cut
92
+ nothing.
93
+ - A stack whose layers meet different parts in slots becomes a part per
94
+ layer (`top, layer 1`), each cutting only its own slots.
95
+ - The collision check reports any overlap deeper than 0.1 mm, where it
96
+ needed a cubic millimetre, and slots need a part to reach 1 mm in,
97
+ so a part dipping 0.13 mm into a floor is reported, not slotted.
98
+ - `ring_stack()` refuses a hole that leaves its core plates or the base
99
+ between their feet thinner than `$min_width`, naming the smallest hole.
100
+ - `children(i)` used several times in one call makes the child once (when it
101
+ only makes a shape), and the point cap is on each shape kept, with ten
102
+ times that for all the work along the way.
103
+ - `pattern()` over an area of many small shapes tests and clips each tile
104
+ only against the shapes it may touch: 30 hearts on a facade take 0.2 s,
105
+ not 6.
106
+ - `$label_parts = true` engraves each part's number on its back face and
107
+ lists the numbers in `kerf check`'s parts and steps (`label` on each part).
108
+ - A `paint()` child lying wholly on an area of the same layer under it
109
+ warns that it can't be seen.
110
+ - A fill lying wholly under fills of layers stacked above it in the files
111
+ warns: printed it won't show, engraved it burns twice. Two `paint()`
112
+ calls whose later piece went on an earlier layer do this. Fills narrower
113
+ than 1 mm all along, a stroke's to cover, are left out.
114
+ - A part narrower than `$min_width` (1.5 mm unless set; 0 turns it off)
115
+ somewhere warns, saying where.
116
+ - `symbol(..., box = "grid")` sizes and places a symbol by its icon set's
117
+ grid, so a set lines up as drawn.
118
+ - `kerf render model.kerf -o model.png [--px 1200]` draws a picture of each
119
+ sheet to check by eye: material, fills in their colours, lines on top.
120
+ - `kerf instructions model.kerf` (and `instructionsHtml()`) writes printable
121
+ assembly instructions: parts, sheets, and a page per step with the model
122
+ drawn so far, that step's parts picked out.
123
+ - `kerf diff a.kerf b.kerf` (and `diffRenders()`) lists what changed between
124
+ two renders, by part and layer, with where.
125
+ - `kerf render lib.kerf --call 'roses(40, 30)'` renders one call of a
126
+ library's module, with `-D` setting variables first.
127
+ - `--sweep 'w,d=100,80;200,150'` tries settings that go together as sets,
128
+ and `--params-list sets.json` reads the sets from a file.
129
+ - Two different parts with one name warn, since slots, glue and `on` find
130
+ parts by name. A length with a unit read before the program sets `$scale`
131
+ warns. `hardware()` warns about a kind outside the documented list
132
+ (`HARDWARE_KINDS`), which adds `steel`, `felt`, `wire` and `led`.
133
+ - A setting passed to `render()` (or `-D`, `--sweep`) that the program never
134
+ assigns warns, with the nearest name.
135
+ - `hardware(sides = ...)` takes 3 to 128 sides, counted as work toward the
136
+ point limit, and the 3D view never builds more. `kerf render -o x.png`
137
+ keeps a picture to 16 million pixels, 16384 a side, drawing a long thin
138
+ sheet smaller. Redefining a layer that is already another layer's back
139
+ (`layer("score-back", ...)` after `layer("score", side = "back")`) is an
140
+ error rather than quietly moving its marks to the front.
141
+ - A bend reaching beyond its part warns, and a 3D view cuts a part's bends
142
+ into at most 2000 bands, only where there is material. `$label_parts`
143
+ warns and leaves the parts unnumbered when the program has a front layer
144
+ of its own named `engrave-back`.
145
+ - The playground's downloads include the back-face jobs: a sheet with back
146
+ marks lists back SVG and DXF files, and one such sheet downloads as a ZIP
147
+ of its front and back.
148
+ - `kerf verify`: a stability claim over several loads needs its retention
149
+ links to join them into one assembly; loads held to separate roots are
150
+ unverified rather than standing together.
151
+
152
+ New libraries:
153
+
154
+ - `kerf/gears`: spur gears, racks, lantern gears and peg wheels,
155
+ eccentrics, snail cams and tappets.
156
+ - `kerf/lock`: a lock with a key, three layers deep.
157
+ - `kerf/rings`: round things of stacked rings on a crossed core.
158
+ - `kerf/joints`: `halved_pair()`, two profiles halved into each other (a
159
+ cross on its foot, a font, a dome), checking the strips beside the slots.
160
+ - `kerf/sizes`: paper, card and photo sizes by name.
161
+ - `kerf/symbols`: 867 pictograms by name, from open icon sets (see
162
+ THIRD-PARTY-NOTICES.md).
163
+ - `kerf/geo`: the world's land from Natural Earth, `world_map()` and
164
+ `is_land()`.
165
+ - `kerf/hinge` adds `flex_strip()`, a strip that follows a profile with
166
+ hinges on its curves and tabs on its straights, `strip_bends()` and
167
+ `narrow_hinge()`; `flex_box()` now shows assembled.
168
+
3
169
  ## 0.6.0 (2026-11-02)
4
170
 
5
171
  Language version 0.2, as in 0.5.0: programs run as before.
@@ -8,7 +174,7 @@ Language version 0.2, as in 0.5.0: programs run as before.
8
174
  jewellery box, drawer cabinet, workshop holders, miniature furniture,
9
175
  radial shade, sliding puzzle, game insert, cable chain, cantilever case,
10
176
  beam balance, tilting stand, screw press, wheel calendar and laced mat.
11
- Each has an animated preview in the gallery.
177
+ Each has a 3D model in the gallery, and the mechanisms among them move.
12
178
  - `kerf import` and `importSvg()` turn an SVG drawing into a program. They
13
179
  write circles, rectangles, polygons, tabs, slots, finger joints, hanger
14
180
  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,23 @@ 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 |
157
194
 
158
195
  ## Layers
159
196
 
@@ -174,7 +211,23 @@ layer("pocket", mode = "fill", color = "#00aa00") ...
174
211
  Use `layer(name, mode, color)` to define a custom layer. Its mode is
175
212
  `"cut"`, `"line"`, `"fill"` or `"guide"`.
176
213
 
177
- Files list layers in this order: engrave, custom layers, score, cut, guide.
214
+ Marks can go on a part's **back face** too: `engrave(side = "back")`,
215
+ `score(side = "back")` or `layer(name, side = "back")`. Draw them where
216
+ they are on the part seen from the top, as everything else; text on the
217
+ back reads the right way round on the back. Each sheet with back marks
218
+ gets a second job (`sheet.back`, or `name-back.svg` from the command line),
219
+ the sheet turned over left to right: cut the sheet, turn it over without
220
+ moving the parts, line it up on the same corner and run the back job.
221
+
222
+ Files list layers in this order: engrave, custom fill layers, custom line
223
+ and cut layers, score, cut, guide, so a line is never covered by a fill.
224
+ `layer(name, order = n)` moves a custom layer among the others, lowest
225
+ first; at the same order fills still go under lines.
226
+
227
+ For printing on the parts before cutting, `layer(name, bleed = 2)` lets
228
+ that layer run 2 mm past the part's edge instead of being clipped to it,
229
+ and `$registration = true` puts marks in three corners of every sheet on
230
+ a `registration` layer, for a print-and-cut machine to line up on.
178
231
  Set the actual operation order, power and speed in your laser software.
179
232
  See [Laser software](docs/compatibility.md) for import details.
180
233
 
@@ -206,12 +259,59 @@ material(thickness = 4, kerf = 0.12, name = "birch") {
206
259
  rotated first, then moved, with its thickness along +Z. A part with copies
207
260
  takes one placement or a list with one per copy. `render()` returns the
208
261
  placed parts as `assembly` and warns when two of them collide.
262
+ `rotate = orient(x, z)` turns the part's own x and z axes onto two
263
+ directions; `euler(rotation(a) * rotation(b))` turns by `b`, then by `a`.
264
+ - More about a part, all named:
265
+ - `stack = n`: n layers glued at each placement, one thickness apart
266
+ along the part's z. The parts list says how many make a stack.
267
+ - `mirror = true`: the part is cut mirrored left to right (x becomes
268
+ -x), and its text still reads the right way round. Make the left of a
269
+ pair by mirroring the right. A list with one `true` or `false` per
270
+ copy mirrors only those copies, `qty = 2, mirror = [false, true]`, so
271
+ a pair of sides shows its art on the outside of both; the mirrored
272
+ copies are listed as a part of their own, `(mirrored)`.
273
+ - `bend = [x0, x1, angle]`, or a list of them: a living hinge from x0 to
274
+ x1 along the part's x bends it by `angle` degrees in the assembled
275
+ view, folding the far end up towards its top face (down for a negative
276
+ angle). The hinge's middle layer keeps its length.
277
+ - `on = "name"`: the part is glued to that bent part, and moves with the
278
+ run of it under its centre.
279
+ - `glue = "name"`, `face = "top"`: the part is glued flat on that part's
280
+ top (or bottom) face; its `at` and `rotate` are measured on the face,
281
+ and the parts list says what it is glued to. With as many copies as
282
+ the part it is glued on, one goes on each.
283
+ - `slots = ["name", ...]`: where the named parts' material passes through
284
+ this part in the assembly, slots are cut through it the shape of their
285
+ cross-section, at any angle, `clearance = 0.1` wider. Draw tabs on one
286
+ part and let the parts they go into cut their own slots. A name may
287
+ have `*` for any run of characters, and `"!name"` leaves out parts the
288
+ names before it took: `slots = ["*", "!back"]` cuts a slot for every
289
+ part that passes through except the back. A slot clears every layer,
290
+ marks included, and a part that only touches the edge leaves no notch.
291
+ - `place(at, rotate) { ... }` places the parts and hardware inside in the
292
+ assembled view, as part()'s `at` and `rotate` do; their own placements
293
+ are inside it. A library module wrapped in `place()` can be set anywhere.
294
+ - `step(text) { ... }`: an assembly step. Parts and hardware inside are
295
+ added in it, in the order steps first run; `render()` returns the steps'
296
+ text as `steps` and each placed part's `step`. The 3D view shows the
297
+ model built up a step at a time. A step inside a step is a sub-step,
298
+ `"outer: inner"`; `step(text, substeps = false)` takes inner steps in.
299
+ - `hardware(kind, from, to, size = 6, up, sides = 24, label)` lists
300
+ hardware the assembly needs, from one point to another: a dowel, a screw,
301
+ a magnet, paper. `size` is a diameter, or `[w, h]` for a flat section
302
+ whose `h` points along `up` (by default up, or along y for something
303
+ standing upright). A round one is drawn with `sides` sides, 3 to 128.
304
+ `render()` returns it as `hardware`, and `kerf check` lists it.
209
305
  - Shapes outside any part form one part named `part`.
210
306
  - `material(thickness, kerf, name) { ... }` sets those special variables for
211
307
  its children.
212
308
  - With `$layout = "pack"`, parts are grouped by material and thickness and
213
309
  repeated `qty` times. They are arranged in rows on sheets of `$sheet` and
214
310
  may be rotated 90° to fit. Parts larger than the sheet produce a warning.
311
+ A project's `kerf.json` can give `"sheet": [w, h]`, the laser's bed, for
312
+ every design in it that does not set `$sheet`.
313
+ - With `$nest = true`, small parts are packed inside the holes of bigger
314
+ ones, as rings inside rings.
215
315
 
216
316
  See [Parts and sheets](docs/parts-and-sheets.md) for spacing, layout and
217
317
  export examples.
@@ -228,9 +328,12 @@ export examples.
228
328
  | `regular_polygon(n, r)` | corner radius `r` |
229
329
  | `star(n, r, inner)` | |
230
330
  | `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 |
331
+ | `path(d, fill = "evenodd", close = false)` | SVG path data; closed subpaths become shapes, open ones lines unless `close` |
232
332
  | `text(text, size = 10, font, halign, valign, spacing = 1)` | `halign`: left, center, right; `valign`: baseline, top, center, bottom |
333
+ | `text(text, size, fit = width)` | no wider than `fit`: the size shrinks to fit, never above `size` if given |
233
334
  | `line(from, to)` | a line, not an area |
335
+ | `line(from, to, width)` | a strip `width` wide between the points, an area |
336
+ | `spline(points, width, steps = 8, closed = false)` | a smooth curve through the points; with `width`, an area along it |
234
337
  | `polyline(points, closed = false)` | |
235
338
  | `arc(r, start = 0, end = 90)` | arc line, angles in degrees |
236
339
 
@@ -253,15 +356,21 @@ playground, the command line and `kerfscript.wasm` have `Atkinson`
253
356
 
254
357
  ### Combining
255
358
 
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 |
359
+ | Module | Notes |
360
+ | ---------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
361
+ | `union()` / `group()` | joins children |
362
+ | `difference()` | removes every later child's area from every layer of the first child |
363
+ | `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 |
364
+ | `fill_holes(min_area)` | fills holes smaller than `min_area` mm², or all of them |
365
+ | `close(r = 0.5)` | closes gaps and notches narrower than `2 r`, keeping the outline |
366
+ | `pattern(spacing, stagger = 0)` | repeats its first child over the area of the others, clipped at the edge |
367
+ | `hatch(angle = 45, pitch = 5, width)` | parallel lines across the children's area, or stripes `width` wide |
368
+ | `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 |
369
+ | `measure(draw = false)` | `$bounds` = `[x0, y0, x1, y1]` of the first child, for the children after |
370
+ | `hull()` | convex hull; each named part inside gets its own hull |
371
+ | `offset(r)` / `offset(delta, chamfer = false)` | grow (positive) or shrink areas; `r` rounds corners |
372
+ | `stroke(width)` | turns lines into areas of that width, for cutting single line art |
373
+ | `outline()` | turns areas into their outline lines |
265
374
 
266
375
  ### Joinery
267
376
 
@@ -274,11 +383,12 @@ playground, the command line and `kerfscript.wasm` have `Atkinson`
274
383
 
275
384
  ### Other
276
385
 
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 |
386
+ | Module | Effect |
387
+ | ---------------------------- | ---------------------------------------------------------------------------------------------------------------- |
388
+ | `echo(...)` | Report values without creating geometry |
389
+ | `assert(condition, message)` | Stop with `message` when `condition` is false |
390
+ | `children(index)` | Render a child passed to the current module; omit `index` to render all children |
391
+ | `call(name, ...)` | Call the module named by the string `name` with the other arguments and the children: `call(entry.draw, 40, 30)` |
282
392
 
283
393
  ## Built-in functions
284
394
 
@@ -304,11 +414,28 @@ arguments.
304
414
  | `norm(v)` | Length of a vector |
305
415
  | `cross(a, b)` | Cross product; a scalar for 2D vectors or a vector for 3D vectors |
306
416
 
417
+ ### Paths and rotations
418
+
419
+ A path is a list of `[x, y]` points.
420
+
421
+ | Function | Result |
422
+ | -------------------------------------------------- | -------------------------------------------------------------------- |
423
+ | `path_length(points)` | Length along the path |
424
+ | `point_at(points, s)` | The point `s` along the path; past either end it carries on straight |
425
+ | `heading_at(points, s)` | The path's direction `s` along it, in degrees from +x |
426
+ | `path_points(d, tolerance)` | The points of SVG path data, a list of points for each subpath |
427
+ | `rotation(angles)` | The 3 × 3 matrix of `[x, y, z]` degrees as `part()` turns; use `*` |
428
+ | `euler(matrix)` | The `[x, y, z]` angles of a rotation matrix, for `rotate` |
429
+ | `orient(x, z = [0, 0, 1])` | The angles that turn a part's own x and z axes onto two directions |
430
+ | `spline_points(points, steps = 8, closed = false)` | The points of the smooth curve `spline()` draws |
431
+
307
432
  ### Lists and strings
308
433
 
309
434
  | Function | Result |
310
435
  | ------------------------------ | -------------------------------------------------------------------------------------------- |
311
- | `len(value)` | Number of items in a list or characters in a string |
436
+ | `len(value)` | Number of items in a list, characters in a string or fields in a record |
437
+ | `keys(record)` | A record's field names, in the order they were written |
438
+ | `merge(a, b)` | A record with the fields of both, `b`'s winning |
312
439
  | `concat(...)` | Join lists and individual values into one list |
313
440
  | `reverse(value)` | Reverse a list or string |
314
441
  | `sum(values)` | Sum a list of numbers |
@@ -325,7 +452,7 @@ arguments.
325
452
  ### Types
326
453
 
327
454
  `is_num(value)`, `is_string(value)`, `is_bool(value)`, `is_list(value)`,
328
- `is_undef(value)` and `is_function(value)` return a boolean.
455
+ `is_undef(value)`, `is_function(value)` and `is_record(value)` return a boolean.
329
456
  `type_of(value)` returns the type name as a string.
330
457
 
331
458
  ### Random values
@@ -339,6 +466,8 @@ bounds. The same seed gives the same sequence.
339
466
  spacing. `text_metrics(text, size, font)` returns
340
467
  `[advance, [[x0, y0], [x1, y1]], ascent, descent]`.
341
468
 
469
+ With `fit = width` they measure the text at the size `text()` would fit it to.
470
+
342
471
  Both require the font to be available to the renderer, just like `text()`.
343
472
 
344
473
  ### Joint dimensions
@@ -397,6 +526,7 @@ module and its parameters. Libraries others publish are installed with
397
526
  | `kerf/hanging` | `keyhole()`, `keyholes()`, `hanging_hole()`, `hanging_loop()` |
398
527
  | `kerf/enclosure` | `enclosure()`, `enclosure_cutouts()`, `vents()`: boxes with a screwed lid |
399
528
  | `kerf/calibration` | `kerf_gauge()`, `slot_gauge()`, `joint_test()`: test pieces |
529
+ | `kerf/joints` | `halved_pair()`: two profiles halved into each other |
400
530
 
401
531
  `box()` makes the six (or five) panels of a finger-jointed box as parts
402
532
  `bottom`, `lid`, `front`, `back`, `left`, `right`, from the outer size.
@@ -433,7 +563,7 @@ Programs are also limited in how much memory they can ask for:
433
563
  | `maxListLength` | 1,000,000 | items in one list or range, or characters in one string, including the text `echo()` writes in one call |
434
564
  | `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
565
  | `maxTextLength` | 2,000 | characters in one `text()` |
436
- | `maxPoints` | 2,000,000 | points in all shapes the modules make, plus 100 for each shape |
566
+ | `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
567
  | `maxOutputPoints` | 1,000,000 | points in the exported files, counting every copy |
438
568
  | `maxSheets` | 200 | sheets in the layout |
439
569
  | `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,