Class: Geoptima::LocationDistance
- Inherits:
-
LocationRange
- Object
- LocationRange
- Geoptima::LocationDistance
- Defined in:
- lib/geoptima/locationrange.rb
Overview
Note that this class does the distance calculation based on a direct translation of distance at the equator. This will be inaccurate far from the equator.
Instance Attribute Summary collapse
-
#center ⇒ Object
readonly
Returns the value of attribute center.
-
#distance ⇒ Object
readonly
Returns the value of attribute distance.
-
#distance_in_km ⇒ Object
readonly
Returns the value of attribute distance_in_km.
Attributes inherited from LocationRange
Instance Method Summary collapse
- #include?(point) ⇒ Boolean
-
#initialize(distance_in_km, center) ⇒ LocationDistance
constructor
A new instance of LocationDistance.
- #to_s ⇒ Object
Methods inherited from LocationRange
everywhere, from, #initialize_min_max, test
Constructor Details
#initialize(distance_in_km, center) ⇒ LocationDistance
Returns a new instance of LocationDistance.
107 108 109 110 111 |
# File 'lib/geoptima/locationrange.rb', line 107 def initialize(distance_in_km,center) @distance_in_km = distance_in_km.to_f @center = center initialize_min_max(@center - distance, @center + distance) end |
Instance Attribute Details
#center ⇒ Object (readonly)
Returns the value of attribute center.
106 107 108 |
# File 'lib/geoptima/locationrange.rb', line 106 def center @center end |
#distance ⇒ Object (readonly)
Returns the value of attribute distance.
106 107 108 |
# File 'lib/geoptima/locationrange.rb', line 106 def distance @distance end |
#distance_in_km ⇒ Object (readonly)
Returns the value of attribute distance_in_km.
106 107 108 |
# File 'lib/geoptima/locationrange.rb', line 106 def distance_in_km @distance_in_km end |
Instance Method Details
#include?(point) ⇒ Boolean
115 116 117 |
# File 'lib/geoptima/locationrange.rb', line 115 def include?(point) super(point) && center.distance(point) < distance end |
#to_s ⇒ Object
118 119 120 |
# File 'lib/geoptima/locationrange.rb', line 118 def to_s super.to_s+",(#{distance},#{center})" end |