Class: GPX::Bounds
Instance Attribute Summary collapse
-
#center_lat ⇒ Object
Returns the middle latitude.
-
#center_lon ⇒ Object
Returns the middle longitude.
-
#max_lat ⇒ Object
Returns the value of attribute max_lat.
-
#max_lon ⇒ Object
Returns the value of attribute max_lon.
-
#min_lat ⇒ Object
Returns the value of attribute min_lat.
-
#min_lon ⇒ Object
Returns the value of attribute min_lon.
Instance Method Summary collapse
-
#add(item) ⇒ Object
Adds an item to itself, expanding its min/max lat/lon as needed to contain the given item.
-
#contains?(pt) ⇒ Boolean
Returns true if the pt is within these bounds.
-
#initialize(opts = { :min_lat => 90.0, :max_lat => -90.0, :min_lon => 180.0, :max_lon => -180.0}) ⇒ Bounds
constructor
Creates a new bounds object with the passed-in min and max longitudes and latitudes.
-
#to_s ⇒ Object
Returns the min_lat, min_lon, max_lat, and max_lon in a labeled string.
Methods inherited from Base
#instantiate_with_text_elements
Constructor Details
#initialize(opts = { :min_lat => 90.0, :max_lat => -90.0, :min_lon => 180.0, :max_lon => -180.0}) ⇒ Bounds
Creates a new bounds object with the passed-in min and max longitudes and latitudes.
29 30 31 32 |
# File 'lib/gpx/bounds.rb', line 29 def initialize(opts = { :min_lat => 90.0, :max_lat => -90.0, :min_lon => 180.0, :max_lon => -180.0}) @min_lat, @max_lat = opts[:min_lat].to_f, opts[:max_lat].to_f @min_lon, @max_lon = opts[:min_lon].to_f, opts[:max_lon].to_f end |
Instance Attribute Details
#center_lat ⇒ Object
Returns the middle latitude.
35 36 37 |
# File 'lib/gpx/bounds.rb', line 35 def center_lat @center_lat end |
#center_lon ⇒ Object
Returns the middle longitude.
41 42 43 |
# File 'lib/gpx/bounds.rb', line 41 def center_lon @center_lon end |
#max_lat ⇒ Object
Returns the value of attribute max_lat.
25 26 27 |
# File 'lib/gpx/bounds.rb', line 25 def max_lat @max_lat end |
#max_lon ⇒ Object
Returns the value of attribute max_lon.
25 26 27 |
# File 'lib/gpx/bounds.rb', line 25 def max_lon @max_lon end |
#min_lat ⇒ Object
Returns the value of attribute min_lat.
25 26 27 |
# File 'lib/gpx/bounds.rb', line 25 def min_lat @min_lat end |
#min_lon ⇒ Object
Returns the value of attribute min_lon.
25 26 27 |
# File 'lib/gpx/bounds.rb', line 25 def min_lon @min_lon end |
Instance Method Details
#add(item) ⇒ Object
Adds an item to itself, expanding its min/max lat/lon as needed to contain the given item. The item can be either another instance of Bounds or a Point.
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/gpx/bounds.rb', line 54 def add(item) if(item.respond_to?(:lat) and item.respond_to?(:lon)) @min_lat = item.lat if item.lat < @min_lat @min_lon = item.lon if item.lon < @min_lon @max_lat = item.lat if item.lat > @max_lat @max_lon = item.lon if item.lon > @max_lon else @min_lat = item.min_lat if item.min_lat < @min_lat @min_lon = item.min_lon if item.min_lon < @min_lon @max_lat = item.max_lat if item.max_lat > @max_lat @max_lon = item.max_lon if item.max_lon > @max_lon end end |
#contains?(pt) ⇒ Boolean
Returns true if the pt is within these bounds.
47 48 49 |
# File 'lib/gpx/bounds.rb', line 47 def contains?(pt) (pt.lat >= min_lat and pt.lat <= max_lat and pt.lon >= min_lon and pt.lon <= max_lon) end |
#to_s ⇒ Object
Returns the min_lat, min_lon, max_lat, and max_lon in a labeled string.
69 70 71 |
# File 'lib/gpx/bounds.rb', line 69 def to_s "min_lat: #{min_lat} min_lon: #{min_lon} max_lat: #{max_lat} max_lon: #{max_lon}" end |