Пример #1
0
    public TryFunc <Face, IEnumerable <TaggedEdge <Face, Edge> > > CreateGraph()
    {
        // select edges of boundary faces
        var edges = _grid.GetEdges().Where(e => e.ClimbableFaces.Length == 2);

        // create graph from edges -- library quickgraph
        var graphEdges = edges.Select(e => new TaggedEdge <Face, Edge>(e.ClimbableFaces[0], e.ClimbableFaces[1], e));
        var graph      = graphEdges.ToUndirectedGraph <Face, TaggedEdge <Face, Edge> >();

        // start face for shortest path
        var start = _grid.Faces[1][0, 0, 0];

        //var start2 = _grid.GetVoxelAt(_grid.Blocks[0].ZeroIndex).Faces.Last(f => f != null && f.Climable);

        // calculate shortest path from start face to all boundary faces
        return(graph.ShortestPathsDijkstra(e => 1.0, start));
    }