Class: GeoMagic::Rectangle

Inherits:
Object
  • Object
show all
Defined in:
lib/geo_magic/rectangle.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(point_a, point_b) ⇒ Rectangle

Returns a new instance of Rectangle.



5
6
7
8
# File 'lib/geo_magic/rectangle.rb', line 5

def initialize point_a, point_b
  @top_left_point     = GeoMagic::Point.new left_lat(point_a, point_b), bot_long(point_a, point_b)
  @bottom_right_point = GeoMagic::Point.new right_lat(point_a, point_b), top_long(point_a, point_b)
end

Instance Attribute Details

#bottom_right_pointObject

Returns the value of attribute bottom_right_point.



3
4
5
# File 'lib/geo_magic/rectangle.rb', line 3

def bottom_right_point
  @bottom_right_point
end

#top_left_pointObject

Returns the value of attribute top_left_point.



3
4
5
# File 'lib/geo_magic/rectangle.rb', line 3

def top_left_point
  @top_left_point
end

Class Method Details

.create_from_coords(lat1, long1, lat2, long2) ⇒ Object



10
11
12
# File 'lib/geo_magic/rectangle.rb', line 10

def self.create_from_coords lat1, long1, lat2, long2
  self.new GeoMagic::Point.new(lat1, long1), GeoMagic::Point.new(lat2, long2)
end

Instance Method Details

#overlaps?(point) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
# File 'lib/geo_magic/rectangle.rb', line 14

def overlaps? point
  # puts "inside_top_left?: #{point} -> #{inside_top_left?(point)}"
  # puts "inside_bottom_right?: #{point} -> #{inside_bottom_right?(point)}"
  inside_top_left?(point) && inside_bottom_right?(point)
end

#to_sObject



20
21
22
# File 'lib/geo_magic/rectangle.rb', line 20

def to_s
  "#{top_left_point} - #{bottom_right_point}"
end