From 83265f58384a9f923c71694001a8e53187918f3a Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Tue, 29 Aug 2023 12:23:20 +0200 Subject: [PATCH] Added TestCase for which CheckSweptTriangleCellCollision does not terminate. --- components/NavigationComponent.cs | 2 +- tests/NavigationComponentTests.cs | 43 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 tests/NavigationComponentTests.cs diff --git a/components/NavigationComponent.cs b/components/NavigationComponent.cs index aa0cc89..f8e97e4 100644 --- a/components/NavigationComponent.cs +++ b/components/NavigationComponent.cs @@ -278,7 +278,7 @@ public class NavigationComponent : Spatial } - bool CheckSweptTriangleCellCollision(Vector3 startWorld, Vector3 endWorld, float radius) + public bool CheckSweptTriangleCellCollision(Vector3 startWorld, Vector3 endWorld, float radius) { Vector2 startPlane = new Vector2(startWorld.x, startWorld.z); Vector2 endPlane = new Vector2(endWorld.x, endWorld.z); diff --git a/tests/NavigationComponentTests.cs b/tests/NavigationComponentTests.cs new file mode 100644 index 0000000..b7c8e8f --- /dev/null +++ b/tests/NavigationComponentTests.cs @@ -0,0 +1,43 @@ +using Godot; +using GoDotTest; +using System.Diagnostics; +using System.Linq; +using Xunit; + +public class NavigationComponentTests : TestClass +{ + private Node _testScene = null; + private TileWorld _tileWorld; + private NavigationComponent _navigationComponent; + private KinematicBody _kinematicBody; + + private PackedScene _tileWorldScene = GD.Load("res://scenes/TileWorld.tscn"); + + public NavigationComponentTests(Node testScene) : base(testScene) + { + _testScene = testScene; + } + + [Setup] + public void Setup() + { + _tileWorld = (TileWorld)_tileWorldScene.Instance(); + _tileWorld.HexGrid = new HexGrid(); + _testScene.AddChild(_tileWorld); + _kinematicBody = new KinematicBody(); + _navigationComponent = new NavigationComponent(); + _navigationComponent.TileWorld = _tileWorld; + } + + [Test] + public void SimpleTest() + { + _tileWorld.HexGrid.AddObstacle(HexCell.FromOffsetCoords(new Vector2 (-4, 7))); + + Vector3 startPoint = new Vector3(-2.25f, 1.2f, -4.76314f); + Vector3 endPoint = new Vector3(-2.533157f, 1.2f, -5.872417f); + + bool isBlocked = _navigationComponent.CheckSweptTriangleCellCollision(startPoint, endPoint, 0.27f); + } + +} \ No newline at end of file