/// <summary> /// Generates list of textures for given square, when left bottom corner is provided. /// </summary> /// <param name="lbx"></param> /// <param name="lby"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <returns>Sequence contains textures, starting from left bottom corner and returning rows first.</returns> public IEnumerable <PointContext> GetWindow(int lbx, int lby, int dx, int dy) { for (int y = 0; y < dy; y++) { for (int x = 0; x < dx; x++) { var geox = lbx + x; var geoy = lby + y; var area = new LocationType[9]; var centerOfArea = new GeoPoint(geox, geoy); for (int i = 0; i < 9; i++) { area[i] = LocationType.Water; } area[Directions.NeighborTopLeft] = points.ContainsKey(centerOfArea.TopLeft()) ? points[centerOfArea.TopLeft()] : LocationType.Water; area[Directions.NeighborNorth] = points.ContainsKey(centerOfArea.Top()) ? points[centerOfArea.Top()] : LocationType.Water; area[Directions.NeighborTopRight] = points.ContainsKey(centerOfArea.TopRight()) ? points[centerOfArea.TopRight()] : LocationType.Water; area[Directions.NeighborWest] = points.ContainsKey(centerOfArea.Left()) ? points[centerOfArea.Left()] : LocationType.Water; area[Directions.NeighborThis] = points.ContainsKey(centerOfArea) ? points[centerOfArea] : LocationType.Water; area[Directions.NeighborEast] = points.ContainsKey(centerOfArea.Right()) ? points[centerOfArea.Right()] : LocationType.Water; area[Directions.NeighborDownLeft] = points.ContainsKey(centerOfArea.DownLeft()) ? points[centerOfArea.DownLeft()] : LocationType.Water; area[Directions.NeighborSouth] = points.ContainsKey(centerOfArea.Down()) ? points[centerOfArea.Down()] : LocationType.Water; area[Directions.NeighborDownRight] = points.ContainsKey(centerOfArea.DownRight()) ? points[centerOfArea.DownRight()] : LocationType.Water; var centerTexture = new TextureHolder(); var handled = false; foreach (var strategy in functionStrategies) { var texture = strategy(area, centerTexture); if (texture == centerTexture) { continue; } centerTexture = texture; handled = true; break; } if (!handled) { foreach (var strategy in strategies) { if (!strategy.CanExecute(area)) { continue; } centerTexture = strategy.Execute(area); handled = true; break; } } if (!handled) { centerTexture = fallbackStrategy.Execute(area); } yield return(new PointContext(centerOfArea, centerTexture)); } } }