1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-12 15:52:55 +08:00

Replace .Distinct() with truncateEndingDuplicates()

This commit is contained in:
Pasi4K5 2023-08-16 01:14:25 +02:00
parent 6346872c39
commit e7e0c49f42

View File

@ -42,7 +42,7 @@ namespace osu.Game.Rulesets.Objects
inheritedLinearPoints.ForEach(p => p.Type = PathType.Linear);
double[] segmentEnds = sliderPath.GetSegmentEnds().ToArray();
double[] distinctSegmentEnds = segmentEnds.Distinct().ToArray();
double[] distinctSegmentEnds = truncateEndingDuplicates(segmentEnds);
// Remove control points at the end which do not affect the visual slider path ("invisible" control points).
if (segmentEnds.Length >= 2 && Precision.AlmostEquals(segmentEnds[^1], segmentEnds[^2]) && distinctSegmentEnds.Length > 1)
@ -83,6 +83,24 @@ namespace osu.Game.Rulesets.Objects
sliderPath.reverseControlPoints(out positionalOffset);
}
/// <summary>
/// Keeps removing the last element of the provided array until the last two elements are not equal.
/// </summary>
/// <param name="arr">The array to truncate.</param>
/// <returns>The truncated array.</returns>
private static double[] truncateEndingDuplicates(double[] arr)
{
if (arr.Length < 2)
return arr;
var result = arr.ToList();
while (Precision.AlmostEquals(result[^1], result[^2]))
result.RemoveAt(result.Count - 1);
return result.ToArray();
}
/// <summary>
/// Reverses the order of the provided <see cref="SliderPath"/>'s <see cref="PathControlPoint"/>s.
/// </summary>