BMesh: refactor edge-vert swapping into API call

This commit is contained in:
Campbell Barton
2015-04-30 02:25:32 +10:00
parent 67fcb04bbf
commit 26541b7488
3 changed files with 29 additions and 35 deletions

View File

@@ -2050,24 +2050,7 @@ bool BM_vert_splice(BMesh *bm, BMVert *v, BMVert *v_target)
/* move all the edges from v's disk to vtarget's disk */
while ((e = v->e)) {
/* loop */
BMLoop *l_first;
if ((l_first = e->l)) {
BMLoop *l_iter = l_first;
do {
if (l_iter->v == v) {
l_iter->v = v_target;
}
/* else if (l_iter->prev->v == v) {...}
* (this case will be handled by a different edge) */
} while ((l_iter = l_iter->radial_next) != l_first);
}
/* disk */
bmesh_disk_edge_remove(e, v);
bmesh_disk_vert_swap(e, v_target, v);
bmesh_disk_edge_append(e, v_target);
bmesh_edge_vert_swap(e, v_target, v);
BLI_assert(e->v1 != e->v2);
}
@@ -2173,23 +2156,7 @@ void bmesh_vert_separate(
}
while ((e = BLI_SMALLSTACK_POP(edges))) {
/* swap out loops */
if (e->l) {
BMLoop *l_iter, *l_first;
l_iter = l_first = e->l;
do {
if (l_iter->v == v) {
l_iter->v = v_new;
}
} while ((l_iter = l_iter->radial_next) != l_first);
}
/* swap out edges */
BLI_assert(e->v1 == v || e->v2 == v);
bmesh_disk_edge_remove(e, v);
bmesh_disk_vert_swap(e, v_new, v);
bmesh_disk_edge_append(e, v_new);
bmesh_edge_vert_swap(e, v_new, v);
}
if (r_vout) {

View File

@@ -55,6 +55,32 @@ void bmesh_disk_vert_swap(BMEdge *e, BMVert *v_dst, BMVert *v_src)
}
}
/**
* Handles all connected data, use with care.
*
* Assumes caller has setup correct state before the swap is done.
*/
void bmesh_edge_vert_swap(BMEdge *e, BMVert *v_dst, BMVert *v_src)
{
/* swap out loops */
if (e->l) {
BMLoop *l_iter, *l_first;
l_iter = l_first = e->l;
do {
if (l_iter->v == v_src) {
l_iter->v = v_dst;
}
} while ((l_iter = l_iter->radial_next) != l_first);
}
/* swap out edges */
BLI_assert(e->v1 == v_src || e->v2 == v_src);
bmesh_disk_edge_remove(e, v_src);
bmesh_disk_vert_swap(e, v_dst, v_src);
bmesh_disk_edge_append(e, v_dst);
BLI_assert(e->v1 != e->v2);
}
/**
* \section bm_cycles BMesh Cycles
* (this is somewhat outdate, though bits of its API are still used) - joeedh

View File

@@ -71,6 +71,7 @@ bool bmesh_radial_validate(int radlen, BMLoop *l) ATTR_WARN_UNUSED_RESULT ATT
/* EDGE UTILITIES */
void bmesh_disk_vert_swap(BMEdge *e, BMVert *v_dst, BMVert *v_src) ATTR_NONNULL();
void bmesh_edge_vert_swap(BMEdge *e, BMVert *v_dst, BMVert *v_src) ATTR_NONNULL();
BMEdge *bmesh_disk_edge_exists(const BMVert *v1, const BMVert *v2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
bool bmesh_disk_validate(int len, BMEdge *e, BMVert *v) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();