Cover area just outside circle in test

This commit is contained in:
Bartłomiej Dach 2020-03-06 22:09:02 +01:00
parent 77fd748035
commit b608764554

View File

@ -71,23 +71,23 @@ namespace osu.Game.Rulesets.Osu.Tests
AddAssert("hit registered", () => hitAreaReceptor.HitAction == OsuAction.LeftButton); AddAssert("hit registered", () => hitAreaReceptor.HitAction == OsuAction.LeftButton);
} }
[Test] [TestCase(0.95f, OsuAction.LeftButton)]
public void TestCircleHitTopLeftEdge() [TestCase(1.05f, null)]
public void TestHitsCloseToEdge(float relativeDistanceFromCentre, OsuAction? expectedAction)
{ {
AddStep("move mouse to top left circle edge", () => AddStep("move mouse to top left circle edge", () =>
{ {
var drawQuad = hitAreaReceptor.ScreenSpaceDrawQuad; var drawQuad = hitAreaReceptor.ScreenSpaceDrawQuad;
// sqrt(2) / 2 = sin(45deg) = cos(45deg) // sqrt(2) / 2 = sin(45deg) = cos(45deg)
// draw width halved to get radius // draw width halved to get radius
// 0.95f taken for leniency float correction = relativeDistanceFromCentre * (float)Math.Sqrt(2) / 2 * (drawQuad.Width / 2);
float correction = 0.95f * (float)Math.Sqrt(2) / 2 * (drawQuad.Width / 2);
var mousePosition = new Vector2(drawQuad.Centre.X - correction, drawQuad.Centre.Y - correction); var mousePosition = new Vector2(drawQuad.Centre.X - correction, drawQuad.Centre.Y - correction);
InputManager.MoveMouseTo(mousePosition); InputManager.MoveMouseTo(mousePosition);
}); });
scheduleHit(); scheduleHit();
AddAssert("hit registered", () => hitAreaReceptor.HitAction == OsuAction.LeftButton); AddAssert($"hit {(expectedAction == null ? "not " : string.Empty)}registered", () => hitAreaReceptor.HitAction == expectedAction);
} }
[Test] [Test]