Class: Laser::Cutter::Sloped::Box

Inherits:
Object
  • Object
show all
Defined in:
lib/laser/cutter/sloped/box.rb

Overview

A box whose front slopes back, drawn as seven panels. It answers what the renderers ask of a Box: the lines to cut, the rectangle that encloses them, and room for the metadata.

The panels come from Panels, each in its own frame and without kerf. Here each one is grown by half the kerf, so it is cut to size, and moved to its place on the sheet.

Constant Summary collapse

LIDS =

How the tilted panel joins the side walls: notched into both, or lying on them.

%i[full plain].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Box

Returns a new instance of Box.

Parameters:

  • config (Configuration, Hash) —

    width, height, depth, front_height, slope, thickness, and optionally notch, kerf, padding and lid

Raises:



28
29
30
31
32
33
# File 'lib/laser/cutter/sloped/box.rb', line 28

def initialize(config)
  @config = config
  @profile = Profile.new(depth: config[:depth], height: config[:height], front_height: config[:front_height],
                         slope: config[:slope], thickness: config[:thickness])
  @metadata = Geometry::Point[0, 0]
end

Instance Attribute Details

#metadata ⇒ Geometry::Point

Returns the size of the metadata block the layout keeps clear.

Returns:

  • (Geometry::Point) —

    the size of the metadata block the layout keeps clear



23
24
25
# File 'lib/laser/cutter/sloped/box.rb', line 23

def 
  @metadata
end

#profile ⇒ Profile (readonly)

Returns the side view of the box.

Returns:

  • (Profile) —

    the side view of the box



20
21
22
# File 'lib/laser/cutter/sloped/box.rb', line 20

def profile
  @profile
end

Instance Method Details

#enclosure ⇒ Geometry::Rect

Returns the smallest rectangle around every line.

Returns:



60
61
62
63
64
65
66
67
# File 'lib/laser/cutter/sloped/box.rb', line 60

def enclosure
  @enclosure ||= begin
    points = generate_notches.flat_map { |line| [line.p1, line.p2] }
    xs = points.map(&:x)
    ys = points.map(&:y)
    Geometry::Rect[Geometry::Point[xs.min, ys.min], Geometry::Point[xs.max, ys.max]]
  end
end

#generate_notches ⇒ Array<Geometry::Line> Also known as: notches

Returns every line to cut.

Returns:



54
55
56
# File 'lib/laser/cutter/sloped/box.rb', line 54

def generate_notches
  outlines.values.flatten
end

#outlines ⇒ Hash{String => Array<Geometry::Line>}

Returns the lines to cut for each panel, by its name.

Returns:

  • (Hash{String => Array<Geometry::Line>}) —

    the lines to cut for each panel, by its name



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

def outlines
  @outlines ||= begin
    placements = layout.placements
    panels.to_h.to_h do |name, loop|
      [name, loop.map { |point| placements[name].apply(point) }.grow(kerf / 2.0).lines]
    end
  end
end