com.babaroga.test.packing
Class SimplePacker

java.lang.Object
  extended by com.babaroga.test.packing.RectanglePacker
      extended by com.babaroga.test.packing.SimplePacker

public class SimplePacker
extends RectanglePacker

Very simple rectangle packer that attempts to pack rectangles by placing as many rectangles in a row before moving to the next y-coordinate while preventing overlap with the previous row. Works best with rectangles of similar height.


Constructor Summary
SimplePacker()
           
 
Method Summary
 java.util.Collection<java.awt.Rectangle> pack(int width, int height, java.util.Collection<java.awt.Rectangle> rectangles)
          Packs the supplied rectangles into the specified bounds.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimplePacker

public SimplePacker()
Method Detail

pack

public java.util.Collection<java.awt.Rectangle> pack(int width,
                                                     int height,
                                                     java.util.Collection<java.awt.Rectangle> rectangles)
                                              throws java.lang.IllegalArgumentException
Description copied from class: RectanglePacker
Packs the supplied rectangles into the specified bounds.

Specified by:
pack in class RectanglePacker
Parameters:
width - The width of the bounding rectangle.
height - The height of the bounding rectangle.
rectangles - The rectangles to be packed.
Returns:
the packed rectangles. This collection may not return all the rectangles that were specified to be packed.
Throws:
java.lang.IllegalArgumentException - If any rectangles are empty (zero length dimensions).

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object