Class: BinPacking::Box

Inherits:
Object
  • Object
show all
Defined in:
lib/bin_packing/box.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#heightObject

Returns the value of attribute height.



3
4
5
# File 'lib/bin_packing/box.rb', line 3

def height
  @height
end

#packedObject

Returns the value of attribute packed.



3
4
5
# File 'lib/bin_packing/box.rb', line 3

def packed
  @packed
end

#widthObject

Returns the value of attribute width.



3
4
5
# File 'lib/bin_packing/box.rb', line 3

def width
  @width
end

#xObject

Returns the value of attribute x.



3
4
5
# File 'lib/bin_packing/box.rb', line 3

def x
  @x
end

#yObject

Returns the value of attribute y.



3
4
5
# File 'lib/bin_packing/box.rb', line 3

def y
  @y
end

Instance Method Details

#areaObject



13
14
15
# File 'lib/bin_packing/box.rb', line 13

def area
  @area ||= @width * @height
end

#labelObject



25
26
27
# File 'lib/bin_packing/box.rb', line 25

def label
  "#{@width}x#{@height} at [#{@x},#{@y}]"
end

#packed?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/bin_packing/box.rb', line 21

def packed?
  @packed
end

#rotateObject



17
18
19
# File 'lib/bin_packing/box.rb', line 17

def rotate
  @width, @height = [@height, @width]
end