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
Packs rectangles into a larger rectangle.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic final classstatic final classstatic final classstatic final classTracks the current silhouette, optimized. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final intAvailable rectangle packing algorithms, skyline is always recommended.static final intprotected intprotected final intprotected final int -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedRectanglePacker(int width, int height) Constructor assumes both width and height are in the range 1..32768. -
Method Summary
Modifier and TypeMethodDescriptionabstract booleanDecides upon an (x, y) position for the given rectangle (leaving its width and height unchanged).abstract voidclear()Clears all the tracked data.voidfree()For native rectangle packer, this must be called to free its native resources.final doubleReturns the ratio of the used area to the maximum area, higher is better.final intfinal intgetWidth()static RectanglePackermake(int width, int height) Creates a rectangle packer using the best algorithm.static RectanglePackermake(int width, int height, int algorithm)
-
Field Details
-
ALGORITHM_SKYLINE
public static final int ALGORITHM_SKYLINEAvailable 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 widthheight- the max height
-
-
Method Details
-
make
Creates a rectangle packer using the best algorithm.- Parameters:
width- the max width, typical value is 256, 512 or 1024height- the max height, typical value is 256, 512 or 1024
-
make
-
getWidth
public final int getWidth() -
getHeight
public final int getHeight() -
clear
public abstract void clear()Clears all the tracked data. -
addRect
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.
-