forked from ppy/osu-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ppy#6066 from OliBomby/betterer-builder
Improve incremental B-spline builder via stochastic optimisation
- Loading branch information
Showing
4 changed files
with
310 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// 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.Linq; | ||
using osu.Framework.Graphics; | ||
using osuTK.Graphics; | ||
using osu.Framework.Graphics.Containers; | ||
|
@@ -18,6 +19,7 @@ public partial class TestSceneInteractivePathDrawing : FrameworkTestScene | |
{ | ||
private readonly Path rawDrawnPath; | ||
private readonly Path approximatedDrawnPath; | ||
private readonly Path controlPointPath; | ||
private readonly Container controlPointViz; | ||
|
||
private readonly IncrementalBSplineBuilder bSplineBuilder = new IncrementalBSplineBuilder(); | ||
|
@@ -39,6 +41,12 @@ public TestSceneInteractivePathDrawing() | |
Colour = Color4.Blue, | ||
PathRadius = 3, | ||
}, | ||
controlPointPath = new Path | ||
{ | ||
Colour = Color4.LightGreen, | ||
PathRadius = 1, | ||
Alpha = 0.5f, | ||
}, | ||
controlPointViz = new Container | ||
{ | ||
RelativeSizeAxes = Axes.Both, | ||
|
@@ -55,11 +63,11 @@ public TestSceneInteractivePathDrawing() | |
bSplineBuilder.Clear(); | ||
}); | ||
|
||
AddSliderStep($"{nameof(bSplineBuilder.Degree)}", 1, 5, 3, v => | ||
AddSliderStep($"{nameof(bSplineBuilder.Degree)}", 1, 4, 3, v => | ||
{ | ||
bSplineBuilder.Degree = v; | ||
}); | ||
AddSliderStep($"{nameof(bSplineBuilder.Tolerance)}", 0f, 3f, 1.5f, v => | ||
AddSliderStep($"{nameof(bSplineBuilder.Tolerance)}", 0f, 3f, 2f, v => | ||
{ | ||
bSplineBuilder.Tolerance = v; | ||
}); | ||
|
@@ -71,17 +79,21 @@ public TestSceneInteractivePathDrawing() | |
|
||
private void updateControlPointsViz() | ||
{ | ||
controlPointPath.Vertices = bSplineBuilder.ControlPoints.SelectMany(o => o).ToArray(); | ||
controlPointViz.Clear(); | ||
|
||
foreach (var cp in bSplineBuilder.ControlPoints) | ||
foreach (var segment in bSplineBuilder.ControlPoints) | ||
{ | ||
controlPointViz.Add(new Box | ||
foreach (var cp in segment) | ||
{ | ||
Origin = Anchor.Centre, | ||
Size = new Vector2(10), | ||
Position = cp, | ||
Colour = Color4.LightGreen, | ||
}); | ||
controlPointViz.Add(new Box | ||
{ | ||
Origin = Anchor.Centre, | ||
Size = new Vector2(10), | ||
Position = cp, | ||
Colour = Color4.LightGreen, | ||
}); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -109,5 +121,13 @@ protected override void OnDrag(DragEvent e) | |
{ | ||
bSplineBuilder.AddLinearPoint(rawDrawnPath.ToLocalSpace(ToScreenSpace(e.MousePosition))); | ||
} | ||
|
||
protected override void OnDragEnd(DragEndEvent e) | ||
{ | ||
if (e.Button == MouseButton.Left) | ||
bSplineBuilder.Finish(); | ||
|
||
base.OnDragEnd(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.