2019-09-06 08:11:58 +00:00
|
|
|
|
using NUnit.Framework;
|
2020-02-21 02:07:59 +00:00
|
|
|
|
using MoonTools.Bonk;
|
|
|
|
|
using MoonTools.Structs;
|
2019-10-31 23:19:30 +00:00
|
|
|
|
using System.Numerics;
|
2019-10-25 10:46:47 +00:00
|
|
|
|
using FluentAssertions;
|
2019-12-09 03:46:08 +00:00
|
|
|
|
using System.Collections.Immutable;
|
2019-09-06 08:11:58 +00:00
|
|
|
|
|
|
|
|
|
namespace Tests
|
|
|
|
|
{
|
2020-01-02 09:40:03 +00:00
|
|
|
|
public class NarrowPhaseTest
|
2019-09-06 08:11:58 +00:00
|
|
|
|
{
|
2019-12-02 06:21:50 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void PointLineOverlapping()
|
|
|
|
|
{
|
2020-01-01 02:23:06 +00:00
|
|
|
|
var point = new Point();
|
|
|
|
|
var pointTransform = new Transform2D(new Position2D(1, 1));
|
2019-12-02 06:21:50 +00:00
|
|
|
|
var line = new Line(new Position2D(-2, -2), new Position2D(2, 2));
|
|
|
|
|
|
2020-01-01 01:45:42 +00:00
|
|
|
|
NarrowPhase.TestCollision(point, pointTransform, line, Transform2D.DefaultTransform).Should().BeTrue();
|
2019-12-02 06:21:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void PointLineNotOverlapping()
|
|
|
|
|
{
|
2020-01-01 02:23:06 +00:00
|
|
|
|
var point = new Point();
|
|
|
|
|
var pointTransform = new Transform2D(new Position2D(1, 1));
|
2019-12-02 06:21:50 +00:00
|
|
|
|
var line = new Line(new Position2D(-3, -2), new Position2D(-9, -5));
|
|
|
|
|
|
2020-01-01 02:23:06 +00:00
|
|
|
|
NarrowPhase.TestCollision(point, pointTransform, line, Transform2D.DefaultTransform).Should().BeFalse();
|
2019-12-02 06:21:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
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));
|
|
|
|
|
|
2020-01-01 01:45:42 +00:00
|
|
|
|
NarrowPhase.TestCollision(point, pointTransform, circle, circleTransform).Should().BeTrue();
|
2019-12-02 06:21:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void PointCircleNotOverlapping()
|
|
|
|
|
{
|
2020-01-01 02:23:06 +00:00
|
|
|
|
var point = new Point();
|
2019-12-02 20:47:27 +00:00
|
|
|
|
var pointTransform = new Transform2D(new Position2D(3, 0));
|
2019-12-02 06:21:50 +00:00
|
|
|
|
var circle = new Circle(1);
|
|
|
|
|
|
2020-01-01 01:45:42 +00:00
|
|
|
|
NarrowPhase.TestCollision(point, pointTransform, circle, Transform2D.DefaultTransform).Should().BeFalse();
|
2019-12-02 06:21:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void PointRectangleOverlapping()
|
|
|
|
|
{
|
2020-01-01 02:23:06 +00:00
|
|
|
|
var point = new Point();
|
2020-01-07 04:06:21 +00:00
|
|
|
|
var rectangle = new Rectangle(-2, -2, 4, 4);
|
2019-12-02 06:21:50 +00:00
|
|
|
|
|
2020-01-01 01:45:42 +00:00
|
|
|
|
NarrowPhase.TestCollision(point, Transform2D.DefaultTransform, rectangle, Transform2D.DefaultTransform).Should().BeTrue();
|
2019-12-02 06:21:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void PointRectangleNotOverlapping()
|
|
|
|
|
{
|
2020-01-01 02:23:06 +00:00
|
|
|
|
var point = new Point();
|
|
|
|
|
var pointTransform = new Transform2D(new Position2D(5, 5));
|
2020-01-07 04:06:21 +00:00
|
|
|
|
var rectangle = new Rectangle(-2, -2, 4, 4);
|
2019-12-02 06:21:50 +00:00
|
|
|
|
|
2020-01-01 02:23:06 +00:00
|
|
|
|
NarrowPhase.TestCollision(point, pointTransform, rectangle, Transform2D.DefaultTransform).Should().BeFalse();
|
2019-12-02 06:21:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void PointPolygonOverlapping()
|
|
|
|
|
{
|
2020-01-01 02:23:06 +00:00
|
|
|
|
var point = new Point();
|
|
|
|
|
var pointTransform = new Transform2D(new Position2D(1, 1));
|
2019-12-09 03:46:08 +00:00
|
|
|
|
var polygon = new Polygon(ImmutableArray.Create(
|
2019-12-02 06:21:50 +00:00
|
|
|
|
new Position2D(-2, -2),
|
|
|
|
|
new Position2D(-3, 2),
|
|
|
|
|
new Position2D(3, 2),
|
|
|
|
|
new Position2D(3, -2)
|
2019-12-09 03:46:08 +00:00
|
|
|
|
));
|
2019-12-02 06:21:50 +00:00
|
|
|
|
|
2020-01-01 02:23:06 +00:00
|
|
|
|
NarrowPhase.TestCollision(point, pointTransform, polygon, Transform2D.DefaultTransform).Should().BeTrue();
|
2019-12-02 06:21:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void PointPolygonNotOverlapping()
|
|
|
|
|
{
|
2020-01-01 02:23:06 +00:00
|
|
|
|
var point = new Point();
|
|
|
|
|
var pointTransform = new Transform2D(new Position2D(5, 5));
|
2019-12-09 03:46:08 +00:00
|
|
|
|
var polygon = new Polygon(ImmutableArray.Create(
|
2019-12-02 06:21:50 +00:00
|
|
|
|
new Position2D(-2, -2),
|
|
|
|
|
new Position2D(-3, 2),
|
|
|
|
|
new Position2D(3, 2),
|
|
|
|
|
new Position2D(3, -2)
|
2019-12-09 03:46:08 +00:00
|
|
|
|
));
|
2019-12-02 06:21:50 +00:00
|
|
|
|
|
2020-01-01 02:23:06 +00:00
|
|
|
|
NarrowPhase.TestCollision(point, pointTransform, polygon, Transform2D.DefaultTransform).Should().BeFalse();
|
2019-12-02 06:21:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-06 08:11:58 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void LineLineOverlapping()
|
|
|
|
|
{
|
|
|
|
|
var lineA = new Line(new Position2D(-1, -1), new Position2D(1, 1));
|
|
|
|
|
var lineB = new Line(new Position2D(-1, 1), new Position2D(1, -1));
|
|
|
|
|
|
2020-01-01 01:45:42 +00:00
|
|
|
|
NarrowPhase.TestCollision(lineA, Transform2D.DefaultTransform, lineB, Transform2D.DefaultTransform).Should().BeTrue();
|
2019-09-06 08:11:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-19 00:00:43 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void ScaledLinesOverlapping()
|
|
|
|
|
{
|
|
|
|
|
var lineA = new Line(new Position2D(-1, -1), new Position2D(1, 1));
|
|
|
|
|
var lineB = new Line(new Position2D(-1, 1), new Position2D(1, -1));
|
|
|
|
|
|
|
|
|
|
var transform = new Transform2D(new Position2D(0, 0), 0f, new Vector2(2, 2));
|
|
|
|
|
|
2020-01-01 01:45:42 +00:00
|
|
|
|
NarrowPhase.TestCollision(lineA, transform, lineB, transform).Should().BeTrue();
|
2019-09-19 00:00:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-06 08:11:58 +00:00
|
|
|
|
[Test]
|
|
|
|
|
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));
|
|
|
|
|
|
2020-01-01 01:45:42 +00:00
|
|
|
|
NarrowPhase.TestCollision(lineA, Transform2D.DefaultTransform, lineB, Transform2D.DefaultTransform).Should().BeFalse();
|
2019-09-06 08:11:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-19 00:00:43 +00:00
|
|
|
|
[Test]
|
|
|
|
|
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));
|
|
|
|
|
|
2020-01-01 01:45:42 +00:00
|
|
|
|
NarrowPhase.TestCollision(lineA, transform, lineB, transform).Should().BeFalse();
|
2019-09-19 00:00:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-06 08:11:58 +00:00
|
|
|
|
[Test]
|
|
|
|
|
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));
|
|
|
|
|
|
2020-01-01 01:45:42 +00:00
|
|
|
|
NarrowPhase.TestCollision(circleA, transformA, circleB, transformB).Should().BeTrue();
|
2019-09-06 08:11:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-19 00:00:43 +00:00
|
|
|
|
[Test]
|
|
|
|
|
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));
|
|
|
|
|
|
2020-01-01 01:45:42 +00:00
|
|
|
|
NarrowPhase.TestCollision(circleA, transformA, circleB, transformB).Should().BeTrue();
|
2019-09-19 00:00:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-06 08:11:58 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void CircleCircleNotOverlapping()
|
|
|
|
|
{
|
|
|
|
|
var circleA = new Circle(2);
|
|
|
|
|
var transformA = new Transform2D(new Vector2(-5, -5));
|
|
|
|
|
var circleB = new Circle(2);
|
|
|
|
|
var transformB = new Transform2D(new Vector2(5, 5));
|
|
|
|
|
|
2020-01-01 01:45:42 +00:00
|
|
|
|
NarrowPhase.TestCollision(circleA, transformA, circleB, transformB).Should().BeFalse();
|
2019-09-06 08:11:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-19 00:00:43 +00:00
|
|
|
|
[Test]
|
|
|
|
|
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));
|
|
|
|
|
|
2020-01-01 01:45:42 +00:00
|
|
|
|
NarrowPhase.TestCollision(circleA, transformA, circleB, transformB).Should().BeFalse();
|
2019-09-19 00:00:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-06 08:11:58 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void PolygonPolygonOverlapping()
|
|
|
|
|
{
|
2019-12-09 03:46:08 +00:00
|
|
|
|
var shapeA = new Polygon(ImmutableArray.Create(
|
2019-09-06 08:11:58 +00:00
|
|
|
|
new Position2D(-1, 1), new Position2D(1, 1),
|
|
|
|
|
new Position2D(-1, -1), new Position2D(1, -1)
|
2019-12-09 03:46:08 +00:00
|
|
|
|
));
|
2019-09-06 08:11:58 +00:00
|
|
|
|
|
|
|
|
|
var transformA = Transform2D.DefaultTransform;
|
|
|
|
|
|
2019-12-09 03:46:08 +00:00
|
|
|
|
var shapeB = new Polygon(ImmutableArray.Create(
|
2019-09-06 08:11:58 +00:00
|
|
|
|
new Position2D(-1, 1), new Position2D(1, 1),
|
|
|
|
|
new Position2D(-1, -1), new Position2D(1, -1)
|
2019-12-09 03:46:08 +00:00
|
|
|
|
));
|
2019-09-06 08:11:58 +00:00
|
|
|
|
|
|
|
|
|
var transformB = new Transform2D(new Vector2(0.5f, 0.5f));
|
|
|
|
|
|
2020-01-01 01:45:42 +00:00
|
|
|
|
NarrowPhase.TestCollision(shapeA, transformA, shapeB, transformB).Should().BeTrue();
|
2019-09-06 08:11:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-19 00:00:43 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void ScaledPolygonsOverlapping()
|
|
|
|
|
{
|
2019-12-09 03:46:08 +00:00
|
|
|
|
var shapeA = new Polygon(ImmutableArray.Create(
|
2019-09-19 00:00:43 +00:00
|
|
|
|
new Position2D(-1, 1), new Position2D(1, 1),
|
|
|
|
|
new Position2D(-1, -1), new Position2D(1, -1)
|
2019-12-09 03:46:08 +00:00
|
|
|
|
));
|
2019-09-19 00:00:43 +00:00
|
|
|
|
|
|
|
|
|
var transformA = Transform2D.DefaultTransform;
|
|
|
|
|
|
2019-12-09 03:46:08 +00:00
|
|
|
|
var shapeB = new Polygon(ImmutableArray.Create(
|
2019-09-19 00:00:43 +00:00
|
|
|
|
new Position2D(-1, 1), new Position2D(1, 1),
|
|
|
|
|
new Position2D(-1, -1), new Position2D(1, -1)
|
2019-12-09 03:46:08 +00:00
|
|
|
|
));
|
2019-09-19 00:00:43 +00:00
|
|
|
|
|
|
|
|
|
var transformB = new Transform2D(new Vector2(3f, 0f), 0f, new Vector2(3f, 3f));
|
|
|
|
|
|
2020-01-01 01:45:42 +00:00
|
|
|
|
NarrowPhase.TestCollision(shapeA, transformA, shapeB, transformB).Should().BeTrue();
|
2019-09-19 00:00:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-06 08:11:58 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void PolygonPolygonNotOverlapping()
|
|
|
|
|
{
|
2019-12-09 03:46:08 +00:00
|
|
|
|
var shapeA = new Polygon(ImmutableArray.Create(
|
2019-09-06 08:11:58 +00:00
|
|
|
|
new Position2D(-1, 1), new Position2D(1, 1),
|
|
|
|
|
new Position2D(-1, -1), new Position2D(1, -1)
|
2019-12-09 03:46:08 +00:00
|
|
|
|
));
|
2019-09-06 08:11:58 +00:00
|
|
|
|
|
|
|
|
|
var transformA = Transform2D.DefaultTransform;
|
|
|
|
|
|
2019-12-09 03:46:08 +00:00
|
|
|
|
var shapeB = new Polygon(ImmutableArray.Create(
|
2019-09-06 08:11:58 +00:00
|
|
|
|
new Position2D(-1, 1), new Position2D(1, 1),
|
|
|
|
|
new Position2D(-1, -1), new Position2D(1, -1)
|
2019-12-09 03:46:08 +00:00
|
|
|
|
));
|
2019-09-06 08:11:58 +00:00
|
|
|
|
|
|
|
|
|
var transformB = new Transform2D(new Vector2(5, 0));
|
|
|
|
|
|
2020-01-01 01:45:42 +00:00
|
|
|
|
NarrowPhase.TestCollision(shapeA, transformA, shapeB, transformB).Should().BeFalse();
|
2019-09-06 08:11:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-19 00:00:43 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void ScaledPolygonsNotOverlapping()
|
|
|
|
|
{
|
2019-12-09 03:46:08 +00:00
|
|
|
|
var shapeA = new Polygon(ImmutableArray.Create(
|
2019-09-19 00:00:43 +00:00
|
|
|
|
new Position2D(-1, 1), new Position2D(1, 1),
|
|
|
|
|
new Position2D(-1, -1), new Position2D(1, -1)
|
2019-12-09 03:46:08 +00:00
|
|
|
|
));
|
2019-09-19 00:00:43 +00:00
|
|
|
|
|
|
|
|
|
var transformA = Transform2D.DefaultTransform;
|
|
|
|
|
|
2019-12-09 03:46:08 +00:00
|
|
|
|
var shapeB = new Polygon(ImmutableArray.Create(
|
2019-10-25 20:39:12 +00:00
|
|
|
|
new Position2D(-2, 2), new Position2D(2, 2),
|
|
|
|
|
new Position2D(-2, -2), new Position2D(2, -2)
|
2019-12-09 03:46:08 +00:00
|
|
|
|
));
|
2019-09-19 00:00:43 +00:00
|
|
|
|
|
2019-10-25 20:39:12 +00:00
|
|
|
|
var transformB = new Transform2D(new Vector2(3f, 0), 0f, new Vector2(0.5f, 0.5f));
|
2019-09-19 00:00:43 +00:00
|
|
|
|
|
2020-01-01 01:45:42 +00:00
|
|
|
|
NarrowPhase.TestCollision(shapeA, transformA, shapeB, transformB).Should().BeFalse();
|
2019-09-19 00:00:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-06 08:11:58 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void LinePolygonOverlapping()
|
|
|
|
|
{
|
|
|
|
|
var line = new Line(new Position2D(-1, -1), new Position2D(1, 1));
|
|
|
|
|
|
|
|
|
|
var transformA = Transform2D.DefaultTransform;
|
|
|
|
|
|
2019-12-09 03:46:08 +00:00
|
|
|
|
var polygon = new Polygon(ImmutableArray.Create(
|
2019-09-06 08:11:58 +00:00
|
|
|
|
new Position2D(-1, -1), new Position2D(1, -1),
|
|
|
|
|
new Position2D(1, 1), new Position2D(-1, 1)
|
2019-12-09 03:46:08 +00:00
|
|
|
|
));
|
2019-09-06 08:11:58 +00:00
|
|
|
|
|
|
|
|
|
var transformB = Transform2D.DefaultTransform;
|
|
|
|
|
|
2020-01-01 01:45:42 +00:00
|
|
|
|
NarrowPhase.TestCollision(line, transformA, polygon, transformB).Should().BeTrue();
|
2019-09-06 08:11:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void LinePolygonNotOverlapping()
|
|
|
|
|
{
|
|
|
|
|
var line = new Line(new Position2D(-5, 5), new Position2D(-5, 5));
|
|
|
|
|
|
|
|
|
|
var transformA = Transform2D.DefaultTransform;
|
|
|
|
|
|
2019-12-09 03:46:08 +00:00
|
|
|
|
var polygon = new Polygon(ImmutableArray.Create(
|
2019-09-06 08:11:58 +00:00
|
|
|
|
new Position2D(-1, -1), new Position2D(1, -1),
|
|
|
|
|
new Position2D(1, 1), new Position2D(-1, 1)
|
2019-12-09 03:46:08 +00:00
|
|
|
|
));
|
2019-09-06 08:11:58 +00:00
|
|
|
|
|
|
|
|
|
var transformB = Transform2D.DefaultTransform;
|
|
|
|
|
|
2020-01-01 01:45:42 +00:00
|
|
|
|
NarrowPhase.TestCollision(line, transformA, polygon, transformB).Should().BeFalse();
|
2019-09-06 08:11:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
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;
|
|
|
|
|
|
2020-01-01 01:45:42 +00:00
|
|
|
|
NarrowPhase.TestCollision(line, transformA, circle, transformB).Should().BeTrue();
|
2019-09-06 08:11:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
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;
|
|
|
|
|
|
2020-01-01 01:45:42 +00:00
|
|
|
|
NarrowPhase.TestCollision(line, transformA, circle, transformB).Should().BeFalse();
|
2019-09-06 08:11:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void CirclePolygonOverlapping()
|
|
|
|
|
{
|
|
|
|
|
var circle = new Circle(1);
|
|
|
|
|
var transformA = new Transform2D(new Vector2(0.25f, 0));
|
|
|
|
|
|
2019-12-09 03:46:08 +00:00
|
|
|
|
var square = new Polygon(ImmutableArray.Create(
|
2019-09-06 08:11:58 +00:00
|
|
|
|
new Position2D(-1, -1), new Position2D(1, -1),
|
|
|
|
|
new Position2D(1, 1), new Position2D(-1, 1)
|
2019-12-09 03:46:08 +00:00
|
|
|
|
));
|
2019-09-06 08:11:58 +00:00
|
|
|
|
|
|
|
|
|
var transformB = Transform2D.DefaultTransform;
|
|
|
|
|
|
2020-01-01 01:45:42 +00:00
|
|
|
|
NarrowPhase.TestCollision(circle, transformA, square, transformB).Should().BeTrue();
|
2019-09-06 08:11:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void CirclePolygonNotOverlapping()
|
|
|
|
|
{
|
|
|
|
|
var circle = new Circle(1);
|
|
|
|
|
var circleTransform = new Transform2D(new Vector2(5, 0));
|
|
|
|
|
|
2019-12-09 03:46:08 +00:00
|
|
|
|
var square = new Polygon(ImmutableArray.Create(
|
2019-09-06 08:11:58 +00:00
|
|
|
|
new Position2D(-1, -1), new Position2D(1, -1),
|
|
|
|
|
new Position2D(1, 1), new Position2D(-1, 1)
|
2019-12-09 03:46:08 +00:00
|
|
|
|
));
|
2019-09-06 08:11:58 +00:00
|
|
|
|
var squareTransform = Transform2D.DefaultTransform;
|
|
|
|
|
|
2020-01-01 01:45:42 +00:00
|
|
|
|
NarrowPhase.TestCollision(circle, circleTransform, square, squareTransform).Should().BeFalse();
|
2019-09-06 08:11:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-26 05:00:34 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void RectanglesNotOverlapping()
|
|
|
|
|
{
|
2020-01-07 04:06:21 +00:00
|
|
|
|
var rectangleA = new Rectangle(-6, -6, 12, 12);
|
2019-10-26 05:00:34 +00:00
|
|
|
|
var transformA = new Transform2D(new Position2D(39, 249));
|
|
|
|
|
|
2020-01-07 04:06:21 +00:00
|
|
|
|
var rectangleB = new Rectangle(-8, -8, 16, 16);
|
2019-10-26 05:00:34 +00:00
|
|
|
|
var transformB = new Transform2D(new Position2D(16, 240));
|
|
|
|
|
|
2020-01-01 01:45:42 +00:00
|
|
|
|
NarrowPhase.TestCollision(rectangleA, transformA, rectangleB, transformB).Should().BeFalse();
|
2019-10-26 05:00:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-06 08:11:58 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void RotatedRectanglesOverlapping()
|
|
|
|
|
{
|
2020-01-07 04:06:21 +00:00
|
|
|
|
var rectangleA = new Rectangle(-1, -3, 3, 6);
|
2020-01-05 00:13:07 +00:00
|
|
|
|
var transformA = new Transform2D(new Vector2(4f, 0), (float)System.Math.PI / 2);
|
2019-09-06 08:11:58 +00:00
|
|
|
|
|
2020-01-07 04:06:21 +00:00
|
|
|
|
var rectangleB = new Rectangle(-1, -1, 2, 2);
|
2020-01-05 00:13:07 +00:00
|
|
|
|
var transformB = new Transform2D(new Vector2(0, 0));
|
2019-09-06 08:11:58 +00:00
|
|
|
|
|
2020-01-01 01:45:42 +00:00
|
|
|
|
NarrowPhase.TestCollision(rectangleA, transformA, rectangleB, transformB).Should().BeTrue();
|
2019-09-06 08:11:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2020-01-01 01:45:42 +00:00
|
|
|
|
public void RectanglesTouchingGJK2D()
|
2019-09-06 08:11:58 +00:00
|
|
|
|
{
|
2020-01-07 04:06:21 +00:00
|
|
|
|
var rectangleA = new Rectangle(-1, -1, 2, 2);
|
2019-09-06 08:11:58 +00:00
|
|
|
|
var transformA = new Transform2D(new Position2D(-1, 0));
|
|
|
|
|
|
2020-01-07 04:06:21 +00:00
|
|
|
|
var rectangleB = new Rectangle(-1, -1, 2, 2);
|
2019-09-06 08:11:58 +00:00
|
|
|
|
var transformB = new Transform2D(new Vector2(1, 0));
|
|
|
|
|
|
2020-01-01 01:45:42 +00:00
|
|
|
|
NarrowPhase.TestCollision(rectangleA, transformA, rectangleB, transformB).Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void RectanglesOverlappingGJK2D()
|
|
|
|
|
{
|
2020-01-07 04:06:21 +00:00
|
|
|
|
var rectangleA = new Rectangle(-1, -1, 2, 2);
|
2020-01-01 01:45:42 +00:00
|
|
|
|
var transformA = new Transform2D(new Position2D(0, 0));
|
|
|
|
|
|
2020-01-07 04:06:21 +00:00
|
|
|
|
var rectangleB = new Rectangle(-1, -1, 2, 2);
|
2020-01-01 01:45:42 +00:00
|
|
|
|
var transformB = new Transform2D(new Vector2(1, 0));
|
|
|
|
|
|
|
|
|
|
NarrowPhase.TestCollision(rectangleA, transformA, rectangleB, transformB).Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void RectanglesTouchingOverlap()
|
|
|
|
|
{
|
2020-01-07 04:06:21 +00:00
|
|
|
|
var rectangleA = new Rectangle(-1, -1, 2, 2);
|
2020-01-01 01:45:42 +00:00
|
|
|
|
var transformA = new Transform2D(new Position2D(-1, 0));
|
|
|
|
|
|
2020-01-07 04:06:21 +00:00
|
|
|
|
var rectangleB = new Rectangle(-1, -1, 2, 2);
|
2020-01-01 01:45:42 +00:00
|
|
|
|
var transformB = new Transform2D(new Vector2(1, 0));
|
|
|
|
|
|
|
|
|
|
NarrowPhase.TestRectangleOverlap(rectangleA, transformA, rectangleB, transformB).Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void RectanglesOverlappingOverlap()
|
|
|
|
|
{
|
2020-01-07 04:06:21 +00:00
|
|
|
|
var rectangleA = new Rectangle(-1, -1, 2, 2);
|
2020-01-01 01:45:42 +00:00
|
|
|
|
var transformA = new Transform2D(new Position2D(0, 0));
|
|
|
|
|
|
2020-01-07 04:06:21 +00:00
|
|
|
|
var rectangleB = new Rectangle(-1, -1, 2, 2);
|
2020-01-05 21:35:49 +00:00
|
|
|
|
var transformB = new Transform2D(new Vector2(1, 0), 0, new Vector2(-1, 1));
|
2020-01-01 01:45:42 +00:00
|
|
|
|
|
|
|
|
|
NarrowPhase.TestRectangleOverlap(rectangleA, transformA, rectangleB, transformB).Should().BeTrue();
|
2019-09-06 08:11:58 +00:00
|
|
|
|
}
|
2020-01-02 09:40:03 +00:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void MultiRectanglesOverlapping()
|
|
|
|
|
{
|
2020-01-05 00:13:07 +00:00
|
|
|
|
var multiRectangleA = new MultiShape(
|
|
|
|
|
ImmutableArray.Create<(IShape2D, Transform2D)>(
|
2020-01-07 04:06:21 +00:00
|
|
|
|
(new Rectangle(-2, 0, 4, 1), new Transform2D(new Position2D(-5, 0))),
|
|
|
|
|
(new Rectangle(-2, 0, 4, 1), new Transform2D(new Position2D(-5, 1))),
|
|
|
|
|
(new Rectangle(-2, 0, 4, 1), new Transform2D(new Position2D(-5, 2)))
|
2020-01-02 09:40:03 +00:00
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
var transformA = new Transform2D(new Position2D(5, 0));
|
|
|
|
|
|
2020-01-05 00:13:07 +00:00
|
|
|
|
var multiRectangleB = new MultiShape(
|
|
|
|
|
ImmutableArray.Create<(IShape2D, Transform2D)>(
|
2020-01-07 04:06:21 +00:00
|
|
|
|
(new Rectangle(-2, 0, 4, 1), new Transform2D(new Position2D(4, -1))),
|
|
|
|
|
(new Rectangle(-2, 0, 4, 1), new Transform2D(new Position2D(4, 0))),
|
|
|
|
|
(new Rectangle(-2, 0, 4, 1), new Transform2D(new Position2D(4, 1)))
|
2020-01-02 09:40:03 +00:00
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
var transformB = new Transform2D(new Position2D(0, 3));
|
|
|
|
|
|
|
|
|
|
NarrowPhase.TestCollision(multiRectangleA, transformA, multiRectangleB, transformB).Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void MultiRectanglesNotOverlapping()
|
|
|
|
|
{
|
2020-01-05 00:13:07 +00:00
|
|
|
|
var multiRectangleA = new MultiShape(
|
|
|
|
|
ImmutableArray.Create<(IShape2D, Transform2D)>(
|
2020-01-07 04:06:21 +00:00
|
|
|
|
(new Rectangle(-2, 0, 4, 1), new Transform2D(new Position2D(-5, 0))),
|
|
|
|
|
(new Rectangle(-2, 0, 4, 1), new Transform2D(new Position2D(-5, 1))),
|
|
|
|
|
(new Rectangle(-2, 0, 4, 1), new Transform2D(new Position2D(-5, 2)))
|
2020-01-02 09:40:03 +00:00
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
var transformA = new Transform2D(new Position2D(5, 0));
|
|
|
|
|
|
2020-01-05 00:13:07 +00:00
|
|
|
|
var multiRectangleB = new MultiShape(
|
|
|
|
|
ImmutableArray.Create<(IShape2D, Transform2D)>(
|
2020-01-07 04:06:21 +00:00
|
|
|
|
(new Rectangle(-2, 0, 4, 1), new Transform2D(new Position2D(4, -1))),
|
|
|
|
|
(new Rectangle(-2, 0, 4, 1), new Transform2D(new Position2D(4, 0))),
|
|
|
|
|
(new Rectangle(-2, 0, 4, 1), new Transform2D(new Position2D(4, 1)))
|
2020-01-02 09:40:03 +00:00
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
var transformB = new Transform2D(new Position2D(0, -3));
|
|
|
|
|
|
|
|
|
|
NarrowPhase.TestCollision(multiRectangleA, transformA, multiRectangleB, transformB).Should().BeFalse();
|
|
|
|
|
}
|
2019-09-06 08:11:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|