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:
commit
7ab31b8256
@ -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]
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user