| Class | GeoKit::Bounds |
| In: |
vendor/plugins/geokit/lib/geo_kit/mappable.rb
|
| Parent: | Object |
Bounds represents a rectangular bounds, defined by the SW and NE corners
returns an instance of bounds which completely encompases the given circle
# File vendor/plugins/geokit/lib/geo_kit/mappable.rb, line 402
402: def from_point_and_radius(point,radius,options={})
403: point=LatLng.normalize(point)
404: p0=point.endpoint(0,radius,options)
405: p90=point.endpoint(90,radius,options)
406: p180=point.endpoint(180,radius,options)
407: p270=point.endpoint(270,radius,options)
408: sw=GeoKit::LatLng.new(p180.lat,p270.lng)
409: ne=GeoKit::LatLng.new(p0.lat,p90.lng)
410: GeoKit::Bounds.new(sw,ne)
411: end
Takes two main combinations of arguements to create a bounds: point,point (this is the only one which takes two arguments [point,point] . . . where a point is anything LatLng#normalize can handle (which is quite a lot)
NOTE: everything combination is assumed to pass points in the order sw, ne
# File vendor/plugins/geokit/lib/geo_kit/mappable.rb, line 419
419: def normalize (thing,other=nil)
420: # maybe this will be simple -- an actual bounds object is passed, and we can all go home
421: return thing if thing.is_a? Bounds
422:
423: # no? OK, if there's no "other," the thing better be a two-element array
424: thing,other=thing if !other && thing.is_a?(Array) && thing.size==2
425:
426: # Now that we're set with a thing and another thing, let LatLng do the heavy lifting.
427: # Exceptions may be thrown
428: Bounds.new(GeoKit::LatLng.normalize(thing),GeoKit::LatLng.normalize(other))
429: end
Returns true if the candidate object is logically equal. Logical equivalence is true if the lat and lng attributes are the same for both objects.
# File vendor/plugins/geokit/lib/geo_kit/mappable.rb, line 395
395: def ==(other)
396: other.is_a?(Bounds) ? self.sw == other.sw && self.ne == other.ne : false
397: end
Returns true if the bounds contain the passed point. allows for bounds which cross the meridian
# File vendor/plugins/geokit/lib/geo_kit/mappable.rb, line 377
377: def contains?(point)
378: point=GeoKit::LatLng.normalize(point)
379: res = point.lat > @sw.lat && point.lat < @ne.lat
380: if crosses_meridian?
381: res &= point.lng < @ne.lng || point.lng > @sw.lng
382: else
383: res &= point.lng < @ne.lng && point.lng > @sw.lng
384: end
385: res
386: end
returns true if the bounds crosses the international dateline
# File vendor/plugins/geokit/lib/geo_kit/mappable.rb, line 389
389: def crosses_meridian?
390: @sw.lng > @ne.lng
391: end