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) private static PathControlPoint[] createPathSegment(PathType type, params Vector2[] positions)
{ {
return new[] return positions.Select(p => new PathControlPoint
{
new PathControlPoint
{
Type = type
},
}.Concat(positions.Select(p => new PathControlPoint
{ {
Position = p Position = p
})).ToArray(); }).Prepend(new PathControlPoint
{
Type = type
}).ToArray();
} }
[TestCase(0, 250)] [TestCase(0, 250)]

View File

@ -1,10 +1,10 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Utils;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Objects.Types;
using osuTK; using osuTK;
@ -41,7 +41,7 @@ public static void Reverse(this SliderPath sliderPath, out Vector2 positionalOff
double[] distinctSegmentEnds = segmentEnds.Distinct().ToArray(); double[] distinctSegmentEnds = segmentEnds.Distinct().ToArray();
// Remove control points at the end which do not affect the visual slider path ("invisible" control points). // 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; int numVisibleSegments = distinctSegmentEnds.Length - 2;
var nonInheritedControlPoints = controlPoints.Where(p => p.Type is not null).ToList(); 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. // 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. // 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) if (controlPoints.Count >= 3 && controlPoints[^3].Type == PathType.PerfectCurve && controlPoints[^2].Type is null && distinctSegmentEnds.Length > 1)