@mylasertools/kerfscript 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/CHANGELOG.md +167 -1
  2. package/LANGUAGE.md +160 -30
  3. package/README.md +8 -2
  4. package/THIRD-PARTY-NOTICES.md +113 -0
  5. package/dist/analysis.d.cts +20 -0
  6. package/dist/analysis.d.ts +20 -0
  7. package/dist/assembly.d.cts +28 -1
  8. package/dist/assembly.d.ts +28 -1
  9. package/dist/ast.d.cts +9 -0
  10. package/dist/ast.d.ts +9 -0
  11. package/dist/cli.js +10165 -4669
  12. package/dist/diff.d.cts +18 -0
  13. package/dist/diff.d.ts +18 -0
  14. package/dist/evaluator.d.cts +34 -0
  15. package/dist/evaluator.d.ts +34 -0
  16. package/dist/functions.d.cts +1 -0
  17. package/dist/functions.d.ts +1 -0
  18. package/dist/geometry.d.cts +17 -0
  19. package/dist/geometry.d.ts +17 -0
  20. package/dist/hardware.d.cts +13 -0
  21. package/dist/hardware.d.ts +13 -0
  22. package/dist/highlight.cjs +2 -2
  23. package/dist/highlight.js +2 -2
  24. package/dist/index.cjs +1941 -52
  25. package/dist/index.d.cts +11 -2
  26. package/dist/index.d.ts +11 -2
  27. package/dist/index.js +1941 -52
  28. package/dist/instructions.d.cts +3 -0
  29. package/dist/instructions.d.ts +3 -0
  30. package/dist/language.cjs +1899 -51
  31. package/dist/language.js +1899 -51
  32. package/dist/libraries.cjs +1874 -26
  33. package/dist/libraries.d.cts +3 -0
  34. package/dist/libraries.d.ts +3 -0
  35. package/dist/libraries.js +1874 -26
  36. package/dist/png.d.cts +9 -0
  37. package/dist/png.d.ts +9 -0
  38. package/dist/render.d.cts +22 -1
  39. package/dist/render.d.ts +22 -1
  40. package/dist/signatures.cjs +244 -11
  41. package/dist/signatures.js +244 -11
  42. package/dist/slots.d.cts +8 -0
  43. package/dist/slots.d.ts +8 -0
  44. package/dist/values.d.cts +6 -1
  45. package/dist/values.d.ts +6 -1
  46. package/dist/verify/command.d.cts +1 -0
  47. package/dist/verify/command.d.ts +1 -0
  48. package/dist/verify/geometry.d.cts +25 -0
  49. package/dist/verify/geometry.d.ts +25 -0
  50. package/dist/verify/index.d.cts +10 -0
  51. package/dist/verify/index.d.ts +10 -0
  52. package/dist/verify/joints.d.cts +7 -0
  53. package/dist/verify/joints.d.ts +7 -0
  54. package/dist/verify/mechanics.d.cts +11 -0
  55. package/dist/verify/mechanics.d.ts +11 -0
  56. package/dist/verify/motion.d.cts +8 -0
  57. package/dist/verify/motion.d.ts +8 -0
  58. package/dist/verify/pose.d.cts +5 -0
  59. package/dist/verify/pose.d.ts +5 -0
  60. package/dist/verify/relations.d.cts +8 -0
  61. package/dist/verify/relations.d.ts +8 -0
  62. package/dist/verify/snapshot.d.cts +11 -0
  63. package/dist/verify/snapshot.d.ts +11 -0
  64. package/dist/verify/solids.d.cts +39 -0
  65. package/dist/verify/solids.d.ts +39 -0
  66. package/dist/verify/spec.d.cts +9 -0
  67. package/dist/verify/spec.d.ts +9 -0
  68. package/dist/verify/summary.d.cts +17 -0
  69. package/dist/verify/summary.d.ts +17 -0
  70. package/dist/verify/types.d.cts +299 -0
  71. package/dist/verify/types.d.ts +299 -0
  72. package/docs/cli.md +87 -15
  73. package/docs/javascript.md +57 -25
  74. package/docs/layers.md +42 -2
  75. package/docs/library.md +299 -3
  76. package/docs/parts-and-sheets.md +186 -1
  77. package/docs/shared-libraries.md +8 -1
  78. package/docs/specification.md +78 -23
  79. package/docs/verification.md +363 -0
  80. package/docs/versions.md +2 -2
  81. package/package.json +2 -1
  82. package/dist/import/dbg.d.cts +0 -1
  83. package/dist/import/dbg.d.ts +0 -1
package/docs/cli.md CHANGED
@@ -47,6 +47,9 @@ to try these commands.
47
47
  kerf render <file.kerf> [-o out.svg] [options]
