Пример #1
0
        public void SpatialMapMove()
        {
            var mySpatialMap = new SpatialMap <MyIDImpl>();

            var myId1 = new MyIDImpl(0);
            var myId2 = new MyIDImpl(1);

            mySpatialMap.Add(myId1, (1, 2));
            mySpatialMap.Add(myId2, (2, 3));

            mySpatialMap.Move(myId1, (5, 6));
            Assert.Equal(new Point(5, 6), mySpatialMap.GetPositionOf(myId1));

            var retVal = mySpatialMap.Contains((5, 6));

            Assert.True(retVal);

            retVal = mySpatialMap.Contains((1, 2));
            Assert.False(retVal);

            retVal = mySpatialMap.Contains((2, 3));
            Assert.True(retVal);

            Assert.Throws <ArgumentException>(() => mySpatialMap.Move(myId2, (5, 6)));
            Assert.True(mySpatialMap.Contains((2, 3)));
            Assert.True(mySpatialMap.Contains((5, 6)));
        }
Пример #2
0
        public void SpatialMapMove()
        {
            var mySpatialMap = new SpatialMap <MyIDImpl>();

            var myId1 = new MyIDImpl(0);
            var myId2 = new MyIDImpl(1);

            mySpatialMap.Add(myId1, (1, 2));
            mySpatialMap.Add(myId2, (2, 3));

            bool retVal = mySpatialMap.Move(myId1, (5, 6));

            Assert.AreEqual(true, retVal);
            Assert.AreEqual(new Coord(5, 6), mySpatialMap.GetPosition(myId1));

            retVal = mySpatialMap.Contains((5, 6));
            Assert.AreEqual(true, retVal);

            retVal = mySpatialMap.Contains((1, 2));
            Assert.AreEqual(false, retVal);

            retVal = mySpatialMap.Contains((2, 3));
            Assert.AreEqual(true, retVal);

            retVal = mySpatialMap.Move(myId2, (5, 6));
            Assert.AreEqual(false, retVal);

            Assert.AreEqual(true, mySpatialMap.Contains((2, 3)));
            Assert.AreEqual(true, mySpatialMap.Contains((5, 6)));
        }
Пример #3
0
        public void SpatialMapAdd()
        {
            var mySpatialMap = new SpatialMap <MyIDImpl>();

            var myId1 = new MyIDImpl(0);
            var myId2 = new MyIDImpl(1);

            mySpatialMap.Add(myId1, (1, 2));
            Assert.Equal(1, mySpatialMap.Count);

            var retVal = mySpatialMap.Contains((1, 2));

            Assert.True(retVal);

            retVal = mySpatialMap.Contains(myId1);
            Assert.True(retVal);

            retVal = mySpatialMap.Contains((2, 3));
            Assert.False(retVal);

            retVal = mySpatialMap.Contains(myId2);
            Assert.False(retVal);

            Assert.Single(mySpatialMap.GetItemsAt((1, 2)));
            Assert.Empty(mySpatialMap.GetItemsAt((2, 3)));

            Assert.Throws <ArgumentException>(() => mySpatialMap.Add(myId2, (1, 2)));

            Assert.Single(mySpatialMap.GetItemsAt((1, 2)));
        }
Пример #4
0
        public void SpatialMapRemove()
        {
            var mySpatialMap = new SpatialMap <MyIDImpl>();

            var myId1 = new MyIDImpl(0);
            var myId2 = new MyIDImpl(1);
            var myId3 = new MyIDImpl(2);

            mySpatialMap.Add(myId1, (1, 2));
            mySpatialMap.Add(myId2, (2, 3));
            mySpatialMap.Add(myId3, (3, 4));

            mySpatialMap.Remove(myId1);

            var retVal = mySpatialMap.Contains(myId1);

            Assert.False(retVal);

            retVal = mySpatialMap.Contains((1, 2));
            Assert.False(retVal);

            Assert.Single(mySpatialMap.Remove((2, 3)));

            Assert.False(mySpatialMap.Contains((2, 3)));
            Assert.False(mySpatialMap.Contains(myId2));

            Assert.Throws <ArgumentException>(() => mySpatialMap.Remove(myId1));
            Assert.Empty(mySpatialMap.Remove((5, 6)));
        }
Пример #5
0
        public void ManualPrintSpatialMap()
        {
            SpatialMap <MyIDImpl> sm = new SpatialMap <MyIDImpl>();

            sm.Add(new MyIDImpl(1), 1, 2);
            sm.Add(new MyIDImpl(2), 1, 3);
            sm.Add(new MyIDImpl(3), 4, 5);

            Console.WriteLine(sm);
        }
Пример #6
0
        public void SpatialMapAdd()
        {
            var mySpatialMap = new SpatialMap <MyIDImpl>();

            var myId1 = new MyIDImpl(0);
            var myId2 = new MyIDImpl(1);

            mySpatialMap.Add(myId1, (1, 2));
            Assert.AreEqual(1, mySpatialMap.Count);

            bool retVal = mySpatialMap.Contains((1, 2));

            Assert.AreEqual(true, retVal);

            retVal = mySpatialMap.Contains(myId1);
            Assert.AreEqual(true, retVal);

            retVal = mySpatialMap.Contains((2, 3));
            Assert.AreEqual(false, retVal);

            retVal = mySpatialMap.Contains(myId2);
            Assert.AreEqual(false, retVal);

            int count = 0;

            foreach (var item in mySpatialMap.GetItems((1, 2)))
            {
                count++;
            }
            Assert.AreEqual(1, count);

            count = 0;
            foreach (var item in mySpatialMap.GetItems((2, 3)))
            {
                count++;
            }
            Assert.AreEqual(0, count);

            retVal = mySpatialMap.Add(myId2, (1, 2));
            Assert.AreEqual(false, retVal);

            count = 0;
            foreach (var item in mySpatialMap.GetItems((1, 2)))
            {
                count++;
            }
            Assert.AreEqual(1, count);
        }
