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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Edge.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/laser-cutter/notching/edge.rb', line 17

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.[](*self.v1)
  self.v2 = Vector.[](*self.v2)

  self.center_out = options[:center_out] || false
  self.thickness = options[:thickness]
  self.corners = options[:corners]
  self.kerf = options[:kerf] || 0
  self.notch_width = options[:notch_width]
  self.adjust_corners = options[:adjust_corners]

  calculate_notch_width!
  adjust_for_kerf!
end

Instance Attribute Details

#adjust_cornersObject

Returns the value of attribute adjust_corners.



13
14
15
# File 'lib/laser-cutter/notching/edge.rb', line 13

def adjust_corners
  @adjust_corners
end

#center_outObject

Returns the value of attribute center_out.



13
14
15
# File 'lib/laser-cutter/notching/edge.rb', line 13

def center_out
  @center_out
end

#cornersObject

Returns the value of attribute corners.



13
14
15
# File 'lib/laser-cutter/notching/edge.rb', line 13

def corners
  @corners
end

#insideObject

Returns the value of attribute inside.



10
11
12
# File 'lib/laser-cutter/notching/edge.rb', line 10

def inside
  @inside
end

#kerfObject

Returns the value of attribute kerf.



12
13
14
# File 'lib/laser-cutter/notching/edge.rb', line 12

def kerf
  @kerf
end

#notch_countObject

Returns the value of attribute notch_count.



14
15
16
# File 'lib/laser-cutter/notching/edge.rb', line 14

def notch_count
  @notch_count
end

#notch_widthObject

Returns the value of attribute notch_width.



11
12
13
# File 'lib/laser-cutter/notching/edge.rb', line 11

def notch_width
  @notch_width
end

#outsideObject

Returns the value of attribute outside.



10
11
12
# File 'lib/laser-cutter/notching/edge.rb', line 10

def outside
  @outside
end

#thicknessObject

Returns the value of attribute thickness.



12
13
14
# File 'lib/laser-cutter/notching/edge.rb', line 12

def thickness
  @thickness
end

#v1Object

Returns the value of attribute v1.



14
15
16
# File 'lib/laser-cutter/notching/edge.rb', line 14

def v1
  @v1
end

#v2Object

Returns the value of attribute v2.



14
15
16
# File 'lib/laser-cutter/notching/edge.rb', line 14

def v2
  @v2
end

Instance Method Details

#add_across_line?(face_setting) ⇒ Boolean

face_setting determines if we want that face to have center notch facing out (for a hole, etc). This works well when we have odd number of notches, but

Returns:

  • (Boolean)


60
61
62
# File 'lib/laser-cutter/notching/edge.rb', line 60

def add_across_line?(face_setting)
  notch_count % 4 == 1 ? face_setting : !face_setting
end

#adjust_for_kerf!Object



39
40
41
42
43
44
# File 'lib/laser-cutter/notching/edge.rb', line 39

def adjust_for_kerf!
  if kerf?
    self.inside  = move_line_for_kerf(inside)
    self.outside = move_line_for_kerf(outside)
  end
end

#first_notch_out?Boolean

True if the first notch should be a tab (sticking out), or false if it’s a hole.

Returns:

  • (Boolean)


65
66
67
# File 'lib/laser-cutter/notching/edge.rb', line 65

def first_notch_out?
  add_across_line?(center_out)
end

#kerf?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/laser-cutter/notching/edge.rb', line 53

def kerf?
  self.kerf > 0.0
end

#move_line_for_kerf(line) ⇒ Object



46
47
48
49
50
51
# File 'lib/laser-cutter/notching/edge.rb', line 46

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