Skip to content

Commit

Permalink
Merge pull request #6047 from Tom94/better-path-drawing
Browse files Browse the repository at this point in the history
IncrementalBSplineBuilder: rewrite algorithm with many improvements
  • Loading branch information
bdach authored Nov 17, 2023
2 parents 5e84e6b + f031906 commit 0fd08a3
Show file tree
Hide file tree
Showing 4 changed files with 302 additions and 71 deletions.
21 changes: 21 additions & 0 deletions osu.Framework.Tests/MathUtils/TestPathApproximator.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. 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;
Expand Down Expand Up @@ -40,5 +42,24 @@ public void TestBSpline()
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<ArgumentOutOfRangeException>(() => PathApproximator.BSplineToPiecewiseLinear(points, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => 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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,21 @@ public TestSceneInteractivePathDrawing()
{
bSplineBuilder.Degree = v;
});
AddSliderStep($"{nameof(bSplineBuilder.Tolerance)}", 0f, 1f, 0.1f, v =>
AddSliderStep($"{nameof(bSplineBuilder.Tolerance)}", 0f, 3f, 1.5f, v =>
{
bSplineBuilder.Tolerance = v;
});
AddSliderStep($"{nameof(bSplineBuilder.CornerThreshold)}", 0f, 1f, 0.4f, v =>
{
bSplineBuilder.CornerThreshold = v;
});
}

private void updateControlPointsViz()
{
controlPointViz.Clear();

foreach (var cp in bSplineBuilder.GetControlPoints())
foreach (var cp in bSplineBuilder.ControlPoints)
{
controlPointViz.Add(new Box
{
Expand Down
Loading

0 comments on commit 0fd08a3

Please sign in to comment.