lib/terraformer/bounds.rb in terraformer-0.0.1 vs lib/terraformer/bounds.rb in terraformer-0.0.2

- old
+ new

@@ -3,11 +3,11 @@ module Bounds class << self def bounds obj, format = :bbox - obj = Terraformer.parse obj unless Primitive === obj + obj = Terraformer.parse obj unless Geometry === obj bbox = case obj.type when 'Point' [ obj.coordinates[0], obj.coordinates[1], obj.coordinates[0], obj.coordinates[1] ] @@ -31,10 +31,12 @@ raise ArgumentError.new 'unknown type: ' + obj.type end case format when :bbox + # yikes! + bbox.extend BBox bbox when :polygon Polygon.new [[bbox[0], bbox[1]], [bbox[0], bbox[3]], [bbox[2], bbox[3]], @@ -49,18 +51,21 @@ if nesting > 0 array.reduce box do |b, a| bounds_for_array a, (nesting - 1), b end else - array.reduce box do |b, lonlat| + bbox = array.reduce box do |b, lonlat| lon, lat = *lonlat set = ->(d, i, t){ b[i] = d if b[i].nil? or d.send(t, b[i]) } set[lon, X1, :<] set[lon, X2, :>] set[lat, Y1, :<] set[lat, Y2, :>] b end + # yikes! + bbox.extend BBox + bbox end end def bounds_for_feature_collection fc bounds_for_collection fc.features, &:geometry