code cleanup - give edge split more helpful var names and replace edgetag macros...
authorCampbell Barton <ideasman42@gmail.com>
Tue, 6 Mar 2012 17:23:26 +0000 (17:23 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 6 Mar 2012 17:23:26 +0000 (17:23 +0000)
source/blender/bmesh/intern/bmesh_core.c
source/blender/bmesh/intern/bmesh_walkers_impl.c
source/blender/bmesh/operators/bmo_bevel.c
source/blender/bmesh/operators/bmo_create.c
source/blender/bmesh/operators/bmo_edgesplit.c
source/blender/editors/mesh/bmesh_select.c
source/blender/editors/mesh/bmesh_tools.c
source/blender/editors/mesh/bmesh_utils.c

index a21834b..d721364 100644 (file)
@@ -144,10 +144,12 @@ static BMLoop *bm_loop_create(BMesh *bm, BMVert *v, BMEdge *e, BMFace *f, const
 
        bm->totloop++;
 
-       if (example)
+       if (example) {
                CustomData_bmesh_copy_data(&bm->ldata, &bm->ldata, example->head.data, &l->head.data);
-       else
+       }
+       else {
                CustomData_bmesh_set_default(&bm->ldata, &l->head.data);
+       }
 
        return l;
 }
index 5c9a6c0..c08a544 100644 (file)
@@ -697,10 +697,12 @@ static void *bmw_EdgeringWalker_yield(BMWalker *walker)
                return NULL;
        }
 
-       if (lwalk->l)
+       if (lwalk->l) {
                return lwalk->l->e;
-       else
+       }
+       else {
                return lwalk->wireedge;
+       }
 }
 
 static void *bmw_EdgeringWalker_step(BMWalker *walker)
index e6262f5..879e5e1 100644 (file)
@@ -522,10 +522,12 @@ void bmo_bevel_exec(BMesh *bm, BMOperator *op)
                                                        if (!vv || BMO_elem_flag_test(bm, vv, BEVEL_FLAG))
                                                                continue;
                                                        
-                                                       if (j)
+                                                       if (j) {
                                                                v1 = vv;
-                                                       else
+                                                       }
+                                                       else {
                                                                v2 = vv;
+                                                       }
                                                        break;
                                                }
                                        }
