public void RectanglesOverlappingOverlap()
        {
            var rectangleA = new MoonTools.Core.Bonk.Rectangle(-1, -1, 1, 1);
            var transformA = new Transform2D(new Position2D(0, 0));

            var rectangleB = new MoonTools.Core.Bonk.Rectangle(-1, -1, 1, 1);
            var transformB = new Transform2D(new Vector2(1, 0));

            NarrowPhase.TestRectangleOverlap(rectangleA, transformA, rectangleB, transformB).Should().BeTrue();
        }
        public void RectanglesTouchingGJK2D()
        {
            var rectangleA = new MoonTools.Core.Bonk.Rectangle(-1, -1, 1, 1);
            var transformA = new Transform2D(new Position2D(-1, 0));

            var rectangleB = new MoonTools.Core.Bonk.Rectangle(-1, -1, 1, 1);
            var transformB = new Transform2D(new Vector2(1, 0));

            NarrowPhase.TestCollision(rectangleA, transformA, rectangleB, transformB).Should().BeTrue();
        }
        public void RotatedRectanglesOverlapping()
        {
            var rectangleA = new MoonTools.Core.Bonk.Rectangle(-1, -1, 2, 2);
            var transformA = new Transform2D(new Vector2(-1, 0), -90f);

            var rectangleB = new MoonTools.Core.Bonk.Rectangle(-1, -1, 1, 1);
            var transformB = new Transform2D(new Vector2(1, 0));

            NarrowPhase.TestCollision(rectangleA, transformA, rectangleB, transformB).Should().BeTrue();
        }
        public void RectanglesNotOverlapping()
        {
            var rectangleA = new MoonTools.Core.Bonk.Rectangle(-6, -6, 6, 6);
            var transformA = new Transform2D(new Position2D(39, 249));

            var rectangleB = new MoonTools.Core.Bonk.Rectangle(0, 0, 16, 16);
            var transformB = new Transform2D(new Position2D(16, 240));

            NarrowPhase.TestCollision(rectangleA, transformA, rectangleB, transformB).Should().BeFalse();
        }
Example #5
0
        public void LineRectangleOverlap()
        {
            var line       = new Line(new Position2D(-4, -4), new Position2D(4, 4));
            var transformA = Transform2D.DefaultTransform;
            var square     = new MoonTools.Core.Bonk.Rectangle(-1, -1, 1, 1);
            var transformB = Transform2D.DefaultTransform;

            var(result, simplex) = NarrowPhase.FindCollisionSimplex(line, transformA, square, transformB);

            result.Should().BeTrue();

            var intersection = NarrowPhase.Intersect(line, transformA, square, transformB, simplex);

            var movedTransform = new Transform2D(transformA.Position - (intersection * 1.01f)); // move a tiny bit past

            NarrowPhase.TestCollision(line, movedTransform, square, transformB).Should().BeFalse();
        }
Example #6
0
        public void RectangleOverlap()
        {
            var squareA    = new MoonTools.Core.Bonk.Rectangle(-1, -1, 1, 1);
            var transformA = Transform2D.DefaultTransform;
            var squareB    = new MoonTools.Core.Bonk.Rectangle(-1, -1, 1, 1);
            var transformB = new Transform2D(new Vector2(1.5f, 0));

            var(result, simplex) = NarrowPhase.FindCollisionSimplex(squareA, transformA, squareB, transformB);

            result.Should().BeTrue();

            var intersection = NarrowPhase.Intersect(squareA, transformA, squareB, transformB, simplex);

            intersection.X.Should().Be(1f);
            intersection.Y.Should().Be(0);

            var movedTransform = new Transform2D(transformA.Position - (intersection * 1.01f)); // move a tiny bit past

            NarrowPhase.TestCollision(squareA, movedTransform, squareB, transformB).Should().BeFalse();
        }