diff --git a/osu.Framework.Tests/MathUtils/TestPathApproximator.cs b/osu.Framework.Tests/MathUtils/TestPathApproximator.cs index f545f42a2..8b32b06d7 100644 --- a/osu.Framework.Tests/MathUtils/TestPathApproximator.cs +++ b/osu.Framework.Tests/MathUtils/TestPathApproximator.cs @@ -1,7 +1,9 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using System.Collections.Generic; +using System.Linq; using NUnit.Framework; using osu.Framework.Utils; using osuTK; @@ -40,5 +42,24 @@ namespace osu.Framework.Tests.MathUtils Assert.True(Precision.AlmostEquals(approximated[28], points[6], 1e-4f)); Assert.True(Precision.AlmostEquals(approximated[10], new Vector2(-0.11415f, -0.69065f), 1e-4f)); } + + [Test] + public void TestBSplineThrowsOnInvalidDegree() + { + Vector2[] points = { new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, -1), new Vector2(-1, -1), new Vector2(-1, 1), new Vector2(3, 2), new Vector2(3, 0) }; + + Assert.Throws(() => PathApproximator.BSplineToPiecewiseLinear(points, 0)); + Assert.Throws(() => PathApproximator.BSplineToPiecewiseLinear(points, -5)); + } + + [TestCase(0)] + [TestCase(1)] + public void TestBSplineDoesNothingWhenGivenTooFewPoints(int pointCount) + { + var points = Enumerable.Repeat(new Vector2(), pointCount).ToArray(); + + Assert.That(PathApproximator.BSplineToPiecewiseLinear(points, 3), Is.EquivalentTo(points)); + Assert.That(PathApproximator.BezierToPiecewiseLinear(points), Is.EquivalentTo(points)); + } } }