LMPacker fix

This commit is contained in:
MihailRis 2023-11-23 12:28:28 +03:00
parent a6a1e7866a
commit 1cf4cb727f
3 changed files with 6 additions and 5 deletions

View File

@ -68,7 +68,7 @@ Atlas* AtlasBuilder::build(uint extrusion) {
vector<rectangle> rects = packer.getResult();
for (uint i = 0; i < entries.size(); i++) {
const rectangle& rect = rects[i];
const atlasentry& entry = entries[i];
const atlasentry& entry = entries[rect.idx];
uint x = rect.x;
uint y = rect.y;
uint w = rect.width;

View File

@ -10,7 +10,7 @@ inline int getPackerScore(rectangle& rect) {
LMPacker::LMPacker(const uint32_t sizes[], size_t length) {
for (unsigned int i = 0; i < length/2; i++) {
rectangle rect(0, 0, (int)sizes[i * 2], (int)sizes[i * 2 + 1]);
rectangle rect(i, 0, 0, (int)sizes[i * 2], (int)sizes[i * 2 + 1]);
rects.push_back(rect);
}
sort(rects.begin(), rects.end(), [](rectangle a, rectangle b) {
@ -50,7 +50,7 @@ bool LMPacker::build(uint32_t width, uint32_t height,
}
for (unsigned int i = 0; i < rects.size(); i++) {
rectangle& rect = rects[i];
rect = rectangle(0, 0, rect.width, rect.height);
rect = rectangle(rect.idx, 0, 0, rect.width, rect.height);
rect.width += extension * 2;
rect.height += extension * 2;
if (mpix > 1) {

View File

@ -16,9 +16,10 @@ struct rectangle {
int height;
int extX = 0;
int extY = 0;
uint idx;
rectangle(int x, int y, int width, int height)
: x(x), y(y), width(width), height(height){
rectangle(uint idx, int x, int y, int width, int height)
: idx(idx), x(x), y(y), width(width), height(height){
}
};