Package org.neuroml.export.svg
Class RectanglePacker<P>
- java.lang.Object
-
- org.neuroml.export.svg.RectanglePacker<P>
-
- Type Parameters:
P
- The type of items to be held
public class RectanglePacker<P> extends Object
Tries to pack rectangles as tightly as possible. An implementation of the algorithm described at http://www.blackpawn.com/texts/lightmaps/default.html- Author:
- ryanm
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RectanglePacker.Rectangle
Yet another Rectangle class.
-
Constructor Summary
Constructors Constructor Description RectanglePacker(int width, int height, int border)
Builds a newRectanglePacker
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clears the packer of all itemsRectanglePacker.Rectangle
findRectangle(P item)
Finds theRectanglePacker.Rectangle
where an item is storedint
getHeight()
Gets the height of this packerint
getWidth()
Gets the width of this packerRectanglePacker.Rectangle
insert(int width, int height, P o)
Attempts to pack an item of the supplied dimensionsvoid
inspectRectangles(List<RectanglePacker.Rectangle> rectangles)
Builds a list of allRectanglePacker.Rectangle
s in the tree, for debugging purposesboolean
remove(P o)
Removes an item from the tree, consolidating the space if possible.
-
-
-
Constructor Detail
-
RectanglePacker
public RectanglePacker(int width, int height, int border)
Builds a newRectanglePacker
- Parameters:
width
- The width of the space available to pack intoheight
- The height of the space available to pack intoborder
- The border to preserve between packed items
-
-
Method Detail
-
inspectRectangles
public void inspectRectangles(List<RectanglePacker.Rectangle> rectangles)
Builds a list of allRectanglePacker.Rectangle
s in the tree, for debugging purposes- Parameters:
rectangles
- The list to add the tree'sRectanglePacker.Rectangle
s to
-
findRectangle
public RectanglePacker.Rectangle findRectangle(P item)
Finds theRectanglePacker.Rectangle
where an item is stored- Parameters:
item
- The item to search for- Returns:
- The
RectanglePacker.Rectangle
where that item resides, or null if not found
-
clear
public void clear()
Clears the packer of all items
-
insert
public RectanglePacker.Rectangle insert(int width, int height, P o)
Attempts to pack an item of the supplied dimensions- Parameters:
width
- The width of the itemheight
- The height of the itemo
- The item to pack- Returns:
- The packed location, or null if it will not fit.
-
remove
public boolean remove(P o)
Removes an item from the tree, consolidating the space if possible. The space can easily become fragmented, so don't rely on this to work as cleverly as you would like.- Parameters:
o
- the item to remove- Returns:
true
if the item was found, false otherwise
-
getWidth
public int getWidth()
Gets the width of this packer- Returns:
- the width of this packer
-
getHeight
public int getHeight()
Gets the height of this packer- Returns:
- The height of this packer
-
-