Improve contour FindPointInPolygon() reliability (3).
This commit is contained in:
@@ -63,5 +63,24 @@ namespace TriangleNet.Tests.Geometry
|
|||||||
i = j;
|
i = j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestFindInteriorPointDup()
|
||||||
|
{
|
||||||
|
// Rectangle contour with duplicate point.
|
||||||
|
var points = new List<Vertex>()
|
||||||
|
{
|
||||||
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ namespace TriangleNet.Tools
|
|||||||
// Length of the segment.
|
// Length of the segment.
|
||||||
double ab = (b.X - a.X) * (b.X - a.X) + (b.Y - a.Y) * (b.Y - a.Y);
|
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).
|
// Check if test point is actually between a and b (right of b).
|
||||||
if (dot > ab) return false;
|
if (dot > ab) return false;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user