APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.badlogic.gdx.tools.texturepacker

public Class MaxRectsPacker

extends Object
implements Packer
Class Inheritance
All Implemented Interfaces
com.badlogic.gdx.tools.texturepacker.TexturePacker.Packer
Imports
java.util.Comparator, com.badlogic.gdx.math.MathUtils, com.badlogic.gdx.tools.texturepacker.TexturePacker.Packer, .TexturePacker.Page, .TexturePacker.ProgressListener, .TexturePacker.Rect, .TexturePacker.Settings, com.badlogic.gdx.utils.Array, .IntSet, .Sort

Packs pages of images using the maximal rectangles bin packing algorithm by Jukka Jylänki. A brute force binary search is used to pack into the smallest bin possible.
Author
Nathan Sweet

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
public static enum
pack-priv class
MaxRectsPacker.MaxRects

Maximal rectangles bin packing algorithm.

Field Summary

Modifier and TypeField and Description
private final MaxRectsPacker.MaxRects
private final MaxRectsPacker.FreeRectChoiceHeuristic[]
private final Comparator<TexturePacker.Rect>
pack-priv final TexturePacker.Settings
private final Sort

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private TexturePacker.Page
public Array<TexturePacker.Page>
public Array<TexturePacker.Page>
private TexturePacker.Page
packAtSize(boolean
If true, the only results that pack all rects will be considered. If false, all results are considered, not all rects may be packed.
fully
,
int width, int height, Array<TexturePacker.Rect> inputRects)

private TexturePacker.Page
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

maxRectsback to summary
private final MaxRectsPacker.MaxRects maxRects
methodsback to summary
private final MaxRectsPacker.FreeRectChoiceHeuristic[] methods
rectComparatorback to summary
private final Comparator<TexturePacker.Rect> rectComparator
settingsback to summary
pack-priv final TexturePacker.Settings settings
sortback to summary
private final Sort sort

Constructor Detail

MaxRectsPackerback to summary
public MaxRectsPacker(TexturePacker.Settings settings)

Method Detail

getBestback to summary
private TexturePacker.Page getBest(TexturePacker.Page result1, TexturePacker.Page result2)
packback to summary
public Array<TexturePacker.Page> pack(Array<TexturePacker.Rect> inputRects)

Implements com.badlogic.gdx.tools.texturepacker.TexturePacker.Packer.pack.

packback to summary
public Array<TexturePacker.Page> pack(TexturePacker.ProgressListener progress, Array<TexturePacker.Rect> inputRects)

Implements com.badlogic.gdx.tools.texturepacker.TexturePacker.Packer.pack.

packAtSizeback to summary
private TexturePacker.Page packAtSize(boolean fully, int width, int height, Array<TexturePacker.Rect> inputRects)
Parameters
fully:boolean

If true, the only results that pack all rects will be considered. If false, all results are considered, not all rects may be packed.

packPageback to summary
private TexturePacker.Page packPage(Array<TexturePacker.Rect> inputRects)
com.badlogic.gdx.tools.texturepacker back to summary

pack-priv Class MaxRectsPacker.BinarySearch

extends Object
Class Inheritance
  • java.lang.Object
  • com.badlogic.gdx.tools.texturepacker.MaxRectsPacker.BinarySearch

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv final int
pack-priv int
pack-priv int
pack-priv final int
pack-priv final int
pack-priv final boolean
pack-priv final boolean

Constructor Summary

AccessConstructor and Description
public
BinarySearch(int min, int max, int fuzziness, boolean pot, boolean mod4)

Method Summary

Modifier and TypeMethod and Description
public int
next(boolean result)

public int
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

currentback to summary
pack-priv int current
fuzzinessback to summary
pack-priv final int fuzziness
highback to summary
pack-priv int high
lowback to summary
pack-priv int low
maxback to summary
pack-priv final int max
minback to summary
pack-priv final int min
mod4back to summary
pack-priv final boolean mod4
potback to summary
pack-priv final boolean pot

Constructor Detail

BinarySearchback to summary
public BinarySearch(int min, int max, int fuzziness, boolean pot, boolean mod4)

Method Detail

nextback to summary
public int next(boolean result)
resetback to summary
public int reset()
com.badlogic.gdx.tools.texturepacker back to summary

public final Enum MaxRectsPacker.FreeRectChoiceHeuristic

extends Enum<MaxRectsPacker.FreeRectChoiceHeuristic>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final MaxRectsPacker.FreeRectChoiceHeuristic
BestAreaFit

BAF: Positions the rectangle into the smallest free rect into which it fits.

public static final MaxRectsPacker.FreeRectChoiceHeuristic
BestLongSideFit

BLSF: Positions the rectangle against the long side of a free rectangle into which it fits the best.

public static final MaxRectsPacker.FreeRectChoiceHeuristic
BestShortSideFit

BSSF: Positions the rectangle against the short side of a free rectangle into which it fits the best.

public static final MaxRectsPacker.FreeRectChoiceHeuristic
BottomLeftRule

BL: Does the Tetris placement.

public static final MaxRectsPacker.FreeRectChoiceHeuristic
ContactPointRule

