DotRecastNetSim/test/DotRecast.Detour.Test/FindNearestPolyTest.cs

85 lines
3.3 KiB
C#
Raw Normal View History

2023-03-14 08:02:43 +03:00
/*
recast4j Copyright (c) 2015-2019 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.
*/
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 NUnit.Framework;
namespace DotRecast.Detour.Test;
2023-03-16 19:48:49 +03:00
public class FindNearestPolyTest : AbstractDetourTest
{
2023-03-14 08:02:43 +03:00
private static readonly long[] POLY_REFS = { 281474976710696L, 281474976710773L, 281474976710680L, 281474976710753L, 281474976710733L };
2023-03-16 19:48:49 +03:00
private static readonly float[][] POLY_POS =
{
2023-03-14 08:02:43 +03:00
new[] { 22.606520f, 10.197294f, -45.918674f }, new[] { 22.331268f, 10.197294f, -1.040187f },
2023-03-16 19:48:49 +03:00
new[] { 18.694363f, 15.803535f, -73.090416f }, new[] { 0.745335f, 10.197294f, -5.940050f },
new[] { -20.651257f, 5.904126f, -13.712508f }
};
2023-03-14 08:02:43 +03:00
[Test]
2023-03-16 19:48:49 +03:00
public void testFindNearestPoly()
{
2023-03-14 08:02:43 +03:00
QueryFilter filter = new DefaultQueryFilter();
2023-03-29 18:59:00 +03:00
Vector3f extents = Vector3f.Of(2, 4, 2);
2023-03-16 19:48:49 +03:00
for (int i = 0; i < startRefs.Length; i++)
{
2023-03-29 18:59:00 +03:00
Vector3f startPos = startPoss[i];
2023-03-14 08:02:43 +03:00
Result<FindNearestPolyResult> poly = query.findNearestPoly(startPos, extents, filter);
Assert.That(poly.succeeded(), Is.True);
Assert.That(poly.result.getNearestRef(), Is.EqualTo(POLY_REFS[i]));
2023-03-16 19:48:49 +03:00
for (int v = 0; v < POLY_POS[i].Length; v++)
{
2023-03-14 08:02:43 +03:00
Assert.That(poly.result.getNearestPos()[v], Is.EqualTo(POLY_POS[i][v]).Within(0.001f));
}
}
}
public class EmptyQueryFilter : QueryFilter
{
public bool passFilter(long refs, MeshTile tile, Poly poly)
{
return false;
}
2023-03-29 18:59:00 +03:00
public float getCost(Vector3f pa, Vector3f pb, long prevRef, MeshTile prevTile, Poly prevPoly, long curRef, MeshTile curTile,
2023-03-14 08:02:43 +03:00
Poly curPoly, long nextRef, MeshTile nextTile, Poly nextPoly)
{
return 0;
}
}
[Test]
2023-03-16 19:48:49 +03:00
public void shouldReturnStartPosWhenNoPolyIsValid()
{
2023-03-14 08:02:43 +03:00
var filter = new EmptyQueryFilter();
2023-03-29 18:59:00 +03:00
Vector3f extents = Vector3f.Of(2, 4, 2);
2023-03-16 19:48:49 +03:00
for (int i = 0; i < startRefs.Length; i++)
{
2023-03-29 18:59:00 +03:00
Vector3f startPos = startPoss[i];
2023-03-14 08:02:43 +03:00
Result<FindNearestPolyResult> poly = query.findNearestPoly(startPos, extents, filter);
Assert.That(poly.succeeded(), Is.True);
2023-03-16 19:09:10 +03:00
Assert.That(poly.result.getNearestRef(), Is.EqualTo(0L));
2023-03-16 19:48:49 +03:00
for (int v = 0; v < POLY_POS[i].Length; v++)
{
2023-03-14 08:02:43 +03:00
Assert.That(poly.result.getNearestPos()[v], Is.EqualTo(startPos[v]).Within(0.001f));
}
}
}
2023-03-16 19:48:49 +03:00
}