Class: Geoptima::Point
- Inherits:
-
Object
- Object
- Geoptima::Point
- Defined in:
- lib/geoptima/locationrange.rb
Instance Attribute Summary collapse
-
#latitude ⇒ Object
readonly
Returns the value of attribute latitude.
-
#longitude ⇒ Object
readonly
Returns the value of attribute longitude.
Instance Method Summary collapse
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #<(other) ⇒ Object
- #<=(other) ⇒ Object
- #>(other) ⇒ Object
- #>=(other) ⇒ Object
- #distance(other) ⇒ Object
-
#initialize(latitude, longitude) ⇒ Point
constructor
A new instance of Point.
- #to_s ⇒ Object
Constructor Details
#initialize(latitude, longitude) ⇒ Point
Returns a new instance of Point.
7 8 9 10 |
# File 'lib/geoptima/locationrange.rb', line 7 def initialize(latitude,longitude) @latitude = latitude.to_f @longitude = longitude.to_f end |
Instance Attribute Details
#latitude ⇒ Object (readonly)
Returns the value of attribute latitude.
6 7 8 |
# File 'lib/geoptima/locationrange.rb', line 6 def latitude @latitude end |
#longitude ⇒ Object (readonly)
Returns the value of attribute longitude.
6 7 8 |
# File 'lib/geoptima/locationrange.rb', line 6 def longitude @longitude end |
Instance Method Details
#+(other) ⇒ Object
28 29 30 31 32 |
# File 'lib/geoptima/locationrange.rb', line 28 def +(other) other.respond_to?('latitude') ? Point.new(self.latitude + other.latitude, self.longitude + other.longitude) : Point.new(self.latitude + other.to_f, self.longitude + other.to_f) end |
#-(other) ⇒ Object
23 24 25 26 27 |
# File 'lib/geoptima/locationrange.rb', line 23 def -(other) other.respond_to?('latitude') ? Point.new(self.latitude - other.latitude, self.longitude - other.longitude) : Point.new(self.latitude - other.to_f, self.longitude - other.to_f) end |
#<(other) ⇒ Object
14 15 16 |
# File 'lib/geoptima/locationrange.rb', line 14 def <(other) self.latitude - other.latitude < 0 && self.longitude - other.longitude < 0 end |
#<=(other) ⇒ Object
20 21 22 |
# File 'lib/geoptima/locationrange.rb', line 20 def <=(other) self.latitude - other.latitude <= 0 && self.longitude - other.longitude <= 0 end |
#>(other) ⇒ Object
11 12 13 |
# File 'lib/geoptima/locationrange.rb', line 11 def >(other) self.latitude - other.latitude > 0 && self.longitude - other.longitude > 0 end |
#>=(other) ⇒ Object
17 18 19 |
# File 'lib/geoptima/locationrange.rb', line 17 def >=(other) self.latitude - other.latitude >= 0 && self.longitude - other.longitude >= 0 end |
#distance(other) ⇒ Object
33 34 35 |
# File 'lib/geoptima/locationrange.rb', line 33 def distance(other) Math.sqrt( (self.latitude-other.latitude)**2 + (self.longitude-other.longitude)**2 ) end |
#to_s ⇒ Object
36 37 38 |
# File 'lib/geoptima/locationrange.rb', line 36 def to_s [@latitude,@longitude].inspect end |