@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
@@ -0,0 +1,16 @@
1
+ import type { Poly, Pt } from './geometry.cjs';
2
+ export interface FlowOptions {
3
+ spacing: number;
4
+ step: number;
5
+ minLength: number;
6
+ seed: number;
7
+ box: [number, number, number, number];
8
+ inside: (p: Pt) => boolean;
9
+ dir: (p: Pt) => Pt | null;
10
+ tick: () => void;
11
+ maxPoints: number;
12
+ }
13
+ export declare function streamlines(o: FlowOptions): Poly[];
14
+ export declare function contourLines(v: Float64Array, nx: number, ny: number, x0: number, y0: number, cell: number, level: number): Poly[];
15
+ export declare function joinLines(lines: Poly[], tol?: number): Poly[];
16
+ export declare function insideTest(regions: Poly[]): (p: Pt) => boolean;
package/dist/plot.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ import type { Poly, Pt } from './geometry.js';
2
+ export interface FlowOptions {
3
+ spacing: number;
4
+ step: number;
5
+ minLength: number;
6
+ seed: number;
7
+ box: [number, number, number, number];
8
+ inside: (p: Pt) => boolean;
9
+ dir: (p: Pt) => Pt | null;
10
+ tick: () => void;
11
+ maxPoints: number;
12
+ }
13
+ export declare function streamlines(o: FlowOptions): Poly[];
14
+ export declare function contourLines(v: Float64Array, nx: number, ny: number, x0: number, y0: number, cell: number, level: number): Poly[];
15
+ export declare function joinLines(lines: Poly[], tol?: number): Poly[];
16
+ export declare function insideTest(regions: Poly[]): (p: Pt) => boolean;
package/dist/render.d.cts CHANGED
@@ -72,6 +72,9 @@ export interface RenderResult {
72
72
  svg: string;
73
73
  parts: PartInfo[];
74
74
  assembly: AssemblyPart[];
75
+ /** Every copy of every part, flat at its own origin, placed or not: for
76
+ * laying the parts out, or exporting them flat */
77
+ flat: AssemblyPart[];
75
78
  layers: LayerDef[];
76
79
  warnings: string[];
77
80
  echoes: string[];
package/dist/render.d.ts CHANGED
@@ -72,6 +72,9 @@ export interface RenderResult {
72
72
  svg: string;
73
73
  parts: PartInfo[];
74
74
  assembly: AssemblyPart[];
75
+ /** Every copy of every part, flat at its own origin, placed or not: for
76
+ * laying the parts out, or exporting them flat */
77
+ flat: AssemblyPart[];
75
78
  layers: LayerDef[];
76
79
  warnings: string[];
77
80
  echoes: string[];
@@ -60,9 +60,13 @@ var text = (name, doc) => ({
60
60
  p("size", "Font size in millimetres", "10"),
61
61
  p("font", "Font name", "$font"),
62
62
  named("halign", "left, center or right", '"left"'),
63
- named("valign", "baseline, top, center or bottom", '"baseline"'),
63
+ named(
64
+ "valign",
65
+ "baseline, top, center, bottom, or cap (capitals centred on y = 0)",
66
+ '"baseline"'
67
+ ),
64
68
  named("spacing", "Letter spacing factor", "1"),
65
- named("fit", "Measure at the size that fits this width")
69
+ named("fit", "Measure at the size that fits this width, or [width, cap height]")
66
70
  ],
67
71
  section: "Text measurements",
68
72
  doc
@@ -101,7 +105,10 @@ var SIGNATURES = [
101
105
  {
102
106
  name: "ellipse",
103
107
  kind: "module",
104
- params: [p("r", "[rx, ry], or one radius for both", "1")],
108
+ params: [
109
+ p("r", "[rx, ry], or one radius for both", "1"),
110
+ named("d", "[width, height], or one diameter for both, instead of r")
111
+ ],
105
112
  section: "Shapes",
106
113
  doc: "An ellipse centred on the origin"
107
114
  },
@@ -152,9 +159,25 @@ var SIGNATURES = [
152
159
  p("size", "Font size in millimetres", "10"),
153
160
  p("font", "Font name", "$font"),
154
161
  named("halign", "left, center or right", '"left"'),
155
- named("valign", "baseline, top, center or bottom", '"baseline"'),
162
+ named(
163
+ "valign",
164
+ "baseline, top, center, bottom, or cap (capitals centred on y = 0)",
165
+ '"baseline"'
166
+ ),
156
167
  named("spacing", "Letter spacing factor", "1"),
157
- named("fit", "Shrink the size so the text is no wider than this")
168
+ named(
169
+ "fit",
170
+ "Shrink the size so the text is no wider than this, or fits [width, cap height]"
171
+ ),
172
+ named(
173
+ "weight",
174
+ '"bold" thickens the strokes by 3.5% of the size, or a number of mm (less than 0 thins them)',
175
+ '"regular"'
176
+ ),
177
+ named(
178
+ "bridge",
179
+ "Join every island (an i's dot, an accent, a stencil's counter) to the rest with a strip this wide"
180
+ )
158
181
  ],
159
182
  section: "Shapes",
160
183
  doc: "Text as shapes; the font must be available to the renderer"
@@ -323,6 +346,60 @@ var SIGNATURES = [
323
346
  section: "Combining",
324
347
  doc: "Parallel lines or stripes across the area of the children"
325
348
  },
349
+ {
350
+ name: "flow",
351
+ kind: "module",
352
+ params: [
353
+ p(
354
+ "field",
355
+ "The direction at a point: function(p) giving degrees, a vector [x, y], or undef where lines stop; or one angle"
356
+ ),
357
+ p("spacing", "Distance between neighbouring lines", "2"),
358
+ p(
359
+ "step",
360
+ "Length of each step along a line: smaller follows the field more closely",
361
+ "min(0.5, spacing / 4)"
362
+ ),
363
+ named("min_length", "Lines shorter than this are left out", "spacing * 2"),
364
+ named("seed", "Where the first lines start; another seed gives another arrangement", "1")
365
+ ],
366
+ children: true,
367
+ section: "Combining",
368
+ doc: "Evenly spaced lines that follow a direction field across the area of the children, never closer than half the spacing"
369
+ },
370
+ {
371
+ name: "contours",
372
+ kind: "module",
373
+ params: [
374
+ p("field", "The height at a point: function(p) giving a number, or undef for none"),
375
+ p(
376
+ "levels",
377
+ "How many levels, spread evenly between the lowest and highest, or a list of heights",
378
+ "10"
379
+ ),
380
+ named("interval", "Instead of levels: every multiple of this height"),
381
+ named("cell", "Distance between the points sampled: smaller is finer and slower", "1")
382
+ ],
383
+ children: true,
384
+ section: "Combining",
385
+ doc: "Contour lines where a height field crosses each level, across the area of the children"
386
+ },
387
+ {
388
+ name: "occlude",
389
+ kind: "module",
390
+ params: [],
391
+ children: true,
392
+ section: "Combining",
393
+ doc: "Children back to front, each opaque: lines and outlines hide behind the areas of later children, and fills lose that area. Each iteration of a for loop is a child of its own"
394
+ },
395
+ {
396
+ name: "hide",
397
+ kind: "module",
398
+ params: [],
399
+ children: true,
400
+ section: "Combining",
401
+ doc: "Inside occlude(): an area that hides what is behind it but is not drawn"
402
+ },
326
403
  {
327
404
  name: "paint",
328
405
  kind: "module",
@@ -347,6 +424,22 @@ var SIGNATURES = [
347
424
  section: "Combining",
348
425
  doc: "Fill the holes in the areas of the children"
349
426
  },
427
+ {
428
+ name: "join_islands",
429
+ kind: "module",
430
+ params: [p("width", "How wide each joining strip is", "1")],
431
+ children: true,
432
+ section: "Combining",
433
+ doc: "Join every separate piece of the material to the nearest other piece with a strip, until it is one piece"
434
+ },
435
+ {
436
+ name: "largest",
437
+ kind: "module",
438
+ params: [p("n", "How many pieces to keep", "1")],
439
+ children: true,
440
+ section: "Combining",
441
+ doc: "Keep the n biggest connected pieces of the material, dropping crumbs; marks stay as drawn"
442
+ },
350
443
  {
351
444
  name: "close",
352
445
  kind: "module",
@@ -450,6 +543,23 @@ var SIGNATURES = [
450
543
  named("on", "The name of a bent part this one is glued to, to move with it"),
451
544
  named("slots", "Names of parts whose tabs pass through this one: their slots are cut"),
452
545
  named("clearance", "Added to the slots, in total across each", "0.1"),
546
+ named(
547
+ "slot_extra",
548
+ "Each slot swept [dx, dy] further in this part, for a hook that goes in and drops"
549
+ ),
550
+ named(
551
+ "halving",
552
+ "Names of parts this one crosses: both take a slot from opposite sides, meeting halfway"
553
+ ),
554
+ named(
555
+ "bores",
556
+ "Labels or kinds of hardware rods passing through this one: holes are cut where they cross it"
557
+ ),
558
+ named(
559
+ "fit",
560
+ 'Room in the bores: "turn" (0.3 mm on the diameter) for a part that turns on its axle, "press" (-0.1 mm) for one held fast, or a number of mm',
561
+ '"turn"'
562
+ ),
453
563
  named(
454
564
  "glue",
455
565
  "The name of a part this one is glued flat onto; at and rotate are then on its face"
@@ -703,6 +813,24 @@ var SIGNATURES = [
703
813
  section: "Paths and rotations",
704
814
  doc: "The path moved sideways, each corner mitred: the two edges of a strip along a curve"
705
815
  },
816
+ {
817
+ name: "bounds",
818
+ kind: "function",
819
+ params: [p("points", "A list of [x, y] points, or of outlines")],
820
+ section: "Paths and rotations",
821
+ doc: "[x0, y0, x1, y1] round the points; undef for none"
822
+ },
823
+ {
824
+ name: "crossings",
825
+ kind: "function",
826
+ params: [
827
+ p("points", "A closed outline of [x, y] points, or a list of outlines"),
828
+ p("x", "The vertical line x = this"),
829
+ p("y", "Or the horizontal line y = this")
830
+ ],
831
+ section: "Paths and rotations",
832
+ doc: "Where the line crosses the outline: the y (or x) values, smallest first, entering and leaving in turn"
833
+ },
706
834
  {
707
835
  name: "point_at",
708
836
  kind: "function",
@@ -799,6 +927,38 @@ var SIGNATURES = [
799
927
  section: "Lists and strings",
800
928
  doc: "A list or string in reverse order"
801
929
  },
930
+ {
931
+ name: "sort",
932
+ kind: "function",
933
+ params: [
934
+ p("values", "A list of numbers, strings or lists of them"),
935
+ p("key", "A function giving the value to order each item by")
936
+ ],
937
+ section: "Lists and strings",
938
+ doc: "The list in order, smallest first; items with equal keys keep their order"
939
+ },
940
+ {
941
+ name: "fold",
942
+ kind: "function",
943
+ params: [
944
+ p("values", "A list"),
945
+ p("initial", "The value to start from"),
946
+ p("fn", "A function(acc, item) giving the next value")
947
+ ],
948
+ section: "Lists and strings",
949
+ doc: "The value after fn(acc, item) for each item in turn, from initial: initial for an empty list"
950
+ },
951
+ {
952
+ name: "scan",
953
+ kind: "function",
954
+ params: [
955
+ p("values", "A list"),
956
+ p("initial", "The value to start from"),
957
+ p("fn", "A function(acc, item) giving the next value")
958
+ ],
959
+ section: "Lists and strings",
960
+ doc: "The value after each item as fold() goes: running totals, one per item"
961
+ },
802
962
  {
803
963
  name: "sum",
804
964
  kind: "function",
@@ -904,6 +1064,19 @@ var SIGNATURES = [
904
1064
  section: "Types",
905
1065
  doc: "The type name: number, string, boolean, undef, list, range, function or record"
906
1066
  },
1067
+ {
1068
+ name: "noise",
1069
+ kind: "function",
1070
+ params: [
1071
+ p("x", "Where to read the noise: a number, or a point [x, y] or [x, y, z]"),
1072
+ p("y", void 0, "0"),
1073
+ p("z", "A third axis: step it to get a related but different pattern", "0"),
1074
+ named("seed", "A different seed gives a different pattern", "1"),
1075
+ named("octaves", "Layers of finer detail, 1 to 8", "1")
1076
+ ],
1077
+ section: "Random values",
1078
+ doc: "Smooth noise between about -1 and 1 that changes gradually from point to point: 0 at whole numbers, so scale the point down (x / 30) for broad shapes"
1079
+ },
907
1080
  {
908
1081
  name: "rands",
909
1082
  kind: "function",
@@ -914,6 +1087,10 @@ var SIGNATURES = [
914
1087
  // Text and joints
915
1088
  text("text_width", "The advance width of the text, including spacing"),
916
1089
  text("text_metrics", "The text as [advance, [[x0, y0], [x1, y1]], ascent, descent]"),
1090
+ text(
1091
+ "text_size",
1092
+ "The text as a record: width (advance), height, bounds, cap (capital height), ascent, descent and size"
1093
+ ),
917
1094
  {
918
1095
  name: "finger_count",
919
1096
  kind: "function",
@@ -35,9 +35,13 @@ var text = (name, doc) => ({
35
35
  p("size", "Font size in millimetres", "10"),
36
36
  p("font", "Font name", "$font"),
37
37
  named("halign", "left, center or right", '"left"'),
38
- named("valign", "baseline, top, center or bottom", '"baseline"'),
38
+ named(
39
+ "valign",
40
+ "baseline, top, center, bottom, or cap (capitals centred on y = 0)",
41
+ '"baseline"'
42
+ ),
39
43
  named("spacing", "Letter spacing factor", "1"),
40
- named("fit", "Measure at the size that fits this width")
44
+ named("fit", "Measure at the size that fits this width, or [width, cap height]")
41
45
  ],
42
46
  section: "Text measurements",
43
47
  doc
@@ -76,7 +80,10 @@ var SIGNATURES = [
76
80
  {
77
81
  name: "ellipse",
78
82
  kind: "module",
79
- params: [p("r", "[rx, ry], or one radius for both", "1")],
83
+ params: [
84
+ p("r", "[rx, ry], or one radius for both", "1"),
85
+ named("d", "[width, height], or one diameter for both, instead of r")
86
+ ],
80
87
  section: "Shapes",
81
88
  doc: "An ellipse centred on the origin"
82
89
  },
@@ -127,9 +134,25 @@ var SIGNATURES = [
127
134
  p("size", "Font size in millimetres", "10"),
128
135
  p("font", "Font name", "$font"),
129
136
  named("halign", "left, center or right", '"left"'),
130
- named("valign", "baseline, top, center or bottom", '"baseline"'),
137
+ named(
138
+ "valign",
139
+ "baseline, top, center, bottom, or cap (capitals centred on y = 0)",
140
+ '"baseline"'
141
+ ),
131
142
  named("spacing", "Letter spacing factor", "1"),
132
- named("fit", "Shrink the size so the text is no wider than this")
143
+ named(
144
+ "fit",
145
+ "Shrink the size so the text is no wider than this, or fits [width, cap height]"
146
+ ),
147
+ named(
148
+ "weight",
149
+ '"bold" thickens the strokes by 3.5% of the size, or a number of mm (less than 0 thins them)',
150
+ '"regular"'
151
+ ),
152
+ named(
153
+ "bridge",
154
+ "Join every island (an i's dot, an accent, a stencil's counter) to the rest with a strip this wide"
155
+ )
133
156
  ],
134
157
  section: "Shapes",
135
158
  doc: "Text as shapes; the font must be available to the renderer"
@@ -298,6 +321,60 @@ var SIGNATURES = [
298
321
  section: "Combining",
299
322
  doc: "Parallel lines or stripes across the area of the children"
300
323
  },
324
+ {
325
+ name: "flow",
326
+ kind: "module",
327
+ params: [
328
+ p(
329
+ "field",
330
+ "The direction at a point: function(p) giving degrees, a vector [x, y], or undef where lines stop; or one angle"
331
+ ),
332
+ p("spacing", "Distance between neighbouring lines", "2"),
333
+ p(
334
+ "step",
335
+ "Length of each step along a line: smaller follows the field more closely",
336
+ "min(0.5, spacing / 4)"
337
+ ),
338
+ named("min_length", "Lines shorter than this are left out", "spacing * 2"),
339
+ named("seed", "Where the first lines start; another seed gives another arrangement", "1")
340
+ ],
341
+ children: true,
342
+ section: "Combining",
343
+ doc: "Evenly spaced lines that follow a direction field across the area of the children, never closer than half the spacing"
344
+ },
345
+ {
346
+ name: "contours",
347
+ kind: "module",
348
+ params: [
349
+ p("field", "The height at a point: function(p) giving a number, or undef for none"),
350
+ p(
351
+ "levels",
352
+ "How many levels, spread evenly between the lowest and highest, or a list of heights",
353
+ "10"
354
+ ),
355
+ named("interval", "Instead of levels: every multiple of this height"),
356
+ named("cell", "Distance between the points sampled: smaller is finer and slower", "1")
357
+ ],
358
+ children: true,
359
+ section: "Combining",
360
+ doc: "Contour lines where a height field crosses each level, across the area of the children"
361
+ },
362
+ {
363
+ name: "occlude",
364
+ kind: "module",
365
+ params: [],
366
+ children: true,
367
+ section: "Combining",
368
+ doc: "Children back to front, each opaque: lines and outlines hide behind the areas of later children, and fills lose that area. Each iteration of a for loop is a child of its own"
369
+ },
370
+ {
371
+ name: "hide",
372
+ kind: "module",
373
+ params: [],
374
+ children: true,
375
+ section: "Combining",
376
+ doc: "Inside occlude(): an area that hides what is behind it but is not drawn"
377
+ },
301
378
  {
302
379
  name: "paint",
303
380
  kind: "module",
@@ -322,6 +399,22 @@ var SIGNATURES = [
322
399
  section: "Combining",
323
400
  doc: "Fill the holes in the areas of the children"
324
401
  },
402
+ {
403
+ name: "join_islands",
404
+ kind: "module",
405
+ params: [p("width", "How wide each joining strip is", "1")],
406
+ children: true,
407
+ section: "Combining",
408
+ doc: "Join every separate piece of the material to the nearest other piece with a strip, until it is one piece"
409
+ },
410
+ {
411
+ name: "largest",
412
+ kind: "module",
413
+ params: [p("n", "How many pieces to keep", "1")],
414
+ children: true,
415
+ section: "Combining",
416
+ doc: "Keep the n biggest connected pieces of the material, dropping crumbs; marks stay as drawn"
417
+ },
325
418
  {
326
419
  name: "close",
327
420
  kind: "module",
@@ -425,6 +518,23 @@ var SIGNATURES = [
425
518
  named("on", "The name of a bent part this one is glued to, to move with it"),
426
519
  named("slots", "Names of parts whose tabs pass through this one: their slots are cut"),
427
520
  named("clearance", "Added to the slots, in total across each", "0.1"),
521
+ named(
522
+ "slot_extra",
523
+ "Each slot swept [dx, dy] further in this part, for a hook that goes in and drops"
524
+ ),
525
+ named(
526
+ "halving",
527
+ "Names of parts this one crosses: both take a slot from opposite sides, meeting halfway"
528
+ ),
529
+ named(
530
+ "bores",
531
+ "Labels or kinds of hardware rods passing through this one: holes are cut where they cross it"
532
+ ),
533
+ named(
534
+ "fit",
535
+ 'Room in the bores: "turn" (0.3 mm on the diameter) for a part that turns on its axle, "press" (-0.1 mm) for one held fast, or a number of mm',
536
+ '"turn"'
537
+ ),
428
538
  named(
429
539
  "glue",
430
540
  "The name of a part this one is glued flat onto; at and rotate are then on its face"
@@ -678,6 +788,24 @@ var SIGNATURES = [
678
788
  section: "Paths and rotations",
679
789
  doc: "The path moved sideways, each corner mitred: the two edges of a strip along a curve"
680
790
  },
791
+ {
792
+ name: "bounds",
793
+ kind: "function",
794
+ params: [p("points", "A list of [x, y] points, or of outlines")],
795
+ section: "Paths and rotations",
796
+ doc: "[x0, y0, x1, y1] round the points; undef for none"
797
+ },
798
+ {
799
+ name: "crossings",
800
+ kind: "function",
801
+ params: [
802
+ p("points", "A closed outline of [x, y] points, or a list of outlines"),
803
+ p("x", "The vertical line x = this"),
804
+ p("y", "Or the horizontal line y = this")
805
+ ],
806
+ section: "Paths and rotations",
807
+ doc: "Where the line crosses the outline: the y (or x) values, smallest first, entering and leaving in turn"
808
+ },
681
809
  {
682
810
  name: "point_at",
683
811
  kind: "function",
@@ -774,6 +902,38 @@ var SIGNATURES = [
774
902
  section: "Lists and strings",
775
903
  doc: "A list or string in reverse order"
776
904
  },
905
+ {
906
+ name: "sort",
907
+ kind: "function",
908
+ params: [
909
+ p("values", "A list of numbers, strings or lists of them"),
910
+ p("key", "A function giving the value to order each item by")
911
+ ],
912
+ section: "Lists and strings",
913
+ doc: "The list in order, smallest first; items with equal keys keep their order"
914
+ },
915
+ {
916
+ name: "fold",
917
+ kind: "function",
918
+ params: [
919
+ p("values", "A list"),
920
+ p("initial", "The value to start from"),
921
+ p("fn", "A function(acc, item) giving the next value")
922
+ ],
923
+ section: "Lists and strings",
924
+ doc: "The value after fn(acc, item) for each item in turn, from initial: initial for an empty list"
925
+ },
926
+ {
927
+ name: "scan",
928
+ kind: "function",
929
+ params: [
930
+ p("values", "A list"),
931
+ p("initial", "The value to start from"),
932
+ p("fn", "A function(acc, item) giving the next value")
933
+ ],
934
+ section: "Lists and strings",
935
+ doc: "The value after each item as fold() goes: running totals, one per item"
936
+ },
777
937
  {
778
938
  name: "sum",
779
939
  kind: "function",
@@ -879,6 +1039,19 @@ var SIGNATURES = [
879
1039
  section: "Types",
880
1040
  doc: "The type name: number, string, boolean, undef, list, range, function or record"
881
1041
  },
1042
+ {
1043
+ name: "noise",
1044
+ kind: "function",
1045
+ params: [
1046
+ p("x", "Where to read the noise: a number, or a point [x, y] or [x, y, z]"),
1047
+ p("y", void 0, "0"),
1048
+ p("z", "A third axis: step it to get a related but different pattern", "0"),
1049
+ named("seed", "A different seed gives a different pattern", "1"),
1050
+ named("octaves", "Layers of finer detail, 1 to 8", "1")
1051
+ ],
1052
+ section: "Random values",
1053
+ doc: "Smooth noise between about -1 and 1 that changes gradually from point to point: 0 at whole numbers, so scale the point down (x / 30) for broad shapes"
1054
+ },
882
1055
  {
883
1056
  name: "rands",
884
1057
  kind: "function",
@@ -889,6 +1062,10 @@ var SIGNATURES = [
889
1062
  // Text and joints
890
1063
  text("text_width", "The advance width of the text, including spacing"),
891
1064
  text("text_metrics", "The text as [advance, [[x0, y0], [x1, y1]], ascent, descent]"),
1065
+ text(
1066
+ "text_size",
1067
+ "The text as a record: width (advance), height, bounds, cap (capital height), ascent, descent and size"
1068
+ ),
892
1069
  {
893
1070
  name: "finger_count",
894
1071
  kind: "function",
package/dist/text.d.cts CHANGED
@@ -9,6 +9,11 @@ interface OtFont {
9
9
  ascender: number;
10
10
  descender: number;
11
11
  unitsPerEm: number;
12
+ tables?: {
13
+ os2?: {
14
+ sCapHeight?: number;
15
+ };
16
+ };
12
17
  }
13
18
  export declare class FontBook {
14
19
  private sources;
@@ -32,5 +37,6 @@ export declare function textMetrics(book: FontBook, text: string, o: TextOptions
32
37
  bounds: number[][];
33
38
  ascent: number;
34
39
  descent: number;
40
+ cap: number;
35
41
  };
36
42
  export {};
package/dist/text.d.ts CHANGED
@@ -9,6 +9,11 @@ interface OtFont {
9
9
  ascender: number;
10
10
  descender: number;
11
11
  unitsPerEm: number;
12
+ tables?: {
13
+ os2?: {
14
+ sCapHeight?: number;
15
+ };
16
+ };
12
17
  }
13
18
  export declare class FontBook {
14
19
  private sources;
@@ -32,5 +37,6 @@ export declare function textMetrics(book: FontBook, text: string, o: TextOptions
32
37
  bounds: number[][];
33
38
  ascent: number;
34
39
  descent: number;
40
+ cap: number;
35
41
  };
36
42
  export {};
@@ -0,0 +1,72 @@
1
+ # 3D files
2
+
3
+ KerfScript writes a model in 3D as well as the files you cut: a GLB to look
4
+ at or render, a 3MF to 3D print in colour, or an STL. Each part becomes a
5
+ solid as thick as its sheet, and what is engraved or scored on it becomes a
6
+ thin coloured layer on its face.
7
+
8
+ ```sh
9
+ kerf render box.kerf -o box.glb # the assembled model, to view or render
10
+ kerf render sign.kerf -o sign.3mf --flat # the parts flat, to print in colour
11
+ kerf render coaster.kerf -o coaster.stl # one mesh
12
+ ```
13
+
14
+ The format follows the file's extension.
15
+
16
+ ## What is in the model
17
+
18
+ - **Parts** are solids `$thickness` thick, where `part(at, rotate)` and
19
+ `place()` put them. A part that bends on a living hinge is bent, its
20
+ hinge's slits cut through it. Each copy of a part is a solid of its own.
21
+ - **Engraving and scoring** are separate bodies on the part's face, in their
22
+ layer's colour, standing 0.1 mm off it (`--mark-height` sets how far).
23
+ Score lines become strips 0.3 mm wide. Each overlaps the face by 0.01 mm,
24
+ so the two never share a face. Marks for the back face (`side = "back"`)
25
+ are on the back.
26
+ - **Hardware** from `hardware()` becomes rods, bars and balls in its colour.
27
+
28
+ A program that places no parts is laid out flat, as `--flat` does.
29
+
30
+ ## Assembled or flat
31
+
32
+ By default the parts are where the assembly puts them. With `--flat` they
33
+ lie side by side on the bed, front face up, which is how a flat design
34
+ prints: a coaster, a sign, an ornament, a bookmark. Laid flat, marks for
35
+ the back face and hardware are left out, since nothing can stand under a
36
+ part on the bed.
37
+
38
+ For printing, set the marks to a few layers' height. `--print` does both:
39
+ the parts flat and the marks 0.6 mm high, so the engraving prints as a
40
+ raised second colour.
41
+
42
+ ```sh
43
+ kerf render coaster.kerf -o coaster.3mf --print
44
+ ```
45
+
46
+ ## Formats
47
+
48
+ | File | Units | Holds |
49
+ | ------ | ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
50
+ | `.glb` | metres, y up (glTF) | a node and mesh for each body, with materials named after the sheet material or layer; each node's `extras` give its `kind` (part, mark, hardware), `part` and `copy` |
51
+ | `.3mf` | millimetres, z up | each part one object, with its engraving and scoring as coloured parts of it, so a slicer prints each in its own colour |
52
+ | `.stl` | millimetres, z up | every body in one mesh, without colours |
53
+
54
+ Every part and mark is a closed solid: each edge is shared by exactly two
55
+ triangles, facing out. A bent part is the exception: it is built from bands
56
+ across its hinge, which meet inside it.
57
+
58
+ ## From JavaScript
59
+
60
+ ```js
61
+ import { render, toModel } from '@mylasertools/kerfscript';
62
+
63
+ const result = render(source);
64
+ const glb = toModel(result, 'glb'); // a Uint8Array
65
+ const print = toModel(result, '3mf', { layout: 'flat', markHeight: 0.6 });
66
+ ```
67
+
68
+ `meshBodies(result, options)` gives the bodies themselves (positions and
69
+ triangles in millimetres) for a viewer of your own, and `toGlb()`, `to3mf()`
70
+ and `toStl()` write them. The options are `layout` (`"assembled"` or
71
+ `"flat"`), `markHeight`, `lineWidth`, `slitWidth`, `hardware` and `gap`.
72
+ See the [JavaScript API](javascript.md).