/// <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); }
/// <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); }