Ejemplo n.º 1
0
        /// <summary>
        /// Run one iteration of a dijkstra map update.  Each cell is set to the lowest
        /// adjacent value - 1.
        /// </summary>
        /// <param name="dMap"></param>
        /// <param name="blockedValue"></param>
        /// <returns></returns>
        public static bool IterateDijkstraMap(this ICellMap <int> dMap, int blockedValue = -1)
        {
            bool changed = false;

            for (int i = 0; i < dMap.CellCount; i++)
            {
                int cellValue = dMap[i];
                if (cellValue != blockedValue)
                {
                    int lowestValue = cellValue;
                    for (int ai = 0; ai <= dMap.AdjacencyCount(i); ai++)
                    {
                        int adjacentCellIndex = dMap.AdjacentCellIndex(i, ai);
                        if (dMap.Exists(adjacentCellIndex))
                        {
                            int adjacentValue = dMap[adjacentCellIndex];
                            if (adjacentValue < lowestValue)
                            {
                                lowestValue = adjacentValue;
                            }
                        }
                    }
                    if (lowestValue < cellValue - 1)
                    {
                        dMap[i] = lowestValue + 1;
                        changed = true;
                    }
                }
            }
            return(changed);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Get the cell adjacent to the cell with the specified
 /// index in the specified direction.
 /// </summary>
 /// <param name="cellIndex">The index of the starting cell</param>
 /// <param name="direction">The direction of the cell to retrieve</param>
 /// <returns></returns>
 public static T AdjacentCell <T>(this ICellMap <T> map, int cellIndex, Vector direction)
 {
     if (map.Exists(cellIndex))
     {
         int i = map.AdjacentCellIndex(cellIndex, direction);
         if (map.Exists(i))
         {
             return(map[i]);
         }
     }
     return(default(T));
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Get the specified adjacent cell to the specified cell
 /// </summary>
 /// <param name="cellIndex">The index of the starting cell</param>
 /// <param name="adjacencyIndex">The adjacency index of the cell to retrieve</param>
 /// <returns></returns>
 public static T AdjacentCell <T>(this ICellMap <T> map, int cellIndex, int adjacencyIndex)
 {
     if (map.Exists(cellIndex))
     {
         int i = map.AdjacentCellIndex(cellIndex, adjacencyIndex);
         if (map.Exists(i))
         {
             return(map[i]);
         }
     }
     return(default(T));
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Retrieve a list of all cells adjacent to the one with the specified index
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="map"></param>
        /// <param name="cellIndex"></param>
        /// <returns></returns>
        public static IList <T> AdjacentCells <T>(this ICellMap <T> map, int cellIndex)
        {
            int aC     = map.AdjacencyCount(cellIndex);
            var result = new List <T>(aC);

            for (int i = 0; i < aC; i++)
            {
                int iA = map.AdjacentCellIndex(cellIndex, i);
                if (map.Exists(iA))
                {
                    result.Add(map[iA]);
                }
            }
            return(result);
        }