BMesh: BM_face_exists no longer uses return arg
authorCampbell Barton <ideasman42@gmail.com>
Sun, 13 Nov 2016 17:10:47 +0000 (04:10 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 13 Nov 2016 17:33:35 +0000 (04:33 +1100)
Just return the face or NULL, like BM_edge_exists(),
Also for BM_face_exists_overlap & bm_face_exists_tri_from_loop_vert.
No functional changes.

Old code did some partial overlap checks where this made some sense,
but it's since been removed.

12 files changed:
source/blender/blenkernel/intern/pbvh_bmesh.c
source/blender/bmesh/intern/bmesh_core.c
source/blender/bmesh/intern/bmesh_queries.c
source/blender/bmesh/intern/bmesh_queries.h
source/blender/bmesh/operators/bmo_bridge.c
source/blender/bmesh/operators/bmo_fill_edgeloop.c
source/blender/bmesh/operators/bmo_hull.c
source/blender/bmesh/operators/bmo_removedoubles.c
source/blender/bmesh/tools/bmesh_decimate_unsubdivide.c
source/blender/editors/mesh/editmesh_rip.c
source/blender/editors/mesh/editmesh_utils.c
source/blender/python/bmesh/bmesh_py_types.c

index 55f9f384081ed12040ab246e08378dabd08f31a4..a821578db1a8c6b624602e06e395a3d3b9d881cf 100644 (file)
@@ -148,8 +148,7 @@ BLI_INLINE void bm_face_as_array_index_tri(BMFace *f, int r_index[3])
  *
  * Its assumed that \a l_radial_first is never forming the target face.
  */
-static bool bm_face_exists_tri_from_loop_vert(
-        BMLoop *l_radial_first, BMVert *v_opposite, BMFace **r_face_existing)
+static BMFace *bm_face_exists_tri_from_loop_vert(BMLoop *l_radial_first, BMVert *v_opposite)
 {
        BLI_assert(!ELEM(v_opposite, l_radial_first->v, l_radial_first->next->v, l_radial_first->prev->v));
        if (l_radial_first->radial_next != l_radial_first) {
@@ -157,12 +156,11 @@ static bool bm_face_exists_tri_from_loop_vert(
                do {
                        BLI_assert(l_radial_iter->f->len == 3);
                        if (l_radial_iter->prev->v == v_opposite) {
-                               *r_face_existing = l_radial_iter->f;
-                               return true;
+                               return l_radial_iter->f;
                        }
                } while ((l_radial_iter = l_radial_iter->radial_next) != l_radial_first);
        }
-       return false;
+       return NULL;
 }
 
 /**
@@ -519,7 +517,7 @@ static BMFace *pbvh_bmesh_face_create(
        PBVHNode *node = &bvh->nodes[node_index];
 
        /* ensure we never add existing face */
-       BLI_assert(BM_face_exists(v_tri, 3, NULL) == false);
+       BLI_assert(!BM_face_exists(v_tri, 3));
 
        BMFace *f = BM_face_create(bvh->bm, v_tri, e_tri, 3, f_example, BM_CREATE_NOP);
        f->head.hflag = f_example->head.hflag;
@@ -1313,18 +1311,17 @@ static void pbvh_bmesh_collapse_edge(
                 * deletion as well. Prevents extraneous "flaps" from being
                 * created. */
 #if 0
-               if (UNLIKELY(BM_face_exists(v_tri, 3, &existing_face)))
+               if (UNLIKELY(existing_face = BM_face_exists(v_tri, 3)))
 #else
-               if (UNLIKELY(bm_face_exists_tri_from_loop_vert(l->next, v_conn, &existing_face)))
+               if (UNLIKELY(existing_face = bm_face_exists_tri_from_loop_vert(l->next, v_conn)))
 #endif
                {
-                       BLI_assert(existing_face);
                        BLI_buffer_append(deleted_faces, BMFace *, existing_face);
                }
                else {
                        BMVert *v_tri[3] = {v_conn, l->next->v, l->prev->v};
 
-                       BLI_assert(BM_face_exists(v_tri, 3, NULL) == false);
+                       BLI_assert(!BM_face_exists(v_tri, 3));
                        BMEdge *e_tri[3];
                        PBVHNode *n = pbvh_bmesh_node_from_face(bvh, f);
                        int ni = n - bvh->nodes;
index a7e1aa7fb07f44f131f219a0ef068ba98b0a07a7..0460a33494c7894eac56323fb9d49807bb701514 100644 (file)
@@ -444,13 +444,10 @@ BMFace *BM_face_create(
 
        if (create_flag & BM_CREATE_NO_DOUBLE) {
                /* Check if face already exists */
-               const bool is_overlap = BM_face_exists(verts, len, &f);
-               if (is_overlap) {
+               f = BM_face_exists(verts, len);
+               if (f != NULL) {
                        return f;
                }
-               else {
-                       BLI_assert(f == NULL);
-               }
        }
 
        f = bm_face_create__internal(bm);
index 0287498482a3ef6b4ef1351fda6ae43bd06a5fdd..87671805ef286ffa0904e379ce3c66499e5d2b65 100644 (file)
@@ -1925,7 +1925,7 @@ BMEdge *BM_edge_find_double(BMEdge *e)
  *
  * \note there used to be a BM_face_exists_overlap function that checks for partial overlap.
  */
-bool BM_face_exists(BMVert **varr, int len, BMFace **r_existface)
+BMFace *BM_face_exists(BMVert **varr, int len)
 {
        if (varr[0]->e) {
                BMEdge *e_iter, *e_first;
@@ -1964,10 +1964,7 @@ bool BM_face_exists(BMVert **varr, int len, BMFace **r_existface)
                                                }
 
                                                if (i_walk == len) {
-                                                       if (r_existface) {
-                                                               *r_existface = l_iter_radial->f;
-                                                       }
-                                                       return true;
+                                                       return l_iter_radial->f;
                                                }
                                        }
                                } while ((l_iter_radial = l_iter_radial->radial_next) != l_first_radial);
@@ -1976,10 +1973,7 @@ bool BM_face_exists(BMVert **varr, int len, BMFace **r_existface)
                } while ((e_iter = BM_DISK_EDGE_NEXT(e_iter, varr[0])) != e_first);
        }
 
-       if (r_existface) {
-               *r_existface = NULL;
-       }
-       return false;
+       return NULL;
 }
 
 
@@ -2122,26 +2116,21 @@ bool BM_face_exists_multi_edge(BMEdge **earr, int len)
  * \note The face may contain other verts \b not in \a varr.
  *
  * \note Its possible there are more than one overlapping faces,
- * in this case the first one found will be assigned to \a r_f_overlap.
+ * in this case the first one found will be returned.
  *
  * \param varr  Array of unordered verts.
  * \param len  \a varr array length.
- * \param r_f_overlap  The overlapping face to return.
- * \return Success
+ * \return The face or NULL.
  */
 
-bool BM_face_exists_overlap(BMVert **varr, const int len, BMFace **r_f_overlap)
+BMFace *BM_face_exists_overlap(BMVert **varr, const int len)
 {
        BMIter viter;
        BMFace *f;
        int i;
-       bool is_overlap = false;
+       BMFace *f_overlap = NULL;
        LinkNode *f_lnk = NULL;
 
-       if (r_f_overlap) {
-               *r_f_overlap = NULL;
-       }
-
 #ifdef DEBUG
        /* check flag isn't already set */
        for (i = 0; i < len; i++) {
@@ -2155,10 +2144,7 @@ bool BM_face_exists_overlap(BMVert **varr, const int len, BMFace **r_f_overlap)
                BM_ITER_ELEM (f, &viter, varr[i], BM_FACES_OF_VERT) {
                        if (BM_ELEM_API_FLAG_TEST(f, _FLAG_OVERLAP) == 0) {
                                if (len <= BM_verts_in_face_count(varr, len, f)) {
-                                       if (r_f_overlap)
-                                               *r_f_overlap = f;
-
-                                       is_overlap = true;
+                                       f_overlap = f;
                                        break;
                                }
 
@@ -2172,7 +2158,7 @@ bool BM_face_exists_overlap(BMVert **varr, const int len, BMFace **r_f_overlap)
                BM_ELEM_API_FLAG_DISABLE((BMFace *)f_lnk->link, _FLAG_OVERLAP);
        }
 
-       return is_overlap;
+       return f_overlap;
 }
 
 /**
index 10e4b9a15aab9040b97a6e99f42d75b8371f6ec9..282050bf8a0db3055cff25fdff1c76b26810bcb5 100644 (file)
@@ -135,12 +135,12 @@ BMLoop *BM_face_find_longest_loop(BMFace *f) ATTR_WARN_UNUSED_RESULT ATTR_NONNUL
 BMEdge *BM_edge_exists(BMVert *v1, BMVert *v2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
 BMEdge *BM_edge_find_double(BMEdge *e) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
 
-bool    BM_face_exists(BMVert **varr, int len, BMFace **r_existface) ATTR_NONNULL(1);
+BMFace* BM_face_exists(BMVert **varr, int len) ATTR_NONNULL(1);
 
 bool    BM_face_exists_multi(BMVert **varr, BMEdge **earr, int len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
 bool    BM_face_exists_multi_edge(BMEdge **earr, int len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
 
-bool    BM_face_exists_overlap(BMVert **varr, const int len, BMFace **r_f_overlap) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
+BMFace *BM_face_exists_overlap(BMVert **varr, const int len) ATTR_WARN_UNUSED_RESULT;
 bool    BM_face_exists_overlap_subset(BMVert **varr, const int len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
 
 int     BM_face_share_face_count(BMFace *f_a, BMFace *f_b) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
index 6ef0fd6b0846118ecc1c6c30f4efb4250cbe6716..61179d7be7035f3af9d4f48cb8e62ed5d07de4eb 100644 (file)
@@ -398,7 +398,8 @@ static void bridge_loop_pair(
 
                        if (v_b != v_b_next) {
                                BMVert *v_arr[4] = {v_a, v_b, v_b_next, v_a_next};
-                               if (BM_face_exists(v_arr, 4, &f) == false) {
+                               f = BM_face_exists(v_arr, 4);
+                               if (f == NULL) {
                                        /* copy if loop data if its is missing on one ring */
                                        f = BM_face_create_verts(bm, v_arr, 4, NULL, BM_CREATE_NOP, true);
 
@@ -411,7 +412,8 @@ static void bridge_loop_pair(
                        }
                        else {
                                BMVert *v_arr[3] = {v_a, v_b, v_a_next};
-                               if (BM_face_exists(v_arr, 3, &f) == false) {
+                               f = BM_face_exists(v_arr, 3);
+                               if (f == NULL) {
                                        /* fan-fill a triangle */
                                        f = BM_face_create_verts(bm, v_arr, 3, NULL, BM_CREATE_NOP, true);
 
index c68130bc11dc7502a28672864017e4a856297156..f33a60ccc5ce075e2c6c008539aeed0ab7391bd2 100644 (file)
@@ -136,7 +136,7 @@ void bmo_edgeloop_fill_exec(BMesh *bm, BMOperator *op)
                                i++;
                        } while ((v != f_verts[0]));
 
-                       if (BM_face_exists(f_verts, i, NULL) == false) {
+                       if (!BM_face_exists(f_verts, i)) {
                                BMFace *f;
 
                                /* don't use calc_edges option because we already have the edges */
index 9c41e4f2115d880d51c3a511ce3f5fa0f5aeb95a..81ec2860cf73aa06b979497128392124ed81baf9 100644 (file)
@@ -119,7 +119,8 @@ static void hull_output_triangles(BMesh *bm, GSet *hull_triangles)
                        };
                        BMFace *f, *example = NULL;
 
-                       if (BM_face_exists(t->v, 3, &f)) {
+                       f = BM_face_exists(t->v, 3);
+                       if (f != NULL) {
                                /* If the operator is run with "use_existing_faces"
                                 * disabled, but an output face in the hull is the
                                 * same as a face in the existing mesh, it should not
index 6da591b23a026167ecf80d2df07d8a95c6b32abf..0ad8247e539da678c13995a424371f228503cae3 100644 (file)
@@ -160,7 +160,7 @@ finally:
        }
 
        if (STACK_SIZE(edges) >= 3) {
-               if (!BM_face_exists(verts, STACK_SIZE(edges), NULL)) {
+               if (!BM_face_exists(verts, STACK_SIZE(edges))) {
                        BMFace *f_new = BM_face_create(bm, verts, edges, STACK_SIZE(edges), f, BM_CREATE_NOP);
                        BLI_assert(f_new != f);
 
index 0fc571bc0a81dd5e2323e5fbc6c3f2aa484175f0..92300ae66a290ca9252abc521b333e0e4291cd8e 100644 (file)
@@ -74,7 +74,7 @@ static bool bm_vert_dissolve_fan_test(BMVert *v)
            ((tot_edge == 3) && (tot_edge_boundary == 0) && (tot_edge_manifold == 3)) ||
            ((tot_edge == 3) && (tot_edge_boundary == 2) && (tot_edge_manifold == 1)))
        {
-               if (!BM_face_exists(varr, tot_edge, NULL)) {
+               if (!BM_face_exists(varr, tot_edge)) {
                        return true;
                }
        }
index e31e4096ded8c6a85e52da0091704cddce534e6c..e05ce727e2287783c6d967cf1b97f5992ae6cb55 100644 (file)
@@ -496,7 +496,7 @@ static void edbm_tagged_loop_pairs_do_fill_faces(BMesh *bm, UnorderedLoopPair *u
                        }
 
                        /* face should never exist */
-                       BLI_assert(BM_face_exists(f_verts, f_verts[3] ? 4 : 3, &f) == false);
+                       BLI_assert(!BM_face_exists(f_verts, f_verts[3] ? 4 : 3));
 
                        f = BM_face_create_verts(bm, f_verts, f_verts[3] ? 4 : 3, f_example, BM_CREATE_NOP, true);
 
index 4fc61e0912e7da6d2b905806f882b5285d66f63a..438c3acdb1137d3a05ce6a21176007e641bb1e62 100644 (file)
@@ -1139,7 +1139,6 @@ BMEdge *EDBM_verts_mirror_get_edge(BMEditMesh *em, BMEdge *e)
 
 BMFace *EDBM_verts_mirror_get_face(BMEditMesh *em, BMFace *f)
 {
-       BMFace *f_mirr = NULL;
        BMVert **v_mirr_arr = BLI_array_alloca(v_mirr_arr, f->len);
 
        BMLoop *l_iter, *l_first;
@@ -1152,8 +1151,7 @@ BMFace *EDBM_verts_mirror_get_face(BMEditMesh *em, BMFace *f)
                }
        } while ((l_iter = l_iter->next) != l_first);
 
-       BM_face_exists(v_mirr_arr, f->len, &f_mirr);
-       return f_mirr;
+       return BM_face_exists(v_mirr_arr, f->len);
 }
 
 void EDBM_verts_mirror_cache_clear(BMEditMesh *em, BMVert *v)
index 1d951bae48bdd6a10bc99868ef3654963bd3c5d6..b20c03bee28f82a501ae4397607b3443c7ccab76 100644 (file)
@@ -2233,7 +2233,7 @@ static PyObject *bpy_bmfaceseq_new(BPy_BMElemSeq *self, PyObject *args)
                }
 
                /* check if the face exists */
-               if (BM_face_exists(vert_array, vert_seq_len, NULL)) {
+               if (BM_face_exists(vert_array, vert_seq_len) != NULL) {
                        PyErr_SetString(PyExc_ValueError,
                                        "faces.new(verts): face already exists");
                        goto cleanup;
@@ -2426,7 +2426,8 @@ static PyObject *bpy_bmfaceseq_get__method(BPy_BMElemSeq *self, PyObject *args)
                        return NULL;
                }
 
-               if (BM_face_exists(vert_array, vert_seq_len, &f)) {
+               f = BM_face_exists(vert_array, vert_seq_len);
+               if (f != NULL) {
                        ret = BPy_BMFace_CreatePyObject(bm, f);
                }
                else {