Class: BB::BoundingBox

Inherits:
BaseBoundingBox show all
Defined in:
lib/bounding_boxes/bounding_box.rb

Overview

can create any type of bounding box and will be able to split it into an array of bounding boxes

Instance Attribute Summary collapse

Attributes inherited from BaseBoundingBox

#max, #min, #preferred_units

Instance Method Summary collapse

Methods inherited from BaseBoundingBox

#fetch, #height, #max_lat, #max_long, #method_missing, #min_lat, #min_long, #side_length, #width

Constructor Details

#initialize(options = {}) ⇒ BoundingBox

Returns a new instance of BoundingBox.



6
7
8
9
10
11
12
13
14
# File 'lib/bounding_boxes/bounding_box.rb', line 6

def initialize(options = {})
  if options.has_key?(:radius)
    build_point_bounding_box(options)
  elsif options.has_key?(:side_length)
    build_square_bounding_box(options)
  elsif options.size == 5 && options.key_present?(:units)
    build_base_bounding_box(options)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class BB::BaseBoundingBox

Instance Attribute Details

#boxObject

Returns the value of attribute box.



5
6
7
# File 'lib/bounding_boxes/bounding_box.rb', line 5

def box
  @box
end

Instance Method Details

#split_geo(max_size) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/bounding_boxes/bounding_box.rb', line 16

def split_geo(max_size)
  raise "split size greater than width or height" unless self.width > max_size && self.height > max_size
  rows = (self.height / max_size).to_i
  columns = (self.width / max_size).to_i

  split_width = self.width / columns
  split_height = self.height / rows

  temp_array = []
  temp_lat = self.min_lat
  temp_long = self.min_long

  (rows - 1).times do |row_num| 
    (columns - 1).times do |column_num| 
      temp_array << BB::SquareBoundingBox.new(temp_lat,
                                              temp_long,
                                              "#{max_size}#{self.preferred_units}" )
      temp_long = temp_array.last.max_long
    end
    temp_lat = temp_array.last.max_lat
    temp_long = self.min_long
  end
  temp_array
end