diff --git a/Bonk/SweepTest/SweepTest.cs b/Bonk/SweepTest/SweepTest.cs index 65ea470..4dd53d4 100644 --- a/Bonk/SweepTest/SweepTest.cs +++ b/Bonk/SweepTest/SweepTest.cs @@ -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(true, new Position2D((int)overlapPosition.X + correctionX, (int)overlapPosition.Y + correctionY), nearestID, nearestRectangle.Value, nearestTransform.Value); } else diff --git a/Test/SweepTestTest.cs b/Test/SweepTestTest.cs index cf07de6..7b9dceb 100644 --- a/Test/SweepTestTest.cs +++ b/Test/SweepTestTest.cs @@ -29,13 +29,13 @@ namespace Tests spatialHash.Insert(3, downRectangle, downTransform); SweepTest.Rectangle(spatialHash, rectangle, transform, new Vector2(12, 0)).Should().Be( - new SweepResult(true, new Vector2(8, 0), 1, otherRectangle, otherTransform) + new SweepResult(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(true, new Vector2(0, 16), 3, downRectangle, downTransform) + new SweepResult(true, new Vector2(0, 15), 3, downRectangle, downTransform) ); } }