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

Methods

Attributes

ne  [RW]  sw and ne are LatLng objects
sw  [RW]  sw and ne are LatLng objects

Public Class methods

returns an instance of bounds which completely encompases the given circle

[Source]

     # 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

provide sw and ne to instantiate a new Bounds instance

[Source]

     # File vendor/plugins/geokit/lib/geo_kit/mappable.rb, line 355
355:     def initialize(sw,ne)
356:       raise ArguementError if !(sw.is_a?(GeoKit::LatLng) && ne.is_a?(GeoKit::LatLng))
357:       @sw,@ne=sw,ne
358:     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

[Source]

     # 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

Public Instance methods

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.

[Source]

     # 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 the a single point which is the center of the rectangular bounds

[Source]

     # File vendor/plugins/geokit/lib/geo_kit/mappable.rb, line 361
361:     def center
362:       @sw.midpoint_to(@ne)
363:     end

Returns true if the bounds contain the passed point. allows for bounds which cross the meridian

[Source]

     # 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

[Source]

     # File vendor/plugins/geokit/lib/geo_kit/mappable.rb, line 389
389:     def crosses_meridian?
390:       @sw.lng > @ne.lng 
391:     end

a two-element array of two-element arrays: sw,ne

[Source]

     # File vendor/plugins/geokit/lib/geo_kit/mappable.rb, line 371
371:     def to_a
372:       [@sw.to_a, @ne.to_a]
373:     end

a simple string representation:sw,ne

[Source]

     # File vendor/plugins/geokit/lib/geo_kit/mappable.rb, line 366
366:     def to_s
367:       "#{@sw.to_s},#{@ne.to_s}"   
368:     end

[Validate]