コード例 #1
0
 private void AddItems(CircularBinaryGrid <string> grid, IntRectangle rect)
 {
     for (var x = rect.Left; x < rect.Right; x++)
     {
         for (var y = rect.Top; y < rect.Bottom; y++)
         {
             AddItem(grid, new IntVector(x, y, 0));
         }
     }
 }
コード例 #2
0
 public Grid(int id, ICoordinateSystem coordinateSystem)
 {
     Id = id;
     CoordinateSystem = coordinateSystem;
     InnerGrid        = new CircularBinaryGrid <Block>(new CoordinateSystem(
                                                           coordinateSystem.MinX / Constants.BlockSize,
                                                           coordinateSystem.MaxX / Constants.BlockSize,
                                                           coordinateSystem.MinY / Constants.BlockSize,
                                                           coordinateSystem.MaxY / Constants.BlockSize,
                                                           coordinateSystem.MinZ / Constants.BlockSize,
                                                           coordinateSystem.MaxZ / Constants.BlockSize));
 }
コード例 #3
0
        public void Test1()
        {
            var coordinateSystem = CoordinateSystem.CreateHorizontalCircular(0, 10);
            var grid             = new CircularBinaryGrid <string>(coordinateSystem);
            var rect             = new IntRectangle(0, 0, 0, 2, 2, 1);
            var calls            = new Dictionary <IntVector, string>();
            EnumerateItemDelegate <string> func = (item, position) => calls.Add(position, item);

            AddItems(grid, new IntRectangle(-1, -1, 0, 4, 4, 1));

            grid.ForEachWithin(rect, func);

            Assert.AreEqual(4, calls.Count);
            AssertItem(calls, new IntVector(0, 0, 0));
            AssertItem(calls, new IntVector(1, 0, 0));
            AssertItem(calls, new IntVector(0, 1, 0));
            AssertItem(calls, new IntVector(1, 1, 0));
        }
コード例 #4
0
        public void TestEnumerateAll()
        {
            var coordinateSystem = CoordinateSystem.CreateHorizontalCircular(0, 16);
            var grid             = new CircularBinaryGrid <string>(coordinateSystem);
            var calls            = new Dictionary <IntVector, string>();
            EnumerateItemDelegate <string> func = (item, position) =>
            {
                calls.Add(position, item);
            };

            AddItems(grid, new IntRectangle(0, 0, 0, 16, 16, 1));

            grid.ForEach(func);

            for (var x = 0; x < 16; x++)
            {
                for (var y = 0; y < 16; y++)
                {
                    AssertItem(calls, new IntVector(x, y, 0));
                }
            }
        }
コード例 #5
0
 private void AddItem(CircularBinaryGrid <string> grid, IntVector position)
 {
     grid.Set(position, grid.CoordinateSystem.Normalize(position).ToString());
 }