Code Cleanup
authorCampbell Barton <ideasman42@gmail.com>
Tue, 28 Feb 2012 08:17:53 +0000 (08:17 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 28 Feb 2012 08:17:53 +0000 (08:17 +0000)
* remove one the changes to fix #30374, instead just check if the face exists.
* remove some unneeded edge checks in BM_face_create_quad_tri_v().

source/blender/bmesh/bmesh_queries.h
source/blender/bmesh/intern/bmesh_construct.c
source/blender/bmesh/intern/bmesh_mods.c
source/blender/bmesh/intern/bmesh_polygon.c
source/blender/bmesh/intern/bmesh_queries.c

index b4b48bb581e46657af42c6302b1c02f20c76a1d2..4285031c3b5b090b10019d35c3b878146b9212de 100644 (file)
@@ -95,16 +95,14 @@ float BM_edge_face_angle(BMesh *bm, BMEdge *e);
 float BM_vert_edge_angle(BMesh *bm, BMVert *v);
 
 /* checks overlapping of existing faces with the verts in varr. */
-int BM_face_exists_overlap(BMesh *bm, BMVert **varr, int len, BMFace **r_existface,
-                           const short do_partial);
-
-/* checks if many existing faces overlap the faces defined by varr */
-int BM_face_exists_multi(BMesh *bm, BMVert **varr, BMEdge **earr, int len);
-int BM_face_exists_multi_edge(BMesh *bm, BMEdge **earr, int len);
+int BM_face_exists_overlap(BMesh *bm, BMVert **varr, int len, BMFace **r_existface);
 
 /* checks if a face defined by varr already exists. */
 int BM_face_exists(BMesh *bm, BMVert **varr, int len, BMFace **r_existface);
 
+/* checks if many existing faces overlap the faces defined by varr */
+int BM_face_exists_multi(BMesh *bm, BMVert **varr, BMEdge **earr, int len);
+int BM_face_exists_multi_edge(BMesh *bm, BMEdge **earr, int len);
 
 /* returns number of edges f1 and f2 share. */
 int BM_face_share_edge_count(BMFace *f1, BMFace *f2);
index f42b9a7a280ec6f93a39adec4cc4088c63688991..9056f59835c5dcda339c6e07b78bc2499298b7db 100644 (file)
@@ -76,40 +76,25 @@ BMFace *BM_face_create_quad_tri(BMesh *bm,
 /* remove the edge array bits from this. Its not really needed? */
 BMFace *BM_face_create_quad_tri_v(BMesh *bm, BMVert **verts, int len, const BMFace *example, const int nodouble)
 {
-       BMEdge *edar[4] = {NULL};
        BMFace *f = NULL;
-       int overlap = 0;
-
-       edar[0] = BM_edge_exists(verts[0], verts[1]);
-       edar[1] = BM_edge_exists(verts[1], verts[2]);
-       if (len == 4) {
-               edar[2] = BM_edge_exists(verts[2], verts[3]);
-               edar[3] = BM_edge_exists(verts[3], verts[0]);
-       }
-       else {
-               edar[2] = BM_edge_exists(verts[2], verts[0]);
-       }
+       int is_overlap = FALSE;
 
        if (nodouble) {
                /* check if face exists or overlaps */
-               if (len == 4) {
-                       overlap = BM_face_exists_overlap(bm, verts, len, &f, FALSE);
-               }
-               else {
-                       overlap = BM_face_exists_overlap(bm, verts, len, &f, FALSE);
-               }
+               is_overlap = BM_face_exists(bm, verts, len, &f);
        }
 
        /* make new face */
-       if ((!f) && (!overlap)) {
-               if (!edar[0]) edar[0] = BM_edge_create(bm, verts[0], verts[1], NULL, FALSE);
-               if (!edar[1]) edar[1] = BM_edge_create(bm, verts[1], verts[2], NULL, FALSE);
+       if ((f == NULL) && (!is_overlap)) {
+               BMEdge *edar[4] = {NULL};
+               edar[0] = BM_edge_create(bm, verts[0], verts[1], NULL, TRUE);
+               edar[1] = BM_edge_create(bm, verts[1], verts[2], NULL, TRUE);
                if (len == 4) {
-                       if (!edar[2]) edar[2] = BM_edge_create(bm, verts[2], verts[3], NULL, FALSE);
-                       if (!edar[3]) edar[3] = BM_edge_create(bm, verts[3], verts[0], NULL, FALSE);
+                       edar[2] = BM_edge_create(bm, verts[2], verts[3], NULL, TRUE);
+                       edar[3] = BM_edge_create(bm, verts[3], verts[0], NULL, TRUE);
                }
                else {
-                       if (!edar[2]) edar[2] = BM_edge_create(bm, verts[2], verts[0], NULL, FALSE);
+                       edar[2] = BM_edge_create(bm, verts[2], verts[0], NULL, TRUE);
                }
 
                f = BM_face_create(bm, verts, edar, len, FALSE);
@@ -127,21 +112,18 @@ BMFace *BM_face_create_quad_tri_v(BMesh *bm, BMVert **verts, int len, const BMFa
 void BM_face_copy_shared(BMesh *bm, BMFace *f)
 {
        BMIter iter;
-       BMLoop *l, *l2;
-
-       if (!f) return;
+       BMLoop *l, *l_other;
 
-       l = BM_iter_new(&iter, bm, BM_LOOPS_OF_FACE, f);
-       for ( ; l; l = BM_iter_step(&iter)) {
-               l2 = l->radial_next;
+       BM_ITER(l, &iter, bm, BM_LOOPS_OF_FACE, f) {
+               l_other = l->radial_next;
                
-               if (l2 && l2 != l) {
-                       if (l2->v == l->v) {
-                               bm_loop_attrs_copy(bm, bm, l2, l);
+               if (l_other && l_other != l) {
+                       if (l_other->v == l->v) {
+                               bm_loop_attrs_copy(bm, bm, l_other, l);
                        }
                        else {
-                               l2 = l2->next;
-                               bm_loop_attrs_copy(bm, bm, l2, l);
+                               l_other = l_other->next;
+                               bm_loop_attrs_copy(bm, bm, l_other, l);
                        }
                }
        }
index 47ae1c6132179814140fe169ecd6647af7a8da7d..964565fe5c8ebf71e0c14d66ab2cd3b751361f7e 100644 (file)
@@ -269,18 +269,22 @@ BMFace *BM_faces_join_pair(BMesh *bm, BMFace *f1, BMFace *f2, BMEdge *e)
 
 BMEdge *BM_verts_connect(BMesh *bm, BMVert *v1, BMVert *v2, BMFace **r_f)
 {
-       BMIter iter, iter2;
-       BMVert *v;
-       BMLoop *nl;
-       BMFace *f;
+       BMIter fiter;
+       BMIter viter;
+       BMVert *v_iter;
+       BMFace *f_iter;
 
        /* be warned: this can do weird things in some ngon situation, see BM_face_legal_splits */
-       for (f = BM_iter_new(&iter, bm, BM_FACES_OF_VERT, v1); f; f = BM_iter_step(&iter)) {
-               for (v = BM_iter_new(&iter2, bm, BM_VERTS_OF_FACE, f); v; v = BM_iter_step(&iter2)) {
-                       if (v == v2) {
-                               f = BM_face_split(bm, f, v1, v2, &nl, NULL);
+       BM_ITER(f_iter, &fiter, bm, BM_FACES_OF_VERT, v1) {
+               BM_ITER(v_iter, &viter, bm, BM_FACES_OF_VERT, f_iter) {
+                       if (v_iter == v2) {
+                               BMLoop *nl;
+
+                               f_iter = BM_face_split(bm, f_iter, v1, v2, &nl, NULL);
 
-                               if (r_f) *r_f = f;
+                               if (r_f) {
+                                       *r_f = f_iter;
+                               }
                                return nl->e;
                        }
                }
index dc8140d678cf4f07d4cd86e1d68d8c2c48a52d8e..c7fa91e8f135f717ec9b7885fff63ace7a272842 100644 (file)
@@ -489,10 +489,8 @@ void BM_vert_normal_update_all(BMesh *bm, BMVert *v)
 {
        BMIter iter;
        BMFace *f;
-       int len = 0;
 
-       f = BM_iter_new(&iter, bm, BM_FACES_OF_VERT, v);
-       for ( ; f; f = BM_iter_step(&iter), len++) {
+       BM_ITER(f, &iter, bm, BM_FACES_OF_VERT, v) {
                BM_face_normal_update(bm, f);
        }
 
index ecb9c47c99753a3d53bd82f766a7f5ecd2aa7c63..2ea37a5c01b38cb6e1bf243b0d4637290b92865e 100644 (file)
@@ -635,27 +635,27 @@ float BM_vert_edge_angle(BMesh *UNUSED(bm), BMVert *v)
  * Given a set of vertices (varr), find out if
  * all those vertices overlap an existing face.
  *
- * \param do_partial When TRUE the overlapping face
- * can be a different length to the one given
+ * \note Making a face here is valid but in some cases you wont want to
+ * make a face thats part of another.
+ *
  * \returns TRUE for overlap
  *
  */
-int BM_face_exists_overlap(BMesh *bm, BMVert **varr, int len, BMFace **r_overlapface,
-                           const short do_partial)
+int BM_face_exists_overlap(BMesh *bm, BMVert **varr, int len, BMFace **r_overlapface)
 {
-       BMIter vertfaces;
+       BMIter viter;
        BMFace *f;
        int i, amount;
 
        for (i = 0; i < len; i++) {
-               f = BM_iter_new(&vertfaces, bm, BM_FACES_OF_VERT, varr[i]);
-               while (f) {
+               BM_ITER(f, &viter, bm, BM_FACES_OF_VERT, varr[i]) {
                        amount = BM_verts_in_face(bm, f, varr, len);
-                       if ((amount >= len) && (do_partial == TRUE || len == f->len)) {
-                               if (r_overlapface) *r_overlapface = f;
+                       if (amount >= len) {
+                               if (r_overlapface) {
+                                       *r_overlapface = f;
+                               }
                                return TRUE;
                        }
-                       f = BM_iter_step(&vertfaces);
                }
        }
 
@@ -666,6 +666,43 @@ int BM_face_exists_overlap(BMesh *bm, BMVert **varr, int len, BMFace **r_overlap
        return FALSE;
 }
 
+/*
+ * BMESH FACE EXISTS
+ *
+ * Given a set of vertices (varr), find out if
+ * there is a face with exactly those vertices
+ * (and only those vertices).
+ *
+ * Returns:
+ * 0 for no face found
+ * 1 for face found
+ */
+
+int BM_face_exists(BMesh *bm, BMVert **varr, int len, BMFace **r_existface)
+{
+       BMIter viter;
+       BMFace *f;
+       int i, amount;
+
+       for (i = 0; i < len; i++) {
+               BM_ITER(f, &viter, bm, BM_FACES_OF_VERT, varr[i]) {
+                       amount = BM_verts_in_face(bm, f, varr, len);
+                       if (amount == len && amount == f->len) {
+                               if (r_existface) {
+                                       *r_existface = f;
+                               }
+                               return TRUE;
+                       }
+               }
+       }
+
+       if (r_existface) {
+               *r_existface = NULL;
+       }
+       return FALSE;
+}
+
+
 /*
  * BMESH EXIST FACE MULTI
  *
@@ -821,42 +858,3 @@ int BM_face_exists_multi_edge(BMesh *bm, BMEdge **earr, int len)
 
        return ok;
 }
-
-
-/*
- * BMESH FACE EXISTS
- *
- * Given a set of vertices (varr), find out if
- * there is a face with exactly those vertices
- * (and only those vertices).
- *
- * Returns:
- * 0 for no face found
- * 1 for face found
- */
-
-int BM_face_exists(BMesh *bm, BMVert **varr, int len, BMFace **r_existface)
-{
-       BMIter vertfaces;
-       BMFace *f;
-       int i, amount;
-
-       for (i = 0; i < len; i++) {
-               f = BM_iter_new(&vertfaces, bm, BM_FACES_OF_VERT, varr[i]);
-               while (f) {
-                       amount = BM_verts_in_face(bm, f, varr, len);
-                       if (amount == len && amount == f->len) {
-                               if (r_existface) {
-                                       *r_existface = f;
-                               }
-                               return TRUE;
-                       }
-                       f = BM_iter_step(&vertfaces);
-               }
-       }
-
-       if (r_existface) {
-               *r_existface = NULL;
-       }
-       return FALSE;
-}