index 67e4f09..6071562 100644 (file)
@@ -228,11 +228,13 @@ static int UNUSED_FUNCTION(rotsys_fill_faces)(BMesh *bm, EdgeData *edata, VertDa
                
                rad = count_edge_faces(bm, e);
                
-               if (rad < 2)
+               if (rad < 2) {
                        starte = e;
-               else
+               }
+               else {
                        continue;
-               
+               }
+
                /* do two passes, going forward then backwar */
                for (i = 0; i < 2; i++) {
                        BLI_smallhash_init(hash);
index e00f8cf..85615cf 100644 (file)
@@ -46,7 +46,7 @@ typedef struct EdgeTag {
 #define FACE_DEL       1
 #define FACE_NEW       2
 
-static BMFace *remake_face(BMesh *bm, EdgeTag *etags, BMFace *f, BMVert **verts, BMEdge **edges_tmp)
+static BMFace *remake_face(BMesh *bm, EdgeTag *etags, BMFace *f, BMVert **f_verts, BMEdge **edges_tmp)
 {
        BMIter liter1, liter2;
        EdgeTag *et;
@@ -57,12 +57,12 @@ static BMFace *remake_face(BMesh *bm, EdgeTag *etags, BMFace *f, BMVert **verts,
        int i;
 
        /* we do final edge last */
-       lastv1 = verts[f->len - 1];
-       lastv2 = verts[0];
-       /* v1 = verts[0]; */ /* UNUSED */
-       /* v2 = verts[1]; */ /* UNUSED */
+       lastv1 = f_verts[f->len - 1];
+       lastv2 = f_verts[0];
+       /* v1 = f_verts[0]; */ /* UNUSED */
+       /* v2 = f_verts[1]; */ /* UNUSED */
        for (i = 0; i < f->len - 1; i++) {
-               e = BM_edge_create(bm, verts[i], verts[i + 1], NULL, TRUE);
+               e = BM_edge_create(bm, f_verts[i], f_verts[i + 1], NULL, TRUE);
                if (!e) {
                        return NULL;
                }
@@ -71,7 +71,7 @@ static BMFace *remake_face(BMesh *bm, EdgeTag *etags, BMFace *f, BMVert **verts,
 
        edges_tmp[i] = BM_edge_create(bm, lastv1, lastv2, NULL, TRUE);
 
-       f2 = BM_face_create(bm, verts, edges_tmp, f->len, FALSE);
+       f2 = BM_face_create(bm, f_verts, edges_tmp, f->len, FALSE);
        if (!f2) {
                return NULL;
        }
@@ -199,16 +199,37 @@ static void tag_out_edges(BMesh *bm, EdgeTag *etags, BMOperator *UNUSED(op))
        }
 }
 
+/* helper functions for edge tag's */
+BM_INLINE BMVert *bm_edge_tag_vert_get(EdgeTag *et, BMVert *v, BMLoop *l)
+{
+       return (l->e->v1 == v) ? et->newv1 : et->newv2;
+}
+
+BM_INLINE void bm_edge_tag_vert_set(EdgeTag *et, BMVert *v, BMLoop *l, BMVert *vset)
+{
+       if (l->e->v1 == v) {
+               et->newv1 = vset;
+       }
+       else {
+               et->newv2 = vset;
+       }
+}
+
 void bmo_edgesplit_exec(BMesh *bm, BMOperator *op)
 {
-       EdgeTag *etags, *et;
+       EdgeTag *etags, *et; /* edge aligned array of tags */
        BMIter iter, liter;
        BMOIter siter;
        BMFace *f, *f2;
-       BMLoop *l, *nextl, *prevl, *l2, *l3;
+       BMLoop *l, *l2, *l3;
+       BMLoop *l_next, *l_prev;
        BMEdge *e, *e2;
-       BMVert *v, *v2, **verts = NULL;
-       BLI_array_declare(verts);
+       BMVert *v, *v2;
+
+       /* face/vert aligned vert array */
+       BMVert **f_verts = NULL;
+       BLI_array_declare(f_verts);
+
        BMEdge **edges_tmp = NULL;
        BLI_array_declare(edges_tmp);
        int i, j;
@@ -238,25 +259,15 @@ void bmo_edgesplit_exec(BMesh *bm, BMOperator *op)
 
        BM_mesh_elem_index_ensure(bm, BM_EDGE);
 
-#ifdef ETV
-#  undef ETV
-#endif
-#ifdef SETETV
-#  undef SETETV
-#endif
-
-#define ETV(et, v, l) (l->e->v1 == v ? et->newv1 : et->newv2)
-#define SETETV(et, v, l, vs) l->e->v1 == v ? (et->newv1 = vs) : (et->newv2 = vs)
-
        BM_ITER(f, &iter, bm, BM_FACES_OF_MESH, NULL) {
 
                if (BMO_elem_flag_test(bm, f, FACE_NEW)) {
                        continue;
                }
 
-               BLI_array_empty(verts);
-               BLI_array_growitems(verts, f->len);
-               memset(verts, 0, sizeof(BMVert *) * f->len);
+               BLI_array_empty(f_verts);
+               BLI_array_growitems(f_verts, f->len);
+               memset(f_verts, 0, sizeof(BMVert *) * f->len);
 
                /* this is passed onto remake_face() so it doesnt need to allocate
                 * a new array on each call. */
@@ -266,38 +277,37 @@ void bmo_edgesplit_exec(BMesh *bm, BMOperator *op)
                i = 0;
                BM_ITER(l, &liter, bm, BM_LOOPS_OF_FACE, f) {
                        if (!BMO_elem_flag_test(bm, l->e, EDGE_SEAM)) {
-                               if (!verts[i]) {
+                               if (!f_verts[i]) {
 
                                        et = &etags[BM_elem_index_get(l->e)];
-                                       if (ETV(et, l->v, l)) {
-                                               verts[i] = ETV(et, l->v, l);
+                                       if (bm_edge_tag_vert_get(et, l->v, l)) {
+                                               f_verts[i] = bm_edge_tag_vert_get(et, l->v, l);
                                        }
-                                       else
-                                       {
-                                               verts[i] = l->v;
+                                       else {
+                                               f_verts[i] = l->v;
                                        }
                                }
                                i++;
                                continue;
                        }
 
-                       nextl = l->next;
-                       prevl = l->prev;
+                       l_next = l->next;
+                       l_prev = l->prev;
                        
                        for (j = 0; j < 2; j++) {
                                /* correct as long as i & j dont change during the loop */
                                const int fv_index = j ? (i + 1) % f->len : i; /* face vert index */
-                               l2 = j ? nextl : prevl;
+                               l2 = j ? l_next : l_prev;
                                v = j ? l2->v : l->v;
 
                                if (BMO_elem_flag_test(bm, l2->e, EDGE_SEAM)) {
-                                       if (verts[fv_index] == NULL) {
+                                       if (f_verts[fv_index] == NULL) {
                                                /* make unique vert here for this face only */
                                                v2 = BM_vert_create(bm, v->co, v);
-                                               verts[fv_index] = v2;
+                                               f_verts[fv_index] = v2;
                                        }
                                        else {
-                                               v2 = verts[fv_index];
+                                               v2 = f_verts[fv_index];
                                        }
                                }
                                else {
@@ -324,12 +334,12 @@ void bmo_edgesplit_exec(BMesh *bm, BMOperator *op)
 
                                        if (l3 == NULL || (BMO_elem_flag_test(bm, l3->e, EDGE_SEAM) && l3->e != l->e)) {
                                                et = &etags[BM_elem_index_get(l2->e)];
-                                               if (ETV(et, v, l2) == NULL) {
+                                               if (bm_edge_tag_vert_get(et, v, l2) == NULL) {
                                                        v2 = BM_vert_create(bm, v->co, v);
                                                        
                                                        l3 = l2;
                                                        do {
-                                                               SETETV(et, v, l3, v2);
+                                                               bm_edge_tag_vert_set(et, v, l3, v2);
                                                                if (BM_edge_face_count(l3->e) != 2) {
                                                                        break;
                                                                }
@@ -341,13 +351,13 @@ void bmo_edgesplit_exec(BMesh *bm, BMOperator *op)
                                                        } while (l3 != l2 && !BMO_elem_flag_test(bm, l3->e, EDGE_SEAM));
                                                }
                                                else {
-                                                       v2 = ETV(et, v, l2);
+                                                       v2 = bm_edge_tag_vert_get(et, v, l2);
                                                }
 
-                                               verts[fv_index] = v2;
+                                               f_verts[fv_index] = v2;
                                        }
                                        else {
-                                               verts[fv_index] = v;
+                                               f_verts[fv_index] = v;
                                        }
                                }
                        }
@@ -363,14 +373,14 @@ void bmo_edgesplit_exec(BMesh *bm, BMOperator *op)
                        float no2[3];
                        float angle_error;
                        printf(" ** found QUAD\n");
-                       normal_tri_v3(no1, verts[0]->co, verts[1]->co, verts[2]->co);
-                       normal_tri_v3(no2, verts[0]->co, verts[2]->co, verts[3]->co);
+                       normal_tri_v3(no1, f_verts[0]->co, f_verts[1]->co, f_verts[2]->co);
+                       normal_tri_v3(no2, f_verts[0]->co, f_verts[2]->co, f_verts[3]->co);
                        if ((angle_error = angle_v3v3(no1, no2)) > 0.05) {
                                printf("     ERROR %.4f\n", angle_error);
-                               print_v3("0", verts[0]->co);
-                               print_v3("1", verts[1]->co);
-                               print_v3("2", verts[2]->co);
-                               print_v3("3", verts[3]->co);
+                               print_v3("0", f_verts[0]->co);
+                               print_v3("1", f_verts[1]->co);
+                               print_v3("2", f_verts[2]->co);
+                               print_v3("3", f_verts[3]->co);
 
                        }
                }
@@ -379,13 +389,12 @@ void bmo_edgesplit_exec(BMesh *bm, BMOperator *op)
                }
 #endif
 
-               f2 = remake_face(bm, etags, f, verts, edges_tmp);
-               if (!f2) {
-                       continue;
+               f2 = remake_face(bm, etags, f, f_verts, edges_tmp);
+               if (f2) {
+                       BMO_elem_flag_enable(bm, f, FACE_DEL);
+                       BMO_elem_flag_enable(bm, f2, FACE_NEW);
                }
-
-               BMO_elem_flag_enable(bm, f, FACE_DEL);
-               BMO_elem_flag_enable(bm, f2, FACE_NEW);
+               /* else { ... should we raise an error here, or an assert? - campbell */
        }
        
        /* remake_face() sets invalid indices,
@@ -421,10 +430,7 @@ void bmo_edgesplit_exec(BMesh *bm, BMOperator *op)
        BMO_slot_buffer_from_flag(bm, op, "edgeout1", EDGE_RET1, BM_EDGE);
        BMO_slot_buffer_from_flag(bm, op, "edgeout2", EDGE_RET2, BM_EDGE);
 
-       BLI_array_free(verts);
+       BLI_array_free(f_verts);
        BLI_array_free(edges_tmp);
        if (etags) MEM_freeN(etags);
 }
-
-#undef ETV
-#undef SETETV
index 3ee365d..3085a29 100644 (file)
@@ -335,10 +335,12 @@ static void findnearestvert__doClosest(void *userData, BMVert *eve, int x, int y
        if (data->dist > 3) {
                int temp = abs(data->mval[0] - x) + abs(data->mval[1]- y);
                if (BM_elem_flag_test(eve, BM_ELEM_SELECT) == data->select) {
-                       if (data->strict == 1)
+                       if (data->strict == 1) {
                                return;
-                       else
+                       }
+                       else {
                                temp += 5;
+                       }
                }
 
                if (temp < data->dist) {
index b1833bc..559ad4d 100644 (file)
 
 static void add_normal_aligned(float nor[3], const float add[3])
 {
-       if (dot_v3v3(nor, add) < -0.9999f)
+       if (dot_v3v3(nor, add) < -0.9999f) {
                sub_v3_v3(nor, add);
-       else
+       }
+       else {
                sub_v3_v3(nor, add);
+       }
 }
 
 
@@ -2646,8 +2648,9 @@ static int blend_from_shape_exec(bContext *C, wmOperator *op)
                        mul_v3_fl(co, blend);
                        add_v3_v3v3(eve->co, eve->co, co);
                }
-               else
+               else {
                        interp_v3_v3v3(eve->co, eve->co, co, blend);
+               }
                
                copy_v3_v3(sco, co);
        }
index 758f301..bee4d42 100644 (file)
@@ -686,8 +686,9 @@ UvVertMap *EDBM_make_uv_vert_map(BMEditMesh *em, int selected, int do_face_idx_a
                                        iterv->next = newvlist;
                                        newvlist = iterv;
                                }
-                               else
+                               else {
                                        lastv = iterv;
+                               }
 
                                iterv = next;
                        }