Cleanup: correct and update comments for bmesh walkers

- Correct variable names which were missed when refactoring.
- Use full sentences.
This commit is contained in:
Campbell Barton 2021-01-31 17:42:11 +11:00
parent 6b8f28a6b5
commit e6a5e548d5
1 changed files with 88 additions and 85 deletions

View File

@ -29,7 +29,7 @@
#include "bmesh.h"
#include "intern/bmesh_walkers_private.h"
/* pop into stack memory (common operation) */
/* Pop into stack memory (common operation). */
#define BMW_state_remove_r(walker, owalk) \
{ \
memcpy(owalk, BMW_current_state(walker), sizeof(*(owalk))); \
@ -86,7 +86,7 @@ static bool bmw_mask_check_face(BMWalker *walker, BMFace *f)
static bool bmw_edge_is_wire(const BMWalker *walker, const BMEdge *e)
{
if (walker->flag & BMW_FLAG_TEST_HIDDEN) {
/* check if this is a wire edge, ignoring hidden faces */
/* Check if this is a wire edge, ignoring hidden faces. */
if (BM_edge_is_wire(e)) {
return true;
}
@ -137,8 +137,7 @@ static void bmw_VertShellWalker_begin(BMWalker *walker, void *data)
switch (h->htype) {
case BM_VERT: {
/* starting the walk at a vert, add all the edges
* to the worklist */
/* Starting the walk at a vert, add all the edges to the work-list. */
v = (BMVert *)h;
BM_ITER_ELEM (e, &eiter, v, BM_EDGES_OF_VERT) {
bmw_VertShellWalker_visitEdge(walker, e);
@ -147,8 +146,7 @@ static void bmw_VertShellWalker_begin(BMWalker *walker, void *data)
}
case BM_EDGE: {
/* starting the walk at an edge, add the single edge
* to the worklist */
/* Starting the walk at an edge, add the single edge to the work-list. */
e = (BMEdge *)h;
bmw_VertShellWalker_visitEdge(walker, e);
break;
@ -201,7 +199,7 @@ static void *bmw_VertShellWalker_step(BMWalker *walker)
BMW_state_remove(walker);
/* find the next edge whose other vertex has not been visite */
/* Find the next edge whose other vertex has not been visited. */
curedge = shellWalk.curedge;
do {
if (!BLI_gset_haskey(walker->visit_set, curedge)) {
@ -212,11 +210,11 @@ static void *bmw_VertShellWalker_step(BMWalker *walker)
v_old = BM_edge_other_vert(curedge, shellWalk.base);
/* push a new state onto the stac */
/* Push a new state onto the stack. */
newState = BMW_state_add(walker);
BLI_gset_insert(walker->visit_set, curedge);
/* populate the new stat */
/* Populate the new state. */
newState->base = v_old;
newState->curedge = curedge;
@ -266,8 +264,7 @@ static void bmw_LoopShellWalker_begin(BMWalker *walker, void *data)
switch (h->htype) {
case BM_LOOP: {
/* starting the walk at a vert, add all the edges
* to the worklist */
/* Starting the walk at a vert, add all the edges to the work-list. */
BMLoop *l = (BMLoop *)h;
bmw_LoopShellWalker_visitLoop(walker, l);
break;
@ -292,7 +289,7 @@ static void bmw_LoopShellWalker_begin(BMWalker *walker, void *data)
case BM_FACE: {
BMFace *f = (BMFace *)h;
BMLoop *l = BM_FACE_FIRST_LOOP(f);
/* walker will handle other loops within the face */
/* Walker will handle other loops within the face. */
bmw_LoopShellWalker_visitLoop(walker, l);
break;
}
@ -312,7 +309,7 @@ static void bmw_LoopShellWalker_step_impl(BMWalker *walker, BMLoop *l)
BMEdge *e_edj_pair[2];
int i;
/* seems paranoid, but one caller also walks edges */
/* Seems paranoid, but one caller also walks edges. */
BLI_assert(l->head.htype == BM_LOOP);
bmw_LoopShellWalker_visitLoop(walker, l->next);
@ -409,7 +406,7 @@ static void bmw_LoopShellWireWalker_visitVert(BMWalker *walker, BMVert *v, const
bmw_LoopShellWalker_visitEdgeWire(walker, e);
/* check if we step onto a non-wire vertex */
/* Check if we step onto a non-wire vertex. */
v_other = BM_edge_other_vert(e, v);
BM_ITER_ELEM (l, &iter, v_other, BM_LOOPS_OF_VERT) {
@ -463,7 +460,7 @@ static void bmw_LoopShellWireWalker_begin(BMWalker *walker, void *data)
break;
}
case BM_FACE: {
/* wire verts will be walked over */
/* Wire verts will be walked over. */
break;
}
default:
@ -581,12 +578,12 @@ static void bmw_ConnectedVertexWalker_visitVertex(BMWalker *walker, BMVert *v)
BMwConnectedVertexWalker *vwalk;
if (BLI_gset_haskey(walker->visit_set, v)) {
/* already visited */
/* Already visited. */
return;
}
if (!bmw_mask_check_vert(walker, v)) {
/* not flagged for walk */
/* Not flagged for walk. */
return;
}
@ -670,10 +667,9 @@ static void *bmw_IslandboundWalker_step(BMWalker *walker)
BMEdge *e;
BMFace *f;
BMLoop *l;
/* int found = 0; */
memcpy(&owalk, BMW_current_state(walker), sizeof(owalk));
/* normally we'd remove here, but delay until after error checking */
/* Normally we'd remove here, but delay until after error checking. */
iwalk = &owalk;
l = iwalk->curloop;
@ -681,7 +677,7 @@ static void *bmw_IslandboundWalker_step(BMWalker *walker)
v = BM_edge_other_vert(e, iwalk->lastv);
/* pop off current state */
/* Pop off current state. */
BMW_state_remove(walker);
f = l->f;
@ -699,7 +695,7 @@ static void *bmw_IslandboundWalker_step(BMWalker *walker)
}
}
else {
/* treat non-manifold edges as boundaries */
/* Treat non-manifold edges as boundaries. */
f = l->f;
e = l->e;
break;
@ -717,9 +713,16 @@ static void *bmw_IslandboundWalker_step(BMWalker *walker)
iwalk = BMW_state_add(walker);
iwalk->base = owalk.base;
// if (!BMO_face_flag_test(walker->bm, l->f, walker->restrictflag))
// iwalk->curloop = l->radial_next;
iwalk->curloop = l; // else iwalk->curloop = l;
#if 0
if (!BMO_face_flag_test(walker->bm, l->f, walker->restrictflag)) {
iwalk->curloop = l->radial_next;
}
else {
iwalk->curloop = l;
}
#else
iwalk->curloop = l;
#endif
iwalk->lastv = v;
return owalk.curloop;
@ -763,7 +766,7 @@ static void *bmw_IslandWalker_step_ex(BMWalker *walker, bool only_manifold)
l_iter = l_first = BM_FACE_FIRST_LOOP(iwalk->cur);
do {
/* could skip loop here too, but don't add unless we need it */
/* Could skip loop here too, but don't add unless we need it. */
if (!bmw_mask_check_edge(walker, l_iter->e)) {
continue;
}
@ -772,7 +775,7 @@ static void *bmw_IslandWalker_step_ex(BMWalker *walker, bool only_manifold)
if (only_manifold && (l_iter->radial_next != l_iter)) {
int face_count = 1;
/* check other faces (not this one), ensure only one other can be walked onto. */
/* Check other faces (not this one), ensure only one other Can be walked onto. */
l_radial_iter = l_iter->radial_next;
do {
if (bmw_mask_check_face(walker, l_radial_iter->f)) {
@ -796,7 +799,7 @@ static void *bmw_IslandWalker_step_ex(BMWalker *walker, bool only_manifold)
continue;
}
/* saves checking BLI_gset_haskey below (manifold edges there's a 50% chance) */
/* Saves checking #BLI_gset_haskey below (manifold edges there's a 50% chance). */
if (f == iwalk->cur) {
continue;
}
@ -947,12 +950,12 @@ static void bmw_EdgeLoopWalker_begin(BMWalker *walker, void *data)
}
if (f_best) {
/* only use hub selection for 5+ sides else this could
/* Only use hub selection for 5+ sides else this could
* conflict with normal edge loop selection. */
lwalk->f_hub = f_best->len > 4 ? f_best : NULL;
}
else {
/* edge doesn't have any faces connected to it */
/* Edge doesn't have any faces connected to it. */
lwalk->f_hub = NULL;
}
}
@ -960,7 +963,7 @@ static void bmw_EdgeLoopWalker_begin(BMWalker *walker, void *data)
lwalk->f_hub = NULL;
}
/* rewind */
/* Rewind. */
while ((owalk_pt = BMW_current_state(walker))) {
owalk = *((BMwEdgeLoopWalker *)owalk_pt);
BMW_walk(walker);
@ -1007,7 +1010,7 @@ static void *bmw_EdgeLoopWalker_step(BMWalker *walker)
nexte = BM_edge_exists(v, l->v);
if (bmw_mask_check_edge(walker, nexte) && !BLI_gset_haskey(walker->visit_set, nexte) &&
/* never step onto a boundary edge, this gives odd-results */
/* Never step onto a boundary edge, this gives odd-results. */
(BM_edge_is_boundary(nexte) == false)) {
lwalk = BMW_state_add(walker);
lwalk->cur = nexte;
@ -1024,7 +1027,7 @@ static void *bmw_EdgeLoopWalker_step(BMWalker *walker)
else if (l == NULL) { /* WIRE EDGE */
BMIter eiter;
/* match trunk: mark all connected wire edges */
/* Match trunk: mark all connected wire edges. */
for (int i = 0; i < 2; i++) {
v = i ? e->v2 : e->v1;
@ -1051,9 +1054,8 @@ static void *bmw_EdgeLoopWalker_step(BMWalker *walker)
vert_edge_tot = BM_vert_edge_count_nonwire(v);
/* Typical loopiong over edges in the middle of a mesh */
/* However, why use 2 here at all?
* I guess for internal ngon loops it can be useful. Antony R. */
/* Typical looping over edges in the middle of a mesh.
* Why use 2 here at all? - for internal ngon loops it can be useful. */
if (ELEM(vert_edge_tot, 4, 2)) {
int i_opposite = vert_edge_tot / 2;
int i = 0;
@ -1094,15 +1096,15 @@ static void *bmw_EdgeLoopWalker_step(BMWalker *walker)
vert_edge_tot = BM_vert_edge_count_nonwire(v);
/* check if we should step, this is fairly involved */
/* Check if we should step, this is fairly involved. */
if (
/* walk over boundary of faces but stop at corners */
/* Walk over boundary of faces but stop at corners. */
(owalk.is_single == false && vert_edge_tot > 2) ||
/* initial edge was a boundary, so is this edge and vertex is only a part of this face
* this lets us walk over the boundary of an ngon which is handy */
/* Initial edge was a boundary, so is this edge and vertex is only a part of this face
* this lets us walk over the boundary of an ngon which is handy. */
(owalk.is_single == true && vert_edge_tot == 2 && BM_edge_is_boundary(e))) {
/* find next boundary edge in the fan */
/* Find next boundary edge in the fan. */
do {
l = BM_loop_other_edge_loop(l, v);
if (BM_edge_is_manifold(l->e)) {
@ -1148,14 +1150,16 @@ static void *bmw_EdgeLoopWalker_step(BMWalker *walker)
*
* Starts at a tool-flagged face and walks over the face loop
* Conditions for starting and stepping the face loop have been
* tuned in an attempt to match the face loops built by EditMesh
* tuned in an attempt to match the face loops built by edit-mesh
* \{ */
/* Check whether the face loop should includes the face specified
* by the given BMLoop */
/**
* Check whether the face loop should includes the face specified
* by the given #BMLoop.
*/
static bool bmw_FaceLoopWalker_include_face(BMWalker *walker, BMLoop *l)
{
/* face must have degree 4 */
/* Face must have degree 4. */
if (l->f->len != 4) {
return false;
}
@ -1164,7 +1168,7 @@ static bool bmw_FaceLoopWalker_include_face(BMWalker *walker, BMLoop *l)
return false;
}
/* the face must not have been already visited */
/* The face must not have been already visited. */
if (BLI_gset_haskey(walker->visit_set, l->f) && BLI_gset_haskey(walker->visit_set_alt, l->e)) {
return false;
}
@ -1172,23 +1176,22 @@ static bool bmw_FaceLoopWalker_include_face(BMWalker *walker, BMLoop *l)
return true;
}
/* Check whether the face loop can start from the given edge */
/* Check whether the face loop can start from the given edge. */
static bool bmw_FaceLoopWalker_edge_begins_loop(BMWalker *walker, BMEdge *e)
{
/* There is no face loop starting from a wire edge */
/* There is no face loop starting from a wire edge. */
if (BM_edge_is_wire(e)) {
return false;
}
/* Don't start a loop from a boundary edge if it cannot
* be extended to cover any faces */
/* Don't start a loop from a boundary edge if it cannot be extended to cover any faces. */
if (BM_edge_is_boundary(e)) {
if (!bmw_FaceLoopWalker_include_face(walker, e->l)) {
return false;
}
}
/* Don't start a face loop from non-manifold edges */
/* Don't start a face loop from non-manifold edges. */
if (!BM_edge_is_manifold(e)) {
return false;
}
@ -1212,7 +1215,7 @@ static void bmw_FaceLoopWalker_begin(BMWalker *walker, void *data)
lwalk->no_calc = false;
BLI_gset_insert(walker->visit_set, lwalk->l->f);
/* rewind */
/* Rewind. */
while ((owalk_pt = BMW_current_state(walker))) {
owalk = *((BMwFaceLoopWalker *)owalk_pt);
BMW_walk(walker);
@ -1277,7 +1280,7 @@ static void *bmw_FaceLoopWalker_step(BMWalker *walker)
lwalk->no_calc = false;
}
/* both may already exist */
/* Both may already exist. */
BLI_gset_add(walker->visit_set_alt, l->e);
BLI_gset_add(walker->visit_set, l->f);
}
@ -1312,7 +1315,7 @@ static void bmw_EdgeringWalker_begin(BMWalker *walker, void *data)
BLI_gset_insert(walker->visit_set, lwalk->l->e);
/* rewind */
/* Rewind. */
while ((owalk_pt = BMW_current_state(walker))) {
owalk = *((BMwEdgeringWalker *)owalk_pt);
BMW_walk(walker);
@ -1370,10 +1373,10 @@ static void *bmw_EdgeringWalker_step(BMWalker *walker)
e = l->e;
if (!EDGE_CHECK(e)) {
/* walker won't traverse to a non-manifold edge, but may
/* Walker won't traverse to a non-manifold edge, but may
* be started on one, and should not traverse *away* from
* a non-manifold edge (non-manifold edges are never in an
* edge ring with manifold edges */
* edge ring with manifold edges. */
return e;
}
@ -1394,7 +1397,7 @@ static void *bmw_EdgeringWalker_step(BMWalker *walker)
i -= 2;
}
}
/* only walk to manifold edge */
/* Only walk to manifold edge. */
if ((l->f->len % 2 == 0) && EDGE_CHECK(l->e) && !BLI_gset_haskey(walker->visit_set, l->e))
#else
@ -1404,7 +1407,7 @@ static void *bmw_EdgeringWalker_step(BMWalker *walker)
if ((l->f->len != 4) || !EDGE_CHECK(l->e) || !bmw_mask_check_face(walker, l->f)) {
l = owalk.l->next->next;
}
/* only walk to manifold edge */
/* Only walk to manifold edge. */
if ((l->f->len == 4) && EDGE_CHECK(l->e) && !BLI_gset_haskey(walker->visit_set, l->e))
#endif
{
@ -1547,8 +1550,8 @@ static void *bmw_UVEdgeWalker_step(BMWalker *walker)
return l;
}
/* go over loops around l->v and nl->v and see which ones share l and nl's
* mloopuv's coordinates. in addition, push on l->next if necessary */
/* Go over loops around `l->v` and `l->next->v` and see which ones share `l` and `l->next`
* UV's coordinates. in addition, push on `l->next` if necessary. */
for (i = 0; i < 2; i++) {
BMIter liter;
BMLoop *l_pivot, *l_radial;
@ -1600,7 +1603,7 @@ static BMWalker bmw_VertShellWalker_Type = {
bmw_VertShellWalker_yield,
sizeof(BMwShellWalker),
BMW_BREADTH_FIRST,
BM_EDGE, /* valid restrict masks */
BM_EDGE, /* Valid restrict masks. */
};
static BMWalker bmw_LoopShellWalker_Type = {
@ -1610,7 +1613,7 @@ static BMWalker bmw_LoopShellWalker_Type = {
bmw_LoopShellWalker_yield,
sizeof(BMwLoopShellWalker),
BMW_BREADTH_FIRST,
BM_EDGE, /* valid restrict masks */
BM_EDGE, /* Valid restrict masks. */
};
static BMWalker bmw_LoopShellWireWalker_Type = {
@ -1620,7 +1623,7 @@ static BMWalker bmw_LoopShellWireWalker_Type = {
bmw_LoopShellWireWalker_yield,
sizeof(BMwLoopShellWireWalker),
BMW_BREADTH_FIRST,
BM_EDGE, /* valid restrict masks */
BM_EDGE, /* Valid restrict masks. */
};
static BMWalker bmw_FaceShellWalker_Type = {
@ -1630,7 +1633,7 @@ static BMWalker bmw_FaceShellWalker_Type = {
bmw_FaceShellWalker_yield,
sizeof(BMwShellWalker),
BMW_BREADTH_FIRST,
BM_EDGE, /* valid restrict masks */
BM_EDGE, /* Valid restrict masks. */
};
static BMWalker bmw_IslandboundWalker_Type = {
@ -1640,7 +1643,7 @@ static BMWalker bmw_IslandboundWalker_Type = {
bmw_IslandboundWalker_yield,
sizeof(BMwIslandboundWalker),
BMW_DEPTH_FIRST,
BM_FACE, /* valid restrict masks */
BM_FACE, /* Valid restrict masks. */
};
static BMWalker bmw_IslandWalker_Type = {
@ -1650,17 +1653,17 @@ static BMWalker bmw_IslandWalker_Type = {
bmw_IslandWalker_yield,
sizeof(BMwIslandWalker),
BMW_BREADTH_FIRST,
BM_EDGE | BM_FACE, /* valid restrict masks */
BM_EDGE | BM_FACE, /* Valid restrict masks. */
};
static BMWalker bmw_IslandManifoldWalker_Type = {
BM_FACE,
bmw_IslandWalker_begin,
bmw_IslandManifoldWalker_step, /* only difference with BMW_ISLAND */
bmw_IslandManifoldWalker_step, /* Only difference with #BMW_ISLAND. */
bmw_IslandWalker_yield,
sizeof(BMwIslandWalker),
BMW_BREADTH_FIRST,
BM_EDGE | BM_FACE, /* valid restrict masks */
BM_EDGE | BM_FACE, /* Valid restrict masks. */
};
static BMWalker bmw_EdgeLoopWalker_Type = {
@ -1671,7 +1674,7 @@ static BMWalker bmw_EdgeLoopWalker_Type = {
sizeof(BMwEdgeLoopWalker),
BMW_DEPTH_FIRST,
0,
/* valid restrict masks */ /* could add flags here but so far none are used */
/* Valid restrict masks. */ /* Could add flags here but so far none are used. */
};
static BMWalker bmw_FaceLoopWalker_Type = {
@ -1682,7 +1685,7 @@ static BMWalker bmw_FaceLoopWalker_Type = {
sizeof(BMwFaceLoopWalker),
BMW_DEPTH_FIRST,
0,
/* valid restrict masks */ /* could add flags here but so far none are used */
/* Valid restrict masks. */ /* Could add flags here but so far none are used. */
};
static BMWalker bmw_EdgeringWalker_Type = {
@ -1692,7 +1695,7 @@ static BMWalker bmw_EdgeringWalker_Type = {
bmw_EdgeringWalker_yield,
sizeof(BMwEdgeringWalker),
BMW_DEPTH_FIRST,
BM_EDGE, /* valid restrict masks */
BM_EDGE, /* Valid restrict masks. */
};
static BMWalker bmw_EdgeboundaryWalker_Type = {
@ -1712,7 +1715,7 @@ static BMWalker bmw_UVEdgeWalker_Type = {
bmw_UVEdgeWalker_yield,
sizeof(BMwUVEdgeWalker),
BMW_DEPTH_FIRST,
BM_EDGE, /* valid restrict masks */
BM_EDGE, /* Valid restrict masks. */
};
static BMWalker bmw_ConnectedVertexWalker_Type = {
@ -1722,23 +1725,23 @@ static BMWalker bmw_ConnectedVertexWalker_Type = {
bmw_ConnectedVertexWalker_yield,
sizeof(BMwConnectedVertexWalker),
BMW_BREADTH_FIRST,
BM_VERT, /* valid restrict masks */
BM_VERT, /* Valid restrict masks. */
};
BMWalker *bm_walker_types[] = {
&bmw_VertShellWalker_Type, /* BMW_VERT_SHELL */
&bmw_LoopShellWalker_Type, /* BMW_LOOP_SHELL */
&bmw_LoopShellWireWalker_Type, /* BMW_LOOP_SHELL_WIRE */
&bmw_FaceShellWalker_Type, /* BMW_FACE_SHELL */
&bmw_EdgeLoopWalker_Type, /* BMW_EDGELOOP */
&bmw_FaceLoopWalker_Type, /* BMW_FACELOOP */
&bmw_EdgeringWalker_Type, /* BMW_EDGERING */
&bmw_EdgeboundaryWalker_Type, /* BMW_EDGEBOUNDARY */
&bmw_UVEdgeWalker_Type, /* BMW_LOOPDATA_ISLAND */
&bmw_IslandboundWalker_Type, /* BMW_ISLANDBOUND */
&bmw_IslandWalker_Type, /* BMW_ISLAND */
&bmw_IslandManifoldWalker_Type, /* BMW_ISLAND_MANIFOLD */
&bmw_ConnectedVertexWalker_Type, /* BMW_CONNECTED_VERTEX */
&bmw_VertShellWalker_Type, /* #BMW_VERT_SHELL */
&bmw_LoopShellWalker_Type, /* #BMW_LOOP_SHELL */
&bmw_LoopShellWireWalker_Type, /* #BMW_LOOP_SHELL_WIRE */
&bmw_FaceShellWalker_Type, /* #BMW_FACE_SHELL */
&bmw_EdgeLoopWalker_Type, /* #BMW_EDGELOOP */
&bmw_FaceLoopWalker_Type, /* #BMW_FACELOOP */
&bmw_EdgeringWalker_Type, /* #BMW_EDGERING */
&bmw_EdgeboundaryWalker_Type, /* #BMW_EDGEBOUNDARY */
&bmw_UVEdgeWalker_Type, /* #BMW_LOOPDATA_ISLAND */
&bmw_IslandboundWalker_Type, /* #BMW_ISLANDBOUND */
&bmw_IslandWalker_Type, /* #BMW_ISLAND */
&bmw_IslandManifoldWalker_Type, /* #BMW_ISLAND_MANIFOLD */
&bmw_ConnectedVertexWalker_Type, /* #BMW_CONNECTED_VERTEX */
};
const int bm_totwalkers = ARRAY_SIZE(bm_walker_types);