diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-09-05 23:21:55 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-09-05 23:21:55 +0400 |
commit | 6e85ffc4fa25d9acb4f2bfef883eaddc7577fe88 (patch) | |
tree | 13948a171caa0a8c0a40268568beef34569f6cd0 /source/blender/bmesh | |
parent | b9e544e82312526af951c4ce34aa99cb680c5a49 (diff) |
code cleanup: bmesh subdivide code was growing arrays one by one, when the final size is known - do this in one go.
also replace for loops with iterator macros.
Diffstat (limited to 'source/blender/bmesh')
-rw-r--r-- | source/blender/bmesh/operators/bmo_subdivide.c | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/source/blender/bmesh/operators/bmo_subdivide.c b/source/blender/bmesh/operators/bmo_subdivide.c index 2af764060fb..00268e84b6d 100644 --- a/source/blender/bmesh/operators/bmo_subdivide.c +++ b/source/blender/bmesh/operators/bmo_subdivide.c @@ -938,9 +938,9 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) BLI_array_empty(splits); /* for case of two edges, connecting them shouldn't be too hard */ - BM_ITER_ELEM (l, &liter, face, BM_LOOPS_OF_FACE) { - BLI_array_grow_one(loops); - loops[BLI_array_count(loops) - 1] = l; + BLI_array_grow_items(loops, face->len); + BM_ITER_ELEM_INDEX (l, &liter, face, BM_LOOPS_OF_FACE, a) { + loops[a] = l; } vlen = BLI_array_count(loops); @@ -971,18 +971,21 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) b += numcuts - 1; + BLI_array_grow_items(splits, numcuts * 2); for (j = 0; j < numcuts; j++) { - BLI_array_grow_one(splits); - splits[BLI_array_count(splits) - 1] = loops[a]; - - BLI_array_grow_one(splits); - splits[BLI_array_count(splits) - 1] = loops[b]; + splits[j * 2 + 0] = loops[a]; + splits[j * 2 + 1] = loops[b]; b = (b - 1) % vlen; a = (a + 1) % vlen; } - //BM_face_legal_splits(bmesh, face, splits, BLI_array_count(splits) / 2); + /* Since these are newly created vertices, we don't need to worry about them being legal, + * ... though there are some cases we _should_ check for + * - concave corner of an ngon. + * - 2 edges being used in 2+ ngons. + */ + // BM_face_legal_splits(bm, face, (BMLoop *(*)[2])splits, BLI_array_count(splits) / 2); for (j = 0; j < BLI_array_count(splits) / 2; j++) { if (splits[j * 2]) { @@ -997,27 +1000,19 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) continue; } - j = a = 0; - for (nl = BM_iter_new(&liter, bm, BM_LOOPS_OF_FACE, face); - nl; - nl = BM_iter_step(&liter)) - { + a = 0; + BM_ITER_ELEM_INDEX (nl, &liter, face, BM_LOOPS_OF_FACE, j) { if (nl->v == facedata[i].start) { a = j + 1; break; } - j++; } - for (j = 0; j < face->len; j++) { - BLI_array_grow_one(verts); - } - - j = 0; - for (nl = BM_iter_new(&liter, bm, BM_LOOPS_OF_FACE, face); nl; nl = BM_iter_step(&liter)) { + BLI_array_grow_items(verts, face->len); + + BM_ITER_ELEM_INDEX (nl, &liter, face, BM_LOOPS_OF_FACE, j) { b = (j - a + face->len) % face->len; verts[b] = nl->v; - j += 1; } BM_CHECK_ELEMENT(face); |