CP: Choosest the placement where the rectangle touches other rects as much as possible.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static MaxRectsPacker.FreeRectChoiceHeuristic
public static MaxRectsPacker.FreeRectChoiceHeuristic[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

BestAreaFitback to summary
public static final MaxRectsPacker.FreeRectChoiceHeuristic BestAreaFit

BAF: Positions the rectangle into the smallest free rect into which it fits.

BestLongSideFitback to summary
public static final MaxRectsPacker.FreeRectChoiceHeuristic BestLongSideFit

BLSF: Positions the rectangle against the long side of a free rectangle into which it fits the best.

BestShortSideFitback to summary
public static final MaxRectsPacker.FreeRectChoiceHeuristic BestShortSideFit

BSSF: Positions the rectangle against the short side of a free rectangle into which it fits the best.

BottomLeftRuleback to summary
public static final MaxRectsPacker.FreeRectChoiceHeuristic BottomLeftRule

BL: Does the Tetris placement.

ContactPointRuleback to summary
public static final MaxRectsPacker.FreeRectChoiceHeuristic ContactPointRule

CP: Choosest the placement where the rectangle touches other rects as much as possible.

Constructor Detail

FreeRectChoiceHeuristicback to summary
private FreeRectChoiceHeuristic()

Method Detail

valueOfback to summary
public static MaxRectsPacker.FreeRectChoiceHeuristic valueOf(String name)
valuesback to summary
public static MaxRectsPacker.FreeRectChoiceHeuristic[] values()
com.badlogic.gdx.tools.texturepacker back to summary

pack-priv Class MaxRectsPacker.MaxRects

extends Object
Class Inheritance

Maximal rectangles bin packing algorithm. Adapted from this C++ public domain source: http://clb.demon.fi/projects/even-more-rectangle-bin-packing
Authors
Jukka Jyl�nki, Nathan Sweet

Field Summary

Modifier and TypeField and Description
private int
private int
private final Array<TexturePacker.Rect>
private final Array<TexturePacker.Rect>
private final Array<TexturePacker.Rect>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private int
commonIntervalLength(int i1start, int i1end, int i2start, int i2end)

private int
contactPointScoreNode(int x, int y, int width, int height)

private TexturePacker.Rect
findPositionForNewNodeBestAreaFit(int width, int height, int rotatedWidth, int rotatedHeight, boolean rotate)

private TexturePacker.Rect
findPositionForNewNodeBestLongSideFit(int width, int height, int rotatedWidth, int rotatedHeight, boolean rotate)

private TexturePacker.Rect
findPositionForNewNodeBestShortSideFit(int width, int height, int rotatedWidth, int rotatedHeight, boolean rotate)

private TexturePacker.Rect
findPositionForNewNodeBottomLeft(int width, int height, int rotatedWidth, int rotatedHeight, boolean rotate)

private TexturePacker.Rect
findPositionForNewNodeContactPoint(int width, int height, int rotatedWidth, int rotatedHeight, boolean rotate)

private float
public TexturePacker.Page
public void
init(int width, int height)

public TexturePacker.Rect
insert(TexturePacker.Rect rect, MaxRectsPacker.FreeRectChoiceHeuristic method)

Packs a single image.

private boolean
public TexturePacker.Page
pack(Array<TexturePacker.Rect> rects, MaxRectsPacker.FreeRectChoiceHeuristic method)

For each rectangle, packs each one then chooses the best and packs that.

private void
private void
private TexturePacker.Rect
private boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

binHeightback to summary
private int binHeight
binWidthback to summary
private int binWidth
freeRectanglesback to summary
private final Array<TexturePacker.Rect> freeRectangles
rectanglesToCheckWhenPruningback to summary
private final Array<TexturePacker.Rect> rectanglesToCheckWhenPruning
usedRectanglesback to summary
private final Array<TexturePacker.Rect> usedRectangles

Constructor Detail

MaxRectsback to summary
pack-priv MaxRects()

Method Detail

commonIntervalLengthback to summary
private int commonIntervalLength(int i1start, int i1end, int i2start, int i2end)
contactPointScoreNodeback to summary
private int contactPointScoreNode(int x, int y, int width, int height)
findPositionForNewNodeBestAreaFitback to summary
private TexturePacker.Rect findPositionForNewNodeBestAreaFit(int width, int height, int rotatedWidth, int rotatedHeight, boolean rotate)
findPositionForNewNodeBestLongSideFitback to summary
private TexturePacker.Rect findPositionForNewNodeBestLongSideFit(int width, int height, int rotatedWidth, int rotatedHeight, boolean rotate)
findPositionForNewNodeBestShortSideFitback to summary
private TexturePacker.Rect findPositionForNewNodeBestShortSideFit(int width, int height, int rotatedWidth, int rotatedHeight, boolean rotate)
findPositionForNewNodeBottomLeftback to summary
private TexturePacker.Rect findPositionForNewNodeBottomLeft(int width, int height, int rotatedWidth, int rotatedHeight, boolean rotate)
findPositionForNewNodeContactPointback to summary
private TexturePacker.Rect findPositionForNewNodeContactPoint(int width, int height, int rotatedWidth, int rotatedHeight, boolean rotate)
getOccupancyback to summary
private float getOccupancy()
getResultback to summary
public TexturePacker.Page getResult()
initback to summary
public void init(int width, int height)
insertback to summary
public TexturePacker.Rect insert(TexturePacker.Rect rect, MaxRectsPacker.FreeRectChoiceHeuristic method)

Packs a single image. Order is defined externally.

isContainedInback to summary
private boolean isContainedIn(TexturePacker.Rect a, TexturePacker.Rect b)
packback to summary
public TexturePacker.Page pack(Array<TexturePacker.Rect> rects, MaxRectsPacker.FreeRectChoiceHeuristic method)

For each rectangle, packs each one then chooses the best and packs that.

placeRectback to summary
private void placeRect(TexturePacker.Rect node)
pruneFreeListback to summary
private void pruneFreeList()
scoreRectback to summary
private TexturePacker.Rect scoreRect(TexturePacker.Rect rect, MaxRectsPacker.FreeRectChoiceHeuristic method)
splitFreeNodeback to summary
private boolean splitFreeNode(TexturePacker.Rect freeNode, TexturePacker.Rect usedNode)