Esempio n. 1
0
        public void Report_ManyRandomElements_ShouldCorrectlyReturnAllCandidateColliders()
        {
            const int ObjectsCount = 1000;

            var shepard = new TestBox(10, 20);
            var random  = new Random();
            var list    = new List <TestBox>();

            list.Add(shepard);
            quadTree.Insert(shepard);
            for (int i = 0; i < ObjectsCount; i++)
            {
                var x   = random.Next(0, WorldWidth - 10);
                var y   = random.Next(0, WorldHeight - 10);
                var obj = new TestBox(x, y);
                list.Add(obj);
                quadTree.Insert(obj);
            }

            var listCollisions = PerformCollisionSearchList(shepard, list)
                                 .OrderBy(e => e)
                                 .ToList();
            var quadTreeCollisions = PerformCollisionSearchQuadTree(shepard, quadTree)
                                     .OrderBy(e => e)
                                     .ToList();

            CollectionAssert.AreEqual(quadTreeCollisions, listCollisions);
        }
Esempio n. 2
0
        static List <TestBox> PerformCollisionSearchList(
            TestBox obj, List <TestBox> list)
        {
            var result = new List <TestBox>();

            //Console.WriteLine(list.Count);
            for (int i = 0; i < list.Count; i++)
            {
                if (obj.Bounds.Intersects(list[i].Bounds) &&
                    obj != list[i])
                {
                    result.Add(list[i]);
                }
            }

            return(result);
        }
Esempio n. 3
0
        static List <TestBox> PerformCollisionSearchQuadTree(
            TestBox obj, QuadTree <TestBox> quadTree)
        {
            var result = new List <TestBox>();
            var collisionCandidates = quadTree.Report(obj.Bounds).ToList();

            //Console.WriteLine(collisionCandidates.Count);
            for (int i = 0; i < collisionCandidates.Count; i++)
            {
                if (obj.Bounds.Intersects(collisionCandidates[i].Bounds) &&
                    obj != collisionCandidates[i])
                {
                    result.Add(collisionCandidates[i]);
                }
            }

            return(result);
        }