mirror of
https://github.com/ppy/osu.git
synced 2025-02-19 11:23:23 +08:00
Improve code readability and add assertion to test scene
This commit is contained in:
parent
cd70673463
commit
6346872c39
@ -48,8 +48,8 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
|
|||||||
|
|
||||||
[TestCase(0, 250)]
|
[TestCase(0, 250)]
|
||||||
[TestCase(0, 200)]
|
[TestCase(0, 200)]
|
||||||
[TestCase(1, 80)]
|
|
||||||
[TestCase(1, 120)]
|
[TestCase(1, 120)]
|
||||||
|
[TestCase(1, 80)]
|
||||||
public void TestSliderReversal(int pathIndex, double length)
|
public void TestSliderReversal(int pathIndex, double length)
|
||||||
{
|
{
|
||||||
var controlPoints = paths[pathIndex];
|
var controlPoints = paths[pathIndex];
|
||||||
@ -57,6 +57,7 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
|
|||||||
Vector2 oldStartPos = default;
|
Vector2 oldStartPos = default;
|
||||||
Vector2 oldEndPos = default;
|
Vector2 oldEndPos = default;
|
||||||
double oldDistance = default;
|
double oldDistance = default;
|
||||||
|
var oldControlPointTypes = controlPoints.Select(p => p.Type);
|
||||||
|
|
||||||
AddStep("Add slider", () =>
|
AddStep("Add slider", () =>
|
||||||
{
|
{
|
||||||
@ -97,6 +98,13 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
|
|||||||
|
|
||||||
AddAssert("Slider has correct end position", () =>
|
AddAssert("Slider has correct end position", () =>
|
||||||
Vector2.Distance(selectedSlider.EndPosition, oldStartPos) < 1);
|
Vector2.Distance(selectedSlider.EndPosition, oldStartPos) < 1);
|
||||||
|
|
||||||
|
AddAssert("Control points have correct types", () =>
|
||||||
|
{
|
||||||
|
var newControlPointTypes = selectedSlider.Path.ControlPoints.Select(p => p.Type).ToArray();
|
||||||
|
|
||||||
|
return oldControlPointTypes.Take(newControlPointTypes.Length).SequenceEqual(newControlPointTypes);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
|
||||||
using osu.Framework.Utils;
|
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;
|
||||||
@ -30,12 +29,17 @@ namespace osu.Game.Rulesets.Objects
|
|||||||
public static void Reverse(this SliderPath sliderPath, out Vector2 positionalOffset)
|
public static void Reverse(this SliderPath sliderPath, out Vector2 positionalOffset)
|
||||||
{
|
{
|
||||||
var controlPoints = sliderPath.ControlPoints;
|
var controlPoints = sliderPath.ControlPoints;
|
||||||
var originalControlPointTypes = controlPoints.Select(p => p.Type).ToArray();
|
|
||||||
|
|
||||||
controlPoints[0].Type ??= PathType.Linear;
|
var inheritedLinearPoints = controlPoints.Where(p => sliderPath.PointsInSegment(p)[0].Type == PathType.Linear && p.Type is null).ToList();
|
||||||
|
|
||||||
// Inherited points after a linear point should be treated as linear points.
|
if (controlPoints[0].Type == null)
|
||||||
controlPoints.Where(p => sliderPath.PointsInSegment(p)[0].Type == PathType.Linear).ForEach(p => p.Type = PathType.Linear);
|
{
|
||||||
|
inheritedLinearPoints.Add(controlPoints[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inherited points after a linear point, as well as the first control point if it inherited,
|
||||||
|
// should be treated as linear points, so their types are temporarily changed to linear.
|
||||||
|
inheritedLinearPoints.ForEach(p => p.Type = PathType.Linear);
|
||||||
|
|
||||||
double[] segmentEnds = sliderPath.GetSegmentEnds().ToArray();
|
double[] segmentEnds = sliderPath.GetSegmentEnds().ToArray();
|
||||||
double[] distinctSegmentEnds = segmentEnds.Distinct().ToArray();
|
double[] distinctSegmentEnds = segmentEnds.Distinct().ToArray();
|
||||||
@ -62,10 +66,7 @@ namespace osu.Game.Rulesets.Objects
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Restore original control point types.
|
// Restore original control point types.
|
||||||
for (int i = 0; i < controlPoints.Count; i++)
|
inheritedLinearPoints.ForEach(p => p.Type = null);
|
||||||
{
|
|
||||||
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user