Class: KDTree::HyperRect
- Inherits:
-
Object
- Object
- KDTree::HyperRect
- Defined in:
- lib/kd_tree/hyper_rect.rb
Instance Attribute Summary collapse
-
#maxima ⇒ Object
Returns the value of attribute maxima.
-
#minima ⇒ Object
Returns the value of attribute minima.
Instance Method Summary collapse
- #clone ⇒ Object
- #cut(dim, pivot) ⇒ Object
-
#initialize(k) ⇒ HyperRect
constructor
A new instance of HyperRect.
- #intersects?(target, radius, metric) ⇒ Boolean
Constructor Details
#initialize(k) ⇒ HyperRect
Returns a new instance of HyperRect.
4 5 6 7 8 9 10 11 |
# File 'lib/kd_tree/hyper_rect.rb', line 4 def initialize(k) @minima = [] @maxima = [] k.times do |i| @minima << -Float::INFINITY @maxima << Float::INFINITY end end |
Instance Attribute Details
#maxima ⇒ Object
Returns the value of attribute maxima.
3 4 5 |
# File 'lib/kd_tree/hyper_rect.rb', line 3 def maxima @maxima end |
#minima ⇒ Object
Returns the value of attribute minima.
3 4 5 |
# File 'lib/kd_tree/hyper_rect.rb', line 3 def minima @minima end |
Instance Method Details
#clone ⇒ Object
13 14 15 16 17 18 |
# File 'lib/kd_tree/hyper_rect.rb', line 13 def clone cl = self.class.new @minima.length cl.minima = @minima.clone cl.maxima = @maxima.clone cl end |
#cut(dim, pivot) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/kd_tree/hyper_rect.rb', line 20 def cut(dim, pivot) left_hr = self.clone left_hr.maxima[dim] = pivot right_hr = self.clone right_hr.minima[dim] = pivot [left_hr, right_hr] end |
#intersects?(target, radius, metric) ⇒ Boolean
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/kd_tree/hyper_rect.rb', line 28 def intersects?(target, radius, metric) near_point = KDTree::Point.new target.length.times do |i| if target[i] <= @minima[i] coord = @minima[i] elsif @minima[i] < target[i] && target[i] < @maxima[i] coord = target[i] else coord = @maxima[i] end near_point[i] = coord end near_point.distance_from(target, metric) <= radius end |