19#define qsort_r BLI_qsort_r
24# pragma GCC diagnostic error "-Wpadded"
62# pragma GCC diagnostic ignored "-Wpadded"
66#define EPSILON 0.0000001f
67#define EPSILON_MERGE 0.00001f
69# define EPSILON_BIAS 0.000001f
75#define CORNERFLAGS (BLF | TRF | TLF | BRF)
104 return box->v[
BL]->y;
109 return box->v[
TR]->y;
120 box->v[
TL]->x = box->v[
BL]->x;
121 box->v[
BR]->x = box->v[
TR]->x;
126 box->v[
TL]->y = box->v[
TR]->y;
127 box->v[
BR]->y = box->v[
BL]->y;
132 box->v[
TR]->x = f + box->w;
139 box->v[
BL]->x = f - box->w;
146 box->v[
TR]->y = f + box->h;
153 box->v[
BL]->y = f - box->h;
166 return box->w * box->h;
180static float max_ff(
const float a,
const float b)
182 return b > a ?
b : a;
195# define BOXDEBUG(b) \
196 printf("\tBox Debug i %i, w:%.3f h:%.3f x:%.3f y:%.3f\n", b->index, b->w, b->h, b->x, b->y)
206 const BoxPack *b1 = p1, *b2 = p2;
229static int vertex_sort(
const void *p1,
const void *p2,
void *vs_ctx_p)
272 BoxPack *boxarray,
const uint len,
const bool sort_boxes,
float *r_tot_x,
float *r_tot_y)
274 uint box_index, verts_pack_len, i, j, k;
275 uint *vertex_pack_indices;
277 float tot_x = 0.0f, tot_y = 0.0f;
298 vertex_pack_indices =
MEM_mallocN(
sizeof(
int[3]) * (
size_t)
len,
"BoxPack Indices");
302 for (box = boxarray, box_index = 0, i = 0; box_index <
len; box_index++, box++) {
353 box->x = box->y = 0.0f;
355 for (i = 0; i < 4; i++) {
356 box->v[i]->used =
true;
362 for (i = 0; i < 3; i++) {
363 vertex_pack_indices[i] = box->v[i + 1]->index;
370 for (box_index = 1; box_index <
len; box_index++, box++) {
376 qsort_r(vertex_pack_indices, (
size_t)verts_pack_len,
sizeof(
int),
vertex_sort, &vs_ctx);
380 i = verts_pack_len - 1;
381 while ((i != 0) && vs_ctx.
vertarray[vertex_pack_indices[i]].
free == 0) {
384 verts_pack_len = i + 1;
391 for (i = 0; i < verts_pack_len && isect; i++) {
392 vert = &vs_ctx.
vertarray[vertex_pack_indices[i]];
400 for (j = 0; (j < 4) && isect; j++) {
442 for (box_test = boxarray; box_test != box; box_test++) {
504# define A (vert->trb->v[TL])
505# define B (vert->tlb->v[TR])
506# define MASK (BLF | BRF)
509 A->free &=
B->free & ~MASK;
513 B->free &= A->free & ~MASK;
525 else if (vert->
tlb->
h > vert->
trb->
h) {
535# define A (vert->blb->v[BR])
536# define B (vert->brb->v[BL])
537# define MASK (TRF | TLF)
540 A->free &=
B->free & ~MASK;
544 B->free &= A->free & ~MASK;
556 else if (vert->
blb->
h > vert->
brb->
h) {
567# define A (vert->blb->v[TL])
568# define B (vert->tlb->v[BL])
569# define MASK (TRF | BRF)
572 A->free &=
B->free & ~MASK;
576 B->free &= A->free & ~MASK;
588 else if (vert->
tlb->
w > vert->
blb->
w) {
599# define A (vert->brb->v[TR])
600# define B (vert->trb->v[BR])
601# define MASK (TLF | BLF)
604 A->free &=
B->free & ~MASK;
608 B->free &= A->free & ~MASK;
620 else if (vert->
trb->
w > vert->
brb->
w) {
629 for (k = 0; k < 4; k++) {
630 if (box->v[k]->used ==
false) {
631 box->v[k]->used =
true;
635 vertex_pack_indices[verts_pack_len] = box->v[k]->index;
655 for (box_index = 0; box_index <
len; box_index++) {
656 box = boxarray + box_index;
657 box->
v[0] = box->v[1] = box->v[2] = box->v[3] =
NULL;
667 full_rect->
w = width;
668 full_rect->
h = height;
681 if (box->w > space->w || box->h > space->h) {
691 if (box->w == space->w && box->h == space->h) {
696 else if (box->w == space->w) {
702 else if (box->h == space->h) {
723 int area_hsplit_large = space->w * (space->h - box->h);
724 int area_vsplit_large = (space->w - box->w) * space->h;
729 if (area_hsplit_large > area_vsplit_large) {
730 new_space->
x = space->x + box->w;
731 new_space->
y = space->y;
732 new_space->
w = space->w - box->w;
733 new_space->
h = box->h;
739 new_space->
x = space->x;
740 new_space->
y = space->y + box->h;
741 new_space->
w = box->w;
742 new_space->
h = space->h - box->h;
void BLI_addhead(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
#define LISTBASE_FOREACH(type, var, list)
#define LISTBASE_FOREACH_MUTABLE(type, var, list)
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Read Guarded memory(de)allocation.
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMVert * v
BLI_INLINE void box_v34x_update(BoxPack *box)
BLI_INLINE void box_v34y_update(BoxPack *box)
static int box_areasort(const void *p1, const void *p2)
static void vert_bias_update(BoxVert *v)
static float box_xmax_get(const BoxPack *box)
void BLI_box_pack_2d_fixedarea(ListBase *boxes, int width, int height, ListBase *packed)
static bool box_isect(const BoxPack *box_a, const BoxPack *box_b)
static float box_ymax_get(const BoxPack *box)
static float box_ymin_get(const BoxPack *box)
void BLI_box_pack_2d(BoxPack *boxarray, const uint len, const bool sort_boxes, float *r_tot_x, float *r_tot_y)
static int vertex_sort(const void *p1, const void *p2, void *vs_ctx_p)
static void box_xmin_set(BoxPack *box, const float f)
static void box_ymin_set(BoxPack *box, const float f)
static float max_ff(const float a, const float b)
static void box_ymax_set(BoxPack *box, const float f)
static float box_xmin_get(const BoxPack *box)
BLI_INLINE int quad_flag(uint q)
static float box_area(const BoxPack *box)
static void box_xmax_set(BoxPack *box, const float f)
local_group_size(16, 16) .push_constant(Type b
void *(* MEM_mallocN)(size_t len, const char *str)
void MEM_freeN(void *vmemh)
void *(* MEM_callocN)(size_t len, const char *str)