laser-cutter 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/pages.yml +44 -0
  3. data/.gitignore +2 -0
  4. data/.openlanes/config.yml +106 -0
  5. data/.plans/002.00/342/224/201/342/224/201/342/232/252/342/224/201/342/224/201/342/235/257lid-options/plan.md +45 -0
  6. data/.plans/003.00/342/224/201/342/224/201/342/232/252/342/224/201/342/224/201/342/235/257ruby-api/plan.md +37 -0
  7. data/.plans/004.00/342/224/201/342/224/201/342/232/252/342/224/201/342/224/201/342/235/257can-we-create-an-angled-box-where-angle-is-configurable-like-in-spec-wishes-image-shows/spec.md +40 -0
  8. data/.plans/004.00/342/224/201/342/224/201/342/232/252/342/224/201/342/224/201/342/235/257can-we-create-an-angled-box-where-angle-is-configurable-like-in-spec-wishes-image-shows/state.json +337 -0
  9. data/.plans/004.01/342/224/201/342/224/201/342/232/252/342/224/201/342/224/201/342/235/257sloped-box-panels/plan.md +91 -0
  10. data/.plans/decisions.md +11 -0
  11. data/CHANGELOG.md +134 -0
  12. data/CLAUDE.md +30 -5
  13. data/Gemfile +2 -1
  14. data/README.md +309 -31
  15. data/Rakefile +11 -7
  16. data/docs/badges/coverage_badge.svg +2 -2
  17. data/docs/decisions/decisions-on-angled-box.md +93 -0
  18. data/docs/decisions/stack.md +6 -0
  19. data/docs/images/box-3d.avif +0 -0
  20. data/docs/images/box-lid-back.avif +0 -0
  21. data/docs/images/box-lid-full.avif +0 -0
  22. data/docs/images/box-lid-plain.avif +0 -0
  23. data/docs/images/box-metric.avif +0 -0
  24. data/docs/images/box-sloped-3d.avif +0 -0
  25. data/docs/images/box-sloped.avif +0 -0
  26. data/docs/images/box-tray.avif +0 -0
  27. data/justfile +24 -8
  28. data/laser-cutter.gemspec +2 -1
  29. data/lib/laser/cutter/aggregator.rb +28 -0
  30. data/lib/laser/cutter/box.rb +192 -24
  31. data/lib/laser/cutter/box_factory.rb +15 -0
  32. data/lib/laser/cutter/cli/command.rb +27 -1
  33. data/lib/laser/cutter/cli/config_file.rb +2 -0
  34. data/lib/laser/cutter/cli/examples.rb +8 -0
  35. data/lib/laser/cutter/cli/generate.rb +41 -5
  36. data/lib/laser/cutter/cli/help.rb +4 -0
  37. data/lib/laser/cutter/cli/page_sizes.rb +3 -0
  38. data/lib/laser/cutter/cli/version.rb +2 -0
  39. data/lib/laser/cutter/cli.rb +23 -4
  40. data/lib/laser/cutter/configuration.rb +42 -2
  41. data/lib/laser/cutter/geometry/dimensions.rb +7 -0
  42. data/lib/laser/cutter/geometry/line.rb +42 -0
  43. data/lib/laser/cutter/geometry/loop.rb +138 -0
  44. data/lib/laser/cutter/geometry/point.rb +3 -0
  45. data/lib/laser/cutter/geometry/rect.rb +25 -0
  46. data/lib/laser/cutter/geometry/shape.rb +19 -1
  47. data/lib/laser/cutter/geometry/transform.rb +50 -0
  48. data/lib/laser/cutter/geometry/tuple.rb +47 -11
  49. data/lib/laser/cutter/invalid_option.rb +8 -0
  50. data/lib/laser/cutter/launcher.rb +14 -1
  51. data/lib/laser/cutter/missing_option.rb +2 -0
  52. data/lib/laser/cutter/notching/angled_edge.rb +67 -0
  53. data/lib/laser/cutter/notching/base.rb +8 -0
  54. data/lib/laser/cutter/notching/edge.rb +59 -4
  55. data/lib/laser/cutter/notching/infinite_iterator.rb +11 -1
  56. data/lib/laser/cutter/notching/path_generator.rb +86 -81
  57. data/lib/laser/cutter/notching/shift.rb +4 -0
  58. data/lib/laser/cutter/options.rb +175 -0
  59. data/lib/laser/cutter/page_manager.rb +12 -2
  60. data/lib/laser/cutter/renderer/base.rb +26 -4
  61. data/lib/laser/cutter/renderer/box_renderer.rb +14 -1
  62. data/lib/laser/cutter/renderer/layout_renderer.rb +13 -3
  63. data/lib/laser/cutter/renderer/line_renderer.rb +6 -0
  64. data/lib/laser/cutter/renderer/meta_renderer.rb +33 -9
  65. data/lib/laser/cutter/renderer/rect_renderer.rb +5 -0
  66. data/lib/laser/cutter/renderer/svg_renderer.rb +12 -4
  67. data/lib/laser/cutter/renderer.rb +2 -0
  68. data/lib/laser/cutter/sloped/box.rb +90 -0
  69. data/lib/laser/cutter/sloped/corners.rb +58 -0
  70. data/lib/laser/cutter/sloped/layout.rb +97 -0
  71. data/lib/laser/cutter/sloped/notcher.rb +53 -0
  72. data/lib/laser/cutter/sloped/panels.rb +121 -0
  73. data/lib/laser/cutter/sloped/placement.rb +36 -0
  74. data/lib/laser/cutter/sloped/profile.rb +176 -0
  75. data/lib/laser/cutter/sloped/request.rb +31 -0
  76. data/lib/laser/cutter/sloped/ring_panel.rb +120 -0
  77. data/lib/laser/cutter/sloped/side_panel.rb +89 -0
  78. data/lib/laser/cutter/types.rb +60 -0
  79. data/lib/laser/cutter/units_converter.rb +5 -0
  80. data/lib/laser/cutter/version.rb +2 -1
  81. data/lib/laser/cutter/zero_value_not_allowed.rb +2 -0
  82. data/lib/laser/cutter.rb +40 -0
  83. data/spec/laser/cutter/angled_edge_spec.rb +103 -0
  84. data/spec/laser/cutter/box_factory_spec.rb +19 -0
  85. data/spec/laser/cutter/box_lid_spec.rb +142 -0
  86. data/spec/laser/cutter/cli_spec.rb +114 -7
  87. data/spec/laser/cutter/configuration_spec.rb +54 -0
  88. data/spec/laser/cutter/loop_spec.rb +107 -0
  89. data/spec/laser/cutter/options_spec.rb +162 -0
  90. data/spec/laser/cutter/renderer/layout_renderer_spec.rb +21 -20
  91. data/spec/laser/cutter/renderer/meta_renderer_spec.rb +82 -0
  92. data/spec/laser/cutter/renderer/svg_renderer_spec.rb +34 -0
  93. data/spec/laser/cutter/sloped/assembly_spec.rb +78 -0
  94. data/spec/laser/cutter/sloped/box_spec.rb +151 -0
  95. data/spec/laser/cutter/sloped/corners_spec.rb +45 -0
  96. data/spec/laser/cutter/sloped/layout_spec.rb +77 -0
  97. data/spec/laser/cutter/sloped/notcher_spec.rb +57 -0
  98. data/spec/laser/cutter/sloped/panels_spec.rb +175 -0
  99. data/spec/laser/cutter/sloped/placement_spec.rb +50 -0
  100. data/spec/laser/cutter/sloped/request_spec.rb +48 -0
  101. data/spec/laser/cutter/sloped/ring_panel_spec.rb +102 -0
  102. data/spec/laser/cutter/sloped/side_panel_spec.rb +98 -0
  103. data/spec/laser/cutter/sloped_profile_spec.rb +156 -0
  104. data/spec/laser/cutter/transform_spec.rb +53 -0
  105. data/spec/laser/cutter_spec.rb +114 -0
  106. data/spec/spec_helper.rb +4 -0
  107. data/spec/support/loops.rb +106 -0
  108. data/spec/support/outline.rb +53 -0
  109. data/spec/support/sloped.rb +26 -0
  110. data/spec/support/solid.rb +95 -0
  111. data/spec/wishes/wish-tilted-box.png +0 -0
  112. metadata +81 -7
  113. /data/.plans/{001.00-dry-cli-migration/plan.md → 001.00/342/224/201/342/224/201/342/232/252/342/224/201/342/224/201/342/235/257dry-cli-migration/plan.md"} +0 -0
@@ -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
- # Override in subclasses, eg:
81
- # def separator
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
- # def hash_keys
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
- # Identity, cloning and sorting/ordering
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
- # Convert from, eg "100,50" to [100.0, 50.0],
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
- # Return array of coordinates
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
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Laser
4
+ module Cutter
5
+ # An option has a value it cannot take.
6
+ class InvalidOption < Error; end
7
+ end
8
+ 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
- Dry::CLI::UI::Console.new(out: @stdout, err: @stderr, box_width: CLI.help_width)
49
+ CLI.console(out: @stdout, err: @stderr)
37
50
  end
38
51
  end
39
52
  end
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Laser
4
4
  module Cutter
5
+ # Raised when a required option, such as a dimension or the thickness,
6
+ # is missing.
5
7
  class MissingOption < Error; end
6
8
  end
7
9
  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
@@ -10,8 +11,40 @@ module Laser
10
11
  # and outside edge of the material. It's also responsible
11
12
  # for calculating the "perfect" notch width.
12
13
  class Edge
14
+ # Both ends of an edge: 1 for p1, 2 for p2.
15
+ ENDS = [1, 2].freeze
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
13
39
  attr_accessor :outside, :inside, :notch_width, :thickness, :kerf, :center_out, :corners, :adjust_corners, :notch_count, :v1, :v2
14
40
 
41
+ # @return [Array<Integer>] the ends that get a corner box when +corners+ is set: 1 for p1, 2 for p2
42
+ attr_accessor :corner_ends
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
15
48
  def initialize(outside, inside, options = {})
16
49
  self.outside = outside.clone
17
50
  self.inside = inside.clone
@@ -26,6 +59,7 @@ module Laser
26
59
  self.center_out = options[:center_out] || false
27
60
  self.thickness = options[:thickness]
28
61
  self.corners = options[:corners]
62
+ self.corner_ends = options[:corner_ends] || ENDS
29
63
  self.kerf = options[:kerf] || 0
30
64
  self.notch_width = options[:notch_width]
31
65
  self.adjust_corners = options[:adjust_corners]
@@ -34,6 +68,9 @@ module Laser
34
68
  calculate_notch_width!
35
69
  end
36
70
 
71
+ # Moves both lines outwards by half the kerf.
72
+ #
73
+ # @return [void]
37
74
  def adjust_for_kerf!
38
75
  return unless kerf?
39
76
 
@@ -41,6 +78,8 @@ module Laser
41
78
  self.outside = move_line_for_kerf(outside)
42
79
  end
43
80
 
81
+ # @param line [Geometry::Line]
82
+ # @return [Geometry::Line] the line moved outwards by half the kerf
44
83
  def move_line_for_kerf(line)
45
84
  k = kerf / 2.0
46
85
  p1 = line.p1.plus(v1 * k)
@@ -48,24 +87,40 @@ module Laser
48
87
  Geometry::Line.new(p1, p2).relocate!
49
88
  end
50
89
 
90
+ # @return [Boolean] whether there is any kerf
51
91
  def kerf?
52
92
  kerf > 0.0
53
93
  end
54
94
 
55
- # face_setting determines if we want that face to have center notch
56
- # facing out (for a hole, etc). This works well when we have odd number
57
- # of notches, but
95
+ # Whether this edge draws a corner box at the given end.
96
+ #
97
+ # @param end_index [Integer] 1 for p1, 2 for p2
98
+ # @return [Boolean]
99
+ def corner_at?(end_index)
100
+ corners ? corner_ends.include?(end_index) : false
101
+ end
102
+
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]
58
109
  def add_across_line?(face_setting)
59
110
  notch_count % 4 == 1 ? face_setting : !face_setting
60
111
  end
61
112
 
62
- # True if the first notch should be a tab (sticking out), or false if it's a hole.
113
+ # @return [Boolean] true when the first notch is a tab, false when it is a hole
63
114
  def first_notch_out?
64
115
  add_across_line?(center_out)
65
116
  end
66
117
 
67
118
  private
68
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]
69
124
  def calculate_notch_width!
70
125
  length = kerf? ? inside.length - kerf : inside.length
71
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
- # Alternating iterator
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