From cb6f4160cce25fb3f233e0e0a623d035836caa32 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 27 Mar 2013 10:14:09 +0000 Subject: api cleanup: replace BMO_vert_edge_flags_count() with more reusable function - BMO_iter_elem_count_flag(). closely matching existing BM_iter_elem_count_flag() function but checks tool-flags instead. --- source/blender/bmesh/intern/bmesh_iterators.c | 28 ++++++++++++++++++++-- source/blender/bmesh/intern/bmesh_iterators.h | 1 + source/blender/bmesh/intern/bmesh_operator_api.h | 6 +---- .../bmesh/intern/bmesh_operator_api_inline.h | 2 +- source/blender/bmesh/intern/bmesh_operators.c | 19 --------------- source/blender/bmesh/operators/bmo_edgeloop_fill.c | 2 +- source/blender/bmesh/operators/bmo_edgenet.c | 6 ++--- 7 files changed, 33 insertions(+), 31 deletions(-) diff --git a/source/blender/bmesh/intern/bmesh_iterators.c b/source/blender/bmesh/intern/bmesh_iterators.c index 44b76df7432..a1dde035224 100644 --- a/source/blender/bmesh/intern/bmesh_iterators.c +++ b/source/blender/bmesh/intern/bmesh_iterators.c @@ -170,7 +170,7 @@ int BM_iter_elem_count_flag(const char itype, void *data, const char hflag, cons BMElem *ele; int count = 0; - for (ele = BM_iter_new(&iter, NULL, itype, data); ele; ele = BM_iter_step(&iter)) { + BM_ITER_ELEM (ele, &iter, data, itype) { if (BM_elem_flag_test_bool(ele, hflag) == value) { count++; } @@ -179,6 +179,30 @@ int BM_iter_elem_count_flag(const char itype, void *data, const char hflag, cons return count; } +/** + * \brief Elem Iter Tool Flag Count + * + * Counts how many flagged / unflagged items are found in this element. + */ +int BMO_iter_elem_count_flag(BMesh *bm, const char itype, void *data, + const short oflag, const bool value) +{ + BMIter iter; + BMElemF *ele; + int count = 0; + + /* loops have no header flags */ + BLI_assert(bm_iter_itype_htype_map[itype] != BM_LOOP); + + BM_ITER_ELEM (ele, &iter, data, itype) { + if (BMO_elem_flag_test_bool(bm, ele, oflag) == value) { + count++; + } + } + return count; +} + + /** * \brief Mesh Iter Flag Count * @@ -190,7 +214,7 @@ int BM_iter_mesh_count_flag(const char itype, BMesh *bm, const char hflag, const BMElem *ele; int count = 0; - for (ele = BM_iter_new(&iter, bm, itype, NULL); ele; ele = BM_iter_step(&iter)) { + BM_ITER_MESH (ele, &iter, bm, itype) { if (BM_elem_flag_test_bool(ele, hflag) == value) { count++; } diff --git a/source/blender/bmesh/intern/bmesh_iterators.h b/source/blender/bmesh/intern/bmesh_iterators.h index 3b795a253bd..5fb226ae11d 100644 --- a/source/blender/bmesh/intern/bmesh_iterators.h +++ b/source/blender/bmesh/intern/bmesh_iterators.h @@ -132,6 +132,7 @@ __attribute__((warn_unused_result)) #endif ; int BM_iter_elem_count_flag(const char itype, void *data, const char hflag, const bool value); +int BMO_iter_elem_count_flag(BMesh *bm, const char itype, void *data, const short oflag, const bool value); int BM_iter_mesh_count_flag(const char itype, BMesh *bm, const char hflag, const bool value); /* private for bmesh_iterators_inline.c */ diff --git a/source/blender/bmesh/intern/bmesh_operator_api.h b/source/blender/bmesh/intern/bmesh_operator_api.h index 978aec0c610..180bc53c2e3 100644 --- a/source/blender/bmesh/intern/bmesh_operator_api.h +++ b/source/blender/bmesh/intern/bmesh_operator_api.h @@ -83,7 +83,7 @@ struct GHashIterator; #define BMO_elem_flag_toggle( bm, ele, oflag) _bmo_elem_flag_toggle (bm, (ele)->oflags, oflag) BLI_INLINE short _bmo_elem_flag_test( BMesh *bm, BMFlagLayer *oflags, const short oflag); -BLI_INLINE short _bmo_elem_flag_test_bool(BMesh *bm, BMFlagLayer *oflags, const short oflag); +BLI_INLINE bool _bmo_elem_flag_test_bool(BMesh *bm, BMFlagLayer *oflags, const short oflag); BLI_INLINE void _bmo_elem_flag_enable( BMesh *bm, BMFlagLayer *oflags, const short oflag); BLI_INLINE void _bmo_elem_flag_disable( BMesh *bm, BMFlagLayer *oflags, const short oflag); BLI_INLINE void _bmo_elem_flag_set( BMesh *bm, BMFlagLayer *oflags, const short oflag, int val); @@ -391,10 +391,6 @@ int BMO_slot_map_count(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_na void BMO_slot_map_insert(BMOperator *op, BMOpSlot *slot, const void *element, const void *data, const int len); -/* Counts the number of edges with tool flag toolflag around - */ -int BMO_vert_edge_flags_count(BMesh *bm, BMVert *v, const short oflag); - /* flags all elements in a mapping. note that the mapping must only have * bmesh elements in it.*/ void BMO_slot_map_to_flag(BMesh *bm, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], diff --git a/source/blender/bmesh/intern/bmesh_operator_api_inline.h b/source/blender/bmesh/intern/bmesh_operator_api_inline.h index 0e1d4fec4d3..724ddcf3b04 100644 --- a/source/blender/bmesh/intern/bmesh_operator_api_inline.h +++ b/source/blender/bmesh/intern/bmesh_operator_api_inline.h @@ -43,7 +43,7 @@ BLI_INLINE short _bmo_elem_flag_test(BMesh *bm, BMFlagLayer *oflags, const short return oflags[bm->stackdepth - 1].f & oflag; } -BLI_INLINE short _bmo_elem_flag_test_bool(BMesh *bm, BMFlagLayer *oflags, const short oflag) +BLI_INLINE bool _bmo_elem_flag_test_bool(BMesh *bm, BMFlagLayer *oflags, const short oflag) { return (oflags[bm->stackdepth - 1].f & oflag) != 0; } diff --git a/source/blender/bmesh/intern/bmesh_operators.c b/source/blender/bmesh/intern/bmesh_operators.c index f52dd7f2be9..a358623834f 100644 --- a/source/blender/bmesh/intern/bmesh_operators.c +++ b/source/blender/bmesh/intern/bmesh_operators.c @@ -1075,25 +1075,6 @@ void BMO_slot_buffer_hflag_disable(BMesh *bm, } } -int BMO_vert_edge_flags_count(BMesh *bm, BMVert *v, const short oflag) -{ - int count = 0; - - if (v->e) { - BMEdge *curedge; - const int len = bmesh_disk_count(v); - int i; - - for (i = 0, curedge = v->e; i < len; i++) { - if (BMO_elem_flag_test(bm, curedge, oflag)) - count++; - curedge = bmesh_disk_edge_next(curedge, v); - } - } - - return count; -} - /** * \brief BMO_FLAG_BUFFER * diff --git a/source/blender/bmesh/operators/bmo_edgeloop_fill.c b/source/blender/bmesh/operators/bmo_edgeloop_fill.c index 62c308d4199..3818f449a15 100644 --- a/source/blender/bmesh/operators/bmo_edgeloop_fill.c +++ b/source/blender/bmesh/operators/bmo_edgeloop_fill.c @@ -84,7 +84,7 @@ void bmo_edgeloop_fill_exec(BMesh *bm, BMOperator *op) for (i = 0; i < totv; i++) { v = verts[i]; /* count how many flagged edges this vertex uses */ - if (BMO_vert_edge_flags_count(bm, v, EDGE_MARK) != 2) { + if (BMO_iter_elem_count_flag(bm, BM_EDGES_OF_VERT, v, EDGE_MARK, true) != 2) { ok = false; break; } diff --git a/source/blender/bmesh/operators/bmo_edgenet.c b/source/blender/bmesh/operators/bmo_edgenet.c index 30cfa2c1496..cf91dfd0f15 100644 --- a/source/blender/bmesh/operators/bmo_edgenet.c +++ b/source/blender/bmesh/operators/bmo_edgenet.c @@ -1112,7 +1112,7 @@ void bmo_edgenet_prepare_exec(BMesh *bm, BMOperator *op) * disk cycle around each of it's vertices */ BMO_ITER (e, &siter, op->slots_in, "edges", BM_EDGE) { for (i = 0; i < 2; i++) { - count = BMO_vert_edge_flags_count(bm, i ? e->v2 : e->v1, EDGE_MARK); + count = BMO_iter_elem_count_flag(bm, BM_EDGES_OF_VERT, (i ? e->v2 : e->v1), EDGE_MARK, true); if (count > 2) { ok = 0; break; @@ -1134,8 +1134,8 @@ void bmo_edgenet_prepare_exec(BMesh *bm, BMOperator *op) while (1) { BMO_ITER (e, &siter, op->slots_in, "edges", BM_EDGE) { if (!BMO_elem_flag_test(bm, e, EDGE_VIS)) { - if (BMO_vert_edge_flags_count(bm, e->v1, EDGE_MARK) == 1 || - BMO_vert_edge_flags_count(bm, e->v2, EDGE_MARK) == 1) + if (BMO_iter_elem_count_flag(bm, BM_EDGES_OF_VERT, e->v1, EDGE_MARK, true) == 1 || + BMO_iter_elem_count_flag(bm, BM_EDGES_OF_VERT, e->v2, EDGE_MARK, true) == 1) { break; } -- cgit v1.2.3