public void TestFillBasicBoundary() { Map map = new Map(2, 2); map.SetTerrain(1, 0, maskTerrain); Rectangle expectedRect = new Rectangle(0, 0, 2, 2); Rectangle rect = map.Fill(0, 1, fillTerrain); HashSet<PointI2D> fillBoundary = map.FillBoundary; // diagonal fill boundary Assert.AreEqual(2, fillBoundary.Count); }
public void TestBasicFill() { Map map = new Map(2, 2); Rectangle expectedRect = new Rectangle(0, 0, 2, 2); Rectangle rect = map.Fill(0, 1, fillTerrain); Assert.AreEqual(expectedRect, rect); foreach (Terrain terrain in map.GetTerrainData()) { Assert.AreEqual(fillTerrain, terrain); } }
public void TestLargeFill() { Map map = new Map(50, 100); Rectangle expectedRect = new Rectangle(0, 0, 50, 100); Rectangle rect = map.Fill(5, 5, fillTerrain); Assert.AreEqual(expectedRect, rect); foreach (Terrain terrain in map.GetTerrainData()) { Assert.AreEqual(fillTerrain, terrain); } }
public void TestSimpleMaskFill() { Map map = new Map(2, 2); map.SetTerrain(1, 0, maskTerrain); Rectangle expectedRect = new Rectangle(0, 0, 2, 2); Rectangle rect = map.Fill(0, 1, fillTerrain); Assert.AreEqual(expectedRect, rect); Assert.AreEqual(maskTerrain, map.GetTerrain(1, 0)); Assert.AreEqual(fillTerrain, map.GetTerrain(1, 1)); Assert.AreEqual(fillTerrain, map.GetTerrain(0, 0)); }
private void AddTextItem() { double offset = MapScrollViewer.ActualWidth - MapCanvas.ActualWidth; if (offset > 0) offset /= 2; else offset = 0; double offsetX = MapScrollViewer.HorizontalOffset - offset; offset = MapScrollViewer.ActualHeight - MapCanvas.ActualHeight; if (offset > 0) offset /= 2; else offset = 0; double offsetY = MapScrollViewer.VerticalOffset - offset; Thickness padding = LabelTextBox.Padding; Thickness border = LabelTextBox.BorderThickness; Rectangle r = new Rectangle() { X = LabelTextBox.Margin.Left + offsetX + padding.Left + border.Left, Y = LabelTextBox.Margin.Top + offsetY + padding.Top + border.Top, Width = LabelTextBox.ActualWidth, Height = LabelTextBox.ActualHeight }; Core.TextBlock text = new Core.TextBlock(LabelTextBox.Margin.Left, LabelTextBox.Margin.Top); text.Text = LabelTextBox.Text; text.Bounds = r; text.FontSize = activeTextFormat.FontSize; text.FontFamily = activeTextFormat.FontFamily; map.AddText(text); mapViewFeaturesTree.Add(text); Rect rect = new Rect(r.X, r.Y, r.Width, r.Height); MapCanvas.Invalidate(rect); }
public bool Contains(Rectangle rect) { return rect.X >= X && rect.Y >= Y && rect.Right <= Right && rect.Bottom <= Bottom; }
/// <summary> /// Fills a region with the defined boundary. /// </summary> /// <param name="boundary"></param> /// <param name="fillTerrain"></param> /// <returns></returns> public Rectangle Fill(int x, int y, HashSet<PointI2D> boundary, Terrain fillTerrain) { fillBoundary = new HashSet<PointI2D>(); // reset the fill fields fillBounds = new Rectangle(x, y, 1, 1); Terrain matchTerrain = null; if (x >= 0 && y >= 0) matchTerrain = GetTerrain(x, y); else return fillBounds; // fill if terrain is not equal to terrain in selected tile if (matchTerrain != fillTerrain) { Stack<Tile> fillStack = new Stack<Tile>(); Tile fillTile = new Tile(x, y); fillTile.Terrain = matchTerrain; fillStack.Push(fillTile); SetTerrain(x, y, fillTerrain); while (fillStack.Count != 0) { Tile currentTile = fillStack.Pop(); currentTile.Terrain = fillTerrain; // North if (currentTile.Y > 0) { FillTile(currentTile, matchTerrain, fillTerrain, fillStack, currentTile.X, currentTile.Y - 1); } // East if (currentTile.X < Width - 1) { FillTile(currentTile, matchTerrain, fillTerrain, fillStack, currentTile.X + 1, currentTile.Y); } // South if (currentTile.Y < height - 1) { FillTile(currentTile, matchTerrain, fillTerrain, fillStack, currentTile.X, currentTile.Y + 1); } // West if (currentTile.X > 0) { FillTile(currentTile, matchTerrain, fillTerrain, fillStack, currentTile.X - 1, currentTile.Y); } } } return fillBounds; }
public static Rect AsRect(Rectangle rect) { return new Rect(rect.X, rect.Y, rect.Width, rect.Height); }