mirror of
https://github.com/ppy/osu.git
synced 2024-11-19 07:33:21 +08:00
6dcd9427ac
This is quite a breaking change, but I think it is beneficial due to the large amount of usage of this class. I originally intended just to remove the allocations of the two delegates handling the `Changed` flow internally, but as nothing was really using the bindables for anything more than a general "point has changed" case, this felt like a better direction.
44 lines
1.4 KiB
C#
44 lines
1.4 KiB
C#
// 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.Linq;
|
|
using osu.Game.Rulesets.Objects.Types;
|
|
using osuTK;
|
|
|
|
#nullable enable
|
|
|
|
namespace osu.Game.Rulesets.Objects
|
|
{
|
|
public static class SliderPathExtensions
|
|
{
|
|
/// <summary>
|
|
/// Reverse the direction of this path.
|
|
/// </summary>
|
|
/// <param name="sliderPath">The <see cref="SliderPath"/>.</param>
|
|
/// <param name="positionalOffset">The positional offset of the resulting path. It should be added to the start position of this path.</param>
|
|
public static void Reverse(this SliderPath sliderPath, out Vector2 positionalOffset)
|
|
{
|
|
var points = sliderPath.ControlPoints.ToArray();
|
|
positionalOffset = points.Last().Position;
|
|
|
|
sliderPath.ControlPoints.Clear();
|
|
|
|
PathType? lastType = null;
|
|
|
|
for (var i = 0; i < points.Length; i++)
|
|
{
|
|
var p = points[i];
|
|
p.Position -= positionalOffset;
|
|
|
|
// propagate types forwards to last null type
|
|
if (i == points.Length - 1)
|
|
p.Type = lastType;
|
|
else if (p.Type != null)
|
|
(p.Type, lastType) = (lastType, p.Type);
|
|
|
|
sliderPath.ControlPoints.Insert(0, p);
|
|
}
|
|
}
|
|
}
|
|
}
|