diff --git a/src/Triangle.Tests/Geomerty/PolygonTest.cs b/src/Triangle.Tests/Geomerty/PolygonTest.cs
new file mode 100644
index 0000000..3d98a5c
--- /dev/null
+++ b/src/Triangle.Tests/Geomerty/PolygonTest.cs
@@ -0,0 +1,76 @@
+using NUnit.Framework;
+using TriangleNet.Geometry;
+
+namespace TriangleNet.Tests.Geometry
+{
+ public class PolygonTest
+ {
+ // The vertices that define the polygon contour (triangle shape).
+ Vertex[] vertices = new Vertex[]
+ {
+ new Vertex(0d, 0d),
+ new Vertex(2d ,0d),
+ new Vertex(1d, 1.5)
+ };
+
+ [Test]
+ public void TestAddContour()
+ {
+ var contour = new Contour(vertices);
+
+ var p = new Polygon();
+
+ p.Add(contour);
+
+ Assert.AreEqual(3, p.Points.Count);
+ Assert.AreEqual(3, p.Segments.Count);
+ Assert.AreEqual(0, p.Holes.Count);
+ Assert.AreEqual(0, p.Regions.Count);
+ }
+
+ [Test]
+ public void TestAddContourAsHole()
+ {
+ var contour = new Contour(vertices);
+
+ var p = new Polygon();
+
+ p.Add(contour, true);
+
+ Assert.AreEqual(3, p.Points.Count);
+ Assert.AreEqual(3, p.Segments.Count);
+ Assert.AreEqual(1, p.Holes.Count);
+ Assert.AreEqual(0, p.Regions.Count);
+ }
+
+ [Test]
+ public void TestAddContourAsRegion()
+ {
+ var contour = new Contour(vertices, 1);
+
+ var p = new Polygon();
+
+ p.Add(contour, 1);
+
+ Assert.AreEqual(3, p.Points.Count);
+ Assert.AreEqual(3, p.Segments.Count);
+ Assert.AreEqual(0, p.Holes.Count);
+ Assert.AreEqual(1, p.Regions.Count);
+ }
+
+ [Test]
+ public void TestBounds()
+ {
+ var contour = new Contour(vertices);
+
+ var p = new Polygon();
+
+ p.Add(contour);
+
+ var bounds = p.Bounds();
+
+ Assert.AreEqual(2d, bounds.Width);
+ Assert.AreEqual(1.5, bounds.Height);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Triangle.Tests/Triangle.Tests.csproj b/src/Triangle.Tests/Triangle.Tests.csproj
index eb685c4..0e1d50f 100644
--- a/src/Triangle.Tests/Triangle.Tests.csproj
+++ b/src/Triangle.Tests/Triangle.Tests.csproj
@@ -9,9 +9,9 @@
-
-
-
+
+
+
diff --git a/src/Triangle/Tools/PolygonValidator.cs b/src/Triangle/Tools/PolygonValidator.cs
index cc6e7a9..944ec8e 100644
--- a/src/Triangle/Tools/PolygonValidator.cs
+++ b/src/Triangle/Tools/PolygonValidator.cs
@@ -121,14 +121,15 @@ namespace TriangleNet.Tools
}
///
- /// Get the ratio of the largest and smallest segment length.
+ /// Gets the minimum and maximum feature size (segment length) of the input polygon.
///
/// The polygon.
- /// The ratio threshold.
+ /// The ratio threshold (smallest to largest segment length, default = 2e-10).
///
- /// This method will also report zero-length segments.
+ /// This method will also report zero-length segments. The method does NOT detect
+ /// free vertices lying close to segments.
///
- public static double GetSegmentRatio(IPolygon poly, double threshold = 2e12)
+ public static (double min, double max) GetSegmentRatio(IPolygon poly, double threshold = 2e-10)
{
var logger = Log.Instance;
@@ -156,15 +157,15 @@ namespace TriangleNet.Tools
max = Math.Max(max, length);
}
- double ratio = max / min;
+ double ratio = min / max;
- if (ratio > threshold)
+ if (ratio < threshold)
{
- logger.Warning(string.Format("Polygon has large segment ratio {0:G2}.", ratio),
+ logger.Warning(string.Format("Polygon has tiny segment ratio {0:G2}.", ratio),
"PolygonValidator.GetSegmentRatio()");
}
- return ratio;
+ return (min, max);
}
///