Revision: 44785
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44785
Author:   campbellbarton
Date:     2012-03-10 14:43:12 +0000 (Sat, 10 Mar 2012)
Log Message:
-----------
style cleanup

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/intern/boxpack2d.c

Modified: trunk/blender/source/blender/blenlib/intern/boxpack2d.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/boxpack2d.c     2012-03-10 
14:20:55 UTC (rev 44784)
+++ trunk/blender/source/blender/blenlib/intern/boxpack2d.c     2012-03-10 
14:43:12 UTC (rev 44785)
@@ -24,12 +24,11 @@
  *  \ingroup bli
  */
 
-
 #include <stdlib.h> /* for qsort */
 
 #include "MEM_guardedalloc.h"
 #include "BLI_boxpack2d.h"
- 
+
 /* BoxPacker for backing 2D rectangles into a square
  * 
  * The defined Below are for internal use only */
@@ -52,7 +51,7 @@
 } boxVert;
 
 /* free vert flags */
-#define eps 0.0000001f
+#define EPSILON 0.0000001f
 #define BLF 1
 #define TRF 2
 #define TLF 4
@@ -64,52 +63,54 @@
 #define TL 2
 #define BR 3
 
-#define BOXLEFT(b)             b->v[BL]->x
-#define BOXRIGHT(b)            b->v[TR]->x
-#define BOXBOTTOM(b)   b->v[BL]->y
-#define BOXTOP(b)              b->v[TR]->y
-#define BOXAREA(b)             (b->w * b->h)
+#define BOXLEFT(b)             ((b)->v[BL]->x)
+#define BOXRIGHT(b)            ((b)->v[TR]->x)
+#define BOXBOTTOM(b)   ((b)->v[BL]->y)
+#define BOXTOP(b)              ((b)->v[TR]->y)
+#define BOXAREA(b)             ((b)->w * (b)->h)
 
-#define UPDATE_V34X(b) b->v[TL]->x = b->v[BL]->x;\
-                                               b->v[BR]->x = b->v[TR]->x
-#define UPDATE_V34Y(b) b->v[TL]->y = b->v[TR]->y;\
-                                               b->v[BR]->y = b->v[BL]->y
-#define UPDATE_V34(b) UPDATE_V34X(b); UPDATE_V34Y(b)  
+#define UPDATE_V34X(b) ((b)->v[TL]->x = (b)->v[BL]->x); \
+                                               ((b)->v[BR]->x = (b)->v[TR]->x)
+#define UPDATE_V34Y(b) ((b)->v[TL]->y = (b)->v[TR]->y); \
+                                               ((b)->v[BR]->y = (b)->v[BL]->y)
+#define UPDATE_V34(b) UPDATE_V34X(b); UPDATE_V34Y(b)
 
-#define SET_BOXLEFT(b, f)      b->v[TR]->x = f + b->w;\
-                                                       b->v[BL]->x = f;\
+#define SET_BOXLEFT(b, f)      (b)->v[TR]->x = f + (b)->w; \
+                                                       (b)->v[BL]->x = f;      
    \
                                                        UPDATE_V34X(b)
-#define SET_BOXRIGHT(b, f)     b->v[BL]->x = f - b->w;\
-                                                       b->v[TR]->x = f;\
+#define SET_BOXRIGHT(b, f)     (b)->v[BL]->x = f - (b)->w; \
+                                                       (b)->v[TR]->x = f;      
    \
                                                        UPDATE_V34X(b)
-#define SET_BOXBOTTOM(b, f)    b->v[TR]->y = f + b->h;\
-                                                       b->v[BL]->y = f;\
+#define SET_BOXBOTTOM(b, f)    (b)->v[TR]->y = f + (b)->h; \
+                                                       (b)->v[BL]->y = f;      
    \
                                                        UPDATE_V34Y(b)
