diff --git a/src/graphics/Atlas.cpp b/src/graphics/Atlas.cpp index 7db65bc6..b7c87ab0 100644 --- a/src/graphics/Atlas.cpp +++ b/src/graphics/Atlas.cpp @@ -68,7 +68,7 @@ Atlas* AtlasBuilder::build(uint extrusion) { vector 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; diff --git a/src/maths/LMPacker.cpp b/src/maths/LMPacker.cpp index eebca1e0..298c1586 100644 --- a/src/maths/LMPacker.cpp +++ b/src/maths/LMPacker.cpp @@ -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) { diff --git a/src/maths/LMPacker.h b/src/maths/LMPacker.h index c280a85f..98ed6439 100644 --- a/src/maths/LMPacker.h +++ b/src/maths/LMPacker.h @@ -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){ } };