@mylasertools/kerfscript 0.6.0 → 0.8.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 +201 -1
  2. package/LANGUAGE.md +169 -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 +10333 -4650
  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 +22 -0
  19. package/dist/geometry.d.ts +22 -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 +2278 -52
  25. package/dist/index.d.cts +11 -2
  26. package/dist/index.d.ts +11 -2
  27. package/dist/index.js +2278 -52
  28. package/dist/instructions.d.cts +3 -0
  29. package/dist/instructions.d.ts +3 -0
  30. package/dist/language.cjs +2235 -50
  31. package/dist/language.js +2235 -50
  32. package/dist/libraries.cjs +2211 -26
  33. package/dist/libraries.d.cts +3 -0
  34. package/dist/libraries.d.ts +3 -0
  35. package/dist/libraries.js +2211 -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 +269 -11
  41. package/dist/signatures.js +269 -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 +40 -0
  65. package/dist/verify/solids.d.ts +40 -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 +301 -0
  71. package/dist/verify/types.d.ts +301 -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 +501 -3
  76. package/docs/parts-and-sheets.md +199 -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
@@ -0,0 +1,301 @@
1
+ import type { Vec3 } from '../assembly.js';
2
+ import type { Bend, Poly } from '../geometry.js';
3
+ import type { Value } from '../values.js';
4
+ export type VerificationStatus = 'pass' | 'fail' | 'unverified';
5
+ export interface PartRef {
6
+ part: string;
7
+ copy?: number;
8
+ }
9
+ export interface HardwareRef {
10
+ hardware: string;
11
+ }
12
+ export type BodyRef = PartRef | HardwareRef;
13
+ export type Interval = [number, number];
14
+ /** Actual finished dimensions of one stock lot. They do not regenerate the cuts. */
15
+ export interface MaterialProfile {
16
+ thickness: Interval;
17
+ kerf: Interval;
18
+ edgeError?: number;
19
+ lot?: string;
20
+ }
21
+ export interface VerificationProvenance {
22
+ sourceHash: string;
23
+ engineHash: string;
24
+ dependencies: Record<string, string>;
25
+ fonts: Record<string, string>;
26
+ }
27
+ export interface SnapshotPart {
28
+ name: string;
29
+ copy: number;
30
+ thickness: number;
31
+ material: string;
32
+ kerf: number | null;
33
+ matrix: number[];
34
+ placed: boolean;
35
+ regions: Poly[];
36
+ /** null means unavailable; [] means known to have no open cutting lines. */
37
+ cutLines: Poly[] | null;
38
+ bends: Bend[];
39
+ stack?: number;
40
+ glue?: PartRef;
41
+ glueFace?: 'top' | 'bottom';
42
+ on?: string;
43
+ }
44
+ export interface SnapshotHardware {
45
+ label: string | null;
46
+ kind: string;
47
+ from: Vec3;
48
+ to: Vec3;
49
+ size: number | [number, number];
50
+ up: Vec3;
51
+ /** A ball of diameter size centred at from (from and to are the same point) */
52
+ shape?: 'ball';
53
+ }
54
+ export interface VerificationSnapshot {
55
+ schemaVersion: 1;
56
+ configuration: string;
57
+ params: Record<string, Value>;
58
+ renderSettings: Record<string, Value>;
59
+ provenance: VerificationProvenance | null;
60
+ parts: SnapshotPart[];
61
+ hardware: SnapshotHardware[];
62
+ warnings: string[];
63
+ legacyHardware: boolean;
64
+ relationsKnown: boolean;
65
+ error?: string;
66
+ }
67
+ interface ClaimBase {
68
+ id: string;
69
+ required?: boolean;
70
+ configurations?: string[];
71
+ }
72
+ export interface GlueContactClaim extends ClaimBase {
73
+ kind: 'glue-contact';
74
+ a: PartRef;
75
+ b: PartRef;
76
+ faceA: 'top' | 'bottom';
77
+ faceB: 'top' | 'bottom';
78
+ minimumArea: number;
79
+ }
80
+ export interface TabSlotClaim extends ClaimBase {
81
+ kind: 'tab-slot';
82
+ tab: PartRef;
83
+ receiver: PartRef;
84
+ /** Rectangle in the tab's local coordinates selecting its tongue. */
85
+ region: [number, number, number, number];
86
+ clearance: Interval;
87
+ /** Require through engagement, allowing this much shortfall. */
88
+ flushTolerance: number;
89
+ minimumLigament: number;
90
+ }
91
+ export interface ShaftStop {
92
+ body: HardwareRef;
93
+ attachment: {
94
+ kind: 'integral';
95
+ } | {
96
+ kind: 'threaded';
97
+ thread: HardwareRef;
98
+ minimumEngagement: number;
99
+ secured: boolean;
100
+ } | {
101
+ kind: 'unknown';
102
+ };
103
+ }
104
+ export interface CapturedShaftClaim extends ClaimBase {
105
+ kind: 'captured-shaft';
106
+ shaft: HardwareRef;
107
+ bearings: [PartRef, PartRef];
108
+ /** Parts between the two bearing faces, including spacers and rotors. */
109
+ stack: PartRef[];
110
+ stops: [ShaftStop, ShaftStop];
111
+ clearance: Interval;
112
+ endplay: Interval;
113
+ minimumOverlap: number;
114
+ maximumStopGap: number;
115
+ }
116
+ export interface InvariantClaim extends ClaimBase {
117
+ kind: 'cut-invariant';
118
+ }
119
+ export interface MaterialClaim extends ClaimBase {
120
+ kind: 'material-assignment';
121
+ }
122
+ export type Trajectory = {
123
+ kind: 'translate';
124
+ by: Vec3;
125
+ } | {
126
+ kind: 'rotate';
127
+ origin: Vec3;
128
+ axis: Vec3;
129
+ angle: number;
130
+ };
131
+ export interface MotionClaim extends ClaimBase {
132
+ kind: 'motion-clearance';
133
+ from: string;
134
+ to: string;
135
+ moving: {
136
+ body: BodyRef;
137
+ trajectory: Trajectory;
138
+ }[];
139
+ minimumGap: number;
140
+ maxIntervals?: number;
141
+ constraints?: string;
142
+ }
143
+ export interface ClearanceClaim extends ClaimBase {
144
+ kind: 'rigid-clearance';
145
+ minimumGap: number;
146
+ /** Defaults to all physical inventory. No whole-pair collision exemptions. */
147
+ bodies?: BodyRef[];
148
+ }
149
+ export interface AssemblyClaim extends ClaimBase {
150
+ kind: 'assembly-access';
151
+ initial: BodyRef[];
152
+ scope?: BodyRef[];
153
+ steps: {
154
+ id: string;
155
+ part: BodyRef;
156
+ /** Starting displacement from the final installed pose. */
157
+ from: Vec3;
158
+ held: boolean;
159
+ fasten?: string[];
160
+ tool?: {
161
+ from: Vec3;
162
+ to: Vec3;
163
+ diameter: number;
164
+ travel: Vec3;
165
+ };
166
+ }[];
167
+ minimumGap: number;
168
+ maxIntervals?: number;
169
+ }
170
+ export interface RetentionClaim extends ClaimBase {
171
+ kind: 'retention';
172
+ roots: BodyRef[];
173
+ /** Each link references a measured geometric contract, with its fastening assumption. */
174
+ links: {
175
+ claim: string;
176
+ fastening: 'glued' | 'locked' | 'captured';
177
+ installed: boolean;
178
+ }[];
179
+ removable?: BodyRef[];
180
+ }
181
+ export type JointRelation = {
182
+ kind: 'fixed';
183
+ a: BodyRef;
184
+ b: BodyRef;
185
+ } | {
186
+ kind: 'revolute';
187
+ a: BodyRef;
188
+ b: BodyRef;
189
+ anchorA: Vec3;
190
+ anchorB: Vec3;
191
+ axisA: Vec3;
192
+ axisB: Vec3;
193
+ range?: Interval;
194
+ } | {
195
+ kind: 'prismatic';
196
+ a: BodyRef;
197
+ b: BodyRef;
198
+ axisA: Vec3;
199
+ travel: Interval;
200
+ } | {
201
+ kind: 'gear';
202
+ a: BodyRef;
203
+ b: BodyRef;
204
+ axisA: Vec3;
205
+ axisB: Vec3;
206
+ ratio: number;
207
+ };
208
+ export interface JointClaim extends ClaimBase {
209
+ kind: 'joint-constraints';
210
+ bodies: BodyRef[];
211
+ roots: BodyRef[];
212
+ joints: JointRelation[];
213
+ expectedDof: number;
214
+ }
215
+ export interface StabilityClaim extends ClaimBase {
216
+ kind: 'stability';
217
+ supports: BodyRef[];
218
+ loads: {
219
+ body: BodyRef;
220
+ mass: number;
221
+ center?: Vec3;
222
+ }[];
223
+ ground: number;
224
+ gravity: Vec3;
225
+ minimumMargin: number;
226
+ retention?: string;
227
+ }
228
+ export interface AssemblySupportClaim extends ClaimBase {
229
+ kind: 'assembly-support';
230
+ plan: string;
231
+ retention: string;
232
+ holds?: {
233
+ step: string;
234
+ bodies: BodyRef[];
235
+ }[];
236
+ }
237
+ export interface UnsupportedClaim extends ClaimBase {
238
+ kind: 'strength';
239
+ }
240
+ export type VerificationClaim = GlueContactClaim | TabSlotClaim | CapturedShaftClaim | InvariantClaim | MaterialClaim | MotionClaim | ClearanceClaim | AssemblyClaim | RetentionClaim | JointClaim | StabilityClaim | AssemblySupportClaim | UnsupportedClaim;
241
+ export interface VerificationSpec {
242
+ schemaVersion: 1;
243
+ model: string;
244
+ configurations: {
245
+ id: string;
246
+ params?: Record<string, Value>;
247
+ materials?: Record<string, MaterialProfile>;
248
+ }[];
249
+ materials?: Record<string, MaterialProfile>;
250
+ claims: VerificationClaim[];
251
+ }
252
+ export interface VerificationIssue {
253
+ code: string;
254
+ message: string;
255
+ path?: string;
256
+ }
257
+ export interface ClaimResult {
258
+ id: string;
259
+ kind: string;
260
+ required: boolean;
261
+ status: VerificationStatus;
262
+ configurations: string[];
263
+ assemblyStep?: string;
264
+ code: string;
265
+ message: string;
266
+ entities: BodyRef[];
267
+ measurements: Record<string, number | Interval>;
268
+ assumptions: string[];
269
+ coverage: 'nominal' | 'bounded-fit' | 'discrete' | 'continuous-nominal' | 'none';
270
+ }
271
+ export interface VerificationReport {
272
+ schemaVersion: 1;
273
+ model: string;
274
+ status: VerificationStatus;
275
+ algorithm: 'kerf-rigid-v1';
276
+ /** Linear predicates within this band are unresolved rather than rounded to pass. */
277
+ numericalTolerance: number;
278
+ specification: VerificationSpec;
279
+ claims: ClaimResult[];
280
+ inputs: {
281
+ configuration: string;
282
+ params: Record<string, Value>;
283
+ renderSettings: Record<string, Value>;
284
+ provenance: VerificationProvenance | null;
285
+ }[];
286
+ uncovered: string[];
287
+ }
288
+ export type VerificationResult = {
289
+ kind: 'invalid-spec' | 'invalid-snapshot';
290
+ issues: VerificationIssue[];
291
+ } | {
292
+ kind: 'report';
293
+ report: VerificationReport;
294
+ };
295
+ export interface VerifyLimits {
296
+ maxPoints?: number;
297
+ maxClaims?: number;
298
+ maxConfigurations?: number;
299
+ maxOperations?: number;
300
+ }
301
+ export {};
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.