Class: Geoptima::LocationDistance

Inherits:
LocationRange show all
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

Attributes inherited from LocationRange

#max, #min

Instance Method Summary collapse

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

#centerObject (readonly)

Returns the value of attribute center.



106
107
108
# File 'lib/geoptima/locationrange.rb', line 106

def center
  @center
end

#distanceObject (readonly)

Returns the value of attribute distance.



106
107
108
# File 'lib/geoptima/locationrange.rb', line 106

def distance
  @distance
end

#distance_in_kmObject (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

Returns:

  • (Boolean)


115
116
117
# File 'lib/geoptima/locationrange.rb', line 115

def include?(point)
  super(point) && center.distance(point) < distance
end

#to_sObject



118
119
120
# File 'lib/geoptima/locationrange.rb', line 118

def to_s
  super.to_s+",(#{distance},#{center})"
end