Revision: 42662
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42662
Author:   campbellbarton
Date:     2011-12-16 07:27:56 +0000 (Fri, 16 Dec 2011)
Log Message:
-----------
minor cleanup to mirror code
- MirrTopoPair.hash was 'long' when only needed to be 'int'
- use 'intptr_t' rather than 'long' when the value is cast back to a pointer.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/include/ED_mesh.h
    trunk/blender/source/blender/editors/mesh/meshtools.c

Modified: trunk/blender/source/blender/editors/include/ED_mesh.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_mesh.h      2011-12-16 
04:16:52 UTC (rev 42661)
+++ trunk/blender/source/blender/editors/include/ED_mesh.h      2011-12-16 
07:27:56 UTC (rev 42662)
@@ -87,8 +87,8 @@
 
 /* meshtools.c */
 
-intptr_t       mesh_octree_table(struct Object *ob, struct EditMesh *em, float 
*co, char mode);
-long           mesh_mirrtopo_table(struct Object *ob, char mode);
+intptr_t   mesh_octree_table(struct Object *ob, struct EditMesh *em, float 
*co, char mode);
+int        mesh_mirrtopo_table(struct Object *ob, char mode);
 
 struct EditVert   *editmesh_get_x_mirror_vert(struct Object *ob, struct 
EditMesh *em, struct EditVert *eve, float *co, int index);
 int                    mesh_get_x_mirror_vert(struct Object *ob, int index);

Modified: trunk/blender/source/blender/editors/mesh/meshtools.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/meshtools.c       2011-12-16 
04:16:52 UTC (rev 42661)
+++ trunk/blender/source/blender/editors/mesh/meshtools.c       2011-12-16 
07:27:56 UTC (rev 42662)
@@ -671,17 +671,17 @@
 
 
 /* temporal define, just to make nicer code below */
