Class: Laser::Cutter::Notching::Edge
- Inherits:
-
Object
- Object
- Laser::Cutter::Notching::Edge
- Defined in:
- lib/laser/cutter/notching/edge.rb
Overview
This class represents a single edge of one side: both inside and outside edge of the material. It's also responsible for calculating the "perfect" notch width.
Constant Summary collapse
- ENDS =
Both ends of an edge: 1 for p1, 2 for p2.
[1, 2].freeze
Instance Attribute Summary collapse
-
#adjust_corners ⇒ Boolean?
Whether corner boxes are widened by the kerf.
-
#center_out ⇒ Boolean
Whether the center notch is a tab.
-
#corner_ends ⇒ Array<Integer>
The ends that get a corner box when
cornersis set: 1 for p1, 2 for p2. -
#corners ⇒ Boolean?
Whether the side draws corner boxes.
-
#inside ⇒ Geometry::Line
The inside line of the side, moved by half the kerf.
-
#kerf ⇒ Float
The width the laser burns away.
-
#notch_count ⇒ Integer
The number of notches, odd and at least MINIMUM_NOTCHES_PER_SIDE.
-
#notch_width ⇒ Float
The requested width at first, then the real one.
-
#outside ⇒ Geometry::Line
The outside line of the side, moved by half the kerf.
-
#thickness ⇒ Float
The thickness of the material.
-
#v1 ⇒ Vector
The unit direction from the inside line to the outside line at p1.
-
#v2 ⇒ Vector
The unit direction from the inside line to the outside line at p2.
Instance Method Summary collapse
-
#add_across_line?(face_setting) ⇒ Boolean
Whether the first notch is a tab, given whether the center one is.
-
#adjust_for_kerf! ⇒ void
Moves both lines outwards by half the kerf.
-
#corner_at?(end_index) ⇒ Boolean
Whether this edge draws a corner box at the given end.
-
#first_notch_out? ⇒ Boolean
True when the first notch is a tab, false when it is a hole.
-
#initialize(outside, inside, options = {}) ⇒ Edge
constructor
A new instance of Edge.
-
#kerf? ⇒ Boolean
Whether there is any kerf.
-
#move_line_for_kerf(line) ⇒ Geometry::Line
The line moved outwards by half the kerf.
Constructor Details
#initialize(outside, inside, options = {}) ⇒ Edge
Returns a new instance of Edge.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/laser/cutter/notching/edge.rb', line 48 def initialize(outside, inside, = {}) self.outside = outside.clone self.inside = inside.clone # two vectors representing directions going from beginning of each inside line to the outside self.v1 = [inside.p1.x - outside.p1.x, inside.p1.y - outside.p1.y].map{ |e| -(e / e.abs).to_f } self.v2 = [inside.p2.x - outside.p2.x, inside.p2.y - outside.p2.y].map{ |e| -(e / e.abs).to_f } self.v1 = Vector.[](*v1) self.v2 = Vector.[](*v2) self.center_out = [:center_out] || false self.thickness = [:thickness] self.corners = [:corners] self.corner_ends = [:corner_ends] || ENDS self.kerf = [:kerf] || 0 self.notch_width = [:notch_width] self.adjust_corners = [:adjust_corners] adjust_for_kerf! calculate_notch_width! end |
Instance Attribute Details
#adjust_corners ⇒ Boolean?
Returns whether corner boxes are widened by the kerf.
39 |
# File 'lib/laser/cutter/notching/edge.rb', line 39 attr_accessor :outside, :inside, :notch_width, :thickness, :kerf, :center_out, :corners, :adjust_corners, :notch_count, :v1, :v2 |
#center_out ⇒ Boolean
Returns whether the center notch is a tab.
39 |
# File 'lib/laser/cutter/notching/edge.rb', line 39 attr_accessor :outside, :inside, :notch_width, :thickness, :kerf, :center_out, :corners, :adjust_corners, :notch_count, :v1, :v2 |
#corner_ends ⇒ Array<Integer>
Returns the ends that get a corner box when corners is set: 1 for p1, 2 for p2.
42 43 44 |
# File 'lib/laser/cutter/notching/edge.rb', line 42 def corner_ends @corner_ends end |
#corners ⇒ Boolean?
Returns whether the side draws corner boxes.
39 |
# File 'lib/laser/cutter/notching/edge.rb', line 39 attr_accessor :outside, :inside, :notch_width, :thickness, :kerf, :center_out, :corners, :adjust_corners, :notch_count, :v1, :v2 |
#inside ⇒ Geometry::Line
Returns the inside line of the side, moved by half the kerf.
39 |
# File 'lib/laser/cutter/notching/edge.rb', line 39 attr_accessor :outside, :inside, :notch_width, :thickness, :kerf, :center_out, :corners, :adjust_corners, :notch_count, :v1, :v2 |
#kerf ⇒ Float
Returns the width the laser burns away.
39 |
# File 'lib/laser/cutter/notching/edge.rb', line 39 attr_accessor :outside, :inside, :notch_width, :thickness, :kerf, :center_out, :corners, :adjust_corners, :notch_count, :v1, :v2 |
#notch_count ⇒ Integer
Returns the number of notches, odd and at least MINIMUM_NOTCHES_PER_SIDE.
39 |
# File 'lib/laser/cutter/notching/edge.rb', line 39 attr_accessor :outside, :inside, :notch_width, :thickness, :kerf, :center_out, :corners, :adjust_corners, :notch_count, :v1, :v2 |
#notch_width ⇒ Float
Returns the requested width at first, then the real one.
39 |
# File 'lib/laser/cutter/notching/edge.rb', line 39 attr_accessor :outside, :inside, :notch_width, :thickness, :kerf, :center_out, :corners, :adjust_corners, :notch_count, :v1, :v2 |
#outside ⇒ Geometry::Line
Returns the outside line of the side, moved by half the kerf.
39 40 41 |
# File 'lib/laser/cutter/notching/edge.rb', line 39 def outside @outside end |
#thickness ⇒ Float
Returns the thickness of the material.
39 |
# File 'lib/laser/cutter/notching/edge.rb', line 39 attr_accessor :outside, :inside, :notch_width, :thickness, :kerf, :center_out, :corners, :adjust_corners, :notch_count, :v1, :v2 |
#v1 ⇒ Vector
Returns the unit direction from the inside line to the outside line at p1.
39 |
# File 'lib/laser/cutter/notching/edge.rb', line 39 attr_accessor :outside, :inside, :notch_width, :thickness, :kerf, :center_out, :corners, :adjust_corners, :notch_count, :v1, :v2 |
#v2 ⇒ Vector
Returns the unit direction from the inside line to the outside line at p2.
39 |
# File 'lib/laser/cutter/notching/edge.rb', line 39 attr_accessor :outside, :inside, :notch_width, :thickness, :kerf, :center_out, :corners, :adjust_corners, :notch_count, :v1, :v2 |
Instance Method Details
#add_across_line?(face_setting) ⇒ Boolean
Whether the first notch is a tab, given whether the center one is. With an odd count the two agree when the count is 1 more than a multiple of 4.
109 110 111 |
# File 'lib/laser/cutter/notching/edge.rb', line 109 def add_across_line?(face_setting) notch_count % 4 == 1 ? face_setting : !face_setting end |
#adjust_for_kerf! ⇒ void
This method returns an undefined value.
Moves both lines outwards by half the kerf.
74 75 76 77 78 79 |
# File 'lib/laser/cutter/notching/edge.rb', line 74 def adjust_for_kerf! return unless kerf? self.inside = move_line_for_kerf(inside) self.outside = move_line_for_kerf(outside) end |
#corner_at?(end_index) ⇒ Boolean
Whether this edge draws a corner box at the given end.
99 100 101 |
# File 'lib/laser/cutter/notching/edge.rb', line 99 def corner_at?(end_index) corners ? corner_ends.include?(end_index) : false end |
#first_notch_out? ⇒ Boolean
Returns true when the first notch is a tab, false when it is a hole.
114 115 116 |
# File 'lib/laser/cutter/notching/edge.rb', line 114 def first_notch_out? add_across_line?(center_out) end |
#kerf? ⇒ Boolean
Returns whether there is any kerf.
91 92 93 |
# File 'lib/laser/cutter/notching/edge.rb', line 91 def kerf? kerf > 0.0 end |
#move_line_for_kerf(line) ⇒ Geometry::Line
Returns the line moved outwards by half the kerf.
83 84 85 86 87 88 |
# File 'lib/laser/cutter/notching/edge.rb', line 83 def move_line_for_kerf(line) k = kerf / 2.0 p1 = line.p1.plus(v1 * k) p2 = line.p2.plus(v2 * k) Geometry::Line.new(p1, p2).relocate! end |