1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 05:02:56 +08:00

trim excess control points on drag end

This commit is contained in:
OliBomby 2024-06-01 21:15:54 +02:00
parent 7254096c90
commit ca41c84ba2

View File

@ -131,10 +131,39 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
{
if (!isDragging) return;
trimExcessControlPoints(Slider.Path);
isDragging = false;
editorBeatmap?.EndChange();
}
/// <summary>
/// Trims control points from the end of the slider path which are not required to reach the expected end of the slider.
/// </summary>
/// <param name="sliderPath">The slider path to trim control points of.</param>
private void trimExcessControlPoints(SliderPath sliderPath)
{
if (!sliderPath.ExpectedDistance.Value.HasValue)
return;
double[] segmentEnds = sliderPath.GetSegmentEnds().ToArray();
int segmentIndex = 0;
for (int i = 1; i < sliderPath.ControlPoints.Count - 1; i++)
{
if (!sliderPath.ControlPoints[i].Type.HasValue) continue;
if (Precision.AlmostBigger(segmentEnds[segmentIndex], 1, 1E-3))
{
sliderPath.ControlPoints.RemoveRange(i + 1, sliderPath.ControlPoints.Count - i - 1);
sliderPath.ControlPoints[^1].Type = null;
break;
}
segmentIndex++;
}
}
/// <summary>
/// Finds the expected distance value for which the slider end is closest to the mouse position.
/// </summary>