-#define MOC_ADDNODE(vx, vy, vz)        mesh_octree_add_node(basetable + 
((vx)*MOC_RES*MOC_RES) + (vy)*MOC_RES + (vz), index)
+#define MOC_INDEX(vx, vy, vz)  (((vx)*MOC_RES*MOC_RES) + (vy)*MOC_RES + (vz))
 
 static void mesh_octree_add_nodes(MocNode **basetable, float *co, float *offs, 
float *div, intptr_t index)
 {
        float fx, fy, fz;
        int vx, vy, vz;
        
-       if (!finite(co[0]) ||
-               !finite(co[1]) ||
-               !finite(co[2])
-       ) {
+       if ( !finite(co[0]) ||
+            !finite(co[1]) ||
+            !finite(co[2]))
+       {
                return;
        }
        
@@ -692,33 +692,33 @@
        CLAMP(fy, 0.0f, MOC_RES-MOC_THRESH);
        CLAMP(fz, 0.0f, MOC_RES-MOC_THRESH);
        
-       vx= floor(fx);
-       vy= floor(fy);
-       vz= floor(fz);
-       
-       MOC_ADDNODE(vx, vy, vz);
-       
-       if( vx>0 )
-               if( fx-((float)vx)-MOC_THRESH < 0.0f)
-                       MOC_ADDNODE(vx-1, vy, vz);
-       if( vx<MOC_RES-2 )
-               if( fx-((float)vx)+MOC_THRESH > 1.0f)
-                       MOC_ADDNODE(vx+1, vy, vz);
+       vx= (int)floorf(fx);
+       vy= (int)floorf(fy);
+       vz= (int)floorf(fz);
 
-       if( vy>0 )
-               if( fy-((float)vy)-MOC_THRESH < 0.0f) 
-                       MOC_ADDNODE(vx, vy-1, vz);
-       if( vy<MOC_RES-2 )
-               if( fy-((float)vy)+MOC_THRESH > 1.0f) 
-                       MOC_ADDNODE(vx, vy+1, vz);
+       mesh_octree_add_node(basetable + MOC_INDEX(vx, vy, vz), index);
 
-       if( vz>0 )
-               if( fz-((float)vz)-MOC_THRESH < 0.0f) 
-                       MOC_ADDNODE(vx, vy, vz-1);
-       if( vz<MOC_RES-2 )
-               if( fz-((float)vz)+MOC_THRESH > 1.0f) 
-                       MOC_ADDNODE(vx, vy, vz+1);
-       
+       if (vx > 0)
+               if (fx-((float)vx)-MOC_THRESH < 0.0f)
+                       mesh_octree_add_node(basetable + MOC_INDEX(vx - 1, vy, 
vz), index);
+       if (vx < MOC_RES - 2)
+               if (fx-((float)vx)+MOC_THRESH > 1.0f)
+                       mesh_octree_add_node(basetable + MOC_INDEX(vx + 1, vy, 
vz), index);
+
+       if (vy > 0)
+               if (fy-((float)vy)-MOC_THRESH < 0.0f)
+                       mesh_octree_add_node(basetable + MOC_INDEX(vx, vy - 1, 
vz), index);
+       if (vy < MOC_RES - 2)
+               if (fy-((float)vy)+MOC_THRESH > 1.0f)
+                       mesh_octree_add_node(basetable + MOC_INDEX(vx, vy + 1, 
vz), index);
+
+       if (vz > 0)
+               if (fz-((float)vz)-MOC_THRESH < 0.0f)
+                       mesh_octree_add_node(basetable + MOC_INDEX(vx, vy, vz - 
1), index);
+       if (vz <MOC_RES - 2)
+               if (fz-((float)vz)+MOC_THRESH > 1.0f)
+                       mesh_octree_add_node(basetable + MOC_INDEX(vx, vy, vz + 
1), index);
+
 }
 
 static intptr_t mesh_octree_find_index(MocNode **bt, MVert *mvert, float *co)
@@ -851,35 +851,36 @@
 
 /* ********************* MESH VERTEX MIRR TOPO LOOKUP *************** */
 
-#define MIRRHASH_TYPE int
+typedef int MirrTopoHash_t;
 
-typedef struct MirrTopoPair {
-       long hash;
-       int vIndex;
-} MirrTopoPair;
+typedef struct MirrTopoPair_t {
+       MirrTopoHash_t  hash;
+       int            vIndex;
+} MirrTopoPair_t;
 
 static int MirrTopo_long_sort(const void *l1, const void *l2)
 {
-       if(                     (MIRRHASH_TYPE)(intptr_t)l1 > 
(MIRRHASH_TYPE)(intptr_t)l2 ) return  1;
-       else if(        (MIRRHASH_TYPE)(intptr_t)l1 < 
(MIRRHASH_TYPE)(intptr_t)l2 ) return -1;
+       if       ((MirrTopoHash_t)(intptr_t)l1 > (MirrTopoHash_t)(intptr_t)l2 ) 
return  1;
+       else if  ((MirrTopoHash_t)(intptr_t)l1 < (MirrTopoHash_t)(intptr_t)l2 ) 
return -1;
        return 0;
 }
 
 static int MirrTopo_item_sort(const void *v1, const void *v2)
 {
-       if(                     ((MirrTopoPair *)v1)->hash > ((MirrTopoPair 
*)v2)->hash ) return  1;
-       else if(        ((MirrTopoPair *)v1)->hash < ((MirrTopoPair *)v2)->hash 
) return -1;
+       if      (((MirrTopoPair_t *)v1)->hash > ((MirrTopoPair_t *)v2)->hash ) 
return  1;
+       else if (((MirrTopoPair_t *)v1)->hash < ((MirrTopoPair_t *)v2)->hash ) 
return -1;
        return 0;
 }
 
-static long *mesh_topo_lookup = NULL;
+static intptr_t *mesh_topo_lookup = NULL;
 static int  mesh_topo_lookup_vert_tot = -1;
 static int  mesh_topo_lookup_edge_tot = -1;
-static int  mesh_topo_lookup_mode = -1;
+static int  mesh_topo_lookup_mode     = -1;
 
 /* mode is 's' start, or 'e' end, or 'u' use */
 /* if end, ob can be NULL */
-long mesh_mirrtopo_table(Object *ob, char mode)
+/* note, is supposed return -1 on error, which callers are currently checking 
for, but is not used so far */
+int mesh_mirrtopo_table(Object *ob, char mode)
 {
        if(mode=='u') {         /* use table */
                Mesh *me= ob->data;
@@ -906,9 +907,9 @@
                int totvert, totedge;
                int totUnique= -1, totUniqueOld= -1;
 
-               MIRRHASH_TYPE *MirrTopoHash = NULL;
-               MIRRHASH_TYPE *MirrTopoHash_Prev = NULL;
-               MirrTopoPair *MirrTopoPairs;
+               MirrTopoHash_t *MirrTopoHash = NULL;
+               MirrTopoHash_t *MirrTopoHash_Prev = NULL;
+               MirrTopoPair_t *MirrTopoPairs;
                mesh_topo_lookup_mode= ob->mode;
 
                /* reallocate if needed */
@@ -930,7 +931,7 @@
                        totvert = me->totvert;
                }
 
-               MirrTopoHash = MEM_callocN( totvert * sizeof(MIRRHASH_TYPE), 
"TopoMirr" );
+               MirrTopoHash = MEM_callocN( totvert * sizeof(MirrTopoHash_t), 
"TopoMirr" );
 
                /* Initialize the vert-edge-user counts used to detect unique 
topology */
                if(em) {
@@ -967,10 +968,10 @@
                                        MirrTopoHash[medge->v2] += 
MirrTopoHash_Prev[medge->v1];
                                }
                        }
-                       memcpy(MirrTopoHash_Prev, MirrTopoHash, 
sizeof(MIRRHASH_TYPE) * totvert);
+                       memcpy(MirrTopoHash_Prev, MirrTopoHash, 
sizeof(MirrTopoHash_t) * totvert);
 
                        /* sort so we can count unique values */
-                       qsort(MirrTopoHash_Prev, totvert, 
sizeof(MIRRHASH_TYPE), MirrTopo_long_sort);
+                       qsort(MirrTopoHash_Prev, totvert, 
sizeof(MirrTopoHash_t), MirrTopo_long_sort);
 
                        totUnique = 1; /* account for skiping the first value */
                        for(a=1; a<totvert; a++) {
@@ -987,7 +988,7 @@
                                totUniqueOld = totUnique;
                        }
                        /* Copy the hash calculated this iter, so we can use 
them next time */
-                       memcpy(MirrTopoHash_Prev, MirrTopoHash, 
sizeof(MIRRHASH_TYPE) * totvert);
+                       memcpy(MirrTopoHash_Prev, MirrTopoHash, 
sizeof(MirrTopoHash_t) * totvert);
                }
 
                /* restore eve->tmp.* */
