Class: GpsUtils::BoundingBox
- Inherits:
-
Object
- Object
- GpsUtils::BoundingBox
- Defined in:
- lib/gpsutils.rb
Instance Attribute Summary collapse
-
#nw ⇒ Point
readonly
South-East corner.
-
#se ⇒ Point
readonly
South-East corner.
Instance Method Summary collapse
-
#cover?(point) ⇒ Boolean
Determine whether point is inside bounding box.
-
#initialize(nw_point, se_point) ⇒ BoundingBox
constructor
Initialize BoundingBox.
Constructor Details
#initialize(nw_point, se_point) ⇒ BoundingBox
Initialize BoundingBox.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# 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 |
Instance Attribute Details
#nw ⇒ Point (readonly)
Returns South-East corner.
71 72 73 |
# File 'lib/gpsutils.rb', line 71 def nw @nw end |
#se ⇒ Point (readonly)
Returns South-East corner.
75 76 77 |
# File 'lib/gpsutils.rb', line 75 def se @se end |
Instance Method Details
#cover?(point) ⇒ Boolean
Determine whether point is inside bounding box.
103 104 105 106 107 108 109 110 |
# 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 |