Class: BinPacking::Heuristics::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/bin_packing/heuristics/base.rb

Instance Method Summary collapse

Instance Method Details

#find_position_for_new_node!(box, free_rectangles) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/bin_packing/heuristics/base.rb', line 4

def find_position_for_new_node!(box, free_rectangles)
  best_score = BinPacking::Score.new
  width = box.width
  height = box.height

  free_rectangles.each do |free_rect|
    try_place_rect_in(free_rect, box, width, height, best_score)

    if box.can_rotate?
      try_place_rect_in(free_rect, box, height, width, best_score)
    end
  end

  best_score
end