-#define SET_BOXTOP(b, f)       b->v[BL]->y = f - b->h;\
-                                                       b->v[TR]->y = f;\
+#define SET_BOXTOP(b, f)       (b)->v[BL]->y = f - (b)->h; \
+                                                       (b)->v[TR]->y = f;      
    \
                                                        UPDATE_V34Y(b)
-#define BOXINTERSECT(b1, b2)\
-       (!( BOXLEFT(b1)+eps>=BOXRIGHT(b2) ||\
-               BOXBOTTOM(b1)+eps>=BOXTOP(b2) ||\
-               BOXRIGHT(b1)-eps<=BOXLEFT(b2) ||\
-               BOXTOP(b1)-eps<=BOXBOTTOM(b2) ))
+#define BOXINTERSECT(b1, b2)                 \
+       !(BOXLEFT(b1)   + EPSILON >= BOXRIGHT(b2) || \
+         BOXBOTTOM(b1) + EPSILON >= BOXTOP(b2)   || \
+         BOXRIGHT(b1)  - EPSILON <= BOXLEFT(b2)  || \
+         BOXTOP(b1)    - EPSILON <= BOXBOTTOM(b2))
 
-#define MIN2(x,y)               ( (x)<(y) ? (x) : (y) )
-#define MAX2(x,y)               ( (x)>(y) ? (x) : (y) )
+#define MIN2(x,y)               ((x) < (y) ? (x) : (y))
+#define MAX2(x,y)               ((x) > (y) ? (x) : (y))
 
-/* #define BOXDEBUG(b)\
- *             printf("\tBox Debug i %i, w:%.3f h:%.3f x:%.3f y:%.3f\n",\
- *             b->index, b->w, b->h, b->x, b->y) */
+#if 0
+#define BOXDEBUG(b) \
+       printf("\tBox Debug i %i, w:%.3f h:%.3f x:%.3f y:%.3f\n", \
+       b->index, b->w, b->h, b->x, b->y)
+#endif
 
 /* qsort function - sort largest to smallest */
 static int box_areasort(const void *p1, const void *p2)
 {
-       const boxPack *b1= p1, *b2= p2;
-       const float a1= BOXAREA(b1);
-       const float a2= BOXAREA(b2);
+       const boxPack *b1 = p1, *b2 = p2;
+       const float a1 = BOXAREA(b1);
+       const float a2 = BOXAREA(b2);
 
-       if              ( a1 < a2 ) return  1;
-       else if ( a1 > a2 ) return -1;
+       if      (a1 < a2) return  1;
+       else if (a1 > a2) return -1;
        return 0;
 }
 
@@ -126,16 +127,16 @@
 {
        boxVert *v1, *v2;
        float a1, a2;
-       
-       v1 = vertarray + ((int *) p1)[0];
-       v2 = vertarray + ((int *) p2)[0];
-       
+
+       v1 = vertarray + ((int *)p1)[0];
+       v2 = vertarray + ((int *)p2)[0];
+
        a1 = MAX2(v1->x+box_width, v1->y+box_height);
        a2 = MAX2(v2->x+box_width, v2->y+box_height);
-       
+
        /* sort largest to smallest */
-       if              ( a1 > a2 ) return  1;
-       else if ( a1 < a2 ) return -1;
+       if      (a1 > a2) return  1;
+       else if (a1 < a2) return -1;
        return 0;
 }
 /* Main boxpacking function accessed from other functions
@@ -155,25 +156,25 @@
 {
        boxVert *vert; /* the current vert */
        int box_index, verts_pack_len, i, j, k, isect;
-       int quad_flags[4]= {BLF,TRF,TLF,BRF}; /* use for looping */
+       int quad_flags[4] = {BLF, TRF, TLF, BRF}; /* use for looping */
        boxPack *box, *box_test; /*current box and another for intersection 
tests*/
        int *vertex_pack_indices; /*an array of indices used for sorting verts*/
-       
+
        if (!len) {
-               *tot_width =  0.0f;
+               *tot_width = 0.0f;
                *tot_height = 0.0f;
                return;
        }
