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
  • Constructor Details

    • 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 Details

    • inspectRectangles

      public void inspectRectangles(List<RectanglePacker.Rectangle> rectangles)
      Builds a list of all RectanglePacker.Rectangles in the tree, for debugging purposes
      Parameters:
      rectangles - The list to add the tree's RectanglePacker.Rectangles to
    • findRectangle

      public RectanglePacker.Rectangle findRectangle(P item)
      Finds the RectanglePacker.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 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