Class: KMeansPP::BasePoint

Inherits:
Object
  • Object
show all
Defined in:
lib/k_means_pp/point.rb

Overview

Common methods for Point and Centroid.

Direct Known Subclasses

Centroid, Point

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#xFloat

X coordinate of the point.

Returns:

  • (Float)


7
8
9
# File 'lib/k_means_pp/point.rb', line 7

def x
  @x
end

#yFloat

Y coordinate of the point.

Returns:

  • (Float)


12
13
14
# File 'lib/k_means_pp/point.rb', line 12

def y
  @y
end

Instance Method Details

#squared_distance_to(point) ⇒ Float

Measure a 2D squared distance between two points.

Parameters:

Returns:

  • (Float)


19
20
21
22
23
24
# File 'lib/k_means_pp/point.rb', line 19

def squared_distance_to(point)
  distance_x       = x - point.x
  distance_y       = y - point.y
  squared_distance = distance_x**2 + distance_y**2
  squared_distance
end

#to_sObject

A string representation of the point.



27
28
29
# File 'lib/k_means_pp/point.rb', line 27

def to_s
  "(#{ x }, #{ y })"
end