Ejemplo n.º 1
0
        public void TestMove()
        {
            var itemsAdded = new List <MySpatialMapItem>();

            var sm = new LayeredSpatialMap <MySpatialMapItem>(5);

            for (int i = 0; i < 5; i++)
            {
                var item = new MySpatialMapItem(i);
                itemsAdded.Add(item);
                sm.Add(item, (1, 2));
            }

            var lastItem = new MySpatialMapItem(3);

            itemsAdded.Add(lastItem);
            sm.Add(lastItem, (5, 6));

            bool result = sm.Move(lastItem, 1, 2);

            Assert.AreEqual(false, result);             // Blocked by first 5 adds and they no layers support multiple items

            result = sm.Move(lastItem, (2, 3));         // At 2, 3 we now have item on layer 3
            Assert.AreEqual(true, result);

            List <MySpatialMapItem> itemsMoved = sm.Move((1, 2), (2, 3)).ToList();

            Assert.AreEqual(4, itemsMoved.Count);             // All original items minus 1 because that one was blocked

            itemsMoved = sm.Move((2, 3), (1, 2), ~sm.LayerMasker.Mask(2)).ToList();
            Assert.AreEqual(3, itemsMoved.Count);             // lastItem from above masked out by layer

            sm = new LayeredSpatialMap <MySpatialMapItem>(5, 1);
            for (int i = 0; i < itemsAdded.Count - 1; i++)             // All but that last item so we add at diff pos
            {
                sm.Add(itemsAdded[i], (1, 2));
            }

            sm.Add(lastItem, (2, 3));
            // We should have added all but the one that was layer 0
            itemsMoved = sm.Move(1, 2, 2, 3).ToList();
            Assert.AreEqual(3, itemsMoved.Count);

            itemsMoved = sm.Move(2, 3, 1, 2, ~sm.LayerMasker.Mask(2)).ToList();
            Assert.AreEqual(2, itemsMoved.Count);
            List <MySpatialMapItem> itemsLeft = sm.GetItems((2, 3)).ToList();

            Assert.AreEqual(2, itemsLeft.Count);
            bool found = false;

            foreach (var item in itemsLeft)
            {
                found = found || item == itemsAdded[2];
            }
            Assert.AreEqual(true, found);
        }
Ejemplo n.º 2
0
        public void TestAdd()
        {
            var  sm = new LayeredSpatialMap <MySpatialMapItem>(5);
            bool result;

            for (int i = 0; i < 5; i++)
            {
                var item = new MySpatialMapItem(i);
                result = sm.Add(item, (1, 2));
                Assert.AreEqual(true, result);
            }

            result = sm.Add(new MySpatialMapItem(5), (2, 3));             // Out of range layer
            Assert.AreEqual(false, result);

            sm     = new LayeredSpatialMap <MySpatialMapItem>(5, 1);
            result = sm.Add(new MySpatialMapItem(0), (5, 6));
            Assert.AreEqual(false, result);
        }
Ejemplo n.º 3
0
        public void TestRemove()
        {
            var itemsAdded = new List <MySpatialMapItem>();
            var sm         = new LayeredSpatialMap <MySpatialMapItem>(5);

            for (int i = 0; i < 5; i++)
            {
                var item = new MySpatialMapItem(i);
                itemsAdded.Add(item);
                sm.Add(item, (1, 2));
            }

            bool result;

            var nonAddedItem = new MySpatialMapItem(2);

            result = sm.Remove(nonAddedItem);
            Assert.AreEqual(false, result);

            foreach (var i in itemsAdded)
            {
                result = sm.Remove(i);
                Assert.AreEqual(true, result);
            }


            foreach (var i in itemsAdded)
            {
                sm.Add(i, (1, 2));
            }

            List <MySpatialMapItem> itemsRemoved = sm.Remove((5, 6)).ToList();

            Assert.AreEqual(0, itemsRemoved.Count);

            itemsRemoved = sm.Remove((1, 2)).ToList();
            Assert.AreEqual(itemsAdded.Count, itemsRemoved.Count);
        }