@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/docs/cli.md CHANGED
@@ -104,27 +104,33 @@ installed libraries by themselves.
104
104
 
105
105
  ## Options
106
106
 
107
- | Option | Use |
108
- | ---------------------- | ------------------------------------------------------------------------------------ |
109
- | `-o, --out <file>` | Output path ending in `.svg`, `.dxf` or `.json`; defaults to `<file>.svg` |
110
- | `-D name=value` | Override a parameter; repeat for multiple values |
111
- | `-p, --params <file>` | Load parameter values from a JSON file |
112
- | `--font <file.ttf>` | Supply a font file; repeat for multiple fonts. `Atkinson` is built in |
113
- | `--kerf <mm>` | Override kerf for every part |
114
- | `--sheet <W>x<H>` | Set the sheet width and height in millimetres |
115
- | `--gap <mm>` | Set spacing between parts |
116
- | `--margin <mm>` | Set spacing at sheet edges; defaults to the gap |
117
- | `--no-pack` | Keep the positions defined in the program |
118
- | `--guides` | Include the guide layer |
119
- | `--split` | Export one file per sheet, and each sheet's back-face job |
120
- | `--nest` | Pack small parts into the holes of bigger ones |
121
- | `--stats` | With `check`: points in the files, by part and layer |
122
- | `--sweep name=a:s:b` | With `check`: try every value from a to b in steps of s, or `name=a,b,c` |
123
- | `-o out.png`, `--px n` | A picture of each sheet, `n` pixels wide (1200), to look at rather than cut |
124
- | `--call 'm(1, 2)'` | Run one call of the file's modules instead of its program; `-D` sets variables first |
125
- | `--params-list file` | With `check`: try each set of settings in a JSON list of objects |
126
- | `-h, --help` | Show command help |
127
- | `-v, --version` | Show version numbers |
107
+ | Option | Use |
108
+ | ---------------------- | ----------------------------------------------------------------------------------------------- |
109
+ | `-o, --out <file>` | Output path ending in `.svg`, `.dxf` or `.json`; defaults to `<file>.svg` |
110
+ | `-D name=value` | Override a parameter; repeat for multiple values |
111
+ | `-p, --params <file>` | Load parameter values from a JSON file |
112
+ | `--font <file.ttf>` | Supply a font file; repeat for multiple fonts. `Atkinson` is built in |
113
+ | `--kerf <mm>` | Override kerf for every part |
114
+ | `--sheet <W>x<H>` | Set the sheet width and height in millimetres |
115
+ | `--gap <mm>` | Set spacing between parts |
116
+ | `--margin <mm>` | Set spacing at sheet edges; defaults to the gap |
117
+ | `--no-pack` | Keep the positions defined in the program |
118
+ | `--guides` | Include the guide layer |
119
+ | `--split` | Export one file per sheet, and each sheet's back-face job |
120
+ | `--nest` | Pack small parts into the holes of bigger ones |
121
+ | `--stats` | With `check`: points in the files, by part and layer |
122
+ | `--sweep name=a:s:b` | With `check`: try every value from a to b in steps of s, or `name=a,b,c` |
123
+ | `--settings` | With `check`: what each setting changes across its range; exit 1 if one changes nothing |
124
+ | `--drive` | With `check`: try every value of the setting marked `drive` (see the customizer) |
125
+ | `-o out.png`, `--px n` | A picture of each sheet, `n` pixels wide (1200), to look at rather than cut |
126
+ | `-o out.glb` | The model in 3D: `.glb` to view, `.3mf` to print in colour, `.stl`; see [3D files](3d-files.md) |
127
+ | `--flat` | With a 3D file: the parts side by side, front face up |
128
+ | `--print` | With a 3D file: `--flat` with the marks 0.6 mm high, to print as a second colour |
129
+ | `--mark-height <mm>` | With a 3D file: how far engraving and scoring stand off the face (0.1) |
130
+ | `--call 'm(1, 2)'` | Run one call of the file's modules instead of its program; `-D` sets variables first |
131
+ | `--params-list file` | With `check`: try each set of settings in a JSON list of objects |
132
+ | `-h, --help` | Show command help |
133
+ | `-v, --version` | Show version numbers |
128
134
 
