DotRecastNetSim/test/DotRecast.Detour.Crowd.Test/DtPathCorridorTest.cs

73 lines
3.2 KiB
C#
Raw Normal View History

2023-03-14 08:02:43 +03:00
/*
recast4j copyright (c) 2021 Piotr Piastucki piotr@jtilia.org
DotRecast Copyright (c) 2023-2024 Choi Ikpil ikpil@naver.com
2023-03-14 08:02:43 +03:00
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;
2023-03-14 08:02:43 +03:00
using System.Collections.Generic;
using DotRecast.Core.Numerics;
2023-03-14 08:02:43 +03:00
using NUnit.Framework;
namespace DotRecast.Detour.Crowd.Test;
2024-05-08 17:50:12 +03:00
public class DtPathCorridorTest
2023-03-16 19:48:49 +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
{
corridor.Init(256);
2023-10-12 17:52:32 +03:00
corridor.Reset(0, new RcVec3f(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
{
var straightPath = new DtStraightPath[4];
straightPath[0] = new DtStraightPath(new RcVec3f(11, 20, 30.00001f), 0, 0);
straightPath[1] = new DtStraightPath(new RcVec3f(12, 20, 30.00002f), 0, 0);
straightPath[2] = new DtStraightPath(new RcVec3f(11f, 21, 32f), 0, 0);
straightPath[3] = new DtStraightPath(new RcVec3f(11f, 21, 32f), 0, 0);
var query = new DtNavMeshQueryMock(straightPath, DtStatus.DT_SUCCESS);
2023-06-19 19:36:03 +03:00
Span<DtStraightPath> path = stackalloc DtStraightPath[8];
var npath = corridor.FindCorners(path, 8, query, filter);
Assert.That(npath, Is.EqualTo(4));
Assert.That(path.Slice(0, npath).ToArray(), Is.EqualTo(straightPath));
2023-03-14 08:02:43 +03:00
}
2023-03-14 08:02:43 +03:00
[Test]
2023-05-05 02:44:48 +03:00
public void ShouldPrunePathInFindCorners()
2023-03-16 19:48:49 +03:00
{
DtStraightPath[] straightPath = new DtStraightPath[5];
straightPath[0] = (new DtStraightPath(new RcVec3f(10, 20, 30.00001f), 0, 0)); // too close
straightPath[1] = (new DtStraightPath(new RcVec3f(10, 20, 30.00002f), 0, 0)); // too close
straightPath[2] = (new DtStraightPath(new RcVec3f(11f, 21, 32f), 0, 0));
straightPath[3] = (new DtStraightPath(new RcVec3f(12f, 22, 33f), DtStraightPathFlags.DT_STRAIGHTPATH_OFFMESH_CONNECTION, 0)); // offmesh
straightPath[4] = (new DtStraightPath(new RcVec3f(11f, 21, 32f), DtStraightPathFlags.DT_STRAIGHTPATH_OFFMESH_CONNECTION, 0)); // offmesh
2023-03-14 08:02:43 +03:00
var query = new DtNavMeshQueryMock(straightPath, DtStatus.DT_SUCCESS);
2023-03-14 08:02:43 +03:00
Span<DtStraightPath> path = stackalloc DtStraightPath[8];
int npath = corridor.FindCorners(path, 8, query, filter);
Assert.That(npath, Is.EqualTo(2));
Assert.That(path.Slice(0, npath).ToArray(), Is.EqualTo(new DtStraightPath[] { straightPath[2], straightPath[3] }));
2023-03-14 08:02:43 +03:00
}
2023-06-19 19:36:03 +03:00
}