2023-03-14 08:02:43 +03:00
|
|
|
/*
|
|
|
|
recast4j copyright (c) 2021 Piotr Piastucki piotr@jtilia.org
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
2023-03-29 18:59:00 +03:00
|
|
|
using DotRecast.Core;
|
2023-04-23 08:13:10 +03:00
|
|
|
using DotRecast.Detour.QueryResults;
|
2023-03-14 08:02:43 +03:00
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
namespace DotRecast.Detour.Crowd.Test;
|
|
|
|
|
2023-04-25 17:22:44 +03:00
|
|
|
[Parallelizable]
|
2023-03-16 19:48:49 +03:00
|
|
|
public class PathCorridorTest
|
|
|
|
{
|
2023-06-08 15:38:02 +03:00
|
|
|
private readonly DtPathCorridor corridor = new DtPathCorridor();
|
|
|
|
private readonly IDtQueryFilter filter = new DtQueryDefaultFilter();
|
2023-03-14 08:02:43 +03:00
|
|
|
|
|
|
|
[SetUp]
|
2023-05-05 02:44:48 +03:00
|
|
|
public void SetUp()
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-06-03 15:47:26 +03:00
|
|
|
corridor.Reset(0, RcVec3f.Of(10, 20, 30));
|
2023-03-14 08:02:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2023-05-05 02:44:48 +03:00
|
|
|
public void ShouldKeepOriginalPathInFindCornersWhenNothingCanBePruned()
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
List<StraightPathItem> straightPath = new();
|
2023-06-03 15:47:26 +03:00
|
|
|
straightPath.Add(new StraightPathItem(RcVec3f.Of(11, 20, 30.00001f), 0, 0));
|
|
|
|
straightPath.Add(new StraightPathItem(RcVec3f.Of(12, 20, 30.00002f), 0, 0));
|
|
|
|
straightPath.Add(new StraightPathItem(RcVec3f.Of(11f, 21, 32f), 0, 0));
|
|
|
|
straightPath.Add(new StraightPathItem(RcVec3f.Of(11f, 21, 32f), 0, 0));
|
2023-04-28 17:22:09 +03:00
|
|
|
Result<List<StraightPathItem>> result = Results.Success(straightPath);
|
2023-06-08 15:38:02 +03:00
|
|
|
var mockQuery = new Mock<DtNavMeshQuery>(It.IsAny<DtNavMesh>());
|
2023-05-05 02:44:48 +03:00
|
|
|
mockQuery.Setup(q => q.FindStraightPath(
|
2023-06-03 15:47:26 +03:00
|
|
|
It.IsAny<RcVec3f>(),
|
|
|
|
It.IsAny<RcVec3f>(),
|
2023-03-16 19:48:49 +03:00
|
|
|
It.IsAny<List<long>>(),
|
|
|
|
It.IsAny<int>(),
|
2023-03-14 08:02:43 +03:00
|
|
|
It.IsAny<int>())
|
|
|
|
).Returns(result);
|
2023-05-05 02:44:48 +03:00
|
|
|
List<StraightPathItem> path = corridor.FindCorners(int.MaxValue, mockQuery.Object, filter);
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(path.Count, Is.EqualTo(4));
|
|
|
|
Assert.That(path, Is.EqualTo(straightPath));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2023-05-05 02:44:48 +03:00
|
|
|
public void ShouldPrunePathInFindCorners()
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
List<StraightPathItem> straightPath = new();
|
2023-06-03 15:47:26 +03:00
|
|
|
straightPath.Add(new StraightPathItem(RcVec3f.Of(10, 20, 30.00001f), 0, 0)); // too close
|
|
|
|
straightPath.Add(new StraightPathItem(RcVec3f.Of(10, 20, 30.00002f), 0, 0)); // too close
|
|
|
|
straightPath.Add(new StraightPathItem(RcVec3f.Of(11f, 21, 32f), 0, 0));
|
2023-06-08 15:38:02 +03:00
|
|
|
straightPath.Add(new StraightPathItem(RcVec3f.Of(12f, 22, 33f), DtNavMeshQuery.DT_STRAIGHTPATH_OFFMESH_CONNECTION, 0)); // offmesh
|
|
|
|
straightPath.Add(new StraightPathItem(RcVec3f.Of(11f, 21, 32f), DtNavMeshQuery.DT_STRAIGHTPATH_OFFMESH_CONNECTION, 0)); // offmesh
|
2023-04-28 17:22:09 +03:00
|
|
|
Result<List<StraightPathItem>> result = Results.Success(straightPath);
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-06-08 15:38:02 +03:00
|
|
|
var mockQuery = new Mock<DtNavMeshQuery>(It.IsAny<DtNavMesh>());
|
2023-05-05 02:44:48 +03:00
|
|
|
var s = mockQuery.Setup(q => q.FindStraightPath(
|
2023-06-03 15:47:26 +03:00
|
|
|
It.IsAny<RcVec3f>(),
|
|
|
|
It.IsAny<RcVec3f>(),
|
2023-03-14 08:02:43 +03:00
|
|
|
It.IsAny<List<long>>(),
|
|
|
|
It.IsAny<int>(),
|
|
|
|
It.IsAny<int>())
|
|
|
|
).Returns(result);
|
|
|
|
|
2023-05-05 02:44:48 +03:00
|
|
|
List<StraightPathItem> path = corridor.FindCorners(int.MaxValue, mockQuery.Object, filter);
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(path.Count, Is.EqualTo(2));
|
|
|
|
Assert.That(path, Is.EqualTo(new List<StraightPathItem> { straightPath[2], straightPath[3] }));
|
|
|
|
}
|
2023-04-29 07:29:40 +03:00
|
|
|
}
|