Class: Warpaint::OrderedCollection

Inherits:
RBTree
  • Object
show all
Defined in:
lib/warpaint/ordered_collection.rb

Direct Known Subclasses

NetworkCollection, PointCollection

Instance Method Summary collapse

Instance Method Details

#closest_to(key) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/warpaint/ordered_collection.rb', line 5

def closest_to(key)
  lower = lower_bound(key)
  upper = upper_bound(key)

  return upper if lower.nil?
  return lower if upper.nil?

  (upper[0] - key).abs > (lower[0] - key).abs ? lower : upper
end