From 9796fcff520b52a150cb469c046d13a42a0cc543 Mon Sep 17 00:00:00 2001 From: OliBomby Date: Sun, 31 Dec 2023 16:59:46 +0100 Subject: [PATCH] Merge position snap grid tests into single file --- .../TestSceneCircularPositionSnapGrid.cs | 111 ----------------- ...apGrid.cs => TestScenePositionSnapGrid.cs} | 51 +++++++- .../TestSceneTriangularPositionSnapGrid.cs | 112 ------------------ 3 files changed, 48 insertions(+), 226 deletions(-) delete mode 100644 osu.Game.Tests/Visual/Editing/TestSceneCircularPositionSnapGrid.cs rename osu.Game.Tests/Visual/Editing/{TestSceneRectangularPositionSnapGrid.cs => TestScenePositionSnapGrid.cs} (66%) delete mode 100644 osu.Game.Tests/Visual/Editing/TestSceneTriangularPositionSnapGrid.cs diff --git a/osu.Game.Tests/Visual/Editing/TestSceneCircularPositionSnapGrid.cs b/osu.Game.Tests/Visual/Editing/TestSceneCircularPositionSnapGrid.cs deleted file mode 100644 index 4481199c94..0000000000 --- a/osu.Game.Tests/Visual/Editing/TestSceneCircularPositionSnapGrid.cs +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -#nullable disable - -using System; -using NUnit.Framework; -using osu.Framework.Allocation; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Shapes; -using osu.Framework.Input.Events; -using osu.Game.Screens.Edit.Compose.Components; -using osuTK; -using osuTK.Graphics; - -namespace osu.Game.Tests.Visual.Editing -{ - public partial class TestSceneCircularPositionSnapGrid : OsuManualInputManagerTestScene - { - private Container content; - protected override Container Content => content; - - [BackgroundDependencyLoader] - private void load() - { - base.Content.AddRange(new Drawable[] - { - new Box - { - RelativeSizeAxes = Axes.Both, - Colour = Colour4.Gray - }, - content = new Container - { - RelativeSizeAxes = Axes.Both, - Padding = new MarginPadding(10), - } - }); - } - - private static readonly object[][] test_cases = - { - new object[] { new Vector2(0, 0), 10, 0f }, - new object[] { new Vector2(240, 180), 10, 10f }, - new object[] { new Vector2(160, 120), 30, -10f }, - new object[] { new Vector2(480, 360), 100, 0f }, - }; - - [TestCaseSource(nameof(test_cases))] - public void TestCircularGrid(Vector2 position, float spacing, float rotation) - { - CircularPositionSnapGrid grid = null; - - AddStep("create grid", () => - { - Child = grid = new CircularPositionSnapGrid - { - RelativeSizeAxes = Axes.Both, - }; - grid.StartPosition.Value = position; - grid.Spacing.Value = spacing; - }); - - AddStep("add snapping cursor", () => Add(new SnappingCursorContainer - { - RelativeSizeAxes = Axes.Both, - GetSnapPosition = pos => grid.GetSnappedPosition(grid.ToLocalSpace(pos)) - })); - } - - private partial class SnappingCursorContainer : CompositeDrawable - { - public Func GetSnapPosition; - - private readonly Drawable cursor; - - public SnappingCursorContainer() - { - RelativeSizeAxes = Axes.Both; - - InternalChild = cursor = new Circle - { - Origin = Anchor.Centre, - Size = new Vector2(50), - Colour = Color4.Red - }; - } - - protected override void LoadComplete() - { - base.LoadComplete(); - - updatePosition(GetContainingInputManager().CurrentState.Mouse.Position); - } - - protected override bool OnMouseMove(MouseMoveEvent e) - { - base.OnMouseMove(e); - - updatePosition(e.ScreenSpaceMousePosition); - return true; - } - - private void updatePosition(Vector2 screenSpacePosition) - { - cursor.Position = GetSnapPosition.Invoke(screenSpacePosition); - } - } - } -} diff --git a/osu.Game.Tests/Visual/Editing/TestSceneRectangularPositionSnapGrid.cs b/osu.Game.Tests/Visual/Editing/TestScenePositionSnapGrid.cs similarity index 66% rename from osu.Game.Tests/Visual/Editing/TestSceneRectangularPositionSnapGrid.cs rename to osu.Game.Tests/Visual/Editing/TestScenePositionSnapGrid.cs index 19903737f6..7e66edc2dd 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneRectangularPositionSnapGrid.cs +++ b/osu.Game.Tests/Visual/Editing/TestScenePositionSnapGrid.cs @@ -16,7 +16,7 @@ using osuTK.Graphics; namespace osu.Game.Tests.Visual.Editing { - public partial class TestSceneRectangularPositionSnapGrid : OsuManualInputManagerTestScene + public partial class TestScenePositionSnapGrid : OsuManualInputManagerTestScene { private Container content; protected override Container Content => content; @@ -42,8 +42,8 @@ namespace osu.Game.Tests.Visual.Editing private static readonly object[][] test_cases = { new object[] { new Vector2(0, 0), new Vector2(10, 10), 0f }, - new object[] { new Vector2(240, 180), new Vector2(10, 15), 30f }, - new object[] { new Vector2(160, 120), new Vector2(30, 20), -30f }, + new object[] { new Vector2(240, 180), new Vector2(10, 15), 10f }, + new object[] { new Vector2(160, 120), new Vector2(30, 20), -10f }, new object[] { new Vector2(480, 360), new Vector2(100, 100), 0f }, }; @@ -70,6 +70,51 @@ namespace osu.Game.Tests.Visual.Editing })); } + [TestCaseSource(nameof(test_cases))] + public void TestTriangularGrid(Vector2 position, Vector2 spacing, float rotation) + { + TriangularPositionSnapGrid grid = null; + + AddStep("create grid", () => + { + Child = grid = new TriangularPositionSnapGrid + { + RelativeSizeAxes = Axes.Both, + }; + grid.StartPosition.Value = position; + grid.Spacing.Value = spacing.X; + grid.GridLineRotation.Value = rotation; + }); + + AddStep("add snapping cursor", () => Add(new SnappingCursorContainer + { + RelativeSizeAxes = Axes.Both, + GetSnapPosition = pos => grid.GetSnappedPosition(grid.ToLocalSpace(pos)) + })); + } + + [TestCaseSource(nameof(test_cases))] + public void TestCircularGrid(Vector2 position, Vector2 spacing, float rotation) + { + CircularPositionSnapGrid grid = null; + + AddStep("create grid", () => + { + Child = grid = new CircularPositionSnapGrid + { + RelativeSizeAxes = Axes.Both, + }; + grid.StartPosition.Value = position; + grid.Spacing.Value = spacing.X; + }); + + AddStep("add snapping cursor", () => Add(new SnappingCursorContainer + { + RelativeSizeAxes = Axes.Both, + GetSnapPosition = pos => grid.GetSnappedPosition(grid.ToLocalSpace(pos)) + })); + } + private partial class SnappingCursorContainer : CompositeDrawable { public Func GetSnapPosition; diff --git a/osu.Game.Tests/Visual/Editing/TestSceneTriangularPositionSnapGrid.cs b/osu.Game.Tests/Visual/Editing/TestSceneTriangularPositionSnapGrid.cs deleted file mode 100644 index b1f82fa114..0000000000 --- a/osu.Game.Tests/Visual/Editing/TestSceneTriangularPositionSnapGrid.cs +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -#nullable disable - -using System; -using NUnit.Framework; -using osu.Framework.Allocation; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Shapes; -using osu.Framework.Input.Events; -using osu.Game.Screens.Edit.Compose.Components; -using osuTK; -using osuTK.Graphics; - -namespace osu.Game.Tests.Visual.Editing -{ - public partial class TestSceneTriangularPositionSnapGrid : OsuManualInputManagerTestScene - { - private Container content; - protected override Container Content => content; - - [BackgroundDependencyLoader] - private void load() - { - base.Content.AddRange(new Drawable[] - { - new Box - { - RelativeSizeAxes = Axes.Both, - Colour = Colour4.Gray - }, - content = new Container - { - RelativeSizeAxes = Axes.Both, - Padding = new MarginPadding(10), - } - }); - } - - private static readonly object[][] test_cases = - { - new object[] { new Vector2(0, 0), 10, 0f }, - new object[] { new Vector2(240, 180), 10, 10f }, - new object[] { new Vector2(160, 120), 30, -10f }, - new object[] { new Vector2(480, 360), 100, 0f }, - }; - - [TestCaseSource(nameof(test_cases))] - public void TestTriangularGrid(Vector2 position, float spacing, float rotation) - { - TriangularPositionSnapGrid grid = null; - - AddStep("create grid", () => - { - Child = grid = new TriangularPositionSnapGrid - { - RelativeSizeAxes = Axes.Both, - }; - grid.StartPosition.Value = position; - grid.Spacing.Value = spacing; - grid.GridLineRotation.Value = rotation; - }); - - AddStep("add snapping cursor", () => Add(new SnappingCursorContainer - { - RelativeSizeAxes = Axes.Both, - GetSnapPosition = pos => grid.GetSnappedPosition(grid.ToLocalSpace(pos)) - })); - } - - private partial class SnappingCursorContainer : CompositeDrawable - { - public Func GetSnapPosition; - - private readonly Drawable cursor; - - public SnappingCursorContainer() - { - RelativeSizeAxes = Axes.Both; - - InternalChild = cursor = new Circle - { - Origin = Anchor.Centre, - Size = new Vector2(50), - Colour = Color4.Red - }; - } - - protected override void LoadComplete() - { - base.LoadComplete(); - - updatePosition(GetContainingInputManager().CurrentState.Mouse.Position); - } - - protected override bool OnMouseMove(MouseMoveEvent e) - { - base.OnMouseMove(e); - - updatePosition(e.ScreenSpaceMousePosition); - return true; - } - - private void updatePosition(Vector2 screenSpacePosition) - { - cursor.Position = GetSnapPosition.Invoke(screenSpacePosition); - } - } - } -}