private void HandleMergeVertex(TVertex vertex) { #if DEBUG int hs = helpers.Count; #endif Debug.Assert(GetVertexType(vertex) == VertexType.Merge); // Deal with connections to the right of the above-incident vertices // Connect each above indicent edge to its helper, if that // helper was a merge vertex. And remove these above-incident edges // from the sweep line status (helpers). This is to complete the regularisation // of merge vertices encountered earlier in the sweep. var aboveEdges = meshUtilities.AboveEdges(vertex).ToList(); foreach (EdgeBase edge in aboveEdges) { if (helpers.ContainsKey(edge)) { TVertex helper = helpers[edge]; if (GetVertexType(helper) == VertexType.Merge) { DiagonalInserterDelegate(mesh, vertex, helper); } } } // Remove the above incident-edges from the sweep foreach (EdgeBase edge in aboveEdges) { bool removed = helpers.Remove(edge); Debug.Assert(removed); } // Deal with connections to the left of the above-incident vertices KeyValuePair <EdgeBase, TVertex>?directlyLeft = DirectlyLeftOf(sweeplineUtilities.RightMost(aboveEdges)); if (directlyLeft.HasValue) { if (helpers.ContainsKey(directlyLeft.Value.Key)) { TVertex helper1 = helpers[directlyLeft.Value.Key]; if (GetVertexType(helper1) == VertexType.Merge) { DiagonalInserterDelegate(mesh, vertex, helper1); } helpers[directlyLeft.Value.Key] = vertex; } } #if DEBUG // There should be no below edges from a merge-vertex var belowEdges = meshUtilities.BelowEdges(vertex); Debug.Assert(belowEdges.Count() == 0); Debug.Assert(helpers.Count == hs - aboveEdges.Count() + belowEdges.Count()); #endif }
/// <summary> /// Find the edges which are above-indicent to the given vertex and /// indicent to the face we are triangulating /// </summary> /// <param name="vertex"></param> /// <returns></returns> private IEnumerable <EdgeBase> AboveEdges(TVertex vertex) { return(meshUtilities.AboveEdges(vertex).Where(e => e.Faces.First == face || e.Faces.Second == face)); }