Class: KMeansPP::BasePoint
- Inherits:
-
Object
- Object
- KMeansPP::BasePoint
- Defined in:
- lib/k_means_pp/point.rb
Overview
Common methods for Point
and Centroid
.
Instance Attribute Summary collapse
-
#x ⇒ Float
X coordinate of the point.
-
#y ⇒ Float
Y coordinate of the point.
Instance Method Summary collapse
-
#squared_distance_to(point) ⇒ Float
Measure a 2D squared distance between two points.
-
#to_s ⇒ Object
A string representation of the point.
Instance Attribute Details
#x ⇒ Float
X coordinate of the point.
7 8 9 |
# File 'lib/k_means_pp/point.rb', line 7 def x @x end |
#y ⇒ Float
Y coordinate of the point.
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.
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_s ⇒ Object
A string representation of the point.
27 28 29 |
# File 'lib/k_means_pp/point.rb', line 27 def to_s "(#{x}, #{y})" end |