Пример #1
0
        public IReadOnlyList <Node> FindRoute(int startNodeId, int endNodeId)
        {
            var previousNodes = FindAllPaths(startNodeId);

            // Walk the shortest path backwards
            var path        = new List <Node>();
            var reachedNode = _mapProvider.GetNode(endNodeId);

            do
            {
                path.Add(reachedNode);
                reachedNode = previousNodes[reachedNode];
            } while (reachedNode.Id != startNodeId);

            path.Reverse();
            return(path);
        }
Пример #2
0
        public Stream Render()
        {
            var outputStream = new MemoryStream();

            using (var bitmap = new Bitmap(1080, 720))
            {
                using (var canvas = Drawing.Graphics.FromImage(bitmap))
                {
                    var distinctEdges   = GetDistinctEdges();
                    var regularPen      = new Pen(Color.White, 4f);
                    var highlightingPen = new Pen(Color.RoyalBlue, 4f);

                    canvas.FillRectangle(new SolidBrush(Color.Salmon), 0, 0, 1080, 720);

                    foreach (var edge in distinctEdges)
                    {
                        var node1 = _mapProvider.GetNode(edge.Node1);
                        var node2 = _mapProvider.GetNode(edge.Node2);

                        var end1 = GetPointOfNode(node1);
                        var end2 = GetPointOfNode(node2);

                        if (IsHighlightedEdge(edge))
                        {
                            canvas.DrawLine(highlightingPen, end1, end2);
                        }
                        else
                        {
                            canvas.DrawLine(regularPen, end1, end2);
                        }
                    }

                    canvas.Save();
                }
                bitmap.Save(outputStream, ImageFormat.Png);
                outputStream.Flush();
                outputStream.Position = 0;
            }

            return(outputStream);
        }