Class: Laser::Cutter::Box
- Inherits:
-
Object
- Object
- Laser::Cutter::Box
- Extended by:
- Forwardable
- Defined in:
- lib/laser-cutter/box.rb
Instance Attribute Summary collapse
-
#back ⇒ Object
Returns the value of attribute back.
-
#bottom ⇒ Object
Returns the value of attribute bottom.
-
#bounds ⇒ Object
Returns the value of attribute bounds.
-
#conf ⇒ Object
Returns the value of attribute conf.
-
#corner_face ⇒ Object
Returns the value of attribute corner_face.
-
#dim ⇒ Object
Returns the value of attribute dim.
-
#faces ⇒ Object
Returns the value of attribute faces.
-
#front ⇒ Object
Returns the value of attribute front.
-
#inside_box ⇒ Object
Returns the value of attribute inside_box.
-
#kerf ⇒ Object
Returns the value of attribute kerf.
-
#left ⇒ Object
Returns the value of attribute left.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#notch_width ⇒ Object
Returns the value of attribute notch_width.
-
#notches ⇒ Object
Returns the value of attribute notches.
-
#padding ⇒ Object
Returns the value of attribute padding.
-
#right ⇒ Object
Returns the value of attribute right.
-
#thickness ⇒ Object
Returns the value of attribute thickness.
-
#top ⇒ Object
Returns the value of attribute top.
-
#units ⇒ Object
Returns the value of attribute units.
Instance Method Summary collapse
- #enclosure ⇒ Object
- #generate_notches ⇒ Object
-
#initialize(config = {}) ⇒ Box
constructor
A new instance of Box.
- #longest ⇒ Object
- #to_s ⇒ Object
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
#back ⇒ Object
Returns the value of attribute back.
12 13 14 |
# File 'lib/laser-cutter/box.rb', line 12 def back @back end |
#bottom ⇒ Object
Returns the value of attribute bottom.
12 13 14 |
# File 'lib/laser-cutter/box.rb', line 12 def bottom @bottom end |
#bounds ⇒ Object
Returns the value of attribute bounds.
13 14 15 |
# File 'lib/laser-cutter/box.rb', line 13 def bounds @bounds end |
#conf ⇒ Object
Returns the value of attribute conf.
13 14 15 |
# File 'lib/laser-cutter/box.rb', line 13 def conf @conf end |
#corner_face ⇒ Object
Returns the value of attribute corner_face.
13 14 15 |
# File 'lib/laser-cutter/box.rb', line 13 def corner_face @corner_face end |
#dim ⇒ Object
Returns the value of attribute dim.
9 10 11 |
# File 'lib/laser-cutter/box.rb', line 9 def dim @dim end |
#faces ⇒ Object
Returns the value of attribute faces.
13 14 15 |
# File 'lib/laser-cutter/box.rb', line 13 def faces @faces end |
#front ⇒ Object
Returns the value of attribute front.
12 13 14 |
# File 'lib/laser-cutter/box.rb', line 12 def front @front end |
#inside_box ⇒ Object
Returns the value of attribute inside_box.
10 11 12 |
# File 'lib/laser-cutter/box.rb', line 10 def inside_box @inside_box end |
#kerf ⇒ Object
Returns the value of attribute kerf.
9 10 11 |
# File 'lib/laser-cutter/box.rb', line 9 def kerf @kerf end |
#left ⇒ Object
Returns the value of attribute left.
12 13 14 |
# File 'lib/laser-cutter/box.rb', line 12 def left @left end |
#metadata ⇒ Object
Returns the value of attribute metadata.
14 15 16 |
# File 'lib/laser-cutter/box.rb', line 14 def @metadata end |
#notch_width ⇒ Object
Returns the value of attribute notch_width.
9 10 11 |
# File 'lib/laser-cutter/box.rb', line 9 def notch_width @notch_width end |
#notches ⇒ Object
Returns the value of attribute notches.
14 15 16 |
# File 'lib/laser-cutter/box.rb', line 14 def notches @notches end |
#padding ⇒ Object
Returns the value of attribute padding.
10 11 12 |
# File 'lib/laser-cutter/box.rb', line 10 def padding @padding end |
#right ⇒ Object
Returns the value of attribute right.
12 13 14 |
# File 'lib/laser-cutter/box.rb', line 12 def right @right end |
#thickness ⇒ Object
Returns the value of attribute thickness.
9 10 11 |
# File 'lib/laser-cutter/box.rb', line 9 def thickness @thickness end |
#top ⇒ Object
Returns the value of attribute top.
12 13 14 |
# File 'lib/laser-cutter/box.rb', line 12 def top @top end |
#units ⇒ Object
Returns the value of attribute units.
10 11 12 |
# File 'lib/laser-cutter/box.rb', line 10 def units @units end |
Instance Method Details
#enclosure ⇒ Object
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_notches ⇒ Object
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 |
#longest ⇒ Object
68 69 70 |
# File 'lib/laser-cutter/box.rb', line 68 def longest [w, h, d].max end |
#to_s ⇒ Object
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 |