Пример #7
0
        /// <summary>
        /// Queue a position update on the FlightContextFactory. The FlightContextFactory will handle further
        /// processing of this position update.
        /// </summary>
        /// <param name="positionUpdate">The position update to queue</param>
        public void Process(PositionUpdate positionUpdate)
        {
            if (positionUpdate == null)
            {
                return;
            }

            EnsureContextAvailable(positionUpdate.Aircraft);

            if (_flightContextDictionary.TryGetValue(positionUpdate.Aircraft, out var flightContext))
            {
                var previousPoint = flightContext.CurrentPosition;

                if (flightContext.Process(positionUpdate))
                {
                    _map.Add(positionUpdate);
                    _map.Remove(previousPoint);

                    if (_map.Nearby(previousPoint, 2).ToList().Count(q => q.Aircraft == positionUpdate.Aircraft) > 1)
                    {
                        Debugger.Break();
                    }
                }
            }
        }
Пример #8
0
        public void NegativeUpdate()
        {
            var map        = new SpatialMap <int>(1);
            var entry      = map.Add(1, new AABB(0.25f, 0.25f, 0.75f, 0.75f));
            var otherEntry = map.Add(2, new AABB(0.25f, 0.25f, 0.75f, 0.75f));

            SequenceEqual(new int[] { 1, 2 }, map.Region(new AABB(0, 0, 1, 1)));

            map.Update(ref entry, new AABB(-0.75f, 0.25f, -0.25f, 0.75f));

            SequenceEqual(new int[] { 2 }, map.Region(new AABB(0, 0, 1, 1)));
            SequenceEqual(new int[] { 1 }, map.Region(new AABB(-1, 0, 0, 1)));

            map.Update(ref entry, new AABB(-9.5f, 1f, -8.5f, 2f));

            SequenceEqual(new int[] { 1 }, map.Region(new AABB(-10, -8, 0, 3)));
        }
Пример #9
0
        public void SpatialMapMoveEvent()
        {
            var mySpatialMap = new SpatialMap <MyIDImpl>();

            var myId1 = new MyIDImpl(0);
            var myId2 = new MyIDImpl(1);
            var myId3 = new MyIDImpl(2);

            mySpatialMap.Add(myId1, (1, 2));
            mySpatialMap.Add(myId2, (2, 3));
            mySpatialMap.Add(myId3, (3, 4));

            mySpatialMap.ItemMoved += onItemMoved;
            oldPos = (1, 2);
            newPos = (5, 6);
            mySpatialMap.Move(myId1, (5, 6));
            mySpatialMap.ItemMoved -= onItemMoved;
        }
Пример #10
0
        public void SpatialMapRemove()
        {
            var mySpatialMap = new SpatialMap <MyIDImpl>();

            var myId1 = new MyIDImpl(0);
            var myId2 = new MyIDImpl(1);
            var myId3 = new MyIDImpl(2);

            mySpatialMap.Add(myId1, (1, 2));
            mySpatialMap.Add(myId2, (2, 3));
            mySpatialMap.Add(myId3, (3, 4));

            bool retVal = mySpatialMap.Remove(myId1);

            Assert.AreEqual(true, retVal);

            retVal = mySpatialMap.Contains(myId1);
            Assert.AreEqual(false, retVal);

            retVal = mySpatialMap.Contains((1, 2));
            Assert.AreEqual(false, retVal);

            int count = 0;

            foreach (var i in mySpatialMap.Remove((2, 3)))
            {
                count++;
            }

            Assert.AreEqual(1, count);
            Assert.AreEqual(false, mySpatialMap.Contains((2, 3)));
            Assert.AreEqual(false, mySpatialMap.Contains(myId2));

            retVal = mySpatialMap.Remove(myId1);
            Assert.AreEqual(false, retVal);

            count = 0;
            foreach (var i in mySpatialMap.Remove((5, 6)))
            {
                count++;
            }
            Assert.AreEqual(0, count);
        }
Пример #11
0
        public void InsertAndGet()
        {
            var map   = new SpatialMap <int>(1);
            var entry = map.Add(1, new AABB(0, 0, 1, 1));

            SequenceEqual(new int[] { 1 }, map.Region(new AABB(-1, -1, 2, 2)));

            map.Update(ref entry, new AABB(3, 3, 4, 4));

            SequenceEqual(new int[] {}, map.Region(new AABB(-1, -1, 2, 2)));
            SequenceEqual(new int[] { 1 }, map.Region(new AABB(2, 2, 3.5f, 3.5f)));

            map.Remove(entry);

            SequenceEqual(new int[] {}, map.Region(new AABB(-1, -1, 5, 5)));
        }
Пример #12
0
 public void AddActor(GameEntity entity)
 {
     MapActors.Add(entity, entity.Position);
 }