mirror of
https://github.com/ppy/osu
synced 2025-04-10 11:11:48 +00:00
Merge pull request #208 from Tom94/fix-multi-segment-sliders
Add treatment of slider segments encoded by the same vertex appearing…
This commit is contained in:
commit
b56dec8f98
@ -13,17 +13,40 @@ namespace osu.Game.Modes.Osu.Objects
|
|||||||
|
|
||||||
private List<Vector2> calculatedPath;
|
private List<Vector2> calculatedPath;
|
||||||
|
|
||||||
public void Calculate()
|
private List<Vector2> calculateSubpath(List<Vector2> subpath)
|
||||||
{
|
{
|
||||||
switch (CurveType)
|
switch (CurveType)
|
||||||
{
|
{
|
||||||
case CurveTypes.Linear:
|
case CurveTypes.Linear:
|
||||||
calculatedPath = Path;
|
return subpath;
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
var bezier = new BezierApproximator(Path);
|
return new BezierApproximator(subpath).CreateBezier();
|
||||||
calculatedPath = bezier.CreateBezier();
|
}
|
||||||
break;
|
}
|
||||||
|
|
||||||
|
public void Calculate()
|
||||||
|
{
|
||||||
|
calculatedPath = new List<Vector2>();
|
||||||
|
|
||||||
|
// Sliders may consist of various subpaths separated by two consecutive vertices
|
||||||
|
// with the same position. The following loop parses these subpaths and computes
|
||||||
|
// their shape independently, consecutively appending them to calculatedPath.
|
||||||
|
List<Vector2> subpath = new List<Vector2>();
|
||||||
|
for (int i = 0; i < Path.Count; ++i)
|
||||||
|
{
|
||||||
|
subpath.Add(Path[i]);
|
||||||
|
if (i == Path.Count - 1 || Path[i] == Path[i + 1])
|
||||||
|
{
|
||||||
|
// If we already constructed a subpath previously, then the new subpath
|
||||||
|
// will have as starting position the end position of the previous subpath.
|
||||||
|
// Hence we can and should remove the previous endpoint to avoid a segment
|
||||||
|
// with 0 length.
|
||||||
|
if (calculatedPath.Count > 0)
|
||||||
|
calculatedPath.RemoveAt(calculatedPath.Count - 1);
|
||||||
|
|
||||||
|
calculatedPath.AddRange(calculateSubpath(subpath));
|
||||||
|
subpath.Clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user