laser-cutter 2.0.1 → 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.
- checksums.yaml +4 -4
- data/.github/workflows/pages.yml +44 -0
- data/.gitignore +2 -0
- data/.openlanes/config.yml +106 -0
- 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
- 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
- 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
- data/.plans/decisions.md +11 -0
- data/CHANGELOG.md +134 -0
- data/CLAUDE.md +18 -6
- data/Gemfile +2 -1
- data/README.md +223 -50
- data/Rakefile +11 -7
- data/docs/badges/coverage_badge.svg +2 -2
- data/docs/decisions/decisions-on-angled-box.md +93 -0
- data/docs/decisions/stack.md +6 -0
- data/docs/images/box-3d.avif +0 -0
- data/docs/images/box-sloped-3d.avif +0 -0
- data/docs/images/box-sloped.avif +0 -0
- data/justfile +24 -8
- data/laser-cutter.gemspec +1 -1
- data/lib/laser/cutter/aggregator.rb +28 -0
- data/lib/laser/cutter/box.rb +95 -5
- data/lib/laser/cutter/box_factory.rb +15 -0
- data/lib/laser/cutter/cli/command.rb +27 -1
- data/lib/laser/cutter/cli/config_file.rb +2 -0
- data/lib/laser/cutter/cli/examples.rb +3 -0
- data/lib/laser/cutter/cli/generate.rb +37 -6
- data/lib/laser/cutter/cli/help.rb +4 -0
- data/lib/laser/cutter/cli/page_sizes.rb +3 -0
- data/lib/laser/cutter/cli/version.rb +2 -0
- data/lib/laser/cutter/cli.rb +23 -4
- data/lib/laser/cutter/configuration.rb +38 -4
- data/lib/laser/cutter/geometry/dimensions.rb +7 -0
- data/lib/laser/cutter/geometry/line.rb +42 -0
- data/lib/laser/cutter/geometry/loop.rb +138 -0
- data/lib/laser/cutter/geometry/point.rb +3 -0
- data/lib/laser/cutter/geometry/rect.rb +25 -0
- data/lib/laser/cutter/geometry/shape.rb +19 -1
- data/lib/laser/cutter/geometry/transform.rb +50 -0
- data/lib/laser/cutter/geometry/tuple.rb +47 -11
- data/lib/laser/cutter/launcher.rb +14 -1
- data/lib/laser/cutter/missing_option.rb +2 -0
- data/lib/laser/cutter/notching/angled_edge.rb +67 -0
- data/lib/laser/cutter/notching/base.rb +8 -0
- data/lib/laser/cutter/notching/edge.rb +44 -4
- data/lib/laser/cutter/notching/infinite_iterator.rb +11 -1
- data/lib/laser/cutter/notching/path_generator.rb +40 -6
- data/lib/laser/cutter/notching/shift.rb +4 -0
- data/lib/laser/cutter/options.rb +25 -4
- data/lib/laser/cutter/page_manager.rb +12 -2
- data/lib/laser/cutter/renderer/base.rb +19 -3
- data/lib/laser/cutter/renderer/box_renderer.rb +14 -1
- data/lib/laser/cutter/renderer/layout_renderer.rb +10 -0
- data/lib/laser/cutter/renderer/line_renderer.rb +6 -0
- data/lib/laser/cutter/renderer/meta_renderer.rb +33 -9
- data/lib/laser/cutter/renderer/rect_renderer.rb +5 -0
- data/lib/laser/cutter/renderer/svg_renderer.rb +9 -1
- data/lib/laser/cutter/renderer.rb +2 -0
- data/lib/laser/cutter/sloped/box.rb +90 -0
- data/lib/laser/cutter/sloped/corners.rb +58 -0
- data/lib/laser/cutter/sloped/layout.rb +97 -0
- data/lib/laser/cutter/sloped/notcher.rb +53 -0
- data/lib/laser/cutter/sloped/panels.rb +121 -0
- data/lib/laser/cutter/sloped/placement.rb +36 -0
- data/lib/laser/cutter/sloped/profile.rb +176 -0
- data/lib/laser/cutter/sloped/request.rb +31 -0
- data/lib/laser/cutter/sloped/ring_panel.rb +120 -0
- data/lib/laser/cutter/sloped/side_panel.rb +89 -0
- data/lib/laser/cutter/types.rb +3 -0
- data/lib/laser/cutter/units_converter.rb +5 -0
- data/lib/laser/cutter/version.rb +2 -1
- data/lib/laser/cutter/zero_value_not_allowed.rb +2 -0
- data/lib/laser/cutter.rb +2 -0
- data/spec/laser/cutter/angled_edge_spec.rb +103 -0
- data/spec/laser/cutter/box_factory_spec.rb +19 -0
- data/spec/laser/cutter/cli_spec.rb +87 -7
- data/spec/laser/cutter/configuration_spec.rb +37 -0
- data/spec/laser/cutter/loop_spec.rb +107 -0
- data/spec/laser/cutter/options_spec.rb +51 -9
- data/spec/laser/cutter/renderer/layout_renderer_spec.rb +18 -0
- data/spec/laser/cutter/renderer/meta_renderer_spec.rb +82 -0
- data/spec/laser/cutter/renderer/svg_renderer_spec.rb +34 -0
- data/spec/laser/cutter/sloped/assembly_spec.rb +78 -0
- data/spec/laser/cutter/sloped/box_spec.rb +151 -0
- data/spec/laser/cutter/sloped/corners_spec.rb +45 -0
- data/spec/laser/cutter/sloped/layout_spec.rb +77 -0
- data/spec/laser/cutter/sloped/notcher_spec.rb +57 -0
- data/spec/laser/cutter/sloped/panels_spec.rb +175 -0
- data/spec/laser/cutter/sloped/placement_spec.rb +50 -0
- data/spec/laser/cutter/sloped/request_spec.rb +48 -0
- data/spec/laser/cutter/sloped/ring_panel_spec.rb +102 -0
- data/spec/laser/cutter/sloped/side_panel_spec.rb +98 -0
- data/spec/laser/cutter/sloped_profile_spec.rb +156 -0
- data/spec/laser/cutter/transform_spec.rb +53 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/support/loops.rb +106 -0
- data/spec/support/sloped.rb +26 -0
- data/spec/support/solid.rb +95 -0
- data/spec/wishes/wish-tilted-box.png +0 -0
- metadata +55 -9
- /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/.plans/{002.00-lid-options/plan.md → 002.00/342/224/201/342/224/201/342/232/252/342/224/201/342/224/201/342/235/257lid-options/plan.md"} +0 -0
- /data/.plans/{003.00-ruby-api/plan.md → 003.00/342/224/201/342/224/201/342/232/252/342/224/201/342/224/201/342/235/257ruby-api/plan.md"} +0 -0
|
@@ -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">
|
|
19
|
-
<text x="80" y="14">
|
|
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.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/justfile
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
set shell
|
|
1
|
+
set shell := ["bash", "-c"]
|
|
2
2
|
|
|
3
|
-
version
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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,7 +22,7 @@ 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
28
|
spec.add_dependency 'dry-struct', '~> 1.6'
|
|
@@ -30,6 +30,8 @@ module Laser
|
|
|
30
30
|
|
|
31
31
|
# Lines running along one axis: 0 for horizontal (constant y), 1 for vertical (constant x).
|
|
32
32
|
#
|
|
33
|
+
# @param lines [Array<Geometry::Line>]
|
|
34
|
+
# @param axis [Integer] 0 for horizontal, 1 for vertical
|
|
33
35
|
# @return [Array<Geometry::Line>]
|
|
34
36
|
def sweep(lines, axis)
|
|
35
37
|
across = (axis + 1) % 2
|
|
@@ -37,16 +39,25 @@ module Laser
|
|
|
37
39
|
groups(along, across).flat_map { |offset, group| cut_intervals(group, axis, offset, across) }
|
|
38
40
|
end
|
|
39
41
|
|
|
42
|
+
# @param lines [Array<Geometry::Line>]
|
|
43
|
+
# @return [Array<Geometry::Line>] the lines on neither axis
|
|
40
44
|
def skewed(lines)
|
|
41
45
|
lines.reject { |line| along?(line, 0) || along?(line, 1) }
|
|
42
46
|
end
|
|
43
47
|
|
|
48
|
+
# @param line [Geometry::Line]
|
|
49
|
+
# @param axis [Integer] 0 for horizontal, 1 for vertical
|
|
50
|
+
# @return [Boolean] whether the line runs along the axis and has a length
|
|
44
51
|
def along?(line, axis)
|
|
45
52
|
across = (axis + 1) % 2
|
|
46
53
|
(line.p1[across] - line.p2[across]).abs <= TOLERANCE && (line.p1[axis] - line.p2[axis]).abs > TOLERANCE
|
|
47
54
|
end
|
|
48
55
|
|
|
49
56
|
# Lines on the same row or column, keyed by the offset of the first one seen.
|
|
57
|
+
#
|
|
58
|
+
# @param lines [Array<Geometry::Line>] lines along one axis
|
|
59
|
+
# @param across [Integer] the other axis
|
|
60
|
+
# @return [Hash{Float => Array<Geometry::Line>}]
|
|
50
61
|
def groups(lines, across)
|
|
51
62
|
lines.sort_by { |line| line.p1[across] }.slice_when { |a, b| b.p1[across] - a.p1[across] > TOLERANCE }
|
|
52
63
|
.to_h { |group| [group.first.p1[across], group] }
|
|
@@ -54,6 +65,12 @@ module Laser
|
|
|
54
65
|
|
|
55
66
|
# Sweeps the endpoints of one collinear group, keeping the stretches an
|
|
56
67
|
# odd number of lines cover.
|
|
68
|
+
#
|
|
69
|
+
# @param group [Array<Geometry::Line>] collinear lines
|
|
70
|
+
# @param axis [Integer] the axis they run along
|
|
71
|
+
# @param offset [Float] their coordinate on the other axis
|
|
72
|
+
# @param across [Integer] the other axis
|
|
73
|
+
# @return [Array<Geometry::Line>]
|
|
57
74
|
def cut_intervals(group, axis, offset, across)
|
|
58
75
|
events = group.flat_map do |line|
|
|
59
76
|
from, to = [line.p1[axis], line.p2[axis]].sort
|
|
@@ -77,6 +94,11 @@ module Laser
|
|
|
77
94
|
end
|
|
78
95
|
|
|
79
96
|
# Joins an interval onto the last one when they touch, and drops one with no length.
|
|
97
|
+
#
|
|
98
|
+
# @param intervals [Array<Array(Float, Float)>] changed in place
|
|
99
|
+
# @param from [Float]
|
|
100
|
+
# @param to [Float]
|
|
101
|
+
# @return [void]
|
|
80
102
|
def extend_or_add(intervals, from, to)
|
|
81
103
|
return if to - from <= TOLERANCE
|
|
82
104
|
|
|
@@ -88,6 +110,12 @@ module Laser
|
|
|
88
110
|
end
|
|
89
111
|
end
|
|
90
112
|
|
|
113
|
+
# @param from [Float] where the line starts along the axis
|
|
114
|
+
# @param to [Float] where it ends
|
|
115
|
+
# @param axis [Integer] the axis it runs along
|
|
116
|
+
# @param offset [Float] its coordinate on the other axis
|
|
117
|
+
# @param across [Integer] the other axis
|
|
118
|
+
# @return [Geometry::Line]
|
|
91
119
|
def line_between(from, to, axis, offset, across)
|
|
92
120
|
a = []
|
|
93
121
|
b = []
|
data/lib/laser/cutter/box.rb
CHANGED
|
@@ -2,8 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
module Laser
|
|
4
4
|
module Cutter
|
|
5
|
-
#
|
|
6
|
-
|
|
5
|
+
# A box of six panels: front, back, top (the lid), bottom, left and
|
|
6
|
+
# right. It lays them out on the page and notches every side so that
|
|
7
|
+
# neighbouring panels interlock. {BoxFactory} builds it unless the
|
|
8
|
+
# settings ask for a slope.
|
|
9
|
+
#
|
|
10
|
+
# Lengths are unitless, in the units of the settings.
|
|
7
11
|
class Box
|
|
8
12
|
# How the lid, the top panel, joins the walls: notched on all four sides,
|
|
9
13
|
# on the side of the back wall only, or on none.
|
|
@@ -12,8 +16,46 @@ module Laser
|
|
|
12
16
|
# The side of each wall that meets the lid, as an index into Rect#sides.
|
|
13
17
|
LID_SIDES = { 'front' => 0, 'left' => 0, 'right' => 0, 'back' => 2 }.freeze
|
|
14
18
|
|
|
15
|
-
#
|
|
16
|
-
|
|
19
|
+
# @!attribute [rw] dim
|
|
20
|
+
# @return [Geometry::Dimensions] the inside width, height and depth
|
|
21
|
+
# @!attribute [rw] thickness
|
|
22
|
+
# @return [Float] the thickness of the material
|
|
23
|
+
# @!attribute [rw] notch_width
|
|
24
|
+
# @return [Float] the notch width asked for; each side fits its own
|
|
25
|
+
# @!attribute [rw] kerf
|
|
26
|
+
# @return [Float] the width the laser burns away
|
|
27
|
+
# @!attribute [rw] padding
|
|
28
|
+
# @return [Float] the space between panels on the page
|
|
29
|
+
# @!attribute [rw] units
|
|
30
|
+
# @return [String, Symbol] the units of every length
|
|
31
|
+
# @!attribute [rw] inside_box
|
|
32
|
+
# @return [Object, nil] read from the settings, and not used in drawing
|
|
33
|
+
# @!attribute [rw] front
|
|
34
|
+
# @return [Geometry::Rect] the front panel
|
|
35
|
+
# @!attribute [rw] back
|
|
36
|
+
# @return [Geometry::Rect] the back panel
|
|
37
|
+
# @!attribute [rw] top
|
|
38
|
+
# @return [Geometry::Rect] the top panel, the lid
|
|
39
|
+
# @!attribute [rw] bottom
|
|
40
|
+
# @return [Geometry::Rect] the bottom panel
|
|
41
|
+
# @!attribute [rw] left
|
|
42
|
+
# @return [Geometry::Rect] the left panel
|
|
43
|
+
# @!attribute [rw] right
|
|
44
|
+
# @return [Geometry::Rect] the right panel
|
|
45
|
+
# @!attribute [rw] faces
|
|
46
|
+
# @return [Array<Geometry::Rect>] the six panels, in the order {#conf} indexes them
|
|
47
|
+
# @!attribute [rw] bounds
|
|
48
|
+
# @return [Object] unused
|
|
49
|
+
# @!attribute [rw] conf
|
|
50
|
+
# @return [Hash] for each face, whether the center notch of its
|
|
51
|
+
# horizontal (:halign) and vertical (:valign) sides is a tab, and
|
|
52
|
+
# which faces carry the corner squares (:corners)
|
|
53
|
+
# @!attribute [rw] corner_face
|
|
54
|
+
# @return [Symbol, nil] unused: {#generate_notches} picks it each time
|
|
55
|
+
# @!attribute [rw] metadata
|
|
56
|
+
# @return [Geometry::Point] the width and height kept free for the settings
|
|
57
|
+
# @!attribute [rw] notches
|
|
58
|
+
# @return [Array<Geometry::Line>] every line to cut, once generated
|
|
17
59
|
attr_accessor :dim, :thickness, :notch_width, :kerf, :padding, :units, :inside_box, :front, :back, :top, :bottom, :left, :right, :faces, :bounds, :conf, :corner_face, :metadata, :notches
|
|
18
60
|
|
|
19
61
|
# @return [Symbol] one of LIDS
|
|
@@ -22,6 +64,9 @@ module Laser
|
|
|
22
64
|
# @return [Hash{String => Array<Geometry::Line>}] the lines to cut for each face, by its name
|
|
23
65
|
attr_accessor :outlines
|
|
24
66
|
|
|
67
|
+
# @param config [Configuration, Hash] width, height, depth and thickness,
|
|
68
|
+
# and optionally notch, kerf, padding, units, inside_box, lid,
|
|
69
|
+
# metadata_width and metadata_height
|
|
25
70
|
def initialize(config = {})
|
|
26
71
|
self.dim = Geometry::Dimensions.new(config['width'], config['height'], config['depth'])
|
|
27
72
|
self.thickness = config['thickness']
|
|
@@ -51,6 +96,8 @@ module Laser
|
|
|
51
96
|
}
|
|
52
97
|
end
|
|
53
98
|
|
|
99
|
+
# @return [Geometry::Rect] the smallest rectangle around every line,
|
|
100
|
+
# generating the notches first if needed
|
|
54
101
|
def enclosure
|
|
55
102
|
generate_notches if notches.empty?
|
|
56
103
|
p1 = notches.first.p1.to_a
|
|
@@ -65,6 +112,10 @@ module Laser
|
|
|
65
112
|
Geometry::Rect[Geometry::Point.new(p1), Geometry::Point.new(p2)]
|
|
66
113
|
end
|
|
67
114
|
|
|
115
|
+
# Lays out the panels and notches them, filling {#outlines} and
|
|
116
|
+
# {#notches}.
|
|
117
|
+
#
|
|
118
|
+
# @return [Array<Geometry::Line>] every line to cut
|
|
68
119
|
def generate_notches
|
|
69
120
|
position_faces!
|
|
70
121
|
corner_face = pick_corners_face
|
|
@@ -83,14 +134,21 @@ module Laser
|
|
|
83
134
|
notches.flatten!
|
|
84
135
|
end
|
|
85
136
|
|
|
137
|
+
# @return [Float] the width
|
|
86
138
|
def w; dim.w; end
|
|
139
|
+
|
|
140
|
+
# @return [Float] the height
|
|
87
141
|
def h; dim.h; end
|
|
142
|
+
|
|
143
|
+
# @return [Float] the depth
|
|
88
144
|
def d; dim.d; end
|
|
89
145
|
|
|
146
|
+
# @return [Float] the longest dimension
|
|
90
147
|
def longest
|
|
91
148
|
[w, h, d].max
|
|
92
149
|
end
|
|
93
150
|
|
|
151
|
+
# @return [String] the dimensions, thickness and notch width
|
|
94
152
|
def to_s
|
|
95
153
|
"Box:\nH:#{dim.h} W:#{dim.w} D:#{dim.d}\nThickness:#{thickness}, Notch:#{notch_width}"
|
|
96
154
|
end
|
|
@@ -100,6 +158,9 @@ module Laser
|
|
|
100
158
|
# One edge for each side of a face, pairing the side with the matching
|
|
101
159
|
# side of the face grown by the thickness.
|
|
102
160
|
#
|
|
161
|
+
# @param face [Geometry::Rect]
|
|
162
|
+
# @param face_index [Integer] its index in {#faces}
|
|
163
|
+
# @param corner_face [Symbol] :front or :top, from {#pick_corners_face}
|
|
103
164
|
# @return [Array<Notching::Edge>]
|
|
104
165
|
def edges_of(face, face_index, corner_face)
|
|
105
166
|
bound = face_bounding_rect(face)
|
|
@@ -120,6 +181,8 @@ module Laser
|
|
|
120
181
|
# A lid that lifts off covers the corners above the walls, so a wall
|
|
121
182
|
# keeps no corner box at the end of a side that touches the lid.
|
|
122
183
|
#
|
|
184
|
+
# @param face [Geometry::Rect]
|
|
185
|
+
# @param side_index [Integer] an index into Rect#sides
|
|
123
186
|
# @return [Array<Integer>] the ends of the side that may carry a corner box
|
|
124
187
|
def corner_ends(face, side_index)
|
|
125
188
|
lid_side = LID_SIDES[face.name]
|
|
@@ -132,6 +195,8 @@ module Laser
|
|
|
132
195
|
end
|
|
133
196
|
end
|
|
134
197
|
|
|
198
|
+
# @param face [Geometry::Rect]
|
|
199
|
+
# @param edges [Array<Notching::Edge>] from {#edges_of}
|
|
135
200
|
# @return [Array<Geometry::Line>] the lines of a face before they are merged
|
|
136
201
|
def lines_of(face, edges)
|
|
137
202
|
return lid_lines(edges) if face.equal?(top)
|
|
@@ -142,12 +207,18 @@ module Laser
|
|
|
142
207
|
end
|
|
143
208
|
|
|
144
209
|
# Whether a side of a wall lies under a lid edge that has no notches.
|
|
210
|
+
#
|
|
211
|
+
# @param face [Geometry::Rect]
|
|
212
|
+
# @param side_index [Integer] an index into Rect#sides
|
|
213
|
+
# @return [Boolean]
|
|
145
214
|
def straight?(face, side_index)
|
|
146
215
|
return false if lid == :full || (lid == :back && face.equal?(back))
|
|
147
216
|
|
|
148
217
|
LID_SIDES[face.name] == side_index
|
|
149
218
|
end
|
|
150
219
|
|
|
220
|
+
# @param edges [Array<Notching::Edge>] the edges of the top panel
|
|
221
|
+
# @return [Array<Geometry::Line>] the lines of the lid, as {#lid} asks
|
|
151
222
|
def lid_lines(edges)
|
|
152
223
|
case lid
|
|
153
224
|
when :plain then edges.map(&:outside)
|
|
@@ -159,6 +230,9 @@ module Laser
|
|
|
159
230
|
# The lid notched into the back wall only. Its other three edges are
|
|
160
231
|
# straight, along the outside of the walls. Either side of the notches
|
|
161
232
|
# it has a foot, the corner square above the side wall.
|
|
233
|
+
#
|
|
234
|
+
# @param edges [Array<Notching::Edge>] the edges of the top panel, the back one first
|
|
235
|
+
# @return [Array<Geometry::Line>]
|
|
162
236
|
def back_lid_lines(edges)
|
|
163
237
|
joint = edges.first
|
|
164
238
|
joint.corners = true
|
|
@@ -170,11 +244,17 @@ module Laser
|
|
|
170
244
|
|
|
171
245
|
# The two sides of a foot the notches do not draw: its bottom, from the
|
|
172
246
|
# outer corner of the lid, and the side that faces the first notch.
|
|
247
|
+
#
|
|
248
|
+
# @param corner [Geometry::Point] the outer corner of the lid
|
|
249
|
+
# @param notch [Geometry::Point] where the notches start or end
|
|
250
|
+
# @return [Array(Geometry::Line, Geometry::Line)]
|
|
173
251
|
def foot(corner, notch)
|
|
174
252
|
turn = Geometry::Point[notch.x, corner.y]
|
|
175
253
|
[Geometry::Line[corner, turn], Geometry::Line[turn, notch]]
|
|
176
254
|
end
|
|
177
255
|
|
|
256
|
+
# @param face [Geometry::Rect]
|
|
257
|
+
# @return [Geometry::Rect] the face grown by the thickness on every side
|
|
178
258
|
def face_bounding_rect(face)
|
|
179
259
|
b = face.clone
|
|
180
260
|
b.move_to(b.position.plus(-thickness, -thickness))
|
|
@@ -203,7 +283,11 @@ module Laser
|
|
|
203
283
|
#
|
|
204
284
|
# 0,0
|
|
205
285
|
# ___________________________________________________________________
|
|
206
|
-
|
|
286
|
+
#
|
|
287
|
+
# Places the six panels in the cross above, leaving room for the
|
|
288
|
+
# settings at the bottom left.
|
|
289
|
+
#
|
|
290
|
+
# @return [Array<Geometry::Rect>] the faces
|
|
207
291
|
def position_faces!
|
|
208
292
|
offset_x = [padding + d + (3 * thickness), metadata.x + (2 * thickness) + padding].max
|
|
209
293
|
offset_y = [padding + d + (3 * thickness), metadata.y + (2 * thickness) + padding].max
|
|
@@ -224,6 +308,9 @@ module Laser
|
|
|
224
308
|
faces.each(&:relocate!)
|
|
225
309
|
end
|
|
226
310
|
|
|
311
|
+
# Creates the six panels at the origin, each the size of its side.
|
|
312
|
+
#
|
|
313
|
+
# @return [Geometry::Rect] the right panel
|
|
227
314
|
def create_faces!
|
|
228
315
|
zero = Geometry::Point.new(0, 0)
|
|
229
316
|
self.front = Geometry::Rect.create(zero, dim.w, dim.h, "front")
|
|
@@ -238,6 +325,9 @@ module Laser
|
|
|
238
325
|
|
|
239
326
|
# Choose which face will be responsible for filling out the little square overlap
|
|
240
327
|
# in the corners. Only one of the 3 possible sides need to be picked.
|
|
328
|
+
#
|
|
329
|
+
# @return [Symbol] :top when every notch count of the front is 3 more
|
|
330
|
+
# than a multiple of 4, :front otherwise
|
|
241
331
|
def pick_corners_face
|
|
242
332
|
b = face_bounding_rect(front)
|
|
243
333
|
edges = []
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Laser
|
|
4
|
+
module Cutter
|
|
5
|
+
# Picks the box a configuration asks for, so a renderer need not know
|
|
6
|
+
# how many kinds there are.
|
|
7
|
+
module BoxFactory
|
|
8
|
+
# @param config [Configuration]
|
|
9
|
+
# @return [Box, Sloped::Box] a sloped box when the configuration has a slope
|
|
10
|
+
def self.for(config)
|
|
11
|
+
config[:slope] ? Sloped::Box.new(config) : Box.new(config)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -10,15 +10,37 @@ module Laser
|
|
|
10
10
|
# Cells in a progress bar.
|
|
11
11
|
BAR_WIDTH = 60
|
|
12
12
|
|
|
13
|
+
# Gives every command the -v, --verbose flag.
|
|
14
|
+
#
|
|
15
|
+
# @param subclass [Class] the new command
|
|
16
|
+
# @return [void]
|
|
13
17
|
def self.inherited(subclass)
|
|
14
18
|
super
|
|
19
|
+
|
|
20
|
+
# Add --verbose flag to the command, but at the very end of the class definition.
|
|
21
|
+
trace = TracePoint.new(:end) do |tp|
|
|
22
|
+
# skip nested classes closing inside the body
|
|
23
|
+
next unless tp.self == subclass
|
|
24
|
+
|
|
25
|
+
# disable the trace point
|
|
26
|
+
trace.disable
|
|
27
|
+
|
|
28
|
+
# add the verbose option to the subclass as the last option
|
|
29
|
+
subclass.class_exec { finalize!(subclass) }
|
|
30
|
+
end
|
|
31
|
+
trace.enable(target_thread: Thread.current)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.finalize!(subclass)
|
|
15
35
|
subclass.option :verbose, type: :boolean, default: false, aliases: ['-v'],
|
|
16
36
|
desc: 'Print the configuration, and the full backtrace on failure'
|
|
17
37
|
end
|
|
18
38
|
|
|
19
39
|
# Boxes are as wide as help is.
|
|
40
|
+
#
|
|
41
|
+
# @return [Dry::CLI::UI::Console]
|
|
20
42
|
def ui
|
|
21
|
-
@ui ||=
|
|
43
|
+
@ui ||= CLI.console(out: out, err: err)
|
|
22
44
|
end
|
|
23
45
|
|
|
24
46
|
# A green bar of BAR_WIDTH cells, or fewer when the terminal is narrower.
|
|
@@ -26,6 +48,7 @@ module Laser
|
|
|
26
48
|
# @param label [String]
|
|
27
49
|
# @param total [Integer]
|
|
28
50
|
# @yieldparam bar [#advance]
|
|
51
|
+
# @return [Object] what the block returns
|
|
29
52
|
def progress(label, total:, &)
|
|
30
53
|
Dry::CLI::UI::Console
|
|
31
54
|
.new(out: out, err: err, box_width: CLI.help_width, width: progress_width(label))
|
|
@@ -36,6 +59,9 @@ module Laser
|
|
|
36
59
|
|
|
37
60
|
# dry-cli-ui sizes a bar as the terminal width less the label and the
|
|
38
61
|
# counters around it, so the bar is capped by capping that width.
|
|
62
|
+
#
|
|
63
|
+
# @param label [String]
|
|
64
|
+
# @return [Integer] the width to give the console
|
|
39
65
|
def progress_width(label)
|
|
40
66
|
wanted = BAR_WIDTH + label.length + Dry::CLI::UI::Widgets::Progress::CHROME
|
|
41
67
|
err.respond_to?(:tty?) && err.tty? ? [wanted, TTY::Screen.width].min : wanted
|
|
@@ -6,6 +6,7 @@ module Laser
|
|
|
6
6
|
# A configuration saved as JSON. The path '-' stands for STDIN when
|
|
7
7
|
# reading, and for the command's own output when writing.
|
|
8
8
|
class ConfigFile
|
|
9
|
+
# The path that stands for STDIN or the command's output.
|
|
9
10
|
STDIO = '-'
|
|
10
11
|
|
|
11
12
|
# @param path [String]
|
|
@@ -23,6 +24,7 @@ module Laser
|
|
|
23
24
|
|
|
24
25
|
# @param settings [Hash]
|
|
25
26
|
# @param out [IO] where '-' writes to
|
|
27
|
+
# @return [void]
|
|
26
28
|
# @raise [Error] when the file cannot be written
|
|
27
29
|
def write(settings, out)
|
|
28
30
|
json = JSON.pretty_generate(settings)
|
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
module Laser
|
|
4
4
|
module Cutter
|
|
5
5
|
module CLI
|
|
6
|
+
# The examples command: prints worked examples of every command.
|
|
6
7
|
class Examples < Command
|
|
7
8
|
desc 'Show detailed usage examples'
|
|
8
9
|
|
|
10
|
+
# The examples it prints.
|
|
9
11
|
TEXT = <<~EXAMPLES
|
|
10
12
|
1. A box in inches, with the kerf set to 0.008", opened once it is written:
|
|
11
13
|
|
|
@@ -38,6 +40,7 @@ module Laser
|
|
|
38
40
|
laser-cutter generate -b 3x2x2/0.125 --lid back -o box.pdf
|
|
39
41
|
EXAMPLES
|
|
40
42
|
|
|
43
|
+
# @return [void]
|
|
41
44
|
def call(**)
|
|
42
45
|
out.puts TEXT
|
|
43
46
|
end
|