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-06-19 17:10:48 +03:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using DotRecast.Core;
|
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 GetPolyWallSegmentsTest : AbstractDetourTest
|
|
|
|
{
|
2023-07-17 17:24:28 +03:00
|
|
|
private static readonly RcSegmentVert[][] VERTICES =
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-07-17 17:24:28 +03:00
|
|
|
new RcSegmentVert[]
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-06-26 16:52:31 +03:00
|
|
|
new(22.084785f, 10.197294f, -48.341274f, 22.684784f, 10.197294f, -44.141273f),
|
|
|
|
new(22.684784f, 10.197294f, -44.141273f, 23.884785f, 10.197294f, -48.041275f),
|
|
|
|
new(23.884785f, 10.197294f, -48.041275f, 22.084785f, 10.197294f, -48.341274f),
|
2023-03-16 19:48:49 +03:00
|
|
|
},
|
2023-07-17 17:24:28 +03:00
|
|
|
new RcSegmentVert[]
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-06-26 16:52:31 +03:00
|
|
|
new(27.784786f, 10.197294f, 4.158730f, 28.384785f, 10.197294f, 2.358727f),
|
|
|
|
new(28.384785f, 10.197294f, 2.358727f, 28.384785f, 10.197294f, -2.141273f),
|
|
|
|
new(28.384785f, 10.197294f, -2.141273f, 27.784786f, 10.197294f, -2.741272f),
|
|
|
|
new(27.784786f, 10.197294f, -2.741272f, 19.684784f, 10.197294f, -4.241272f),
|
|
|
|
new(19.684784f, 10.197294f, -4.241272f, 19.684784f, 10.197294f, 4.158730f),
|
|
|
|
new(19.684784f, 10.197294f, 4.158730f, 27.784786f, 10.197294f, 4.158730f),
|
2023-03-16 19:48:49 +03:00
|
|
|
},
|
2023-07-17 17:24:28 +03:00
|
|
|
new RcSegmentVert[]
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-06-26 16:52:31 +03:00
|
|
|
new(22.384785f, 14.997294f, -71.741272f, 19.084785f, 16.597294f, -74.741272f),
|
|
|
|
new(19.084785f, 16.597294f, -74.741272f, 18.184784f, 15.997294f, -73.541275f),
|
|
|
|
new(18.184784f, 15.997294f, -73.541275f, 17.884785f, 14.997294f, -72.341278f),
|
|
|
|
new(17.884785f, 14.997294f, -72.341278f, 17.584785f, 14.997294f, -70.841278f),
|
|
|
|
new(17.584785f, 14.997294f, -70.841278f, 22.084785f, 14.997294f, -70.541275f),
|
|
|
|
new(22.084785f, 14.997294f, -70.541275f, 22.384785f, 14.997294f, -71.741272f),
|
2023-03-16 19:48:49 +03:00
|
|
|
},
|
2023-07-17 17:24:28 +03:00
|
|
|
new RcSegmentVert[]
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-06-26 16:52:31 +03:00
|
|
|
new(4.684784f, 10.197294f, -6.941269f, 1.984785f, 10.197294f, -8.441269f),
|
|
|
|
new(1.984785f, 10.197294f, -8.441269f, -4.015217f, 10.197294f, -6.941269f),
|
|
|
|
new(-4.015217f, 10.197294f, -6.941269f, -1.615215f, 10.197294f, -1.541275f),
|
|
|
|
new(-1.615215f, 10.197294f, -1.541275f, 1.384785f, 10.197294f, 1.458725f),
|
|
|
|
new(1.384785f, 10.197294f, 1.458725f, 7.984783f, 10.197294f, -2.441269f),
|
|
|
|
new(7.984783f, 10.197294f, -2.441269f, 4.684784f, 10.197294f, -6.941269f),
|
2023-03-16 19:48:49 +03:00
|
|
|
},
|
2023-07-17 17:24:28 +03:00
|
|
|
new RcSegmentVert[]
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-06-26 16:52:31 +03:00
|
|
|
new(-22.315216f, 6.597294f, -17.141273f, -23.815216f, 5.397294f, -13.841270f),
|
|
|
|
new(-23.815216f, 5.397294f, -13.841270f, -24.115217f, 4.997294f, -12.041275f),
|
|
|
|
new(-24.115217f, 4.997294f, -12.041275f, -22.315216f, 4.997294f, -11.441269f),
|
|
|
|
new(-22.315216f, 4.997294f, -11.441269f, -17.815216f, 5.197294f, -11.441269f),
|
|
|
|
new(-17.815216f, 5.197294f, -11.441269f, -22.315216f, 6.597294f, -17.141273f),
|
2023-03-16 19:48:49 +03:00
|
|
|
}
|
|
|
|
};
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-03-16 19:48:49 +03:00
|
|
|
private static readonly long[][] REFS =
|
|
|
|
{
|
|
|
|
new[] { 281474976710695L, 0L, 0L },
|
|
|
|
new[] { 0L, 281474976710770L, 0L, 281474976710769L, 281474976710772L, 0L },
|
|
|
|
new[] { 281474976710683L, 281474976710674L, 0L, 281474976710679L, 281474976710684L, 0L },
|
|
|
|
new[] { 281474976710750L, 281474976710748L, 0L, 0L, 281474976710755L, 281474976710756L },
|
|
|
|
new[] { 0L, 0L, 0L, 281474976710735L, 281474976710736L }
|
|
|
|
};
|
2023-03-14 08:02:43 +03:00
|
|
|
|
|
|
|
[Test]
|
2023-05-05 02:44:48 +03:00
|
|
|
public void TestFindDistanceToWall()
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-07-17 17:24:28 +03:00
|
|
|
var segmentVerts = new List<RcSegmentVert>();
|
2023-06-19 17:10:48 +03:00
|
|
|
var segmentRefs = new List<long>();
|
|
|
|
|
2023-06-08 15:38:02 +03:00
|
|
|
IDtQueryFilter filter = new DtQueryDefaultFilter();
|
2023-03-16 19:48:49 +03:00
|
|
|
for (int i = 0; i < startRefs.Length; i++)
|
|
|
|
{
|
2023-06-19 17:10:48 +03:00
|
|
|
var result = query.GetPolyWallSegments(startRefs[i], true, filter, ref segmentVerts, ref segmentRefs);
|
2023-06-26 16:52:31 +03:00
|
|
|
Assert.That(segmentVerts.Count, Is.EqualTo(VERTICES[i].Length));
|
2023-06-19 17:10:48 +03:00
|
|
|
Assert.That(segmentRefs.Count, Is.EqualTo(REFS[i].Length));
|
2023-03-16 19:48:49 +03:00
|
|
|
for (int v = 0; v < VERTICES[i].Length / 6; v++)
|
|
|
|
{
|
2023-10-12 17:04:29 +03:00
|
|
|
Assert.That(segmentVerts[v].vmin.X, Is.EqualTo(VERTICES[i][v].vmin.X).Within(0.001f));
|
|
|
|
Assert.That(segmentVerts[v].vmin.Y, Is.EqualTo(VERTICES[i][v].vmin.Y).Within(0.001f));
|
|
|
|
Assert.That(segmentVerts[v].vmin.Z, Is.EqualTo(VERTICES[i][v].vmin.Z).Within(0.001f));
|
|
|
|
Assert.That(segmentVerts[v].vmax.X, Is.EqualTo(VERTICES[i][v].vmax.X).Within(0.001f));
|
|
|
|
Assert.That(segmentVerts[v].vmax.Y, Is.EqualTo(VERTICES[i][v].vmax.Y).Within(0.001f));
|
|
|
|
Assert.That(segmentVerts[v].vmax.Z, Is.EqualTo(VERTICES[i][v].vmax.Z).Within(0.001f));
|
2023-03-14 08:02:43 +03:00
|
|
|
}
|
2023-03-16 19:48:49 +03:00
|
|
|
|
|
|
|
for (int v = 0; v < REFS[i].Length; v++)
|
|
|
|
{
|
2023-06-19 17:10:48 +03:00
|
|
|
Assert.That(segmentRefs[v], Is.EqualTo(REFS[i][v]));
|
2023-03-14 08:02:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-16 19:48:49 +03:00
|
|
|
}
|