129
135
  `-D` accepts KerfScript values, including numbers, quoted strings, booleans
130
136
  and lists. For example: `-D width=200` or `-D 'name="Ada"'`.
@@ -28,14 +28,6 @@ and operation order.
28
28
 
29
29
  Six reference models passed these import checks on 28 October 2026.
30
30
  Drawing dimensions matched within 0.02 mm, including kerf compensation.
31
- These results cover file imports; they do not establish a fit for a
32
- particular machine or material.
33
-
34
- ## Not checked yet
35
-
36
- LightBurn, xTool Studio, xTool Creative Space, RDWorks and LaserGRBL have
37
- not yet been verified with the reference models. Import handling can differ
38
- between programs, especially for units, layer colours and fills.
39
31
 
40
32
  ## Checklist for a new program
41
33
 
@@ -55,6 +55,80 @@ A `//` comment immediately above a variable supplies its caption. Keep the
55
55
  file's introductory comment separate with a blank line so it does not
56
56
  become the first setting's caption.
57
57
 
58
+ ## The setting that moves the model
59
+
60
+ A model with moving parts usually has one number that drives them: a crank
61
+ angle, a lid's opening, the time of day. Mark it with `drive` after its
62
+ range:
63
+
64
+ ```kerf
65
+ crank = 0; // [0:5:360] drive
66
+
67
+ part("Wheel", at = [0, 0, 0]) circle(d = 60);
68
+ part("Crank", at = [0, 0, 3], rotate = [0, 0, crank]) rect([30, 8], center = true);
69
+ ```
70
+
71
+ The playground gives it a Play button that steps it round its range, and
72
+ `kerf check model.kerf --drive` builds the model at every step and reports
73
+ any position that warns (parts colliding, a slot that misses), as
74
+ `--sweep crank=0:5:360` would. `kerf params` lists it with `"drive": true`.
75
+
76
+ ## Settings that apply only sometimes
77
+
78
+ A setting that matters only with certain other choices can say so with
79
+ `when` and a condition at the end of its comment, after its range or
80
+ choices or on its own. The playground and the desktop app show it only
81
+ while the condition holds, and hide a group when none of its settings
82
+ show:
83
+
84
+ ```kerf
85
+ mount = "wall"; // [wall:On a wall, stand:On a stand]
86
+ // Room for the stand's tabs in their slots
87
+ clearance = 0.15; // [0:0.05:0.5] when mount == "stand"
88
+ // Hole for a nail
89
+ hole = 5; // when mount == "wall"
90
+
91
+ rect([120, 80], r = 6);
92
+ ```
93
+
94
+ The condition can use the other settings by name, numbers, strings,
95
+ `true` and `false`, comparisons, `&&`, `||`, `!`, arithmetic, `? :` and
96
+ `[i]` indexing. A condition that names something other than a setting, or
97
+ calls a function, is reported as a warning, and the setting then always
98
+ shows. `kerf params` lists the condition as `"when"`, and in JavaScript
99
+ `shown(parameter, values, parameters)` says whether a setting applies to
100
+ the values chosen so far.
101
+
102
+ ## Settings that do nothing
103
+
104
+ A setting whose slider moves nothing confuses the people using the design.
105
+ `kerf check --settings` tries each setting across its range, the others as
106
+ they are, and says what it changes:
107
+
108
+ ```text
109
+ $ kerf check sign.kerf --settings
110
+ Each setting tried across its range, the others as they are:
111
+ name: changes the files
112
+ band: changes the files
113
+ from 50 to 60 it changes nothing
114
+ notes: changes nothing at "for the shop", "for th", "pohs eht rof"
115
+ lift: changes only the assembled view, not the files
116
+ mount: changes the files
117
+ "wall" and "hook" give the same result
118
+ clearance: not tried, as it applies only when mount == "stand"
119
+ ```
120
+
121
+ A range is tried at its ends and three points between, a menu at every
122
+ choice, a checkbox both ways and text shorter and changed. The files, the
123
+ sheets' material and thickness and the parts list count as what is cut;
124
+ each part's shape, marks and place as the assembled view. A setting that
125
+ changes nothing, or that the program stops at for all values but one, makes
126
+ the command exit with 1, with the errors listed; a range where nothing
127
+ changes, or choices that give the same result, are pointed out without
128
+ failing. The
129
+ setting marked `drive` and settings whose `when` doesn't hold are left out.
130
+ In JavaScript, `settingEffects(source, options)` gives the same as a list.
131
+
58
132
  ## Changing settings without editing the file
