コード例 #1
0
        private void AddHorizEdges(PointF from, PointF to)
        {
            var fromX = Math.Min(from.X, to.X);
            var toX   = Math.Max(from.X, to.X);

            //find intersected edges
            var edges = AllElements.OfType <Edge>().Where(
                e => !e.IsHorisontal &&
                e.Node1.OriginalLocation.X >= fromX &&
                e.Node1.OriginalLocation.X <= toX &&
                e.Contains(new PointF(e.Node1.OriginalLocation.X, from.Y))
                ).OrderBy(e => e.Node1.OriginalLocation.X).ToArray();

            if (edges.Length < 2)
            {
                return;
            }

            Node prevNode = new Node(this, new PointF(edges[0].Node1.OriginalLocation.X, from.Y));

            DivideEdge(edges[0], prevNode);
            for (int i = 1; i < edges.Length; i++)
            {
                Node node = new Node(this, new PointF(edges[i].Node1.OriginalLocation.X, from.Y));
                DivideEdge(edges[i], node);
                new Edge(prevNode, node);
                prevNode = node;
            }
        }
コード例 #2
0
        bool RemoveFreeEdges()
        {
            bool removed = false;
            bool result  = false;

            do
            {
                removed = false;

                foreach (var e in AllElements.OfType <Edge>().ToArray())
                {
                    if (e.Node1.Edges.Count == 1 || e.Node2.Edges.Count == 1)
                    {
                        //remove edge
                        e.Node1.Edges.Remove(e);
                        e.Node2.Edges.Remove(e);
                        removed = true;
                        result  = true;
                    }
                }
            } while (removed);

            return(result);
        }