Exemplo n.º 1
0
        private void _flowWater(Watershed newCell, Watershed oldCell)
        {
            if (oldCell == null)
            {
                _flowWater(Grid.First(c => c.Coordinate == newCell.FlowCoordinate), newCell);
            }

            else if (!newCell.IsIdentified && !oldCell.IsIdentified)
            {
                if (!oldCell.IsSink)
                {
                    _flowWater(Grid.First(c => c.Coordinate == newCell.FlowCoordinate), newCell);
                }
                else
                {
                    oldCell.Identifier = IDENTIFIERS[CURRENT_IDENTIFIER_INDEX++];
                }

                oldCell.Identifier = newCell.Identifier;
            }
            else if (!newCell.IsIdentified && oldCell.IsIdentified)
            {
                newCell.Identifier = oldCell.Identifier;
                if (!newCell.IsSink)
                {
                    _flowWater(Grid.First(c => c.Coordinate == newCell.FlowCoordinate), newCell);
                }
            }
            else if (newCell.IsIdentified && !oldCell.IsIdentified)
            {
                oldCell.Identifier = newCell.Identifier;
            }
        }
Exemplo n.º 2
0
        private Point _getFlowCoordinate(Watershed cell, IEnumerable <Point> neighbors)
        {
            if (neighbors.Count() == 0)
            {
                return(cell.Coordinate);
            }

            int minValue = neighbors.Min(p => Grid.FirstOrDefault(c => c.Coordinate == p).Value);

            if (minValue >= cell.Value)
            {
                return(cell.Coordinate);
            }

            var eligableNeighbors = neighbors.Where(p => Grid.First(c => c.Coordinate == p).Value == minValue);

            //Eligable cells == 1
            if (eligableNeighbors.Count() == 1)
            {
                return(eligableNeighbors.First());
            }

            //Eligable cells > 1
            //North
            if (eligableNeighbors.Any(p => p.Y == cell.Coordinate.Y - 1))
            {
                return(eligableNeighbors.First(p => p.Y == cell.Coordinate.Y - 1));
            }
            //West
            if (eligableNeighbors.Any(p => p.X == cell.Coordinate.X - 1))
            {
                return(eligableNeighbors.First(p => p.X == cell.Coordinate.X - 1));
            }
            //East
            if (eligableNeighbors.Any(p => p.X == cell.Coordinate.X + 1))
            {
                return(eligableNeighbors.First(p => p.X == cell.Coordinate.X + 1));
            }
            //South
            if (eligableNeighbors.Any(p => p.Y == cell.Coordinate.Y + 1))
            {
                return(eligableNeighbors.First(p => p.Y == cell.Coordinate.Y + 1));
            }

            return(new Point(-1, -1));
        }