Beispiel #1
0
        public void CollectFromQuadTree(int worldScale)
        {
            var tree = new QuadTree <string>(worldScale);

            var added = new List <string>()
            {
                "-8,0",
                "-5,0",
                "0,0",
                "5,0",
                "8,0"
            };

            tree.AddItem(added[0], new Vector2r(-8, 0));
            tree.AddItem(added[1], new Vector2r(-5, 0));
            tree.AddItem(added[2], new Vector2r(0, 0));
            tree.AddItem(added[3], new Vector2r(5, 0));
            tree.AddItem(added[4], new Vector2r(8, 0));

            // collect everything (both positive and negative)
            {
                List <string> everything = tree.CollectItems <List <string> >(new Bound(0, 0, 200));
                Assert.Equal(5, everything.Count);
                Assert.Contains(added[0], everything);
                Assert.Contains(added[1], everything);
                Assert.Contains(added[2], everything);
                Assert.Contains(added[3], everything);
                Assert.Contains(added[4], everything);
            }

            // collection a positive region
            {
                var positiveOnly = tree.CollectItems <List <string> >(new Bound(5, 0, 4));
                Assert.Equal(2, positiveOnly.Count);
                Assert.Contains(added[3], positiveOnly);
                Assert.Contains(added[4], positiveOnly);
            }

            // collect a negative region
            {
                var negativeOnly = tree.CollectItems <List <string> >(new Bound(-5, 0, 4));
                Assert.Equal(2, negativeOnly.Count);
                Assert.Contains(added[0], negativeOnly);
                Assert.Contains(added[1], negativeOnly);
            }

            // collect an empty region
            {
                var nothing = tree.CollectItems <List <string> >(new Bound(100, 0, 5));
                Assert.Empty(nothing);
            }
        }