@mylasertools/kerfscript 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 (60) hide show
  1. package/CHANGELOG.md +157 -0
  2. package/LANGUAGE.md +200 -84
  3. package/README.md +4 -3
  4. package/dist/assembly.d.cts +4 -1
  5. package/dist/assembly.d.ts +4 -1
  6. package/dist/ast.d.cts +6 -0
  7. package/dist/ast.d.ts +6 -0
  8. package/dist/bores.d.cts +15 -0
  9. package/dist/bores.d.ts +15 -0
  10. package/dist/cli.js +8959 -6064
  11. package/dist/customizer.d.cts +4 -0
  12. package/dist/customizer.d.ts +4 -0
  13. package/dist/effects.d.cts +31 -0
  14. package/dist/effects.d.ts +31 -0
  15. package/dist/evaluator.d.cts +10 -0
  16. package/dist/evaluator.d.ts +10 -0
  17. package/dist/export/mesh.d.cts +53 -0
  18. package/dist/export/mesh.d.ts +53 -0
  19. package/dist/export/model.d.cts +12 -0
  20. package/dist/export/model.d.ts +12 -0
  21. package/dist/export/triangulate.d.cts +5 -0
  22. package/dist/export/triangulate.d.ts +5 -0
  23. package/dist/export/zip.d.cts +5 -0
  24. package/dist/export/zip.d.ts +5 -0
  25. package/dist/functions.d.cts +2 -0
  26. package/dist/functions.d.ts +2 -0
  27. package/dist/geometry.d.cts +7 -0
  28. package/dist/geometry.d.ts +7 -0
  29. package/dist/halving.d.cts +8 -0
  30. package/dist/halving.d.ts +8 -0
  31. package/dist/highlight.cjs +3 -2
  32. package/dist/highlight.js +3 -2
  33. package/dist/import/dbg.d.cts +1 -0
  34. package/dist/import/dbg.d.ts +1 -0
  35. package/dist/index.cjs +522 -56
  36. package/dist/index.d.cts +6 -2
  37. package/dist/index.d.ts +6 -2
  38. package/dist/index.js +522 -56
  39. package/dist/language.cjs +495 -36
  40. package/dist/language.js +495 -36
  41. package/dist/libraries.cjs +474 -16
  42. package/dist/libraries.js +474 -16
  43. package/dist/plot.d.cts +16 -0
  44. package/dist/plot.d.ts +16 -0
  45. package/dist/render.d.cts +3 -0
  46. package/dist/render.d.ts +3 -0
  47. package/dist/signatures.cjs +182 -5
  48. package/dist/signatures.js +182 -5
  49. package/dist/text.d.cts +6 -0
  50. package/dist/text.d.ts +6 -0
  51. package/docs/3d-files.md +72 -0
  52. package/docs/cli.md +27 -21
  53. package/docs/compatibility.md +0 -8
  54. package/docs/customizer.md +74 -0
  55. package/docs/javascript.md +46 -0
  56. package/docs/library.md +162 -1
  57. package/docs/openscad.md +15 -13
  58. package/docs/parts-and-sheets.md +57 -1
  59. package/docs/versions.md +2 -2
  60. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,162 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.10.0 (2026-11-16)
