Class: Laser::Cutter::Box
- Inherits:
-
Object
- Object
- Laser::Cutter::Box
- Defined in:
- lib/laser/cutter/box.rb
Overview
A box of six panels: front, back, top (the lid), bottom, left and right. It lays them out on the page and notches every side so that neighbouring panels interlock. BoxFactory builds it unless the settings ask for a slope.
Lengths are unitless, in the units of the settings.
Constant Summary collapse
- LIDS =
How the lid, the top panel, joins the walls: notched on all four sides, on the side of the back wall only, or on none.
%i[full back plain].freeze
- LID_SIDES =
The side of each wall that meets the lid, as an index into Rect#sides.
{ 'front' => 0, 'left' => 0, 'right' => 0, 'back' => 2 }.freeze
Instance Attribute Summary collapse
-
#back ⇒ Geometry::Rect
The back panel.
-
#bottom ⇒ Geometry::Rect
The bottom panel.
-
#bounds ⇒ Object
Unused.
-
#conf ⇒ Hash
For each face, whether the center notch of its horizontal (:halign) and vertical (:valign) sides is a tab, and which faces carry the corner squares (:corners).
-
#corner_face ⇒ Symbol?
Unused: #generate_notches picks it each time.
-
#dim ⇒ Geometry::Dimensions
The inside width, height and depth.
-
#faces ⇒ Array<Geometry::Rect>
The six panels, in the order #conf indexes them.
-
#front ⇒ Geometry::Rect
The front panel.
-
#inside_box ⇒ Object?
Read from the settings, and not used in drawing.
-
#kerf ⇒ Float
The width the laser burns away.
-
#left ⇒ Geometry::Rect
The left panel.
-
#lid ⇒ Symbol
One of LIDS.
-
#metadata ⇒ Geometry::Point
The width and height kept free for the settings.
-
#notch_width ⇒ Float
The notch width asked for; each side fits its own.
-
#notches ⇒ Array<Geometry::Line>
Every line to cut, once generated.
-
#outlines ⇒ Hash{String => Array<Geometry::Line>}
The lines to cut for each face, by its name.
-
#padding ⇒ Float
The space between panels on the page.
-
#right ⇒ Geometry::Rect
The right panel.
-
#thickness ⇒ Float
The thickness of the material.
-
#top ⇒ Geometry::Rect
The top panel, the lid.
-
#units ⇒ String, Symbol
The units of every length.
Instance Method Summary collapse
-
#d ⇒ Float
The depth.
-
#enclosure ⇒ Geometry::Rect
The smallest rectangle around every line, generating the notches first if needed.
- #generate_notches ⇒ Array<Geometry::Line>
-
#h ⇒ Float
The height.
-
#initialize(config = {}) ⇒ Box
constructor
A new instance of Box.
-
#longest ⇒ Float
The longest dimension.
-
#to_s ⇒ String
The dimensions, thickness and notch width.
-
#w ⇒ Float
The width.
Constructor Details
#initialize(config = {}) ⇒ Box
Returns a new instance of Box.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/laser/cutter/box.rb', line 70 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 * longest / 5.0) self.kerf = config['kerf'] || 0.0 self.padding = config['padding'] self.units = config['units'] self.inside_box = config['inside_box'] self.lid = (config['lid'] || LIDS.first).to_sym self.notches = [] self.outlines = {} 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: { front: [:no, :yes, :no, :yes, :no, :no], # our default choice, but may not work top: [:yes, :no, :yes, :no, :no, :no] # 2nd choice, has to work if 1st doesn't }, } end |
Instance Attribute Details
#back ⇒ Geometry::Rect
Returns the back panel.
59 |
# File 'lib/laser/cutter/box.rb', line 59 attr_accessor :dim, :thickness, :notch_width, :kerf, :padding, :units, :inside_box, :front, :back, :top, :bottom, :left, :right, :faces, :bounds, :conf, :corner_face, :metadata, :notches |
#bottom ⇒ Geometry::Rect
Returns the bottom panel.
59 |
# File 'lib/laser/cutter/box.rb', line 59 attr_accessor :dim, :thickness, :notch_width, :kerf, :padding, :units, :inside_box, :front, :back, :top, :bottom, :left, :right, :faces, :bounds, :conf, :corner_face, :metadata, :notches |
#bounds ⇒ Object
Returns unused.
59 |
# File 'lib/laser/cutter/box.rb', line 59 attr_accessor :dim, :thickness, :notch_width, :kerf, :padding, :units, :inside_box, :front, :back, :top, :bottom, :left, :right, :faces, :bounds, :conf, :corner_face, :metadata, :notches |
#conf ⇒ Hash
Returns for each face, whether the center notch of its horizontal (:halign) and vertical (:valign) sides is a tab, and which faces carry the corner squares (:corners).
59 |
# File 'lib/laser/cutter/box.rb', line 59 attr_accessor :dim, :thickness, :notch_width, :kerf, :padding, :units, :inside_box, :front, :back, :top, :bottom, :left, :right, :faces, :bounds, :conf, :corner_face, :metadata, :notches |
#corner_face ⇒ Symbol?
Returns unused: #generate_notches picks it each time.
59 |
# File 'lib/laser/cutter/box.rb', line 59 attr_accessor :dim, :thickness, :notch_width, :kerf, :padding, :units, :inside_box, :front, :back, :top, :bottom, :left, :right, :faces, :bounds, :conf, :corner_face, :metadata, :notches |
#dim ⇒ Geometry::Dimensions
Returns the inside width, height and depth.
59 60 61 |
# File 'lib/laser/cutter/box.rb', line 59 def dim @dim end |
#faces ⇒ Array<Geometry::Rect>
Returns the six panels, in the order #conf indexes them.
59 |
# File 'lib/laser/cutter/box.rb', line 59 attr_accessor :dim, :thickness, :notch_width, :kerf, :padding, :units, :inside_box, :front, :back, :top, :bottom, :left, :right, :faces, :bounds, :conf, :corner_face, :metadata, :notches |
#front ⇒ Geometry::Rect
Returns the front panel.
59 |
# File 'lib/laser/cutter/box.rb', line 59 attr_accessor :dim, :thickness, :notch_width, :kerf, :padding, :units, :inside_box, :front, :back, :top, :bottom, :left, :right, :faces, :bounds, :conf, :corner_face, :metadata, :notches |
#inside_box ⇒ Object?
Returns read from the settings, and not used in drawing.
59 |
# File 'lib/laser/cutter/box.rb', line 59 attr_accessor :dim, :thickness, :notch_width, :kerf, :padding, :units, :inside_box, :front, :back, :top, :bottom, :left, :right, :faces, :bounds, :conf, :corner_face, :metadata, :notches |
#kerf ⇒ Float
Returns the width the laser burns away.
59 |
# File 'lib/laser/cutter/box.rb', line 59 attr_accessor :dim, :thickness, :notch_width, :kerf, :padding, :units, :inside_box, :front, :back, :top, :bottom, :left, :right, :faces, :bounds, :conf, :corner_face, :metadata, :notches |
#left ⇒ Geometry::Rect
Returns the left panel.
59 |
# File 'lib/laser/cutter/box.rb', line 59 attr_accessor :dim, :thickness, :notch_width, :kerf, :padding, :units, :inside_box, :front, :back, :top, :bottom, :left, :right, :faces, :bounds, :conf, :corner_face, :metadata, :notches |
#lid ⇒ Symbol
Returns one of LIDS.
62 63 64 |
# File 'lib/laser/cutter/box.rb', line 62 def lid @lid end |
#metadata ⇒ Geometry::Point
Returns the width and height kept free for the settings.
59 |
# File 'lib/laser/cutter/box.rb', line 59 attr_accessor :dim, :thickness, :notch_width, :kerf, :padding, :units, :inside_box, :front, :back, :top, :bottom, :left, :right, :faces, :bounds, :conf, :corner_face, :metadata, :notches |
#notch_width ⇒ Float
Returns the notch width asked for; each side fits its own.
59 |
# File 'lib/laser/cutter/box.rb', line 59 attr_accessor :dim, :thickness, :notch_width, :kerf, :padding, :units, :inside_box, :front, :back, :top, :bottom, :left, :right, :faces, :bounds, :conf, :corner_face, :metadata, :notches |
#notches ⇒ Array<Geometry::Line>
Returns every line to cut, once generated.
59 |
# File 'lib/laser/cutter/box.rb', line 59 attr_accessor :dim, :thickness, :notch_width, :kerf, :padding, :units, :inside_box, :front, :back, :top, :bottom, :left, :right, :faces, :bounds, :conf, :corner_face, :metadata, :notches |
#outlines ⇒ Hash{String => Array<Geometry::Line>}
Returns the lines to cut for each face, by its name.
65 66 67 |
# File 'lib/laser/cutter/box.rb', line 65 def outlines @outlines end |
#padding ⇒ Float
Returns the space between panels on the page.
59 |
# File 'lib/laser/cutter/box.rb', line 59 attr_accessor :dim, :thickness, :notch_width, :kerf, :padding, :units, :inside_box, :front, :back, :top, :bottom, :left, :right, :faces, :bounds, :conf, :corner_face, :metadata, :notches |
#right ⇒ Geometry::Rect
Returns the right panel.
59 |
# File 'lib/laser/cutter/box.rb', line 59 attr_accessor :dim, :thickness, :notch_width, :kerf, :padding, :units, :inside_box, :front, :back, :top, :bottom, :left, :right, :faces, :bounds, :conf, :corner_face, :metadata, :notches |
#thickness ⇒ Float
Returns the thickness of the material.
59 |
# File 'lib/laser/cutter/box.rb', line 59 attr_accessor :dim, :thickness, :notch_width, :kerf, :padding, :units, :inside_box, :front, :back, :top, :bottom, :left, :right, :faces, :bounds, :conf, :corner_face, :metadata, :notches |
#top ⇒ Geometry::Rect
Returns the top panel, the lid.
59 |
# File 'lib/laser/cutter/box.rb', line 59 attr_accessor :dim, :thickness, :notch_width, :kerf, :padding, :units, :inside_box, :front, :back, :top, :bottom, :left, :right, :faces, :bounds, :conf, :corner_face, :metadata, :notches |
#units ⇒ String, Symbol
Returns the units of every length.
59 |
# File 'lib/laser/cutter/box.rb', line 59 attr_accessor :dim, :thickness, :notch_width, :kerf, :padding, :units, :inside_box, :front, :back, :top, :bottom, :left, :right, :faces, :bounds, :conf, :corner_face, :metadata, :notches |
Instance Method Details
#d ⇒ Float
Returns the depth.
144 |
# File 'lib/laser/cutter/box.rb', line 144 def d; dim.d; end |
#enclosure ⇒ Geometry::Rect
Returns the smallest rectangle around every line, generating the notches first if needed.
101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/laser/cutter/box.rb', line 101 def enclosure generate_notches if 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 ⇒ Array<Geometry::Line>
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/laser/cutter/box.rb', line 119 def generate_notches position_faces! corner_face = pick_corners_face self.notches = [] self.outlines = {} faces.each_with_index do |face, face_index| edges = edges_of(face, face_index, corner_face) if edges.any?(&:corners) && !edges.all?(&:first_notch_out?) edges.each { |e| e.adjust_corners = true } end outlines[face.name] = Aggregator.new(lines_of(face, edges)).lines notches << outlines[face.name] end notches.flatten! end |
#h ⇒ Float
Returns the height.
141 |
# File 'lib/laser/cutter/box.rb', line 141 def h; dim.h; end |
#longest ⇒ Float
Returns the longest dimension.
147 148 149 |
# File 'lib/laser/cutter/box.rb', line 147 def longest [w, h, d].max end |
#to_s ⇒ String
Returns the dimensions, thickness and notch width.
152 153 154 |
# File 'lib/laser/cutter/box.rb', line 152 def to_s "Box:\nH:#{dim.h} W:#{dim.w} D:#{dim.d}\nThickness:#{thickness}, Notch:#{notch_width}" end |
#w ⇒ Float
Returns the width.
138 |
# File 'lib/laser/cutter/box.rb', line 138 def w; dim.w; end |