20#define qsort_r BLI_qsort_r
57#define EPSILON 0.0000001f
58#define EPSILON_MERGE 0.00001f
60# define EPSILON_BIAS 0.000001f
66#define CORNERFLAGS (BLF | TRF | TLF | BRF)
100 return box->
v[
TR]->
y;
123 box->
v[
TR]->
x = f + box->
w;
130 box->
v[
BL]->
x = f - box->
w;
137 box->
v[
TR]->
y = f + box->
h;
144 box->
v[
BL]->
y = f - box->
h;
157 return box->
w * box->
h;
180# define BOXDEBUG(b) \
181 printf("\tBox Debug i %i, w:%.3f h:%.3f x:%.3f y:%.3f\n", b->index, b->w, b->h, b->x, b->y)
215static int vertex_sort(
const void *p1,
const void *p2,
void *vs_ctx_p)
258 BoxPack *boxarray,
const uint len,
const bool sort_boxes,
float *r_tot_x,
float *r_tot_y)
260 uint box_index, verts_pack_len,
i, j, k;
261 uint *vertex_pack_indices;
263 float tot_x = 0.0f, tot_y = 0.0f;
288 for (box = boxarray, box_index = 0,
i = 0; box_index <
len; box_index++, box++) {
339 box->
x = box->
y = 0.0f;
341 for (
i = 0;
i < 4;
i++) {
348 for (
i = 0;
i < 3;
i++) {
349 vertex_pack_indices[
i] = box->
v[
i + 1]->
index;
356 for (box_index = 1; box_index <
len; box_index++, box++) {
362 qsort_r(vertex_pack_indices,
size_t(verts_pack_len),
sizeof(
int),
vertex_sort, &vs_ctx);
366 i = verts_pack_len - 1;
367 while ((
i != 0) && vs_ctx.
vertarray[vertex_pack_indices[
i]].
free == 0) {
370 verts_pack_len =
i + 1;
377 for (
i = 0;
i < verts_pack_len && isect;
i++) {
378 vert = &vs_ctx.
vertarray[vertex_pack_indices[
i]];
386 for (j = 0; (j < 4) && isect; j++) {
428 for (box_test = boxarray; box_test != box; box_test++) {
490# define A (vert->trb->v[TL])
491# define B (vert->tlb->v[TR])
492# define MASK (BLF | BRF)
511 else if (vert->
tlb->
h > vert->
trb->
h) {
521# define A (vert->blb->v[BR])
522# define B (vert->brb->v[BL])
523# define MASK (TRF | TLF)
542 else if (vert->
blb->
h > vert->
brb->
h) {
553# define A (vert->blb->v[TL])
554# define B (vert->tlb->v[BL])
555# define MASK (TRF | BRF)
574 else if (vert->
tlb->
w > vert->
blb->
w) {
585# define A (vert->brb->v[TR])
586# define B (vert->trb->v[BR])
587# define MASK (TLF | BLF)
606 else if (vert->
trb->
w > vert->
brb->
w) {
615 for (k = 0; k < 4; k++) {
616 if (box->
v[k]->
used ==
false) {
617 box->
v[k]->
used =
true;
621 vertex_pack_indices[verts_pack_len] = box->
v[k]->
index;
641 for (box_index = 0; box_index <
len; box_index++) {
642 box = boxarray + box_index;
643 box->
v[0] = box->
v[1] = box->
v[2] = box->
v[3] =
nullptr;
653 full_rect->
w = width;
654 full_rect->
h = height;
667 if (box->w > space->w || box->h > space->h) {
677 if (box->w == space->w && box->h == space->h) {
682 else if (box->w == space->w) {
688 else if (box->h == space->h) {
709 int area_hsplit_large = space->w * (space->h - box->h);
710 int area_vsplit_large = (space->w - box->w) * space->h;
715 if (area_hsplit_large > area_vsplit_large) {
716 new_space->
x = space->x + box->w;
717 new_space->
y = space->y;
718 new_space->
w = space->w - box->w;
719 new_space->
h = box->h;
725 new_space->
x = space->x;
726 new_space->
y = space->y + box->h;
727 new_space->
w = box->w;
728 new_space->
h = space->h - box->h;
#define LISTBASE_FOREACH(type, var, list)
#define LISTBASE_FOREACH_MUTABLE(type, var, list)
void void BLI_freelistN(ListBase *listbase) ATTR_NONNULL(1)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
MINLINE float max_ff(float a, float b)
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 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)
void * MEM_callocN(size_t len, const char *str)
void * MEM_malloc_arrayN(size_t len, size_t size, const char *str)
void MEM_freeN(void *vmemh)