提交 e9151589 编写于 作者: S Sean Barrett

duh, best-fit should tiebreak using waste, not prioritize waste (which makes bizarre towers)

上级 2c56e11c
// stb_rect_pack.h - v0.01 - public domain - rectangle packing // stb_rect_pack.h - v0.02 - public domain - rectangle packing
// Sean Barrett 2014 // Sean Barrett 2014
// //
// Useful for e.g. packing rectangular textures into an atlas. // Useful for e.g. packing rectangular textures into an atlas.
...@@ -311,9 +311,9 @@ static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int widt ...@@ -311,9 +311,9 @@ static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int widt
} }
} else { } else {
// best-fit // best-fit
if (waste < best_waste) {
// can only use it if it first vertically
if (y + height <= c->height) { if (y + height <= c->height) {
// can only use it if it first vertically
if (y < best_y || (y == best_y && waste < best_waste)) {
best_y = y; best_y = y;
best_waste = waste; best_waste = waste;
best = prev; best = prev;
...@@ -361,14 +361,17 @@ static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int widt ...@@ -361,14 +361,17 @@ static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int widt
} }
assert(node->next->x > xpos && node->x <= xpos); assert(node->next->x > xpos && node->x <= xpos);
y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste); y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
if (waste <= best_waste && y + height < c->height) { if (y + height < c->height) {
if (waste < best_waste || y < best_y || (y==best_y && xpos < best_x)) { if (y <= best_y) {
if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
best_x = xpos; best_x = xpos;
assert(y <= best_y);
best_y = y; best_y = y;
best_waste = waste; best_waste = waste;
best = prev; best = prev;
} }
} }
}
tail = tail->next; tail = tail->next;
} }
} }
...@@ -472,6 +475,17 @@ static int rect_height_compare(const void *a, const void *b) ...@@ -472,6 +475,17 @@ static int rect_height_compare(const void *a, const void *b)
return (p->w > q->w) ? -1 : (p->w < q->w); return (p->w > q->w) ? -1 : (p->w < q->w);
} }
static int rect_width_compare(const void *a, const void *b)
{
stbrp_rect *p = (stbrp_rect *) a;
stbrp_rect *q = (stbrp_rect *) b;
if (p->w > q->w)
return -1;
if (p->w < q->w)
return 1;
return (p->h > q->h) ? -1 : (p->h < q->h);
}
static int rect_original_order(const void *a, const void *b) static int rect_original_order(const void *a, const void *b)
{ {
stbrp_rect *p = (stbrp_rect *) a; stbrp_rect *p = (stbrp_rect *) a;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册