1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 04:43:22 +08:00

Make sure control points is internally initialised

This commit is contained in:
smoogipoo 2018-11-12 17:10:37 +09:00
parent f4fd6189f8
commit f3ba429701
2 changed files with 19 additions and 8 deletions

View File

@ -1,7 +1,6 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;

View File

@ -13,11 +13,6 @@ namespace osu.Game.Rulesets.Objects
{
public struct SliderPath : IEquatable<SliderPath>
{
/// <summary>
/// The control points of the path.
/// </summary>
public readonly Vector2[] ControlPoints;
/// <summary>
/// The user-set distance of the path. If non-null, <see cref="Distance"/> will match this value,
/// and the path will be shortened/lengthened to match this length.
@ -29,6 +24,9 @@ namespace osu.Game.Rulesets.Objects
/// </summary>
public readonly PathType Type;
[JsonProperty]
private Vector2[] controlPoints;
private List<Vector2> calculatedPath;
private List<double> cumulativeLength;
@ -46,14 +44,27 @@ namespace osu.Game.Rulesets.Objects
public SliderPath(PathType type, Vector2[] controlPoints, double? expectedDistance = null)
{
this = default;
this.controlPoints = controlPoints;
ControlPoints = controlPoints;
Type = type;
ExpectedDistance = expectedDistance;
ensureInitialised();
}
/// <summary>
/// The control points of the path.
/// </summary>
[JsonIgnore]
public ReadOnlySpan<Vector2> ControlPoints
{
get
{
ensureInitialised();
return controlPoints.AsSpan();
}
}
/// <summary>
/// The distance of the path after lengthening/shortening to account for <see cref="ExpectedDistance"/>.
/// </summary>
@ -116,6 +127,7 @@ namespace osu.Game.Rulesets.Objects
return;
isInitialised = true;
controlPoints = controlPoints ?? Array.Empty<Vector2>();
calculatedPath = new List<Vector2>();
cumulativeLength = new List<double>();
@ -166,7 +178,7 @@ namespace osu.Game.Rulesets.Objects
if (i == ControlPoints.Length - 1 || ControlPoints[i] == ControlPoints[i + 1])
{
ReadOnlySpan<Vector2> cpSpan = ControlPoints.AsSpan().Slice(start, end - start);
ReadOnlySpan<Vector2> cpSpan = ControlPoints.Slice(start, end - start);
foreach (Vector2 t in calculateSubpath(cpSpan))
if (calculatedPath.Count == 0 || calculatedPath.Last() != t)