59
133
 
60
134
  The CLI accepts values with `-D` or a JSON file with `--params`:
@@ -127,6 +127,52 @@ if (width) {
127
127
  Read the settings again after editing the source; the offsets refer to the
128
128
  string passed to `parameters()`.
129
129
 
130
+ A setting whose comment ends with a `when` condition (see the
131
+ [customizer](customizer.md)) has it as `when`. `shown()` says whether it
132
+ applies to the values chosen so far, the others at their initial values:
133
+
134
+ ```js
135
+ import { parameters, shown } from '@mylasertools/kerfscript';
136
+
137
+ const settings = parameters(source).parameters;
138
+ const visible = settings.filter((p) => shown(p, { mount: 'stand' }, settings));
139
+ ```
140
+
141
+ ## settingEffects()
142
+
143
+ What each setting changes, as `kerf check --settings` reports it:
144
+
145
+ ```js
146
+ import { settingEffects } from '@mylasertools/kerfscript';
147
+
148
+ for (const e of settingEffects(source)) console.log(e.name, e.effect, e.same);
149
+ ```
150
+
151
+ Each entry has `name`, the values `tried` and `effect`: `"files"`,
152
+ `"view"` (only the assembled view, steps or hardware), `"nothing"`,
153
+ `"failed"` (the program stops at all values but one, or all of them) or
154
+ `"skipped"` with a `reason`. `same` lists runs of a range, or groups of
155
+ choices, that give the same result, and `errors` the values the program
156
+ stops at. Pass render options as the second argument and how many values
157
+ of a range to try as the third (5).
158
+
159
+ ## toModel()
160
+
161
+ Write the model in 3D, as [3D files](3d-files.md) describes:
162
+
163
+ ```js
164
+ import { render, toModel } from '@mylasertools/kerfscript';
165
+
166
+ const glb = toModel(render(source), 'glb');
167
+ const print = toModel(render(source), '3mf', { layout: 'flat', markHeight: 0.6 });
168
+ ```
169
+
170
+ The format is `"glb"`, `"3mf"` or `"stl"`, and the result a `Uint8Array`.
171
+ `meshBodies(result, options)` gives the solid bodies (positions and
172
+ triangles in millimetres, z up) for a viewer of your own; `toGlb()`,
173
+ `to3mf()` and `toStl()` write a list of them. `result.flat` lists every copy
174
+ of every part flat at its own origin, placed or not.
175
+
130
176
  ## format()
131
177
 
132
178
  `format(source)` returns the program with its layout set, as `kerf fmt`
package/docs/library.md CHANGED
@@ -21,6 +21,7 @@ show each module's description when you hover over it.
21
21
  | ---------------------------------- | -------------------------------------------------------------- |
22
22
  | [`kerf/box`](#boxes) | Finger-jointed boxes and dividers that slide into them |
23
23
  | [`kerf/tabs`](#tabs-and-slots) | Tabs on one panel and the slots in another that they go into |
24
+ | [`kerf/stand`](#stands) | A sign or photo standing in a base, upright or leaning back |
24
25
  | [`kerf/hinge`](#living-hinges) | Living hinges that bend flat sheet, and a box with round sides |
25
26
  | [`kerf/dividers`](#dividers) | Dividers that slot into each other like an egg crate |
26
27
  | [`kerf/hanging`](#hanging) | Keyholes, holes and loops for hanging things on a wall |
@@ -32,6 +33,8 @@ show each module's description when you hover over it.
32
33
  | [`kerf/lock`](#lock) | A lock with a key, three layers deep |
33
34
  | [`kerf/rings`](#rings) | Round things of stacked rings on a crossed core |
34
35
  | [`kerf/joints`](#joints) | Two profiles halved into each other: crosses, fonts, domes |
36
+ | [`kerf/fit`](#fit-and-align) | Drawings scaled to a size and placed by a point of their box |
37
+ | [`kerf/shapes`](#shapes) | Hearts, teardrops, clouds, shields, banners, tags and more |
35
38
  | [`kerf/sizes`](#sizes) | Paper, card and photo sizes |
36
39
  | [`kerf/symbols`](#symbols) | 867 pictograms by name |
37
40
  | [`kerf/geo`](#maps) | The world's land, for maps and globes |
@@ -40,6 +43,17 @@ Sizes are in millimetres. Joints use `$thickness`, the sheet thickness, so
40
43
  set it to what you measure. Each section has an example in the gallery that
41
44
  you can open in the playground.
42
45
 
46
+ ### Before you draw it yourself
47
+
48
+ | To | Use |
49
+ | -------------------------------------------------- | ------------------------------------------------------- |
50
+ | Draw a heart, a teardrop, a cloud, a banner or tag | [`kerf/shapes`](#shapes) |
51
+ | Draw a pictogram: a paw, a tree, a star, a house | `symbol("paw", size)` from [`kerf/symbols`](#symbols) |
52
+ | Scale a drawing to a box, or place it by a corner | `fit()` and `align()` from [`kerf/fit`](#fit-and-align) |
53
+ | Close small gaps between shapes | `close(r)`, in place of `offset(delta = -r) offset(r)` |
54
+ | Fit text to a width or a height | `text(fit = [w, h])`, and `text_size()` to measure it |
55
+ | Stand a sign or a photo up | `stand()` from [`kerf/stand`](#stands) |
56
+
43
57
  ## Boxes
44
58
 
45
59
  `use <kerf/box>`
@@ -125,6 +139,50 @@ is `true` or `false` for all four, or `[bottom, right, top, left]`.
125
139
  The centres of the tabs along an edge, for placing anything else that
126
140
  lines up with them.
127
141
 
142
+ ## Stands
143
+
144
+ `use <kerf/stand>`
145
+
146
+ A panel (a sign, a photo frame, a calendar) standing in a base, its tabs
147
+ through slots in the base, upright or leaning back. `stand()` makes both
148
+ parts and puts them together; the tabs and slots always match, at any
149
+ lean and `$thickness`.
150
+
151
+ ```kerf
152
+ use <kerf/stand>
153
+
154
+ stand(160, depth = 45, lean = 10) {
155
+ rect([160, 90], r = 6);
156
+ engrave() translate([80, 45]) text("OPEN", fit = [120, 40], halign = "center", valign = "cap");
157
+ }
158
+ ```
159
+
160
+ ### `stand(width, depth = 40, count, tab, lean = 0, margin = 10, back, r = 3, clearance = 0.1, name = "Sign")`
161
+
162
+ The children draw the panel, its bottom edge on y = 0 from x = 0 to
163
+ `width`; `stand()` adds the tabs. The base is `depth` deep, `margin` wider
164
+ than the panel on each side, with corners rounded to `r`. The panel leans
165
+ back by `lean` degrees (up to 45), its back face meeting the base `back`
166
+ from the front (half way by default). The parts are `name` and
167
+ `"name stand"`.
168
+
169
+ | Parameter | Default | Meaning |
170
+ | ----------- | ------------------------------- | ------------------------------------ |
171
+ | `count` | one for every 50 mm, at least 1 | Number of tabs |
172
+ | `tab` | half the space between tabs | Width of each tab |
173
+ | `clearance` | `0.1` | Added to each slot's width and depth |
174
+
175
+ ### `stand_tabs(width, count, tab, lean = 0)`
176
+
177
+ The tabs for the bottom edge of a panel, x from 0 to `width`, hanging below
178
+ y = 0 far enough to go through a base `$thickness` thick at that lean.
179
+
180
+ ### `stand_slots(width, count, tab, lean = 0, clearance = 0.1)`
181
+
182
+ The slots for `stand_tabs()` with the same `width`, `count`, `tab` and
183
+ `lean`, for a base of your own: x from 0 to `width`, for a panel whose back
184
+ face meets the top of the base on y = 0, leaning back towards +y.
185
+
128
186
  ## Living hinges
129
187
 
130
188
  `use <kerf/hinge>`
@@ -732,6 +790,103 @@ floor on the front, x positions (3 mm wide) or `[x, width]` pairs, and
732
790
  naming both parts. The strips beside both slots must keep `$min_width`,
733
791
  and a foot may not run into the front's slot: either stops with where.
734
792
 
793
+ ## Fit and align
794
+
795
+ `use <kerf/fit>`
796
+
797
+ For a drawing whose size you don't know beforehand, such as an imported
798
+ SVG path, a silhouette or a symbol, these measure their children and
799
+ scale or move them, keeping every layer together. They are for drawings,
800
+ not parts: scaling a part would scale its joints but not its thickness.
801
+
802
+ ```kerf
803
+ use <kerf/fit>
804
+
805
+ part("tag") {
806
+ rect([60, 40], r = 4);
807
+ engrave() translate([30, 20]) fit([44, 24], anchor = "center")
808
+ path("M0 0 L40 0 L50 30 L20 45 Z");
809
+ }
810
+ ```
811
+
812
+ ### `fit(size, mode = "contain", anchor = "bottom-left")`
813
+
814
+ The children scaled to `size` (`[w, h]`, or one number for a square).
815
+ `mode = "contain"` keeps their proportions and fits them inside;
816
+ `"stretch"` fills the size exactly. A drawing with no width or no height,
817
+ a straight line, is scaled by its other side. The result is placed by
818
+ `anchor`, as `align()` does.
819
+
820
+ ### `align(anchor = "center")`, `anchor_point(anchor)`
821
+
822
+ The children moved so the point of their box that `anchor` names is at
823
+ the origin: `"center"`, `"left"`, `"right"`, `"top"`, `"bottom"`,
824
+ `"top-left"`, `"top-right"`, `"bottom-left"`, `"bottom-right"`, or
825
+ `[fx, fy]` as fractions of the box. `anchor_point()` gives those fractions.
826
+
827
+ ## Shapes
828
+
829
+ `use <kerf/shapes>`
830
+
831
+ Basic shapes by name, each sized to a box: `size` is `[w, h]`, or one
832
+ number for both, and the shape is centred on the origin as `circle()` and
833
+ `ellipse()` are. Arrows and chevrons point along x; the others stand
834
+ upright. Curves follow `$fn` when it is set, and otherwise take about a
835
+ point per millimetre.
836
+
837
+ ```kerf
838
+ use <kerf/shapes>
839
+
840
+ part("gift tag") {
841
+ tag([70, 36]);
842
+ engrave() translate([8, 0]) heart([16, 14]);
843
+ }
844
+ part("sign", at = [0, 50, 0]) {
845
+ banner([120, 30]);
846
+ engrave() text("WELCOME", fit = [80, 12], halign = "center", valign = "cap");
847
+ }
848
+ ```
849
+
850
+ A shape with one outline also has a `_points()` function that gives the
851
+ outline as points, counter-clockwise, with the same arguments: for
852
+ `offset_path()`, `flex_strip()`, `point_at()` and anything else that works
853
+ on a list of points. `heart_points(40)` is the outline of `heart(40)`.
854
+
855
+ | Shape | Draws |
856
+ | ------------------------------------------- | ----------------------------------------------------------------------------------------------- |
857
+ | `heart(size = 20)` | a heart: two round lobes, a dip between them and a point at the bottom |
858
+ | `teardrop(size = [14, 20])` | round at the bottom, a point at the top; taller than it is wide |
859
+ | `egg(size = [16, 20], taper = 0.2)` | an egg on its broad end; `taper` 0 is an ellipse |
860
+ | `lens(size = [10, 20])` | two arcs meeting in a point at each end of its longer side: a leaf, a petal, an eye |
861
+ | `crescent(d = 20, thickness)` | a crescent moon `d` across, open to the right, `thickness` (`d / 4`) at its widest |
862
+ | `capsule(size = [30, 10])` | a rectangle with round ends |
863
+ | `diamond(size = [14, 20])` | a rhombus touching the middle of each side of its box |
864
+ | `rounded_polygon(n = 6, r = 10, round = 2)` | `regular_polygon(n, r)` with each corner rounded to radius `round` |
865
+ | `shield(size = [16, 20], point = 0.55)` | a flat top and straight sides curving in to a point; `point` is the curve's part of `h` |
866
+ | `arrow(size = [30, 14], shaft, head)` | an arrow `size[0]` long with a head `size[1]` wide; `shaft` is `h / 3`, `head` `h` |
867
+ | `chevron(size = [12, 20], thickness)` | a chevron (>), each arm `thickness` (`w / 2`) across along x |
868
+ | `banner(size = [60, 16], notch)` | a banner with a V `notch` (`h / 3`) deep cut into each end |
869
+ | `house(size = [20, 24], roof)` | walls and a pitched roof `roof` (`w / 2`) tall |
870
+ | `tag(size = [50, 25], cut, hole)` | a tag with its left corners cut off by `cut` (`h / 4`) and a hole `hole` (`h / 4`) across |
871
+ | `ring(d = 20, width = 3)` | a ring `d` across with a band `width` wide |
872
+ | `scalloped(d = 30, n = 16)` | a circle `d` across with `n` round scallops round its edge |
873
+ | `flower(d = 30, petals = 6, center = 0.35)` | petals round a round middle `center` of `d` across |
874
+ | `cloud(size = [40, 24], puffs = 3)` | a flat bottom with `puffs` round puffs along the top |
875
+ | `speech_bubble(size = [40, 30], r, tail)` | a rounded box with a tail `tail` (`h / 4`) long at its bottom left; `mirror()` it for the right |
876
+
877
+ The outlines: `heart_points()`, `teardrop_points()`, `egg_points()`,
878
+ `lens_points()`, `crescent_points()`, `capsule_points()`,
879
+ `diamond_points()`, `rounded_polygon_points()`, `shield_points()`,
880
+ `arrow_points()`, `chevron_points()`, `banner_points()`, `house_points()`
881
+ and `tag_points()` (without the hole).
882
+
883
+ The library's helpers are there for your own shapes too:
884
+ `shape_size(size, what)` turns a number or `[w, h]` into `[w, h]` and
885
+ checks it, `shape_steps(length)` is the number of points for a curve about
886
+ `length` mm long, `shape_fill(points, size)` scales points to fill a box
887
+ centred on the origin, `shape_centre(points)` centres them, and
888
+ `shape_arc(c, r, a0, a1, n)` gives `n + 1` points along an arc. `shape_tall_lens([w, h])` is a lens pointed at the top and the bottom, as `lens()` draws one no wider than it is tall.
889
+
735
890
  ## Sizes
736
891
 
737
892
  `use <kerf/sizes>`
@@ -795,7 +950,7 @@ part("tag") {
795
950
  }
796
951
  ```
797
952
 
798
- ### `symbol(name, size = 10, center = true, fill = "nonzero", box = "drawn")`
953
+ ### `symbol(name, size = 10, center = true, fill = "nonzero", box = "drawn", solid = false, close, bridge)`
799
954
 
800
955
  The symbol `size` mm across the longer side of what it draws, centred on
801
956
  the origin, or with its bottom left corner there. With `box = "grid"`,
@@ -803,6 +958,12 @@ the origin, or with its bottom left corner there. With `box = "grid"`,
803
958
  Material Design Icons), so icons from one set keep their sizes and places
804
959
  relative to each other: paw prints in a trail, an icon swapped for another.
805
960
 
961
+ To cut a pictogram out rather than engrave it, `solid = true` gives one
962
+ silhouette, with gaps narrower than `2 * close` (default `size / 30`)
963
+ closed and holes filled, and the drawing's own detail engraved on it.
964
+ `bridge = w` also joins pieces too far apart to close, such as a moon
965
+ beside a mountain, with strips `w` wide.
966
+
806
967
  ### `symbol_names(category)`, `symbol_size(name, size = 10, box = "drawn")`, `symbol_source(name)`, `symbol_entry(name)`
807
968
 
808
969
  The names of every symbol, or of one category; the `[width, height]` a
package/docs/openscad.md CHANGED
@@ -23,15 +23,15 @@ See the [language reference](../LANGUAGE.md) for supported arguments.
23
23
 
24
24
  ## Different
25
25
 
26
- | Feature | OpenSCAD | KerfScript |
27
- | ----------- | ------------------------------------------------------------ | ---------------------------------------------------------- |
28
- | Geometry | 3D and 2D | 2D parts for laser cutting |
29
- | Output | 3D formats and 2D exports | SVG and DXF with operation layers |
30
- | Assignments | The last assignment in a scope applies throughout that scope | Assignments take effect in order |
31
- | Type errors | Many produce `undef` and a warning | Stop evaluation with an error |
32
- | `color()` | Sets a shape's colour | Use `cut()`, `score()`, `engrave()` or `layer()` |
33
- | Fonts | Looks up system fonts | Uses fonts supplied by the application or CLI |
34
- | Libraries | Can load local files | Loads the standard library and sources allowed by the host |
26
+ | Feature | OpenSCAD | KerfScript |
27
+ | ----------- | ------------------------------------------------------------ | ------------------------------------------------------------------------ |
28
+ | Geometry | 3D and 2D | 2D parts for laser cutting |
29
+ | Output | 3D formats and 2D exports | SVG and DXF with operation layers |
30
+ | Assignments | The last assignment in a scope applies throughout that scope | Assignments take effect in order |
31
+ | Type errors | Many produce `undef` and a warning | Stop evaluation with an error |
32
+ | `color()` | Sets a shape's colour | Ignored with a warning; use `cut()`, `score()`, `engrave()` or `layer()` |
33
+ | Fonts | Looks up system fonts | Uses fonts supplied by the application or CLI |
34
+ | Libraries | Can load local files | Loads the standard library and sources allowed by the host |
35
35
 
36
36
  Assignment order is especially important when adapting a design. A value
37
37
  assigned later in a KerfScript program does not change earlier geometry.
@@ -39,11 +39,13 @@ assigned later in a KerfScript program does not change earlier geometry.
39
39
  ## Not in KerfScript
40
40
 
41
41
  KerfScript does not support `cube`, `sphere`, `cylinder`, `polyhedron`,
42
- `linear_extrude`, `rotate_extrude` or `projection`. It also does not support
43
- `minkowski`, `resize`, `color`, `import`, `surface` or `render`.
42
+ `rotate_extrude` or `projection`. It also does not support `minkowski`,
43
+ `resize`, `import`, `surface` or `render`. Calls to these modules produce an
44
+ error.
44
45
 
45
- Calls to these modules produce an error. For a design based on an extruded
46
- 2D outline, start with that outline and remove the extrusion.
46
+ `color()` and `linear_extrude()` run as their children, with a warning, so
47
+ the 2D part of an OpenSCAD file runs as it is: `linear_extrude(3) shape();`
48
+ cuts `shape()` as a flat part, whose thickness comes from `$thickness`.
47
49
 
48
50
  ## Only in KerfScript
49
51
 
@@ -99,7 +99,8 @@ place(at = [20, 10, 30], rotate = [0, 0, 90]) box([80, 60, 40], name = "crate");
99
99
  as wrapping it in `material(name = "red acrylic")` would.
100
100
  - `mirror = true` cuts the part mirrored left to right. A lopsided end
101
101
  plate's other half is the same part mirrored, and its engraving still
102
- reads the right way round.
102
+ reads the right way round. A mirrored copy of a bent part bends as its
103
+ mirror image: give `bend` as for the part itself.
103
104
  - `glue = "top plate", face = "top"` lays a part on another part's face,
104
105
  its `at` and `rotate` measured on that face. Move the plate, and what is
105
106
  glued on it moves too. A stack glued under a part (`face = "bottom"`)
@@ -140,6 +141,55 @@ part("back", at = [0, 55, 3], rotate = [75, 0, 0]) {
140
141
  Parts that only touch cut nothing: a wall standing on a shelf without tabs
141
142
  leaves it whole.
142
143
 
144
+ When tabs of two parts land in the same place in a third, as walls of two
145
+ storeys lining up over a floor, the check names both and where they meet,
146
+ so one can move its tabs along the edge.
147
+
148
+ A hook that goes in through its slot and then drops, as on a pegboard,
149
+ needs a slot taller than its tab: `slot_extra = [0, 6]` sweeps each slot
150
+ 6 mm further along the receiving part's own y.
151
+
152
+ ### Halving joints
153
+
154
+ Two plates that cross, as the dividers of an egg crate or the ribs and
155
+ rings of a lamp, each take a slot halfway through from opposite sides.
156
+ Give one of them `halving = ["Rib*"]` and both are cut: where they cross,
157
+ each gets a strip as wide as the other plate's section (wider when they
158
+ meet at an angle), `clearance` more, from the middle of the crossing out
159
+ through its own edge. The slots run the way that leaves both parts
160
+ soonest, so a ring is slotted from its inner rim and a rib notched from
161
+ its outer edge, and a slot stops at the first edge it meets, never across
162
+ a hole to the far side.
163
+
164
+ ```kerf
165
+ part("Ring", at = [0, 0, 30], halving = ["Rib"])
166
+ difference() { circle(r = 55); circle(r = 45); }
167
+ part("Rib", qty = 4, at = [for (a = [0:90:270]) [-1.5 * sin(a), 1.5 * cos(a), 0]],
168
+ rotate = [for (a = [0:90:270]) [90, 0, a]]) translate([10, 0]) rect([50, 60]);
169
+ ```
170
+
171
+ ### Bores for axles and dowels
172
+
173
+ A mechanism's axles pass through several parts: the frame they turn in, and
174
+ the wheels, cams and cranks fixed on them. Declare the axle once as
175
+ hardware and let each part cut its own hole: `bores = ["Crank axle"]` cuts,
176
+ through this part, the section of the hardware labelled so (or of that
177
+ kind) wherever it passes through in the assembly. An axle at an angle cuts
178
+ the longer hole it needs, and a square or hexagonal rod its own shape.
179
+
180
+ The fit sets the room round the rod: `fit = "turn"` (the default, 0.3 mm on
181
+ the diameter) for a part that turns on it, `fit = "press"` (0.1 mm under)
182
+ for one held fast, or a number of millimetres. Measure your laser's kerf
183
+ and your dowels with `kerf/calibration`, and adjust.
184
+
185
+ ```kerf
186
+ hardware("dowel", [30, -5, 20], [30, 40, 20], 6, label = "Crank axle");
187
+ part("Side", qty = 2, at = [[0, 3, 0], [0, 33, 0]], rotate = [90, 0, 0],
188
+ bores = ["Crank axle"]) rect([60, 40]);
189
+ part("Cam", at = [30, 18, 20], rotate = [90, 0, 0], bores = ["Crank axle"],
190
+ fit = "press") circle(d = 30);
191
+ ```
192
+
143
193
  ### Bends
144
194
 
145
195
  A living hinge bends a part, and the assembled view can show it bent.
@@ -279,6 +329,12 @@ ones before the rows are packed: the rings of a stacked vase or globe each
279
329
  inside the next, washers inside a wheel. A part goes into a hole only
280
330
  where its outline, `$gap` all round, fits.
281
331
 
332
+ Copies of a curved part are packed in rows, every other one turned 180
333
+ degrees and slid up against the one before, `$gap` clear, when that takes
334
+ much less room than their boxes side by side: S-shaped ribs, crescents and
335
+ L brackets nest into each other, so 24 lamp ribs that took four sheets fit
336
+ on one. Rectangles and other parts that don't nest are packed as before.
337
+
282
338
  ## One file per sheet
283
339
 
284
340
  A combined SVG stacks all sheets in one preview. For the material example
package/docs/versions.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Versions
2
2
 
3
- KerfScript 0.8.0 implements language version 0.3. The package version tracks
3
+ KerfScript 0.10.0 implements language version 0.3. The package version tracks
4
4
  the software release; the language version tracks the syntax and behavior
5
5
  of `.kerf` programs.
6
6
 
@@ -30,4 +30,4 @@ files used with a design. Applications that store designs should retain
30
30
  that information and compare the output before upgrading the interpreter.
31
31
 
32
32
  Pin the npm package to an exact version when your application needs a fixed
33
- renderer, for example `@mylasertools/kerfscript@0.8.0`.
33
+ renderer, for example `@mylasertools/kerfscript@0.10.0`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mylasertools/kerfscript",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "KerfScript: a programming language and library for laser-cutting generators. Write parametric 2D parts with cut, score and engrave layers, kerf compensation and joinery, then turn settings into SVG or DXF cut files from Node.js, the browser, the command line or WebAssembly.",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-only",