public class RectanglePacker
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private Texture |
backingStore
A reference to the backing store that was created (lazily)
by the backing store manager.
|
private int |
length |
private java.util.List<Level> |
levels
Manages a list of Levels; this is the core data structure
contained within the RectanglePacker and encompasses the storage
algorithm for the contained Rects.
|
private static int |
MIN_SIZE |
private int |
recentUsedLevelIndex |
private static int |
ROUND_UP |
private int |
size |
private int |
sizeOffset |
private boolean |
vertical |
private int |
x |
private int |
y |
Constructor and Description |
---|
RectanglePacker(Texture backingStore,
int width,
int height)
Creates a new RectanglePacker.
|
RectanglePacker(Texture backingStore,
int x,
int y,
int width,
int height,
boolean vertical) |
Modifier and Type | Method and Description |
---|---|
boolean |
add(Rectangle rect)
Decides upon an (x, y) position for the given rectangle (leaving
its width and height unchanged) and places it on the backing
store.
|
private static int |
binarySearch(java.util.List<Level> levels,
int k)
Using binary search to find the last index of best fit level for k,
where k is a rounded-up value.
|
void |
clear()
Clears all Rectangles contained in this RectanglePacker.
|
void |
dispose()
Disposes the backing store allocated by the
BackingStoreManager.
|
Texture |
getBackingStore()
Gets a reference to the backing store, creating it lazily if necessary.
|
private Texture backingStore
private java.util.List<Level> levels
private static final int MIN_SIZE
private static final int ROUND_UP
private int recentUsedLevelIndex
private int length
private int size
private int sizeOffset
private int x
private int y
private boolean vertical
public RectanglePacker(Texture backingStore, int x, int y, int width, int height, boolean vertical)
public RectanglePacker(Texture backingStore, int width, int height)
backingStore
- The backing store texture, must not be nullwidth
- The width of the backing store, must be > 0 (typically > 512)height
- The height of the backing store, must be > 0 (typically > 512)public final Texture getBackingStore()
public final boolean add(Rectangle rect)
public void clear()
public void dispose()
private static int binarySearch(java.util.List<Level> levels, int k)