-       
+
        /* Sort boxes, biggest first */
        qsort(boxarray, len, sizeof(boxPack), box_areasort);
-       
+
        /* add verts to the boxes, these are only used internally  */
-       vert = vertarray = MEM_mallocN( len*4*sizeof(boxVert), "boxPack Verts");
-       vertex_pack_indices = MEM_mallocN( len*3*sizeof(int), "boxPack 
Indices");
-       
-       for (box=boxarray, box_index=0, i=0; box_index < len; box_index++, 
box++) {
+       vert = vertarray = MEM_mallocN(len * 4 * sizeof(boxVert), "boxPack 
Verts");
+       vertex_pack_indices = MEM_mallocN(len * 3 * sizeof(int), "boxPack 
Indices");
 
+       for (box = boxarray, box_index = 0, i = 0; box_index < len; 
box_index++, box++) {
+
                vert->blb = vert->brb = vert->tlb =
                        vert->isect_cache[0] = vert->isect_cache[1] =
                        vert->isect_cache[2] = vert->isect_cache[3] = NULL;
@@ -207,98 +208,98 @@
                box->v[BR] = vert; vert++;
        }
        vert = NULL;
-       
-       
+
        /* Pack the First box!
         * then enter the main box-packing loop */
-       
+
        box = boxarray; /* get the first box  */
        /* First time, no boxes packed */
        box->v[BL]->free = 0; /* Can't use any if these */
-       box->v[BR]->free &= ~(BLF|BRF);
-       box->v[TL]->free &= ~(BLF|TLF);
-       
+       box->v[BR]->free &= ~(BLF | BRF);
+       box->v[TL]->free &= ~(BLF | TLF);
+
        *tot_width = box->w;
-       *tot_height = box->h; 
-       
+       *tot_height = box->h;
+
        /* This sets all the vertex locations */
        SET_BOXLEFT(box, 0.0f);
        SET_BOXBOTTOM(box, 0.0f);
        box->x = box->y = 0.0f;
-       
-       for (i=0; i<3; i++)
-               vertex_pack_indices[i] = box->v[i+1]->index; 
+
+       for (i = 0; i < 3; i++)
+               vertex_pack_indices[i] = box->v[i + 1]->index;
        verts_pack_len = 3;
        box++; /* next box, needed for the loop below */
        /* ...done packing the first box */
 
        /* Main boxpacking loop */
-       for (box_index=1; box_index < len; box_index++, box++) {
-               
+       for (box_index = 1; box_index < len; box_index++, box++) {
+
                /* These static floatds are used for sorting */
                box_width = box->w;
                box_height = box->h;
-               
+
                qsort(vertex_pack_indices, verts_pack_len, sizeof(int), 
vertex_sort);
-               
+
                /* Pack the box in with the others */
                /* sort the verts */
                isect = 1;
-               
-               for (i=0; i<verts_pack_len && isect; i++) {
+
+               for (i = 0; i < verts_pack_len && isect; i++) {
                        vert = vertarray + vertex_pack_indices[i];
                        /* printf("\ttesting vert %i %i %i %f %f\n", i,
                         *              vert->free, verts_pack_len, vert->x, 
vert->y); */
-                       
+
                        /* This vert has a free quadrant
                         * Test if we can place the box here
                         * vert->free & quad_flags[j] - Checks 
                         * */
-                                               
-                       for (j=0; (j<4) && isect; j++) {
+
+                       for (j = 0; (j < 4) && isect; j++) {
                                if (vert->free & quad_flags[j]) {
                                        switch (j) {
-                                       case BL:
-                                               SET_BOXRIGHT(box, vert->x);
-                                               SET_BOXTOP(box, vert->y);
-                                               break;
-                                       case TR:
-                                               SET_BOXLEFT(box, vert->x);
-                                               SET_BOXBOTTOM(box, vert->y);
-                                               break;
-                                       case TL:
-                                               SET_BOXRIGHT(box, vert->x);
-                                               SET_BOXBOTTOM(box, vert->y);
-                                               break;
-                                       case BR:
-                                               SET_BOXLEFT(box, vert->x);
-                                               SET_BOXTOP(box, vert->y);
-                                               break;
+                                               case BL:
+                                                       SET_BOXRIGHT(box, 
vert->x);
+                                                       SET_BOXTOP(box, 
vert->y);
+                                                       break;
+                                               case TR:
+                                                       SET_BOXLEFT(box, 
vert->x);
+                                                       SET_BOXBOTTOM(box, 
vert->y);
+                                                       break;
+                                               case TL:
+                                                       SET_BOXRIGHT(box, 
vert->x);
+                                                       SET_BOXBOTTOM(box, 
vert->y);
+                                                       break;
+                                               case BR:
+                                                       SET_BOXLEFT(box, 
vert->x);
+                                                       SET_BOXTOP(box, 
vert->y);
+                                                       break;
                                        }
-                                       
+
                                        /* Now we need to check that the box 
intersects
                                         * with any other boxes
                                         * Assume no intersection... */
                                        isect = 0;
                                        
                                        if (/* Constrain boxes to positive X/Y 
values */
-                                               BOXLEFT(box)<0.0f || 
BOXBOTTOM(box) < 0.0f ||
+                                               BOXLEFT(box) < 0.0f || 
BOXBOTTOM(box) < 0.0f ||
                                                /* check for last intersected */
                                                (       vert->isect_cache[j] &&
-                                                       BOXINTERSECT(box, 
vert->isect_cache[j]) )
-                                          ) {
+                                                       BOXINTERSECT(box, 
vert->isect_cache[j])))
+                                       {
                                                /* Here we check that the last 
intersected
                                                 * box will intersect with this 
one using
                                                 * isect_cache that can store a 
pointer to a
                                                 * box for each quadrant
                                                 * big speedup */
                                                isect = 1;
-                                       } else {
+                                       }
+                                       else {
                                                /* do a full search for 
colliding box
                                                 * this is really slow, some 
spatially divided
                                                 * data-structure would be 
better */
-                                               for (box_test=boxarray; 
box_test != box; box_test++) {
-                                                       if BOXINTERSECT(box, 
box_test) {
+                                               for (box_test = boxarray; 
box_test != box; box_test++) {
+                                                       if (BOXINTERSECT(box, 
box_test)) {
                                                                /* Store the 
last intersecting here as cache
                                                                 * for faster 
checking next time around */
                                                                
vert->isect_cache[j] = box_test;
@@ -307,35 +308,35 @@
                                                        }
                                                }
                                        }
-                                       
+
                                        if (!isect) {
-                                               
+
                                                /* maintain the total width and 
height */
                                                (*tot_width) = 
MAX2(BOXRIGHT(box), (*tot_width));
                                                (*tot_height) = 
MAX2(BOXTOP(box), (*tot_height));
-                                               
+
                                                /* Place the box */
                                                vert->free &= ~quad_flags[j];
-                                               
+
                                                switch (j) {
-                                               case TR:
-                                                       box->v[BL]= vert;
-                                                       vert->trb = box;
-                                                        break;
-                                               case TL:
-                                                       box->v[BR]= vert;
-                                                       vert->tlb = box;
-                                                        break;
-                                               case BR:
-                                                       box->v[TL]= vert;
-                                                       vert->brb = box;
-                                                       break;
-                                               case BL:
-                                                       box->v[TR]= vert;
-                                                       vert->blb = box;
-                                                        break;
+                                                       case TR:
+                                                               box->v[BL] = 
vert;
+                                                               vert->trb = box;
+                                                               break;
+                                                       case TL:
+                                                               box->v[BR] = 
vert;
+                                                               vert->tlb = box;
+                                                               break;
+                                                       case BR:
+                                                               box->v[TL] = 
vert;
+                                                               vert->brb = box;
+                                                               break;
+                                                       case BL:
+                                                               box->v[TR] = 
vert;
+                                                               vert->blb = box;
+                                                               break;

@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to