48
48
  kerf params <file.kerf>
49
49
  kerf check <file.kerf>
50
+ kerf verify <file.kerf> --spec <file.json> [-o report.json] [--summary]
51
+ kerf diff <a.kerf> <b.kerf> [-D name=value] [--json]
52
+ kerf instructions <file.kerf> [-o out.html] [options]
50
53
  kerf fmt <files or folders>
51
54
  kerf fmt --check <files or folders>
52
55
  kerf fmt -
@@ -62,6 +65,11 @@ kerf pack [folder] [-o file]
62
65
  choose the format. `params` lists the editable settings as JSON. `check`
63
66
  reports parts, dimensions, cut lengths, sheets and warnings.
64
67
 
68
+ `verify` checks explicit rigid fit, retention, installation and motion contracts and writes a JSON report. It
69
+ exits with 0 for passed required claims, 1 for failures, and 2 for unverified or
70
+ invalid inputs. See [Assembly verification](verification.md) for supported claims,
71
+ material profiles and the limits of a pass.
72
+
65
73
  `fmt` formats `.kerf` files in place, searching folders for them, except
66
74
  `kerf_libraries/`, whose files `kerf.lock` pins as they are. It sets
67
75
  indentation (two spaces), the spaces between tokens, blank lines (at most one
@@ -96,25 +104,89 @@ installed libraries by themselves.
96
104
 
97
105
  ## Options
98
106
 
99
- | Option | Use |
100
- | --------------------- | ------------------------------------------------------------------------- |
101
- | `-o, --out <file>` | Output path ending in `.svg`, `.dxf` or `.json`; defaults to `<file>.svg` |
102
- | `-D name=value` | Override a parameter; repeat for multiple values |
103
- | `-p, --params <file>` | Load parameter values from a JSON file |
104
- | `--font <file.ttf>` | Supply a font file; repeat for multiple fonts. `Atkinson` is built in |
105
- | `--kerf <mm>` | Override kerf for every part |
106
- | `--sheet <W>x<H>` | Set the sheet width and height in millimetres |
107
- | `--gap <mm>` | Set spacing between parts |
108
- | `--margin <mm>` | Set spacing at sheet edges; defaults to the gap |
109
- | `--no-pack` | Keep the positions defined in the program |
110
- | `--guides` | Include the guide layer |
111
- | `--split` | Export one file per sheet |
112
- | `-h, --help` | Show command help |
113
- | `-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
+ | `-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 |
114
128
 
115
129
  `-D` accepts KerfScript values, including numbers, quoted strings, booleans
116
130
  and lists. For example: `-D width=200` or `-D 'name="Ada"'`.
117
131
 
132
+ `kerf check` lists the parts, how many make each glued stack and what a
133
+ part is glued to, the hardware to buy, alike pieces counted together, and
134
+ the assembly steps. A design with marks on the parts' back faces writes a
135
+ second file beside the first, `design-back.svg`: the sheet turned over
136
+ left to right, for the job after the parts are turned over.
137
+
138
+ `--sweep` checks a design over many settings at once. Repeat it to try
139
+ every combination; each line says `ok` or lists what went wrong, and the
140
+ command exits with 1 if any combination warns or fails:
141
+
142
+ ```sh
143
+ kerf check tray.kerf --sweep '$thickness=3:0.5:6' --sweep size=small,large
144
+ ```
145
+
146
+ Settings that only make sense together go in one `--sweep`, their names
147
+ joined by commas and each set of values after a `;`, so the sets are tried
148
+ as they are rather than crossed. `--params-list` reads the sets from a JSON
149
+ list instead; both cross with the other sweeps:
150
+
151
+ ```sh
152
+ kerf check room.kerf --sweep 'width,depth,height=115,140,190;160,200,260' --sweep '$thickness=3,4'
153
+ kerf check room.kerf --params-list sizes.json
154
+ ```
155
+
156
+ `--call` tries one module of a library on its own, without writing a
157
+ design for it. The file's modules and functions are available, as with
158
+ `use`; `-D` values are set first, so they can be special variables or
159
+ names in the call:
160
+
161
+ ```sh
162
+ kerf render lib/props.kerf --call 'roses(40, 30)' -D '$thickness=4' -o roses.svg
163
+ kerf check lib/kerf/box.kerf --call 'box([w, 40, 30])' -D w=60
164
+ ```
165
+
166
+ `kerf instructions` writes the assembly instructions as one HTML page to
167
+ print or save as PDF: the parts list with each part's number, the sheets,
168
+ then a page per `step()` with the model drawn as it stands after it, the
169
+ step's parts in orange, and the parts and hardware it adds. With
170
+ `$label_parts = true` the numbers match the ones engraved on the parts.
171
+
172
+ ```sh
173
+ kerf instructions lock-box.kerf -o lock-box-instructions.html
174
+ ```
175
+
176
+ `kerf diff` renders two designs (or one design before and after a change)
177
+ with the same settings and lists, part by part and layer by layer, what
178
+ differs: the area of shapes that changed, open lines added or removed, and
179
+ where, in the part's own coordinates. It exits 1 if anything changed, so a
180
+ refactor can prove it changed nothing:
181
+
182
+ ```sh
183
+ kerf diff old/garage.kerf garage.kerf
184
+ ```
185
+
186
+ The `"sheet": [600, 400]` in a project's `kerf.json` is the sheet for every
187
+ design in the project that does not set `$sheet`: set your laser's bed
188
+ once.
189
+
118
190
  ## Examples
119
191
 
120
192
  ```sh
@@ -31,20 +31,23 @@ changing the source string.
31
31
 
32
32
  ### Options
33
33
 
34
- | Option | Value |
35
- | ------------- | ---------------------------------------------------------------------- |
36
- | `params` | Parameter values keyed by name |
37
- | `fonts` | Font files keyed by name, as `ArrayBuffer` or `Uint8Array` |
38
- | `defaultFont` | Name to use when `text()` does not specify a font |
39
- | `resolve` | `(path) => source` callback for libraries outside the standard library |
40
- | `kerf` | Kerf override for every part, in millimetres |
41
- | `layout` | `"pack"` or `"none"` |
42
- | `sheet` | `[width, height]` in millimetres |
43
- | `gap` | Space between parts, in millimetres |
44
- | `margin` | Space at sheet edges, in millimetres; defaults to `gap` |
45
- | `guides` | Whether to include guide geometry |
46
- | `maxSteps` | Evaluation step limit |
47
- | `limits` | Memory limits, see below; any you leave out keep their default |
34
+ | Option | Value |
35
+ | -------------- | ------------------------------------------------------------------------------------- |
36
+ | `params` | Parameter values keyed by name |
37
+ | `fonts` | Font files keyed by name, as `ArrayBuffer` or `Uint8Array` |
38
+ | `defaultFont` | Name to use when `text()` does not specify a font |
39
+ | `resolve` | `(path) => source` callback for libraries outside the standard library |
40
+ | `kerf` | Kerf override for every part, in millimetres |
41
+ | `layout` | `"pack"` or `"none"` |
42
+ | `sheet` | `[width, height]` in millimetres, over the program's `$sheet` |
43
+ | `defaultSheet` | `[width, height]` for programs that do not set `$sheet`: the laser bed |
44
+ | `nest` | Pack small parts into the holes of bigger ones, as `$nest` |
45
+ | `gap` | Space between parts, in millimetres |
46
+ | `margin` | Space at sheet edges, in millimetres; defaults to `gap` |
47
+ | `guides` | Whether to include guide geometry |
48
+ | `analysis` | Capture nominal cut geometry before compensation, for [verification](verification.md) |
49
+ | `maxSteps` | Evaluation step limit |
50
+ | `limits` | Memory limits, see below; any you leave out keep their default |
48
51
 
49
52
  Supply a font for programs that use text:
50
53
 
@@ -61,17 +64,30 @@ The URL should point to a font file provided by your application.
61
64
 
62
65
  ### Result
63
66
 
64
- | Field | Contents |
65
- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
66
- | `svg` | Combined SVG containing all sheets |
67
- | `width`, `height` | Combined SVG dimensions in millimetres |
68
- | `sheets` | Each sheet's dimensions, material, thickness, SVG, DXF, paths and placed items |
69
- | `parts` | Part names, quantities, dimensions, piece counts, cut lengths and material properties |
70
- | `assembly` | One entry per copy of a part with `name`, `copy`, `thickness`, `outline`, a 4 × 4 `matrix` and `placed`, for showing the design put together. Parts without `at` or `rotate` have `placed: false` |
71
- | `paths` | Layer paths with `name`, `mode`, `color`, `d`, `regions` and `lines` |
72
- | `layers` | Layer definitions in output order |
73
- | `warnings` | Problems that did not stop the render |
74
- | `echoes` | Output from the program's `echo()` calls |
67
+ | Field | Contents |
68
+ | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
69
+ | `svg` | Combined SVG containing all sheets |
70
+ | `width`, `height` | Combined SVG dimensions in millimetres |
71
+ | `sheets` | Each sheet's dimensions, material, thickness, SVG, DXF, paths and placed items |
72
+ | `parts` | Part names, quantities, dimensions, piece counts, cut lengths and material properties |
73
+ | `assembly` | One entry per copy of a part with `name`, `copy`, `thickness`, `material`, `outline`, a 4 × 4 `matrix` and `placed`, for showing the design put together. Parts without `at` or `rotate` have `placed: false`. A bent part has `bends`; a part in a step has `step`; `marks` holds what is engraved and scored on it, front and back |
74
+ | `steps` | The text of each assembly step, in order; a part's `step` counts from 1 |
75
+ | `hardware` | Each `hardware()`: `kind`, `from`, `to`, `size`, `up`, `sides`, `step` and `label` |
76
+ | `paths` | Layer paths with `name`, `mode`, `color`, `d`, `regions` and `lines` |
77
+ | `layers` | Layer definitions in output order |
78
+ | `warnings` | Problems that did not stop the render |
79
+ | `echoes` | Output from the program's `echo()` calls |
80
+ | `analysis` | When requested: nominal cut regions and lines per definition, with compensation kerf; see [assembly verification](verification.md) |
81
+
82
+ Each sheet with back-face marks has `back`, with its own `svg`, `dxf` and
83
+ `paths`: the sheet turned over left to right.
84
+
85
+ `bendPoint(bends, thickness, [x, y, z])` gives where a point of a bent
86
+ part goes, in the part's own coordinates, before its `matrix`; and
87
+ `meshPieces(outline, bends)` cuts a part's outline into pieces narrow
88
+ enough across its hinges to bend smoothly. A 3D view extrudes each piece
89
+ by the thickness, moves its points with `bendPoint()` and then by the
90
+ `matrix`.
75
91
 
76
92
  Use `result.svg` for a combined preview. Use `result.sheets[i].svg` or
77
93
  `.dxf` to export individual sheets, particularly when they use different
@@ -129,6 +145,22 @@ format('x=1;module m(a,b=2){rect([a,b]);}');
129
145
 
130
146
  `format(source, { indent: 4 })` uses four spaces per level.
131
147
 
148
+ ## instructionsHtml()
149
+
150
+ `instructionsHtml(result, title)` turns a `render()` result into the page
151
+ `kerf instructions` writes: a standalone HTML document with the parts,
152
+ the sheets and a drawing for each step.
153
+
154
+ ## diffRenders()
155
+
156
+ `diffRenders(a, b)` compares two results of `render(source, { layout: "none" })`
157
+ and returns what differs, one entry per part copy and layer: `part`, `copy`,
158
+ `layer`, `change` (`"added"`, `"removed"` or `"changed"`), `area` (mm² of
159
+ shapes that differ), `linesAdded`, `linesRemoved` and `at`, the box of the
160
+ difference in the part's own coordinates. With layout `"none"`, each sheet
161
+ item's `offset` is the move from the part's coordinates (y down) to the
162
+ sheet's.
163
+
132
164
  ## importSvg()
133
165
 
134
166
  `importSvg(svg, options)` turns an SVG drawing into a program, as
package/docs/layers.md CHANGED
@@ -99,10 +99,50 @@ The rectangle and circle use separate engraving layers. You can assign each
99
99
  a different power in your laser software. Supported modes are `"cut"`,
100
100
  `"line"`, `"fill"` and `"guide"`.
101
101
 
102
+ ## The back face
103
+
104
+ `engrave(side = "back")`, `score(side = "back")` and `layer(name, side =
105
+ "back")` mark the face underneath, made after the parts are turned over.
106
+ Draw the marks where they are on the part seen from the top; text reads
107
+ the right way round on the back. They go into each sheet's back job,
108
+ turned over left to right, and not into the front file.
109
+
110
+ ## Painting in order
111
+
112
+ `paint()` lays shapes like paint, each over the ones before: every child
113
+ loses the area of the children after it. Give it a layer for each child,
114
+ and a picture in several tones comes out with no two layers overlapping:
115
+
116
+ ```kerf
117
+ layer("light", mode = "fill", color = "#c8a070");
118
+ layer("dark", mode = "fill", color = "#000000");
119
+ part("tile") {
120
+ rect([60, 60]);
121
+ paint(["light", "dark"]) {
122
+ circle(d = 50);
123
+ translate([30, 30]) circle(d = 20);
124
+ }
125
+ }
126
+ ```
127
+
128
+ A child given the layer `""` is left out, but still covers the ones
129
+ before it: a bare patch.
130
+
131
+ ## Printing on parts
132
+
133
+ To print on the parts and then cut them, `layer(name, mode = "fill",
134
+ bleed = 2)` lets the printed layer run 2 mm past each part's edge, so the
135
+ cut never leaves a bare rim. `$registration = true` puts marks in three
136
+ corners of every sheet, on the `registration` layer, for a print-and-cut
137
+ machine to line the cut up with the print.
138
+
102
139
  ## Order in the file
103
140
 
104
- KerfScript writes layers in this order: engrave, custom layers, score, cut,
105
- then guide. Within a cut layer, inner paths precede outer outlines.
141
+ KerfScript writes layers in this order: engrave, custom fill layers,
142
+ custom line and cut layers, score, cut, then guide, so a line is never
143
+ hidden under a fill. `layer(name, order = n)` moves a custom layer among
144
+ the others, lowest first. Within a cut layer, inner paths precede outer
145
+ outlines.
106
146
 
107
147
  Laser software may reorder these paths. Check its job preview so engraving
108
148
  runs before cutting and holes are cut before the surrounding part.
package/docs/library.md CHANGED
@@ -26,6 +26,13 @@ show each module's description when you hover over it.
26
26
  | [`kerf/hanging`](#hanging) | Keyholes, holes and loops for hanging things on a wall |
27
27
  | [`kerf/enclosure`](#enclosures) | Boxes with a screwed-on lid, cutouts for ports and vents |
28
28
  | [`kerf/calibration`](#calibration) | Test pieces that measure the kerf and how your sheet fits |
29
+ | [`kerf/gears`](#gears-and-cams) | Spur gears, racks, lantern gears, cams and tappets |
30
+ | [`kerf/lock`](#lock) | A lock with a key, three layers deep |
31
+ | [`kerf/rings`](#rings) | Round things of stacked rings on a crossed core |
32
+ | [`kerf/joints`](#joints) | Two profiles halved into each other: crosses, fonts, domes |
33
+ | [`kerf/sizes`](#sizes) | Paper, card and photo sizes |
34
+ | [`kerf/symbols`](#symbols) | 867 pictograms by name |
35
+ | [`kerf/geo`](#maps) | The world's land, for maps and globes |
29
36
 
30
37
  Sizes are in millimetres. Joints use `$thickness`, the sheet thickness, so
31
38
  set it to what you measure. Each section has an example in the gallery that
@@ -39,16 +46,26 @@ you can open in the playground.
39
46
 
40
47
  Finger-jointed boxes. Example: [box.kerf](../examples/box.kerf).
41
48
 
42
- ### `box(size, lid = false, finger)`
49
+ ### `box(size, lid = false, finger, name = "")`
43
50
 
44
51
  The panels of a box as parts `bottom`, `front`, `back`, `left`, `right` and,
45
- with a lid, `lid`, placed for the assembled view.
52
+ with a lid, `lid`, placed for the assembled view. Shapes given to `box()`
53
+ go on the front, drawn from its bottom left corner as seen from outside.
54
+ Wrap it in `place()` to set it anywhere:
55
+
56
+ ```kerf
57
+ use <kerf/box>
58
+
59
+ place(at = [0, 0, 40]) box([120, 80, 60], name = "crate")
60
+ engrave() translate([60, 30]) text("TEA", size = 14, halign = "center");
61
+ ```
46
62
 
47
63
  | Parameter | Default | Meaning |
48
64
  | --------- | ------------------------ | ------------------------------------------------------ |
49
65
  | `size` | | Outside `[width, depth, height]`, lid included |
50
66
  | `lid` | `false` | Add a lid, finger-jointed to the walls like the bottom |
51
67
  | `finger` | `max(3 * $thickness, 6)` | Finger width |
68
+ | `name` | `""` | Goes before each panel's name, as `crate front` |
52
69
 
53
70
  ### `divider(size, finger)`
54
71
 
@@ -149,13 +166,56 @@ bent at the corners. The tabs of part `bottom` go through slots along the
149
166
  strip. Part `lid` rests on top, and part `lid insert`, glued under it,
150
167
  keeps it in place. `size` is the outside `[width, depth, height]`, lid
151
168
  included, and `r` the outside corner radius, more than two thicknesses.
152
- The strip is bent, so the parts are not placed in an assembled view.
169
+ The assembled view shows the strip bent round the bottom.
153
170
 
154
171
  ### `flex_panel(size, r, sw, sd)`
155
172
 
156
173
  The bottom of `flex_box()`: a rounded rectangle with tabs on its straight
157
174
  edges, `sw` long on the front and back and `sd` on the sides.
158
175
 
176
+ ### `narrow_hinge(size, spacing = 1.5, bridge = 1.5)`
177
+
178
+ A hinge for a narrow strap or band, as lines across `[w, h]`: cuts from
179
+ alternate edges, each stopping `bridge` short of the far edge, so the
180
+ strip zigzags and bends evenly however narrow it is. Use it where
181
+ `living_hinge()` would leave only a cut or two across.
182
+
183
+ ### `flex_strip(path, width, name = "strip", tabs = true, straight = 10, r, spacing = 1.5, bridge = 3, narrow = false)`
184
+
185
+ A strip that follows a profile: `path` is a list of `[x, y]` points along
186
+ its middle in a side plate's plane, as `path_points()` or a list
187
+ comprehension gives them. The strip has a living hinge wherever the path
188
+ curves and tabs along both edges wherever it runs straight. It is one
189
+ part, placed in the plate's coordinates with its edge at z = 0 and its
190
+ width running down to `-width`, and bent in the assembled view.
191
+
192
+ ```kerf
193
+ use <kerf/hinge>
194
+
195
+ W = 80;
196
+ path = [for (a = [180:5:360]) [40, 40] + 40 * [cos(a), sin(a)]];
197
+ module plate() offset(delta = 12) polygon(concat(path, [[80, 70], [0, 70]]));
198
+ part("end A", rotate = [90, 0, 0], slots = ["tray"]) plate();
199
+ part("end B", at = [0, W + $thickness, 0], rotate = [90, 0, 0], slots = ["tray"]) plate();
200
+ place(rotate = [90, 0, 0]) flex_strip(path, W, name = "tray");
201
+ ```
202
+
203
+ Wrap it in `place()` with the plate's placement, put the other plate
204
+ `width` away, and give both plates `slots`: they cut the slots for the
205
+ tabs where the strip passes through them. Segments of the path shorter
206
+ than `straight` are taken as curve; a sharp corner bends round radius
207
+ `r`, two thicknesses by default. `narrow` uses `narrow_hinge()`.
208
+
209
+ ### `strip_bends(path, straight = 10, r)`
210
+
211
+ The bends `flex_strip()` makes, as `[s0, s1, angle]` along the path:
212
+ where each curve starts and ends and how far it turns, left positive.
213
+ Give them to `part(bend = ...)` for a strip of your own.
214
+
215
+ ### `strip_merge(list)`
216
+
217
+ Joins bends from `strip_bends()` that touch into one.
218
+
159
219
  ## Dividers
160
220
 
161
221
  `use <kerf/dividers>`
@@ -337,3 +397,239 @@ A pair of finger-jointed pieces for each kerf in `kerfs`, parts
337
397
  `joint <kerf> out` and `joint <kerf> in`, each cut with that kerf
338
398
  compensation. The pair that holds together without glue or forcing has
339
399
  the kerf to set for this sheet.
400
+
401
+ ## Gears and cams
402
+
403
+ `use <kerf/gears>`
404
+
405
+ Gears, racks, the lantern gears of old mills, and the cams and tappets
406
+ that make a model move. Gears go by their module `mod`: the pitch
407
+ diameter is `mod * teeth`, and two gears mesh when they have the same
408
+ module and their centres are `gear_distance()` apart.
409
+
410
+ ```kerf
411
+ use <kerf/gears>
412
+
413
+ part("big") spur_gear(36, 2, bore = 6, spokes = 5);
414
+ part("small", at = [gear_distance(36, 12, 2), 0, 0], rotate = [0, 0, gear_phase(12)])
415
+ spur_gear(12, 2, bore = 6);
416
+ ```
417
+
418
+ ### `spur_gear(teeth, mod = 2, bore = 5, pressure = 20, backlash = 0.1, spokes = 0, square = false)`
419
+
420
+ A gear with involute teeth centred on the origin, a tooth along +x, and a
421
+ hole for its axle: round, or `square` to turn with a square axle.
422
+ `spokes` from 3 to 6 cuts windows between spokes. `backlash` thins each
423
+ tooth so meshed gears don't bind.
424
+
425
+ ### `gear_points(teeth, mod = 2, pressure = 20, backlash = 0.1, steps = 6)`
426
+
427
+ The gear's outline as a list of points, for gears of your own shape.
428
+
429
+ ### `gear_window(r0, r1, span, w)`
430
+
431
+ One rounded window between two spokes, from radius `r0` to `r1`.
432
+
433
+ ### `gear_radius(teeth, mod = 2)`, `gear_distance(teeth_a, teeth_b, mod = 2)`
434
+
435
+ The pitch radius, and the distance between the centres of two gears in
436
+ mesh.
437
+
438
+ ### `gear_turn(driver, driven, angle)`
439
+
440
+ How far a gear with `driven` teeth turns when one with `driver` teeth in
441
+ mesh with it turns `angle` degrees: the other way round.
442
+
443
+ ### `gear_phase(teeth)`
444
+
445
+ The turn that lines a gear's teeth up with the gear beside it along x.
446
+
447
+ ### `rack(teeth, mod = 2, height, pressure = 20, backlash = 0.1)`
448
+
449
+ A straight rack along +x, its pitch line at y = 0. A `spur_gear()` of the
450
+ same module meshes with it from `gear_radius()` above.
451
+
452
+ ### `lantern_disc(staves, r, d = 6, bore = 6, rim)`, `peg_wheel(pegs, r, d = 6, bore = 6, rim)`
453
+
454
+ A lantern gear is two discs with dowel staves between them; `lantern_disc()`
455
+ is one disc, with holes for `staves` staves of diameter `d` on radius `r`.
456
+ A `peg_wheel()` has dowel pegs standing out of its face, which drive the
457
+ staves of a lantern gear at right angles. Match the pitch of the pegs and
458
+ the staves.
459
+
460
+ ### `peg_radius(n, pitch)`
461
+
462
+ The radius for `n` pegs or staves `pitch` apart.
463
+
464
+ ### `eccentric(r, offset, bore = 6, square = false)`, `snail_cam(r0, r1, bore = 6, steps = 72, square = false)`, `tappets(n, r, w = 10, hub = 14, bore = 6, square = false)`
465
+
466
+ Cams: an `eccentric()` pushes a follower up and down by twice `offset`; a
467
+ `snail_cam()` lifts it slowly from `r0` to `r1` over a turn and drops it at
468
+ once, as a trip hammer works; `tappets()` lift a lever `n` times a turn.
469
+
470
+ ## Lock
471
+
472
+ `use <kerf/lock>`
473
+
474
+ A lock with a key, for boxes, diaries and money boxes. A flat key turns an
475
+ eccentric cam that slides a bolt; half a turn throws its nose out past the
476
+ lock's top edge into a notch in whatever it locks. It is three layers of
477
+ the current material: a base, a frame with the cam and the bolt, and a
478
+ plate with the keyhole.
479
+
480
+ ### `cam_lock(throw = 7, locked = true, name = "Lock", key = true, ring = true)`
481
+
482
+ The lock's parts, lying flat with the key's axis on the z axis and the
483
+ bolt moving along +y. Wrap it in `place()` to set it on a box front or a
484
+ cover. `throw` is how far the bolt moves; `locked` shows it thrown;
485
+ `ring` engraves a ring round the keyhole.
486
+
487
+ ### `lock_bounds(throw = 7)`, `lock_nose(throw = 7)`
488
+
489
+ The lock's outline as `[x0, y0, x1, y1]` round the key's axis, and the
490
+ bolt's nose as `[width, y of its tip when locked]`: cut a notch a little
491
+ wider than the nose where it goes.
492
+
493
+ ### `lock_key(t = $thickness, ws = 5)`, `lock_dims(throw)`
494
+
495
+ The key, drawn standing on y = 0, and the lock's inner sizes.
496
+
497
+ ## Rings
498
+
499
+ `use <kerf/rings>`
500
+
501
+ Round things built from stacked rings threaded on a core of two crossed
502
+ plates: drums, barrels, vases, towers and turned legs.
503
+
504
+ ```kerf
505
+ use <kerf/rings>
506
+
507
+ ring_stack([for (k = [0:11]) 60 + 20 * sin(k * 15)], 30, name = "vase");
508
+ part("base", at = [0, 0, -$thickness], slots = ["vase core A", "vase core B"]) circle(d = 90);
509
+ ```
510
+
511
+ ### `ring_stack(diameters, hole, name = "ring", count, feet = true, clearance = 0.1)`
512
+
513
+ Rings with outsides `diameters`, bottom up, on z = 0 and the z axis, all
514
+ with a round `hole`; or `count` alike rings of one diameter. The core
515
+ plates, `name core A` and `name core B`, are half-lapped, with two tabs
516
+ each below z = 0 for a base: give the base `slots` naming them. The plates
517
+ keep `$min_width` beside their halving slot and the feet keep it between
518
+ their slots in the base, so a hole too small for either stops with the
519
+ smallest hole that works (about 7 mm, and 12 mm with feet, in 3 mm ply).
520
+
521
+ ### `ring_core_width(hole, clearance = 0.1)`
522
+
523
+ The width of a core plate whose corners just clear a round hole.
524
+
525
+ ## Joints
526
+
527
+ `use <kerf/joints>`
528
+
529
+ Two profiles halved into each other at right angles, standing on a floor:
530
+ a cross on its foot, a font, a dome, a tree.
531
+
532
+ ```kerf
533
+ use <kerf/joints>
534
+
535
+ module tree() polygon([[-14, 0], [14, 0], [14, 4], [4, 4], [4, 8], [20, 8], [0, 50], [-20, 8], [-4, 8], [-4, 4], [-14, 4]]);
536
+ part("floor", at = [-30, -30, -$thickness], slots = ["tree front", "tree side"]) square(60);
537
+ halved_pair("tree", cap = 30, feet = [[-10, 4], [10, 4]]) { tree(); engrave() translate([0, 20]) circle(d = 4); }
538
+ ```
539
+
540
+ ### `halved_pair(name, at = [0, 0, 0], cap, feet = [], side_feet, clearance = 0.1)`
541
+
542
+ The first child is the profile, drawn with x across and y up, centred on
543
+ x = 0 with the floor at y = 0. The front, `name front`, is the whole
544
+ profile along x, slotted from below; the side, `name side`, is the profile
545
+ along y capped at height `cap` (all of it without), slotted from above, the
546
+ slots meeting halfway up the side. A second child is drawn on both faces,
547
+ clipped to each part: their engraving or print. `feet` are tabs below the
548
+ floor on the front, x positions (3 mm wide) or `[x, width]` pairs, and
549
+ `side_feet` the side's (the same unless given); give the floor `slots`
550
+ naming both parts. The strips beside both slots must keep `$min_width`,
551
+ and a foot may not run into the front's slot: either stops with where.
552
+
553
+ ## Sizes
554
+
555
+ `use <kerf/sizes>`
556
+
557
+ Paper, card and photo sizes in millimetres, for holders, folders, frames
558
+ and boxes made to fit them.
559
+
560
+ ### `paper_size(name)`, `card_size(name)`, `photo_size(name)`
561
+
562
+ `[width, height]` by name, ignoring case: paper from `"A0"` to `"A8"`,
563
+ `"B4"` to `"B6"`, `"C4"` to `"C6"`, `"DL"`, `"letter"`, `"legal"`,
564
+ `"tabloid"`, `"half letter"`, `"executive"`, `"pocket"` and `"traveler"`,
565
+ standing; cards `"business"`, `"us business"`, `"credit"`, `"japan"`,
566
+ `"playing"`, `"bridge"`, `"tarot"`, `"postcard"` and `"us postcard"`, and
567
+ photos `"4x6"`, `"5x7"`, `"8x10"`, `"10x15"`, `"13x18"` and the instant
568
+ film sizes, lying down. An unknown name stops with the list of known ones.
569
+
570
+ ### `landscape(size)`, `portrait(size)`
571
+
572
+ A size turned to lie wider than tall, or to stand taller than wide.
573
+
574
+ ### `lookup_size(name, table)`, `size_names(table)`
575
+
576
+ The size of a name in a table of `[name, size]`, and the names in it.
577
+
578
+ ## Symbols
579
+
580
+ `use <kerf/symbols>`
581
+
582
+ 867 pictograms by name, from open icon sets: animals, food, nature,
583
+ sports, travel, holidays, music, flowers and more. Each comes from a set
584
+ under the Apache 2.0, MIT or CC0 licence, named by `symbol_source()`; the
585
+ [notices](../THIRD-PARTY-NOTICES.md) list them.
586
+
587
+ ```kerf
588
+ use <kerf/symbols>
589
+
590
+ part("tag") {
591
+ circle(d = 40);
592
+ engrave() symbol("paw", 24);
593
+ }
594
+ ```
595
+
596
+ ### `symbol(name, size = 10, center = true, fill = "nonzero", box = "drawn")`
597
+
598
+ The symbol `size` mm across the longer side of what it draws, centred on
599
+ the origin, or with its bottom left corner there. With `box = "grid"`,
600
+ `size` and the centre are those of the icon set's own grid (24 x 24 for
601
+ Material Design Icons), so icons from one set keep their sizes and places
602
+ relative to each other: paw prints in a trail, an icon swapped for another.
603
+
604
+ ### `symbol_names(category)`, `symbol_size(name, size = 10, box = "drawn")`, `symbol_source(name)`, `symbol_entry(name)`
605
+
606
+ The names of every symbol, or of one category; the `[width, height]` a
607
+ symbol draws at a size; where it comes from as `[source, licence]`; and
608
+ its row of the table, `[name, category, drawn box, source, path, grid]`,
609
+ the boxes as `[x, y, w, h]`.
610
+
611
+ ## Maps
612
+
613
+ `use <kerf/geo>`
614
+
615
+ The world's land from Natural Earth (public domain), for maps, globes and
616
+ country-shaped signs.
617
+
618
+ ### `world_map(width = 200, projection = "equirectangular", south = -60)`
619
+
620
+ The land as shapes, a map `width` mm wide centred on the origin, as
621
+ `"equirectangular"` (twice as wide as tall) or `"mercator"`. Land south of
622
+ `south` is left out.
623
+
624
+ ### `is_land(lat, lon)`
625
+
626
+ Whether a point is on land, to the nearest degree: quick enough to call
627
+ for every point of a globe.
628
+
629
+ ### `geo_point(lat, lon, width = 200, projection = "equirectangular")`
630
+
631
+ Where a place goes on the map, to mark a city or a journey.
632
+
633
+ ### `land_polygons()`
634
+
635
+ The land as polygons: each a list of rings of `[longitude, latitude]`.