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
|
@@ -3,28 +3,49 @@
|
|
|
3
3
|
module Laser
|
|
4
4
|
module Cutter
|
|
5
5
|
module Geometry
|
|
6
|
+
# An axis-aligned rectangle, given by two opposite corners: p1, the
|
|
7
|
+
# lesser, and p2. It keeps its four vertices and sides up to date.
|
|
6
8
|
class Rect < Line
|
|
9
|
+
# @!attribute [rw] sides
|
|
10
|
+
# @return [Array<Line>] the four sides, counter-clockwise from p1
|
|
11
|
+
# @!attribute [rw] vertices
|
|
12
|
+
# @return [Array<Point>] the four corners, counter-clockwise from p1
|
|
7
13
|
attr_accessor :sides, :vertices
|
|
8
14
|
|
|
15
|
+
# @param p1 [Point] one corner
|
|
16
|
+
# @param p2 [Point] the opposite corner
|
|
17
|
+
# @return [Rect]
|
|
9
18
|
def self.[](p1, p2)
|
|
10
19
|
Rect.new(p1, p2)
|
|
11
20
|
end
|
|
12
21
|
|
|
22
|
+
# @param point [Point] the corner with the least x and y
|
|
23
|
+
# @param w [Float] the width
|
|
24
|
+
# @param h [Float] the height
|
|
25
|
+
# @param name [String, Symbol, nil]
|
|
26
|
+
# @return [Rect]
|
|
13
27
|
def self.create(point, w, h, name = nil)
|
|
14
28
|
r = Rect.new(point, Point[point.x + w, point.y + h])
|
|
15
29
|
r.name = name
|
|
16
30
|
r
|
|
17
31
|
end
|
|
18
32
|
|
|
33
|
+
# @param line [Line] its ends become opposite corners
|
|
34
|
+
# @return [Rect]
|
|
19
35
|
def self.from_line(line)
|
|
20
36
|
Rect.new(line.p1, line.p2)
|
|
21
37
|
end
|
|
22
38
|
|
|
39
|
+
# Takes whatever {Line#initialize} takes.
|
|
23
40
|
def initialize(*)
|
|
24
41
|
super
|
|
25
42
|
relocate!
|
|
26
43
|
end
|
|
27
44
|
|
|
45
|
+
# Moves the rectangle to its position and rebuilds its vertices and
|
|
46
|
+
# sides.
|
|
47
|
+
#
|
|
48
|
+
# @return [Rect] self
|
|
28
49
|
def relocate!
|
|
29
50
|
super
|
|
30
51
|
self.vertices = []
|
|
@@ -39,18 +60,22 @@ module Laser
|
|
|
39
60
|
self
|
|
40
61
|
end
|
|
41
62
|
|
|
63
|
+
# @return [Float] the width
|
|
42
64
|
def w
|
|
43
65
|
p2.x - p1.x
|
|
44
66
|
end
|
|
45
67
|
|
|
68
|
+
# @return [Float] the height
|
|
46
69
|
def h
|
|
47
70
|
p2.y - p1.y
|
|
48
71
|
end
|
|
49
72
|
|
|
73
|
+
# @return [String] the size and the position
|
|
50
74
|
def to_s
|
|
51
75
|
"#{sprintf '%3d', w}(w)x#{sprintf '%3d', h}(h) @ #{position}"
|
|
52
76
|
end
|
|
53
77
|
|
|
78
|
+
# @return [Array<Array<Float>>] both corners, as [[x1, y1], [x2, y2]]
|
|
54
79
|
def to_a
|
|
55
80
|
[[p1.x, p1.y], [p2.x, p2.y]]
|
|
56
81
|
end
|
|
@@ -3,36 +3,54 @@
|
|
|
3
3
|
module Laser
|
|
4
4
|
module Cutter
|
|
5
5
|
module Geometry
|
|
6
|
+
# The base of a shape that sits at a position and can be moved there.
|
|
6
7
|
class Shape
|
|
8
|
+
# @!attribute [rw] name
|
|
9
|
+
# @return [String, Symbol, nil] the name of the shape, such as the face of a box
|
|
7
10
|
attr_accessor :position, :name
|
|
8
11
|
|
|
12
|
+
# @return [Point] where the shape sits, the origin until set
|
|
9
13
|
def position
|
|
10
14
|
@position ||= Point.new(0, 0)
|
|
11
15
|
end
|
|
12
16
|
|
|
17
|
+
# @param value [Float] the new x of the position
|
|
18
|
+
# @return [Float] the value
|
|
13
19
|
def x=(value)
|
|
14
20
|
position.x = value
|
|
15
21
|
end
|
|
16
22
|
|
|
23
|
+
# @return [Float] the x of the position
|
|
17
24
|
def x
|
|
18
25
|
position.x
|
|
19
26
|
end
|
|
20
27
|
|
|
28
|
+
# @param value [Float] the new y of the position
|
|
29
|
+
# @return [Float] the value
|
|
21
30
|
def y=(value)
|
|
22
31
|
position.y = value
|
|
23
32
|
end
|
|
24
33
|
|
|
34
|
+
# @return [Float] the y of the position
|
|
25
35
|
def y
|
|
26
36
|
position.y
|
|
27
37
|
end
|
|
28
38
|
|
|
39
|
+
# Moves the shape so that its position is the point.
|
|
40
|
+
#
|
|
41
|
+
# @param new_point [Point]
|
|
42
|
+
# @return [Shape] self
|
|
29
43
|
def move_to(new_point)
|
|
30
44
|
self.position = new_point
|
|
31
45
|
relocate!
|
|
32
46
|
self
|
|
33
47
|
end
|
|
34
48
|
|
|
35
|
-
#
|
|
49
|
+
# Moves the shape's own coordinates to its position. Each shape
|
|
50
|
+
# implements it.
|
|
51
|
+
#
|
|
52
|
+
# @return [void]
|
|
53
|
+
# @raise [RuntimeError] when the shape does not implement it
|
|
36
54
|
def relocate!
|
|
37
55
|
raise 'Abstract method'
|
|
38
56
|
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Laser
|
|
4
|
+
module Cutter
|
|
5
|
+
module Geometry
|
|
6
|
+
# A rotation followed by a move, from a local frame into the page.
|
|
7
|
+
#
|
|
8
|
+
# Notches are drawn along the x axis of a local frame, where every side
|
|
9
|
+
# is horizontal and the axis-aligned notching code applies unchanged.
|
|
10
|
+
# A Transform then turns and moves the result onto a side at any angle.
|
|
11
|
+
class Transform
|
|
12
|
+
# @return [Point] where the local origin lands
|
|
13
|
+
attr_reader :origin
|
|
14
|
+
|
|
15
|
+
# @return [Float] the turn, in radians, counter-clockwise
|
|
16
|
+
attr_reader :angle
|
|
17
|
+
|
|
18
|
+
# The frame whose x axis runs from one point towards another, with
|
|
19
|
+
# its origin on the first. Its y axis points to the left of that run.
|
|
20
|
+
#
|
|
21
|
+
# @param from [Point]
|
|
22
|
+
# @param to [Point]
|
|
23
|
+
# @return [Transform]
|
|
24
|
+
def self.along(from, to)
|
|
25
|
+
new(from, Math.atan2(to.y - from.y, to.x - from.x))
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# @param origin [Point]
|
|
29
|
+
# @param angle [Numeric] radians, counter-clockwise
|
|
30
|
+
def initialize(origin, angle)
|
|
31
|
+
@origin = origin.clone.freeze
|
|
32
|
+
@angle = angle.to_f
|
|
33
|
+
@cos = Math.cos(@angle)
|
|
34
|
+
@sin = Math.sin(@angle)
|
|
35
|
+
freeze
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# @param shape [Point, Line] in the local frame
|
|
39
|
+
# @return [Point, Line] a new shape, on the page
|
|
40
|
+
def apply(shape)
|
|
41
|
+
case shape
|
|
42
|
+
when Line then Line.new(apply(shape.p1), apply(shape.p2))
|
|
43
|
+
when Point then Point[origin.x + (shape.x * @cos) - (shape.y * @sin), origin.y + (shape.x * @sin) + (shape.y * @cos)]
|
|
44
|
+
else raise ArgumentError, "cannot transform #{shape.class}"
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -3,11 +3,19 @@
|
|
|
3
3
|
module Laser
|
|
4
4
|
module Cutter
|
|
5
5
|
module Geometry
|
|
6
|
+
# A fixed list of coordinates held as a Vector: the base of {Point} and
|
|
7
|
+
# {Dimensions}. Two tuples are equal when their coordinates are within
|
|
8
|
+
# {PRECISION} of each other.
|
|
6
9
|
class Tuple
|
|
10
|
+
# @!attribute [rw] coords
|
|
11
|
+
# @return [Vector] the coordinates, as Floats
|
|
7
12
|
attr_accessor :coords
|
|
8
13
|
|
|
14
|
+
# The squared distance below which two coordinates count as equal.
|
|
9
15
|
PRECISION = 0.000001
|
|
10
16
|
|
|
17
|
+
# @param args [Array] the coordinates, as numbers, or one String
|
|
18
|
+
# ("1,2"), Hash ({x: 1, y: 2}), Array, Tuple or Vector
|
|
11
19
|
def initialize(*args)
|
|
12
20
|
x = args.first
|
|
13
21
|
coordinates = case x
|
|
@@ -26,6 +34,11 @@ module Laser
|
|
|
26
34
|
self.coords = Vector.[](*coordinates)
|
|
27
35
|
end
|
|
28
36
|
|
|
37
|
+
# Shifts the tuple.
|
|
38
|
+
#
|
|
39
|
+
# @param x [Vector, Tuple, Numeric] the shift, or its x
|
|
40
|
+
# @param y [Numeric, nil] the y of the shift, when x is a number
|
|
41
|
+
# @return [Tuple] a new tuple of the same class
|
|
29
42
|
def +(x, y = nil)
|
|
30
43
|
shift = if x.is_a?(Vector)
|
|
31
44
|
x
|
|
@@ -37,59 +50,72 @@ module Laser
|
|
|
37
50
|
self.class.new(coords + shift)
|
|
38
51
|
end
|
|
39
52
|
|
|
53
|
+
# The same as {#+}.
|
|
54
|
+
#
|
|
55
|
+
# @return [Tuple]
|
|
40
56
|
alias_method :plus, :+
|
|
41
57
|
|
|
58
|
+
# @return [Array<Float>] the coordinates
|
|
42
59
|
def to_a
|
|
43
60
|
coords.to_a
|
|
44
61
|
end
|
|
45
62
|
|
|
63
|
+
# @return [String] the coordinates to five digits, as "{1.00000,2.00000}"
|
|
46
64
|
def to_s
|
|
47
65
|
"{#{coords.to_a.map { |a| sprintf('%.5f', a) }.join(separator)}}"
|
|
48
66
|
end
|
|
49
67
|
|
|
68
|
+
# @return [true]
|
|
69
|
+
# @raise [RuntimeError] when a coordinate is nil
|
|
50
70
|
def valid?
|
|
51
71
|
raise "Have nil value: #{inspect}" if coords.to_a.any?(&:nil?)
|
|
52
72
|
|
|
53
73
|
true
|
|
54
74
|
end
|
|
55
75
|
|
|
76
|
+
# @param value [Float] the new x
|
|
77
|
+
# @return [Float] the value
|
|
56
78
|
def x=(value)
|
|
57
79
|
self.coords = Vector.[](value, coords.[](1))
|
|
58
80
|
end
|
|
59
81
|
|
|
82
|
+
# @param value [Float] the new y
|
|
83
|
+
# @return [Float] the value
|
|
60
84
|
def y=(value)
|
|
61
85
|
self.coords = Vector.[](coords.[](0), value)
|
|
62
86
|
end
|
|
63
87
|
|
|
88
|
+
# @return [Float] the first coordinate
|
|
64
89
|
def x
|
|
65
90
|
coords.[](0)
|
|
66
91
|
end
|
|
67
92
|
|
|
93
|
+
# @return [Float] the second coordinate
|
|
68
94
|
def y
|
|
69
95
|
coords.[](1)
|
|
70
96
|
end
|
|
71
97
|
|
|
98
|
+
# @return [String] the separator between the coordinates in a String
|
|
72
99
|
def separator
|
|
73
100
|
','
|
|
74
101
|
end
|
|
75
102
|
|
|
103
|
+
# @param value [Integer] the index of a coordinate
|
|
104
|
+
# @return [Float, nil] the coordinate
|
|
76
105
|
def [](value)
|
|
77
106
|
coords.[](value)
|
|
78
107
|
end
|
|
79
108
|
|
|
80
|
-
#
|
|
81
|
-
#
|
|
82
|
-
# ';'
|
|
83
|
-
# end
|
|
109
|
+
# The keys a Hash of coordinates uses, in order. A subclass with other
|
|
110
|
+
# coordinates overrides it, and {#separator} with it.
|
|
84
111
|
#
|
|
85
|
-
#
|
|
86
|
-
# [:x, :y, :z] or [:h, :w, :d]
|
|
87
|
-
# end
|
|
112
|
+
# @return [Array<Symbol>]
|
|
88
113
|
def hash_keys
|
|
89
114
|
[:x, :y]
|
|
90
115
|
end
|
|
91
116
|
|
|
92
|
-
#
|
|
117
|
+
# @param other [Tuple, Object]
|
|
118
|
+
# @return [Boolean] whether every coordinate is within {PRECISION} of the other's
|
|
93
119
|
def eql?(other)
|
|
94
120
|
return false unless other.respond_to?(:coords)
|
|
95
121
|
|
|
@@ -103,18 +129,27 @@ module Laser
|
|
|
103
129
|
equal
|
|
104
130
|
end
|
|
105
131
|
|
|
132
|
+
# Orders by x, then by y.
|
|
133
|
+
#
|
|
134
|
+
# @param other [Tuple]
|
|
135
|
+
# @return [Integer, nil]
|
|
106
136
|
def <=>(other)
|
|
107
137
|
x == other.x ? y <=> other.y : x <=> other.x
|
|
108
138
|
end
|
|
109
139
|
|
|
140
|
+
# @param other [Tuple]
|
|
141
|
+
# @return [Boolean] whether this tuple comes first, by x and then by y
|
|
110
142
|
def <(other)
|
|
111
143
|
x == other.x ? y < other.y : x < other.x
|
|
112
144
|
end
|
|
113
145
|
|
|
146
|
+
# @param other [Tuple]
|
|
147
|
+
# @return [Boolean] whether this tuple comes last, by x and then by y
|
|
114
148
|
def >(other)
|
|
115
149
|
x == other.x ? y > other.y : x > other.x
|
|
116
150
|
end
|
|
117
151
|
|
|
152
|
+
# @return [Tuple] a copy that does not share its coordinates
|
|
118
153
|
def clone
|
|
119
154
|
clone = super
|
|
120
155
|
clone.coords = coords.clone
|
|
@@ -123,13 +158,14 @@ module Laser
|
|
|
123
158
|
|
|
124
159
|
private
|
|
125
160
|
|
|
126
|
-
#
|
|
127
|
-
#
|
|
161
|
+
# @param string [String] the coordinates, such as "100,50"
|
|
162
|
+
# @return [Array<Float>] such as [100.0, 50.0]
|
|
128
163
|
def parse_string(string)
|
|
129
164
|
string.split(separator).map(&:to_f)
|
|
130
165
|
end
|
|
131
166
|
|
|
132
|
-
#
|
|
167
|
+
# @param hash [Hash] the coordinates by {#hash_keys}
|
|
168
|
+
# @return [Array] the coordinates in order
|
|
133
169
|
def parse_hash(hash)
|
|
134
170
|
hash_keys.map{ |k, _v| hash[k] }
|
|
135
171
|
end
|
|
@@ -5,6 +5,11 @@ module Laser
|
|
|
5
5
|
# Starts the CLI. The executable and the Aruba suite both build one, each
|
|
6
6
|
# with its own argv and streams, and it exits only through kernel.exit.
|
|
7
7
|
class Launcher
|
|
8
|
+
# @param argv [Array<String>] the command line, without the program name
|
|
9
|
+
# @param stdin [IO]
|
|
10
|
+
# @param stdout [IO]
|
|
11
|
+
# @param stderr [IO]
|
|
12
|
+
# @param kernel [#exit] what exits with the status
|
|
8
13
|
def initialize(argv, stdin = $stdin, stdout = $stdout, stderr = $stderr, kernel = Kernel)
|
|
9
14
|
@argv = argv
|
|
10
15
|
@stdin = stdin
|
|
@@ -13,6 +18,9 @@ module Laser
|
|
|
13
18
|
@kernel = kernel
|
|
14
19
|
end
|
|
15
20
|
|
|
21
|
+
# Runs the command line and exits with its status.
|
|
22
|
+
#
|
|
23
|
+
# @return [void]
|
|
16
24
|
def execute!
|
|
17
25
|
@kernel.exit(run)
|
|
18
26
|
end
|
|
@@ -20,6 +28,9 @@ module Laser
|
|
|
20
28
|
private
|
|
21
29
|
|
|
22
30
|
# dry-cli exits by itself after help or a usage error; its status is kept.
|
|
31
|
+
# Any other error is shown in a box, with its backtrace under --verbose.
|
|
32
|
+
#
|
|
33
|
+
# @return [Integer] the exit status
|
|
23
34
|
def run
|
|
24
35
|
Dry::CLI.new(CLI).call(arguments: @argv, out: @stdout, err: @stderr)
|
|
25
36
|
0
|
|
@@ -32,8 +43,10 @@ module Laser
|
|
|
32
43
|
end
|
|
33
44
|
|
|
34
45
|
# The same boxes the commands draw, on this run's own streams.
|
|
46
|
+
#
|
|
47
|
+
# @return [Dry::CLI::UI::Console]
|
|
35
48
|
def ui
|
|
36
|
-
|
|
49
|
+
CLI.console(out: @stdout, err: @stderr)
|
|
37
50
|
end
|
|
38
51
|
end
|
|
39
52
|
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Laser
|
|
4
|
+
module Cutter
|
|
5
|
+
# Lays out the notches along the sides of a panel, and draws them as
|
|
6
|
+
# lines.
|
|
7
|
+
module Notching
|
|
8
|
+
# Notches along a side at any angle: the sloped side of a wall under a
|
|
9
|
+
# tilted panel.
|
|
10
|
+
#
|
|
11
|
+
# It lays the side flat along the x axis of a local frame, notches it
|
|
12
|
+
# there with the same Edge and PathGenerator every other side uses, and
|
|
13
|
+
# turns the lines back onto the side. A side of the same length therefore
|
|
14
|
+
# gets the same notch count and width wherever it points, so a tilted
|
|
15
|
+
# panel, itself a plain rectangle, mates with the sloped wall.
|
|
16
|
+
#
|
|
17
|
+
# It draws no corner boxes: the corners of a sloped side are not square.
|
|
18
|
+
# Kerf moves the ends along the side as it does on a square corner, which
|
|
19
|
+
# is close but not exact when the corner is not square.
|
|
20
|
+
class AngledEdge
|
|
21
|
+
extend ::Forwardable
|
|
22
|
+
|
|
23
|
+
# The side of the run, from +from+ to +to+, the material lies beyond.
|
|
24
|
+
SIDES = { left: 1, right: -1 }.freeze
|
|
25
|
+
|
|
26
|
+
def_delegators :@edge, :notch_count, :notch_width, :first_notch_out?, :center_out, :thickness, :kerf
|
|
27
|
+
|
|
28
|
+
# @return [Geometry::Transform] from the local frame onto the page
|
|
29
|
+
attr_reader :transform
|
|
30
|
+
|
|
31
|
+
# @param from [Geometry::Point] where the inside line starts
|
|
32
|
+
# @param to [Geometry::Point] where it ends
|
|
33
|
+
# @param outward [Symbol] :left or :right of the run from +from+ to +to+
|
|
34
|
+
# @param options [Hash] as for Edge: notch_width, thickness, kerf, center_out
|
|
35
|
+
def initialize(from, to, outward:, **options)
|
|
36
|
+
sign = SIDES.fetch(outward) { raise ArgumentError, "outward must be one of #{SIDES.keys}, got #{outward.inspect}" }
|
|
37
|
+
length = Geometry::Line.new(from, to).length
|
|
38
|
+
raise ArgumentError, "a run needs a length, but it starts and ends at #{from}" unless length > Geometry::Tuple::PRECISION
|
|
39
|
+
|
|
40
|
+
@transform = Geometry::Transform.along(from, to)
|
|
41
|
+
@edge = Edge.new(*local_lines(length, options.fetch(:thickness), sign), options.merge(corners: false))
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# @return [Array<Geometry::Line>] the notched path, on the page
|
|
45
|
+
def lines
|
|
46
|
+
PathGenerator.new(@edge).generate.map { |line| transform.apply(line) }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
|
|
51
|
+
# The outside and inside lines of a side of the given length, laid
|
|
52
|
+
# along the local x axis, the way Box pairs a face with its bounds.
|
|
53
|
+
#
|
|
54
|
+
# @param length [Float] the length of the side
|
|
55
|
+
# @param thickness [Float] the thickness of the material
|
|
56
|
+
# @param sign [Integer] 1 when the material lies to the left, -1 to the right
|
|
57
|
+
# @return [Array(Geometry::Line, Geometry::Line)] the outside line, then the inside line
|
|
58
|
+
def local_lines(length, thickness, sign)
|
|
59
|
+
offset = sign * thickness
|
|
60
|
+
outside = Geometry::Line.new(Geometry::Point[-thickness, offset], Geometry::Point[length + thickness, offset])
|
|
61
|
+
inside = Geometry::Line.new(Geometry::Point[0, 0], Geometry::Point[length, 0])
|
|
62
|
+
[outside, inside]
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -3,13 +3,21 @@
|
|
|
3
3
|
module Laser
|
|
4
4
|
module Cutter
|
|
5
5
|
module Notching
|
|
6
|
+
# The base of a notching strategy for one {Edge}.
|
|
6
7
|
class Base
|
|
8
|
+
# @!attribute [rw] edge
|
|
9
|
+
# @return [Edge] the side to notch
|
|
7
10
|
attr_accessor :edge
|
|
8
11
|
|
|
12
|
+
# @param edge [Edge] the side to notch
|
|
9
13
|
def initialize(edge)
|
|
10
14
|
@edge = edge
|
|
11
15
|
end
|
|
12
16
|
|
|
17
|
+
# Each strategy implements it.
|
|
18
|
+
#
|
|
19
|
+
# @return [Array<Geometry::Line>] the notched path
|
|
20
|
+
# @raise [RuntimeError] when the strategy does not implement it
|
|
13
21
|
def notches
|
|
14
22
|
raise 'Abstract method'
|
|
15
23
|
end
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
module Laser
|
|
4
4
|
module Cutter
|
|
5
5
|
module Notching
|
|
6
|
+
# The fewest notches a side gets, however short it is.
|
|
6
7
|
MINIMUM_NOTCHES_PER_SIDE = 3
|
|
7
8
|
# Decimal places kept of length / notch width before counting notches.
|
|
8
9
|
RATIO_DIGITS = 6
|
|
@@ -13,11 +14,37 @@ module Laser
|
|
|
13
14
|
# Both ends of an edge: 1 for p1, 2 for p2.
|
|
14
15
|
ENDS = [1, 2].freeze
|
|
15
16
|
|
|
17
|
+
# @!attribute [rw] outside
|
|
18
|
+
# @return [Geometry::Line] the outside line of the side, moved by half the kerf
|
|
19
|
+
# @!attribute [rw] inside
|
|
20
|
+
# @return [Geometry::Line] the inside line of the side, moved by half the kerf
|
|
21
|
+
# @!attribute [rw] notch_width
|
|
22
|
+
# @return [Float] the requested width at first, then the real one
|
|
23
|
+
# @!attribute [rw] thickness
|
|
24
|
+
# @return [Float] the thickness of the material
|
|
25
|
+
# @!attribute [rw] kerf
|
|
26
|
+
# @return [Float] the width the laser burns away
|
|
27
|
+
# @!attribute [rw] center_out
|
|
28
|
+
# @return [Boolean] whether the center notch is a tab
|
|
29
|
+
# @!attribute [rw] corners
|
|
30
|
+
# @return [Boolean, nil] whether the side draws corner boxes
|
|
31
|
+
# @!attribute [rw] adjust_corners
|
|
32
|
+
# @return [Boolean, nil] whether corner boxes are widened by the kerf
|
|
33
|
+
# @!attribute [rw] notch_count
|
|
34
|
+
# @return [Integer] the number of notches, odd and at least {MINIMUM_NOTCHES_PER_SIDE}
|
|
35
|
+
# @!attribute [rw] v1
|
|
36
|
+
# @return [Vector] the unit direction from the inside line to the outside line at p1
|
|
37
|
+
# @!attribute [rw] v2
|
|
38
|
+
# @return [Vector] the unit direction from the inside line to the outside line at p2
|
|
16
39
|
attr_accessor :outside, :inside, :notch_width, :thickness, :kerf, :center_out, :corners, :adjust_corners, :notch_count, :v1, :v2
|
|
17
40
|
|
|
18
41
|
# @return [Array<Integer>] the ends that get a corner box when +corners+ is set: 1 for p1, 2 for p2
|
|
19
42
|
attr_accessor :corner_ends
|
|
20
43
|
|
|
44
|
+
# @param outside [Geometry::Line] the outside line of the side
|
|
45
|
+
# @param inside [Geometry::Line] the inside line, parallel to it
|
|
46
|
+
# @param options [Hash] :notch_width, :thickness, :kerf, :center_out,
|
|
47
|
+
# :corners, :corner_ends and :adjust_corners
|
|
21
48
|
def initialize(outside, inside, options = {})
|
|
22
49
|
self.outside = outside.clone
|
|
23
50
|
self.inside = inside.clone
|
|
@@ -41,6 +68,9 @@ module Laser
|
|
|
41
68
|
calculate_notch_width!
|
|
42
69
|
end
|
|
43
70
|
|
|
71
|
+
# Moves both lines outwards by half the kerf.
|
|
72
|
+
#
|
|
73
|
+
# @return [void]
|
|
44
74
|
def adjust_for_kerf!
|
|
45
75
|
return unless kerf?
|
|
46
76
|
|
|
@@ -48,6 +78,8 @@ module Laser
|
|
|
48
78
|
self.outside = move_line_for_kerf(outside)
|
|
49
79
|
end
|
|
50
80
|
|
|
81
|
+
# @param line [Geometry::Line]
|
|
82
|
+
# @return [Geometry::Line] the line moved outwards by half the kerf
|
|
51
83
|
def move_line_for_kerf(line)
|
|
52
84
|
k = kerf / 2.0
|
|
53
85
|
p1 = line.p1.plus(v1 * k)
|
|
@@ -55,6 +87,7 @@ module Laser
|
|
|
55
87
|
Geometry::Line.new(p1, p2).relocate!
|
|
56
88
|
end
|
|
57
89
|
|
|
90
|
+
# @return [Boolean] whether there is any kerf
|
|
58
91
|
def kerf?
|
|
59
92
|
kerf > 0.0
|
|
60
93
|
end
|
|
@@ -67,20 +100,27 @@ module Laser
|
|
|
67
100
|
corners ? corner_ends.include?(end_index) : false
|
|
68
101
|
end
|
|
69
102
|
|
|
70
|
-
#
|
|
71
|
-
#
|
|
72
|
-
# of
|
|
103
|
+
# Whether the first notch is a tab, given whether the center one is.
|
|
104
|
+
# With an odd count the two agree when the count is 1 more than a
|
|
105
|
+
# multiple of 4.
|
|
106
|
+
#
|
|
107
|
+
# @param face_setting [Boolean] whether the center notch is a tab
|
|
108
|
+
# @return [Boolean]
|
|
73
109
|
def add_across_line?(face_setting)
|
|
74
110
|
notch_count % 4 == 1 ? face_setting : !face_setting
|
|
75
111
|
end
|
|
76
112
|
|
|
77
|
-
#
|
|
113
|
+
# @return [Boolean] true when the first notch is a tab, false when it is a hole
|
|
78
114
|
def first_notch_out?
|
|
79
115
|
add_across_line?(center_out)
|
|
80
116
|
end
|
|
81
117
|
|
|
82
118
|
private
|
|
83
119
|
|
|
120
|
+
# Sets {#notch_count} to an odd number of notches near the requested
|
|
121
|
+
# width, and {#notch_width} to the width that fits them exactly.
|
|
122
|
+
#
|
|
123
|
+
# @return [void]
|
|
84
124
|
def calculate_notch_width!
|
|
85
125
|
length = kerf? ? inside.length - kerf : inside.length
|
|
86
126
|
# Rounded before #ceil: when the notch divides the side exactly,
|
|
@@ -3,16 +3,26 @@
|
|
|
3
3
|
module Laser
|
|
4
4
|
module Cutter
|
|
5
5
|
module Notching
|
|
6
|
-
#
|
|
6
|
+
# Hands out copies of the items of an array in turn, starting again at
|
|
7
|
+
# the first after the last, for ever.
|
|
7
8
|
InfiniteIterator = Struct.new(:array) do
|
|
9
|
+
# @!attribute [rw] next_index
|
|
10
|
+
# @return [Integer] the index of the item {#next} returns
|
|
11
|
+
# @!attribute [rw] calls
|
|
12
|
+
# @return [Integer] how many times {#next} has been called
|
|
8
13
|
attr_accessor :array, :next_index, :calls
|
|
9
14
|
|
|
15
|
+
# @param array [Array] the items, each answering clone
|
|
10
16
|
def initialize(array)
|
|
11
17
|
self.array = array
|
|
12
18
|
self.calls = 0
|
|
13
19
|
self.next_index = 0
|
|
14
20
|
end
|
|
15
21
|
|
|
22
|
+
# @yieldparam item [Object] a copy of the next item
|
|
23
|
+
# @yieldparam calls [Integer] how many times next has been called, this time included
|
|
24
|
+
# @yieldreturn [Object] what next returns instead
|
|
25
|
+
# @return [Object] a copy of the next item, or what the block returned
|
|
16
26
|
def next
|
|
17
27
|
item = array[next_index].clone
|
|
18
28
|
self.next_index += 1
|