Method: MagicCloud::Layouter::Place#initialize

Defined in:
lib/magic_cloud/layouter/place.rb

#initialize(layouter, shape) ⇒ Place

rubocop:todo Metrics/AbcSize



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/magic_cloud/layouter/place.rb', line 13

def initialize(layouter, shape) # rubocop:todo Metrics/AbcSize
  @layouter, @shape = layouter, shape

  # initial position
  @start_x = (@layouter.width/2-@shape.width/2).to_i
  @start_y = (@layouter.height/2-@shape.height/2).to_i

  # when shift of position is more than max delta (diagonal of cloud)
  # there is no hope it will eventually found its place
  @max_delta = Math.sqrt(@layouter.width**2 + @layouter.height**2)

  # algo of next position calc
  @spiral = make_spiral(@shape.size)

  # direction of spiral
  @dt = rand < 0.5 ? 1 : -1 

  # initial point of time before we start to look for place
  @t = -@dt
end