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

71 lines
3.0 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.
*/
using DotRecast.Core.Numerics;
2023-03-14 08:02:43 +03:00
using NUnit.Framework;
namespace DotRecast.Detour.Test;
2023-04-25 17:22:44 +03:00
[Parallelizable]
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 RcVec3f[] POLY_POS =
2023-03-16 19:48:49 +03:00
{
new RcVec3f(22.606520f, 10.197294f, -45.918674f),
new RcVec3f(22.331268f, 10.197294f, -1.040187f),
new RcVec3f(18.694363f, 15.803535f, -73.090416f),
new RcVec3f(0.745335f, 10.197294f, -5.940050f),
new RcVec3f(-20.651257f, 5.904126f, -13.712508f)
2023-03-16 19:48:49 +03:00
};
2023-03-14 08:02:43 +03:00
[Test]
2023-05-05 02:44:48 +03:00
public void TestFindNearestPoly()
2023-03-16 19:48:49 +03:00
{
IDtQueryFilter filter = new DtQueryDefaultFilter();
2023-10-12 17:52:32 +03:00
RcVec3f extents = new RcVec3f(2, 4, 2);
2023-03-16 19:48:49 +03:00
for (int i = 0; i < startRefs.Length; i++)
{
RcVec3f startPos = startPoss[i];
2023-06-11 07:41:37 +03:00
var status = query.FindNearestPoly(startPos, extents, filter, out var nearestRef, out var nearestPt, out var _);
2023-06-11 07:28:05 +03:00
Assert.That(status.Succeeded(), Is.True);
Assert.That(nearestRef, Is.EqualTo(POLY_REFS[i]));
Assert.That(nearestPt.X, Is.EqualTo(POLY_POS[i].X).Within(0.001f));
Assert.That(nearestPt.Y, Is.EqualTo(POLY_POS[i].Y).Within(0.001f));
Assert.That(nearestPt.Z, Is.EqualTo(POLY_POS[i].Z).Within(0.001f));
2023-03-14 08:02:43 +03:00
}
}
[Test]
2023-05-05 02:44:48 +03:00
public void ShouldReturnStartPosWhenNoPolyIsValid()
2023-03-16 19:48:49 +03:00
{
2023-10-12 17:52:32 +03:00
RcVec3f extents = new RcVec3f(2, 4, 2);
2023-03-16 19:48:49 +03:00
for (int i = 0; i < startRefs.Length; i++)
{
RcVec3f startPos = startPoss[i];
2023-08-16 17:49:43 +03:00
var status = query.FindNearestPoly(startPos, extents, DtQueryEmptyFilter.Shared, out var nearestRef, out var nearestPt, out var _);
2023-06-11 07:28:05 +03:00
Assert.That(status.Succeeded(), Is.True);
Assert.That(nearestRef, Is.EqualTo(0L));
Assert.That(nearestPt.X, Is.EqualTo(startPos.X).Within(0.001f));
Assert.That(nearestPt.Y, Is.EqualTo(startPos.Y).Within(0.001f));
Assert.That(nearestPt.Z, Is.EqualTo(startPos.Z).Within(0.001f));
2023-03-14 08:02:43 +03:00
}
}
2023-03-16 19:48:49 +03:00
}