Class: RGeoServer::BoundingBox
- Inherits:
-
Object
- Object
- RGeoServer::BoundingBox
- Defined in:
- lib/rgeoserver/utils/boundingbox.rb
Constant Summary collapse
- @@epsilon =
0.0001
Instance Attribute Summary collapse
-
#maxx ⇒ Object
readonly
Returns the value of attribute maxx.
-
#maxy ⇒ Object
readonly
Returns the value of attribute maxy.
-
#minx ⇒ Object
readonly
Returns the value of attribute minx.
-
#miny ⇒ Object
readonly
Returns the value of attribute miny.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(point) ⇒ Object
- #add(x, y) ⇒ Object
- #area ⇒ Object
- #constrict(rate = @@epsilon) ⇒ Object
- #expand(rate = @@epsilon) ⇒ Object
- #height ⇒ Object
-
#initialize(options = {}) ⇒ BoundingBox
constructor
A new instance of BoundingBox.
- #inspect ⇒ Object
- #max ⇒ Object
- #min ⇒ Object
- #reset ⇒ Object
- #to_a ⇒ Object
- #to_geometry ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
-
#valid? ⇒ Boolean
True if bounding box has non-zero area.
- #width ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ BoundingBox
Returns a new instance of BoundingBox.
26 27 28 29 30 31 32 |
# File 'lib/rgeoserver/utils/boundingbox.rb', line 26 def initialize = {} reset if ['minx', 'miny', 'maxx', 'maxy'].all? {|k| .include?(k)} add ['minx'].to_f, ['miny'].to_f # SW add ['maxx'].to_f, ['maxx'].to_f # NE end end |
Instance Attribute Details
#maxx ⇒ Object (readonly)
Returns the value of attribute maxx.
5 6 7 |
# File 'lib/rgeoserver/utils/boundingbox.rb', line 5 def maxx @maxx end |
#maxy ⇒ Object (readonly)
Returns the value of attribute maxy.
5 6 7 |
# File 'lib/rgeoserver/utils/boundingbox.rb', line 5 def maxy @maxy end |
#minx ⇒ Object (readonly)
Returns the value of attribute minx.
5 6 7 |
# File 'lib/rgeoserver/utils/boundingbox.rb', line 5 def minx @minx end |
#miny ⇒ Object (readonly)
Returns the value of attribute miny.
5 6 7 |
# File 'lib/rgeoserver/utils/boundingbox.rb', line 5 def miny @miny end |
Class Method Details
.epsilon ⇒ Object
9 10 11 |
# File 'lib/rgeoserver/utils/boundingbox.rb', line 9 def self.epsilon @@epsilon end |
.epsilon=(value) ⇒ Object
13 14 15 |
# File 'lib/rgeoserver/utils/boundingbox.rb', line 13 def self.epsilon= value @@epsilon = value end |
.from_a(a) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/rgeoserver/utils/boundingbox.rb', line 18 def self.from_a a self.class.new Hash.new('minx' => a[0].to_f, 'miny' => a[1].to_f, 'maxx' => a[2].to_f, 'maxy' => a[3].to_f) end |
Instance Method Details
#<<(point) ⇒ Object
39 40 41 |
# File 'lib/rgeoserver/utils/boundingbox.rb', line 39 def << point add point[0], point[1] end |
#add(x, y) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rgeoserver/utils/boundingbox.rb', line 43 def add x, y if @empty @minx = @maxx = x @miny = @maxy = y end @minx = [minx, x].min @miny = [miny, y].min @maxx = [maxx, x].max @maxy = [maxy, y].max @empty = false end |
#area ⇒ Object
87 88 89 |
# File 'lib/rgeoserver/utils/boundingbox.rb', line 87 def area width * height end |
#constrict(rate = @@epsilon) ⇒ Object
75 76 77 |
# File 'lib/rgeoserver/utils/boundingbox.rb', line 75 def constrict rate = @@epsilon (-rate) end |
#expand(rate = @@epsilon) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/rgeoserver/utils/boundingbox.rb', line 65 def rate = @@epsilon _minx, _miny = [minx - rate, miny - rate] _maxx, _maxy = [maxx + rate, maxy + rate] reset add _minx, _miny add _maxx, _maxy end |
#height ⇒ Object
83 84 85 |
# File 'lib/rgeoserver/utils/boundingbox.rb', line 83 def height maxy - miny end |
#inspect ⇒ Object
127 128 129 |
# File 'lib/rgeoserver/utils/boundingbox.rb', line 127 def inspect "#<#{self.class} #{to_s}>" end |
#max ⇒ Object
61 62 63 |
# File 'lib/rgeoserver/utils/boundingbox.rb', line 61 def max [maxx, maxy] end |
#min ⇒ Object
57 58 59 |
# File 'lib/rgeoserver/utils/boundingbox.rb', line 57 def min [minx, miny] end |
#reset ⇒ Object
34 35 36 37 |
# File 'lib/rgeoserver/utils/boundingbox.rb', line 34 def reset @minx = @miny = @maxx = @maxy = 0.0 @empty = true end |
#to_a ⇒ Object
119 120 121 |
# File 'lib/rgeoserver/utils/boundingbox.rb', line 119 def to_a [minx, miny, maxx, maxy] end |
#to_geometry ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/rgeoserver/utils/boundingbox.rb', line 96 def to_geometry factory = RGeo::Cartesian::Factory.new point_min, point_max = unless [minx, miny] == [maxx, maxy] [factory.point(minx, miny), factory.point(maxx, maxy)] else [factory.point(minx - @@epsilon, miny - @@epsilon), factory.point(maxx + @@epsilon, maxy + @@epsilon)] end line_string = factory.line_string [point_min, point_max] line_string.envelope end |
#to_h ⇒ Object
110 111 112 113 114 115 116 117 |
# File 'lib/rgeoserver/utils/boundingbox.rb', line 110 def to_h { :minx => minx, :miny => miny, :maxx => maxx, :maxy => maxy } end |
#to_s ⇒ Object
123 124 125 |
# File 'lib/rgeoserver/utils/boundingbox.rb', line 123 def to_s to_a.join(', ') end |
#valid? ⇒ Boolean
Returns true if bounding box has non-zero area.
92 93 94 |
# File 'lib/rgeoserver/utils/boundingbox.rb', line 92 def valid? area > 0 end |
#width ⇒ Object
79 80 81 |
# File 'lib/rgeoserver/utils/boundingbox.rb', line 79 def width maxx - minx end |