Class: Laser::Cutter::Notching::Edge

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(outside, inside, options = {}) ⇒ Edge

Returns a new instance of Edge.

Parameters:

  • outside (Geometry::Line) —

    the outside line of the side

  • inside (Geometry::Line) —

    the inside line, parallel to it

  • options (Hash) (defaults to: {}) —

    :notch_width, :thickness, :kerf, :center_out, :corners, :corner_ends and :adjust_corners



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, options = {})
  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 = options[:center_out] || false
  self.thickness = options[:thickness]
  self.corners = options[:corners]
  self.corner_ends = options[:corner_ends] || ENDS
  self.kerf = options[:kerf] || 0
  self.notch_width = options[:notch_width]
  self.adjust_corners = options[:adjust_corners]

  adjust_for_kerf!
  calculate_notch_width!
end

Instance Attribute Details

#adjust_corners ⇒ Boolean?

Returns whether corner boxes are widened by the kerf.

Returns:

  • (Boolean, nil) —

    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.

Returns:

  • (Boolean) —

    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.

Returns:

  • (Array<Integer>) —

    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.

Returns:

  • (Boolean, nil) —

    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.

Returns:

  • (Geometry::Line) —

    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.

Returns:

  • (Float) —

    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.

Returns:



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.

Returns:

  • (Float) —

    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.

Returns:

  • (Geometry::Line) —

    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.

Returns:

  • (Float) —

    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.

Returns:

  • (Vector) —

    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.

Returns:

  • (Vector) —

    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.

Parameters:

  • face_setting (Boolean) —

    whether the center notch is a tab

Returns:

  • (Boolean)


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.

Parameters:

  • end_index (Integer) —

    1 for p1, 2 for p2

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean) —

    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.

Returns:

  • (Boolean) —

    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.

Parameters:

Returns:



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