class Geomodel::Types::Box

A two-dimensional rectangular region defined by NE and SW points.

Attributes:

north_east: A read-only geotypes.Point indicating the box's Northeast
    coordinate.
south_west: A read-only geotypes.Point indicating the box's Southwest
    coordinate.
north: A float indicating the box's North latitude.
east: A float indicating the box's East longitude.
south: A float indicating the box's South latitude.
west: A float indicating the box's West longitude.

Attributes

north_east[R]
south_west[R]

Public Class Methods

new(north, east, south, west) click to toggle source
# File lib/geomodel/geotypes.rb, line 55
def initialize(north, east, south, west)
  south, north = north, south if south > north
  
  # Don't swap east and west to allow disambiguation of
  # antimeridian crossing.
  @north_east = Point.new(north, east)
  @south_west = Point.new(south, west)
end

Public Instance Methods

==(box) click to toggle source
# File lib/geomodel/geotypes.rb, line 98
def ==(box)
  (@north_east === box.north_east) && (@south_west === box.south_west)
end
east() click to toggle source
# File lib/geomodel/geotypes.rb, line 86
def east
  @north_east.longitude
end
east=(east) click to toggle source
# File lib/geomodel/geotypes.rb, line 69
def east=(east)
  @north_east.longitude = east
end
north() click to toggle source
# File lib/geomodel/geotypes.rb, line 82
def north
  @north_east.latitude
end
north=(north) click to toggle source
# File lib/geomodel/geotypes.rb, line 64
def north=(north)
  raise ArgumentError.new("Latitude must be north of box's south latitude") if north < @south_west.latitude
  @north_east.latitude = north
end
south() click to toggle source
# File lib/geomodel/geotypes.rb, line 90
def south
  @south_west.latitude
end
south=(south) click to toggle source
# File lib/geomodel/geotypes.rb, line 73
def south=(south)
  raise ArgumentError.new("Latitude must be south of box's north latitude") if south > @south_west.latitude
  @south_west.latitude = south
end
to_s() click to toggle source
# File lib/geomodel/geotypes.rb, line 102
def to_s
  "(#{@north_east.latitude}, #{@north_east.longitude}, #{@south_west.latitude}, #{@south_west.longitude})"
end
west() click to toggle source
# File lib/geomodel/geotypes.rb, line 94
def west
  @south_west.longitude
end
west=(west) click to toggle source
# File lib/geomodel/geotypes.rb, line 78
def west=(west)
  @south_west.longitude = west
end