public void ShouldBePossibleWithNonOverlappingRectangle() { // Arrange var sut = new CollisionMap(10, 10); sut.Insert(new RectangleF(1, 1, 1, 1).Yield()); // Act var actual = sut.Check(new RectangleF(4, 4, 1, 1).Yield()); // Assert Assert.True(actual); }
public void ShouldNotBePossibleWhenOverlappingWithExisting() { // Arrange var sut = new CollisionMap(10, 10); sut.Insert(new RectangleF(1, 1, 3, 3).Yield()); // Act var actual = sut.Check(new RectangleF(2, 2, 3, 3).Yield()); // Assert Assert.False(actual); }
public void ShouldContainAddedElement() { // Arrange var sut = new CollisionMap(1, 1); var expected = new RectangleF(1, 1, 1, 1); sut.Insert(expected.Yield()); // Act var actual = sut.Rectangles.ToList(); // Assert Assert.Contains(expected, actual); }
public void ShouldContainAddedElements() { // Arrange var sut = new CollisionMap(1, 1); var expected1 = new RectangleF(1, 1, 1, 1); var expected2 = new RectangleF(2, 2, 1, 1); sut.Insert(new[] { expected1, expected2 }); // Act var actual = sut.Rectangles.ToList(); // Assert Assert.Contains(expected1, actual); Assert.Contains(expected2, actual); }
/// <summary> /// Clears the collision grid and inserts all entities before checking collisions /// </summary> protected override void PreProcess() { _comparisons = 0; _map.Clear(); var maxEntities = AssociatedEntities.Count; for (int e = 0; e < maxEntities; e++) { // Insert all entities with collision components if (AssociatedEntities[e].HasComponent <CollisionComponent>()) { var collision = AssociatedEntities[e].GetComponent <CollisionComponent>(); collision.Event = false; collision.Collider = null; _map.Insert(AssociatedEntities[e], collision); } } }