fix bug in handling rectangle with width or height of 0

This commit is contained in:
Sean Barrett 2015-09-13 11:17:13 -07:00
parent 6b8938124e
commit 83d36fd28a

View File

@ -1,4 +1,4 @@
// stb_rect_pack.h - v0.06 - public domain - rectangle packing
// stb_rect_pack.h - v0.07 - public domain - rectangle packing
// Sean Barrett 2014
//
// Useful for e.g. packing rectangular textures into an atlas.
@ -28,10 +28,11 @@
// Minor features
// Martins Mozeiko
// Bugfixes / warning fixes
// [your name could be here]
// Jeremy Jaussaud
//
// Version history:
//
// 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0)
// 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort
// 0.05: added STBRP_ASSERT to allow replacing assert
// 0.04: fixed minor bug in STBRP_LARGE_RECTS support
@ -548,6 +549,10 @@ STBRP_DEF void stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int n
for (i=0; i < num_rects; ++i) {
stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
if (rects[i].w == 0 || rects[i].h == 0) {
rects[i].x = rects[i].y = 0; // empty rect needs no space
} else {
if (fr.prev_link) {
rects[i].x = (stbrp_coord) fr.x;
rects[i].y = (stbrp_coord) fr.y;
@ -555,6 +560,7 @@ STBRP_DEF void stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int n
rects[i].x = rects[i].y = STBRP__MAXVAL;
}
}
}
// unsort
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order);