public void MultiSpatialMapAdd() { var mySpatialMap = new MultiSpatialMap <MyIDImpl>(); var myId1 = new MyIDImpl(0); var myId2 = new MyIDImpl(1); var myId3 = new MyIDImpl(2); mySpatialMap.Add(myId1, Coord.Get(1, 2)); Assert.AreEqual(1, mySpatialMap.Count); bool retVal = mySpatialMap.Contains(Coord.Get(1, 2)); Assert.AreEqual(true, retVal); retVal = mySpatialMap.Contains(myId1); Assert.AreEqual(true, retVal); retVal = mySpatialMap.Contains(Coord.Get(2, 3)); Assert.AreEqual(false, retVal); retVal = mySpatialMap.Contains(myId2); Assert.AreEqual(false, retVal); int count = 0; foreach (var item in mySpatialMap.GetItems(Coord.Get(1, 2))) { count++; } Assert.AreEqual(1, count); count = 0; foreach (var item in mySpatialMap.GetItems(Coord.Get(2, 3))) { count++; } Assert.AreEqual(0, count); retVal = mySpatialMap.Add(myId2, Coord.Get(1, 2)); Assert.AreEqual(true, retVal); count = 0; foreach (var item in mySpatialMap.GetItems(Coord.Get(1, 2))) { count++; } Assert.AreEqual(2, count); }
public void MultiSpatialMapMove() { var mySpatialMap = new MultiSpatialMap <MyIDImpl>(); var myId1 = new MyIDImpl(0); var myId2 = new MyIDImpl(1); mySpatialMap.Add(myId1, Coord.Get(1, 2)); mySpatialMap.Add(myId2, Coord.Get(2, 3)); bool retVal = mySpatialMap.Move(myId1, Coord.Get(5, 6)); Assert.AreEqual(true, retVal); Assert.AreEqual(Coord.Get(5, 6), mySpatialMap.GetPosition(myId1)); retVal = mySpatialMap.Contains(Coord.Get(5, 6)); Assert.AreEqual(true, retVal); retVal = mySpatialMap.Contains(Coord.Get(1, 2)); Assert.AreEqual(false, retVal); retVal = mySpatialMap.Contains(Coord.Get(2, 3)); Assert.AreEqual(true, retVal); retVal = mySpatialMap.Move(myId2, Coord.Get(5, 6)); Assert.AreEqual(true, retVal); Assert.AreEqual(false, mySpatialMap.Contains(Coord.Get(2, 3))); Assert.AreEqual(true, mySpatialMap.Contains(Coord.Get(5, 6))); int count = 0; foreach (var i in mySpatialMap.GetItems(Coord.Get(5, 6))) { count++; } Assert.AreEqual(2, count); }
// Checking whether a certain type of // entity is at a specified location the manager's list of entities // and if it exists, return that Entity public T GetEntityAt <T>(Point location) where T : Entity { return(Entities.GetItems(location).OfType <T>().FirstOrDefault()); }