diff --git a/src/Triangle.Tests/Geomerty/ContourTest.cs b/src/Triangle.Tests/Geomerty/ContourTest.cs index c7a41cf..087c23f 100644 --- a/src/Triangle.Tests/Geomerty/ContourTest.cs +++ b/src/Triangle.Tests/Geomerty/ContourTest.cs @@ -63,5 +63,24 @@ namespace TriangleNet.Tests.Geometry i = j; } } + + [Test] + public void TestFindInteriorPointDup() + { + // Rectangle contour with duplicate point. + var points = new List() + { + new Vertex(0.0, 0.0), + new Vertex(0.0, 1.0), + new Vertex(2.0, 1.0), + new Vertex(2.0, 0.5), + new Vertex(2.0, 0.5), // duplicate + new Vertex(2.0, 0.0) + }; + + var contour = new Contour(points); + + Assert.DoesNotThrow(() => contour.FindInteriorPoint()); + } } } diff --git a/src/Triangle/Tools/IntersectionHelper.cs b/src/Triangle/Tools/IntersectionHelper.cs index bbe663a..8810bf5 100644 --- a/src/Triangle/Tools/IntersectionHelper.cs +++ b/src/Triangle/Tools/IntersectionHelper.cs @@ -36,6 +36,9 @@ namespace TriangleNet.Tools // Length of the segment. double ab = (b.X - a.X) * (b.X - a.X) + (b.Y - a.Y) * (b.Y - a.Y); + // Ignore duplicate input points. + if (ab == 0) return false; + // Check if test point is actually between a and b (right of b). if (dot > ab) return false;