Class: Laser::Cutter::Box

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/laser-cutter/box.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Box

Returns a new instance of Box.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/laser-cutter/box.rb', line 16

def initialize(config = {})
  self.dim       = Geometry::Dimensions.new(config['width'], config['height'], config['depth'])
  self.thickness = config['thickness']

  self.notch_width = config['notch'] || (1.0 * self.longest / 5.0)
  self.kerf        = config['kerf'] || 0.0
  self.padding     = config['padding']
  self.units       = config['units']
  self.inside_box  = config['inside_box']

  self.notches = []

  self. = Geometry::Point[config['metadata_width'] || 0, config['metadata_height'] || 0]

  create_faces! # generates dimensions for each side
  self.faces     = [top, front, bottom, back, left, right]

  self.conf = {
    valign:  [:out, :out, :out, :out, :in, :in],
    halign:  [:in, :out, :in, :out, :in, :in],
    corners: {
      top: [:yes, :no, :yes, :no, :no, :no], # 2nd choice, has to work if 1st doesn't
      front: [:no, :yes, :no, :yes, :no, :no], # our default choice, but may not work
    },
  }
  self
end

Instance Attribute Details

#backObject

Returns the value of attribute back.



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

def back
  @back
end

#bottomObject

Returns the value of attribute bottom.



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

def bottom
  @bottom
end

#boundsObject

Returns the value of attribute bounds.



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

def bounds
  @bounds
end

#confObject

Returns the value of attribute conf.



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

def conf
  @conf
end

#corner_faceObject

Returns the value of attribute corner_face.



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

def corner_face
  @corner_face
end

#dimObject

Returns the value of attribute dim.



9
10
11
# File 'lib/laser-cutter/box.rb', line 9

def dim
  @dim
end

#facesObject

Returns the value of attribute faces.



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

def faces
  @faces
end

#frontObject

Returns the value of attribute front.



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

def front
  @front
end

#inside_boxObject

Returns the value of attribute inside_box.



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

def inside_box
  @inside_box
end

#kerfObject

Returns the value of attribute kerf.



9
10
11
# File 'lib/laser-cutter/box.rb', line 9

def kerf
  @kerf
end

#leftObject

Returns the value of attribute left.



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

def left
  @left
end

#metadataObject

Returns the value of attribute metadata.



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

def 
  @metadata
end

#notch_widthObject

Returns the value of attribute notch_width.



9
10
11
# File 'lib/laser-cutter/box.rb', line 9

def notch_width
  @notch_width
end

#notchesObject

Returns the value of attribute notches.



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

def notches
  @notches
end

#paddingObject

Returns the value of attribute padding.



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

def padding
  @padding
end

#rightObject

Returns the value of attribute right.



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

def right
  @right
end

#thicknessObject

Returns the value of attribute thickness.



9
10
11
# File 'lib/laser-cutter/box.rb', line 9

def thickness
  @thickness
end

#topObject

Returns the value of attribute top.



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

def top
  @top
end

#unitsObject

Returns the value of attribute units.



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

def units
  @units
end

Instance Method Details

#enclosureObject



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/laser-cutter/box.rb', line 54

def enclosure
  generate_notches if self.notches.empty?
  p1 = notches.first.p1.to_a
  p2 = notches.first.p2.to_a

  notches.each do |notch|
    n = notch.normalized
    n.p1.to_a.each_with_index {|c, i| p1[i] = c if c < p1[i]}
    n.p2.to_a.each_with_index {|c, i| p2[i] = c if c > p2[i]}
  end

  Geometry::Rect[Geometry::Point.new(p1), Geometry::Point.new(p2)]
end

#generate_notchesObject



44
45
46
47
48
49
50
51
52
# File 'lib/laser-cutter/box.rb', line 44

def generate_notches
  position_faces!
  self.corner_face = pick_corners_face
  self.notches     = []
  faces.each_with_index do |face, face_index|
    create_face_edges(face, face_index)
  end
  self.notches.flatten!
end

#longestObject



68
69
70
# File 'lib/laser-cutter/box.rb', line 68

def longest
  [w, h, d].max
end

#to_sObject



72
73
74
# File 'lib/laser-cutter/box.rb', line 72

def to_s
  "Box:\nH:#{dim.h} W:#{dim.w} D:#{dim.d}\nThickness:#{thickness}, Notch:#{notch_width}"
end