diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-04-19 16:45:56 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-04-19 16:45:56 +0400 |
commit | 3ef79439100a910f2f23b8ad1d3584984d289ee9 (patch) | |
tree | c962832271925fe410f479dedddda848a01eb5fc | |
parent | 7cadd242d3eb7a29f19efe1d1462dbe12998c196 (diff) |
code cleanup: first step to replace BM_ITER BM_ITER_INDEX macros.
-rw-r--r-- | source/blender/blenkernel/intern/customdata.c | 2 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_iterators.c | 9 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_iterators.h | 23 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_mesh.c | 46 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_operators.c | 4 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_select.c | 2 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_tools.c | 13 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_utils.c | 6 |
8 files changed, 57 insertions, 48 deletions
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index f2238a37ff9..b0c0294ca39 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -2191,7 +2191,7 @@ void CustomData_bmesh_merge(CustomData *source, CustomData *dest, if (t != BM_LOOPS_OF_FACE) { /*ensure all current elements follow new customdata layout*/ - BM_ITER (h, &iter, bm, t, NULL) { + BM_ITER_MESH (h, &iter, bm, t) { tmp = NULL; CustomData_bmesh_copy_data(&destold, dest, h->data, &tmp); CustomData_bmesh_free_block(&destold, &h->data); diff --git a/source/blender/bmesh/intern/bmesh_iterators.c b/source/blender/bmesh/intern/bmesh_iterators.c index b234d4514c0..384715d74f7 100644 --- a/source/blender/bmesh/intern/bmesh_iterators.c +++ b/source/blender/bmesh/intern/bmesh_iterators.c @@ -83,18 +83,17 @@ void *BM_iter_at_index(BMesh *bm, const char itype, void *data, int index) * Sometimes its convenient to get the iterator as an array * to avoid multiple calls to #BM_iter_at_index. */ -int BM_iter_as_array(BMesh *bm, const char type, void *data, void **array, const int len) +int BM_iter_as_array(BMesh *bm, const char itype, void *data, void **array, const int len) { int i = 0; /* sanity check */ if (len > 0) { - BMIter iter; - void *val; + void *ele; - BM_ITER (val, &iter, bm, type, data) { - array[i] = val; + for (ele = BM_iter_new(&iter, bm, itype, data); ele; ele = BM_iter_step(&iter)) { + array[i] = ele; i++; if (i == len) { return len; diff --git a/source/blender/bmesh/intern/bmesh_iterators.h b/source/blender/bmesh/intern/bmesh_iterators.h index d3566d8aead..65da25015ee 100644 --- a/source/blender/bmesh/intern/bmesh_iterators.h +++ b/source/blender/bmesh/intern/bmesh_iterators.h @@ -83,13 +83,24 @@ typedef enum BMIterType { extern const char bm_iter_itype_htype_map[BM_ITYPE_MAX]; -#define BM_ITER(ele, iter, bm, itype, data) \ - ele = BM_iter_new(iter, bm, itype, data); \ - for ( ; ele; ele = BM_iter_step(iter)) +#define BM_ITER(ele, iter, bm, itype, data) \ + for (ele = BM_iter_new(iter, bm, itype, data); ele; ele = BM_iter_step(iter)) + +#define BM_ITER_MESH(ele, iter, bm, itype) \ + for (ele = BM_iter_new(iter, bm, itype, NULL); ele; ele = BM_iter_step(iter)) + +#define BM_ITER_MESH_INDEX(ele, iter, bm, itype, indexvar) \ + for (ele = BM_iter_new(iter, bm, itype, NULL), indexvar = 0; ele; ele = BM_iter_step(iter), (indexvar)++) + +#define BM_ITER_ELEM(ele, iter, data, itype) \ + for (ele = BM_iter_new(iter, NULL, itype, data); ele; ele = BM_iter_step(iter)) + +#define BM_ITER_ELEM_INDEX(ele, iter, data, itype) \ + for (ele = BM_iter_new(iter, NULL, itype, data), indexvar = 0; ele; ele = BM_iter_step(iter), (indexvar)++) + +#define BM_ITER_INDEX(ele, iter, bm, itype, data, indexvar) \ + for (ele = BM_iter_new(iter, bm, itype, data), indexvar = 0; ele; ele = BM_iter_step(iter), (indexvar)++) -#define BM_ITER_INDEX(ele, iter, bm, itype, data, indexvar) \ - ele = BM_iter_new(iter, bm, itype, data); \ - for (indexvar = 0; ele; indexvar++, ele = BM_iter_step(iter)) /* Iterator Structure */ typedef struct BMIter { diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.c index c70e694f9ea..d3c0404e73e 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.c +++ b/source/blender/bmesh/intern/bmesh_mesh.c @@ -214,7 +214,7 @@ void BM_mesh_normals_update(BMesh *bm, const short skip_hidden) BM_ITER (f, &faces, bm, BM_FACES_OF_MESH, NULL) { if (skip_hidden && BM_elem_flag_test(f, BM_ELEM_HIDDEN)) continue; -#if 0 /* UNUSED */ +#if 0 /* UNUSED */ if (f->head.flag & BM_NONORMCALC) continue; #endif @@ -304,7 +304,7 @@ void BM_mesh_normals_update(BMesh *bm, const short skip_hidden) */ //keep in sycn with utils.c! -#define FACE_FLIP 8 +#define FACE_FLIP 8 static void bm_rationalize_normals(BMesh *bm, int undo) { BMOperator bmop; @@ -540,7 +540,7 @@ void BM_mesh_elem_index_validate(BMesh *bm, const char *location, const char *fu int err_val = 0; int err_idx = 0; - BM_ITER (ele, &iter, bm, iter_types[i], NULL) { + BM_ITER_MESH (ele, &iter, bm, iter_types[i]) { if (!is_dirty) { if (BM_elem_index_get(ele) != index) { err_val = BM_elem_index_get(ele); @@ -561,7 +561,7 @@ void BM_mesh_elem_index_validate(BMesh *bm, const char *location, const char *fu } else if ((is_error == FALSE) && (is_dirty == TRUE)) { -#if 0 /* mostly annoying */ +#if 0 /* mostly annoying */ /* dirty may have been incorrectly set */ fprintf(stderr, @@ -619,8 +619,8 @@ void BM_mesh_remap(BMesh *bm, int *vert_idx, int *edge_idx, int *face_idx) vptr_map = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "BM_mesh_remap vert pointers mapping"); /* Make a copy of all vertices. */ - verts_pool = MEM_callocN(sizeof(BMVert*) * totvert, "BM_mesh_remap verts pool"); - BM_iter_as_array(bm, BM_VERTS_OF_MESH, NULL, (void**)verts_pool, totvert); + verts_pool = MEM_callocN(sizeof(BMVert *) * totvert, "BM_mesh_remap verts pool"); + BM_iter_as_array(bm, BM_VERTS_OF_MESH, NULL, (void **)verts_pool, totvert); verts_copy = MEM_mallocN(sizeof(BMVert) * totvert, "BM_mesh_remap verts copy"); for (i = totvert, ve = verts_copy + totvert - 1, vep = verts_pool + totvert - 1; i--; ve--, vep--) { *ve = **vep; @@ -635,7 +635,7 @@ void BM_mesh_remap(BMesh *bm, int *vert_idx, int *edge_idx, int *face_idx) BMVert *new_vep = verts_pool[*new_idx]; *new_vep = *ve; /* printf("mapping vert from %d to %d (%p/%p to %p)\n", i, *new_idx, *vep, verts_pool[i], new_vep);*/ - BLI_ghash_insert(vptr_map, (void*)*vep, (void*)new_vep); + BLI_ghash_insert(vptr_map, (void *)*vep, (void *)new_vep); } bm->elem_index_dirty |= BM_VERT; @@ -653,8 +653,8 @@ void BM_mesh_remap(BMesh *bm, int *vert_idx, int *edge_idx, int *face_idx) eptr_map = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "BM_mesh_remap edge pointers mapping"); /* Make a copy of all vertices. */ - edges_pool = MEM_callocN(sizeof(BMEdge*) * totedge, "BM_mesh_remap edges pool"); - BM_iter_as_array(bm, BM_EDGES_OF_MESH, NULL, (void**)edges_pool, totedge); + edges_pool = MEM_callocN(sizeof(BMEdge *) * totedge, "BM_mesh_remap edges pool"); + BM_iter_as_array(bm, BM_EDGES_OF_MESH, NULL, (void **)edges_pool, totedge); edges_copy = MEM_mallocN(sizeof(BMEdge) * totedge, "BM_mesh_remap edges copy"); for (i = totedge, ed = edges_copy + totedge - 1, edp = edges_pool + totedge - 1; i--; ed--, edp--) { *ed = **edp; @@ -667,7 +667,7 @@ void BM_mesh_remap(BMesh *bm, int *vert_idx, int *edge_idx, int *face_idx) for (i = totedge; i--; new_idx--, ed--, edp--) { BMEdge *new_edp = edges_pool[*new_idx]; *new_edp = *ed; - BLI_ghash_insert(eptr_map, (void*)*edp, (void*)new_edp); + BLI_ghash_insert(eptr_map, (void *)*edp, (void *)new_edp); } bm->elem_index_dirty |= BM_EDGE; @@ -686,8 +686,8 @@ void BM_mesh_remap(BMesh *bm, int *vert_idx, int *edge_idx, int *face_idx) fptr_map = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "BM_mesh_remap face pointers mapping"); /* Make a copy of all vertices. */ - faces_pool = MEM_callocN(sizeof(BMFace*) * totface, "BM_mesh_remap faces pool"); - BM_iter_as_array(bm, BM_FACES_OF_MESH, NULL, (void**)faces_pool, totface); + faces_pool = MEM_callocN(sizeof(BMFace *) * totface, "BM_mesh_remap faces pool"); + BM_iter_as_array(bm, BM_FACES_OF_MESH, NULL, (void **)faces_pool, totface); faces_copy = MEM_mallocN(sizeof(BMFace) * totface, "BM_mesh_remap faces copy"); for (i = totface, fa = faces_copy + totface - 1, fap = faces_pool + totface - 1; i--; fa--, fap--) { *fa = **fap; @@ -700,7 +700,7 @@ void BM_mesh_remap(BMesh *bm, int *vert_idx, int *edge_idx, int *face_idx) for (i = totface; i--; new_idx--, fa--, fap--) { BMFace *new_fap = faces_pool[*new_idx]; *new_fap = *fa; - BLI_ghash_insert(fptr_map, (void*)*fap, (void*)new_fap); + BLI_ghash_insert(fptr_map, (void *)*fap, (void *)new_fap); } bm->elem_index_dirty |= BM_FACE; @@ -712,36 +712,36 @@ void BM_mesh_remap(BMesh *bm, int *vert_idx, int *edge_idx, int *face_idx) /* And now, fix all vertices/edges/faces/loops pointers! */ /* Verts' pointers, only edge pointers... */ if (eptr_map) { - BM_ITER(ve, &iter, bm, BM_VERTS_OF_MESH, NULL) { + BM_ITER (ve, &iter, bm, BM_VERTS_OF_MESH, NULL) { /* printf("Vert e: %p -> %p\n", ve->e, BLI_ghash_lookup(eptr_map, (const void*)ve->e));*/ - ve->e = BLI_ghash_lookup(eptr_map, (const void*)ve->e); + ve->e = BLI_ghash_lookup(eptr_map, (const void *)ve->e); } } /* Edges' pointers, only vert pointers (as we don’t mess with loops!)... */ if (vptr_map) { - BM_ITER(ed, &iter, bm, BM_EDGES_OF_MESH, NULL) { + BM_ITER (ed, &iter, bm, BM_EDGES_OF_MESH, NULL) { /* printf("Edge v1: %p -> %p\n", ed->v1, BLI_ghash_lookup(vptr_map, (const void*)ed->v1));*/ /* printf("Edge v2: %p -> %p\n", ed->v2, BLI_ghash_lookup(vptr_map, (const void*)ed->v2));*/ - ed->v1 = BLI_ghash_lookup(vptr_map, (const void*)ed->v1); - ed->v2 = BLI_ghash_lookup(vptr_map, (const void*)ed->v2); + ed->v1 = BLI_ghash_lookup(vptr_map, (const void *)ed->v1); + ed->v2 = BLI_ghash_lookup(vptr_map, (const void *)ed->v2); } } /* Faces' pointers (loops, in fact), always needed... */ - BM_ITER(fa, &iter, bm, BM_FACES_OF_MESH, NULL) { - BM_ITER(lo, &iterl, bm, BM_LOOPS_OF_FACE, fa) { + BM_ITER (fa, &iter, bm, BM_FACES_OF_MESH, NULL) { + BM_ITER (lo, &iterl, bm, BM_LOOPS_OF_FACE, fa) { if (vptr_map) { /* printf("Loop v: %p -> %p\n", lo->v, BLI_ghash_lookup(vptr_map, (const void*)lo->v));*/ - lo->v = BLI_ghash_lookup(vptr_map, (const void*)lo->v); + lo->v = BLI_ghash_lookup(vptr_map, (const void *)lo->v); } if (eptr_map) { /* printf("Loop e: %p -> %p\n", lo->e, BLI_ghash_lookup(eptr_map, (const void*)lo->e));*/ - lo->e = BLI_ghash_lookup(eptr_map, (const void*)lo->e); + lo->e = BLI_ghash_lookup(eptr_map, (const void *)lo->e); } if (fptr_map) { /* printf("Loop f: %p -> %p\n", lo->f, BLI_ghash_lookup(fptr_map, (const void*)lo->f));*/ - lo->f = BLI_ghash_lookup(fptr_map, (const void*)lo->f); + lo->f = BLI_ghash_lookup(fptr_map, (const void *)lo->f); } } } diff --git a/source/blender/bmesh/intern/bmesh_operators.c b/source/blender/bmesh/intern/bmesh_operators.c index 32abaf10f64..e16554eb637 100644 --- a/source/blender/bmesh/intern/bmesh_operators.c +++ b/source/blender/bmesh/intern/bmesh_operators.c @@ -473,7 +473,7 @@ static int bmo_mesh_flag_count(BMesh *bm, const char htype, const short oflag, for (i = 0; i < 3; i++) { if (htype & flag_types[i]) { - BM_ITER (ele_f, &iter, bm, iter_types[i], NULL) { + BM_ITER_MESH (ele_f, &iter, bm, iter_types[i]) { if (BMO_elem_flag_test_bool(bm, ele_f, oflag) == test_for_enabled) count++; } @@ -508,7 +508,7 @@ void BMO_mesh_flag_disable_all(BMesh *bm, BMOperator *UNUSED(op), const char hty for (i = 0; i < 3; i++) { if (htype & flag_types[i]) { - BM_ITER (ele, &iter, bm, iter_types[i], NULL) { + BM_ITER_MESH (ele, &iter, bm, iter_types[i]) { BMO_elem_flag_disable(bm, ele, oflag); } } diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c index df1775c3f07..831813c566f 100644 --- a/source/blender/editors/mesh/editmesh_select.c +++ b/source/blender/editors/mesh/editmesh_select.c @@ -2044,7 +2044,7 @@ static void walker_deselect_nth(BMEditMesh *em, int nth, int offset, BMHeader *h /* Walker restrictions uses BMO flags, not header flags, * so transfer BM_ELEM_SELECT from HFlags onto a BMO flag layer. */ BMO_push(bm, NULL); - BM_ITER (ele, &iter, bm, itertype, NULL) { + BM_ITER_MESH (ele, &iter, bm, itertype) { if (BM_elem_flag_test(ele, BM_ELEM_SELECT)) { /* BMESH_TODO, don't use 'BM_ELEM_SELECT' here, its a HFLAG only! */ BMO_elem_flag_enable(bm, (BMElemF *)ele, BM_ELEM_SELECT); diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index fe9571b1978..ba280878b2a 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -159,7 +159,7 @@ void EMBM_project_snap_verts(bContext *C, ARegion *ar, Object *obedit, BMEditMes BMIter iter; BMVert *eve; - BM_ITER (eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { + BM_ITER (eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) { float mval[2], vec[3], no_dummy[3]; int dist_dummy; @@ -350,8 +350,7 @@ static short edbm_extrude_vert(Object *obedit, BMEditMesh *em, const char hflag, BMEdge *eed; /* ensure vert flags are consistent for edge selections */ - eed = BM_iter_new(&iter, em->bm, BM_EDGES_OF_MESH, NULL); - for ( ; eed; eed = BM_iter_step(&iter)) { + BM_ITER_MESH(eed, &iter, em->bm, BM_EDGES_OF_MESH) { if (BM_elem_flag_test(eed, hflag)) { if (hflag & BM_ELEM_SELECT) { BM_elem_select_set(em->bm, eed->v1, TRUE); @@ -2033,7 +2032,7 @@ void MESH_OT_remove_doubles(wmOperatorType *ot) { /* identifiers */ ot->name = "Remove Doubles"; - ot->description= "Remove duplicate vertices"; + ot->description = "Remove duplicate vertices"; ot->idname = "MESH_OT_remove_doubles"; /* api callbacks */ @@ -3662,7 +3661,7 @@ static void xsortvert_flag(bContext *C, int flag) sortblock = MEM_callocN(sizeof(xvertsort) * totvert, "xsort sorted"); /* Stores unchanged verts, will be reused as final old2new vert mapping... */ unchangedblock = MEM_callocN(sizeof(int) * totvert, "xsort unchanged"); - BM_ITER_INDEX(ve, &iter, em->bm, BM_VERTS_OF_MESH, NULL, i) { + BM_ITER_INDEX (ve, &iter, em->bm, BM_VERTS_OF_MESH, NULL, i) { if (BM_elem_flag_test(ve, flag)) { sortblock[i].org_idx = i; sorted++; @@ -3754,8 +3753,8 @@ static int float_sort(const void *v1, const void *v2) x1 = face_sort_floats[((int *) v1)[0]]; x2 = face_sort_floats[((int *) v2)[0]]; - if (x1 > x2) return 1; - else if (x1 < x2) return -1; + if (x1 > x2) return 1; + else if (x1 < x2) return -1; return 0; } diff --git a/source/blender/editors/mesh/editmesh_utils.c b/source/blender/editors/mesh/editmesh_utils.c index d48f1776c59..13e059bb5d8 100644 --- a/source/blender/editors/mesh/editmesh_utils.c +++ b/source/blender/editors/mesh/editmesh_utils.c @@ -1189,7 +1189,7 @@ void EDBM_mesh_hide(BMEditMesh *em, int swap) else itermode = BM_FACES_OF_MESH; - BM_ITER (ele, &iter, em->bm, itermode, NULL) { + BM_ITER_MESH (ele, &iter, em->bm, itermode) { if (BM_elem_flag_test(ele, BM_ELEM_SELECT) ^ swap) BM_elem_hide_set(em->bm, ele, TRUE); } @@ -1223,7 +1223,7 @@ void EDBM_mesh_reveal(BMEditMesh *em) /* Use tag flag to remember what was hidden before all is revealed. * BM_ELEM_HIDDEN --> BM_ELEM_TAG */ for (i = 0; i < 3; i++) { - BM_ITER (ele, &iter, em->bm, iter_types[i], NULL) { + BM_ITER_MESH (ele, &iter, em->bm, iter_types[i]) { BM_elem_flag_set(ele, BM_ELEM_TAG, BM_elem_flag_test(ele, BM_ELEM_HIDDEN)); } } @@ -1237,7 +1237,7 @@ void EDBM_mesh_reveal(BMEditMesh *em) continue; } - BM_ITER (ele, &iter, em->bm, iter_types[i], NULL) { + BM_ITER_MESH (ele, &iter, em->bm, iter_types[i]) { if (BM_elem_flag_test(ele, BM_ELEM_TAG)) { BM_elem_select_set(em->bm, ele, TRUE); } |