1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 07:42:57 +08:00

Merge pull request #18234 from peppy/distance-snap-no-snap-to-zero

Fix distance snap providing zero-distance snaps incorrectly
This commit is contained in:
Dan Balasescu 2022-05-12 15:40:44 +09:00 committed by GitHub
commit 7ab31b8256
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -113,7 +113,14 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
public void TestCursorInCentre()
{
AddStep("move mouse to centre", () => InputManager.MoveMouseTo(grid.ToScreenSpace(grid_position)));
assertSnappedDistance(0);
assertSnappedDistance(beat_length);
}
[Test]
public void TestCursorAlmostInCentre()
{
AddStep("move mouse to almost centre", () => InputManager.MoveMouseTo(grid.ToScreenSpace(grid_position) + new Vector2(1)));
assertSnappedDistance(beat_length);
}
[Test]

View File

@ -76,14 +76,19 @@ namespace osu.Game.Screens.Edit.Compose.Components
Vector2 travelVector = (position - StartPosition);
// We need a non-zero travel vector in order to find a valid direction.
if (travelVector == Vector2.Zero)
return (StartPosition, StartTime);
travelVector = new Vector2(0, -1);
float travelLength = travelVector.Length;
// FindSnappedDistance will always round down, but we want to potentially round upwards.
travelLength += DistanceBetweenTicks / 2;
// We never want to snap towards zero.
if (travelLength < DistanceBetweenTicks)
travelLength = DistanceBetweenTicks;
// When interacting with the resolved snap provider, the distance spacing multiplier should first be removed
// to allow for snapping at a non-multiplied ratio.
float snappedDistance = SnapProvider.FindSnappedDistance(ReferenceObject, travelLength / distanceSpacingMultiplier);