Ejemplo n.º 1
0
        public void FindAllCollisions()
        {
            var grid     = new CollisionGrid <GameObject>(-1, -1, 2, 2, 1, 1);
            var expected = new HashSet <(GameObject, GameObject)>();

            grid.FindAllCollisions((_, __) => Assert.Fail());
            var a = new GameObject(0, 0, 0.01f);

            grid.Add(a);
            grid.FindAllCollisions((_, __) => Assert.Fail());
            grid.Add(a);
            expected.Add((a, a));
            var result = new HashSet <(GameObject, GameObject)>();

            grid.FindAllCollisions((c1, c2) => Assert.AreEqual((a, a), (c1, c2)));
            grid.FindAllCollisions((c1, c2) => result.Add((c1, c2)));
            result.SymmetricExceptWith(expected);
            //Assert.AreEqual(expected, result);
            var b = new GameObject(1, 1, 0.01f);

            grid.Add(b);
            //grid.FindAllCollisions((c1, c2) => Assert.AreEqual((a, a), (c1, c2)));
            grid.Add(b);
            //grid.FindAllCollisions((c1, c2) => Assert.AreEqual((a, a), (c1, c2)));
        }
 public void CellCount()
 {
     for (int cellCountX = 1; cellCountX < 20; ++cellCountX)
     {
         for (int cellCountY = 1; cellCountY < 20; ++cellCountY)
         {
             var grid = new CollisionGrid <GameObject>(-1, -1, 2, 2, cellCountX, cellCountY);
             Assert.AreEqual(grid.CellCountX * grid.CellCountY, cellCountX * cellCountY);
         }
     }
 }
Ejemplo n.º 3
0
 public void CellCount()
 {
     for (uint cellCountX = 1u; cellCountX < 20; ++cellCountX)
     {
         for (uint cellCountY = 1u; cellCountY < 20; ++cellCountY)
         {
             var grid = new CollisionGrid <GameObject>(-1, -1, 2, 2, cellCountX, cellCountY);
             Assert.AreEqual((uint)grid.GetGrid().Length, cellCountX * cellCountY);
         }
     }
 }
        public void FindAllCollisionsSingleObject()
        {
            var grid = new CollisionGrid <GameObject>(-1, -1, 2, 2, 1, 1);

            grid.FindAllCollisions((_, __) => Assert.Fail());

            var a = new GameObject(0, 0, 0.01f);

            grid.Add(a);
            grid.FindAllCollisions((_, __) => Assert.Fail());

            grid.Add(a);
            grid.FindAllCollisions((c1, c2) => Assert.AreEqual((a, a), (c1, c2)));

            var expected = new HashSet <(ICollider, ICollider)> {
                (a, a)
            };
            var result = new HashSet <(ICollider, ICollider)>();

            grid.FindAllCollisions((c1, c2) => result.Add((c1, c2)));
            CollectionAssert.AreEqual(expected.ToList(), result.ToList());
        }