public virtual void MergeEdges(Vertex middleVertex) { List <Halfedge> edges = middleVertex.edges; Asserts.AssertThat(edges.Count == 2, "Vertex must has exactly two halfedges connecting to it."); RemoveVertexFromList(middleVertex); RemoveHalfedgeFromList(edges[0].opposite); RemoveHalfedgeFromList(edges[1].opposite); edges[0].vertex = edges[0].next.vertex; edges[1].vertex = edges[1].next.vertex; edges[0].vertex.edge = edges[0]; edges[1].vertex.edge = edges[1]; edges[0].next.next.prev = edges[0]; edges[1].next.next.prev = edges[1]; edges[0].next = edges[0].next.next; edges[1].next = edges[1].next.next; edges[0].opposite = edges[1]; edges[1].opposite = edges[0]; if (!edges[0].isBoundary) { edges[0].face.edge = edges[0]; } if (!edges[1].isBoundary) { edges[1].face.edge = edges[1]; } }
/// <summary> Merges two neighboring faces as one given one of their connecting halfedge. </summary> public virtual void MergeFaces(Halfedge edge) { Halfedge oppo = edge.opposite; Face face1 = edge.face; Face face2 = oppo.face; Asserts.AssertThat( (face1 != face2 && edge.next != oppo && edge.prev != oppo) || (face1 == face2 && (edge.next == oppo ^ edge.prev == oppo)), $"Merge will lead to non-valid geometry! face1 {(face1 == face2 ? "==" : "!=")} face2, edge.next {(edge.next == oppo ? "==" : "!=")} oppo, edge.prev {(edge.prev == oppo ? "==" : "!=")} oppo."); if (face1 != face2) { face2.edges.ForEach(e => e.face = face1); RemoveFaceFromList(face2); } face1.edge = edge.next != oppo ? edge.next : edge.prev; if (edge.next != oppo) { edge.next.prev = oppo.prev; oppo.prev.next = edge.next; edge.vertex.edge = oppo.prev; } else { RemoveVertexFromList(edge.vertex); } if (oppo.next != edge) { oppo.next.prev = edge.prev; edge.prev.next = oppo.next; oppo.vertex.edge = edge.prev; } else { RemoveVertexFromList(oppo.vertex); } RemoveHalfedgeFromList(edge); RemoveHalfedgeFromList(oppo); }