Class: MagicCloud::Layouter

Inherits:
Object
  • Object
show all
Defined in:
lib/magic_cloud/layouter.rb,
lib/magic_cloud/layouter/place.rb

Overview

Main magic of magic cloud - layouting shapes without collisions. Also, alongside with CollisionBoard - the slowest and algorithmically trickiest part.

Defined Under Namespace

Classes: Place, PlaceNotFound

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(w, h, options = {}) ⇒ Layouter

Returns a new instance of Layouter.



10
11
12
13
14
# File 'lib/magic_cloud/layouter.rb', line 10

def initialize(w, h, options = {})
  @board = CollisionBoard.new(w, h)

  @options = options
end

Instance Attribute Details

#boardObject (readonly)

Returns the value of attribute board.



16
17
18
# File 'lib/magic_cloud/layouter.rb', line 16

def board
  @board
end

Instance Method Details

#heightObject



22
23
24
# File 'lib/magic_cloud/layouter.rb', line 22

def height
  board.height
end

#layout!(shapes) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/magic_cloud/layouter.rb', line 26

def layout!(shapes)
  visible_shapes = []

  shapes.each do |shape|
    next unless find_place(shape)

    visible_shapes.push(shape)
  end

  visible_shapes
end

#widthObject



18
19
20
# File 'lib/magic_cloud/layouter.rb', line 18

def width
  board.width
end