Package icyllis.arc3d.core

# 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.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static final class`
  `RectanglePacker.BinaryTree`
  `static final class`
  `RectanglePacker.Horizon`
  `static final class`
  `RectanglePacker.HorizonOld`
  `static final class`
  `RectanglePacker.Power2Line`
  `static final class`
  `RectanglePacker.Skyline`
  Tracks the current silhouette, optimized.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `ALGORITHM_BINARY_TREE`
  `static final int`
  `ALGORITHM_HORIZON`
  `static final int`
  `ALGORITHM_HORIZON_OLD`
  `static final int`
  `ALGORITHM_POWER2_LINE`
  `static final int`
  `ALGORITHM_SKYLINE`
  Available rectangle packing algorithms, skyline is always recommended.
  `static final int`
  `ALGORITHM_SKYLINE_NEW`
  `protected int`
  `mArea`
  `protected final int`
  `mHeight`
  `protected final int`
  `mWidth`

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `RectanglePacker(int width, int height)`
  Constructor assumes both width and height are in the range 1..32768.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `abstract boolean`
  `addRect(Rect2i rect)`
  Decides upon an (x, y) position for the given rectangle (leaving its width and height unchanged).
  `abstract void`
  `clear()`
  Clears all the tracked data.
  `void`
  `free()`
  For native rectangle packer, this must be called to free its native resources.
  `final double`
  `getCoverage()`
  Returns the ratio of the used area to the maximum area, higher is better.
  `final int`
  `getHeight()`
  `final int`
  `getWidth()`
  `static RectanglePacker`
  `make(int width, int height)`
  Creates a rectangle packer using the best algorithm.
  `static RectanglePacker`
  `make(int width, int height, int algorithm)`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### ALGORITHM_SKYLINE

    public static final int ALGORITHM_SKYLINE
    Available rectangle packing algorithms, skyline is always recommended.
    See Also:
      - Constant Field Values

  - ### ALGORITHM_HORIZON

    public static final int ALGORITHM_HORIZON
    See Also:
      - Constant Field Values

  - ### ALGORITHM_HORIZON_OLD

    public static final int ALGORITHM_HORIZON_OLD
    See Also:
      - Constant Field Values

  - ### ALGORITHM_BINARY_TREE

    public static final int ALGORITHM_BINARY_TREE
    See Also:
      - Constant Field Values

  - ### ALGORITHM_POWER2_LINE

    public static final int ALGORITHM_POWER2_LINE
    See Also:
      - Constant Field Values

  - ### ALGORITHM_SKYLINE_NEW

    public static final int ALGORITHM_SKYLINE_NEW
    See Also:
      - Constant Field Values

  - ### 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.