Blender V5.0
boxpack_2d.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cmath> /* for fabsf */
10#include <cstdlib> /* for qsort */
11
12#include "MEM_guardedalloc.h"
13
14#include "BLI_boxpack_2d.h" /* own include */
15#include "BLI_listbase.h"
16#include "BLI_math_base.h"
17#include "BLI_utildefines.h"
18
19#include "BLI_sort.h" /* qsort_r */
20#define qsort_r BLI_qsort_r
21
22#include "BLI_strict_flags.h" /* IWYU pragma: keep. Keep last. */
23
24/* de-duplicate as we pack */
25#define USE_MERGE
26/* use strip-free */
27#define USE_FREE_STRIP
28/* slight bias, needed when packing many boxes the _exact_ same size */
29#define USE_PACK_BIAS
30
31/* BoxPacker for backing 2D rectangles into a square
32 *
33 * The defined Below are for internal use only */
34struct BoxVert {
35 float x;
36 float y;
37
38 int free; /* vert status */
39 bool used;
41
42#ifdef USE_PACK_BIAS
43 float bias;
44#endif
45
46 BoxPack *trb; /* top right box */
47 BoxPack *blb; /* bottom left box */
48 BoxPack *brb; /* bottom right box */
49 BoxPack *tlb; /* top left box */
50
51 /* Store last intersecting boxes here
52 * speedup intersection testing */
54};
55
56/* free vert flags */
57#define EPSILON 0.0000001f
58#define EPSILON_MERGE 0.00001f
59#ifdef USE_PACK_BIAS
60# define EPSILON_BIAS 0.000001f
61#endif
62#define BLF 1
63#define TRF 2
64#define TLF 4
65#define BRF 8
66#define CORNERFLAGS (BLF | TRF | TLF | BRF)
67
69{
70 BLI_assert(q < 4);
71 return (1 << q);
72}
73
74#define BL 0
75#define TR 1
76#define TL 2
77#define BR 3
78
79/* -------------------------------------------------------------------- */
82
83static float box_xmin_get(const BoxPack *box)
84{
85 return box->v[BL]->x;
86}
87
88static float box_xmax_get(const BoxPack *box)
89{
90 return box->v[TR]->x;
91}
92
93static float box_ymin_get(const BoxPack *box)
94{
95 return box->v[BL]->y;
96}
97
98static float box_ymax_get(const BoxPack *box)
99{
100 return box->v[TR]->y;
101}
102
104
105/* -------------------------------------------------------------------- */
108
110{
111 box->v[TL]->x = box->v[BL]->x;
112 box->v[BR]->x = box->v[TR]->x;
113}
114
116{
117 box->v[TL]->y = box->v[TR]->y;
118 box->v[BR]->y = box->v[BL]->y;
119}
120
121static void box_xmin_set(BoxPack *box, const float f)
122{
123 box->v[TR]->x = f + box->w;
124 box->v[BL]->x = f;
125 box_v34x_update(box);
126}
127
128static void box_xmax_set(BoxPack *box, const float f)
129{
130 box->v[BL]->x = f - box->w;
131 box->v[TR]->x = f;
132 box_v34x_update(box);
133}
134
135static void box_ymin_set(BoxPack *box, const float f)
136{
137 box->v[TR]->y = f + box->h;
138 box->v[BL]->y = f;
139 box_v34y_update(box);
140}
141
142static void box_ymax_set(BoxPack *box, const float f)
143{
144 box->v[BL]->y = f - box->h;
145 box->v[TR]->y = f;
146 box_v34y_update(box);
147}
148
150
151/* -------------------------------------------------------------------- */
154
155static float box_area(const BoxPack *box)
156{
157 return box->w * box->h;
158}
159
160static bool box_isect(const BoxPack *box_a, const BoxPack *box_b)
161{
162 return !(box_xmin_get(box_a) + EPSILON >= box_xmax_get(box_b) ||
163 box_ymin_get(box_a) + EPSILON >= box_ymax_get(box_b) ||
164 box_xmax_get(box_a) - EPSILON <= box_xmin_get(box_b) ||
165 box_ymax_get(box_a) - EPSILON <= box_ymin_get(box_b));
166}
167
169
170#ifdef USE_PACK_BIAS
171/* set when used is enabled */
173{
174 BLI_assert(v->used);
175 v->bias = (v->x * v->y) * EPSILON_BIAS;
176}
177#endif
178
179#if 0
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)
182#endif
183
184/* -------------------------------------------------------------------- */
187
188/* qsort function - sort largest to smallest */
189static int box_areasort(const void *p1, const void *p2)
190{
191 const BoxPack *b1 = static_cast<const BoxPack *>(p1);
192 const BoxPack *b2 = static_cast<const BoxPack *>(p2);
193 const float a1 = box_area(b1);
194 const float a2 = box_area(b2);
195
196 if (a1 < a2) {
197 return 1;
198 }
199 if (a1 > a2) {
200 return -1;
201 }
202 return 0;
203}
204
205/* qsort vertex sorting function
206 * sorts from lower left to top right It uses the current box's width and height
207 * as offsets when sorting, this has the result of not placing boxes outside
208 * the bounds of the existing backed area where possible
209 */
214
215static int vertex_sort(const void *p1, const void *p2, void *vs_ctx_p)
216{
217 const VertSortContext *vs_ctx = static_cast<const VertSortContext *>(vs_ctx_p);
218 const BoxVert *v1, *v2;
219 float a1, a2;
220
221 v1 = &vs_ctx->vertarray[*((const uint *)p1)];
222 v2 = &vs_ctx->vertarray[*((const uint *)p2)];
223
224#ifdef USE_FREE_STRIP
225 /* push free verts to the end so we can strip */
226 if (UNLIKELY(v1->free == 0 && v2->free == 0)) {
227 return 0;
228 }
229 if (UNLIKELY(v1->free == 0)) {
230 return 1;
231 }
232 if (UNLIKELY(v2->free == 0)) {
233 return -1;
234 }
235#endif
236
237 a1 = max_ff(v1->x + vs_ctx->box_width, v1->y + vs_ctx->box_height);
238 a2 = max_ff(v2->x + vs_ctx->box_width, v2->y + vs_ctx->box_height);
239
240#ifdef USE_PACK_BIAS
241 a1 += v1->bias;
242 a2 += v2->bias;
243#endif
244
245 /* sort largest to smallest */
246 if (a1 > a2) {
247 return 1;
248 }
249 if (a1 < a2) {
250 return -1;
251 }
252 return 0;
253}
254
256
258 BoxPack *boxarray, const uint len, const bool sort_boxes, float *r_tot_x, float *r_tot_y)
259{
260 uint box_index, verts_pack_len, i, j, k;
261 uint *vertex_pack_indices; /* an array of indices used for sorting verts */
262 bool isect;
263 float tot_x = 0.0f, tot_y = 0.0f;
264
265 BoxPack *box, *box_test; /* Current box and another for intersection tests. */
266 BoxVert *vert; /* The current vert. */
267
268 VertSortContext vs_ctx;
269
270 if (!len) {
271 *r_tot_x = tot_x;
272 *r_tot_y = tot_y;
273 return;
274 }
275
276 if (sort_boxes) {
277 /* Sort boxes, biggest first.
278 * Be careful, qsort is not deterministic! */
279 qsort(boxarray, size_t(len), sizeof(BoxPack), box_areasort);
280 }
281
282 /* Add verts to the boxes, these are only used internally. */
283 vert = MEM_malloc_arrayN<BoxVert>(4 * size_t(len), "BoxPack Verts");
284 vertex_pack_indices = MEM_malloc_arrayN<uint>(3 * size_t(len), "BoxPack Indices");
285
286 vs_ctx.vertarray = vert;
287
288 for (box = boxarray, box_index = 0, i = 0; box_index < len; box_index++, box++) {
289
290 vert->blb = vert->brb = vert->tlb = vert->isect_cache[0] = vert->isect_cache[1] =
291 vert->isect_cache[2] = vert->isect_cache[3] = nullptr;
292 vert->free = CORNERFLAGS & ~TRF;
293 vert->trb = box;
294 vert->used = false;
295 vert->index = i++;
296 box->v[BL] = vert++;
297
298 vert->trb = vert->brb = vert->tlb = vert->isect_cache[0] = vert->isect_cache[1] =
299 vert->isect_cache[2] = vert->isect_cache[3] = nullptr;
300 vert->free = CORNERFLAGS & ~BLF;
301 vert->blb = box;
302 vert->used = false;
303 vert->index = i++;
304 box->v[TR] = vert++;
305
306 vert->trb = vert->blb = vert->tlb = vert->isect_cache[0] = vert->isect_cache[1] =
307 vert->isect_cache[2] = vert->isect_cache[3] = nullptr;
308 vert->free = CORNERFLAGS & ~BRF;
309 vert->brb = box;
310 vert->used = false;
311 vert->index = i++;
312 box->v[TL] = vert++;
313
314 vert->trb = vert->blb = vert->brb = vert->isect_cache[0] = vert->isect_cache[1] =
315 vert->isect_cache[2] = vert->isect_cache[3] = nullptr;
316 vert->free = CORNERFLAGS & ~TLF;
317 vert->tlb = box;
318 vert->used = false;
319 vert->index = i++;
320 box->v[BR] = vert++;
321 }
322 vert = nullptr;
323
324 /* Pack the First box!
325 * then enter the main box-packing loop */
326
327 box = boxarray; /* Get the first box. */
328 /* First time, no boxes packed */
329 box->v[BL]->free = 0; /* Can't use any if these */
330 box->v[BR]->free &= ~(BLF | BRF);
331 box->v[TL]->free &= ~(BLF | TLF);
332
333 tot_x = box->w;
334 tot_y = box->h;
335
336 /* This sets all the vertex locations */
337 box_xmin_set(box, 0.0f);
338 box_ymin_set(box, 0.0f);
339 box->x = box->y = 0.0f;
340
341 for (i = 0; i < 4; i++) {
342 box->v[i]->used = true;
343#ifdef USE_PACK_BIAS
344 vert_bias_update(box->v[i]);
345#endif
346 }
347
348 for (i = 0; i < 3; i++) {
349 vertex_pack_indices[i] = box->v[i + 1]->index;
350 }
351 verts_pack_len = 3;
352 box++; /* next box, needed for the loop below */
353 /* ...done packing the first box */
354
355 /* Main box-packing loop */
356 for (box_index = 1; box_index < len; box_index++, box++) {
357
358 /* These floats are used for sorting re-sorting */
359 vs_ctx.box_width = box->w;
360 vs_ctx.box_height = box->h;
361
362 qsort_r(vertex_pack_indices, size_t(verts_pack_len), sizeof(int), vertex_sort, &vs_ctx);
363
364#ifdef USE_FREE_STRIP
365 /* strip free vertices */
366 i = verts_pack_len - 1;
367 while ((i != 0) && vs_ctx.vertarray[vertex_pack_indices[i]].free == 0) {
368 i--;
369 }
370 verts_pack_len = i + 1;
371#endif
372
373 /* Pack the box in with the others */
374 /* sort the verts */
375 isect = true;
376
377 for (i = 0; i < verts_pack_len && isect; i++) {
378 vert = &vs_ctx.vertarray[vertex_pack_indices[i]];
379 // printf("\ttesting vert %i %i %i %f %f\n", i,
380 // vert->free, verts_pack_len, vert->x, vert->y);
381
382 /* This vert has a free quadrant
383 * Test if we can place the box here
384 * `vert->free & quad_flags[j]` - Checks. */
385
386 for (j = 0; (j < 4) && isect; j++) {
387 if (vert->free & quad_flag(j)) {
388 switch (j) {
389 case BL:
390 box_xmax_set(box, vert->x);
391 box_ymax_set(box, vert->y);
392 break;
393 case TR:
394 box_xmin_set(box, vert->x);
395 box_ymin_set(box, vert->y);
396 break;
397 case TL:
398 box_xmax_set(box, vert->x);
399 box_ymin_set(box, vert->y);
400 break;
401 case BR:
402 box_xmin_set(box, vert->x);
403 box_ymax_set(box, vert->y);
404 break;
405 }
406
407 /* Now we need to check that the box intersects
408 * with any other boxes
409 * Assume no intersection... */
410 isect = false;
411
412 if (/* Constrain boxes to positive X/Y values */
413 box_xmin_get(box) < 0.0f || box_ymin_get(box) < 0.0f ||
414 /* check for last intersected */
415 (vert->isect_cache[j] && box_isect(box, vert->isect_cache[j])))
416 {
417 /* Here we check that the last intersected
418 * box will intersect with this one using
419 * isect_cache that can store a pointer to a
420 * box for each quadrant
421 * big speedup */
422 isect = true;
423 }
424 else {
425 /* do a full search for colliding box
426 * this is really slow, some spatially divided
427 * data-structure would be better */
428 for (box_test = boxarray; box_test != box; box_test++) {
429 if (box_isect(box, box_test)) {
430 /* Store the last intersecting here as cache
431 * for faster checking next time around */
432 vert->isect_cache[j] = box_test;
433 isect = true;
434 break;
435 }
436 }
437 }
438
439 if (!isect) {
440
441 /* maintain the total width and height */
442 tot_x = max_ff(box_xmax_get(box), tot_x);
443 tot_y = max_ff(box_ymax_get(box), tot_y);
444
445 /* Place the box */
446 vert->free &= ~quad_flag(j);
447
448 switch (j) {
449 case TR:
450 box->v[BL] = vert;
451 vert->trb = box;
452 break;
453 case TL:
454 box->v[BR] = vert;
455 vert->tlb = box;
456 break;
457 case BR:
458 box->v[TL] = vert;
459 vert->brb = box;
460 break;
461 case BL:
462 box->v[TR] = vert;
463 vert->blb = box;
464 break;
465 }
466
467 /* Mask free flags for verts that are
468 * on the bottom or side so we don't get
469 * boxes outside the given rectangle ares
470 *
471 * We can use `else if` here because only the first
472 * box can be at the very bottom left corner. */
473 if (box_xmin_get(box) <= 0) {
474 box->v[TL]->free &= ~(TLF | BLF);
475 box->v[BL]->free &= ~(TLF | BLF);
476 }
477 else if (box_ymin_get(box) <= 0) {
478 box->v[BL]->free &= ~(BRF | BLF);
479 box->v[BR]->free &= ~(BRF | BLF);
480 }
481
482 /* The following block of code does a logical
483 * check with 2 adjacent boxes, its possible to
484 * flag verts on one or both of the boxes
485 * as being used by checking the width or
486 * height of both boxes */
487 if (vert->tlb && vert->trb && ELEM(box, vert->tlb, vert->trb)) {
488 if (UNLIKELY(fabsf(vert->tlb->h - vert->trb->h) < EPSILON_MERGE)) {
489#ifdef USE_MERGE
490# define A (vert->trb->v[TL])
491# define B (vert->tlb->v[TR])
492# define MASK (BLF | BRF)
493 BLI_assert(A->used != B->used);
494 if (A->used) {
495 A->free &= B->free & ~MASK;
496 B = A;
497 }
498 else {
499 B->free &= A->free & ~MASK;
500 A = B;
501 }
502 BLI_assert((A->free & MASK) == 0);
503# undef A
504# undef B
505# undef MASK
506#else
507 vert->tlb->v[TR]->free &= ~BLF;
508 vert->trb->v[TL]->free &= ~BRF;
509#endif
510 }
511 else if (vert->tlb->h > vert->trb->h) {
512 vert->trb->v[TL]->free &= ~(TLF | BLF);
513 }
514 else /* if (vert->tlb->h < vert->trb->h) */ {
515 vert->tlb->v[TR]->free &= ~(TRF | BRF);
516 }
517 }
518 else if (vert->blb && vert->brb && ELEM(box, vert->blb, vert->brb)) {
519 if (UNLIKELY(fabsf(vert->blb->h - vert->brb->h) < EPSILON_MERGE)) {
520#ifdef USE_MERGE
521# define A (vert->blb->v[BR])
522# define B (vert->brb->v[BL])
523# define MASK (TRF | TLF)
524 BLI_assert(A->used != B->used);
525 if (A->used) {
526 A->free &= B->free & ~MASK;
527 B = A;
528 }
529 else {
530 B->free &= A->free & ~MASK;
531 A = B;
532 }
533 BLI_assert((A->free & MASK) == 0);
534# undef A
535# undef B
536# undef MASK
537#else
538 vert->blb->v[BR]->free &= ~TRF;
539 vert->brb->v[BL]->free &= ~TLF;
540#endif
541 }
542 else if (vert->blb->h > vert->brb->h) {
543 vert->brb->v[BL]->free &= ~(TLF | BLF);
544 }
545 else /* if (vert->blb->h < vert->brb->h) */ {
546 vert->blb->v[BR]->free &= ~(TRF | BRF);
547 }
548 }
549 /* Horizontal */
550 if (vert->tlb && vert->blb && ELEM(box, vert->tlb, vert->blb)) {
551 if (UNLIKELY(fabsf(vert->tlb->w - vert->blb->w) < EPSILON_MERGE)) {
552#ifdef USE_MERGE
553# define A (vert->blb->v[TL])
554# define B (vert->tlb->v[BL])
555# define MASK (TRF | BRF)
556 BLI_assert(A->used != B->used);
557 if (A->used) {
558 A->free &= B->free & ~MASK;
559 B = A;
560 }
561 else {
562 B->free &= A->free & ~MASK;
563 A = B;
564 }
565 BLI_assert((A->free & MASK) == 0);
566# undef A
567# undef B
568# undef MASK
569#else
570 vert->blb->v[TL]->free &= ~TRF;
571 vert->tlb->v[BL]->free &= ~BRF;
572#endif
573 }
574 else if (vert->tlb->w > vert->blb->w) {
575 vert->blb->v[TL]->free &= ~(TLF | TRF);
576 }
577 else /* if (vert->tlb->w < vert->blb->w) */ {
578 vert->tlb->v[BL]->free &= ~(BLF | BRF);
579 }
580 }
581 else if (vert->trb && vert->brb && ELEM(box, vert->trb, vert->brb)) {
582 if (UNLIKELY(fabsf(vert->trb->w - vert->brb->w) < EPSILON_MERGE)) {
583
584#ifdef USE_MERGE
585# define A (vert->brb->v[TR])
586# define B (vert->trb->v[BR])
587# define MASK (TLF | BLF)
588 BLI_assert(A->used != B->used);
589 if (A->used) {
590 A->free &= B->free & ~MASK;
591 B = A;
592 }
593 else {
594 B->free &= A->free & ~MASK;
595 A = B;
596 }
597 BLI_assert((A->free & MASK) == 0);
598# undef A
599# undef B
600# undef MASK
601#else
602 vert->brb->v[TR]->free &= ~TLF;
603 vert->trb->v[BR]->free &= ~BLF;
604#endif
605 }
606 else if (vert->trb->w > vert->brb->w) {
607 vert->brb->v[TR]->free &= ~(TLF | TRF);
608 }
609 else /* if (vert->trb->w < vert->brb->w) */ {
610 vert->trb->v[BR]->free &= ~(BLF | BRF);
611 }
612 }
613 /* End logical check */
614
615 for (k = 0; k < 4; k++) {
616 if (box->v[k]->used == false) {
617 box->v[k]->used = true;
618#ifdef USE_PACK_BIAS
619 vert_bias_update(box->v[k]);
620#endif
621 vertex_pack_indices[verts_pack_len] = box->v[k]->index;
622 verts_pack_len++;
623 }
624 }
625 /* The Box verts are only used internally
626 * Update the box x and y since that's what external
627 * functions will see */
628 box->x = box_xmin_get(box);
629 box->y = box_ymin_get(box);
630 }
631 }
632 }
633 }
634 }
635
636 *r_tot_x = tot_x;
637 *r_tot_y = tot_y;
638
639 /* free all the verts, not really needed because they shouldn't be
640 * touched anymore but accessing the pointers would crash blender */
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;
644 }
645 MEM_freeN(vertex_pack_indices);
646 MEM_freeN(vs_ctx.vertarray);
647}
648
649void BLI_box_pack_2d_fixedarea(ListBase *boxes, int width, int height, ListBase *packed)
650{
651 ListBase spaces = {nullptr};
652 FixedSizeBoxPack *full_rect = MEM_callocN<FixedSizeBoxPack>(__func__);
653 full_rect->w = width;
654 full_rect->h = height;
655
656 BLI_addhead(&spaces, full_rect);
657
658 /* The basic idea of the algorithm is to keep a list of free spaces in the packing area.
659 * Then, for each box to be packed, we try to find a space that can contain it.
660 * The found space is then split into the area that is occupied by the box and the
661 * remaining area, which is reinserted into the free space list.
662 * By inserting the smaller remaining spaces first, the algorithm tries to use these
663 * smaller spaces first instead of "wasting" a large space. */
665 LISTBASE_FOREACH (FixedSizeBoxPack *, space, &spaces) {
666 /* Skip this space if it's too small. */
667 if (box->w > space->w || box->h > space->h) {
668 continue;
669 }
670
671 /* Pack this box into this space. */
672 box->x = space->x;
673 box->y = space->y;
674 BLI_remlink(boxes, box);
675 BLI_addtail(packed, box);
676
677 if (box->w == space->w && box->h == space->h) {
678 /* Box exactly fills space, so just remove the space. */
679 BLI_remlink(&spaces, space);
680 MEM_freeN(space);
681 }
682 else if (box->w == space->w) {
683 /* Box fills the entire width, so we can just contract the box
684 * to the upper part that remains. */
685 space->y += box->h;
686 space->h -= box->h;
687 }
688 else if (box->h == space->h) {
689 /* Box fills the entire height, so we can just contract the box
690 * to the right part that remains. */
691 space->x += box->w;
692 space->w -= box->w;
693 }
694 else {
695 /* Split the remaining L-shaped space into two spaces.
696 * There are two ways to do so, we pick the one that produces the biggest
697 * remaining space:
698 *
699 * Horizontal Split Vertical Split
700 * ################### ###################
701 * # # # - #
702 * # Large # # Small - #
703 * # # # - #
704 * #********---------# #******** Large #
705 * # Box * Small # # Box * #
706 * # * # # * #
707 * ################### ###################
708 */
709 int area_hsplit_large = space->w * (space->h - box->h);
710 int area_vsplit_large = (space->w - box->w) * space->h;
711
712 /* Perform split. This space becomes the larger space,
713 * while the new smaller space is inserted _before_ it. */
714 FixedSizeBoxPack *new_space = MEM_callocN<FixedSizeBoxPack>(__func__);
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;
720
721 space->y += box->h;
722 space->h -= box->h;
723 }
724 else {
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;
729
730 space->x += box->w;
731 space->w -= box->w;
732 }
733 BLI_addhead(&spaces, new_space);
734 }
735
736 break;
737 }
738 }
739
740 BLI_freelistN(&spaces);
741}
#define BLI_assert(a)
Definition BLI_assert.h:46
#define BLI_INLINE
#define LISTBASE_FOREACH(type, var, list)
#define LISTBASE_FOREACH_MUTABLE(type, var, list)
void void BLI_freelistN(ListBase *listbase) ATTR_NONNULL(1)
Definition listbase.cc:497
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:111
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:131
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:91
MINLINE float max_ff(float a, float b)
unsigned int uint
#define UNLIKELY(x)
#define ELEM(...)
Read Guarded memory(de)allocation.
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMVert * v
#define EPSILON
Definition boxpack_2d.cc:57
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)
#define qsort_r
Definition boxpack_2d.cc:20
static void vert_bias_update(BoxVert *v)
#define TL
Definition boxpack_2d.cc:76
static float box_xmax_get(const BoxPack *box)
Definition boxpack_2d.cc:88
#define TR
Definition boxpack_2d.cc:75
#define TRF
Definition boxpack_2d.cc:63
#define TLF
Definition boxpack_2d.cc:64
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)
Definition boxpack_2d.cc:98
static float box_ymin_get(const BoxPack *box)
Definition boxpack_2d.cc:93
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)
#define CORNERFLAGS
Definition boxpack_2d.cc:66
#define A
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)
Definition boxpack_2d.cc:83
BLI_INLINE int quad_flag(uint q)
Definition boxpack_2d.cc:68
#define BLF
Definition boxpack_2d.cc:62
#define BRF
Definition boxpack_2d.cc:65
#define EPSILON_BIAS
Definition boxpack_2d.cc:60
static float box_area(const BoxPack *box)
static void box_xmax_set(BoxPack *box, const float f)
#define BL
Definition boxpack_2d.cc:74
#define EPSILON_MERGE
Definition boxpack_2d.cc:58
#define MASK
#define BR
Definition boxpack_2d.cc:77
#define packed
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void * MEM_malloc_arrayN(size_t len, size_t size, const char *str)
Definition mallocn.cc:133
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
#define B
#define fabsf
struct BoxVert * v[4]
BoxPack * blb
Definition boxpack_2d.cc:47
bool used
Definition boxpack_2d.cc:39
BoxPack * tlb
Definition boxpack_2d.cc:49
float x
Definition boxpack_2d.cc:35
float y
Definition boxpack_2d.cc:36
BoxPack * trb
Definition boxpack_2d.cc:46
float bias
Definition boxpack_2d.cc:43
uint index
Definition boxpack_2d.cc:40
BoxPack * brb
Definition boxpack_2d.cc:48
BoxPack * isect_cache[4]
Definition boxpack_2d.cc:53
BoxVert * vertarray
i
Definition text_draw.cc:230
uint len