compas icon indicating copy to clipboard operation
compas copied to clipboard

mesh_collapse_edge does not fully clear all halfedges involved

Open tkmmark opened this issue 2 years ago • 0 comments

form = Mesh()

form.add_vertex(x=0., y=0., z=0.)
form.add_vertex(x=10., y=0., z=0.)
form.add_vertex(x=10.,y=10., z=0.)
form.add_vertex(x=0., y=5., z=0.)
form.add_vertex(x=0., y=10., z=0.)

form.add_face([0, 1, 2])
form.add_face([0, 2, 3, 4])

# collapse edge
form.collapse_edge(3, 4, allow_boundary=True)

print('\nvertices: ', list(form.vertices()))
print('edges: ', list(form.edges()))
print('faces: ', list(form.face.items()))
print('halfedges:')
pprint(form.halfedge)

Current output: items that should be removed are marked by asterisks

vertices:  [0, 1, 2, 3]
edges:  [(0, 1), (0, 2), **(0, 4),** (1, 2), (2, 3), (3, 0)]
faces:  [(0, [0, 1, 2]), (1, [0, 2, 3])]
halfedges:
{0: {1: 0, 2: 1, **4: None**},
 1: {0: None, 2: 0},
 2: {0: 0, 1: None, 3: 1},
 3: {0: 1, 2: None}}

Suggested resolution: Insert the following code after line 161 in collapse.py so that the full if clause becomes:

    if fkey is None:
        del mesh.halfedge[v][u]
        hes_to_del = [(_u, _v) for _u, _vs in mesh.halfedge.items() 
                      for _v, _ in _vs.items() if _v == v]
        for _u, _v in hes_to_del:
            del mesh.halfedge[_u][_v]

tkmmark avatar Jul 18 '21 09:07 tkmmark