public final class BinPacker<T> extends Object implements Comparator<T>, DimensionPacker<T>
This packer is inspired from the grower bin packing algorithm explained by Jakes Gordon to give a position to a set of dimensions in the lowest area.
Comparator interface is implemented to guarantee that dimensions will
be packed beginning with the biggest one (width * height).
| Constructor and Description |
|---|
BinPacker()
Builds a new packer.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addElement(Dimension dimension,
T data)
Adds a new dimension with its associated data to the elements to be packed.
|
void |
clearElements()
Clears all the elements previously added.
|
int |
compare(T a,
T b) |
Dimension |
getFilledArea()
Returns the area which contains all the filled zones.
|
Map<Region,T> |
getRegions()
Packs and returns the regions which result of the computation of the dimension
indicated thanks to the
DimensionPacker.addElement(Dimension, Object)
method. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitequalspublic void addElement(Dimension dimension, T data)
Adds a new dimension with its associated data to the elements to be packed.
addElement in interface DimensionPacker<T>dimension - the dimensiondata - the data.public Map<Region,T> getRegions()
Packs and returns the regions which result of the computation of the dimension
indicated thanks to the DimensionPacker.addElement(Dimension, Object)
method.
getRegions in interface DimensionPacker<T>public Dimension getFilledArea()
Returns the area which contains all the filled zones.
getFilledArea in interface DimensionPacker<T>public int compare(T a, T b)
compare in interface Comparator<T>public void clearElements()
Clears all the elements previously added.
clearElements in interface DimensionPacker<T>Copyright © 2012-2015. All Rights Reserved.