Class RectanglePacker

java.lang.Object
icyllis.arc3d.core.RectanglePacker
Direct Known Subclasses:
RectanglePacker.BinaryTree, RectanglePacker.Horizon, RectanglePacker.HorizonOld, RectanglePacker.Power2Line, RectanglePacker.Skyline

public abstract class RectanglePacker extends Object
Packs rectangles into a larger rectangle.
  • Field Details

    • ALGORITHM_SKYLINE

      public static final int ALGORITHM_SKYLINE
      Available rectangle packing algorithms, skyline is always recommended.
      See Also:
    • ALGORITHM_HORIZON

      public static final int ALGORITHM_HORIZON
      See Also:
    • ALGORITHM_HORIZON_OLD

      public static final int ALGORITHM_HORIZON_OLD
      See Also:
    • ALGORITHM_BINARY_TREE

      public static final int ALGORITHM_BINARY_TREE
      See Also:
    • ALGORITHM_POWER2_LINE

      public static final int ALGORITHM_POWER2_LINE
      See Also:
    • ALGORITHM_SKYLINE_NEW

      public static final int ALGORITHM_SKYLINE_NEW
      See Also:
    • mWidth

      protected final int mWidth
    • mHeight

      protected final int mHeight
    • mArea

      protected int mArea
  • Constructor Details

    • RectanglePacker

      protected RectanglePacker(int width, int height)
      Constructor assumes both width and height are in the range 1..32768.
      Parameters:
      width - the max width
      height - the max height
  • Method Details

    • make

      public static RectanglePacker make(int width, int height)
      Creates a rectangle packer using the best algorithm.
      Parameters:
      width - the max width, typical value is 256, 512 or 1024
      height - the max height, typical value is 256, 512 or 1024
    • make

      public static RectanglePacker make(int width, int height, int algorithm)
    • getWidth

      public final int getWidth()
    • getHeight

      public final int getHeight()
    • clear

      public abstract void clear()
      Clears all the tracked data.
    • addRect

      public abstract boolean addRect(Rect2i rect)
      Decides upon an (x, y) position for the given rectangle (leaving its width and height unchanged).
      Returns:
      true on success; false on failure
    • getCoverage

      public final double getCoverage()
      Returns the ratio of the used area to the maximum area, higher is better.
      Returns:
      the ratio of coverage, 0..1
    • free

      public void free()
      For native rectangle packer, this must be called to free its native resources.