Class 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
    • Constructor Detail

      • RectanglePacker

        public RectanglePacker​(int width,
                               int height,
                               int border)
        Builds a new RectanglePacker
        Parameters:
        width - The width of the space available to pack into
        height - The height of the space available to pack into
        border - The border to preserve between packed items
    • Method Detail

      • 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 item
        height - The height of the item
        o - 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