Esempio n. 1
0
 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);
 }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
        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));
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
 public bool Contains(Rectangle rect)
 {
     return rect.X >= X && rect.Y >= Y
         && rect.Right <= Right && rect.Bottom <= Bottom;
 }
Esempio n. 7
0
 /// <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;
 }
Esempio n. 8
0
 public static Rect AsRect(Rectangle rect)
 {
     return new Rect(rect.X, rect.Y, rect.Width, rect.Height);
 }