@mylasertools/kerfscript 0.8.0 → 0.9.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.
- package/CHANGELOG.md +69 -0
- package/LANGUAGE.md +189 -81
- package/README.md +2 -2
- package/dist/assembly.d.cts +2 -1
- package/dist/assembly.d.ts +2 -1
- package/dist/ast.d.cts +6 -0
- package/dist/ast.d.ts +6 -0
- package/dist/bores.d.cts +5 -0
- package/dist/bores.d.ts +5 -0
- package/dist/cli.js +1900 -274
- package/dist/customizer.d.cts +1 -0
- package/dist/customizer.d.ts +1 -0
- package/dist/evaluator.d.cts +9 -0
- package/dist/evaluator.d.ts +9 -0
- package/dist/functions.d.cts +2 -0
- package/dist/functions.d.ts +2 -0
- package/dist/geometry.d.cts +6 -0
- package/dist/geometry.d.ts +6 -0
- package/dist/halving.d.cts +8 -0
- package/dist/halving.d.ts +8 -0
- package/dist/highlight.cjs +2 -1
- package/dist/highlight.js +2 -1
- package/dist/index.cjs +131 -52
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +131 -52
- package/dist/language.cjs +111 -32
- package/dist/language.js +111 -32
- package/dist/libraries.cjs +93 -14
- package/dist/libraries.js +93 -14
- package/dist/plot.d.cts +16 -0
- package/dist/plot.d.ts +16 -0
- package/dist/signatures.cjs +160 -1
- package/dist/signatures.js +160 -1
- package/docs/cli.md +1 -0
- package/docs/compatibility.md +0 -8
- package/docs/customizer.md +18 -0
- package/docs/library.md +42 -1
- package/docs/parts-and-sheets.md +55 -0
- package/docs/versions.md +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,74 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.9.0 (2026-11-09)
|
|
4
|
+
|
|
5
|
+
Language version 0.3, as in 0.8.0: programs run as before.
|
|
6
|
+
|
|
7
|
+
Language:
|
|
8
|
+
|
|
9
|
+
- `assert(c, msg) expr` and `echo(...) expr` check or trace before an
|
|
10
|
+
expression, so a library function can refuse bad sizes itself; `let` (and
|
|
11
|
+
a function literal) can follow an operator.
|
|
12
|
+
- `sort(values, key)`, `fold(values, initial, fn)` and `scan(values,
|
|
13
|
+
initial, fn)`; `bounds(points)` and `crossings(points, x | y)` for
|
|
14
|
+
outlines as point lists.
|
|
15
|
+
- `intersection_for` intersects its iterations, as in OpenSCAD.
|
|
16
|
+
- `part(qty = 0)` makes nothing; `largest(n)` keeps the biggest pieces of the
|
|
17
|
+
material; `join_islands(width)` joins every piece to the rest.
|
|
18
|
+
- `text(weight = "bold")` and `text(bridge = w)` for cut-out lettering;
|
|
19
|
+
`symbol(solid = true, bridge)` cuts a pictogram in one piece with its
|
|
20
|
+
detail engraved.
|
|
21
|
+
|
|
22
|
+
Plotting (line art as pen plotters draw it, for score and engrave lines):
|
|
23
|
+
|
|
24
|
+
- `noise(x, y, z, seed, octaves)`: smooth gradient noise, or of a point
|
|
25
|
+
`noise(p / 30)`.
|
|
26
|
+
- `flow(field, spacing, step, min_length, seed)` fills an area with evenly
|
|
27
|
+
spaced lines that follow a direction field: an angle, or a function of
|
|
28
|
+
the point giving degrees, a vector, or `undef` where lines stop.
|
|
29
|
+
- `contours(field, levels, interval, cell)` draws where a height field
|
|
30
|
+
crosses each level across an area.
|
|
31
|
+
- `occlude()` draws its children back to front, each opaque: lines and
|
|
32
|
+
outlines hide behind later areas, with each `for` iteration a child of
|
|
33
|
+
its own; `hide()` is an area that covers without being drawn. Stacked
|
|
34
|
+
ridgelines, landscapes and overlapping shapes score without double lines.
|
|
35
|
+
- `$join_lines = true` joins lines that meet end to end and orders them
|
|
36
|
+
nearest first, so the laser travels less between them.
|
|
37
|
+
|
|
38
|
+
Joints, mechanisms and layout:
|
|
39
|
+
|
|
40
|
+
- `part(bores = ["Crank axle"], fit = "turn" | "press" | mm)` cuts holes
|
|
41
|
+
where hardware rods pass through, at any angle.
|
|
42
|
+
- `part(halving = ["Rib*"])`: crossing plates each slotted halfway, from
|
|
43
|
+
opposite sides.
|
|
44
|
+
- `part(slot_extra = [dx, dy])` sweeps slots for parts that drop in.
|
|
45
|
+
- `kerf check` names two parts whose tabs meet in one slot.
|
|
46
|
+
- A setting marked `// [0:5:360] drive` is the one that moves the model:
|
|
47
|
+
`kerf check --drive` tries every value, and the playground plays it.
|
|
48
|
+
- Copies of curved parts pack in rows, every other one turned, when that
|
|
49
|
+
takes fewer sheets (24 S-curved ribs: four sheets to one).
|
|
50
|
+
- `kerf/fit`: `fit(size, mode, anchor)` and `align(anchor)` for drawings of
|
|
51
|
+
unknown size.
|
|
52
|
+
|
|
53
|
+
Fixes:
|
|
54
|
+
|
|
55
|
+
- Slots: an edge lying on a face (a gable wall's top under its roof) is
|
|
56
|
+
touching, not a slot the length of the contact. The slot spans the part
|
|
57
|
+
only across from what goes deeper than the touching tolerance, so a tab's
|
|
58
|
+
flared shoulder is still cut. This removes stray slots from roofs whose
|
|
59
|
+
walls also tab through them.
|
|
60
|
+
- Sheet items of mirrored copies (`mirror = [false, true]`) keep their copy
|
|
61
|
+
numbers from the assembly; both used to say copy 1.
|
|
62
|
+
- A module that uses `children(i)` past the last child it was given warns,
|
|
63
|
+
with the call's line: `m() a(); b();` gives m() one child.
|
|
64
|
+
- Two libraries defining a module or function of the same name warn once,
|
|
65
|
+
naming both files; the later one is still used.
|
|
66
|
+
- A collision is reported at a point inside the overlap, not the middle of
|
|
67
|
+
the two parts' boxes.
|
|
68
|
+
- A line far longer than the area it is clipped to (a part's material, a
|
|
69
|
+
`difference()`) is clipped where it crosses the area, instead of running
|
|
70
|
+
on without reaching the step limit.
|
|
71
|
+
|
|
3
72
|
## 0.8.0 (2026-11-08)
|
|
4
73
|
|
|
5
74
|
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
|
-
| `$
|
|
193
|
-
| `$
|
|
194
|
-
| `$
|
|
195
|
-
| `$
|
|
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. `
|
|
263
|
-
|
|
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,24 @@ 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
|
-
| `
|
|
342
|
-
| `
|
|
343
|
-
| `
|
|
344
|
-
| `
|
|
345
|
-
| `
|
|
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])` | |
|
|
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 |
|
|
377
|
+
| `text(text, size, fit = width)` | no wider than `fit`: the size shrinks to fit, never above `size` if given |
|
|
378
|
+
| `text(text, size, weight = "bold")` | strokes thickened by 3.5% of the size, or by a number of mm (less than 0 thins) |
|
|
379
|
+
| `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 |
|
|
380
|
+
| `line(from, to)` | a line, not an area |
|
|
381
|
+
| `line(from, to, width)` | a strip `width` wide between the points, an area |
|
|
382
|
+
| `spline(points, width, steps = 8, closed = false)` | a smooth curve through the points; with `width`, an area along it |
|
|
383
|
+
| `polyline(points, closed = false)` | |
|
|
384
|
+
| `arc(r, start = 0, end = 90)` | arc line, angles in degrees |
|
|
346
385
|
|
|
347
386
|
Supply geometry as children of a shape-processing module, for example
|
|
348
387
|
`translate([10, 0]) circle(d = 5);`. Fonts used by `text()` must be supplied
|
|
@@ -363,21 +402,27 @@ playground, the command line and `kerfscript.wasm` have `Atkinson`
|
|
|
363
402
|
|
|
364
403
|
### Combining
|
|
365
404
|
|
|
366
|
-
| Module
|
|
367
|
-
|
|
|
368
|
-
| `union()` / `group()`
|
|
369
|
-
| `difference()`
|
|
370
|
-
| `intersection()`
|
|
371
|
-
| `fill_holes(min_area)`
|
|
372
|
-
| `
|
|
373
|
-
| `
|
|
374
|
-
| `
|
|
375
|
-
| `
|
|
376
|
-
| `
|
|
377
|
-
| `
|
|
378
|
-
| `
|
|
379
|
-
| `
|
|
380
|
-
| `
|
|
405
|
+
| Module | Notes |
|
|
406
|
+
| ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------- |
|
|
407
|
+
| `union()` / `group()` | joins children |
|
|
408
|
+
| `difference()` | removes every later child's area from every layer of the first child |
|
|
409
|
+
| `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 |
|
|
410
|
+
| `fill_holes(min_area)` | fills holes smaller than `min_area` mm², or all of them |
|
|
411
|
+
| `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 |
|
|
412
|
+
| `largest(n = 1)` | keeps the `n` biggest connected pieces of the material, dropping crumbs; marks stay as drawn |
|
|
413
|
+
| `close(r = 0.5)` | closes gaps and notches narrower than `2 r`, keeping the outline |
|
|
414
|
+
| `pattern(spacing, stagger = 0)` | repeats its first child over the area of the others, clipped at the edge |
|
|
415
|
+
| `hatch(angle = 45, pitch = 5, width)` | parallel lines across the children's area, or stripes `width` wide |
|
|
416
|
+
| `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) |
|
|
417
|
+
| `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` |
|
|
418
|
+
| `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 |
|
|
419
|
+
| `hide()` | inside `occlude()`, an area that hides what is behind it and is not drawn |
|
|
420
|
+
| `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 |
|
|
421
|
+
| `measure(draw = false)` | `$bounds` = `[x0, y0, x1, y1]`, `$area` and `$centroid` = `[x, y]` of the first child, for the children after |
|
|
422
|
+
| `hull()` | convex hull; each named part inside gets its own hull |
|
|
423
|
+
| `offset(r)` / `offset(delta, chamfer = false)` | grow (positive) or shrink areas; `r` rounds corners |
|
|
424
|
+
| `stroke(width)` | turns lines into areas of that width, for cutting single line art |
|
|
425
|
+
| `outline()` | turns areas into their outline lines |
|
|
381
426
|
|
|
382
427
|
### Joinery
|
|
383
428
|
|
|
@@ -397,6 +442,57 @@ playground, the command line and `kerfscript.wasm` have `Atkinson`
|
|
|
397
442
|
| `children(index)` | Render a child passed to the current module; omit `index` to render all children |
|
|
398
443
|
| `call(name, ...)` | Call the module named by the string `name` with the other arguments and the children: `call(entry.draw, 40, 30)` |
|
|
399
444
|
|
|
445
|
+
### Plotting
|
|
446
|
+
|
|
447
|
+
Line art drawn the way pen plotters draw, for score and engrave lines.
|
|
448
|
+
|
|
449
|
+
`flow(field)` grows lines both ways from seeds until they leave the area,
|
|
450
|
+
the field stops, or they come within half of `spacing` of another line or
|
|
451
|
+
of themselves; new lines start `spacing` to either side of each line, so
|
|
452
|
+
they fill the area evenly. `field` is one angle, or a function of the point
|
|
453
|
+
`p` giving degrees, a vector `[x, y]`, or `undef` where lines stop. Another
|
|
454
|
+
`seed` gives another arrangement.
|
|
455
|
+
|
|
456
|
+
```kerf
|
|
457
|
+
part("Panel") {
|
|
458
|
+
rect([120, 80], r = 5);
|
|
459
|
+
score() flow(function(p) 180 * noise(p / 40, seed = 3, octaves = 2), spacing = 2)
|
|
460
|
+
offset(-5) rect([120, 80], r = 5);
|
|
461
|
+
}
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
`contours(field)` samples `field(p)` every `cell` mm across the area and
|
|
465
|
+
draws where it crosses each level, as a map's height lines.
|
|
466
|
+
|
|
467
|
+
```kerf
|
|
468
|
+
part("Coaster") {
|
|
469
|
+
circle(d = 90);
|
|
470
|
+
score() contours(function(p) noise(p / 30, seed = 7, octaves = 3), interval = 0.08)
|
|
471
|
+
circle(d = 82);
|
|
472
|
+
}
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
`occlude()` draws its children back to front as if each were opaque. Lines
|
|
476
|
+
and the outlines of line layers are cut where a later child's area covers
|
|
477
|
+
them; filled layers lose that area, as in `paint()`; cut and guide layers
|
|
478
|
+
are unchanged. `hide()` gives a child an area that covers without being
|
|
479
|
+
drawn. Stacked ridgelines, nearest last:
|
|
480
|
+
|
|
481
|
+
```kerf
|
|
482
|
+
ridge = function(k) [for (x = [0:2:100]) [x, k * 3 + 12 * max(0, noise(x / 15, k / 5))]];
|
|
483
|
+
part("Ridges") {
|
|
484
|
+
translate([-5, -5]) rect([110, 75]);
|
|
485
|
+
occlude() for (k = [19:-1:0]) {
|
|
486
|
+
score() polyline(ridge(k));
|
|
487
|
+
hide() polygon(concat(ridge(k), [[100, -1], [0, -1]]));
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
Set `$join_lines = true` to join lines that meet end to end into one and
|
|
493
|
+
put them in nearest-first order, each started from its end nearer the
|
|
494
|
+
last, so the laser head travels less between them.
|
|
495
|
+
|
|
400
496
|
## Built-in functions
|
|
401
497
|
|
|
402
498
|
Functions return values. Arguments can be positional or named with the
|
|
@@ -426,37 +522,42 @@ arguments.
|
|
|
426
522
|
|
|
427
523
|
A path is a list of `[x, y]` points.
|
|
428
524
|
|
|
429
|
-
| Function
|
|
430
|
-
|
|
|
431
|
-
| `path_length(points)`
|
|
432
|
-
| `point_at(points, s)`
|
|
433
|
-
| `heading_at(points, s)`
|
|
434
|
-
| `offset_path(points, d, closed = false)`
|
|
435
|
-
| `path_points(d, tolerance)`
|
|
436
|
-
| `rotation(angles)`
|
|
437
|
-
| `euler(matrix)`
|
|
438
|
-
| `orient(x, z = [0, 0, 1])`
|
|
439
|
-
| `spline_points(points, steps = 8, closed = false)`
|
|
525
|
+
| Function | Result |
|
|
526
|
+
| ---------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
|
|
527
|
+
| `path_length(points)` | Length along the path |
|
|
528
|
+
| `point_at(points, s)` | The point `s` along the path; past either end it carries on straight |
|
|
529
|
+
| `heading_at(points, s)` | The path's direction `s` along it, in degrees from +x |
|
|
530
|
+
| `offset_path(points, d, closed = false)` | The path moved `d` to its left (right for `d < 0`), corners mitred |
|
|
531
|
+
| `path_points(d, tolerance)` | The points of SVG path data, a list of points for each subpath |
|
|
532
|
+
| `rotation(angles)` | The 3 × 3 matrix of `[x, y, z]` degrees as `part()` turns; use `*` |
|
|
533
|
+
| `euler(matrix)` | The `[x, y, z]` angles of a rotation matrix, for `rotate` |
|
|
534
|
+
| `orient(x, z = [0, 0, 1])` | The angles that turn a part's own x and z axes onto two directions |
|
|
535
|
+
| `spline_points(points, steps = 8, closed = false)` | The points of the smooth curve `spline()` draws |
|
|
536
|
+
| `bounds(points)` | `[x0, y0, x1, y1]` round a list of points, or of outlines |
|
|
537
|
+
| `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
538
|
|
|
441
539
|
### Lists and strings
|
|
442
540
|
|
|
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
|
-
| `
|
|
451
|
-
| `
|
|
452
|
-
| `
|
|
453
|
-
| `
|
|
454
|
-
| `
|
|
455
|
-
| `
|
|
456
|
-
| `
|
|
457
|
-
| `
|
|
458
|
-
| `
|
|
459
|
-
| `
|
|
541
|
+
| Function | Result |
|
|
542
|
+
| ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------- |
|
|
543
|
+
| `len(value)` | Number of items in a list, characters in a string or fields in a record |
|
|
544
|
+
| `keys(record)` | A record's field names, in the order they were written |
|
|
545
|
+
| `merge(a, b)` | A record with the fields of both, `b`'s winning |
|
|
546
|
+
| `concat(...)` | Join lists and individual values into one list |
|
|
547
|
+
| `reverse(value)` | Reverse a list or string |
|
|
548
|
+
| `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 |
|
|
549
|
+
| `fold(values, initial, fn)` | The value after `fn(acc, item)` for each item in turn, from `initial` |
|
|
550
|
+
| `scan(values, initial, fn)` | The value after each item as `fold()` goes: running totals, `[]` for an empty list |
|
|
551
|
+
| `sum(values)` | Sum a list of numbers |
|
|
552
|
+
| `slice(value, start = 0, end)` | Extract part of a list or string; `end` is exclusive and defaults to its length |
|
|
553
|
+
| `str(...)` | Convert values to text and join them |
|
|
554
|
+
| `chr(...)`, `ord(text)` | Convert Unicode code points to text, or read the first character's code point |
|
|
555
|
+
| `upper(text)`, `lower(text)` | Change letter case |
|
|
556
|
+
| `split(text, separator = " ")` | Split text into a list of strings |
|
|
557
|
+
| `join(values, separator = "")` | Join values into a string |
|
|
558
|
+
| `search(value, list)` | Index of the first equal item, or `undef` if absent; also searches characters in strings |
|
|
559
|
+
| `contains(value, item)` | Whether a list contains an item or a string contains a substring |
|
|
560
|
+
| `lookup(x, table)` | Interpolate in a table of `[x, y]` pairs; use the nearest endpoint outside the table's range |
|
|
460
561
|
|
|
461
562
|
### Types
|
|
462
563
|
|
|
@@ -469,6 +570,13 @@ A path is a list of `[x, y]` points.
|
|
|
469
570
|
`rands(min, max, count, seed = 1)` returns a list of numbers between the
|
|
470
571
|
bounds. The same seed gives the same sequence.
|
|
471
572
|
|
|
573
|
+
`noise(x, y = 0, z = 0, seed = 1, octaves = 1)` is smooth gradient noise,
|
|
574
|
+
about -1 to 1, that changes gradually from point to point; `x` may be a
|
|
575
|
+
point `[x, y]` or `[x, y, z]`, as in `noise(p / 30, seed = 4)`. It is 0 at
|
|
576
|
+
whole numbers, so scale the point down for broad shapes. `octaves` adds
|
|
577
|
+
finer layers, each half as strong at twice the detail. Step `z` to get a
|
|
578
|
+
related but different pattern.
|
|
579
|
+
|
|
472
580
|
### Text measurements
|
|
473
581
|
|
|
474
582
|
`text_width(text, size, font)` returns the advance width, including glyph
|
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
|
|
73
|
-
|
|
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:
|
package/dist/assembly.d.cts
CHANGED
|
@@ -31,9 +31,10 @@ 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[];
|
package/dist/assembly.d.ts
CHANGED
|
@@ -31,9 +31,10 @@ 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[];
|
package/dist/ast.d.cts
CHANGED
|
@@ -81,6 +81,11 @@ export type Expr = {
|
|
|
81
81
|
body: Expr;
|
|
82
82
|
pos: Pos;
|
|
83
83
|
end?: number;
|
|
84
|
+
} | {
|
|
85
|
+
kind: 'chain';
|
|
86
|
+
check: Expr;
|
|
87
|
+
body: Expr;
|
|
88
|
+
pos: Pos;
|
|
84
89
|
};
|
|
85
90
|
export type ListItem = {
|
|
86
91
|
kind: 'item';
|
|
@@ -153,6 +158,7 @@ export type Stmt = ({
|
|
|
153
158
|
assigns: Assign[];
|
|
154
159
|
body: Stmt[];
|
|
155
160
|
pos: Pos;
|
|
161
|
+
intersect?: boolean;
|
|
156
162
|
} | {
|
|
157
163
|
kind: 'if';
|
|
158
164
|
cond: Expr;
|
package/dist/ast.d.ts
CHANGED
|
@@ -81,6 +81,11 @@ export type Expr = {
|
|
|
81
81
|
body: Expr;
|
|
82
82
|
pos: Pos;
|
|
83
83
|
end?: number;
|
|
84
|
+
} | {
|
|
85
|
+
kind: 'chain';
|
|
86
|
+
check: Expr;
|
|
87
|
+
body: Expr;
|
|
88
|
+
pos: Pos;
|
|
84
89
|
};
|
|
85
90
|
export type ListItem = {
|
|
86
91
|
kind: 'item';
|
|
@@ -153,6 +158,7 @@ export type Stmt = ({
|
|
|
153
158
|
assigns: Assign[];
|
|
154
159
|
body: Stmt[];
|
|
155
160
|
pos: Pos;
|
|
161
|
+
intersect?: boolean;
|
|
156
162
|
} | {
|
|
157
163
|
kind: 'if';
|
|
158
164
|
cond: Expr;
|
package/dist/bores.d.cts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { HardwareItem } from './evaluator.cjs';
|
|
2
|
+
import { type Poly } from './geometry.cjs';
|
|
3
|
+
import type { Solid } from './slots.cjs';
|
|
4
|
+
export declare const FITS: Record<string, number>;
|
|
5
|
+
export declare function boreFor(target: Solid, h: HardwareItem, room: number): Poly | undefined;
|
package/dist/bores.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { HardwareItem } from './evaluator.js';
|
|
2
|
+
import { type Poly } from './geometry.js';
|
|
3
|
+
import type { Solid } from './slots.js';
|
|
4
|
+
export declare const FITS: Record<string, number>;
|
|
5
|
+
export declare function boreFor(target: Solid, h: HardwareItem, room: number): Poly | undefined;
|