public void PointRectangleOverlapping()
        {
            var point     = new Point();
            var rectangle = new Rectangle(-2, -2, 2, 2);

            NarrowPhase.TestCollision(point, Transform2D.DefaultTransform, rectangle, Transform2D.DefaultTransform).Should().BeTrue();
        }
        public void LineLineNotOverlapping()
        {
            var lineA = new Line(new Position2D(0, 1), new Position2D(1, 0));
            var lineB = new Line(new Position2D(-1, -1), new Position2D(-2, -2));

            NarrowPhase.TestCollision(lineA, Transform2D.DefaultTransform, lineB, Transform2D.DefaultTransform).Should().BeFalse();
        }
        public void PointCircleNotOverlapping()
        {
            var point          = new Point();
            var pointTransform = new Transform2D(new Position2D(3, 0));
            var circle         = new Circle(1);

            NarrowPhase.TestCollision(point, pointTransform, circle, Transform2D.DefaultTransform).Should().BeFalse();
        }
        public void PointLineNotOverlapping()
        {
            var point          = new Point();
            var pointTransform = new Transform2D(new Position2D(1, 1));
            var line           = new Line(new Position2D(-3, -2), new Position2D(-9, -5));

            NarrowPhase.TestCollision(point, pointTransform, line, Transform2D.DefaultTransform).Should().BeFalse();
        }
        public void PointRectangleNotOverlapping()
        {
            var point          = new Point();
            var pointTransform = new Transform2D(new Position2D(5, 5));
            var rectangle      = new Rectangle(-2, -2, 2, 2);

            NarrowPhase.TestCollision(point, pointTransform, rectangle, Transform2D.DefaultTransform).Should().BeFalse();
        }
        public void LineCircleNotOverlapping()
        {
            var line       = new Line(new Position2D(-5, -5), new Position2D(-4, -4));
            var transformA = Transform2D.DefaultTransform;
            var circle     = new Circle(1);
            var transformB = Transform2D.DefaultTransform;

            NarrowPhase.TestCollision(line, transformA, circle, transformB).Should().BeFalse();
        }
        public void ScaledCirclesNotOverlapping()
        {
            var circleA    = new Circle(2);
            var transformA = new Transform2D(new Vector2(-5, -5), 0, new Vector2(0.2f, 0.2f));
            var circleB    = new Circle(2);
            var transformB = new Transform2D(new Vector2(5, 5), 0, new Vector2(0.2f, 0.2f));

            NarrowPhase.TestCollision(circleA, transformA, circleB, transformB).Should().BeFalse();
        }
        public void ScaledCirclesOverlapping()
        {
            var circleA    = new Circle(2);
            var transformA = new Transform2D(new Vector2(-3, 0), 0f, new Vector2(2, 2));
            var circleB    = new Circle(2);
            var transformB = new Transform2D(new Vector2(3, 0), 0f, new Vector2(2, 2));

            NarrowPhase.TestCollision(circleA, transformA, circleB, transformB).Should().BeTrue();
        }
        public void CircleCircleOverlapping()
        {
            var circleA    = new Circle(2);
            var transformA = new Transform2D(new Vector2(-1, -1));
            var circleB    = new Circle(2);
            var transformB = new Transform2D(new Vector2(1, 1));

            NarrowPhase.TestCollision(circleA, transformA, circleB, transformB).Should().BeTrue();
        }
        public void ScaledLinesNotOverlapping()
        {
            var lineA = new Line(new Position2D(0, 1), new Position2D(1, 0));
            var lineB = new Line(new Position2D(-1, -1), new Position2D(-2, -2));

            var transform = new Transform2D(new Position2D(0, 0), 0f, new Vector2(2, 2));

            NarrowPhase.TestCollision(lineA, transform, lineB, transform).Should().BeFalse();
        }
        public void LineCircleOverlapping()
        {
            var line       = new Line(new Position2D(-1, -1), new Position2D(1, 1));
            var transformA = Transform2D.DefaultTransform;
            var circle     = new Circle(1);
            var transformB = Transform2D.DefaultTransform;

            NarrowPhase.TestCollision(line, transformA, circle, 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();
        }
        public void PointCircleOverlapping()
        {
            var point  = new Point();
            var circle = new Circle(3);

            var pointTransform  = new Transform2D(new Position2D(1, 1));
            var circleTransform = new Transform2D(new Position2D(-1, 0));

            NarrowPhase.TestCollision(point, pointTransform, circle, circleTransform).Should().BeTrue();
        }
        public void RectanglesOverlappingGJK2D()
        {
            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.TestCollision(rectangleA, transformA, rectangleB, transformB).Should().BeTrue();
        }
        public void CirclePolygonNotOverlapping()
        {
            var circle          = new Circle(1);
            var circleTransform = new Transform2D(new Vector2(5, 0));

            var square = new Polygon(ImmutableArray.Create(
                                         new Position2D(-1, -1), new Position2D(1, -1),
                                         new Position2D(1, 1), new Position2D(-1, 1)
                                         ));
            var squareTransform = Transform2D.DefaultTransform;

            NarrowPhase.TestCollision(circle, circleTransform, square, squareTransform).Should().BeFalse();
        }
        public void PointPolygonNotOverlapping()
        {
            var point          = new Point();
            var pointTransform = new Transform2D(new Position2D(5, 5));
            var polygon        = new Polygon(ImmutableArray.Create(
                                                 new Position2D(-2, -2),
                                                 new Position2D(-3, 2),
                                                 new Position2D(3, 2),
                                                 new Position2D(3, -2)
                                                 ));

            NarrowPhase.TestCollision(point, pointTransform, polygon, Transform2D.DefaultTransform).Should().BeFalse();
        }
        public void CirclePolygonOverlapping()
        {
            var circle     = new Circle(1);
            var transformA = new Transform2D(new Vector2(0.25f, 0));

            var square = new Polygon(ImmutableArray.Create(
                                         new Position2D(-1, -1), new Position2D(1, -1),
                                         new Position2D(1, 1), new Position2D(-1, 1)
                                         ));

            var transformB = Transform2D.DefaultTransform;

            NarrowPhase.TestCollision(circle, transformA, square, transformB).Should().BeTrue();
        }
        public void LinePolygonNotOverlapping()
        {
            var line = new Line(new Position2D(-5, 5), new Position2D(-5, 5));

            var transformA = Transform2D.DefaultTransform;

            var polygon = new Polygon(ImmutableArray.Create(
                                          new Position2D(-1, -1), new Position2D(1, -1),
                                          new Position2D(1, 1), new Position2D(-1, 1)
                                          ));

            var transformB = Transform2D.DefaultTransform;

            NarrowPhase.TestCollision(line, transformA, polygon, transformB).Should().BeFalse();
        }
示例#19
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();
        }
        public void ScaledPolygonsNotOverlapping()
        {
            var shapeA = new Polygon(ImmutableArray.Create(
                                         new Position2D(-1, 1), new Position2D(1, 1),
                                         new Position2D(-1, -1), new Position2D(1, -1)
                                         ));

            var transformA = Transform2D.DefaultTransform;

            var shapeB = new Polygon(ImmutableArray.Create(
                                         new Position2D(-2, 2), new Position2D(2, 2),
                                         new Position2D(-2, -2), new Position2D(2, -2)
                                         ));

            var transformB = new Transform2D(new Vector2(3f, 0), 0f, new Vector2(0.5f, 0.5f));

            NarrowPhase.TestCollision(shapeA, transformA, shapeB, transformB).Should().BeFalse();
        }
示例#21
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();
        }
示例#22
0
        public void CircleOverlap()
        {
            var circleA    = new Circle(2);
            var transformA = Transform2D.DefaultTransform;
            var circleB    = new Circle(1);
            var transformB = new Transform2D(new Vector2(1, 1));

            var(result, simplex) = NarrowPhase.FindCollisionSimplex(circleA, transformA, circleB, transformB);

            result.Should().BeTrue();

            var intersection = NarrowPhase.Intersect(circleA, transformA, circleB, transformB, simplex);

            var ix = (circleA.Radius * (float)Math.Cos(Math.PI / 4)) - ((circleB.Radius * (float)Math.Cos(5 * Math.PI / 4)) + transformB.Position.X);
            var iy = (circleA.Radius * (float)Math.Sin(Math.PI / 4)) - ((circleB.Radius * (float)Math.Sin(5 * Math.PI / 4)) + transformB.Position.Y);

            intersection.X.Should().BeApproximately(ix, 0.01f);
            intersection.Y.Should().BeApproximately(iy, 0.01f);

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

            NarrowPhase.TestCollision(circleA, movedTransform, circleB, transformB).Should().BeFalse();
        }