forked from MoonsideGames/MoonTools.Bonk
fix sweep test correction sign
parent
354912d674
commit
38f5180a45
|
@ -106,8 +106,8 @@ namespace MoonTools.Core.Bonk
|
||||||
if (nearestRectangle.HasValue)
|
if (nearestRectangle.HasValue)
|
||||||
{
|
{
|
||||||
var overlapPosition = ray * shortestDistance;
|
var overlapPosition = ray * shortestDistance;
|
||||||
var correctionX = ray.X > 0 ? -1 : 1;
|
var correctionX = -Math.Sign(ray.X);
|
||||||
var correctionY = ray.Y > 0 ? -1 : 1;
|
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);
|
return new SweepResult<T, Rectangle>(true, new Position2D((int)overlapPosition.X + correctionX, (int)overlapPosition.Y + correctionY), nearestID, nearestRectangle.Value, nearestTransform.Value);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -29,13 +29,13 @@ namespace Tests
|
||||||
spatialHash.Insert(3, downRectangle, downTransform);
|
spatialHash.Insert(3, downRectangle, downTransform);
|
||||||
|
|
||||||
SweepTest.Rectangle(spatialHash, rectangle, transform, new Vector2(12, 0)).Should().Be(
|
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(-12, 0)).Hit.Should().BeFalse();
|
||||||
|
|
||||||
SweepTest.Rectangle(spatialHash, rectangle, transform, new Vector2(0, 20)).Should().Be(
|
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)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue