A game framework written with osu! in mind.
at master 74 lines 2.4 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using System; 5using System.Collections.Generic; 6using osu.Framework.Graphics; 7using osu.Framework.Graphics.Lines; 8using osu.Framework.Graphics.Sprites; 9using osu.Framework.Utils; 10using osu.Framework.Testing; 11using osuTK; 12using osuTK.Graphics; 13 14namespace osu.Framework.Tests.Visual.Drawables 15{ 16 public class TestScenePathApproximator : GridTestScene 17 { 18 public TestScenePathApproximator() 19 : base(2, 2) 20 { 21 Cell(0).AddRange(new[] 22 { 23 createLabel("ApproximateBezier"), 24 new ApproximatedPathTest(PathApproximator.ApproximateBezier), 25 }); 26 27 Cell(1).AddRange(new[] 28 { 29 createLabel("ApproximateCatmull"), 30 new ApproximatedPathTest(PathApproximator.ApproximateCatmull), 31 }); 32 33 Cell(2).AddRange(new[] 34 { 35 createLabel("ApproximateCircularArc"), 36 new ApproximatedPathTest(PathApproximator.ApproximateCircularArc), 37 }); 38 39 Cell(3).AddRange(new[] 40 { 41 createLabel("ApproximateLagrangePolynomial"), 42 new ApproximatedPathTest(PathApproximator.ApproximateLagrangePolynomial), 43 }); 44 } 45 46 private Drawable createLabel(string text) => new SpriteText 47 { 48 Text = text, 49 Font = new FontUsage(size: 20), 50 Colour = Color4.White, 51 }; 52 53 private class ApproximatedPathTest : SmoothPath 54 { 55 public delegate List<Vector2> ApproximatorFunc(ReadOnlySpan<Vector2> controlPoints); 56 57 public ApproximatedPathTest(ApproximatorFunc approximator) 58 { 59 Vector2[] points = new Vector2[5]; 60 points[0] = new Vector2(50, 250); 61 points[1] = new Vector2(150, 230); 62 points[2] = new Vector2(100, 150); 63 points[3] = new Vector2(200, 80); 64 points[4] = new Vector2(250, 50); 65 66 AutoSizeAxes = Axes.None; 67 RelativeSizeAxes = Axes.Both; 68 PathRadius = 2; 69 Vertices = approximator(points); 70 Colour = Color4.White; 71 } 72 } 73 } 74}