Ejemplo n.º 1
0
        /// <summary>
        /// Calculates routes for edges in a graph, so that they avoid nodes.
        /// </summary>
        public Dictionary <TEdge, RoutedEdge> RouteEdges <TEdge>(IEnumerable <IRect> nodes, IEnumerable <TEdge> edges)
            where TEdge : class, IEdge
        {
            var routeGraph    = RouteGraph.InitializeVertices(nodes, edges, 0, 0);
            var routedEdges   = new Dictionary <TEdge, RoutedEdge>();
            var occludedEdges = new List <TEdge>();

            foreach (var edge in edges)
            {
                var straightEdge = routeGraph.TryRouteEdgeStraight(edge);
                if (straightEdge != null)
                {
                    routedEdges[edge] = straightEdge;
                }
                else
                {
                    occludedEdges.Add(edge);
                }
            }
            if (occludedEdges.Count > 0)
            {
                // there are some edges that couldn't be routed as straight lines
                routeGraph.ComputeVisibilityGraph();
                foreach (var edge in occludedEdges)
                {
                    RoutedEdge routedEdge = routeGraph.RouteEdge(edge);
                    routedEdges[edge] = routedEdge;
                }
            }
            return(routedEdges);
        }
Ejemplo n.º 2
0
        public List <RoutedEdge> RouteEdges(IEnumerable <IRect> nodes, IEnumerable <IEdge> edges)
        {
            var routeGraph = RouteGraph.InitializeVertices(nodes, edges);
            List <RoutedEdge> routedEdges = new List <RoutedEdge>();
            var occludedEdges             = new List <IEdge>();

            foreach (IEdge edge in edges)
            {
                var straightEdge = routeGraph.TryRouteEdgeStraight(edge);
                if (straightEdge != null)
                {
                    routedEdges.Add(straightEdge);
                }
                else
                {
                    occludedEdges.Add(edge);
                }
            }
            if (occludedEdges.Count > 0)
            {
                // there are some edges that couldn't be routed as straight lines
                routeGraph.ComputeVisibilityGraph();
                foreach (IEdge edge in occludedEdges)
                {
                    RoutedEdge routedEdge = routeGraph.RouteEdge(edge);
                    routedEdges.Add(routedEdge);
                }
            }
            return(routedEdges);
        }