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
12
# File 'lib/bin_packing/box.rb', line 5

def initialize(width, height)
  @width = width
  @height = height
  @x = 0
  @y = 0
  @packed = false
  @can_rotate = true
end

Instance Attribute Details

#can_rotateObject

Returns the value of attribute can_rotate.



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

def can_rotate
  @can_rotate
end

#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



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

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

#can_rotate?Boolean

Returns:

  • (Boolean)


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

def can_rotate?
  @can_rotate
end

#labelObject



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

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

#packed?Boolean

Returns:

  • (Boolean)


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

def packed?
  @packed
end