fix sweep test correction sign

multishape
Evan Hemsley 2020-01-05 13:14:06 -08:00
parent 354912d674
commit 38f5180a45
2 changed files with 4 additions and 4 deletions

View File

@ -106,8 +106,8 @@ namespace MoonTools.Core.Bonk
if (nearestRectangle.HasValue)
{
var overlapPosition = ray * shortestDistance;
var correctionX = ray.X > 0 ? -1 : 1;
var correctionY = ray.Y > 0 ? -1 : 1;
var correctionX = -Math.Sign(ray.X);
var correctionY = -Math.Sign(ray.Y);
return new SweepResult<T, Rectangle>(true, new Position2D((int)overlapPosition.X + correctionX, (int)overlapPosition.Y + correctionY), nearestID, nearestRectangle.Value, nearestTransform.Value);
}
else

View File

@ -29,13 +29,13 @@ namespace Tests
spatialHash.Insert(3, downRectangle, downTransform);
SweepTest.Rectangle(spatialHash, rectangle, transform, new Vector2(12, 0)).Should().Be(
new SweepResult<int, Rectangle>(true, new Vector2(8, 0), 1, otherRectangle, otherTransform)
new SweepResult<int, Rectangle>(true, new Vector2(7, 0), 1, otherRectangle, otherTransform)
);
SweepTest.Rectangle(spatialHash, rectangle, transform, new Vector2(-12, 0)).Hit.Should().BeFalse();
SweepTest.Rectangle(spatialHash, rectangle, transform, new Vector2(0, 20)).Should().Be(
new SweepResult<int, Rectangle>(true, new Vector2(0, 16), 3, downRectangle, downTransform)
new SweepResult<int, Rectangle>(true, new Vector2(0, 15), 3, downRectangle, downTransform)
);
}
}