2020-01-05 07:17:29 +00:00
|
|
|
|
using System.Numerics;
|
|
|
|
|
using FluentAssertions;
|
2020-02-21 08:03:47 +00:00
|
|
|
|
using MoonTools.Bonk;
|
|
|
|
|
using MoonTools.Structs;
|
2020-01-05 07:17:29 +00:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
|
|
namespace Tests
|
|
|
|
|
{
|
|
|
|
|
class SweepTestTest
|
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void SweepsThrough()
|
|
|
|
|
{
|
2020-01-07 04:06:21 +00:00
|
|
|
|
var rectangle = new Rectangle(-2, -2, 4, 4);
|
2020-01-05 07:17:29 +00:00
|
|
|
|
var transform = new Transform2D(new Position2D(-6, 0));
|
|
|
|
|
|
2020-01-07 04:06:21 +00:00
|
|
|
|
var otherRectangle = new Rectangle(-2, -2, 4, 4);
|
2020-01-05 07:17:29 +00:00
|
|
|
|
var otherTransform = new Transform2D(new Position2D(6, 0));
|
|
|
|
|
|
2020-01-07 04:06:21 +00:00
|
|
|
|
var farthestRectangle = new Rectangle(-2, -2, 4, 4);
|
2020-01-05 07:17:29 +00:00
|
|
|
|
var farthestTransform = new Transform2D(new Position2D(12, 0));
|
|
|
|
|
|
2020-01-07 04:06:21 +00:00
|
|
|
|
var downRectangle = new Rectangle(-6, -2, 12, 4);
|
2020-01-05 21:10:52 +00:00
|
|
|
|
var downTransform = new Transform2D(new Position2D(-6, 20));
|
|
|
|
|
|
2020-01-05 07:17:29 +00:00
|
|
|
|
var spatialHash = new SpatialHash<int>(16);
|
|
|
|
|
spatialHash.Insert(1, otherRectangle, otherTransform);
|
|
|
|
|
spatialHash.Insert(2, farthestRectangle, farthestTransform);
|
2020-01-05 21:10:52 +00:00
|
|
|
|
spatialHash.Insert(3, downRectangle, downTransform);
|
2020-01-05 07:17:29 +00:00
|
|
|
|
|
2020-01-06 09:38:13 +00:00
|
|
|
|
SweepTest.Test(spatialHash, rectangle, transform, new Vector2(12, 0)).Should().Be(
|
|
|
|
|
new SweepResult<int>(true, new Vector2(7, 0), 1)
|
2020-01-05 07:17:29 +00:00
|
|
|
|
);
|
|
|
|
|
|
2020-01-06 09:38:13 +00:00
|
|
|
|
SweepTest.Test(spatialHash, rectangle, transform, new Vector2(-12, 0)).Hit.Should().BeFalse();
|
2020-01-05 21:10:52 +00:00
|
|
|
|
|
2020-01-06 09:38:13 +00:00
|
|
|
|
SweepTest.Test(spatialHash, rectangle, transform, new Vector2(0, 20)).Should().Be(
|
|
|
|
|
new SweepResult<int>(true, new Vector2(0, 15), 3)
|
2020-01-05 21:10:52 +00:00
|
|
|
|
);
|
2020-01-05 07:17:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|