public void UnRotatedRectanglesCollideCorrectly() { var rect1 = new BoundingRectangle(10, 6) { Position = new Vector2d(5, 3) }; var rect2 = new BoundingRectangle(3, 3) { Position = new Vector2d(5, 3) }; Assert.True(rect1.Intersects(rect2)); Assert.True(rect2.Intersects(rect1)); rect2.Position += 3; Assert.True(rect1.Intersects(rect2)); Assert.True(rect2.Intersects(rect1)); rect2.Position++; Assert.True(rect1.Intersects(rect2)); Assert.True(rect2.Intersects(rect1)); rect2.Position++; Assert.False(rect1.Intersects(rect2)); Assert.False(rect2.Intersects(rect1)); }
public void RotatedRectanglesCollideCorrectly() { var rect1 = new BoundingRectangle(4.24, 2.83) { Position = new Vector2d(2.5, 2.5), Rotation = - Math.PI / 4 }; var rect2 = new BoundingRectangle(6, 4) { Position = new Vector2d(9, 4) }; Assert.False(rect1.Intersects(rect2)); Assert.False(rect2.Intersects(rect1)); rect2.Position.X-=2; Assert.True(rect1.Intersects(rect2)); Assert.True(rect2.Intersects(rect1)); rect2.Rotation = Math.PI / 2; rect2.Position++; Assert.False(rect1.Intersects(rect2)); Assert.False(rect2.Intersects(rect1)); rect2.Rotation = Math.PI; rect2.Position--; Assert.True(rect1.Intersects(rect2)); Assert.True(rect2.Intersects(rect1)); rect2.Position.Y+=10; Assert.False(rect1.Intersects(rect2)); Assert.False(rect2.Intersects(rect1)); rect2.Position.Y -= 10; rect1.Position.X += 5; Assert.True(rect1.Intersects(rect2)); Assert.True(rect2.Intersects(rect1)); rect1.Position.X += 9; Assert.False(rect1.Intersects(rect2)); Assert.False(rect2.Intersects(rect1)); rect1.Rotation = 0; rect1.Position.X = 12; rect2.Rotation = Math.PI; Assert.True(rect1.Intersects(rect2)); Assert.True(rect2.Intersects(rect1)); }