BMesh: use typed filter callbacks (const args too)
authorCampbell Barton <ideasman42@gmail.com>
Sat, 28 Nov 2015 02:37:02 +0000 (13:37 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 28 Nov 2015 02:37:02 +0000 (13:37 +1100)
source/blender/bmesh/bmesh_class.h
source/blender/bmesh/intern/bmesh_construct.c
source/blender/bmesh/intern/bmesh_construct.h
source/blender/bmesh/operators/bmo_fill_attribute.c
source/blender/bmesh/operators/bmo_normals.c

index 57107ed..16e8285 100644 (file)
@@ -309,7 +309,11 @@ enum {
 struct BPy_BMGeneric;
 extern void bpy_bm_generic_invalidate(struct BPy_BMGeneric *self);
 
-typedef bool (*BMElemFilterFunc)(BMElem *, void *user_data);
+typedef bool (*BMElemFilterFunc)(const BMElem *, void *user_data);
+typedef bool (*BMVertFilterFunc)(const BMVert *, void *user_data);
+typedef bool (*BMEdgeFilterFunc)(const BMEdge *, void *user_data);
+typedef bool (*BMFaceFilterFunc)(const BMFace *, void *user_data);
+typedef bool (*BMLoopFilterFunc)(const BMLoop *, void *user_data);
 
 /* defines */
 #define BM_ELEM_CD_SET_INT(ele, offset, f) { CHECK_TYPE_NONCONST(ele); \
index 7664108..3c2a85e 100644 (file)
@@ -116,7 +116,7 @@ BMFace *BM_face_create_quad_tri(
  */
 void BM_face_copy_shared(
         BMesh *bm, BMFace *f,
-        BMElemFilterFunc filter_fn, void *user_data)
+        BMLoopFilterFunc filter_fn, void *user_data)
 {
        BMLoop *l_first;
        BMLoop *l_iter;
@@ -149,7 +149,7 @@ void BM_face_copy_shared(
                        for (j = 0; j < 2; j++) {
                                BLI_assert(l_dst[j]->v == l_src[j]->v);
                                if (BM_ELEM_API_FLAG_TEST(l_dst[j], _FLAG_OVERLAP) == 0) {
-                                       if ((filter_fn == NULL) || filter_fn((BMElem *)l_src[j], user_data)) {
+                                       if ((filter_fn == NULL) || filter_fn(l_src[j], user_data)) {
                                                bm_loop_attrs_copy(bm, bm, l_src[j], l_dst[j]);
                                                BM_ELEM_API_FLAG_ENABLE(l_dst[j], _FLAG_OVERLAP);
                                        }
index 2950367..ce8b8dd 100644 (file)
@@ -38,7 +38,7 @@ BMFace *BM_face_create_quad_tri(
 
 void BM_face_copy_shared(
         BMesh *bm, BMFace *f,
-        BMElemFilterFunc filter_fn, void *user_data);
+        BMLoopFilterFunc filter_fn, void *user_data);
 
 BMFace *BM_face_create_ngon(
         BMesh *bm, BMVert *v1, BMVert *v2, BMEdge **edges, const int len,
index 85bca74..233ed74 100644 (file)
@@ -53,9 +53,9 @@ static bool bm_loop_is_all_radial_tag(BMLoop *l)
 /**
  * Callback to run on source-loops for #BM_face_copy_shared
  */
-static bool bm_loop_is_face_untag(BMElem *ele, void *UNUSED(user_data))
+static bool bm_loop_is_face_untag(const BMLoop *l, void *UNUSED(user_data))
 {
-       return (BM_elem_flag_test(((BMLoop *)ele)->f, BM_ELEM_TAG) == 0);
+       return (BM_elem_flag_test(l->f, BM_ELEM_TAG) == 0);
 }
 
 /**
index 1f50feb..06ceece 100644 (file)
@@ -41,9 +41,9 @@
 #define FACE_FLIP      (1 << 1)
 #define FACE_TEMP      (1 << 2)
 
-static bool bmo_recalc_normal_edge_filter_cb(BMElem *ele, void *UNUSED(user_data))
+static bool bmo_recalc_normal_edge_filter_cb(const BMElem *ele, void *UNUSED(user_data))
 {
-       return BM_edge_is_manifold((BMEdge *)ele);
+       return BM_edge_is_manifold((const BMEdge *)ele);
 }
 
 /**
@@ -229,7 +229,7 @@ static void bmo_recalc_face_normals_array(BMesh *bm, BMFace **faces, const int f
                do {
                        BMLoop *l_other = l_iter->radial_next;
 
-                       if ((l_other != l_iter) && bmo_recalc_normal_edge_filter_cb((BMElem *)l_iter->e, NULL)) {
+                       if ((l_other != l_iter) && bmo_recalc_normal_edge_filter_cb((const BMElem *)l_iter->e, NULL)) {
                                if (!BMO_elem_flag_test(bm, l_other->f, FACE_TEMP)) {
                                        BMO_elem_flag_enable(bm, l_other->f, FACE_TEMP);
                                        BMO_elem_flag_set(bm, l_other->f, FACE_FLIP, (l_other->v == l_iter->v) != flip_state);