示例#1
0
        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
        }
        // TODO: This could be an iterator
        private List <ChainVertex> TraceRightAndDown(TVertex top)
        {
            TVertex                vertex = top;
            List <ChainVertex>     result = new List <ChainVertex>();
            IEnumerable <EdgeBase> belowEdges;

            while ((belowEdges = BelowEdges(vertex)).Count() > 0)
            {
                EdgeBase edge  = sweeplineUtilities.RightMost(belowEdges);
                TVertex  lower = meshUtilities.LowerVertex(edge);
                result.Add(new ChainVertex(lower, Chain.Right));
                vertex = lower;
            }
            return(result);
        }