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
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
module Laser
|
|
6
|
+
module Cutter
|
|
7
|
+
module Geometry
|
|
8
|
+
RSpec.describe Loop do
|
|
9
|
+
def loop_of(*pairs) = described_class.new(pairs.map { |x, y| Point[x, y] })
|
|
10
|
+
def corners(outline) = outline.points.map { |point| point.to_a.map { |c| c.round(9) + 0.0 } }
|
|
11
|
+
|
|
12
|
+
subject(:square) { loop_of([0, 0], [4, 0], [4, 4], [0, 4]) }
|
|
13
|
+
|
|
14
|
+
its(:area) { is_expected.to eq(16.0) }
|
|
15
|
+
it { is_expected.to be_frozen }
|
|
16
|
+
|
|
17
|
+
it 'joins its corners end to end, back to the first' do
|
|
18
|
+
expect(square.lines.map { |line| [line.p1.to_a, line.p2.to_a] })
|
|
19
|
+
.to eq([[[0, 0], [4, 0]], [[4, 0], [4, 4]], [[4, 4], [0, 4]], [[0, 4], [0, 0]]])
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'hands out copies of its corners' do
|
|
23
|
+
square.points.first.x = 9
|
|
24
|
+
expect(corners(square).first).to eq([0, 0])
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe 'what a walk leaves behind' do
|
|
28
|
+
it 'drops a point given twice' do
|
|
29
|
+
expect(corners(loop_of([0, 0], [4, 0], [4, 0], [4, 4], [0, 4], [0, 0]))).to eq(corners(square))
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'drops a point in the middle of a straight run' do
|
|
33
|
+
expect(corners(loop_of([0, 0], [1, 0], [3, 0], [4, 0], [4, 4], [0, 4]))).to eq(corners(square))
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'drops a spike, out and straight back' do
|
|
37
|
+
expect(corners(loop_of([0, 0], [4, 0], [4, 4], [4, 6], [4, 4], [0, 4]))).to eq(corners(square))
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'drops a spike that ends on the first point' do
|
|
41
|
+
expect(corners(loop_of([0, 0], [4, 0], [4, 4], [0, 4], [0, 0], [-2, 0]))).to eq(corners(square))
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it 'drops a spike that turns back only part of the way' do
|
|
45
|
+
expect(corners(loop_of([0, 0], [6, 0], [4, 0], [4, 4], [0, 4]))).to eq(corners(square))
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it 'keeps a corner a point away from the noise of a float' do
|
|
49
|
+
expect(corners(loop_of([0, 0], [4, 0], [4 + 1e-13, 1e-13], [4, 4], [0, 4])).size).to eq(4)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'refuses a walk that encloses nothing' do
|
|
53
|
+
expect { loop_of([0, 0], [1, 0], [2, 0]) }.to raise_error(ArgumentError, /on one line/)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it 'refuses fewer than three corners' do
|
|
57
|
+
expect { loop_of([0, 0], [1, 0]) }.to raise_error(ArgumentError, /three corners/)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
describe '#grow' do
|
|
62
|
+
it 'moves every side of a square out' do
|
|
63
|
+
expect(corners(square.grow(0.5))).to eq([[-0.5, -0.5], [4.5, -0.5], [4.5, 4.5], [-0.5, 4.5]])
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it 'grows a clockwise outline outwards too' do
|
|
67
|
+
expect(described_class.new(square.points.reverse).grow(0.5).area).to eq(25.0)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it 'moves an inside corner out with the sides that meet there' do
|
|
71
|
+
ell = loop_of([0, 0], [4, 0], [4, 2], [2, 2], [2, 4], [0, 4])
|
|
72
|
+
expect(corners(ell.grow(0.25))).to eq([[-0.25, -0.25], [4.25, -0.25], [4.25, 2.25], [2.25, 2.25], [2.25, 4.25], [-0.25, 4.25]])
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it 'keeps a corner that is not square sharp, each side the distance out' do
|
|
76
|
+
grown = loop_of([0, 0], [4, 0], [4, 3]).grow(0.1)
|
|
77
|
+
expect(corners(grown).map { |x, y| [x.round(6), y.round(6)] }).to eq([[-0.3, -0.1], [4.1, -0.1], [4.1, 3.2]])
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it 'shrinks by a negative distance' do
|
|
81
|
+
expect(square.grow(-1).area).to eq(4.0)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it 'returns itself for no distance' do
|
|
85
|
+
expect(square.grow(0)).to be(square)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# The box with six panels widens its tabs and narrows its holes by
|
|
89
|
+
# the kerf, edge by edge. Growing the outline it cuts without kerf
|
|
90
|
+
# by half the kerf must come to the same lines.
|
|
91
|
+
it 'grows a panel by half the kerf to what Box draws with that kerf' do
|
|
92
|
+
settings = { width: 70, height: 20, depth: 50, thickness: 4.3, notch: 10, units: 'mm', file: 'box.pdf' }
|
|
93
|
+
plain, cut = [0.0, 0.3].map { |kerf| Box.new(Configuration.new(settings.merge(kerf: kerf))).tap(&:generate_notches) }
|
|
94
|
+
grown = plain.outlines.transform_values { |lines| Loops.rounded(Loops.chain(lines).grow(0.15).lines) }
|
|
95
|
+
expect(grown).to eq(cut.outlines.transform_values { |lines| Loops.rounded(lines) })
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
describe '#map' do
|
|
100
|
+
it 'moves every corner' do
|
|
101
|
+
expect(corners(square.map { |point| point.plus(1, 2) })).to eq([[1, 2], [5, 2], [5, 6], [1, 6]])
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
@@ -59,6 +59,34 @@ module Laser
|
|
|
59
59
|
its(:page_layout) { is_expected.to eq('landscape') }
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
+
describe 'with a slope' do
|
|
63
|
+
let(:settings) { dimensions.merge('slope' => '45', 'front_height' => '10') }
|
|
64
|
+
|
|
65
|
+
its(:slope) { is_expected.to eql(45.0) }
|
|
66
|
+
its(:front_height) { is_expected.to eql(10.0) }
|
|
67
|
+
|
|
68
|
+
it 'carries both into the configuration' do
|
|
69
|
+
expect(options.to_configuration).to include(slope: 45.0, front_height: 10.0)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it 'takes a front height of zero' do
|
|
73
|
+
expect(described_class.new(dimensions.merge(slope: 60, front_height: 0)).front_height).to eql(0.0)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it 'takes a lid that lifts off' do
|
|
77
|
+
expect(described_class.new(settings.merge(lid: :plain)).lid).to eq('plain')
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
describe 'without a slope' do
|
|
82
|
+
its(:slope) { is_expected.to be_nil }
|
|
83
|
+
its(:front_height) { is_expected.to be_nil }
|
|
84
|
+
|
|
85
|
+
it 'reads blank Strings from a form as no slope' do
|
|
86
|
+
expect(described_class.new(dimensions.merge('slope' => '', 'front_height' => '')).slope).to be_nil
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
62
90
|
describe 'given an Options' do
|
|
63
91
|
it 'returns it' do
|
|
64
92
|
expect(described_class.new(options)).to be(options)
|
|
@@ -74,15 +102,20 @@ module Laser
|
|
|
74
102
|
|
|
75
103
|
describe 'what it refuses' do
|
|
76
104
|
{
|
|
77
|
-
{ lid: 'sliding' }
|
|
78
|
-
{ units: 'cm' }
|
|
79
|
-
{ format: 'dxf' }
|
|
80
|
-
{ page_layout: 'sideways' }
|
|
81
|
-
{ page_size: 'A99' }
|
|
82
|
-
{ width: 'wide' }
|
|
83
|
-
{ depth: 0 }
|
|
84
|
-
{ kerf: -0.1 }
|
|
85
|
-
{ metadata: 'maybe' }
|
|
105
|
+
{ lid: 'sliding' } => 'lid cannot be "sliding", but must be one of: full, back, plain.',
|
|
106
|
+
{ units: 'cm' } => 'units cannot be "cm", but must be one of: in, mm.',
|
|
107
|
+
{ format: 'dxf' } => 'format cannot be "dxf", but must be one of: pdf, svg.',
|
|
108
|
+
{ page_layout: 'sideways' } => 'page_layout cannot be "sideways", but must be one of: portrait, landscape.',
|
|
109
|
+
{ page_size: 'A99' } => 'page_size cannot be "A99".',
|
|
110
|
+
{ width: 'wide' } => 'width cannot be "wide".',
|
|
111
|
+
{ depth: 0 } => 'depth cannot be 0.',
|
|
112
|
+
{ kerf: -0.1 } => 'kerf cannot be -0.1.',
|
|
113
|
+
{ metadata: 'maybe' } => 'metadata cannot be "maybe".',
|
|
114
|
+
{ slope: 90, front_height: 10 } => 'slope cannot be 90.',
|
|
115
|
+
{ slope: 0, front_height: 10 } => 'slope cannot be 0.',
|
|
116
|
+
{ front_height: -1, slope: 45 } => 'front_height cannot be -1.',
|
|
117
|
+
{ front_height: 10 } => 'front_height is the front of a sloped box, so it needs a slope.',
|
|
118
|
+
{ lid: 'back', slope: 45, front_height: 10 } => 'lid cannot be "back" with a slope, but must be one of: full, plain.'
|
|
86
119
|
}.each do |bad, message|
|
|
87
120
|
it "raises InvalidOption when #{bad.keys.first} is #{bad.values.first.inspect}" do
|
|
88
121
|
expect { described_class.new(dimensions.merge(bad)) }.to raise_error(InvalidOption, message)
|
|
@@ -98,6 +131,15 @@ module Laser
|
|
|
98
131
|
.to raise_error(MissingOption, 'height, depth, thickness are required, but missing.')
|
|
99
132
|
end
|
|
100
133
|
|
|
134
|
+
it 'raises MissingOption for a slope without a front height' do
|
|
135
|
+
expect { described_class.new(dimensions.merge(slope: 45)) }
|
|
136
|
+
.to raise_error(MissingOption, 'front_height is required with slope, but missing.')
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
it 'raises InvalidOption for a slope the depth cannot take' do
|
|
140
|
+
expect { described_class.new(dimensions.merge(slope: 10, front_height: 10)) }.to raise_error(InvalidOption, /needs a depth of/)
|
|
141
|
+
end
|
|
142
|
+
|
|
101
143
|
it 'raises MissingOption naming the one dimension left out' do
|
|
102
144
|
expect { described_class.new(dimensions.except(:width)) }.to raise_error(MissingOption, 'width is required, but missing.')
|
|
103
145
|
end
|
|
@@ -20,6 +20,24 @@ module Laser
|
|
|
20
20
|
expect(File.binread(filename)).to start_with('%PDF')
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
+
context 'with a slope' do
|
|
24
|
+
let(:config) do
|
|
25
|
+
Laser::Cutter::Configuration.new('box' => '4x3x5/0.25/0.6', 'slope' => '45', 'front_height' => '1', 'file' => file)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'is able to generate a PDF file' do
|
|
29
|
+
render_file file
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'draws the seven panels of a sloped box' do
|
|
33
|
+
expect(renderer.total).to eq(Laser::Cutter::Sloped::Box.new(config).notches.size)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'draws them twice with the outline without kerf' do
|
|
37
|
+
expect(LayoutRenderer.new(Laser::Cutter::Configuration.new(config.to_hash.merge(debug: true))).total).to eq(2 * renderer.total)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
23
41
|
context 'metric' do
|
|
24
42
|
let(:config) {
|
|
25
43
|
Laser::Cutter::Configuration.new(
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
module Laser
|
|
6
|
+
module Cutter
|
|
7
|
+
module Renderer
|
|
8
|
+
RSpec.describe MetaRenderer do
|
|
9
|
+
subject(:renderer) { described_class.new(Configuration.new(settings)) }
|
|
10
|
+
|
|
11
|
+
let(:settings) { { box: '4x3x5/0.125', file: 'box.pdf' } }
|
|
12
|
+
|
|
13
|
+
def pages(settings) = LayoutRenderer.new(Configuration.new(settings)).document.scan(%r{/Type /Page\b}).size
|
|
14
|
+
|
|
15
|
+
it 'prints the settings of the box, in order' do
|
|
16
|
+
expect(renderer.fields.keys).to eq(%i[units width height depth thickness notch lid kerf stroke padding margin page_size])
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'calls a page fitted to the box custom, and leaves its layout out' do
|
|
20
|
+
expect(renderer.fields.slice(:page_size, :page_layout)).to eq(page_size: 'custom')
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'is as tall as its banner and one line for each setting' do
|
|
24
|
+
expect(renderer.enclosure.h).to be_within(1e-9).of(55 + (12 * 8.2) + 4)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'fits on the page of the box' do
|
|
28
|
+
expect(pages(settings)).to eq(1)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Zero is a setting like any other: no kerf, or a slope that starts at the bottom.
|
|
32
|
+
context 'with a setting of zero' do
|
|
33
|
+
let(:settings) { super().merge(kerf: 0, slope: 50, front_height: 0) }
|
|
34
|
+
|
|
35
|
+
it 'prints the kerf and the front height' do
|
|
36
|
+
expect(renderer.fields).to include(kerf: 0, front_height: 0, slope: 50)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'keeps the order of the settings' do
|
|
40
|
+
expect(renderer.fields.keys.first(6)).to eq(%i[units width height depth front_height slope])
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'is as tall as the lines it prints' do
|
|
44
|
+
expect(renderer.enclosure.h).to be_within(1e-9).of(55 + (14 * 8.2) + 4)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'fits on the page of the box' do
|
|
48
|
+
expect(pages(settings)).to eq(1)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
context 'with a page size' do
|
|
53
|
+
let(:settings) { super().merge(page_size: 'A3', page_layout: 'landscape') }
|
|
54
|
+
|
|
55
|
+
it 'prints the size and the layout' do
|
|
56
|
+
expect(renderer.fields).to include(page_size: 'A3', page_layout: 'landscape')
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it 'fits on the page' do
|
|
60
|
+
expect(pages(settings)).to eq(1)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
context 'with a sloped box' do
|
|
65
|
+
let(:settings) { super().merge(slope: 45, front_height: 1) }
|
|
66
|
+
|
|
67
|
+
it 'prints the front height and the slope after the depth' do
|
|
68
|
+
expect(renderer.fields.keys[3, 3]).to eq(%i[depth front_height slope])
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it 'grows by two lines' do
|
|
72
|
+
expect(renderer.enclosure.h).to be_within(1e-9).of(55 + (14 * 8.2) + 4)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it 'fits on the page of the box' do
|
|
76
|
+
expect(pages(settings)).to eq(1)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
@@ -48,4 +48,38 @@ RSpec.describe Laser::Cutter::Renderer::SvgRenderer do
|
|
|
48
48
|
expect(svg).not_to include('<desc>')
|
|
49
49
|
end
|
|
50
50
|
end
|
|
51
|
+
|
|
52
|
+
context 'with a slope' do
|
|
53
|
+
let(:settings) { { box: '4x3x5/0.25/0.6', slope: 45, front_height: 1, file: file } }
|
|
54
|
+
|
|
55
|
+
before { renderer.render }
|
|
56
|
+
|
|
57
|
+
it 'draws the seven panels of a sloped box' do
|
|
58
|
+
expect(svg.scan('<line').size).to eq(renderer.total).and eq(Laser::Cutter::Sloped::Box.new(config).notches.size)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it 'draws lines along the slope' do
|
|
62
|
+
skewed = svg.scan(/x1="([\d.-]+)" y1="([\d.-]+)" x2="([\d.-]+)" y2="([\d.-]+)"/).map { |found| found.map(&:to_f) }
|
|
63
|
+
.reject { |x1, y1, x2, y2| (x1 - x2).abs < 1e-4 || (y1 - y2).abs < 1e-4 }
|
|
64
|
+
expect(skewed.map { |x1, y1, x2, y2| ((y2 - y1) / (x2 - x1)).abs.round(3) }.uniq).to eq([1.0])
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it 'keeps every line on the page' do
|
|
68
|
+
width, height = svg.match(/viewBox="0 0 ([\d.]+) ([\d.]+)"/).captures.map(&:to_f)
|
|
69
|
+
xs, ys = svg.scan(/[xy][12]="([\d.-]+)"/).flatten.map(&:to_f).each_slice(2).to_a.transpose
|
|
70
|
+
expect([xs.min, ys.min, width - xs.max, height - ys.max]).to all(be_within(0.002).of(0.125))
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
context 'when it starts at the bottom' do
|
|
74
|
+
let(:settings) { super().merge(slope: 50, front_height: 0, kerf: 0) }
|
|
75
|
+
|
|
76
|
+
it 'describes a front height of zero, and no kerf' do
|
|
77
|
+
expect(svg).to match(/<desc>.*front_height: 0, slope: 50,.*kerf: 0,/m)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it 'describes the slope' do
|
|
82
|
+
expect(svg).to match(/<desc>.*depth: 5\.0, front_height: 1, slope: 45, thickness/m)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
51
85
|
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
module Laser
|
|
6
|
+
module Cutter
|
|
7
|
+
module Sloped
|
|
8
|
+
# The panels, stood up in space the way they are glued. Two panels that
|
|
9
|
+
# both claim a point of material cannot be put together, and that is
|
|
10
|
+
# what catches a corner cube given to two panels, or a strip that runs
|
|
11
|
+
# into the tilted panel.
|
|
12
|
+
RSpec.describe 'the sloped box, put together' do
|
|
13
|
+
include_context 'with a sloped box'
|
|
14
|
+
|
|
15
|
+
let(:panels) { Panels.new(profile: profile, width: width, notcher: notcher, lid: lid) }
|
|
16
|
+
let(:solid) { Solid.new(profile: profile, width: width, outlines: panels.to_h) }
|
|
17
|
+
|
|
18
|
+
shared_examples 'panels that fit' do
|
|
19
|
+
it 'has no material that two panels both claim' do
|
|
20
|
+
expect(solid.collisions).to be_empty
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it_behaves_like 'panels that fit'
|
|
25
|
+
|
|
26
|
+
it 'finds the panel a point of material belongs to' do
|
|
27
|
+
owners = [[-0.1, 2.5, 1.0], [2.0, 2.5, -0.1], [2.0, 5.1, 1.5], [2.0, 4.0, 3.1], [2.0, 1.0, 2.1], [2.0, -0.1, 0.5]]
|
|
28
|
+
expect(owners.map { |point| solid.owners_of(*point) }).to eq([['left'], ['bottom'], ['back'], ['top'], ['tilted'], ['front']])
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# The back is taller than the front strip, so in its place it runs into the side walls.
|
|
32
|
+
it 'would catch a panel standing where another already is' do
|
|
33
|
+
doubled = Solid.new(profile: profile, width: width, outlines: panels.to_h.merge('front' => panels.to_h['back']))
|
|
34
|
+
expect(doubled.collisions.keys).to include('front+left', 'front+right')
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
context 'when the bottom and the top strip carry the corners' do
|
|
38
|
+
let(:notch) { 0.7 }
|
|
39
|
+
|
|
40
|
+
it_behaves_like 'panels that fit'
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
context 'with a tilted panel that lifts off' do
|
|
44
|
+
let(:lid) { :plain }
|
|
45
|
+
|
|
46
|
+
it_behaves_like 'panels that fit'
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
context 'at 60 degrees from a front half as high as the back' do
|
|
50
|
+
let(:slope) { 60 }
|
|
51
|
+
let(:front_height) { 1.5 }
|
|
52
|
+
|
|
53
|
+
it_behaves_like 'panels that fit'
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
context 'without a front strip' do
|
|
57
|
+
let(:front_height) { 0 }
|
|
58
|
+
let(:slope) { 50 }
|
|
59
|
+
|
|
60
|
+
it_behaves_like 'panels that fit'
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
context 'without a top strip' do
|
|
64
|
+
let(:slope) { Math.atan(2.0 / 5.0) * 180 / Math::PI }
|
|
65
|
+
|
|
66
|
+
it_behaves_like 'panels that fit'
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
context 'with neither strip' do
|
|
70
|
+
let(:front_height) { 0 }
|
|
71
|
+
let(:slope) { Math.atan(3.0 / 5.0) * 180 / Math::PI }
|
|
72
|
+
|
|
73
|
+
it_behaves_like 'panels that fit'
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
module Laser
|
|
6
|
+
module Cutter
|
|
7
|
+
module Sloped
|
|
8
|
+
RSpec.describe Box do
|
|
9
|
+
subject(:box) { described_class.new(Configuration.new(settings)) }
|
|
10
|
+
|
|
11
|
+
let(:padding) { 0.2 }
|
|
12
|
+
let(:kerf) { 0.0 }
|
|
13
|
+
let(:overrides) { {} }
|
|
14
|
+
let(:settings) do
|
|
15
|
+
{ width: 4, height: 3, depth: 5, front_height: 1, slope: 45, thickness: 0.25, notch: 0.6,
|
|
16
|
+
kerf: kerf, padding: padding, units: 'in', file: 'box.pdf' }.merge(overrides)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# @return [Array(Float, Float, Float, Float)] the least and most x, then y, of a panel
|
|
20
|
+
def bounds(name)
|
|
21
|
+
points = box.outlines.fetch(name).flat_map { |line| [line.p1, line.p2] }
|
|
22
|
+
[*points.map(&:x).minmax, *points.map(&:y).minmax].map { |c| c.round(6) }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'answers what the renderers ask of a box' do
|
|
26
|
+
expect(box).to respond_to(:generate_notches, :notches, :outlines, :enclosure, :metadata=)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it 'draws seven panels' do
|
|
30
|
+
expect(box.outlines.keys).to eq(%w[left right bottom back top tilted front])
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'returns every line of every panel' do
|
|
34
|
+
expect(box.generate_notches.size).to eq(box.outlines.values.sum(&:size)).and eq(box.notches.size)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'closes every outline' do
|
|
38
|
+
expect(box.outlines.values.map { |lines| Outline.closed?(lines) }).to all(be(true))
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Across: a side wall 5.5, the column 4.5, a side wall 5.5, and two paddings.
|
|
42
|
+
# Up: the bottom 5.5, the back 3.5, the strips and the tilted panel, and four paddings.
|
|
43
|
+
it 'encloses every line, from the corner of the sheet' do
|
|
44
|
+
expect(box.enclosure.to_a.flatten.map { |c| c.round(6) }).to eq([0.0, 0.0, 15.9, 17.335534])
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
describe 'the sheet' do
|
|
48
|
+
it 'unfolds the panels around the back, a padding apart' do
|
|
49
|
+
gaps = [bounds('back')[2] - bounds('bottom')[3], bounds('top')[2] - bounds('back')[3],
|
|
50
|
+
bounds('tilted')[2] - bounds('top')[3], bounds('front')[2] - bounds('tilted')[3],
|
|
51
|
+
bounds('back')[0] - bounds('left')[1], bounds('right')[0] - bounds('back')[1]]
|
|
52
|
+
expect(gaps.map { |gap| gap.round(6) }).to all(eq(padding))
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it 'lines the column up between the side walls' do
|
|
56
|
+
expect(%w[bottom back top tilted front].map { |name| bounds(name).first(2) }.uniq).to eq([[5.7, 10.2]])
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it 'draws the right wall as the mirror image of the left' do
|
|
60
|
+
axis = (bounds('left')[0] + bounds('right')[1]) / 2
|
|
61
|
+
mirrored = box.outlines['left'].map do |line|
|
|
62
|
+
Geometry::Line.new(Geometry::Point[(2 * axis) - line.p1.x, line.p1.y], Geometry::Point[(2 * axis) - line.p2.x, line.p2.y])
|
|
63
|
+
end
|
|
64
|
+
expect(Loops.rounded(mirrored)).to eq(Loops.rounded(box.outlines['right']))
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it 'turns the front strip so its plain edge faces the tilted panel' do
|
|
68
|
+
lowest = box.outlines['front'].select { |line| [line.p1.y, line.p2.y].all? { |y| (y - bounds('front')[2]).abs < 1e-6 } }
|
|
69
|
+
expect(lowest.map(&:length).map { |length| length.round(6) }).to eq([4.5])
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
describe 'room for the metadata' do
|
|
74
|
+
before { box.metadata = Geometry::Point[9, 8] }
|
|
75
|
+
|
|
76
|
+
it 'moves the bottom to the right of the block and the left wall above it' do
|
|
77
|
+
expect([bounds('bottom')[0], bounds('left')[2]]).to eq([9.45, 8.45])
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it 'draws afresh once the block is known' do
|
|
81
|
+
before = box.enclosure
|
|
82
|
+
box.metadata = Geometry::Point[20, 20]
|
|
83
|
+
expect(box.enclosure.p2.x).to be > before.p2.x
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
describe 'kerf' do
|
|
88
|
+
let(:kerf) { 0.02 }
|
|
89
|
+
let(:plain) { described_class.new(Configuration.new(settings.merge(kerf: 0.0))) }
|
|
90
|
+
|
|
91
|
+
it 'grows the sheet by half the kerf on every side' do
|
|
92
|
+
expect(box.enclosure.to_a.flatten.zip(plain.enclosure.to_a.flatten).map { |cut, drawn| (cut - drawn).round(6) })
|
|
93
|
+
.to eq([-0.01, -0.01, 0.01, 0.01])
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it 'keeps every line, each one moved out and none turned' do
|
|
97
|
+
turned = box.outlines['left'].zip(plain.outlines['left']).reject do |cut, drawn|
|
|
98
|
+
((cut.p2.x - cut.p1.x) * (drawn.p2.y - drawn.p1.y)) - ((cut.p2.y - cut.p1.y) * (drawn.p2.x - drawn.p1.x)) < 1e-9
|
|
99
|
+
end
|
|
100
|
+
expect([box.outlines['left'].size, turned]).to eq([plain.outlines['left'].size, []])
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it 'moves the slope of a side wall out by half the kerf, square to the slope' do
|
|
104
|
+
longest = ->(lines) { lines.reject { |l| (l.p1.x - l.p2.x).abs < 1e-6 || (l.p1.y - l.p2.y).abs < 1e-6 }.max_by(&:length) }
|
|
105
|
+
cut = longest.call(box.outlines['left'])
|
|
106
|
+
drawn = longest.call(plain.outlines['left'])
|
|
107
|
+
offset = ((cut.p1.x - drawn.p1.x) * -Math.sin(Math::PI / 4)) + ((cut.p1.y - drawn.p1.y) * Math.cos(Math::PI / 4))
|
|
108
|
+
expect(offset.abs).to be_within(1e-9).of(0.01)
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
describe 'the lid' do
|
|
113
|
+
let(:overrides) { { lid: 'plain' } }
|
|
114
|
+
|
|
115
|
+
it 'draws the tilted panel as a rectangle that lies on the side walls' do
|
|
116
|
+
expect([box.outlines['tilted'].size, bounds('tilted').first(2)]).to eq([4, [5.7, 10.2]])
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
describe 'the defaults' do
|
|
121
|
+
subject(:box) { described_class.new({ width: 4, height: 3, depth: 5, front_height: 1, slope: 45, thickness: 0.25 }) }
|
|
122
|
+
|
|
123
|
+
it 'draws without kerf, padding, notch or lid, from a plain Hash' do
|
|
124
|
+
expect(box.outlines.keys.size).to eq(7)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
it 'takes a notch three times the thickness' do
|
|
128
|
+
expect(box.outlines['tilted'].size).to eq(described_class.new({ width: 4, height: 3, depth: 5, front_height: 1, slope: 45,
|
|
129
|
+
thickness: 0.25, notch: 0.75 }).outlines['tilted'].size)
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
context 'without strips' do
|
|
134
|
+
let(:overrides) { { front_height: 0, slope: Math.atan(3.0 / 5.0) * 180 / Math::PI } }
|
|
135
|
+
|
|
136
|
+
it 'draws five panels' do
|
|
137
|
+
expect(box.outlines.keys).to eq(%w[left right bottom back tilted])
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
it 'refuses numbers that do not make the shape' do
|
|
142
|
+
expect { described_class.new(Configuration.new(settings.merge(slope: 10))) }.to raise_error(InvalidOption, /needs a depth/)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
it 'exposes the profile it draws' do
|
|
146
|
+
expect(box.profile.top_depth).to be_within(1e-9).of(3.0)
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
module Laser
|
|
6
|
+
module Cutter
|
|
7
|
+
module Sloped
|
|
8
|
+
RSpec.describe Corners do
|
|
9
|
+
include_context 'with a sloped box'
|
|
10
|
+
|
|
11
|
+
subject(:corners) { described_class.new(profile: profile, width: width, notcher: notcher) }
|
|
12
|
+
|
|
13
|
+
# A notch of 0.6 gives the width 9 notches, which begin with a tab.
|
|
14
|
+
context 'when the back and the front strip begin with a tab along the width' do
|
|
15
|
+
its(:front_bottom) { is_expected.to eq(:front) }
|
|
16
|
+
its(:bottom_back) { is_expected.to eq(:back) }
|
|
17
|
+
its(:back_top) { is_expected.to eq(:back) }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# A notch of 0.7 gives the width and the height 7 notches and the
|
|
21
|
+
# front 3, and a tab in the middle of those begins with a hole.
|
|
22
|
+
context 'when they begin with a hole on both edges at the corner' do
|
|
23
|
+
let(:notch) { 0.7 }
|
|
24
|
+
|
|
25
|
+
its(:front_bottom) { is_expected.to eq(:bottom) }
|
|
26
|
+
its(:bottom_back) { is_expected.to eq(:bottom) }
|
|
27
|
+
its(:back_top) { is_expected.to eq(:top) }
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
context 'without a front strip' do
|
|
31
|
+
let(:front_height) { 0 }
|
|
32
|
+
|
|
33
|
+
its(:front_bottom) { is_expected.to be_nil }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context 'without a top strip' do
|
|
37
|
+
let(:slope) { Math.atan(2.0 / 5.0) * 180 / Math::PI }
|
|
38
|
+
|
|
39
|
+
its(:back_top) { is_expected.to be_nil }
|
|
40
|
+
its(:bottom_back) { is_expected.to eq(:back) }
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|