Class: Moo::Model::BoundingBox

Inherits:
Object
  • Object
show all
Defined in:
lib/moo/model/bounding_box.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ BoundingBox

Returns a new instance of BoundingBox.

Yields:

  • (_self)

Yield Parameters:



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

#angleObject

Returns the value of attribute angle.



5
6
7
# File 'lib/moo/model/bounding_box.rb', line 5

def angle
  @angle
end

#centreObject

Returns the value of attribute centre.



5
6
7
# File 'lib/moo/model/bounding_box.rb', line 5

def centre
  @centre
end

#heightObject

Returns the value of attribute height.



5
6
7
# File 'lib/moo/model/bounding_box.rb', line 5

def height
  @height
end

#widthObject

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_hashObject



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_jsonObject



13
14
15
# File 'lib/moo/model/bounding_box.rb', line 13

def to_json
  to_hash.to_json
end