use of com.badlogic.gdx.tools.texturepacker.TexturePacker.Page in project libgdx by libgdx.
the class GridPacker method pack.
public Array<Page> pack(Array<Rect> inputRects) {
if (!settings.silent)
System.out.print("Packing");
int cellWidth = 0, cellHeight = 0;
for (int i = 0, nn = inputRects.size; i < nn; i++) {
Rect rect = inputRects.get(i);
cellWidth = Math.max(cellWidth, rect.width);
cellHeight = Math.max(cellHeight, rect.height);
}
cellWidth += settings.paddingX;
cellHeight += settings.paddingY;
inputRects.reverse();
Array<Page> pages = new Array();
while (inputRects.size > 0) {
Page result = packPage(inputRects, cellWidth, cellHeight);
pages.add(result);
}
return pages;
}
use of com.badlogic.gdx.tools.texturepacker.TexturePacker.Page in project libgdx by libgdx.
the class MaxRectsPacker method packAtSize.
/** @param fully If true, the only results that pack all rects will be considered. If false, all results are considered, not
* all rects may be packed. */
private Page packAtSize(boolean fully, int width, int height, Array<Rect> inputRects) {
Page bestResult = null;
for (int i = 0, n = methods.length; i < n; i++) {
maxRects.init(width, height);
Page result;
if (!settings.fast) {
result = maxRects.pack(inputRects, methods[i]);
} else {
Array<Rect> remaining = new Array();
for (int ii = 0, nn = inputRects.size; ii < nn; ii++) {
Rect rect = inputRects.get(ii);
if (maxRects.insert(rect, methods[i]) == null) {
while (ii < nn) remaining.add(inputRects.get(ii++));
}
}
result = maxRects.getResult();
result.remainingRects = remaining;
}
if (fully && result.remainingRects.size > 0)
continue;
if (result.outputRects.size == 0)
continue;
bestResult = getBest(bestResult, result);
}
return bestResult;
}
use of com.badlogic.gdx.tools.texturepacker.TexturePacker.Page in project libgdx by libgdx.
the class MaxRectsPacker method pack.
public Array<Page> pack(Array<Rect> inputRects) {
for (int i = 0, nn = inputRects.size; i < nn; i++) {
Rect rect = inputRects.get(i);
rect.width += settings.paddingX;
rect.height += settings.paddingY;
}
if (settings.fast) {
if (settings.rotation) {
// Sort by longest side if rotation is enabled.
sort.sort(inputRects, new Comparator<Rect>() {
public int compare(Rect o1, Rect o2) {
int n1 = o1.width > o1.height ? o1.width : o1.height;
int n2 = o2.width > o2.height ? o2.width : o2.height;
return n2 - n1;
}
});
} else {
// Sort only by width (largest to smallest) if rotation is disabled.
sort.sort(inputRects, new Comparator<Rect>() {
public int compare(Rect o1, Rect o2) {
return o2.width - o1.width;
}
});
}
}
Array<Page> pages = new Array();
while (inputRects.size > 0) {
Page result = packPage(inputRects);
pages.add(result);
inputRects = result.remainingRects;
}
return pages;
}
use of com.badlogic.gdx.tools.texturepacker.TexturePacker.Page in project skin-composer by raeleus.
the class MaxRectsPacker method pack.
public Array<Page> pack(Array<Rect> inputRects) {
for (int i = 0, nn = inputRects.size; i < nn; i++) {
Rect rect = inputRects.get(i);
rect.width += settings.paddingX;
rect.height += settings.paddingY;
}
if (settings.fast) {
if (settings.rotation) {
// Sort by longest side if rotation is enabled.
sort.sort(inputRects, new Comparator<Rect>() {
public int compare(Rect o1, Rect o2) {
int n1 = o1.width > o1.height ? o1.width : o1.height;
int n2 = o2.width > o2.height ? o2.width : o2.height;
return n2 - n1;
}
});
} else {
// Sort only by width (largest to smallest) if rotation is disabled.
sort.sort(inputRects, new Comparator<Rect>() {
public int compare(Rect o1, Rect o2) {
return o2.width - o1.width;
}
});
}
}
Array<Page> pages = new Array();
while (inputRects.size > 0) {
Page result = packPage(inputRects);
pages.add(result);
inputRects = result.remainingRects;
}
return pages;
}
use of com.badlogic.gdx.tools.texturepacker.TexturePacker.Page in project skin-composer by raeleus.
the class MaxRectsPacker method packAtSize.
/**
* @param fully If true, the only results that pack all rects will be considered. If false, all results are considered, not
* all rects may be packed.
*/
private Page packAtSize(boolean fully, int width, int height, Array<Rect> inputRects) {
Page bestResult = null;
for (int i = 0, n = methods.length; i < n; i++) {
maxRects.init(width, height);
Page result;
if (!settings.fast) {
result = maxRects.pack(inputRects, methods[i]);
} else {
Array<Rect> remaining = new Array();
for (int ii = 0, nn = inputRects.size; ii < nn; ii++) {
Rect rect = inputRects.get(ii);
if (maxRects.insert(rect, methods[i]) == null) {
while (ii < nn) remaining.add(inputRects.get(ii++));
}
}
result = maxRects.getResult();
result.remainingRects = remaining;
}
if (fully && result.remainingRects.size > 0)
continue;
if (result.outputRects.size == 0)
continue;
bestResult = getBest(bestResult, result);
}
return bestResult;
}