4
+
5
+ Language version 0.3, as in 0.9.0: programs run as before, except that
6
+ `color()` and `linear_extrude()` now warn instead of stopping.
7
+
8
+ Changes to the output of existing programs, each a fix (see Fixes below):
9
+
10
+ - Slots for parts that pass through at an angle are cut to what passes
11
+ through the sheet, so they can be narrower than before; check the fit of
12
+ angled tabs, tapered ones especially.
13
+ - `intersection()` with a part as its first child clips the part instead of
14
+ emptying it.
15
+ - A default such as `w = $thickness` takes the `$thickness` passed with the
16
+ call.
17
+ - Parts riding a bent part, and mirrored copies of bent parts, are placed,
18
+ slotted and bored where they end up.
19
+ - SVG import reads units on shapes and keeps a viewBox's proportions.
20
+
21
+ Language:
22
+
23
+ - `text(fit = [w, h])` keeps text no wider than `w` and its capitals no
24
+ taller than `h`; `valign = "cap"` centres the capitals on y = 0.
25
+ - `text_size()` gives a text's measurements as a record: `width`, `height`,
26
+ `bounds`, `cap`, `ascent`, `descent` and the `size` used.
27
+ - `ellipse(d = [w, h])` takes the width and height, as `circle(d)` does.
28
+ - `color()` and `linear_extrude()` run as their children with a warning, so
29
+ the 2D part of an OpenSCAD file runs unchanged.
30
+ - Recursion and step-limit errors say what to check, instead of assuming an
31
+ endless loop.
32
+ - `use <...>` takes a Windows path, as `use <C:\Designs\lib\feet>`, and
33
+ paths with spaces; a library named that way finds the libraries beside it.
34
+
35
+ Fixes:
36
+
37
+ - `intersection()` clips a part that is its first child to the other
38
+ children, and warns when it leaves a part nothing to cut.
39
+ - A module's or function's defaults see the special variables passed with
40
+ the call: `w = $thickness` called with `$thickness = 6` is 6.
41
+ - Slots for parts at an angle cut only what passes through the sheet: a
42
+ tapered tab no longer cuts its wider part into the slot.
43
+ - Parts riding a bent part (`on = "host"`) have their slots, bores and
44
+ halvings cut where they ride.
45
+ - `sort()` counts its comparisons against the step limit.
46
+ - A mirrored copy of a bent part bends as its mirror image, and the copies
47
+ of a mirrored rider each ride their own host.
48
+ - Children that define a layer are evaluated each time they are used.
49
+ - Shaft capture fails when a part on the shaft can slide off over a bearing
50
+ and its retainer.
51
+ - SVG import: lengths on shapes keep their units (`width="40mm"`), and a
52
+ viewBox keeps its proportions as `preserveAspectRatio` says, centred by
53
+ default.
54
+
55
+ 3D files:
56
+
57
+ - `kerf render model.kerf -o model.glb` writes the model in 3D: `.glb` to view
58
+ or render, `.3mf` to 3D print in colour, `.stl` as one mesh. Each part is a
59
+ closed solid as thick as its sheet, where the assembly puts it, bent on its
60
+ living hinges; engraving and scoring are thin coloured bodies on its faces,
61
+ and hardware rods and balls. `--flat` lays the parts side by side, front
62
+ face up, for printing; `--mark-height` sets how far the marks stand off,
63
+ and `--print` is `--flat` with the marks 0.6 mm high.
64
+ - In JavaScript, `toModel(result, "glb" | "3mf" | "stl", options)`, with
65
+ `meshBodies()` for the solid bodies and `result.flat` for every part flat.
66
+
67
+ Libraries:
68
+
69
+ - `kerf/shapes`: `heart`, `teardrop`, `egg`, `lens`, `crescent`, `capsule`,
70
+ `diamond`, `rounded_polygon`, `shield`, `arrow`, `chevron`, `banner`,
71
+ `house`, `tag`, `ring`, `scalloped`, `flower`, `cloud` and
72
+ `speech_bubble`, each sized to a box and centred; shapes with one outline
73
+ also give it as points, `heart_points()` and the like.
74
+ - `kerf/stand`: `stand()` stands a sign or a photo in a base, upright or
75
+ leaning back, with `stand_tabs()` and `stand_slots()` for a base of your
76
+ own.
77
+
78
+ Customizer:
79
+
80
+ - `kerf check --settings` tries each setting across its range and says what
81
+ it changes: the files, only the assembled view, or nothing. It points out
82
+ where a slider stops changing anything and menu choices that give the same
83
+ result, and exits with 1 when a setting changes nothing or the program
84
+ stops at its values.
85
+ `settingEffects()` gives the same in JavaScript.
86
+ - A setting can end its comment with `when` and a condition on the other
87
+ settings, `// [0:0.05:0.5] when mount == "stand"`: the playground and the
88
+ desktop app show it only while the condition holds. `shown()` evaluates
89
+ it in JavaScript.
90
+
91
+ ## 0.9.0 (2026-11-09)
92
+
93
+ Language version 0.3, as in 0.8.0: programs run as before.
94
+
95
+ Language:
96
+
97
+ - `assert(c, msg) expr` and `echo(...) expr` check or trace before an
98
+ expression, so a library function can refuse bad sizes itself; `let` (and
99
+ a function literal) can follow an operator.
100
+ - `sort(values, key)`, `fold(values, initial, fn)` and `scan(values,
101
+ initial, fn)`; `bounds(points)` and `crossings(points, x | y)` for
102
+ outlines as point lists.
103
+ - `intersection_for` intersects its iterations, as in OpenSCAD.
104
+ - `part(qty = 0)` makes nothing; `largest(n)` keeps the biggest pieces of the
105
+ material; `join_islands(width)` joins every piece to the rest.
106
+ - `text(weight = "bold")` and `text(bridge = w)` for cut-out lettering;
107
+ `symbol(solid = true, bridge)` cuts a pictogram in one piece with its
108
+ detail engraved.
109
+
110
+ Plotting (line art as pen plotters draw it, for score and engrave lines):
111
+
112
+ - `noise(x, y, z, seed, octaves)`: smooth gradient noise, or of a point
113
+ `noise(p / 30)`.
114
+ - `flow(field, spacing, step, min_length, seed)` fills an area with evenly
115
+ spaced lines that follow a direction field: an angle, or a function of
116
+ the point giving degrees, a vector, or `undef` where lines stop.
117
+ - `contours(field, levels, interval, cell)` draws where a height field
118
+ crosses each level across an area.
119
+ - `occlude()` draws its children back to front, each opaque: lines and
120
+ outlines hide behind later areas, with each `for` iteration a child of
121
+ its own; `hide()` is an area that covers without being drawn. Stacked
122
+ ridgelines, landscapes and overlapping shapes score without double lines.
123
+ - `$join_lines = true` joins lines that meet end to end and orders them
124
+ nearest first, so the laser travels less between them.
125
+
126
+ Joints, mechanisms and layout:
127
+
128
+ - `part(bores = ["Crank axle"], fit = "turn" | "press" | mm)` cuts holes
129
+ where hardware rods pass through, at any angle.
130
+ - `part(halving = ["Rib*"])`: crossing plates each slotted halfway, from
131
+ opposite sides.
132
+ - `part(slot_extra = [dx, dy])` sweeps slots for parts that drop in.
133
+ - `kerf check` names two parts whose tabs meet in one slot.
134
+ - A setting marked `// [0:5:360] drive` is the one that moves the model:
135
+ `kerf check --drive` tries every value, and the playground plays it.
136
+ - Copies of curved parts pack in rows, every other one turned, when that
137
+ takes fewer sheets (24 S-curved ribs: four sheets to one).
138
+ - `kerf/fit`: `fit(size, mode, anchor)` and `align(anchor)` for drawings of
139
+ unknown size.
140
+
141
+ Fixes:
142
+
143
+ - Slots: an edge lying on a face (a gable wall's top under its roof) is
144
+ touching, not a slot the length of the contact. The slot spans the part
145
+ only across from what goes deeper than the touching tolerance, so a tab's
146
+ flared shoulder is still cut. This removes stray slots from roofs whose
147
+ walls also tab through them.
148
+ - Sheet items of mirrored copies (`mirror = [false, true]`) keep their copy
149
+ numbers from the assembly; both used to say copy 1.
150
+ - A module that uses `children(i)` past the last child it was given warns,
151
+ with the call's line: `m() a(); b();` gives m() one child.
152
+ - Two libraries defining a module or function of the same name warn once,
153
+ naming both files; the later one is still used.
154
+ - A collision is reported at a point inside the overlap, not the middle of
155
+ the two parts' boxes.
156
+ - A line far longer than the area it is clipped to (a part's material, a
157
+ `difference()`) is clipped where it crosses the area, instead of running
158
+ on without reaching the step limit.
159
+
3
160
  ## 0.8.0 (2026-11-08)
4
161
 
5
162
  Language version 0.3, as in 0.7.0: programs run as before.
package/LANGUAGE.md CHANGED
@@ -90,7 +90,20 @@ produce an error at the source line.
90
90
  In conditions, `false`, `0`, `""`, `[]` and `undef` count as false.
91
91
 
92
92
  Use `let (a = 1, b = a + 1) expr` to define names for one expression.
93
- Each binding can use the ones before it.
93
+ Each binding can use the ones before it. A `let` can follow an operator,
94
+ as in `ok && let (d = b - a) d > 0`; its expression reaches as far right as
95
+ it can.
96
+
97
+ `assert(condition, message) expr` checks before it works out `expr`, which
98
+ a failed assertion never reaches, and `echo(...) expr` prints on the way.
99
+ Checks chain, so a function can refuse bad arguments itself:
100
+
101
+ ```kerf
102
+ function slot_width(t, clearance) =
103
+ assert(t > 0, "Thickness must be positive")
104
+ assert(clearance >= 0, "Clearance must not be negative")
105
+ t + clearance;
106
+ ```
94
107
 
95
108
  ### List comprehensions
96
109
 
@@ -117,6 +130,7 @@ module name(a, b = 2) { ... } // module (makes shapes)
117
130
  name(args) child; // module call with one child
118
131
  name(args) { child; child; } // module call with a block of children
119
132
  for (i = range_or_list, j = ...) ... // repeats, combined as a union
133
+ intersection_for (i = ...) ... // repeats, keeping what every one covers
120
134
  if (cond) ... else ...
121
135
  let (a = 1) ...
122
136
  use <path> // import modules and functions
@@ -128,6 +142,8 @@ Arguments can be positional or named: `rect([20, 10], r = 2)`.
128
142
  A library's own `use <path>` and `include <path>` look next to that
129
143
  library first, then where the main program's would: `lib/props.kerf`
130
144
  saying `use <finish.kerf>` finds `lib/finish.kerf`.
145
+ When two libraries define a module or function of the same name, the one
146
+ used later replaces the earlier, with a warning naming both.
131
147
 
132
148
  ### Lengths in real units
133
149
 
@@ -165,6 +181,9 @@ the render options. `!` is accepted for OpenSCAD files and has no effect.
165
181
  Inside a module, `children()` renders all child statements passed by the
166
182
  caller. `children(index)` selects one child by its position from 0, or several with a list of positions.
167
183
  `$children` is the number of children.
184
+ A call without braces takes exactly one statement as its child: in
185
+ `m() a(); b();` only `a()` is a child, and `b()` stands on its own. A module
186
+ that asks for a child past the last one it was given warns.
168
187
 
169
188
  ```kerf
170
189
  module hang_hole(d = 5) {
@@ -174,25 +193,26 @@ module hang_hole(d = 5) {
174
193
 
175
194
  ## Special variables
176
195
 
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]` |
196
+ | Name | Default | Meaning |
197
+ | ----------------- | ------------- | ----------------------------------------------------------------------------- |
198
+ | `$thickness` | `3` | material thickness, used by joinery and stored on parts |
199
+ | `$kerf` | `0` | beam width; cut outlines are offset by half of it |
200
+ | `$material` | `"material"` | material name; parts are packed per material and thickness |
201
+ | `$sheet` | `[600, 400]` | sheet size for packing |
202
+ | `$gap` | `3` | space between packed parts and around the sheet edge |
203
+ | `$layout` | `"pack"` | `"pack"` packs parts onto sheets, `"none"` keeps your placement |
204
+ | `$fn` `$fa` `$fs` | `0` `2` `0.2` | curve resolution: fixed segment count, or max angle and max segment length |
205
+ | `$font` | | default font name for `text()` |
206
+ | `$mirrored` | `false` | set inside a mirrored part and on the back face: `text()` reads right |
207
+ | `$scale` | `1` | the model's scale: `140cm` is 1400 mm divided by `$scale` |
208
+ | `$nest` | `false` | pack small parts into the holes of bigger ones |
209
+ | `$registration` | `false` | print-and-cut marks in three corners of every sheet |
210
+ | `$label_parts` | `false` | engrave each part's number on its back face, as in the parts list and steps |
211
+ | `$join_lines` | `false` | join lines that meet end to end and order them nearest first, for less travel |
212
+ | `$min_width` | `1.5` | warn where a part's material is narrower than this; `0` turns it off |
213
+ | `$bounds` | | set by `measure()` for the children after the one it measures |
214
+ | `$area` | | set by `measure()`: the area of material the measured child cuts |
215
+ | `$centroid` | | set by `measure()`: the measured child's balance point `[x, y]` |
196
216
 
197
217
  ## Layers
198
218
 
@@ -259,8 +279,10 @@ material(thickness = 4, kerf = 0.12, name = "birch") {
259
279
  `$thickness`, `$kerf` and `$material` where it is called. `at = [x, y, z]`
260
280
  and `rotate = [x, y, z]` (degrees) place the part in the assembled view:
261
281
  rotated first, then moved, with its thickness along +Z. A part with copies
262
- takes one placement or a list with one per copy. `render()` returns the
263
- placed parts as `assembly` and warns when two of them collide.
282
+ takes one placement or a list with one per copy. `qty = 0` makes nothing,
283
+ so `part(qty = len(list), at = list)` needs no guard for an empty list.
284
+ `render()` returns the placed parts as `assembly` and warns when two of
285
+ them collide.
264
286
  `rotate = orient(x, z)` turns the part's own x and z axes onto two
265
287
  directions; `euler(rotation(a) * rotation(b))` turns by `b`, then by `a`.
266
288
  - More about a part, all named:
@@ -292,6 +314,21 @@ material(thickness = 4, kerf = 0.12, name = "birch") {
292
314
  names before it took: `slots = ["*", "!back"]` cuts a slot for every
293
315
  part that passes through except the back. A slot clears every layer,
294
316
  marks included, and a part that only touches the edge leaves no notch.
317
+ - `slot_extra = [dx, dy]` sweeps each of its slots that far in this
318
+ part's own coordinates: a pegboard hook goes in through the slot and
319
+ drops, so its slot is taller than its tab.
320
+ - `halving = ["name", ...]`: where this part and the named parts cross,
321
+ each takes a slot from opposite sides, meeting halfway along the line
322
+ they cross on, `clearance` wider, so they slide together: an egg-crate
323
+ grid, or ribs notched from their outer edge onto rings slotted from
324
+ their inner rim. The way round that leaves both parts soonest is used,
325
+ and a slot stops at the part's first edge. Names take `*` and `!`.
326
+ - `bores = ["label", ...]`: where the hardware rods with those labels (or
327
+ kinds) pass through this part, holes are cut the shape of their section,
328
+ at any angle. `fit = "turn"` (the default) makes them 0.3 mm wider than
329
+ the rod for a part that turns on it, `"press"` 0.1 mm narrower for one
330
+ held fast, or give a number of millimetres. Names take `*` and `!` as in
331
+ `slots`.
295
332
  - `place(at, rotate) { ... }` places the parts and hardware inside in the
296
333
  assembled view, as part()'s `at` and `rotate` do; their own placements
297
334
  are inside it. A library module wrapped in `place()` can be set anywhere.
@@ -327,22 +364,25 @@ export examples.
327
364
 
328
365
  ### Shapes
329
366
 
330
- | Module | Notes |
331
- | ---------------------------------------------------------- | ---------------------------------------------------------------------------- |
332
- | `rect(size, center = false, r = 0)` | `size` is a number or `[w, h]`; `r` rounds the corners. `square` is an alias |
333
- | `circle(r)` or `circle(d = ...)` | |
334
- | `ellipse([rx, ry])` | |
335
- | `regular_polygon(n, r)` | corner radius `r` |
336
- | `star(n, r, inner)` | |
337
- | `polygon(points, paths)` | even-odd fill, `paths` lists point indexes per outline |
338
- | `path(d, fill = "evenodd", close = false)` | SVG path data; closed subpaths become shapes, open ones lines unless `close` |
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 |
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 |
344
- | `polyline(points, closed = false)` | |
345
- | `arc(r, start = 0, end = 90)` | arc line, angles in degrees |
367
+ | Module | Notes |
368
+ | ---------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
369
+ | `rect(size, center = false, r = 0)` | `size` is a number or `[w, h]`; `r` rounds the corners. `square` is an alias |
370
+ | `circle(r)` or `circle(d = ...)` | |
371
+ | `ellipse([rx, ry])` or `ellipse(d = [w, h])` | radii, or the width and height |
372
+ | `regular_polygon(n, r)` | corner radius `r` |
373
+ | `star(n, r, inner)` | |
374
+ | `polygon(points, paths)` | even-odd fill, `paths` lists point indexes per outline |
375
+ | `path(d, fill = "evenodd", close = false)` | SVG path data; closed subpaths become shapes, open ones lines unless `close` |
376
+ | `text(text, size = 10, font, halign, valign, spacing = 1)` | `halign`: left, center, right; `valign`: baseline, top, center, bottom, or cap (capitals centred on y = 0) |
377
+ | `text(text, size, fit = width)` | no wider than `fit`: the size shrinks to fit, never above `size` if given |
378
+ | `text(text, size, fit = [w, h])` | no wider than `w`, capitals no taller than `h`; either may be `undef` |
379
+ | `text(text, size, weight = "bold")` | strokes thickened by 3.5% of the size, or by a number of mm (less than 0 thins) |
380
+ | `text(text, size, bridge = w)` | every island (an i's dot, an accent, a stencil's counter) joined to the rest by a strip `w` wide, for cut-out and stencil lettering |
381
+ | `line(from, to)` | a line, not an area |
382
+ | `line(from, to, width)` | a strip `width` wide between the points, an area |
383
+ | `spline(points, width, steps = 8, closed = false)` | a smooth curve through the points; with `width`, an area along it |
384
+ | `polyline(points, closed = false)` | |
385
+ | `arc(r, start = 0, end = 90)` | arc line, angles in degrees |
346
386
 
347
387
  Supply geometry as children of a shape-processing module, for example
348
388
  `translate([10, 0]) circle(d = 5);`. Fonts used by `text()` must be supplied
@@ -363,21 +403,27 @@ playground, the command line and `kerfscript.wasm` have `Atkinson`
363
403
 
364
404
  ### Combining
365
405
 
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 |
406
+ | Module | Notes |
407
+ | ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------- |
408
+ | `union()` / `group()` | joins children |
409
+ | `difference()` | removes every later child's area from every layer of the first child |
410
+ | `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 |
411
+ | `fill_holes(min_area)` | fills holes smaller than `min_area` mm², or all of them |
412
+ | `join_islands(width = 1)` | joins every separate piece of the material to the nearest other piece with a strip `width` wide, until it is one piece |
413
+ | `largest(n = 1)` | keeps the `n` biggest connected pieces of the material, dropping crumbs; marks stay as drawn |
414
+ | `close(r = 0.5)` | closes gaps and notches narrower than `2 r`, keeping the outline |
415
+ | `pattern(spacing, stagger = 0)` | repeats its first child over the area of the others, clipped at the edge |
416
+ | `hatch(angle = 45, pitch = 5, width)` | parallel lines across the children's area, or stripes `width` wide |
417
+ | `flow(field, spacing = 2, step, min_length, seed = 1)` | evenly spaced lines following `field(p)` (degrees, a vector, or `undef` to stop) across the children's area; see [Plotting](#plotting) |
418
+ | `contours(field, levels = 10, interval, cell = 1)` | lines where `field(p)` crosses each level across the children's area: `levels` evenly spaced ones or a list, or every `interval` |
419
+ | `occlude()` | children back to front: lines and outlines hide behind later children's areas, fills lose them. Each iteration of a `for` is a child |
420
+ | `hide()` | inside `occlude()`, an area that hides what is behind it and is not drawn |
421
+ | `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 |
422
+ | `measure(draw = false)` | `$bounds` = `[x0, y0, x1, y1]`, `$area` and `$centroid` = `[x, y]` of the first child, for the children after |
423
+ | `hull()` | convex hull; each named part inside gets its own hull |
424
+ | `offset(r)` / `offset(delta, chamfer = false)` | grow (positive) or shrink areas; `r` rounds corners |
425
+ | `stroke(width)` | turns lines into areas of that width, for cutting single line art |
426
+ | `outline()` | turns areas into their outline lines |
381
427
 
382
428
  ### Joinery
383
429
 
@@ -397,6 +443,57 @@ playground, the command line and `kerfscript.wasm` have `Atkinson`
397
443
  | `children(index)` | Render a child passed to the current module; omit `index` to render all children |
398
444
  | `call(name, ...)` | Call the module named by the string `name` with the other arguments and the children: `call(entry.draw, 40, 30)` |
399
445
 
446
+ ### Plotting
447
+
448
+ Line art drawn the way pen plotters draw, for score and engrave lines.
449
+
450
+ `flow(field)` grows lines both ways from seeds until they leave the area,
451
+ the field stops, or they come within half of `spacing` of another line or
452
+ of themselves; new lines start `spacing` to either side of each line, so
453
+ they fill the area evenly. `field` is one angle, or a function of the point
454
+ `p` giving degrees, a vector `[x, y]`, or `undef` where lines stop. Another
455
+ `seed` gives another arrangement.
456
+
457
+ ```kerf
458
+ part("Panel") {
459
+ rect([120, 80], r = 5);
460
+ score() flow(function(p) 180 * noise(p / 40, seed = 3, octaves = 2), spacing = 2)
461
+ offset(-5) rect([120, 80], r = 5);
462
+ }
463
+ ```
464
+
465
+ `contours(field)` samples `field(p)` every `cell` mm across the area and
466
+ draws where it crosses each level, as a map's height lines.
467
+
468
+ ```kerf
469
+ part("Coaster") {
470
+ circle(d = 90);
471
+ score() contours(function(p) noise(p / 30, seed = 7, octaves = 3), interval = 0.08)
472
+ circle(d = 82);
473
+ }
474
+ ```
475
+
476
+ `occlude()` draws its children back to front as if each were opaque. Lines
477
+ and the outlines of line layers are cut where a later child's area covers
478
+ them; filled layers lose that area, as in `paint()`; cut and guide layers
479
+ are unchanged. `hide()` gives a child an area that covers without being
480
+ drawn. Stacked ridgelines, nearest last:
481
+
482
+ ```kerf
483
+ ridge = function(k) [for (x = [0:2:100]) [x, k * 3 + 12 * max(0, noise(x / 15, k / 5))]];
484
+ part("Ridges") {
485
+ translate([-5, -5]) rect([110, 75]);
486
+ occlude() for (k = [19:-1:0]) {
487
+ score() polyline(ridge(k));
488
+ hide() polygon(concat(ridge(k), [[100, -1], [0, -1]]));
489
+ }
490
+ }
491
+ ```
492
+
493
+ Set `$join_lines = true` to join lines that meet end to end into one and
494
+ put them in nearest-first order, each started from its end nearer the
495
+ last, so the laser head travels less between them.
496
+
400
497
  ## Built-in functions
401
498
 
402
499
  Functions return values. Arguments can be positional or named with the
@@ -426,37 +523,42 @@ arguments.
426
523
 
427
524
  A path is a list of `[x, y]` points.
428
525
 
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 |
526
+ | Function | Result |
527
+ | ---------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
528
+ | `path_length(points)` | Length along the path |
529
+ | `point_at(points, s)` | The point `s` along the path; past either end it carries on straight |
530
+ | `heading_at(points, s)` | The path's direction `s` along it, in degrees from +x |
531
+ | `offset_path(points, d, closed = false)` | The path moved `d` to its left (right for `d < 0`), corners mitred |
532
+ | `path_points(d, tolerance)` | The points of SVG path data, a list of points for each subpath |
533
+ | `rotation(angles)` | The 3 × 3 matrix of `[x, y, z]` degrees as `part()` turns; use `*` |
534
+ | `euler(matrix)` | The `[x, y, z]` angles of a rotation matrix, for `rotate` |
535
+ | `orient(x, z = [0, 0, 1])` | The angles that turn a part's own x and z axes onto two directions |
536
+ | `spline_points(points, steps = 8, closed = false)` | The points of the smooth curve `spline()` draws |
537
+ | `bounds(points)` | `[x0, y0, x1, y1]` round a list of points, or of outlines |
538
+ | `crossings(points, x)` or `crossings(points, y = v)` | Where a vertical (or horizontal) line crosses a closed outline, or a list of them: the y (or x) values, smallest first |
440
539
 
441
540
  ### Lists and strings
442
541
 
443
- | Function | Result |
444
- | ------------------------------ | -------------------------------------------------------------------------------------------- |
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 |
448
- | `concat(...)` | Join lists and individual values into one list |
449
- | `reverse(value)` | Reverse a list or string |
450
- | `sum(values)` | Sum a list of numbers |
451
- | `slice(value, start = 0, end)` | Extract part of a list or string; `end` is exclusive and defaults to its length |
452
- | `str(...)` | Convert values to text and join them |
453
- | `chr(...)`, `ord(text)` | Convert Unicode code points to text, or read the first character's code point |
454
- | `upper(text)`, `lower(text)` | Change letter case |
455
- | `split(text, separator = " ")` | Split text into a list of strings |
456
- | `join(values, separator = "")` | Join values into a string |
457
- | `search(value, list)` | Index of the first equal item, or `undef` if absent; also searches characters in strings |
458
- | `contains(value, item)` | Whether a list contains an item or a string contains a substring |
459
- | `lookup(x, table)` | Interpolate in a table of `[x, y]` pairs; use the nearest endpoint outside the table's range |
542
+ | Function | Result |
543
+ | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------- |
544
+ | `len(value)` | Number of items in a list, characters in a string or fields in a record |
545
+ | `keys(record)` | A record's field names, in the order they were written |
546
+ | `merge(a, b)` | A record with the fields of both, `b`'s winning |
547
+ | `concat(...)` | Join lists and individual values into one list |
548
+ | `reverse(value)` | Reverse a list or string |
549
+ | `sort(values, key)` | The list smallest first: numbers, strings, or lists item by item; ordered by `key(item)` if given, equal keys keeping their order |
550
+ | `fold(values, initial, fn)` | The value after `fn(acc, item)` for each item in turn, from `initial` |
551
+ | `scan(values, initial, fn)` | The value after each item as `fold()` goes: running totals, `[]` for an empty list |
552
+ | `sum(values)` | Sum a list of numbers |
553
+ | `slice(value, start = 0, end)` | Extract part of a list or string; `end` is exclusive and defaults to its length |
554
+ | `str(...)` | Convert values to text and join them |
555
+ | `chr(...)`, `ord(text)` | Convert Unicode code points to text, or read the first character's code point |
556
+ | `upper(text)`, `lower(text)` | Change letter case |
557
+ | `split(text, separator = " ")` | Split text into a list of strings |
558
+ | `join(values, separator = "")` | Join values into a string |
559
+ | `search(value, list)` | Index of the first equal item, or `undef` if absent; also searches characters in strings |
560
+ | `contains(value, item)` | Whether a list contains an item or a string contains a substring |
561
+ | `lookup(x, table)` | Interpolate in a table of `[x, y]` pairs; use the nearest endpoint outside the table's range |
460
562
 
461
563
  ### Types
462
564
 
@@ -469,15 +571,29 @@ A path is a list of `[x, y]` points.
469
571
  `rands(min, max, count, seed = 1)` returns a list of numbers between the
470
572
  bounds. The same seed gives the same sequence.
471
573
 
574
+ `noise(x, y = 0, z = 0, seed = 1, octaves = 1)` is smooth gradient noise,
575
+ about -1 to 1, that changes gradually from point to point; `x` may be a
576
+ point `[x, y]` or `[x, y, z]`, as in `noise(p / 30, seed = 4)`. It is 0 at
577
+ whole numbers, so scale the point down for broad shapes. `octaves` adds
578
+ finer layers, each half as strong at twice the detail. Step `z` to get a
579
+ related but different pattern.
580
+
472
581
  ### Text measurements
473
582
 
474
583
  `text_width(text, size, font)` returns the advance width, including glyph
475
584
  spacing. `text_metrics(text, size, font)` returns
476
- `[advance, [[x0, y0], [x1, y1]], ascent, descent]`.
585
+ `[advance, [[x0, y0], [x1, y1]], ascent, descent]`. `text_size(text, size,
586
+ font)` returns the same as a record, with the capital height and the size
587
+ used: `width`, `height`, `bounds`, `cap`, `ascent`, `descent` and `size`.
588
+
589
+ ```kerf
590
+ m = text_size("Anna", fit = [80, 20]);
591
+ echo(m.size, m.cap); // the size that fits, and capitals 20 mm tall
592
+ ```
477
593
 
478
- With `fit = width` they measure the text at the size `text()` would fit it to.
594
+ With `fit` they measure the text at the size `text()` would fit it to.
479
595
 
480
- Both require the font to be available to the renderer, just like `text()`.
596
+ All three require the font to be available to the renderer, just like `text()`.
481
597
 
482
598
  ### Joint dimensions
483
599
 
package/README.md CHANGED
@@ -69,8 +69,8 @@ npx @mylasertools/kerfscript render box.kerf -o box.svg -D width=200
69
69
 
70
70
  That writes all six panels packed on a sheet, kerf compensated, as a
71
71
  millimetre SVG with one layer per operation. Output is checked automatically
72
- in Inkscape; see [docs/compatibility.md](docs/compatibility.md) for what has
73
- and has not been tested in other laser software.
72
+ in Inkscape; see [docs/compatibility.md](docs/compatibility.md) for import
73
+ settings in laser software.
74
74
 
75
75
  `kerf/box` is one of the libraries in the
76
76
  [standard library](docs/library.md), built into every renderer:
@@ -235,7 +235,8 @@ Errors are thrown as `KerfError` with `line` and `col`.
235
235
 
236
236
  - [Getting started](docs/getting-started.md), then the guides on
237
237
  [layers](docs/layers.md), [kerf](docs/kerf.md),
238
- [parts and sheets](docs/parts-and-sheets.md), [settings](docs/customizer.md),
238
+ [parts and sheets](docs/parts-and-sheets.md), [3D files](docs/3d-files.md),
239
+ [settings](docs/customizer.md),
239
240
  the [desktop app](docs/desktop.md), the [command line](docs/cli.md), the
240
241
  [JavaScript API](docs/javascript.md),
241
242
  [assembly verification](docs/verification.md),
@@ -31,13 +31,16 @@ export declare function placementMatrix(p: Placement): number[];
31
31
  export declare function worldBox(p: AssemblyPart): [Vec3, Vec3];
32
32
  export declare function besideAssembly(placed: AssemblyPart[], loose: AssemblyPart[], gap?: number): AssemblyPart[];
33
33
  export declare function collisions(parts: AssemblyPart[], maxPairs?: number, eps?: number, pitch?: number, volume?: number): {
34
- found: [AssemblyPart, AssemblyPart][];
34
+ found: [AssemblyPart, AssemblyPart, Vec3][];
35
35
  complete: boolean;
36
36
  };
37
+ export declare function overlapPoint(a: AssemblyPart, b: AssemblyPart, eps?: number, pitch?: number, volume?: number): Vec3 | undefined;
37
38
  export declare function translation(x: number, y: number, z: number): number[];
38
39
  export declare const IDENTITY4: number[];
39
40
  export declare function invert(m: number[]): number[];
40
41
  export declare function sortedBends(bends: Bend[]): Bend[];
42
+ /** Where each bend lies along the part's own x, as [from, to] */
43
+ export declare function bendSpans(bends: Bend[]): [number, number][];
41
44
  export declare function bendRuns(bends: Bend[], t: number): number[][];
42
45
  export declare function bendPoint(bends: Bend[], t: number, p: Vec3): Vec3;
43
46
  export declare function runOf(bends: Bend[], x: number): number;
@@ -31,13 +31,16 @@ export declare function placementMatrix(p: Placement): number[];
31
31
  export declare function worldBox(p: AssemblyPart): [Vec3, Vec3];
32
32
  export declare function besideAssembly(placed: AssemblyPart[], loose: AssemblyPart[], gap?: number): AssemblyPart[];
33
33
  export declare function collisions(parts: AssemblyPart[], maxPairs?: number, eps?: number, pitch?: number, volume?: number): {
34
- found: [AssemblyPart, AssemblyPart][];
34
+ found: [AssemblyPart, AssemblyPart, Vec3][];
35
35
  complete: boolean;
36
36
  };
37
+ export declare function overlapPoint(a: AssemblyPart, b: AssemblyPart, eps?: number, pitch?: number, volume?: number): Vec3 | undefined;
37
38
  export declare function translation(x: number, y: number, z: number): number[];
38
39
  export declare const IDENTITY4: number[];
39
40
  export declare function invert(m: number[]): number[];
40
41
  export declare function sortedBends(bends: Bend[]): Bend[];
42
+ /** Where each bend lies along the part's own x, as [from, to] */
43
+ export declare function bendSpans(bends: Bend[]): [number, number][];
41
44
  export declare function bendRuns(bends: Bend[], t: number): number[][];
42
45
  export declare function bendPoint(bends: Bend[], t: number, p: Vec3): Vec3;
43
46
  export declare function runOf(bends: Bend[], x: number): number;