Class: Clusto::Cluster
- Inherits:
-
Object
- Object
- Clusto::Cluster
- Defined in:
- lib/clusto/cluster.rb
Instance Attribute Summary collapse
-
#location ⇒ Object
Returns the value of attribute location.
-
#points ⇒ Object
Returns the value of attribute points.
Instance Method Summary collapse
-
#initialize(location) ⇒ Cluster
constructor
A new instance of Cluster.
- #reposition ⇒ Object
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
#location ⇒ Object
Returns the value of attribute location.
3 4 5 |
# File 'lib/clusto/cluster.rb', line 3 def location @location end |
#points ⇒ Object
Returns the value of attribute points.
3 4 5 |
# File 'lib/clusto/cluster.rb', line 3 def points @points end |
Instance Method Details
#reposition ⇒ Object
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 |