Improve contour FindPointInPolygon() reliability (2).

This commit is contained in:
wo80
2022-02-23 12:42:54 +01:00
parent bc955bb740
commit 2e83d7ee5e
3 changed files with 76 additions and 4 deletions
@@ -0,0 +1,41 @@
using NUnit.Framework;
using TriangleNet.Geometry;
using TriangleNet.Tools;
namespace TriangleNet.Tests.Tools
{
public class IntersectionHelperTest
{
[Test]
public void TestIsPointOnSegment()
{
var a = new Vertex(1.0, 1.0);
var b = new Vertex(2.0, 2.0);
// Test point = segment start point.
Assert.IsTrue(IntersectionHelper.IsPointOnSegment(a, b, new Vertex(1.0, 1.0)));
// Test point = segment end point.
Assert.IsTrue(IntersectionHelper.IsPointOnSegment(a, b, new Vertex(2.0, 2.0)));
// Test point on segment.
Assert.IsTrue(IntersectionHelper.IsPointOnSegment(a, b, new Vertex(1.5, 1.5)));
// Test point collinear, but not on segment.
Assert.IsFalse(IntersectionHelper.IsPointOnSegment(a, b, new Vertex(0.0, 0.0)));
Assert.IsFalse(IntersectionHelper.IsPointOnSegment(a, b, new Vertex(3.0, 3.0)));
// Test point not on segment.
Assert.IsFalse(IntersectionHelper.IsPointOnSegment(a, b, new Vertex(1.5, 0.5)));
double eps = 1e-12;
// Test point collinear near endpoint, but not on segment.
Assert.IsFalse(IntersectionHelper.IsPointOnSegment(a, b, new Vertex(2.0 + eps, 2.0 + eps)));
Assert.IsFalse(IntersectionHelper.IsPointOnSegment(a, b, new Vertex(2.0 - eps, 2.0 + eps)));
// Test point collinear near endpoint on segment.
Assert.IsTrue(IntersectionHelper.IsPointOnSegment(a, b, new Vertex(2.0 - eps, 2.0 - eps)));
}
}
}