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.
Files changed (104) 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/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
  6. 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
  7. 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
  8. data/.plans/decisions.md +11 -0
  9. data/CHANGELOG.md +134 -0
  10. data/CLAUDE.md +18 -6
  11. data/Gemfile +2 -1
  12. data/README.md +223 -50
  13. data/Rakefile +11 -7
  14. data/docs/badges/coverage_badge.svg +2 -2
  15. data/docs/decisions/decisions-on-angled-box.md +93 -0
  16. data/docs/decisions/stack.md +6 -0
  17. data/docs/images/box-3d.avif +0 -0
  18. data/docs/images/box-sloped-3d.avif +0 -0
  19. data/docs/images/box-sloped.avif +0 -0
  20. data/justfile +24 -8
  21. data/laser-cutter.gemspec +1 -1
  22. data/lib/laser/cutter/aggregator.rb +28 -0
  23. data/lib/laser/cutter/box.rb +95 -5
  24. data/lib/laser/cutter/box_factory.rb +15 -0
  25. data/lib/laser/cutter/cli/command.rb +27 -1
  26. data/lib/laser/cutter/cli/config_file.rb +2 -0
  27. data/lib/laser/cutter/cli/examples.rb +3 -0
  28. data/lib/laser/cutter/cli/generate.rb +37 -6
  29. data/lib/laser/cutter/cli/help.rb +4 -0
  30. data/lib/laser/cutter/cli/page_sizes.rb +3 -0
  31. data/lib/laser/cutter/cli/version.rb +2 -0
  32. data/lib/laser/cutter/cli.rb +23 -4
  33. data/lib/laser/cutter/configuration.rb +38 -4
  34. data/lib/laser/cutter/geometry/dimensions.rb +7 -0
  35. data/lib/laser/cutter/geometry/line.rb +42 -0
  36. data/lib/laser/cutter/geometry/loop.rb +138 -0
  37. data/lib/laser/cutter/geometry/point.rb +3 -0
  38. data/lib/laser/cutter/geometry/rect.rb +25 -0
  39. data/lib/laser/cutter/geometry/shape.rb +19 -1
  40. data/lib/laser/cutter/geometry/transform.rb +50 -0
  41. data/lib/laser/cutter/geometry/tuple.rb +47 -11
  42. data/lib/laser/cutter/launcher.rb +14 -1
  43. data/lib/laser/cutter/missing_option.rb +2 -0
  44. data/lib/laser/cutter/notching/angled_edge.rb +67 -0
  45. data/lib/laser/cutter/notching/base.rb +8 -0
  46. data/lib/laser/cutter/notching/edge.rb +44 -4
  47. data/lib/laser/cutter/notching/infinite_iterator.rb +11 -1
  48. data/lib/laser/cutter/notching/path_generator.rb +40 -6
  49. data/lib/laser/cutter/notching/shift.rb +4 -0
  50. data/lib/laser/cutter/options.rb +25 -4
  51. data/lib/laser/cutter/page_manager.rb +12 -2
  52. data/lib/laser/cutter/renderer/base.rb +19 -3
  53. data/lib/laser/cutter/renderer/box_renderer.rb +14 -1
  54. data/lib/laser/cutter/renderer/layout_renderer.rb +10 -0
  55. data/lib/laser/cutter/renderer/line_renderer.rb +6 -0
  56. data/lib/laser/cutter/renderer/meta_renderer.rb +33 -9
  57. data/lib/laser/cutter/renderer/rect_renderer.rb +5 -0
  58. data/lib/laser/cutter/renderer/svg_renderer.rb +9 -1
  59. data/lib/laser/cutter/renderer.rb +2 -0
  60. data/lib/laser/cutter/sloped/box.rb +90 -0
  61. data/lib/laser/cutter/sloped/corners.rb +58 -0
  62. data/lib/laser/cutter/sloped/layout.rb +97 -0
  63. data/lib/laser/cutter/sloped/notcher.rb +53 -0
  64. data/lib/laser/cutter/sloped/panels.rb +121 -0
  65. data/lib/laser/cutter/sloped/placement.rb +36 -0
  66. data/lib/laser/cutter/sloped/profile.rb +176 -0
  67. data/lib/laser/cutter/sloped/request.rb +31 -0
  68. data/lib/laser/cutter/sloped/ring_panel.rb +120 -0
  69. data/lib/laser/cutter/sloped/side_panel.rb +89 -0
  70. data/lib/laser/cutter/types.rb +3 -0
  71. data/lib/laser/cutter/units_converter.rb +5 -0
  72. data/lib/laser/cutter/version.rb +2 -1
  73. data/lib/laser/cutter/zero_value_not_allowed.rb +2 -0
  74. data/lib/laser/cutter.rb +2 -0
  75. data/spec/laser/cutter/angled_edge_spec.rb +103 -0
  76. data/spec/laser/cutter/box_factory_spec.rb +19 -0
  77. data/spec/laser/cutter/cli_spec.rb +87 -7
  78. data/spec/laser/cutter/configuration_spec.rb +37 -0
  79. data/spec/laser/cutter/loop_spec.rb +107 -0
  80. data/spec/laser/cutter/options_spec.rb +51 -9
  81. data/spec/laser/cutter/renderer/layout_renderer_spec.rb +18 -0
  82. data/spec/laser/cutter/renderer/meta_renderer_spec.rb +82 -0
  83. data/spec/laser/cutter/renderer/svg_renderer_spec.rb +34 -0
  84. data/spec/laser/cutter/sloped/assembly_spec.rb +78 -0
  85. data/spec/laser/cutter/sloped/box_spec.rb +151 -0
  86. data/spec/laser/cutter/sloped/corners_spec.rb +45 -0
  87. data/spec/laser/cutter/sloped/layout_spec.rb +77 -0
  88. data/spec/laser/cutter/sloped/notcher_spec.rb +57 -0
  89. data/spec/laser/cutter/sloped/panels_spec.rb +175 -0
  90. data/spec/laser/cutter/sloped/placement_spec.rb +50 -0
  91. data/spec/laser/cutter/sloped/request_spec.rb +48 -0
  92. data/spec/laser/cutter/sloped/ring_panel_spec.rb +102 -0
  93. data/spec/laser/cutter/sloped/side_panel_spec.rb +98 -0
  94. data/spec/laser/cutter/sloped_profile_spec.rb +156 -0
  95. data/spec/laser/cutter/transform_spec.rb +53 -0
  96. data/spec/spec_helper.rb +4 -0
  97. data/spec/support/loops.rb +106 -0
  98. data/spec/support/sloped.rb +26 -0
  99. data/spec/support/solid.rb +95 -0
  100. data/spec/wishes/wish-tilted-box.png +0 -0
  101. metadata +55 -9
  102. /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
  103. /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
  104. /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
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ module Laser
6
+ module Cutter
7
+ module Sloped
8
+ RSpec.describe Layout do
9
+ subject(:layout) { described_class.new(sizes: sizes, thickness: 0.25, padding: 0.5, metadata: metadata) }
10
+
11
+ let(:metadata) { Geometry::Point[0, 0] }
12
+ let(:sizes) do
13
+ { 'left' => [5.0, 3.0], 'right' => [5.0, 3.0], 'bottom' => [4.0, 5.0], 'back' => [4.0, 3.0],
14
+ 'top' => [4.0, 3.4], 'tilted' => [4.0, 2.3], 'front' => [4.0, 1.4] }
15
+ end
16
+ let(:origins) { layout.placements.transform_values { |placement| placement.origin.to_a } }
17
+
18
+ it { is_expected.to be_frozen }
19
+
20
+ # The left wall and the bottom reach a thickness past their own size
21
+ # on each side, and the sheet starts at zero.
22
+ it 'puts the back clear of the left wall and of the bottom' do
23
+ expect(origins['back']).to eq([6.25, 6.25])
24
+ end
25
+
26
+ it 'puts a side wall either side of the back, a padding from its notches' do
27
+ expect(origins.values_at('left', 'right')).to eq([[0.25, 6.25], [11.25, 6.25]])
28
+ end
29
+
30
+ it 'draws the right wall as the mirror image of the left' do
31
+ expect(layout.placements['right'].apply(Geometry::Point[5, 0]).to_a).to eq([11.25, 6.25])
32
+ end
33
+
34
+ it 'puts the bottom under the back' do
35
+ expect(origins['bottom']).to eq([6.25, 0.25])
36
+ end
37
+
38
+ it 'stacks the top strip, the tilted panel and the front strip above the back' do
39
+ expect(origins.values_at('top', 'tilted', 'front').map { |x, y| [x, y.round(6)] })
40
+ .to eq([[6.25, 10.25], [6.25, 14.15], [6.25, 16.95]])
41
+ end
42
+
43
+ it 'turns the front strip half way round, its notched edge on top' do
44
+ expect(layout.placements['front'].apply(Geometry::Point[0, 0]).to_a.map { |c| c.round(6) }).to eq([10.25, 18.35])
45
+ end
46
+
47
+ context 'with a metadata block larger than the left wall and the bottom' do
48
+ let(:metadata) { Geometry::Point[8, 9] }
49
+
50
+ it 'moves the back clear of the block' do
51
+ expect(origins['back']).to eq([9.0, 10.0])
52
+ end
53
+ end
54
+
55
+ context 'without a top strip' do
56
+ let(:sizes) { super().except('top') }
57
+
58
+ it 'puts the tilted panel a padding above the plain top of the back' do
59
+ expect(origins['tilted']).to eq([6.25, 9.75])
60
+ end
61
+
62
+ it 'places six panels' do
63
+ expect(origins.keys).to eq(%w[left right bottom back tilted front])
64
+ end
65
+ end
66
+
67
+ context 'without a front strip' do
68
+ let(:sizes) { super().except('front') }
69
+
70
+ it 'places six panels' do
71
+ expect(origins.keys).to eq(%w[left right bottom back top tilted])
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ module Laser
6
+ module Cutter
7
+ module Sloped
8
+ RSpec.describe Notcher do
9
+ subject(:notcher) { described_class.new(notch_width: 0.6, thickness: 0.25) }
10
+
11
+ def point(x, y) = Geometry::Point[x, y]
12
+ def rounded(points) = points.map { |corner| corner.to_a.map { |c| c.round(6) + 0.0 } }
13
+
14
+ it { is_expected.to be_frozen }
15
+ its(:thickness) { is_expected.to eq(0.25) }
16
+
17
+ describe '#path' do
18
+ it 'runs from the one corner to the other' do
19
+ path = notcher.path(point(0, 0), point(3, 0), center_out: false)
20
+ expect(rounded([path.first, path.last])).to eq([[0, 0], [3, 0]])
21
+ end
22
+
23
+ it 'notches to the right of the way it runs' do
24
+ path = notcher.path(point(0, 0), point(3, 0), center_out: true)
25
+ expect(rounded(path).map(&:last).uniq.sort).to eq([-0.25, 0.0])
26
+ end
27
+
28
+ it 'notches an upward run towards larger x' do
29
+ path = notcher.path(point(0, 0), point(0, 3), center_out: true)
30
+ expect(rounded(path).map(&:first).uniq.sort).to eq([0.0, 0.25])
31
+ end
32
+
33
+ it 'takes no kerf: the first notch is as long as the rest' do
34
+ path = rounded(notcher.path(point(0, 0), point(3, 0), center_out: false))
35
+ expect(path.each_cons(2).map { |a, b| (b[0] - a[0]).abs.round(5) }.reject(&:zero?).uniq).to eq([0.42857])
36
+ end
37
+ end
38
+
39
+ describe '#tab_first?' do
40
+ # 3 / 0.6 comes to 7 notches, so the middle one is the fourth: the first is its opposite.
41
+ it 'begins with a hole when seven notches have a tab in the middle' do
42
+ expect(notcher.tab_first?(3, center_out: true)).to be(false)
43
+ end
44
+
45
+ it 'begins with a tab when seven notches have a hole in the middle' do
46
+ expect(notcher.tab_first?(3, center_out: false)).to be(true)
47
+ end
48
+
49
+ # 4 / 0.6 comes to 9 notches, so the first matches the middle one.
50
+ it 'begins with a tab when nine notches have a tab in the middle' do
51
+ expect(notcher.tab_first?(4, center_out: true)).to be(true)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,175 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ module Laser
6
+ module Cutter
7
+ module Sloped
8
+ RSpec.describe Panels do
9
+ include_context 'with a sloped box'
10
+
11
+ subject(:panels) { described_class.new(profile: profile, width: width, notcher: notcher, lid: lid) }
12
+
13
+ let(:outlines) { panels.to_h }
14
+ let(:span) { profile.tilted_span }
15
+
16
+ def tabs(name, from, to)
17
+ from, to = [from, to].map { |corner| corner.is_a?(Array) ? point(*corner) : corner }
18
+ Loops.tabs(outlines[name].lines, from: from, to: to, thickness: thickness)
19
+ end
20
+
21
+ # Each joint as the same stretch on its two panels, walked the way each outline runs.
22
+ def joints
23
+ top = profile.top_depth
24
+ tilted = profile.tilted_length
25
+ {
26
+ 'side to bottom' => [['left', [0, 0], [depth, 0]], ['bottom', [0, depth], [0, 0]]],
27
+ 'side to back' => [['left', [depth, 0], [depth, height]], ['back', [0, height], [0, 0]]],
28
+ 'side to top' => [['left', [depth, height], [depth - top, height]], ['top', [0, top], [0, 0]]],
29
+ 'side to tilted' => [['left', span.p2, span.p1], ['tilted', [0, tilted], [0, 0]]],
30
+ 'side to front' => [['left', [0, front_height], [0, 0]], ['front', [width, 0], [width, front_height]]],
31
+ 'bottom to back' => [['bottom', [width, depth], [0, depth]], ['back', [0, 0], [width, 0]]],
32
+ 'back to top' => [['back', [width, height], [0, height]], ['top', [0, 0], [width, 0]]],
33
+ 'bottom to front' => [['bottom', [0, 0], [width, 0]], ['front', [0, 0], [width, 0]]]
34
+ }
35
+ end
36
+
37
+ def interlocking
38
+ joints.select { |_name, sides| sides.all? { |panel, _from, _to| outlines.key?(panel) } }.transform_values do |ours, theirs|
39
+ from, to = ours.drop(1).map { |corner| corner.is_a?(Array) ? point(*corner) : corner }
40
+ Loops.interlock?(tabs(*ours), tabs(*theirs), Math.hypot(to.x - from.x, to.y - from.y))
41
+ end
42
+ end
43
+
44
+ shared_examples 'a box that fits together' do |joint_count|
45
+ it "interlocks at each of its #{joint_count} joints" do
46
+ expect(interlocking).to eq(interlocking.transform_values { true }).and have_attributes(size: joint_count)
47
+ end
48
+
49
+ it 'draws no outline that crosses itself' do
50
+ expect(outlines.values.map { |outline| Loops.simple?(outline.lines) }).to all(be(true))
51
+ end
52
+
53
+ it 'gives every panel a size' do
54
+ expect(panels.sizes.keys).to eq(outlines.keys)
55
+ end
56
+ end
57
+
58
+ context 'with both strips' do
59
+ it_behaves_like 'a box that fits together', 8
60
+
61
+ it 'has seven panels' do
62
+ expect(outlines.keys).to eq(Panels::NAMES)
63
+ end
64
+
65
+ it 'draws both side walls alike' do
66
+ expect(corners_of(outlines['left'])).to eq(corners_of(outlines['right']))
67
+ end
68
+
69
+ it 'sizes the strips and the tilted panel as the profile says' do
70
+ expect(panels.sizes.values_at('top', 'tilted', 'front'))
71
+ .to eq([[4.0, profile.top_strip_length], [4.0, profile.tilted_length], [4.0, profile.front_strip_length]])
72
+ end
73
+
74
+ it 'runs each strip a thickness wide over the end of the tilted panel' do
75
+ far = [profile.top_strip_length, profile.front_strip_length]
76
+ ends = %w[top front].zip(far).map { |name, y| corners_of(outlines[name]).select { |_x, cy| (cy - y).abs < 1e-6 }.map(&:first).minmax }
77
+ expect(ends).to eq([[-0.25, 4.25], [-0.25, 4.25]])
78
+ end
79
+
80
+ it 'gives each corner cube to the back or the front strip' do
81
+ expect(%w[back front].map { |name| corners_of(outlines[name]).include?([-0.25, -0.25]) }).to eq([true, true])
82
+ end
83
+
84
+ it 'keeps the bottom and the top strip out of the corners' do
85
+ expect(%w[bottom top].flat_map { |name| corners_of(outlines[name]).select { |x, y| x < 0 && y < 0 } }).to be_empty
86
+ end
87
+ end
88
+
89
+ context 'when the back and the front strip cannot carry a corner' do
90
+ let(:notch) { 0.7 }
91
+
92
+ it_behaves_like 'a box that fits together', 8
93
+
94
+ it 'gives each corner cube to the bottom or the top strip' do
95
+ carried = { 'bottom' => [[-0.25, -0.25], [-0.25, 5.25]], 'top' => [[-0.25, -0.25]] }
96
+ expect(carried.map { |name, corners| corners_of(outlines[name]).intersection(corners).size }).to eq([2, 1])
97
+ end
98
+
99
+ it 'keeps the back and the front strip out of the corners' do
100
+ expect(%w[back front].flat_map { |name| corners_of(outlines[name]).select { |x, y| x < 0 && (y < 0 || y > height) } }).to be_empty
101
+ end
102
+ end
103
+
104
+ context 'with a tilted panel that lifts off' do
105
+ let(:lid) { :plain }
106
+
107
+ it 'interlocks at the other seven joints' do
108
+ expect(interlocking.except('side to tilted').values).to all(be(true)).and have_attributes(size: 7)
109
+ end
110
+
111
+ it 'leaves the slope of the side walls plain' do
112
+ expect(tabs('left', span.p2, span.p1)).to be_empty
113
+ end
114
+
115
+ it 'draws the tilted panel as a rectangle' do
116
+ expect(outlines['tilted'].lines.size).to eq(4)
117
+ end
118
+
119
+ it 'lays the tilted panel over both side walls' do
120
+ expect(corners_of(outlines['tilted']).map(&:first).minmax).to eq([-0.25, 4.25])
121
+ end
122
+ end
123
+
124
+ context 'without a top strip' do
125
+ let(:slope) { Math.atan(2.0 / 5.0) * 180 / Math::PI }
126
+
127
+ it_behaves_like 'a box that fits together', 6
128
+
129
+ it 'has no top strip' do
130
+ expect(outlines.keys).to eq(Panels::NAMES - ['top'])
131
+ end
132
+
133
+ it 'ends the back plain at its top, between the side walls' do
134
+ expect(corners_of(outlines['back']).select { |_x, y| (y - height).abs < 1e-6 }.map(&:first).minmax).to eq([0.0, 4.0])
135
+ end
136
+ end
137
+
138
+ context 'without a front strip' do
139
+ let(:front_height) { 0 }
140
+ let(:slope) { 50 }
141
+
142
+ it_behaves_like 'a box that fits together', 6
143
+
144
+ it 'has no front strip' do
145
+ expect(outlines.keys).to eq(Panels::NAMES - ['front'])
146
+ end
147
+
148
+ it 'ends the bottom plain at its front, between the side walls' do
149
+ expect(corners_of(outlines['bottom']).select { |_x, y| y.abs < 1e-6 }.map(&:first).minmax).to eq([0.0, 4.0])
150
+ end
151
+ end
152
+
153
+ context 'with neither strip' do
154
+ let(:front_height) { 0 }
155
+ let(:slope) { Math.atan(3.0 / 5.0) * 180 / Math::PI }
156
+
157
+ it_behaves_like 'a box that fits together', 4
158
+
159
+ it 'has five panels' do
160
+ expect(outlines.keys).to eq(%w[left right bottom back tilted])
161
+ end
162
+ end
163
+
164
+ [[30, 0.5], [60, 1.5], [75, 2.0]].each do |angle, front|
165
+ context "at #{angle} degrees from a front #{front} high" do
166
+ let(:slope) { angle }
167
+ let(:front_height) { front }
168
+
169
+ it_behaves_like 'a box that fits together', 8
170
+ end
171
+ end
172
+ end
173
+ end
174
+ end
175
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ module Laser
6
+ module Cutter
7
+ module Sloped
8
+ RSpec.describe Placement do
9
+ subject(:placement) { described_class.new(Geometry::Point[10, 20], size: [4, 3], **flips) }
10
+
11
+ let(:flips) { {} }
12
+
13
+ def placed(x, y) = placement.apply(Geometry::Point[x, y]).to_a
14
+
15
+ it { is_expected.to be_frozen }
16
+
17
+ it 'moves the origin of the panel to its place' do
18
+ expect(placed(0, 0)).to eq([10, 20])
19
+ end
20
+
21
+ it 'keeps the panel the way it was drawn' do
22
+ expect(placed(1, 2)).to eq([11, 22])
23
+ end
24
+
25
+ it 'keeps its own copy of the origin' do
26
+ origin = Geometry::Point[1, 1]
27
+ placement = described_class.new(origin, size: [4, 3])
28
+ origin.x = 9
29
+ expect(placement.origin.to_a).to eq([1, 1])
30
+ end
31
+
32
+ context 'flipped in x' do
33
+ let(:flips) { { flip_x: true } }
34
+
35
+ it 'draws the mirror image within the width' do
36
+ expect([placed(0, 0), placed(4, 0), placed(1, 2)]).to eq([[14, 20], [10, 20], [13, 22]])
37
+ end
38
+ end
39
+
40
+ context 'flipped in both' do
41
+ let(:flips) { { flip_x: true, flip_y: true } }
42
+
43
+ it 'turns the panel half way round within its size' do
44
+ expect([placed(0, 0), placed(4, 3), placed(1, 2)]).to eq([[14, 23], [10, 20], [13, 21]])
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ module Laser
6
+ module Cutter
7
+ module Sloped
8
+ RSpec.describe Request do
9
+ let(:box) { { depth: 5, height: 3, thickness: 0.25 } }
10
+
11
+ def validate(**settings) = described_class.validate!(box.merge(settings))
12
+
13
+ it 'passes settings that ask for no slope' do
14
+ expect(validate(lid: 'back')).to be_nil
15
+ end
16
+
17
+ it 'returns the profile of a sloped box' do
18
+ expect(validate(slope: 45, front_height: 1)).to be_a(Profile).and have_attributes(top_depth: be_within(1e-9).of(3.0))
19
+ end
20
+
21
+ it 'takes a front height of zero' do
22
+ expect(validate(slope: 45, front_height: 0)).not_to be_front_strip
23
+ end
24
+
25
+ it 'takes the lid as a String or a Symbol' do
26
+ expect([validate(slope: 45, front_height: 1, lid: 'plain'), validate(slope: 45, front_height: 1, lid: :full)]).to all(be_a(Profile))
27
+ end
28
+
29
+ it 'raises MissingOption for a slope without a front height' do
30
+ expect { validate(slope: 45) }.to raise_error(MissingOption, /front_height is required with slope/)
31
+ end
32
+
33
+ it 'raises InvalidOption for a front height without a slope' do
34
+ expect { validate(front_height: 1) }.to raise_error(InvalidOption, /needs a slope/)
35
+ end
36
+
37
+ it 'raises InvalidOption for a lid notched into the back wall' do
38
+ expect { validate(slope: 45, front_height: 1, lid: 'back') }
39
+ .to raise_error(InvalidOption, /lid cannot be "back" with a slope, but must be one of: full, plain/)
40
+ end
41
+
42
+ it 'raises InvalidOption for numbers that do not make the shape' do
43
+ expect { validate(slope: 10, front_height: 1) }.to raise_error(InvalidOption, /needs a depth/)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ module Laser
6
+ module Cutter
7
+ module Sloped
8
+ RSpec.describe RingPanel do
9
+ include_context 'with a sloped box'
10
+
11
+ let(:length) { 3.0 }
12
+ let(:settings) { { joint: length } }
13
+
14
+ subject(:outline) { described_class.new(notcher: notcher, width: width, length: length, **settings).loop }
15
+
16
+ def tabs(from, to)
17
+ Loops.tabs(outline.lines, from: point(*from), to: point(*to), thickness: thickness).map { |run| run.map { |d| d.round(6) } }
18
+ end
19
+
20
+ context 'lying on the side walls, with both edges plain' do
21
+ let(:settings) { { joint: 0.0 } }
22
+
23
+ it 'is a rectangle a thickness wider at each end' do
24
+ expect(corners_of(outline)).to contain_exactly([-0.25, 0], [4.25, 0], [4.25, 3], [-0.25, 3])
25
+ end
26
+ end
27
+
28
+ context 'notched into the side walls end to end, with both edges plain' do
29
+ it 'keeps its plain edges between the walls' do
30
+ expect(corners_of(outline).select { |_x, y| [0.0, 3.0].include?(y) }.map(&:first).minmax).to eq([0.0, 4.0])
31
+ end
32
+
33
+ it 'has a tab in the middle of each end' do
34
+ expect(tabs([4, 0], [4, 3]).any? { |from, to| from < 1.5 && to > 1.5 }).to be(true)
35
+ end
36
+
37
+ it 'notches both ends alike' do
38
+ expect(tabs([4, 0], [4, 3])).to eq(tabs([0, 3], [0, 0]))
39
+ end
40
+
41
+ # Three tabs of 3/7 at each end, a thickness deep.
42
+ it 'covers what its tabs add to the rectangle' do
43
+ expect(outline.area).to be_within(1e-9).of((4 * 3) + (2 * 3 * (3.0 / 7) * thickness))
44
+ end
45
+ end
46
+
47
+ context 'with a notched near edge, and ends notched part of the way' do
48
+ let(:settings) { { joint: 2.0, near: false } }
49
+
50
+ # 2 / 0.6 comes to five notches of 0.4, the last of them a tab.
51
+ it 'notches each end as far as the joint' do
52
+ expect(tabs([4, 0], [4, 3]).first(2)).to eq([[0.0, 0.4], [0.8, 1.2]])
53
+ end
54
+
55
+ it 'covers the wall from there on, a thickness out, in one run with its last tab' do
56
+ expect(tabs([4, 0], [4, 3]).last).to eq([1.6, 3.0])
57
+ end
58
+
59
+ it 'ends a thickness wide at its far edge' do
60
+ expect(corners_of(outline)).to include([4.25, 3.0], [-0.25, 3.0])
61
+ end
62
+
63
+ it 'has a hole in the middle of the near edge' do
64
+ expect(tabs([0, 0], [4, 0]).none? { |from, to| from < 2 && to > 2 }).to be(true)
65
+ end
66
+
67
+ it 'does not cross itself' do
68
+ expect(Loops.simple?(outline.lines)).to be(true)
69
+ end
70
+ end
71
+
72
+ context 'carrying the corners of its near edge' do
73
+ let(:settings) { { joint: length, near: true, corners: [:near] } }
74
+
75
+ it 'reaches round both outer corners' do
76
+ expect(corners_of(outline)).to include([-0.25, -0.25], [4.25, -0.25])
77
+ end
78
+
79
+ it 'leaves the far corners alone' do
80
+ expect(corners_of(outline)).not_to include([-0.25, 3.25], [4.25, 3.25])
81
+ end
82
+
83
+ it 'does not cross itself' do
84
+ expect(Loops.simple?(outline.lines)).to be(true)
85
+ end
86
+ end
87
+
88
+ context 'carrying the corners of its far edge' do
89
+ let(:settings) { { joint: length, near: true, far: true, corners: [:far] } }
90
+
91
+ it 'reaches round both outer corners' do
92
+ expect(corners_of(outline)).to include([-0.25, 3.25], [4.25, 3.25])
93
+ end
94
+
95
+ it 'leaves the near corners alone' do
96
+ expect(corners_of(outline)).not_to include([-0.25, -0.25], [4.25, -0.25])
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ module Laser
6
+ module Cutter
7
+ module Sloped
8
+ RSpec.describe SidePanel do
9
+ include_context 'with a sloped box'
10
+
11
+ subject(:outline) { described_class.new(profile: profile, notcher: notcher, lid: lid).loop }
12
+
13
+ let(:span) { profile.tilted_span }
14
+
15
+ def tabs(from, to) = Loops.tabs(outline.lines, from: from, to: to, thickness: thickness)
16
+ def rounded(corner) = corner.to_a.map { |c| c.round(6) + 0.0 }
17
+
18
+ it 'does not cross itself' do
19
+ expect(Loops.simple?(outline.lines)).to be(true)
20
+ end
21
+
22
+ it 'has a hole in the middle of every square edge' do
23
+ edges = [[[0, 0], [5, 0]], [[5, 0], [5, 3]], [[5, 3], [2, 3]], [[0, 1], [0, 0]]]
24
+ middles = edges.map do |from, to|
25
+ half = Math.hypot(to[0] - from[0], to[1] - from[1]) / 2
26
+ tabs(point(*from), point(*to)).any? { |start, finish| start < half && finish > half }
27
+ end
28
+ expect(middles).to all(be(false))
29
+ end
30
+
31
+ it 'is notched along the slope, over the span of the tilted panel' do
32
+ expect(tabs(span.p2, span.p1)).not_to be_empty
33
+ end
34
+
35
+ # 0.25 / sin 45 is 0.353553: how far the strips run past the corners.
36
+ it 'closes the wedge under the top strip with a triangle up to the strip' do
37
+ expect(corners_of(outline)).to include([2.0, 3.0], [1.646447, 3.0], rounded(span.p2))
38
+ end
39
+
40
+ it 'closes the wedge behind the front strip with a triangle up to its top' do
41
+ expect(corners_of(outline)).to include([0.0, 1.0], [0.0, 1.353553], rounded(span.p1))
42
+ end
43
+
44
+ it 'stays within a thickness of the profile' do
45
+ xs, ys = corners_of(outline).transpose
46
+ expect([xs.minmax, ys.minmax]).to eq([[-0.25, 5.25], [-0.25, 3.25]])
47
+ end
48
+
49
+ context 'under a tilted panel that lifts off' do
50
+ let(:lid) { :plain }
51
+
52
+ it 'runs straight down the slope' do
53
+ expect(tabs(span.p2, span.p1)).to be_empty
54
+ end
55
+
56
+ it 'keeps both triangles' do
57
+ expect(corners_of(outline)).to include([1.646447, 3.0], [0.0, 1.353553])
58
+ end
59
+ end
60
+
61
+ context 'without a top strip' do
62
+ let(:slope) { Math.atan(2.0 / 5.0) * 180 / Math::PI }
63
+
64
+ it 'runs the slope from the top of the back' do
65
+ expect(rounded(span.p2)).to eq([5.0, 3.0])
66
+ end
67
+
68
+ it 'does not cross itself' do
69
+ expect(Loops.simple?(outline.lines)).to be(true)
70
+ end
71
+ end
72
+
73
+ context 'without a front strip' do
74
+ let(:front_height) { 0 }
75
+ let(:slope) { 50 }
76
+
77
+ it 'runs the slope down to the front of the bottom' do
78
+ expect(rounded(span.p1)).to eq([0.0, 0.0])
79
+ end
80
+
81
+ it 'does not cross itself' do
82
+ expect(Loops.simple?(outline.lines)).to be(true)
83
+ end
84
+ end
85
+
86
+ context 'with neither strip' do
87
+ let(:front_height) { 0 }
88
+ let(:slope) { Math.atan(3.0 / 5.0) * 180 / Math::PI }
89
+
90
+ it 'is a wedge notched on all three sides' do
91
+ sides = [[point(0, 0), point(5, 0)], [point(5, 0), point(5, 3)], [span.p2, span.p1]]
92
+ expect(sides.map { |from, to| tabs(from, to) }).to all(satisfy { |found| !found.empty? })
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end