/// <summary> /// To return a RectangleChunk we will need the bounding box and a check for missing locations /// </summary> /// <returns></returns> public override HashSet<ChunkContainer> GetChunks(LocationPool locationPool) { HashSet<ChunkContainer> result = new HashSet<ChunkContainer>(); if (IsRectangle()) { MonoRectangleChunk rectangleChunk = new MonoRectangleChunk(); rectangleChunk.Origin = BoundingBox.UpperLeft; rectangleChunk.Width = BoundingBox.Width(); rectangleChunk.Height = BoundingBox.Height(); MonoRectangleChunkContainer container = new MonoRectangleChunkContainer(); container.Chunk = rectangleChunk; container.Locations = GetLocations(BoundingBox); //container.AdditionalSize = NewColorCount(locationPool.Palette); container.Color = Color; result.Add(container); return result; } //break up into many rectangles and return rest here HashSet<Location> locations = new HashSet<Location>(Locations); HashSet<BoundingBox> rectangles = GetAllRectangles(locations, BoundingBox); foreach (BoundingBox rectangle in rectangles) { MonoRectangleChunk rectangleChunk = new MonoRectangleChunk(); rectangleChunk.Origin = rectangle.UpperLeft; rectangleChunk.Width = rectangle.Width(); rectangleChunk.Height = rectangle.Height(); MonoRectangleChunkContainer container = new MonoRectangleChunkContainer(); container.Chunk = rectangleChunk; container.Color = Color; //container.AdditionalSize = NewColorCount(locationPool.Palette); container.Locations = GetLocations(rectangle); result.Add(container); } //now for the remaining locations, create monocolorchunks BoundingBox remaining = new BoundingBox(); foreach (Location location in locations) { remaining.Add(location.Point); } MonoBitPlaneChunk monoColorChunk = new MonoBitPlaneChunk(); monoColorChunk.Width = remaining.Width(); monoColorChunk.Height = remaining.Height(); monoColorChunk.Initialize(); monoColorChunk.Origin = remaining.UpperLeft; foreach (Location location in locations) { monoColorChunk.SetColor(location.Point.X, location.Point.Y); } MonoBitPlaneChunkContainer monoContainer = new MonoBitPlaneChunkContainer(); monoContainer.Chunk = monoColorChunk; monoContainer.Locations = GetLocations(remaining); monoContainer.Color = Color; result.Add(monoContainer); return result; }
public bool IsRectangle(HashSet<Location> locations, BoundingBox boundingBox) { bool[,] boolArray = new bool[boundingBox.Width(), boundingBox.Height()]; foreach (Location location in locations) { if (boundingBox.Contains(location.Point.X, location.Point.Y)) { boolArray[location.Point.X - boundingBox.UpperLeft.X, location.Point.Y - boundingBox.UpperLeft.Y] = true; } } for (int x = 0; x < boolArray.GetLength(0); x++) { for (int y = 0; y < boolArray.GetLength(1); y++) { if (!boolArray[x, y]) { return false; } } } return true; }