DotRecastNetSim/test/DotRecast.Detour.Test/PolygonByCircleConstraintTe...

93 lines
3.5 KiB
C#
Raw Permalink Normal View History

2023-03-14 08:02:43 +03:00
/*
recast4j copyright (c) 2021 Piotr Piastucki piotr@jtilia.org
2023-08-19 10:13:37 +03:00
DotRecast Copyright (c) 2023 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 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 PolygonByCircleConstraintTest
{
2023-08-16 17:49:43 +03:00
private readonly IDtPolygonByCircleConstraint _constraint = DtStrictDtPolygonByCircleConstraint.Shared;
2023-03-14 08:02:43 +03:00
[Test]
2023-05-05 02:44:48 +03:00
public void ShouldHandlePolygonFullyInsideCircle()
2023-03-16 19:48:49 +03:00
{
2023-03-14 08:02:43 +03:00
float[] polygon = { -2, 0, 2, 2, 0, 2, 2, 0, -2, -2, 0, -2 };
2023-10-12 17:52:32 +03:00
RcVec3f center = new RcVec3f(1, 0, 1);
float[] constrained = _constraint.Apply(polygon, center, 6);
2023-03-14 08:02:43 +03:00
Assert.That(constrained, Is.EqualTo(polygon));
}
[Test]
2023-05-05 02:44:48 +03:00
public void ShouldHandleVerticalSegment()
2023-03-16 19:48:49 +03:00
{
2023-03-14 08:02:43 +03:00
int expectedSize = 21;
float[] polygon = { -2, 0, 2, 2, 0, 2, 2, 0, -2, -2, 0, -2 };
2023-10-12 17:52:32 +03:00
RcVec3f center = new RcVec3f(2, 0, 0);
2023-03-14 08:02:43 +03:00
float[] constrained = _constraint.Apply(polygon, center, 3);
2023-03-14 08:02:43 +03:00
Assert.That(constrained.Length, Is.EqualTo(expectedSize));
2023-03-16 19:48:49 +03:00
Assert.That(constrained, Is.SupersetOf(new[] { 2f, 0f, 2f, 2f, 0f, -2f }));
2023-03-14 08:02:43 +03:00
}
[Test]
2023-05-05 02:44:48 +03:00
public void ShouldHandleCircleFullyInsidePolygon()
2023-03-16 19:48:49 +03:00
{
2023-03-14 08:02:43 +03:00
int expectedSize = 12 * 3;
float[] polygon = { -4, 0, 0, -3, 0, 3, 2, 0, 3, 3, 0, -3, -2, 0, -4 };
2023-10-12 17:52:32 +03:00
RcVec3f center = new RcVec3f(-1, 0, -1);
float[] constrained = _constraint.Apply(polygon, center, 2);
2023-03-14 08:02:43 +03:00
Assert.That(constrained.Length, Is.EqualTo(expectedSize));
2023-03-16 19:48:49 +03:00
for (int i = 0; i < expectedSize; i += 3)
{
2023-03-14 08:02:43 +03:00
float x = constrained[i] + 1;
float z = constrained[i + 2] + 1;
Assert.That(x * x + z * z, Is.EqualTo(4).Within(1e-4f));
}
}
[Test]
2023-05-05 02:44:48 +03:00
public void ShouldHandleCircleInsidePolygon()
2023-03-16 19:48:49 +03:00
{
2023-03-14 08:02:43 +03:00
int expectedSize = 9 * 3;
float[] polygon = { -4, 0, 0, -3, 0, 3, 2, 0, 3, 3, 0, -3, -2, 0, -4 };
2023-10-12 17:52:32 +03:00
RcVec3f center = new RcVec3f(-2, 0, -1);
float[] constrained = _constraint.Apply(polygon, center, 3);
2023-03-14 08:02:43 +03:00
Assert.That(constrained.Length, Is.EqualTo(expectedSize));
2023-10-24 18:09:34 +03:00
Assert.That(constrained, Is.SupersetOf(new[] { -2f, 0f, -4f, -4f, 0f, 0f, -3.4641016f, 0.0f, 1.60769534f, -2.0f, 0.0f, 2.0f }));
2023-03-14 08:02:43 +03:00
}
[Test]
2023-05-05 02:44:48 +03:00
public void ShouldHandleCircleOutsidePolygon()
2023-03-14 08:02:43 +03:00
{
int expectedSize = 7 * 3;
float[] polygon = { -4, 0, 0, -3, 0, 3, 2, 0, 3, 3, 0, -3, -2, 0, -4 };
2023-10-12 17:52:32 +03:00
RcVec3f center = new RcVec3f(4, 0, 0);
float[] constrained = _constraint.Apply(polygon, center, 4);
2023-03-14 08:02:43 +03:00
Assert.That(constrained.Length, Is.EqualTo(expectedSize));
2023-10-24 18:09:34 +03:00
Assert.That(constrained, Is.SupersetOf(new[] { 1.53589869f, 0f, 3f, 2f, 0f, 3f, 3f, 0f, -3f }));
2023-03-16 19:48:49 +03:00
}
}