Search in sources :

Example 6 with Page

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;
}
Also used : Array(com.badlogic.gdx.utils.Array) Rect(com.badlogic.gdx.tools.texturepacker.TexturePacker.Rect) Page(com.badlogic.gdx.tools.texturepacker.TexturePacker.Page)

Aggregations

Page (com.badlogic.gdx.tools.texturepacker.TexturePacker.Page)6 Rect (com.badlogic.gdx.tools.texturepacker.TexturePacker.Rect)6 Array (com.badlogic.gdx.utils.Array)5 Settings (com.badlogic.gdx.tools.texturepacker.TexturePacker.Settings)1 Random (java.util.Random)1