osukey/osu.Game/Rulesets/UI/Scrolling/Visualisers/ConstantSpeedChangeVisualiser.cs
2018-11-08 14:04:20 +09:00

29 lines
1.1 KiB
C#

// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
namespace osu.Game.Rulesets.UI.Scrolling.Visualisers
{
public readonly struct ConstantSpeedChangeVisualiser : ISpeedChangeVisualiser
{
private readonly double timeRange;
private readonly float scrollLength;
public ConstantSpeedChangeVisualiser(double timeRange, float scrollLength)
{
this.timeRange = timeRange;
this.scrollLength = scrollLength;
}
public double GetDisplayStartTime(double time) => time - timeRange;
public float GetLength(double startTime, double endTime)
{
// At the hitobject's end time, the hitobject will be positioned such that its end rests at the origin.
// This results in a negative-position value, and the absolute of it indicates the length of the hitobject.
return -PositionAt(startTime, endTime);
}
public float PositionAt(double time, double currentTime) => (float)((time - currentTime) / timeRange * scrollLength);
}
}