Class: KDTree::Point
- Inherits:
-
Array
- Object
- Array
- KDTree::Point
- Defined in:
- lib/kd_tree/point.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
3 4 5 |
# File 'lib/kd_tree/point.rb', line 3 def data @data end |
Instance Method Details
#distance_from(target, metric) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/kd_tree/point.rb', line 5 def distance_from(target, metric) i = 0 case metric when :euclidean self.inject(0) do |acc, el| dist = acc + ((el-target[i])**2.0) i += 1 dist end when :manhattan self.inject(0) do |acc, el| dist = acc + (el-target[i]).abs i += 1 dist end when :chebyshev self.inject(0) do |acc, el| delt = (el-target[i]).abs dist = delt > acc ? delt : acc i += 1 dist end end end |