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 System.Collections.Generic;
|
2023-10-16 17:55:34 +03:00
|
|
|
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 FindPathTest : AbstractDetourTest
|
|
|
|
{
|
2023-06-08 15:38:02 +03:00
|
|
|
private static readonly DtStatus[] STATUSES =
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-12-21 19:23:13 +03:00
|
|
|
DtStatus.DT_SUCCESS,
|
|
|
|
DtStatus.DT_SUCCESS | DtStatus.DT_PARTIAL_RESULT,
|
|
|
|
DtStatus.DT_SUCCESS,
|
|
|
|
DtStatus.DT_SUCCESS,
|
|
|
|
DtStatus.DT_SUCCESS
|
2023-03-16 19:48:49 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
private static readonly long[][] RESULTS =
|
|
|
|
{
|
|
|
|
new[]
|
|
|
|
{
|
|
|
|
281474976710696L, 281474976710695L, 281474976710694L, 281474976710703L, 281474976710706L,
|
|
|
|
281474976710705L, 281474976710702L, 281474976710701L, 281474976710714L, 281474976710713L,
|
|
|
|
281474976710712L, 281474976710727L, 281474976710730L, 281474976710717L, 281474976710721L
|
|
|
|
},
|
|
|
|
new[]
|
|
|
|
{
|
|
|
|
281474976710773L, 281474976710772L, 281474976710768L, 281474976710754L, 281474976710755L,
|
|
|
|
281474976710753L, 281474976710748L, 281474976710752L, 281474976710731L, 281474976710729L,
|
|
|
|
281474976710717L, 281474976710724L, 281474976710728L, 281474976710737L, 281474976710738L,
|
|
|
|
281474976710736L, 281474976710733L, 281474976710735L, 281474976710742L, 281474976710740L,
|
|
|
|
281474976710746L, 281474976710745L, 281474976710744L
|
|
|
|
},
|
|
|
|
new[]
|
|
|
|
{
|
|
|
|
281474976710680L, 281474976710684L, 281474976710688L, 281474976710687L, 281474976710686L,
|
|
|
|
281474976710697L, 281474976710695L, 281474976710694L, 281474976710703L, 281474976710706L,
|
|
|
|
281474976710705L, 281474976710702L, 281474976710701L, 281474976710714L, 281474976710713L,
|
|
|
|
281474976710712L, 281474976710727L, 281474976710730L, 281474976710717L, 281474976710729L,
|
|
|
|
281474976710731L, 281474976710752L, 281474976710748L, 281474976710753L, 281474976710755L,
|
|
|
|
281474976710754L, 281474976710768L, 281474976710772L, 281474976710773L, 281474976710770L,
|
|
|
|
281474976710757L, 281474976710761L, 281474976710758L
|
|
|
|
},
|
|
|
|
new[] { 281474976710753L, 281474976710748L, 281474976710752L, 281474976710731L },
|
|
|
|
new[]
|
|
|
|
{
|
|
|
|
281474976710733L, 281474976710736L, 281474976710738L, 281474976710737L, 281474976710728L,
|
|
|
|
281474976710724L, 281474976710717L, 281474976710729L, 281474976710731L, 281474976710752L,
|
|
|
|
281474976710748L, 281474976710753L, 281474976710755L, 281474976710754L, 281474976710768L,
|
|
|
|
281474976710772L
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-10-04 18:11:58 +03:00
|
|
|
private static readonly DtStraightPath[][] STRAIGHT_PATHS =
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
|
|
|
new[]
|
|
|
|
{
|
2023-10-12 17:52:32 +03:00
|
|
|
new DtStraightPath(new RcVec3f(22.606520f, 10.197294f, -45.918674f), 1, 281474976710696L),
|
|
|
|
new DtStraightPath(new RcVec3f(3.484785f, 10.197294f, -34.241272f), 0, 281474976710713L),
|
|
|
|
new DtStraightPath(new RcVec3f(1.984785f, 10.197294f, -31.241272f), 0, 281474976710712L),
|
|
|
|
new DtStraightPath(new RcVec3f(1.984785f, 10.197294f, -29.741272f), 0, 281474976710727L),
|
|
|
|
new DtStraightPath(new RcVec3f(2.584784f, 10.197294f, -27.941273f), 0, 281474976710730L),
|
|
|
|
new DtStraightPath(new RcVec3f(6.457663f, 10.197294f, -18.334061f), 2, 0L)
|
2023-03-16 19:48:49 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
new[]
|
|
|
|
{
|
2023-10-12 17:52:32 +03:00
|
|
|
new DtStraightPath(new RcVec3f(22.331268f, 10.197294f, -1.040187f), 1, 281474976710773L),
|
|
|
|
new DtStraightPath(new RcVec3f(9.784786f, 10.197294f, -2.141273f), 0, 281474976710755L),
|
|
|
|
new DtStraightPath(new RcVec3f(7.984783f, 10.197294f, -2.441269f), 0, 281474976710753L),
|
|
|
|
new DtStraightPath(new RcVec3f(1.984785f, 10.197294f, -8.441269f), 0, 281474976710752L),
|
|
|
|
new DtStraightPath(new RcVec3f(-4.315216f, 10.197294f, -15.341270f), 0, 281474976710724L),
|
|
|
|
new DtStraightPath(new RcVec3f(-8.215216f, 10.197294f, -17.441269f), 0, 281474976710728L),
|
|
|
|
new DtStraightPath(new RcVec3f(-10.015216f, 10.197294f, -17.741272f), 0, 281474976710738L),
|
|
|
|
new DtStraightPath(new RcVec3f(-11.815216f, 9.997294f, -17.441269f), 0, 281474976710736L),
|
|
|
|
new DtStraightPath(new RcVec3f(-17.815216f, 5.197294f, -11.441269f), 0, 281474976710735L),
|
|
|
|
new DtStraightPath(new RcVec3f(-17.815216f, 5.197294f, -8.441269f), 0, 281474976710746L),
|
|
|
|
new DtStraightPath(new RcVec3f(-11.815216f, 0.197294f, 3.008419f), 2, 0L)
|
2023-03-16 19:48:49 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
new[]
|
|
|
|
{
|
2023-10-12 17:52:32 +03:00
|
|
|
new DtStraightPath(new RcVec3f(18.694363f, 15.803535f, -73.090416f), 1, 281474976710680L),
|
|
|
|
new DtStraightPath(new RcVec3f(17.584785f, 10.197294f, -49.841274f), 0, 281474976710697L),
|
|
|
|
new DtStraightPath(new RcVec3f(17.284786f, 10.197294f, -48.041275f), 0, 281474976710695L),
|
|
|
|
new DtStraightPath(new RcVec3f(16.084785f, 10.197294f, -45.341274f), 0, 281474976710694L),
|
|
|
|
new DtStraightPath(new RcVec3f(3.484785f, 10.197294f, -34.241272f), 0, 281474976710713L),
|
|
|
|
new DtStraightPath(new RcVec3f(1.984785f, 10.197294f, -31.241272f), 0, 281474976710712L),
|
|
|
|
new DtStraightPath(new RcVec3f(1.984785f, 10.197294f, -8.441269f), 0, 281474976710753L),
|
|
|
|
new DtStraightPath(new RcVec3f(7.984783f, 10.197294f, -2.441269f), 0, 281474976710755L),
|
|
|
|
new DtStraightPath(new RcVec3f(9.784786f, 10.197294f, -2.141273f), 0, 281474976710768L),
|
|
|
|
new DtStraightPath(new RcVec3f(38.423977f, 10.197294f, -0.116067f), 2, 0L)
|
2023-03-16 19:48:49 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
new[]
|
|
|
|
{
|
2023-10-12 17:52:32 +03:00
|
|
|
new DtStraightPath(new RcVec3f(0.745335f, 10.197294f, -5.940050f), 1, 281474976710753L),
|
|
|
|
new DtStraightPath(new RcVec3f(0.863553f, 10.197294f, -10.310320f), 2, 0L)
|
2023-03-16 19:48:49 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
new[]
|
|
|
|
{
|
2023-10-12 17:52:32 +03:00
|
|
|
new DtStraightPath(new RcVec3f(-20.651257f, 5.904126f, -13.712508f), 1, 281474976710733L),
|
|
|
|
new DtStraightPath(new RcVec3f(-11.815216f, 9.997294f, -17.441269f), 0, 281474976710738L),
|
|
|
|
new DtStraightPath(new RcVec3f(-10.015216f, 10.197294f, -17.741272f), 0, 281474976710728L),
|
|
|
|
new DtStraightPath(new RcVec3f(-8.215216f, 10.197294f, -17.441269f), 0, 281474976710724L),
|
|
|
|
new DtStraightPath(new RcVec3f(-4.315216f, 10.197294f, -15.341270f), 0, 281474976710729L),
|
|
|
|
new DtStraightPath(new RcVec3f(1.984785f, 10.197294f, -8.441269f), 0, 281474976710753L),
|
|
|
|
new DtStraightPath(new RcVec3f(7.984783f, 10.197294f, -2.441269f), 0, 281474976710755L),
|
|
|
|
new DtStraightPath(new RcVec3f(18.784092f, 10.197294f, 3.054368f), 2, 0L)
|
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 TestFindPath()
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-06-08 15:38:02 +03:00
|
|
|
IDtQueryFilter filter = new DtQueryDefaultFilter();
|
2023-06-23 01:33:03 +03:00
|
|
|
var path = new List<long>();
|
2023-03-16 19:48:49 +03:00
|
|
|
for (int i = 0; i < startRefs.Length; i++)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
long startRef = startRefs[i];
|
|
|
|
long endRef = endRefs[i];
|
2023-06-03 15:47:26 +03:00
|
|
|
RcVec3f startPos = startPoss[i];
|
|
|
|
RcVec3f endPos = endPoss[i];
|
2023-06-23 01:33:03 +03:00
|
|
|
var status = query.FindPath(startRef, endRef, startPos, endPos, filter, ref path, DtFindPathOption.NoOption);
|
|
|
|
Assert.That(status, Is.EqualTo(STATUSES[i]));
|
|
|
|
Assert.That(path.Count, Is.EqualTo(RESULTS[i].Length));
|
2023-03-16 19:48:49 +03:00
|
|
|
for (int j = 0; j < RESULTS[i].Length; j++)
|
|
|
|
{
|
2023-06-23 01:33:03 +03:00
|
|
|
Assert.That(path[j], Is.EqualTo(RESULTS[i][j]));
|
2023-03-14 08:02:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2023-05-05 02:44:48 +03:00
|
|
|
public void TestFindPathSliced()
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-06-08 15:38:02 +03:00
|
|
|
IDtQueryFilter filter = new DtQueryDefaultFilter();
|
2023-06-23 01:54:28 +03:00
|
|
|
var path = new List<long>();
|
2023-03-16 19:48:49 +03:00
|
|
|
for (int i = 0; i < startRefs.Length; i++)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
long startRef = startRefs[i];
|
|
|
|
long endRef = endRefs[i];
|
2023-03-29 18:59:00 +03:00
|
|
|
var startPos = startPoss[i];
|
|
|
|
var endPos = endPoss[i];
|
2023-10-08 08:28:56 +03:00
|
|
|
query.InitSlicedFindPath(startRef, endRef, startPos, endPos, filter, DtFindPathOptions.DT_FINDPATH_ANY_ANGLE);
|
2023-06-10 06:37:39 +03:00
|
|
|
DtStatus status = DtStatus.DT_IN_PROGRESS;
|
2023-06-10 15:57:39 +03:00
|
|
|
while (status.InProgress())
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-06-20 16:41:51 +03:00
|
|
|
status = query.UpdateSlicedFindPath(10, out var _);
|
2023-03-14 08:02:43 +03:00
|
|
|
}
|
2023-03-16 19:48:49 +03:00
|
|
|
|
2023-06-23 01:54:28 +03:00
|
|
|
status = query.FinalizeSlicedFindPath(ref path);
|
|
|
|
Assert.That(status, Is.EqualTo(STATUSES[i]), $"index({i})");
|
|
|
|
Assert.That(path.Count, Is.EqualTo(RESULTS[i].Length));
|
2023-03-16 19:48:49 +03:00
|
|
|
for (int j = 0; j < RESULTS[i].Length; j++)
|
|
|
|
{
|
2023-06-23 01:54:28 +03:00
|
|
|
Assert.That(path[j], Is.EqualTo(RESULTS[i][j]));
|
2023-03-14 08:02:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2023-05-05 02:44:48 +03:00
|
|
|
public void TestFindPathStraight()
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-06-08 15:38:02 +03:00
|
|
|
IDtQueryFilter filter = new DtQueryDefaultFilter();
|
2023-06-23 01:33:03 +03:00
|
|
|
var path = new List<long>();
|
2023-03-16 19:48:49 +03:00
|
|
|
for (int i = 0; i < STRAIGHT_PATHS.Length; i++)
|
|
|
|
{
|
|
|
|
// startRefs.Length; i++) {
|
2023-03-14 08:02:43 +03:00
|
|
|
long startRef = startRefs[i];
|
|
|
|
long endRef = endRefs[i];
|
2023-03-29 18:59:00 +03:00
|
|
|
var startPos = startPoss[i];
|
|
|
|
var endPos = endPoss[i];
|
2023-06-23 01:33:03 +03:00
|
|
|
var status = query.FindPath(startRef, endRef, startPos, endPos, filter, ref path, DtFindPathOption.NoOption);
|
2023-10-04 18:11:58 +03:00
|
|
|
var straightPath = new List<DtStraightPath>();
|
2023-06-23 01:33:03 +03:00
|
|
|
query.FindStraightPath(startPos, endPos, path, ref straightPath, int.MaxValue, 0);
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(straightPath.Count, Is.EqualTo(STRAIGHT_PATHS[i].Length));
|
2023-03-16 19:48:49 +03:00
|
|
|
for (int j = 0; j < STRAIGHT_PATHS[i].Length; j++)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(straightPath[j].refs, Is.EqualTo(STRAIGHT_PATHS[i][j].refs));
|
2023-10-28 06:08:17 +03:00
|
|
|
Assert.That(straightPath[j].pos.X, Is.EqualTo(STRAIGHT_PATHS[i][j].pos.X).Within(0.01f));
|
|
|
|
Assert.That(straightPath[j].pos.Y, Is.EqualTo(STRAIGHT_PATHS[i][j].pos.Y).Within(0.01f));
|
|
|
|
Assert.That(straightPath[j].pos.Z, Is.EqualTo(STRAIGHT_PATHS[i][j].pos.Z).Within(0.01f));
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(straightPath[j].flags, Is.EqualTo(STRAIGHT_PATHS[i][j].flags));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-16 19:48:49 +03:00
|
|
|
}
|