EdgeMesh::Face* EdgeMesh::Face::DissolveEdge(Edge& edge, std::vector<Polygon>* newHoles) { assert(edge.twin); assert(edge.face == this); Face* otherFace = edge.twin->face == this ? nullptr : edge.twin->face; assert(IsValid()); if (otherFace) { assert(otherFace->IsValid()); AdoptEdgeLoop(*edge.twin); } Edge& oldPrev = *edge.prev; Edge& newNext = *edge.twin->next; Edge& newPrev = *edge.twin->prev; Edge& oldNext = *edge.next; oldPrev.ConnectTo(newNext); newPrev.ConnectTo(oldNext); m_edges.erase(FindEdge(*edge.twin)); m_edges.erase(FindEdge(edge)); if (!otherFace) { assert(newHoles); if (newHoles) { Face hole; hole.AdoptEdgeLoop(newPrev); if (hole.GetPolygon().IsCW()) // Got the wrong bit! swap(*this, hole); Polygon holePoly = hole.GetPolygon(); holePoly.MakeCW(); newHoles->push_back(holePoly); } } assert(IsValid()); return otherFace; }