Parent

Geokit::Bounds

Bounds represents a rectangular bounds, defined by the SW and NE corners

Attributes

sw[RW]

sw and ne are LatLng objects

ne[RW]

sw and ne are LatLng objects

Public Class Methods

from_point_and_radius(point,radius,options={}) click to toggle source

returns an instance of bounds which completely encompases the given circle

     # File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 498
498:       def from_point_and_radius(point,radius,options={})
499:         point=LatLng.normalize(point)
500:         p0=point.endpoint(0,radius,options)
501:         p90=point.endpoint(90,radius,options)
502:         p180=point.endpoint(180,radius,options)
503:         p270=point.endpoint(270,radius,options)
504:         sw=Geokit::LatLng.new(p180.lat,p270.lng)
505:         ne=Geokit::LatLng.new(p0.lat,p90.lng)
506:         Geokit::Bounds.new(sw,ne)
507:       end
new(sw,ne) click to toggle source

provide sw and ne to instantiate a new Bounds instance

     # File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 441
441:     def initialize(sw,ne)
442:       raise ArgumentError if !(sw.is_a?(Geokit::LatLng) && ne.is_a?(Geokit::LatLng))
443:       @sw,@ne=sw,ne
444:     end
normalize(thing,other=nil) click to toggle source

Takes two main combinations of arguments 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 /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 515
515:       def normalize (thing,other=nil)   
516:         # maybe this will be simple -- an actual bounds object is passed, and we can all go home
517:         return thing if thing.is_a? Bounds
518:         
519:         # no? OK, if there's no "other," the thing better be a two-element array        
520:         thing,other=thing if !other && thing.is_a?(Array) && thing.size==2
521: 
522:         # Now that we're set with a thing and another thing, let LatLng do the heavy lifting.
523:         # Exceptions may be thrown
524:         Bounds.new(Geokit::LatLng.normalize(thing),Geokit::LatLng.normalize(other))
525:       end

Public Instance Methods

==(other) click to toggle source

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 /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 481
481:     def ==(other)
482:       other.is_a?(Bounds) ? self.sw == other.sw && self.ne == other.ne : false
483:     end
center() click to toggle source

returns the a single point which is the center of the rectangular bounds

     # File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 447
447:     def center
448:       @sw.midpoint_to(@ne)
449:     end
contains?(point) click to toggle source

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

     # File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 463
463:     def contains?(point)
464:       point=Geokit::LatLng.normalize(point)
465:       res = point.lat > @sw.lat && point.lat < @ne.lat
466:       if crosses_meridian?
467:         res &= point.lng < @ne.lng || point.lng > @sw.lng
468:       else
469:         res &= point.lng < @ne.lng && point.lng > @sw.lng
470:       end
471:       res
472:     end
crosses_meridian?() click to toggle source

returns true if the bounds crosses the international dateline

     # File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 475
475:     def crosses_meridian?
476:       @sw.lng > @ne.lng 
477:     end
to_a() click to toggle source

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

     # File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 457
457:     def to_a
458:       [@sw.to_a, @ne.to_a]
459:     end
to_s() click to toggle source

a simple string representation:sw,ne

     # File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 452
452:     def to_s
453:       "#{@sw.to_s},#{@ne.to_s}"   
454:     end
to_span() click to toggle source

Equivalent to Google Maps API’s .toSpan() method on GLatLng’s.

Returns a LatLng object, whose coordinates represent the size of a rectangle defined by these bounds.

     # File /Users/andre/projects/rails/geokit/lib/geokit/mappable.rb, line 489
489:     def to_span
490:       lat_span = (@ne.lat - @sw.lat).abs
491:       lng_span = (crosses_meridian? ? 360 + @ne.lng - @sw.lng : @ne.lng - @sw.lng).abs
492:       Geokit::LatLng.new(lat_span, lng_span)
493:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.