@@ -1004,7 +1005,7 @@
                
                
                /* Hash/Index pairs are needed for sorting to find index pairs 
*/
-               MirrTopoPairs= MEM_callocN( sizeof(MirrTopoPair) * totvert, 
"MirrTopoPairs");
+               MirrTopoPairs= MEM_callocN( sizeof(MirrTopoPair_t) * totvert, 
"MirrTopoPairs");
 
                /* since we are looping through verts, initialize these values 
here too */
                mesh_topo_lookup = MEM_mallocN( totvert * sizeof(long), 
"mesh_topo_lookup" );
@@ -1022,7 +1023,7 @@
                        mesh_topo_lookup[a] = -1;
                }
 
-               qsort(MirrTopoPairs, totvert, sizeof(MirrTopoPair), 
MirrTopo_item_sort);
+               qsort(MirrTopoPairs, totvert, sizeof(MirrTopoPair_t), 
MirrTopo_item_sort);
 
                /* Since the loop starts at 2, we must define the last index 
where the hash's differ */
                last = ((totvert >= 2) && (MirrTopoPairs[0].hash == 
MirrTopoPairs[1].hash)) ? 0 : 1;
@@ -1034,8 +1035,8 @@
                        if ((a==totvert) || (MirrTopoPairs[a-1].hash != 
MirrTopoPairs[a].hash)) {
                                if (a-last==2) {
                                        if(em) {
-                                               
mesh_topo_lookup[MirrTopoPairs[a-1].vIndex] =   
(long)EM_get_vert_for_index(MirrTopoPairs[a-2].vIndex);
-                                               
mesh_topo_lookup[MirrTopoPairs[a-2].vIndex] =   
(long)EM_get_vert_for_index(MirrTopoPairs[a-1].vIndex);
+                                               
mesh_topo_lookup[MirrTopoPairs[a-1].vIndex] =   
(intptr_t)EM_get_vert_for_index(MirrTopoPairs[a-2].vIndex);
+                                               
mesh_topo_lookup[MirrTopoPairs[a-2].vIndex] =   
(intptr_t)EM_get_vert_for_index(MirrTopoPairs[a-1].vIndex);
                                        } else {
                                                
mesh_topo_lookup[MirrTopoPairs[a-1].vIndex] =   MirrTopoPairs[a-2].vIndex;
                                                
mesh_topo_lookup[MirrTopoPairs[a-2].vIndex] =   MirrTopoPairs[a-1].vIndex;
@@ -1123,7 +1124,7 @@
 
 static EditVert *editmesh_get_x_mirror_vert_topo(Object *ob, struct EditMesh 
*em, EditVert *eve, int index)
 {
-       long poinval;
+       intptr_t poinval;
        if (mesh_mirrtopo_table(ob, 'u')==-1)
                return NULL;
 

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to