Minor changes and additions.

This commit is contained in:
wo80
2022-02-16 21:12:19 +01:00
parent b12d168cea
commit 8952d7d993
6 changed files with 76 additions and 11 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ namespace TriangleNet.Examples
using TriangleNet.Smoothing;
/// <summary>
/// Refine only a part of a polygon mesh be using region pointers and an area constraint.
/// Refine only a part of a polygon mesh by using region pointers and an area constraint.
/// </summary>
public class Example4
{
+14 -1
View File
@@ -1,8 +1,10 @@
namespace TriangleNet.Examples
{
using System;
using TriangleNet.Geometry;
using TriangleNet.Meshing;
using TriangleNet.Meshing.Iterators;
using TriangleNet.Rendering.Text;
/// <summary>
@@ -26,7 +28,18 @@ namespace TriangleNet.Examples
};
// Generate mesh using the polygons Triangulate extension method.
var mesh = poly.Triangulate(quality);
var mesh = (Mesh)poly.Triangulate(quality);
// Validate.
foreach (var e in EdgeIterator.EnumerateEdges(mesh))
{
double length = Math.Sqrt(DistSqr(e.GetVertex(0), e.GetVertex(1)));
if (length > MAX_EDGE_LENGTH)
{
Console.WriteLine("Something's wrong in here ...");
}
}
if (print) SvgImage.Save(mesh, "example-7.svg", 500);
}
+2 -2
View File
@@ -11,7 +11,7 @@ namespace TriangleNet.Examples
/// </summary>
public class Example9
{
public static void Run()
public static void Run(bool print = false)
{
var pts = new List<Vertex>
{
@@ -39,7 +39,7 @@ namespace TriangleNet.Examples
var list = MeshValidator.GetDegenerateBoundaryTriangles(mesh);
if (list.Any())
if (print && list.Any())
{
Console.WriteLine("Iteration {0}: found {1} degenerate triangle(s) of {2}.",
i, list.Count(), mesh.Triangles.Count);
+1 -1
View File
@@ -142,7 +142,7 @@ namespace TriangleNet.Geometry
double dx, dy;
double h;
var predicates = new RobustPredicates();
var predicates = RobustPredicates.Default;
a = contour[0];
b = contour[1];
+53 -6
View File
@@ -37,17 +37,17 @@ namespace TriangleNet.Tools
if (p == null)
{
horrors++;
logger.Warning(String.Format("Point {0} is null.", i), "PolygonValidator.IsConsistent()");
logger.Warning(string.Format("Point {0} is null.", i), "PolygonValidator.IsConsistent()");
}
else if (double.IsNaN(p.x) || double.IsNaN(p.y))
{
horrors++;
logger.Warning(String.Format("Point {0} has invalid coordinates.", i), "PolygonValidator.IsConsistent()");
logger.Warning(string.Format("Point {0} has invalid coordinates.", i), "PolygonValidator.IsConsistent()");
}
else if (double.IsInfinity(p.x) || double.IsInfinity(p.y))
{
horrors++;
logger.Warning(String.Format("Point {0} has invalid coordinates.", i), "PolygonValidator.IsConsistent()");
logger.Warning(string.Format("Point {0} has invalid coordinates.", i), "PolygonValidator.IsConsistent()");
}
i++;
@@ -60,7 +60,7 @@ namespace TriangleNet.Tools
if (seg == null)
{
horrors++;
logger.Warning(String.Format("Segment {0} is null.", i), "PolygonValidator.IsConsistent()");
logger.Warning(string.Format("Segment {0} is null.", i), "PolygonValidator.IsConsistent()");
// Always abort if a NULL-segment is found.
return false;
@@ -72,7 +72,7 @@ namespace TriangleNet.Tools
if ((p.x == q.x) && (p.y == q.y))
{
horrors++;
logger.Warning(String.Format("Endpoints of segment {0} are coincident (IDs {1} / {2}).", i, p.id, q.id),
logger.Warning(string.Format("Endpoints of segment {0} are coincident (IDs {1} / {2}).", i, p.id, q.id),
"PolygonValidator.IsConsistent()");
}
@@ -109,7 +109,7 @@ namespace TriangleNet.Tools
if (points[i - 1] == points[i])
{
horrors++;
logger.Warning(string.Format("Found duplicate point {0}.", points[i]),
logger.Warning(string.Format("Found duplicate point ({0}, {1}).", points[i].x, points[i].y),
"PolygonValidator.HasDuplicateVertices()");
}
}
@@ -117,6 +117,53 @@ namespace TriangleNet.Tools
return horrors > 0;
}
/// <summary>
/// Get the ratio of the largest and smallest segment length.
/// </summary>
/// <param name="poly">The polygon.</param>
/// <param name="threshold">The ratio threshold.</param>
/// <remarks>
/// This method will also report zero-length segments.
/// </remarks>
public static double GetSegmentRatio(IPolygon poly, double threshold = 2e12)
{
var logger = Log.Instance;
double min = double.MaxValue;
double max = 0.0;
foreach (var seg in poly.Segments)
{
var p = seg.GetVertex(0);
var q = seg.GetVertex(1);
var dx = p.X - q.X;
var dy = p.Y - q.Y;
var length = Math.Sqrt(dx * dx + dy * dy);
if (length == 0.0)
{
logger.Warning(string.Format("Found zero-length segment (vertex IDs {0} / {1}).", p.id, q.id),
"PolygonValidator.GetSegmentRatio()");
continue;
}
min = Math.Min(min, length);
max = Math.Max(max, length);
}
double ratio = max / min;
if (ratio > threshold)
{
logger.Warning(string.Format("Polygon has large segment ratio {0:G2}.", ratio),
"PolygonValidator.GetSegmentRatio()");
}
return ratio;
}
/// <summary>
/// Test the polygon for 360 degree angles.
/// </summary>
+5
View File
@@ -27,6 +27,11 @@ namespace TriangleNet
// A stack of free triangles.
Stack<Triangle> stack;
/// <summary>
/// Gets the total number of currently allocated triangles.
/// </summary>
public int Capacity => size;
public TrianglePool()
{
size = 0;