// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System.Linq; using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Objects.Types; using osuTK; namespace osu.Game.Rulesets.Objects { public static class SliderPathExtensions { /// /// Snaps the provided 's duration using the . /// public static void SnapTo(this THitObject hitObject, IDistanceSnapProvider? snapProvider) where THitObject : HitObject, IHasPath { hitObject.Path.ExpectedDistance.Value = snapProvider?.FindSnappedDistance(hitObject, (float)hitObject.Path.CalculatedDistance) ?? hitObject.Path.CalculatedDistance; } /// /// Reverse the direction of this path. /// /// The . /// The positional offset of the resulting path. It should be added to the start position of this path. public static void Reverse(this SliderPath sliderPath, out Vector2 positionalOffset) { var points = sliderPath.ControlPoints.ToArray(); positionalOffset = sliderPath.PositionAt(1); sliderPath.ControlPoints.Clear(); PathType? lastType = null; for (int 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; p.Position = Vector2.Zero; } else if (p.Type != null) (p.Type, lastType) = (lastType, p.Type); sliderPath.ControlPoints.Insert(0, p); } } } }