Code cleanup

This commit is contained in:
Pasi4K5 2023-08-14 21:56:08 +02:00
parent 19c8b74a47
commit 449bee98cc
2 changed files with 11 additions and 11 deletions

View File

@ -35,16 +35,13 @@ public partial class TestSceneSliderReversal : TestSceneOsuEditor
private static PathControlPoint[] createPathSegment(PathType type, params Vector2[] positions)
{
return new[]
{
new PathControlPoint
{
Type = type
},
}.Concat(positions.Select(p => new PathControlPoint
return positions.Select(p => new PathControlPoint
{
Position = p
})).ToArray();
}).Prepend(new PathControlPoint
{
Type = type
}).ToArray();
}
[TestCase(0, 250)]

View File

@ -1,10 +1,10 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Utils;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects.Types;
using osuTK;
@ -41,7 +41,7 @@ public static void Reverse(this SliderPath sliderPath, out Vector2 positionalOff
double[] distinctSegmentEnds = segmentEnds.Distinct().ToArray();
// Remove control points at the end which do not affect the visual slider path ("invisible" control points).
if (segmentEnds.Length >= 2 && Math.Abs(segmentEnds[^1] - segmentEnds[^2]) < 1e-10 && distinctSegmentEnds.Length > 1)
if (segmentEnds.Length >= 2 && Precision.AlmostEquals(segmentEnds[^1], segmentEnds[^2]) && distinctSegmentEnds.Length > 1)
{
int numVisibleSegments = distinctSegmentEnds.Length - 2;
var nonInheritedControlPoints = controlPoints.Where(p => p.Type is not null).ToList();
@ -62,7 +62,10 @@ public static void Reverse(this SliderPath sliderPath, out Vector2 positionalOff
}
// Restore original control point types.
controlPoints.Zip(originalControlPointTypes).ForEach(x => x.First.Type = x.Second);
for (int i = 0; i < controlPoints.Count; i++)
{
controlPoints[i].Type = originalControlPointTypes[i];
}
// Recalculate perfect curve at the end of the slider path.
if (controlPoints.Count >= 3 && controlPoints[^3].Type == PathType.PerfectCurve && controlPoints[^2].Type is null && distinctSegmentEnds.Length > 1)