mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 07:23:14 +08:00
Fix snapped distances potentially exceeding the source distance
This results in slider placement including "excess" length, where the curve is not applied to the placed path. This is generally not what we want. I considered adding a bool parameter (or enum) to change the floor/rounding mode, but on further examination I think this is what we always expect from this function.
This commit is contained in:
parent
997ea2f27e
commit
6c7475f085
@ -169,17 +169,17 @@ namespace osu.Game.Tests.Editing
|
||||
[Test]
|
||||
public void GetSnappedDistanceFromDistance()
|
||||
{
|
||||
assertSnappedDistance(50, 100);
|
||||
assertSnappedDistance(50, 0);
|
||||
assertSnappedDistance(100, 100);
|
||||
assertSnappedDistance(150, 200);
|
||||
assertSnappedDistance(150, 100);
|
||||
assertSnappedDistance(200, 200);
|
||||
assertSnappedDistance(250, 300);
|
||||
assertSnappedDistance(250, 200);
|
||||
|
||||
AddStep("set slider multiplier = 2", () => composer.EditorBeatmap.BeatmapInfo.BaseDifficulty.SliderMultiplier = 2);
|
||||
|
||||
assertSnappedDistance(50, 0);
|
||||
assertSnappedDistance(100, 200);
|
||||
assertSnappedDistance(150, 200);
|
||||
assertSnappedDistance(100, 0);
|
||||
assertSnappedDistance(150, 0);
|
||||
assertSnappedDistance(200, 200);
|
||||
assertSnappedDistance(250, 200);
|
||||
|
||||
@ -190,8 +190,8 @@ namespace osu.Game.Tests.Editing
|
||||
});
|
||||
|
||||
assertSnappedDistance(50, 0);
|
||||
assertSnappedDistance(100, 200);
|
||||
assertSnappedDistance(150, 200);
|
||||
assertSnappedDistance(100, 0);
|
||||
assertSnappedDistance(150, 0);
|
||||
assertSnappedDistance(200, 200);
|
||||
assertSnappedDistance(250, 200);
|
||||
assertSnappedDistance(400, 400);
|
||||
|
@ -293,7 +293,13 @@ namespace osu.Game.Rulesets.Edit
|
||||
|
||||
public override float GetSnappedDistanceFromDistance(double referenceTime, float distance)
|
||||
{
|
||||
var snappedEndTime = BeatSnapProvider.SnapTime(referenceTime + DistanceToDuration(referenceTime, distance), referenceTime);
|
||||
double actualDuration = referenceTime + DistanceToDuration(referenceTime, distance);
|
||||
|
||||
double snappedEndTime = BeatSnapProvider.SnapTime(actualDuration, referenceTime);
|
||||
|
||||
// we don't want to exceed the actual duration and snap to a point in the future.
|
||||
if (snappedEndTime > actualDuration)
|
||||
snappedEndTime -= BeatSnapProvider.GetBeatLengthAtTime(referenceTime);
|
||||
|
||||
return DurationToDistance(referenceTime, snappedEndTime - referenceTime);
|
||||
}
|
||||
|
@ -47,6 +47,7 @@ namespace osu.Game.Rulesets.Edit
|
||||
|
||||
/// <summary>
|
||||
/// Converts an unsnapped distance to a snapped distance.
|
||||
/// The returned distance will always be floored (as to never exceed the provided <paramref name="distance"/>.
|
||||
/// </summary>
|
||||
/// <param name="referenceTime">The time of the timing point which <paramref name="distance"/> resides in.</param>
|
||||
/// <param name="distance">The distance to convert.</param>
|
||||
|
Loading…
Reference in New Issue
Block a user