laser-cutter 2.0.0 → 3.0.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 (113) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/pages.yml +44 -0
  3. data/.gitignore +2 -0
  4. data/.openlanes/config.yml +106 -0
  5. data/.plans/002.00/342/224/201/342/224/201/342/232/252/342/224/201/342/224/201/342/235/257lid-options/plan.md +45 -0
  6. data/.plans/003.00/342/224/201/342/224/201/342/232/252/342/224/201/342/224/201/342/235/257ruby-api/plan.md +37 -0
  7. data/.plans/004.00/342/224/201/342/224/201/342/232/252/342/224/201/342/224/201/342/235/257can-we-create-an-angled-box-where-angle-is-configurable-like-in-spec-wishes-image-shows/spec.md +40 -0
  8. data/.plans/004.00/342/224/201/342/224/201/342/232/252/342/224/201/342/224/201/342/235/257can-we-create-an-angled-box-where-angle-is-configurable-like-in-spec-wishes-image-shows/state.json +337 -0
  9. data/.plans/004.01/342/224/201/342/224/201/342/232/252/342/224/201/342/224/201/342/235/257sloped-box-panels/plan.md +91 -0
  10. data/.plans/decisions.md +11 -0
  11. data/CHANGELOG.md +134 -0
  12. data/CLAUDE.md +30 -5
  13. data/Gemfile +2 -1
  14. data/README.md +309 -31
  15. data/Rakefile +11 -7
  16. data/docs/badges/coverage_badge.svg +2 -2
  17. data/docs/decisions/decisions-on-angled-box.md +93 -0
  18. data/docs/decisions/stack.md +6 -0
  19. data/docs/images/box-3d.avif +0 -0
  20. data/docs/images/box-lid-back.avif +0 -0
  21. data/docs/images/box-lid-full.avif +0 -0
  22. data/docs/images/box-lid-plain.avif +0 -0
  23. data/docs/images/box-metric.avif +0 -0
  24. data/docs/images/box-sloped-3d.avif +0 -0
  25. data/docs/images/box-sloped.avif +0 -0
  26. data/docs/images/box-tray.avif +0 -0
  27. data/justfile +24 -8
  28. data/laser-cutter.gemspec +2 -1
  29. data/lib/laser/cutter/aggregator.rb +28 -0
  30. data/lib/laser/cutter/box.rb +192 -24
  31. data/lib/laser/cutter/box_factory.rb +15 -0
  32. data/lib/laser/cutter/cli/command.rb +27 -1
  33. data/lib/laser/cutter/cli/config_file.rb +2 -0
  34. data/lib/laser/cutter/cli/examples.rb +8 -0
  35. data/lib/laser/cutter/cli/generate.rb +41 -5
  36. data/lib/laser/cutter/cli/help.rb +4 -0
  37. data/lib/laser/cutter/cli/page_sizes.rb +3 -0
  38. data/lib/laser/cutter/cli/version.rb +2 -0
  39. data/lib/laser/cutter/cli.rb +23 -4
  40. data/lib/laser/cutter/configuration.rb +42 -2
  41. data/lib/laser/cutter/geometry/dimensions.rb +7 -0
  42. data/lib/laser/cutter/geometry/line.rb +42 -0
  43. data/lib/laser/cutter/geometry/loop.rb +138 -0
  44. data/lib/laser/cutter/geometry/point.rb +3 -0
  45. data/lib/laser/cutter/geometry/rect.rb +25 -0
  46. data/lib/laser/cutter/geometry/shape.rb +19 -1
  47. data/lib/laser/cutter/geometry/transform.rb +50 -0
  48. data/lib/laser/cutter/geometry/tuple.rb +47 -11
  49. data/lib/laser/cutter/invalid_option.rb +8 -0
  50. data/lib/laser/cutter/launcher.rb +14 -1
  51. data/lib/laser/cutter/missing_option.rb +2 -0
  52. data/lib/laser/cutter/notching/angled_edge.rb +67 -0
  53. data/lib/laser/cutter/notching/base.rb +8 -0
  54. data/lib/laser/cutter/notching/edge.rb +59 -4
  55. data/lib/laser/cutter/notching/infinite_iterator.rb +11 -1
  56. data/lib/laser/cutter/notching/path_generator.rb +86 -81
  57. data/lib/laser/cutter/notching/shift.rb +4 -0
  58. data/lib/laser/cutter/options.rb +175 -0
  59. data/lib/laser/cutter/page_manager.rb +12 -2
  60. data/lib/laser/cutter/renderer/base.rb +26 -4
  61. data/lib/laser/cutter/renderer/box_renderer.rb +14 -1
  62. data/lib/laser/cutter/renderer/layout_renderer.rb +13 -3
  63. data/lib/laser/cutter/renderer/line_renderer.rb +6 -0
  64. data/lib/laser/cutter/renderer/meta_renderer.rb +33 -9
  65. data/lib/laser/cutter/renderer/rect_renderer.rb +5 -0
  66. data/lib/laser/cutter/renderer/svg_renderer.rb +12 -4
  67. data/lib/laser/cutter/renderer.rb +2 -0
  68. data/lib/laser/cutter/sloped/box.rb +90 -0
  69. data/lib/laser/cutter/sloped/corners.rb +58 -0
  70. data/lib/laser/cutter/sloped/layout.rb +97 -0
  71. data/lib/laser/cutter/sloped/notcher.rb +53 -0
  72. data/lib/laser/cutter/sloped/panels.rb +121 -0
  73. data/lib/laser/cutter/sloped/placement.rb +36 -0
  74. data/lib/laser/cutter/sloped/profile.rb +176 -0
  75. data/lib/laser/cutter/sloped/request.rb +31 -0
  76. data/lib/laser/cutter/sloped/ring_panel.rb +120 -0
  77. data/lib/laser/cutter/sloped/side_panel.rb +89 -0
  78. data/lib/laser/cutter/types.rb +60 -0
  79. data/lib/laser/cutter/units_converter.rb +5 -0
  80. data/lib/laser/cutter/version.rb +2 -1
  81. data/lib/laser/cutter/zero_value_not_allowed.rb +2 -0
  82. data/lib/laser/cutter.rb +40 -0
  83. data/spec/laser/cutter/angled_edge_spec.rb +103 -0
  84. data/spec/laser/cutter/box_factory_spec.rb +19 -0
  85. data/spec/laser/cutter/box_lid_spec.rb +142 -0
  86. data/spec/laser/cutter/cli_spec.rb +114 -7
  87. data/spec/laser/cutter/configuration_spec.rb +54 -0
  88. data/spec/laser/cutter/loop_spec.rb +107 -0
  89. data/spec/laser/cutter/options_spec.rb +162 -0
  90. data/spec/laser/cutter/renderer/layout_renderer_spec.rb +21 -20
  91. data/spec/laser/cutter/renderer/meta_renderer_spec.rb +82 -0
  92. data/spec/laser/cutter/renderer/svg_renderer_spec.rb +34 -0
  93. data/spec/laser/cutter/sloped/assembly_spec.rb +78 -0
  94. data/spec/laser/cutter/sloped/box_spec.rb +151 -0
  95. data/spec/laser/cutter/sloped/corners_spec.rb +45 -0
  96. data/spec/laser/cutter/sloped/layout_spec.rb +77 -0
  97. data/spec/laser/cutter/sloped/notcher_spec.rb +57 -0
  98. data/spec/laser/cutter/sloped/panels_spec.rb +175 -0
  99. data/spec/laser/cutter/sloped/placement_spec.rb +50 -0
  100. data/spec/laser/cutter/sloped/request_spec.rb +48 -0
  101. data/spec/laser/cutter/sloped/ring_panel_spec.rb +102 -0
  102. data/spec/laser/cutter/sloped/side_panel_spec.rb +98 -0
  103. data/spec/laser/cutter/sloped_profile_spec.rb +156 -0
  104. data/spec/laser/cutter/transform_spec.rb +53 -0
  105. data/spec/laser/cutter_spec.rb +114 -0
  106. data/spec/spec_helper.rb +4 -0
  107. data/spec/support/loops.rb +106 -0
  108. data/spec/support/outline.rb +53 -0
  109. data/spec/support/sloped.rb +26 -0
  110. data/spec/support/solid.rb +95 -0
  111. data/spec/wishes/wish-tilted-box.png +0 -0
  112. metadata +81 -7
  113. /data/.plans/{001.00-dry-cli-migration/plan.md → 001.00/342/224/201/342/224/201/342/232/252/342/224/201/342/224/201/342/235/257dry-cli-migration/plan.md"} +0 -0
data/README.md CHANGED
@@ -1,9 +1,13 @@
1
- [![Gem Version](https://badge.fury.io/rb/laser-cutter.svg)](http://badge.fury.io/rb/laser-cutter) ![coverage](docs/badges/coverage_badge.svg)
1
+ [![Gem Version](https://badge.fury.io/rb/laser-cutter.svg)](http://badge.fury.io/rb/laser-cutter) ![coverage](docs/badges/coverage_badge.svg) [![documentation](https://assets.readthedocs.org/static/projects/badges/passing-flat.svg)](https://kigster.github.io/laser-cutter/)
2
2
 
3
3
  ## LaserCutter and Make-A-Box.io
4
4
 
5
5
  `laser-cutter` is a ruby library for generating PDF designs for boxes of custom dimensions that suit your project, that can be cut from wood or acrylic using a laser-cutter. The sides of the box snap together using alternating notches, that are deliberately layed out in a symmetric form.
6
6
 
7
+ ![An assembled box, 5 in wide, 3 in deep and 4 in tall, its six panels joined by notches](docs/images/box-3d.avif)
8
+
9
+ A box 5 in wide, 3 in deep and 4 in tall, assembled from the six panels `laser-cutter` draws.
10
+
7
11
  To use `laser-cutter` you need to have a recent version of ruby interpreter, install it as a gem, and use command line to generate PDFs.
8
12
 
9
13
  [Make-A-Box](http://makeabox.io) is a online web application that uses `laser-cutter` library and provides a straight-forward user interface for generating PDF designs without the need to install the gem or use command line.
@@ -16,6 +20,8 @@ One of the design goals of this project is to provide a highly extensible platfo
16
20
 
17
21
  `laser-cutter` supports many flexible command line options that allow setting dimensions, stroke width, page size, layout, margins, padding (spacing between the boxes), and many more.
18
22
 
23
+ Version 3.0 adds a [sloped front](#a-sloped-front): a seven-panel enclosure whose front leans back, to hold a screen or a control panel.
24
+
19
25
  ## Dependencies
20
26
 
21
27
  The gem depends primarily on [Prawn](http://prawnpdf.org) – a fantastic PDF generation library. SVG output uses [Victor](https://github.com/DannyBen/victor), and the command line is built on [dry-cli](https://dry-cli.tools/). It needs Ruby 4.0 or newer.
@@ -42,8 +48,10 @@ $ gem install laser-cutter
42
48
 
43
49
  ## Usage
44
50
 
51
+ The gem installs two executables that run the same program: `laser-cutter`, and its shortcut `lc`. The examples below use `lc`.
52
+
45
53
  ```text
46
- laser-cutter COMMAND [OPTIONS]
54
+ lc COMMAND [OPTIONS]
47
55
 
48
56
  generate, g Draw the panels of a box into a PDF or an SVG file
49
57
  page-sizes List every page size, with its dimensions
@@ -53,19 +61,35 @@ laser-cutter COMMAND [OPTIONS]
53
61
  completion Print a bash or zsh completion script
54
62
  ```
55
63
 
56
- `laser-cutter help generate` lists every option. The common ones:
57
-
58
- | Option | Meaning |
59
- | :--------------------- | :------------------------------------------------------------- |
60
- | `-b`, `--box` | `WxHxD/T[/N]`: width, height, depth, thickness, optional notch |
61
- | `-w`, `-H`, `-d`, `-t` | Width, height, depth and thickness, one at a time |
62
- | `-n`, `--notch` | Notch length, a guide only |
63
- | `-k`, `--kerf` | Kerf, the width of the cut |
64
- | `-u`, `--units` | `in` (default) or `mm` |
65
- | `-o`, `--file` | File to write, required |
66
- | `-f`, `--format` | `pdf` (default) or `svg`, in either case |
67
- | `-B`, `--inside-box` | Also draw the box without kerf, in red |
68
- | `-W`, `-R` | Save the configuration to a file, or read it from one |
64
+ `lc help generate` lists every option:
65
+
66
+ | Option | Meaning | Default |
67
+ | :------------------------ | :---------------------------------------------------------------------------------------------------------------------- | :------------ |
68
+ | `-b`, `--box` | `WxHxD/T[/N]`: width, height, depth, thickness and optional notch, in one expression | |
69
+ | `-w`, `--width` | Internal width of the box | |
70
+ | `-H`, `--height` | Internal height of the box | |
71
+ | `-d`, `--depth` | Internal depth of the box | |
72
+ | `-t`, `--thickness` | Thickness of the material | |
73
+ | `-S`, `--slope` | Angle of a sloped panel above horizontal, in degrees, for mounting a screen. Requires `--front-height`, see below | |
74
+ | `-F`, `--front-height` | Internal height at the front of a sloped box, where the slope begins | |
75
+ | `-L`, `--lid` | `full` (notched on every side), `back` (into the back wall only, not with `--slope`) or `plain` (no notches), see below | `full` |
76
+ | `-n`, `--notch` | Notch length, a guide only | 3 × thickness |
77
+ | `-k`, `--kerf` | Kerf, the width of the cut | `0.0024in` |
78
+ | `-u`, `--units` | Units every dimension is in: `in` or `mm` | `in` |
79
+ | `-o`, `--file` | File to write | required |
80
+ | `-f`, `--format` | `pdf` or `svg`, in either case | `pdf` |
81
+ | `-m`, `--margin` | Margin from the edge of the page | |
82
+ | `-p`, `--padding` | Space between the panels | |
83
+ | `-s`, `--stroke` | Stroke width of the lines | |
84
+ | `-i`, `--page-size` | Page size, such as `LETTER` or `A3`; PDF only | fit the box |
85
+ | `-l`, `--page-layout` | `portrait` or `landscape`; PDF only | `portrait` |
86
+ | `-M`, `--[no-]metadata` | Print the settings of the box on the page | `true` |
87
+ | `-B`, `--[no-]inside-box` | Also draw the box without kerf, in red, to check the kerf | `false` |
88
+ | `-O`, `--[no-]open` | Open the file once it is written | `false` |
89
+ | `-W`, `--write` | Save the configuration to a file, or to STDOUT with `-` | |
90
+ | `-R`, `--read` | Read the configuration from a file, or from STDIN with `-` | |
91
+ | `-v`, `--[no-]verbose` | Print the configuration, and the full backtrace on failure | `false` |
92
+ | `-h`, `--help` | Show help | |
69
93
 
70
94
  Height is `-H`, because `-h` prints help.
71
95
 
@@ -74,33 +98,270 @@ Height is `-H`, because `-h` prints help.
74
98
  A box in inches, with the kerf set to 0.008", opened once it is written:
75
99
 
76
100
  ```bash
77
- laser-cutter generate -b 3x2x2/0.125 -k 0.008 -O -o box.pdf
101
+ lc generate -b 3x2x2/0.125 -k 0.008 -O -o box.pdf
102
+ ```
103
+
104
+ `g` is short for `generate`, and the rest of the examples use it.
105
+
106
+ A box with a lid that lifts off:
107
+
108
+ ```bash
109
+ lc g -b 3x2x2/0.125 --lid plain -o box.pdf
110
+ ```
111
+
112
+ ### The lid
113
+
114
+ The lid is the top panel. `--lid` sets how it joins the walls:
115
+
116
+ | `--lid` | The lid | The walls under it |
117
+ | :------ | :----------------------------------- | :------------------------------------------------ |
118
+ | `full` | Notched on all four sides | Notched; the box is glued shut |
119
+ | `back` | Notched where it meets the back wall | The back is notched, the other three are straight |
120
+ | `plain` | A rectangle, no notches | All four are straight |
121
+
122
+ | `--lid full` | `--lid back` | `--lid plain` |
123
+ | :------------------------------------------------------ | :--------------------------------------------------------------------- | :-------------------------------------------------------- |
124
+ | ![A box with a full lid](docs/images/box-lid-full.avif) | ![A box with a lid notched at the back](docs/images/box-lid-back.avif) | ![A box with a plain lid](docs/images/box-lid-plain.avif) |
125
+
126
+ Each is `lc g -b 3x2x2/0.125 --lid …`. The lid is the panel at the bottom of the page, the back wall the one at the top.
127
+
128
+ A lid edge without notches reaches the outside of the wall under it, and that wall ends at the internal height. So a `plain` lid is `W + 2T` by `D + 2T` and lies on top of the box, and the space inside is still `W` by `H` by `D`.
129
+
130
+ ### A sloped front
131
+
132
+ `--slope` draws a console: a box whose front leans back, the kind that holds a display tilted towards the reader. `--front-height` is where the slope begins.
133
+
134
+ ![An assembled sloped box, 5 in wide, 3 in deep and 4 in tall, with a 2.1 in front and a 45 degree slope](docs/images/box-sloped-3d.avif)
135
+
136
+ Assembled: 5 in wide, 3 in deep, 4 in tall at the back, with a 2.1 in front and the tilted panel at 45°. Mount a display or a control panel on the tilted panel, and it faces the reader.
137
+
138
+ The panels to cut:
139
+
140
+ ```bash
141
+ lc g -b 4x3x5/0.125 --slope 45 --front-height 1 -o console.pdf
78
142
  ```
79
143
 
144
+ ![A box whose front slopes back at 45 degrees](docs/images/box-sloped.avif)
145
+
146
+ Seen from the side, with `H` the height at the back and `D` the depth:
147
+
148
+ ```text
149
+ top strip
150
+ +-----------+
151
+ / |
152
+ / tilted | back, H
153
+ + |
154
+ | front |
155
+ +--------------+
156
+ bottom, D
157
+ ```
158
+
159
+ - Seven panels: two side walls, the bottom, the back, and the top strip, the tilted panel and the front strip, drawn in that order up the page from the back.
160
+ - `--slope` is the angle of the tilted panel above horizontal, above 0 and below 90. The top strip takes the depth the slope leaves: `D - (H - front height) / tan(slope)`.
161
+ - A strip of no size is dropped: `--front-height 0` starts the slope at the bottom, and a slope that reaches the back leaves no top strip.
162
+ - The tilted panel meets the strips in a plain butt joint, to be glued. Every other joint is notched.
163
+ - `--lid plain` makes the tilted panel a lid: a rectangle that lies on straight side walls and lifts off. `--lid back` does not apply.
164
+ - Numbers that do not make the shape are refused, with the reason: a slope too shallow for the depth, or strips that leave no room for a tilted panel.
165
+
80
166
  The same box as an SVG:
81
167
 
82
168
  ```bash
83
- laser-cutter generate -b 3x2x2/0.125 -f svg -o box.svg
169
+ lc g -b 3x2x2/0.125 -f svg -o box.svg
84
170
  ```
85
171
 
86
172
  A box in millimeters on a landscape A3 page, with a 0.5mm stroke:
87
173
 
88
174
  ```bash
89
- laser-cutter generate -u mm -w 70 -H 20 -d 50 -t 4.3 -n 5 -i A3 -l landscape -s 0.5 -o box.pdf
175
+ lc g -u mm -w 70 -H 20 -d 50 -t 4.3 -n 5 -i A3 -l landscape -s 0.5 -o box.pdf
90
176
  ```
91
177
 
92
178
  Every page size, in millimeters:
93
179
 
94
180
  ```bash
95
- laser-cutter page-sizes -u mm
181
+ lc page-sizes -u mm
96
182
  ```
97
183
 
98
184
  Save the settings of a box, and use them again:
99
185
 
100
186
  ```bash
101
- laser-cutter generate -b 1.1x2.5x1.5/0.125/0.125 -p 0.1 -o box.pdf -W box-settings.json
102
- laser-cutter generate -o box.pdf -R box-settings.json
103
- cat box-settings.json | laser-cutter generate -o box.pdf -R -
187
+ lc g -b 1.1x2.5x1.5/0.125/0.125 -p 0.1 -o box.pdf -W box-settings.json
188
+ lc g -o box.pdf -R box-settings.json
189
+ cat box-settings.json | lc g -o box.pdf -R -
190
+ ```
191
+
192
+ ### More boxes
193
+
194
+ A shallow box in millimeters, glued shut:
195
+
196
+ ```bash
197
+ lc g -u mm -w 70 -H 20 -d 50 -t 4.3 -n 5 -f svg -o box.svg
198
+ ```
199
+
200
+ ![A 70 by 20 by 50 millimeter box](docs/images/box-metric.avif)
201
+
202
+ A tray with a lid that lifts off, from 3mm material with wide notches:
203
+
204
+ ```bash
205
+ lc g -u mm -w 120 -H 25 -d 80 -t 3 -n 12 --lid plain -f svg -o tray.svg
206
+ ```
207
+
208
+ ![A 120 by 25 by 80 millimeter tray with a plain lid](docs/images/box-tray.avif)
209
+
210
+ ### Storage boxes
211
+
212
+ No special folding option is needed for notch-joined storage boxes: cut the separate panels and assemble them. These designs do not use hinges or fold flat as a single sheet. Use `--lid plain` for a removable lid, or leave that panel out when cutting to make an open tray.
213
+
214
+ For a 3" square footprint and 3" height, or a 9" square footprint and 4" height, using 1/8" material:
215
+
216
+ ```bash
217
+ lc g -u in -b 3x3x3/0.125 --lid plain -o storage-small.pdf
218
+ lc g -u in -b 9x4x9/0.125 --lid plain -o storage-large.pdf
219
+ ```
220
+
221
+ The shorthand is **width × height × depth**, and dimensions describe the inside space. To nest one assembled box inside another, allow clearance for the smaller box's outside dimensions, including the material thickness; sizes are not adjusted for nesting automatically.
222
+
223
+ The pictures on this page are the SVG files themselves, drawn with a thicker stroke (`-s 0.5`) and converted:
224
+
225
+ ```bash
226
+ magick -density 96 -background white box.svg -flatten box.avif
227
+ ```
228
+
229
+ ## Using it from Ruby
230
+
231
+ The API documentation is at [kigster.github.io/laser-cutter](https://kigster.github.io/laser-cutter/), built from the YARD comments with `rake doc`.
232
+
233
+ A Ruby program draws a box in its own process; nothing runs the command line. It needs three things:
234
+
235
+ | Call | What it does |
236
+ | :------------------------------ | :------------------------------------------------ |
237
+ | `Laser::Cutter::Options.new` | Every setting of a box, typed and checked |
238
+ | `Laser::Cutter.render(options)` | Returns the PDF or the SVG as a String |
239
+ | `Laser::Cutter.write(options)` | Writes it to `options.file`, and returns the path |
240
+
241
+ ```ruby
242
+ require "laser-cutter"
243
+
244
+ options = Laser::Cutter::Options.new(
245
+ width: 70, height: 20, depth: 50, thickness: 4.3,
246
+ units: :mm, lid: :plain, format: :svg
247
+ )
248
+
249
+ svg = Laser::Cutter.render(options) # a String, no file written
250
+ Laser::Cutter.write(options.new(file: "box.pdf", format: nil)) # the extension picks the format
251
+ ```
252
+
253
+ `Options` has an attribute for each option of `generate`:
254
+
255
+ | Attribute | Type | When left out |
256
+ | :-------------------------------------- | :----------------------- | :----------------------------- |
257
+ | `width`, `height`, `depth`, `thickness` | Float above zero | `MissingOption` is raised |
258
+ | `notch` | Float above zero | Three times the thickness |
259
+ | `kerf`, `margin`, `padding` | Float, zero or more | The default for the units |
260
+ | `stroke` | Float above zero | The default for the units |
261
+ | `units` | `in` or `mm` | `in` |
262
+ | `lid` | `full`, `back`, `plain` | `full` |
263
+ | `slope` | Float, above 0, below 90 | The box has six panels |
264
+ | `front_height` | Float, zero or more | Required with `slope` |
265
+ | `format` | `pdf` or `svg` | `pdf`, or the file's extension |
266
+ | `file` | String | Only `write` needs it |
267
+ | `page_size` | A name such as `A4` | The page fits the box |
268
+ | `page_layout` | `portrait`, `landscape` | `portrait` |
269
+ | `metadata` | Boolean | `true` |
270
+ | `inside_box` | Boolean | `false` |
271
+
272
+ - Values are coerced, so the Strings a web form sends will do, and a blank String counts as left out. Keys may be Strings or Symbols.
273
+ - A value it cannot use, or a key that is not an option, raises `Laser::Cutter::InvalidOption` with a message such as `lid cannot be "sliding", but must be one of: full, back, plain.` Both errors descend from `Laser::Cutter::Error`.
274
+ - An `Options` cannot be changed; `options.new(lid: :back)` returns a changed copy.
275
+
276
+ In a Rails controller:
277
+
278
+ ```ruby
279
+ def create
280
+ box = params.require(:box).permit(*Laser::Cutter::Options.attribute_names)
281
+ send_data Laser::Cutter.render(box.to_h), type: "application/pdf", filename: "box.pdf"
282
+ rescue Laser::Cutter::Error => e
283
+ redirect_to new_box_path, alert: e.message
284
+ end
285
+ ```
286
+
287
+ `Laser::Cutter::Box::LIDS` lists the lids, for a select, and `Laser::Cutter::Sloped::Box::LIDS` those of a sloped box. `Configuration`, `Renderer::LayoutRenderer#render` and `PageManager#page_size_values`, which MakeABox.io called in 1.0.3, still work.
288
+
289
+ ### Drawing a PDF or an SVG
290
+
291
+ `render` and `write` share one path. A slope picks the box, and the format picks the renderer. `SlopedBox` in the diagram is `Sloped::Box`.
292
+
293
+ ```mermaid
294
+ ---
295
+ config:
296
+ layout: elk
297
+ look: neo
298
+ fontFamily: '''Open Sans Variable'', sans-serif'
299
+ theme: redux-color
300
+ htmlLabels: true
301
+ themeVariables:
302
+ fontFamily: '''Open Sans Variable'', sans-serif'
303
+ ---
304
+ classDiagram
305
+ direction TB
306
+ class Cutter {
307
+ +render(options) String
308
+ +write(options) String
309
+ }
310
+ class Options
311
+ class Configuration
312
+ class Renderer {
313
+ +for(format, config)
314
+ }
315
+ class LayoutRenderer
316
+ class SvgRenderer
317
+ class BoxFactory {
318
+ +for(config)
319
+ }
320
+ class Box
321
+ class SlopedBox
322
+
323
+ Cutter --> Options
324
+ Options --> Configuration
325
+ Cutter --> Renderer
326
+ Configuration --> Renderer
327
+ Renderer ..> LayoutRenderer : pdf
328
+ Renderer ..> SvgRenderer : svg
329
+ LayoutRenderer --> BoxFactory
330
+ SvgRenderer --> BoxFactory
331
+ BoxFactory --> Box : no slope
332
+ BoxFactory --> SlopedBox : slope
333
+ ```
334
+
335
+ ```mermaid
336
+ ---
337
+ config:
338
+ layout: elk
339
+ look: neo
340
+ fontFamily: '''Open Sans Variable'', sans-serif'
341
+ theme: redux-color
342
+ htmlLabels: true
343
+ themeVariables:
344
+ fontFamily: '''Open Sans Variable'', sans-serif'
345
+ ---
346
+ stateDiagram-v2
347
+ [*] --> Options
348
+ Options --> Checked : validate
349
+ Checked --> Configuration
350
+ Configuration --> BoxKind
351
+ state BoxKind <<choice>>
352
+ BoxKind --> Straight : no slope
353
+ BoxKind --> Sloped : slope
354
+ Straight --> Notched : generate notches
355
+ Sloped --> Notched : generate notches
356
+ Notched --> Format
357
+ state Format <<choice>>
358
+ Format --> PDF : pdf
359
+ Format --> SVG : svg
360
+ PDF --> Document
361
+ SVG --> Document
362
+ Document --> [*] : render
363
+ Document --> Written : write
364
+ Written --> [*]
104
365
  ```
105
366
 
106
367
  ## Feature Wish List
@@ -141,21 +402,38 @@ And laser-cutter:
141
402
 
142
403
  ```bash
143
404
  gem install laser-cutter
144
- laser-cutter generate -b 1x1.5x2/0.125/0.125 -O -o box.pdf
405
+ lc g -b 1x1.5x2/0.125/0.125 -O -o box.pdf
145
406
  ```
146
407
 
147
408
  ![LaserCutter Comparison](docs/images/comparison.jpg).
148
409
 
149
- ## Contributing
150
-
151
- 1. Fork it ( https://github.com/[my-github-username]/laser-cutter/fork )
152
- 1. Create your feature branch (`git checkout -b my-new-feature`)
153
- 1. Commit your changes (`git commit -am 'Add some feature'`)
154
- 1. Create a new Pull Request
155
- 1. Push to the branch (`git push origin my-new-feature`)
410
+ ## Contributing to `laser-cutter`
411
+
412
+ The `justfile` runs the development commands. Ruby recipes load rbenv and then `bundle exec`, so they use the Ruby pinned in `.ruby-version`. `just` with no arguments opens a picker. `just --list` prints every recipe.
413
+
414
+ | Command | What it does |
415
+ | :--------------------- | :--------------------------------------------------------------------------------------------------------------- |
416
+ | `just lint` | Run RuboCop |
417
+ | `just format` | Autocorrect Ruby, then format every Markdown file. Extra arguments go to RuboCop. `-A` allows unsafe corrections |
418
+ | `just format-markdown` | Format every Markdown file |
419
+ | `just test` | Run RSpec. A path limits the run: `just test spec/laser/cutter/edge_spec.rb:42` |
420
+ | `just test-docs` | Run RSpec with the documentation formatter |
421
+ | `just test-coverage` | Run RSpec with coverage on, including a partial run |
422
+ | `just ci` | Lint, then run the coverage suite. `just check-all` is the same command |
423
+ | `just lefthook` | Run the pre-commit hooks against every file |
424
+ | `just clean` | Remove `.DS_Store` files, `tmp/`, and `coverage/` |
425
+ | `just clobber` | Remove generated files (`rake clobber`) |
426
+ | `just version` | Print the gem version |
427
+ | `just doc` | Build the YARD documentation into `doc/` |
428
+ | `just build` | Build the gem into `pkg/` |
429
+ | `just changelog` | Write `CHANGELOG.md` from the GitHub releases. Requires `CHANGELOG_GITHUB_TOKEN` |
430
+ | `just publish` | Build the gem and push it to RubyGems. `just publish 123456` passes that two-factor code |
431
+ | `just release` | Point the version tag at the current commit, force-push tags, and create the GitHub release |
432
+
433
+ The fork and pull request steps are in [CONTRIBUTING.md](CONTRIBUTING.md).
156
434
 
157
435
  ## License
158
436
 
159
437
  MIT License (MIT). Please see [LICENSE](LICENSE) for more information.
160
438
 
161
- Author: © 2015-2024 Konstantin Gredeskoul [@kigster](https://github.com/kigster)
439
+ Author: © 2015-2024 Konstantin Gredeskoul [@kigster](https://github.com/kigster)
data/Rakefile CHANGED
@@ -29,13 +29,17 @@ end
29
29
  task build: :permissions
30
30
 
31
31
  YARD::Rake::YardocTask.new(:doc) do |t|
32
- t.files = %w[lib/**/*.rb - README.md LICENSE.txt CHANGELOG.md]
33
- t.options.unshift("--title", '"dry-cli-ui: runtime terminal UI for dry-cli commands"')
34
- t.after = -> { exec("open doc/index.html") } if RUBY_PLATFORM =~ /darwin/
35
-
36
- require "fileutils"
37
- FileUtils.mkdir_p("doc/docs/badges")
38
- FileUtils.cp("docs/badges/coverage_badge.svg", "doc/docs/badges")
32
+ t.files = %w[lib/**/*.rb - README.md CHANGELOG.md CONTRIBUTING.md LICENSE.txt]
33
+ t.options = %w[--title laser-cutter --readme README.md --markup markdown --output-dir doc]
34
+ # The README shows the images and the coverage badge under docs/, so the
35
+ # site needs them at the same relative path.
36
+ t.after = lambda do
37
+ require "fileutils"
38
+ FileUtils.mkdir_p("doc/docs")
39
+ # Ensure images exist relative to the index.html
40
+ FileUtils.cp_r(%w[docs/images docs/badges], "doc/docs")
41
+ system("open", "doc/index.html") if RUBY_PLATFORM.include?("darwin") && !ENV["CI"]
42
+ end
39
43
  end
40
44
 
41
45
  RSpec::Core::RakeTask.new(:spec)
@@ -15,7 +15,7 @@
15
15
  <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
16
16
  <text x="31.5" y="15" fill="#010101" fill-opacity=".3">coverage</text>
17
17
  <text x="31.5" y="14">coverage</text>
18
- <text x="80" y="15" fill="#010101" fill-opacity=".3">97%</text>
19
- <text x="80" y="14">97%</text>
18
+ <text x="80" y="15" fill="#010101" fill-opacity=".3">99%</text>
19
+ <text x="80" y="14">99%</text>
20
20
  </g>
21
21
  </svg>
@@ -0,0 +1,93 @@
1
+ # Decisions on the angled box
2
+
3
+ Source: `spec/wishes/wish-tilted-box.png`, plan `004.00`.
4
+
5
+ ## What the wish image shows
6
+
7
+ A console box, the kind that holds an LCD tilted towards the reader. Seen from the side, the profile is a pentagon:
8
+
9
+ ```mermaid
10
+ flowchart LR
11
+ A["back (H, full height)"] --- B["top strip (Dt)"]
12
+ B --- C["tilted panel (S, at angle α)"]
13
+ C --- D["front strip (Hf)"]
14
+ D --- E["bottom (D)"]
15
+ E --- A
16
+ ```
17
+
18
+ - **Sides:** two pentagons, notched on all five edges, the sloped one included.
19
+ - **Back, bottom:** rectangles notched on all four sides, as today.
20
+ - **Tilted panel (LCD), top strip, front strip:** rectangles notched only on their ends, into the sides. Their long edges, where they meet each other at an angle, are plain.
21
+ - Seven panels, not six.
22
+
23
+ ## Decided
24
+
25
+ - **Parameters:** depth `D`, back height `H`, front height `Hf`, slope `α` in degrees, all of the inside outline. The top strip follows: `Dt = D − (H − Hf) / tan α`. `Sloped::Profile` computes it.
26
+ - **Invocation:** flags on `generate`: `--slope DEGREES` and `--front-height HF`. No `--slope` means today's six-panel box. Each flag gets an `Options` attribute.
27
+ - **Angled joints:** plain butt joints, outside faces meeting. At the obtuse corners the strip runs past the corner over the tilted panel's end, and the tilted panel stops short:
28
+ - top strip: `Dt + t / sin α`; front strip: `Hf + t / cos α`
29
+ - tilted panel: `S − t / tan α` (top) `− t · tan α` (front)
30
+ - The joint is not flush. The strip's square end stands proud of the tilted face, and a wedge of the same size stays open inside, under the strip, to be glued. The size is the length the tilted panel stops short by: `t / tan α` at the top strip, `t · tan α` at the front strip. Both are 0.25 at 45° in quarter-inch stock.
31
+ - Where a strip is dropped the corner is acute, and both panels end at the corner. Their square ends touch along the inside edge only, which leaves a V-shaped groove open on the outside and little surface to glue.
32
+ - **Lid:** `--lid` applies to the tilted panel: `full` (notched into both sides, fixed) or `plain` (lies on the sides, lifts off). `back` raises `InvalidOption`: no back wall touches the tilted panel.
33
+ - **Range:** `0 < α < 90`. The top strip is dropped when `Dt = 0` and the front strip when `Hf = 0`; with both dropped the side is a three-cornered wedge. A negative `Dt` raises `InvalidOption`, and so does a tilted panel with no length left, which a steep slope or a tall front causes.
34
+ - **`--slope` needs `--front-height`**, and the other way round: `MissingOption` and `InvalidOption`. A front height of zero is said, not assumed.
35
+
36
+ ## Joints
37
+
38
+ | Joint | Kind |
39
+ | :------------------------------------------------------- | :-------------------------------------------------------------------- |
40
+ | side to bottom, back, top strip, front strip | notched; the side has a hole in the middle |
41
+ | side to tilted panel | notched with `--lid full`; plain with `--lid plain`, the panel on top |
42
+ | bottom to back, bottom to front strip, back to top strip | notched; the back and the front strip have a tab in the middle |
43
+ | tilted panel to a strip | plain butt joint |
44
+ | tilted panel to the back or the bottom, a strip dropped | plain, both ending at the corner |
45
+
46
+ - **Strip ends:** a strip is notched into the side wall for its inside length (`Dt` or `Hf`). Past that, over the end of the tilted panel, it is a thickness wider at each end and covers the side wall.
47
+ - **The wedge:** the side wall carries a triangle under each strip, up to the outside face of the tilted panel, so the wedge the butt joint leaves is closed at both ends.
48
+ - **Corner cubes:** at each square corner of the side wall, three panels meet and one fills the cube. The back or the front strip takes it, unless both of its notches at that corner are holes; then the bottom or the top strip does.
49
+ - **A plain lid** is `W + 2t` wide and as long as the tilted panel. It lies on the straight slope of the side walls, between the strips.
50
+
51
+ ## Shape of the code
52
+
53
+ ```mermaid
54
+ flowchart TD
55
+ Config --> BoxFactory
56
+ BoxFactory -->|no slope| Box
57
+ BoxFactory -->|slope| SB[Sloped::Box]
58
+ SB --> Profile
59
+ SB --> Panels
60
+ Panels --> SidePanel
61
+ Panels --> RingPanel
62
+ Panels --> Corners
63
+ SidePanel --> Notcher
64
+ RingPanel --> Notcher
65
+ Notcher --> AngledEdge
66
+ SB --> Layout --> Placement
67
+ SB --> Loop[Geometry::Loop]
68
+ ```
69
+
70
+ - `Box` stays the six-panel box. `Sloped::Box` is a new class beside it, with the same interface, and `BoxFactory` picks one.
71
+ - **A sloped edge** is notched by laying it flat: `Notching::AngledEdge` turns the edge into a local frame with `Geometry::Transform`, notches it with `Edge` and `PathGenerator`, and turns the lines back.
72
+ - **Outlines are loops, not aggregated lines.** Each panel is one walk of points, a `Geometry::Loop`, which drops repeated points, spikes and points in the middle of a run. `Aggregator` merges only lines along an axis, so it could not do this for a sloped edge.
73
+ - **Kerf** grows each loop by half the kerf, corners kept sharp. At a corner that is not square, moving each notch by the kerf would leave a gap; growing the loop does not. On square panels it equals what `Box` draws.
74
+ - **Sheet:** the panels unfold around the back: a side wall either side of it, the bottom below, and the top strip, the tilted panel and the front strip above, in the order they wrap round the box. The right wall is the mirror image of the left. The metadata block stays at the bottom left.
75
+
76
+ ```text
77
+ +-------+
78
+ | front |
79
+ +-------+
80
+ | tilted|
81
+ +-------+
82
+ | top |
83
+ +------++-------++------+
84
+ | side || back || side |
85
+ +------++-------++------+
86
+ | bottom|
87
+ +-------+
88
+ ```
89
+
90
+ ## Next
91
+
92
+ - MakeABox.io previews the box; its form needs the two fields, and a release of this gem to call.
93
+ - A real cut, to check the fit of the butt joints and of the wedge.
@@ -0,0 +1,6 @@
1
+ # Stack
2
+
3
+ Recorded by `openlanes init`; `openlanes init --reconfigure` rewrites it.
4
+
5
+ - **Language:** ruby
6
+ - **Deployment:** gem
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
data/justfile CHANGED
@@ -1,12 +1,13 @@
1
- set shell := ["bash", "-c"]
1
+ set shell := ["bash", "-c"]
2
2
 
3
- version := `gawk -F'"' '/VERSION/ { printf "%s", $2 }' lib/laser/cutter/version.rb`
4
- rbenv := 'eval "$(rbenv init - bash 2>/dev/null || true)"; bundle exec '
5
- repo := 'git@github.com:kigster/laser-cutter.git'
6
-
7
- gem_name := 'laser-cutter'
8
- gem_file := 'pkg/' + gem_name + '-' + version + '.gem'
9
- gem_url := 'https://rubygems.org/gems/' + gem_name
3
+ version := `gawk -F'"' '/VERSION/ { printf "%s", $2 }' lib/laser/cutter/version.rb`
4
+ rbenv_init := 'eval "$(rbenv init - bash 2>/dev/null || true)"'
5
+ rbenv := rbenv_init + ' && bundle exec'
6
+ rbenv_exec := rbenv_init + ' && rbenv exec'
7
+ repo := 'git@github.com:kigster/laser-cutter.git'
8
+ gem_name := 'laser-cutter'
9
+ gem_file := 'pkg/' + gem_name + '-' + version + '.gem'
10
+ gem_url := 'https://rubygems.org/gems/' + gem_name
10
11
 
11
12
  [no-exit-message]
12
13
  recipes:
@@ -65,6 +66,21 @@ doc:
65
66
  build:
66
67
  {{ rbenv }} rake build
67
68
 
69
+ # Write CHANGELOG.md from the GitHub releases
70
+ changelog:
71
+ #!/usr/bin/env bash
72
+ set -euo pipefail
73
+ {{ rbenv_init }}
74
+ hash -r
75
+ if ! command -v github_changelog_generator >/dev/null 2>&1; then
76
+ {{ rbenv }} gem install github_changelog_generator -N >/dev/null
77
+ fi
78
+ if [[ -z ${CHANGELOG_GITHUB_TOKEN:-} ]]; then
79
+ echo "ERROR: CHANGELOG_GITHUB_TOKEN is not set" >&2
80
+ exit 1
81
+ fi
82
+ {{ rbenv_exec }} github_changelog_generator -u kigster -p laser-cutter -t "$CHANGELOG_GITHUB_TOKEN"
83
+
68
84
  # `gem push` rather than `rake release`: release also tags and pushes git,
69
85
  # which `just release` does separately, and it gives no way to pass a 2FA code.
70
86
  #
data/laser-cutter.gemspec CHANGED
@@ -22,9 +22,10 @@ Gem::Specification.new do |spec|
22
22
  spec.required_ruby_version = '>= 4.0'
23
23
 
24
24
  spec.add_dependency 'dry-cli', '~> 1.4.1'
25
- spec.add_dependency 'dry-cli-autocomplete'
25
+ spec.add_dependency 'dry-cli-autocomplete', '~> 0.6'
26
26
  spec.add_dependency 'dry-cli-help'
27
27
  spec.add_dependency 'dry-cli-ui'
28
+ spec.add_dependency 'dry-struct', '~> 1.6'
28
29
  spec.add_dependency 'hashie'
29
30
  spec.add_dependency 'matrix'
30
31
  spec.add_dependency 'pastel'