Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2014-04-24 19:02:51 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-04-24 21:13:35 +0400
commit6c57ee53bfff5c06edafa30c9893dbc1841a8688 (patch)
tree02607f0d8e4d04af03ea43186a11b9818e702eee /source
parentb8ea2e73d2b10b6c1db46dcc14471c1291ef1bd2 (diff)
Box Pack: Improve when packing boxes of the same size
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenlib/intern/boxpack2d.c52
1 files changed, 28 insertions, 24 deletions
diff --git a/source/blender/blenlib/intern/boxpack2d.c b/source/blender/blenlib/intern/boxpack2d.c
index 4b51aefbd87..52d746c3af4 100644
--- a/source/blender/blenlib/intern/boxpack2d.c
+++ b/source/blender/blenlib/intern/boxpack2d.c
@@ -25,12 +25,15 @@
*/
#include <stdlib.h> /* for qsort */
+#include <math.h> /* for fabsf */
#include "MEM_guardedalloc.h"
-#include "BLI_strict_flags.h"
+#include "BLI_utildefines.h"
#include "BLI_boxpack2d.h" /* own include */
+#include "BLI_strict_flags.h"
+
#ifdef __GNUC__
# pragma GCC diagnostic error "-Wpadded"
#endif
@@ -57,6 +60,7 @@ typedef struct BoxVert {
/* free vert flags */
#define EPSILON 0.0000001f
+#define EPSILON_MERGE 0.00001f
#define BLF 1
#define TRF 2
#define TLF 4
@@ -367,53 +371,53 @@ void BLI_box_pack_2d(BoxPack *boxarray, const unsigned int len, float *tot_width
* as being used by checking the width or
* height of both boxes */
if (vert->tlb && vert->trb && (box == vert->tlb || box == vert->trb)) {
+ if (UNLIKELY(fabsf(vert->tlb->h - vert->trb->h) < EPSILON_MERGE)) {
+ vert->tlb->v[TR]->free &= ~BLF;
+ vert->trb->v[TL]->free &= ~BRF;
+ }
if (vert->tlb->h > vert->trb->h) {
vert->trb->v[TL]->free &= ~(TLF | BLF);
}
- else if (vert->tlb->h < vert->trb->h) {
+ else /* if (vert->tlb->h < vert->trb->h) */ {
vert->tlb->v[TR]->free &= ~(TRF | BRF);
}
- else { /*same*/
- vert->tlb->v[TR]->free &= ~BLF;
- vert->trb->v[TL]->free &= ~BRF;
- }
}
else if (vert->blb && vert->brb && (box == vert->blb || box == vert->brb)) {
- if (vert->blb->h > vert->brb->h) {
+ if (UNLIKELY(fabsf(vert->blb->h - vert->brb->h) < EPSILON_MERGE)) {
+ vert->blb->v[BR]->free &= ~TRF;
+ vert->brb->v[BL]->free &= ~TLF;
+ }
+ else if (vert->blb->h > vert->brb->h) {
vert->brb->v[BL]->free &= ~(TLF | BLF);
}
- else if (vert->blb->h < vert->brb->h) {
+ else /* if (vert->blb->h < vert->brb->h) */ {
vert->blb->v[BR]->free &= ~(TRF | BRF);
}
- else { /*same*/
- vert->blb->v[BR]->free &= ~TRF;
- vert->brb->v[BL]->free &= ~TLF;
- }
}
/* Horizontal */
if (vert->tlb && vert->blb && (box == vert->tlb || box == vert->blb)) {
- if (vert->tlb->w > vert->blb->w) {
+ if (UNLIKELY(fabsf(vert->tlb->w - vert->blb->w) < EPSILON_MERGE)) {
+ vert->blb->v[TL]->free &= ~TRF;
+ vert->tlb->v[BL]->free &= ~BRF;
+ }
+ else if (vert->tlb->w > vert->blb->w) {
vert->blb->v[TL]->free &= ~(TLF | TRF);
}
- else if (vert->tlb->w < vert->blb->w) {
+ else /* if (vert->tlb->w < vert->blb->w) */ {
vert->tlb->v[BL]->free &= ~(BLF | BRF);
}
- else { /*same*/
- vert->blb->v[TL]->free &= ~TRF;
- vert->tlb->v[BL]->free &= ~BRF;
- }
}
else if (vert->trb && vert->brb && (box == vert->trb || box == vert->brb)) {
- if (vert->trb->w > vert->brb->w) {
+ if (UNLIKELY(fabsf(vert->trb->w - vert->brb->w) < EPSILON_MERGE)) {
+ vert->brb->v[TR]->free &= ~TLF;
+ vert->trb->v[BR]->free &= ~BLF;
+ }
+ else if (vert->trb->w > vert->brb->w) {
vert->brb->v[TR]->free &= ~(TLF | TRF);
}
- else if (vert->trb->w < vert->brb->w) {
+ else /* if (vert->trb->w < vert->brb->w) */ {
vert->trb->v[BR]->free &= ~(BLF | BRF);
}
- else { /*same*/
- vert->brb->v[TR]->free &= ~TLF;
- vert->trb->v[BR]->free &= ~BLF;
- }
}
/* End logical check */