class GpsUtils::BoundingBox
Attributes
nw[R]
@!attribute [r] nw
@return [Point] North-West corner
se[R]
@!attribute [r] nw
@return [Point] South-East corner
Public Class Methods
new(nw_point, se_point)
click to toggle source
Initialize BoundingBox
.
@param nw_point [Point] North-West corner @param se_point [Point] South-East corner
# File lib/gpsutils.rb, line 81 def initialize(nw_point, se_point) unless nw_point.is_a? Point raise ArgumentError.new 'nw_point must be a Point.' end unless se_point.is_a? Point raise ArgumentError.new 'se_point must be a Point.' end @nw = nw_point @se = se_point @p21 = @se.lat - @nw.lat @p41 = @nw.lng - @se.lng @p21ms = @p21 ** 2 @p41ms = @p41 ** 2 end
Public Instance Methods
cover?(point)
click to toggle source
Determine whether point is inside bounding box.
@param point [Point]
# File lib/gpsutils.rb, line 103 def cover?(point) p = [point.lat - @nw.lat, point.lng - @se.lng] p21x = p[0] * @p21 p41x = p[1] * @p41 0 < p21x and p21x < @p21ms and 0 <= p41x and p41x <= @p41ms end