Class: Clusto::Cluster

Inherits:
Object
  • Object
show all
Defined in:
lib/clusto/cluster.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location) ⇒ Cluster

Returns a new instance of Cluster.



5
6
7
8
# File 'lib/clusto/cluster.rb', line 5

def initialize(location)
  @location = location
  @points = []
end

Instance Attribute Details

#locationObject

Returns the value of attribute location.



3
4
5
# File 'lib/clusto/cluster.rb', line 3

def location
  @location
end

#pointsObject

Returns the value of attribute points.



3
4
5
# File 'lib/clusto/cluster.rb', line 3

def points
  @points
end

Instance Method Details

#repositionObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/clusto/cluster.rb', line 10

def reposition
  return if @points.empty?
  
  x = 0
  y = 0
  center = @location
  
  @points.each do |point|
    x += point.x
    y += point.y
  end

  x /= points.length
  y /= points.length
  
  @location = Clusto::Point.new(x, y)
end