class Laser::Cutter::Notching::Edge

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.

Attributes

adjust_corners[RW]
center_out[RW]
corners[RW]
inside[RW]
kerf[RW]
notch_count[RW]
notch_width[RW]
outside[RW]
thickness[RW]
v1[RW]
v2[RW]

Public Class Methods

new(outside, inside, options = {}) click to toggle source
# 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

Public Instance Methods

add_across_line?(face_setting) click to toggle source

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

# 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!() click to toggle source
# 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?() click to toggle source

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

# File lib/laser-cutter/notching/edge.rb, line 65
def first_notch_out?
  add_across_line?(center_out)
end
kerf?() click to toggle source
# File lib/laser-cutter/notching/edge.rb, line 53
def kerf?
  self.kerf > 0.0
end
move_line_for_kerf(line) click to toggle source
# 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

Private Instance Methods

calculate_notch_width!() click to toggle source
# File lib/laser-cutter/notching/edge.rb, line 70
def calculate_notch_width!
  count = ((self.inside.length) / notch_width).to_f.ceil + 1
  count = (count / 2 * 2) + 1 # make count always an odd number
  count = [MINIMUM_NOTCHES_PER_SIDE, count].max

  self.notch_width = 1.0 * (self.inside.length) / count
  self.notch_count = count
end