260 BoxPack *boxarray,
const uint len,
const bool sort_boxes,
float *r_tot_x,
float *r_tot_y)
262 uint box_index, verts_pack_len, i, j, k;
263 uint *vertex_pack_indices;
265 float tot_x = 0.0f, tot_y = 0.0f;
290 for (box = boxarray, box_index = 0, i = 0; box_index <
len; box_index++, box++) {
292 vert->blb = vert->brb = vert->tlb = vert->isect_cache[0] = vert->isect_cache[1] =
293 vert->isect_cache[2] = vert->isect_cache[3] =
nullptr;
300 vert->trb = vert->brb = vert->tlb = vert->isect_cache[0] = vert->isect_cache[1] =
301 vert->isect_cache[2] = vert->isect_cache[3] =
nullptr;
308 vert->trb = vert->blb = vert->tlb = vert->isect_cache[0] = vert->isect_cache[1] =
309 vert->isect_cache[2] = vert->isect_cache[3] =
nullptr;
316 vert->trb = vert->blb = vert->brb = vert->isect_cache[0] = vert->isect_cache[1] =
317 vert->isect_cache[2] = vert->isect_cache[3] =
nullptr;
341 box->
x = box->
y = 0.0f;
343 for (i = 0; i < 4; i++) {
344 box->
v[i]->
used =
true;
350 for (i = 0; i < 3; i++) {
351 vertex_pack_indices[i] = box->
v[i + 1]->
index;
358 for (box_index = 1; box_index <
len; box_index++, box++) {
364 qsort_r(vertex_pack_indices,
size_t(verts_pack_len),
sizeof(
int),
vertex_sort, &vs_ctx);
368 i = verts_pack_len - 1;
369 while ((i != 0) && vs_ctx.
vertarray[vertex_pack_indices[i]].
free == 0) {
372 verts_pack_len = i + 1;
379 for (i = 0; i < verts_pack_len && isect; i++) {
380 vert = &vs_ctx.
vertarray[vertex_pack_indices[i]];
388 for (j = 0; (j < 4) && isect; j++) {
417 (vert->isect_cache[j] &&
box_isect(box, vert->isect_cache[j])))
430 for (box_test = boxarray; box_test != box; box_test++) {
434 vert->isect_cache[j] = box_test;
489 if (vert->tlb && vert->trb &&
ELEM(box, vert->tlb, vert->trb)) {
492# define A (vert->trb->v[TL])
493# define B (vert->tlb->v[TR])
494# define MASK (BLF | BRF)
509 vert->tlb->v[
TR]->free &=
~BLF;
510 vert->trb->v[
TL]->free &=
~BRF;
513 else if (vert->tlb->h > vert->trb->h) {
514 vert->trb->v[
TL]->free &= ~(
TLF |
BLF);
517 vert->tlb->v[
TR]->free &= ~(
TRF |
BRF);
520 else if (vert->blb && vert->brb &&
ELEM(box, vert->blb, vert->brb)) {
523# define A (vert->blb->v[BR])
524# define B (vert->brb->v[BL])
525# define MASK (TRF | TLF)
540 vert->blb->v[
BR]->free &=
~TRF;
541 vert->brb->v[
BL]->free &=
~TLF;
544 else if (vert->blb->h > vert->brb->h) {
545 vert->brb->v[
BL]->free &= ~(
TLF |
BLF);
548 vert->blb->v[
BR]->free &= ~(
TRF |
BRF);
552 if (vert->tlb && vert->blb &&
ELEM(box, vert->tlb, vert->blb)) {
555# define A (vert->blb->v[TL])
556# define B (vert->tlb->v[BL])
557# define MASK (TRF | BRF)
572 vert->blb->v[
TL]->free &=
~TRF;
573 vert->tlb->v[
BL]->free &=
~BRF;
576 else if (vert->tlb->w > vert->blb->w) {
577 vert->blb->v[
TL]->free &= ~(
TLF |
TRF);
580 vert->tlb->v[
BL]->free &= ~(
BLF |
BRF);
583 else if (vert->trb && vert->brb &&
ELEM(box, vert->trb, vert->brb)) {
587# define A (vert->brb->v[TR])
588# define B (vert->trb->v[BR])
589# define MASK (TLF | BLF)
604 vert->brb->v[
TR]->free &=
~TLF;
605 vert->trb->v[
BR]->free &=
~BLF;
608 else if (vert->trb->w > vert->brb->w) {
609 vert->brb->v[
TR]->free &= ~(
TLF |
TRF);
612 vert->trb->v[
BR]->free &= ~(
BLF |
BRF);
617 for (k = 0; k < 4; k++) {
618 if (box->
v[k]->
used ==
false) {
619 box->
v[k]->
used =
true;
623 vertex_pack_indices[verts_pack_len] = box->
v[k]->
index;
643 for (box_index = 0; box_index <
len; box_index++) {
644 box = boxarray + box_index;
645 box->
v[0] = box->
v[1] = box->
v[2] = box->
v[3] =
nullptr;
647 MEM_delete(vertex_pack_indices);
654 ListBaseT<FixedSizeBoxPack> *packed)
656 ListBaseT<FixedSizeBoxPack> spaces = {
nullptr};
658 full_rect->
w = width;
659 full_rect->
h = height;
672 if (box.w > space.w || box.h > space.h) {
682 if (box.w == space.w && box.h == space.h) {
687 else if (box.w == space.w) {
693 else if (box.h == space.h) {
714 int area_hsplit_large = space.w * (space.h - box.h);
715 int area_vsplit_large = (space.w - box.w) * space.h;
720 if (area_hsplit_large > area_vsplit_large) {
721 new_space->
x = space.x + box.w;
722 new_space->
y = space.y;
723 new_space->
w = space.w - box.w;
724 new_space->
h = box.h;
730 new_space->
x = space.x;
731 new_space->
y = space.y + box.h;
732 new_space->
w = box.w;
733 new_space->
h = space.h - box.h;
745 spaces.free_no_destruct();