Class LevelSet

java.lang.Object
com.jogamp.opengl.util.packrect.LevelSet

public class LevelSet extends Object
Manages a list of Levels; this is the core data structure contained within the RectanglePacker and encompasses the storage algorithm for the contained Rects.
  • Constructor Summary

    Constructors
    Constructor
    Description
    LevelSet(int w, int h)
    A LevelSet manages all of the backing store for a region of a specified width and height.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    add(Rect rect)
    Returns true if the given rectangle was successfully added to the LevelSet given its current dimensions, false if not.
    boolean
    canExpand(Level level, int height)
    Indicates whether it's legal to trivially increase the height of the given Level.
    void
    Clears out all Levels stored in this LevelSet.
    boolean
    compactAndAdd(Rect rect, Object backingStore, BackingStoreManager manager)
    Allocates the given Rectangle, performing compaction of a Level if necessary.
    void
    expand(Level level, int oldHeight, int newHeight)
     
    int
    Gets the used height of the levels in this LevelSet.
    int
    h()
     
     
    boolean
    remove(Rect rect)
    Removes the given Rect from this LevelSet.
    void
    setHeight(int height)
    Sets the height of this LevelSet.
    void
    Updates the references to the Rect objects in this LevelSet with the "next locations" of those Rects.
    float
    Returns the vertical fragmentation ratio of this LevelSet.
    void
    visit(RectVisitor visitor)
    Visits all Rects contained in this LevelSet.
    int
    w()
     

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • LevelSet

      public LevelSet(int w, int h)
      A LevelSet manages all of the backing store for a region of a specified width and height.
  • Method Details

    • w

      public int w()
    • h

      public int h()
    • add

      public boolean add(Rect rect)
      Returns true if the given rectangle was successfully added to the LevelSet given its current dimensions, false if not. Caller is responsible for performing compaction, expansion, etc. as a consequence.
    • remove

      public boolean remove(Rect rect)
      Removes the given Rect from this LevelSet.
    • compactAndAdd

      public boolean compactAndAdd(Rect rect, Object backingStore, BackingStoreManager manager)
      Allocates the given Rectangle, performing compaction of a Level if necessary. This is the correct fallback path to add(Rect) above. Returns true if allocated successfully, false otherwise (indicating the need to expand the backing store).
    • canExpand

      public boolean canExpand(Level level, int height)
      Indicates whether it's legal to trivially increase the height of the given Level. This is only possible if it's the last Level added and there's enough room in the backing store.
    • expand

      public void expand(Level level, int oldHeight, int newHeight)
    • getUsedHeight

      public int getUsedHeight()
      Gets the used height of the levels in this LevelSet.
    • setHeight

      public void setHeight(int height) throws IllegalArgumentException
      Sets the height of this LevelSet. It is only legal to reduce the height to greater than or equal to the currently used height.
      Throws:
      IllegalArgumentException
    • verticalFragmentationRatio

      public float verticalFragmentationRatio()
      Returns the vertical fragmentation ratio of this LevelSet. This is defined as the ratio of the sum of the heights of all completely empty Levels divided by the overall used height of the LevelSet. A high vertical fragmentation ratio indicates that it may be profitable to perform a compaction.
    • iterator

      public Iterator<Level> iterator()
    • visit

      public void visit(RectVisitor visitor)
      Visits all Rects contained in this LevelSet.
    • updateRectangleReferences

      public void updateRectangleReferences()
      Updates the references to the Rect objects in this LevelSet with the "next locations" of those Rects. This is actually used to update the new Rects in a newly laid-out LevelSet with the original Rects.
    • clear

      public void clear()
      Clears out all Levels stored in this LevelSet.