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.



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

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

  @options = options
end

Instance Attribute Details

#boardObject (readonly)

Returns the value of attribute board.



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

def board
  @board
end

Instance Method Details

#heightObject



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

def height
  board.height
end

#layout!(shapes) ⇒ Object



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

def layout!(shapes)
  visible_shapes = []

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

    visible_shapes.push(shape)
  end

  visible_shapes
end

#widthObject



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

def width
  board.width
end