Class: BinPacking::Box
- Inherits:
-
Object
- Object
- BinPacking::Box
- Defined in:
- lib/bin_packing/box.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#packed ⇒ Object
Returns the value of attribute packed.
-
#width ⇒ Object
Returns the value of attribute width.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
- #area ⇒ Object
-
#initialize(width, height) ⇒ Box
constructor
A new instance of Box.
- #label ⇒ Object
- #packed? ⇒ Boolean
- #rotate ⇒ Object
Constructor Details
#initialize(width, height) ⇒ Box
Returns a new instance of Box.
5 6 7 8 9 10 11 |
# File 'lib/bin_packing/box.rb', line 5 def initialize(width, height) @width = width @height = height @x = 0 @y = 0 @packed = false end |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
3 4 5 |
# File 'lib/bin_packing/box.rb', line 3 def height @height end |
#packed ⇒ Object
Returns the value of attribute packed.
3 4 5 |
# File 'lib/bin_packing/box.rb', line 3 def packed @packed end |
#width ⇒ Object
Returns the value of attribute width.
3 4 5 |
# File 'lib/bin_packing/box.rb', line 3 def width @width end |
#x ⇒ Object
Returns the value of attribute x.
3 4 5 |
# File 'lib/bin_packing/box.rb', line 3 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
3 4 5 |
# File 'lib/bin_packing/box.rb', line 3 def y @y end |
Instance Method Details
#area ⇒ Object
13 14 15 |
# File 'lib/bin_packing/box.rb', line 13 def area @area ||= @width * @height end |
#label ⇒ Object
25 26 27 |
# File 'lib/bin_packing/box.rb', line 25 def label "#{@width}x#{@height} at [#{@x},#{@y}]" end |
#packed? ⇒ Boolean
21 22 23 |
# File 'lib/bin_packing/box.rb', line 21 def packed? @packed end |
#rotate ⇒ Object
17 18 19 |
# File 'lib/bin_packing/box.rb', line 17 def rotate @width, @height = [@height, @width] end |