Class: Geomodel::Types::Point

Inherits:
Object
  • Object
show all
Defined in:
lib/geomodel/geotypes.rb

Overview

A two-dimensional point in the [-90,90] x [-180,180] lat/lon space.

Attributes:

lat: A float in the range [-90,90] indicating the point's latitude.
lon: A float in the range [-180,180] indicating the point's longitude.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(latitude, longitude) ⇒ Point

Returns a new instance of Point.



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/geomodel/geotypes.rb', line 16

def initialize(latitude, longitude)
  if -90 > latitude || latitude > 90
    raise ArgumentError.new("Latitude must be in [-90, 90]") 
  else
    @latitude = latitude
  end 
  
  if -180 > longitude || longitude > 180
    raise ArgumentError.new("Longitude must be in [-180, 180]") 
  else
    @longitude = longitude
  end        
end

Instance Attribute Details

#latitudeObject Also known as: lat

Returns the value of attribute latitude.



11
12
13
# File 'lib/geomodel/geotypes.rb', line 11

def latitude
  @latitude
end

#longitudeObject Also known as: lon

Returns the value of attribute longitude.



11
12
13
# File 'lib/geomodel/geotypes.rb', line 11

def longitude
  @longitude
end

Instance Method Details

#==(point) ⇒ Object



30
31
32
# File 'lib/geomodel/geotypes.rb', line 30

def ==(point)
  (@latitude === point.latitude) && (@longitude === point.longitude)
end

#to_sObject



34
35
36
# File 'lib/geomodel/geotypes.rb', line 34

def to_s
  "(#{@latitude}, #{@longitude})"
end