Class: Moo::Model::BoundingBox
Instance Attribute Summary collapse
-
#angle ⇒ Object
Returns the value of attribute angle.
-
#centre ⇒ Object
Returns the value of attribute centre.
-
#height ⇒ Object
Returns the value of attribute height.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #from_json(json) ⇒ Object
-
#initialize {|_self| ... } ⇒ BoundingBox
constructor
A new instance of BoundingBox.
- #to_hash ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ BoundingBox
Returns a new instance of BoundingBox.
7 8 9 10 11 |
# File 'lib/moo/model/bounding_box.rb', line 7 def initialize @centre = [0,0] @width, @height, @angle = 0, 0, 0 yield self if block_given? end |
Instance Attribute Details
#angle ⇒ Object
Returns the value of attribute angle.
5 6 7 |
# File 'lib/moo/model/bounding_box.rb', line 5 def angle @angle end |
#centre ⇒ Object
Returns the value of attribute centre.
5 6 7 |
# File 'lib/moo/model/bounding_box.rb', line 5 def centre @centre end |
#height ⇒ Object
Returns the value of attribute height.
5 6 7 |
# File 'lib/moo/model/bounding_box.rb', line 5 def height @height end |
#width ⇒ Object
Returns the value of attribute width.
5 6 7 |
# File 'lib/moo/model/bounding_box.rb', line 5 def width @width end |
Instance Method Details
#from_json(json) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/moo/model/bounding_box.rb', line 29 def from_json(json) hash = JSON.parse(json, :symbolize_names => true) @centre = [hash[:center][:x], hash[:center][:y]] @width = hash[:width] @height = hash[:height] @angle = hash[:angle] end |
#to_hash ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/moo/model/bounding_box.rb', line 17 def to_hash { :center => { :x => @centre[0], :y => @centre[1] }, :width => @width, :height => @height, :angle => @angle } end |
#to_json ⇒ Object
13 14 15 |
# File 'lib/moo/model/bounding_box.rb', line 13 def to_json to_hash.to_json end |