From 66197a01e8e154e2f22fcbf110a614cb31f137a7 Mon Sep 17 00:00:00 2001 From: wo80 Date: Mon, 14 Feb 2022 13:59:16 +0100 Subject: [PATCH] Cleanup and documentation. --- src/MeshExplorer/FormLog.cs | 1 - src/Triangle/Geometry/Polygon.cs | 49 +++++------------------ src/Triangle/Meshing/ConstraintOptions.cs | 8 ++++ src/Triangle/Meshing/Converter.cs | 2 +- src/Triangle/Tools/PolygonValidator.cs | 15 ++++--- src/Triangle/Tools/VertexSorter.cs | 30 +++++++------- src/Triangle/Voronoi/VoronoiBase.cs | 5 +-- 7 files changed, 44 insertions(+), 66 deletions(-) diff --git a/src/MeshExplorer/FormLog.cs b/src/MeshExplorer/FormLog.cs index ec6d9a5..ca38d8d 100644 --- a/src/MeshExplorer/FormLog.cs +++ b/src/MeshExplorer/FormLog.cs @@ -3,7 +3,6 @@ using System.Drawing; using System.Text; using System.Windows.Forms; using TriangleNet; -using TriangleNet.Logging; namespace MeshExplorer { diff --git a/src/Triangle/Geometry/Polygon.cs b/src/Triangle/Geometry/Polygon.cs index eea71ca..ebe65ef 100644 --- a/src/Triangle/Geometry/Polygon.cs +++ b/src/Triangle/Geometry/Polygon.cs @@ -21,28 +21,16 @@ namespace TriangleNet.Geometry List segments; /// - public List Points - { - get { return points; } - } + public List Points => points; /// - public List Holes - { - get { return holes; } - } + public List Holes => holes; /// - public List Regions - { - get { return regions; } - } + public List Regions => regions; /// - public List Segments - { - get { return segments; } - } + public List Segments => segments; /// public bool HasPointMarkers { get; set; } @@ -112,20 +100,13 @@ namespace TriangleNet.Geometry return bounds; } - /// - /// Add a vertex to the polygon. - /// - /// The vertex to insert. + /// public void Add(Vertex vertex) { this.points.Add(vertex); } - /// - /// Add a segment to the polygon. - /// - /// The segment to insert. - /// If true, both endpoints will be added to the points list. + /// public void Add(ISegment segment, bool insert = false) { this.segments.Add(segment); @@ -137,11 +118,7 @@ namespace TriangleNet.Geometry } } - /// - /// Add a segment to the polygon. - /// - /// The segment to insert. - /// The index of the segment endpoint to add to the points list (must be 0 or 1). + /// public void Add(ISegment segment, int index) { this.segments.Add(segment); @@ -149,11 +126,7 @@ namespace TriangleNet.Geometry this.points.Add(segment.GetVertex(index)); } - /// - /// Add a contour to the polygon. - /// - /// The contour to insert. - /// Treat contour as a hole. + /// public void Add(Contour contour, bool hole = false) { if (hole) @@ -167,11 +140,7 @@ namespace TriangleNet.Geometry } } - /// - /// Add a contour to the polygon. - /// - /// The contour to insert. - /// Point inside the contour, making it a hole. + /// public void Add(Contour contour, Point hole) { this.points.AddRange(contour.Points); diff --git a/src/Triangle/Meshing/ConstraintOptions.cs b/src/Triangle/Meshing/ConstraintOptions.cs index b531ac6..684273e 100644 --- a/src/Triangle/Meshing/ConstraintOptions.cs +++ b/src/Triangle/Meshing/ConstraintOptions.cs @@ -6,6 +6,14 @@ namespace TriangleNet.Meshing /// public class ConstraintOptions { + // TODO: remove ConstraintOptions.UseRegions + + /// + /// Gets or sets a value indicating whether to use regions. + /// + [System.Obsolete("Not used anywhere, will be removed in beta 4.")] + public bool UseRegions { get; set; } + /// /// Gets or sets a value indicating whether to create a Conforming /// Delaunay triangulation. diff --git a/src/Triangle/Meshing/Converter.cs b/src/Triangle/Meshing/Converter.cs index 2f653c9..51c4b86 100644 --- a/src/Triangle/Meshing/Converter.cs +++ b/src/Triangle/Meshing/Converter.cs @@ -27,7 +27,7 @@ namespace TriangleNet.Meshing /// /// Reconstruct a triangulation from its raw data representation. /// - public static Mesh ToMesh(Polygon polygon, IList triangles) + public static Mesh ToMesh(Polygon polygon, ICollection triangles) { return ToMesh(polygon, triangles.ToArray()); } diff --git a/src/Triangle/Tools/PolygonValidator.cs b/src/Triangle/Tools/PolygonValidator.cs index 7d1c010..4609519 100644 --- a/src/Triangle/Tools/PolygonValidator.cs +++ b/src/Triangle/Tools/PolygonValidator.cs @@ -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}.", points[i]), "PolygonValidator.HasDuplicateVertices()"); } } @@ -122,6 +122,11 @@ namespace TriangleNet.Tools /// /// The polygon. /// The angle threshold. + /// + /// This method assumes that segments are stored in order. There may be different, + /// unconnected contours in the polygon, but the segments of each contour have to + /// be in order to get a meaningful result. + /// public static bool HasBadAngles(IPolygon poly, double threshold = 2e-12) { var logger = Log.Instance; @@ -132,8 +137,6 @@ namespace TriangleNet.Tools Point p0 = null, p1 = null; Point q0, q1; - int count = poly.Points.Count; - foreach (var seg in poly.Segments) { q0 = p0; // Previous segment start point. @@ -156,7 +159,7 @@ namespace TriangleNet.Tools if (IsBadAngle(q0, p0, p1,threshold)) { horrors++; - logger.Warning(String.Format("Bad segment angle found at index {0}.", i), + logger.Warning(string.Format("Bad segment angle found at index {0}.", i), "PolygonValidator.HasBadAngles()"); } } @@ -208,14 +211,14 @@ namespace TriangleNet.Tools if (p.id < 0 || p.id >= count) { horrors++; - logger.Warning(String.Format("Segment {0} has invalid startpoint.", i), + logger.Warning(string.Format("Segment {0} has invalid startpoint.", i), "PolygonValidator.IsConsistent()"); } if (q.id < 0 || q.id >= count) { horrors++; - logger.Warning(String.Format("Segment {0} has invalid endpoint.", i), + logger.Warning(string.Format("Segment {0} has invalid endpoint.", i), "PolygonValidator.IsConsistent()"); } diff --git a/src/Triangle/Tools/VertexSorter.cs b/src/Triangle/Tools/VertexSorter.cs index be90ad9..c23994a 100644 --- a/src/Triangle/Tools/VertexSorter.cs +++ b/src/Triangle/Tools/VertexSorter.cs @@ -216,7 +216,7 @@ namespace TriangleNet.Tools int arraysize = right - left + 1; int oleft = left, oright = right; int pivot; - double pivot1, pivot2; + double px, py; // pivot x and y coordinatex Vertex temp; var array = this.points; @@ -237,8 +237,8 @@ namespace TriangleNet.Tools // Choose a random pivot to split the array. pivot = rand.Next(left, right); - pivot1 = array[pivot].x; - pivot2 = array[pivot].y; + px = array[pivot].x; + py = array[pivot].y; left--; right++; @@ -249,16 +249,16 @@ namespace TriangleNet.Tools { left++; } - while ((left <= right) && ((array[left].x < pivot1) || - ((array[left].x == pivot1) && (array[left].y < pivot2)))); + while ((left <= right) && ((array[left].x < px) || + ((array[left].x == px) && (array[left].y < py)))); // Search for a vertex whose x-coordinate is too small for the right. do { right--; } - while ((left <= right) && ((array[right].x > pivot1) || - ((array[right].x == pivot1) && (array[right].y > pivot2)))); + while ((left <= right) && ((array[right].x > px) || + ((array[right].x == px) && (array[right].y > py)))); if (left < right) { @@ -269,7 +269,7 @@ namespace TriangleNet.Tools } } - // Unlike in vertexsort(), at most one of the following conditionals is true. + // Unlike in QuickSort(), at most one of the following conditionals is true. if (left > median) { // Recursively shuffle the left subset. @@ -299,7 +299,7 @@ namespace TriangleNet.Tools int arraysize = right - left + 1; int oleft = left, oright = right; int pivot; - double pivot1, pivot2; + double px, py; // pivot x and y coordinatex Vertex temp; var array = this.points; @@ -320,8 +320,8 @@ namespace TriangleNet.Tools // Choose a random pivot to split the array. pivot = rand.Next(left, right); - pivot1 = array[pivot].y; - pivot2 = array[pivot].x; + px = array[pivot].y; + py = array[pivot].x; left--; right++; @@ -332,16 +332,16 @@ namespace TriangleNet.Tools { left++; } - while ((left <= right) && ((array[left].y < pivot1) || - ((array[left].y == pivot1) && (array[left].x < pivot2)))); + while ((left <= right) && ((array[left].y < px) || + ((array[left].y == px) && (array[left].x < py)))); // Search for a vertex whose x-coordinate is too small for the right. do { right--; } - while ((left <= right) && ((array[right].y > pivot1) || - ((array[right].y == pivot1) && (array[right].x > pivot2)))); + while ((left <= right) && ((array[right].y > px) || + ((array[right].y == px) && (array[right].x > py)))); if (left < right) { diff --git a/src/Triangle/Voronoi/VoronoiBase.cs b/src/Triangle/Voronoi/VoronoiBase.cs index 323c81e..37978e2 100644 --- a/src/Triangle/Voronoi/VoronoiBase.cs +++ b/src/Triangle/Voronoi/VoronoiBase.cs @@ -37,8 +37,7 @@ namespace TriangleNet.Voronoi /// If set to true, the constuctor will call the Generate /// method, which builds the Voronoi diagram. protected VoronoiBase(Mesh mesh, IVoronoiFactory factory, IPredicates predicates, - bool generate) - : base(false) + bool generate) : base(false) { this.factory = factory; this.predicates = predicates; @@ -105,7 +104,7 @@ namespace TriangleNet.Voronoi // Maps all vertices to a list of leaving edges. var map = new List[mesh.triangles.Count]; - // Compue triangle circumcenters + // Compute triangle circumcenters foreach (var t in mesh.triangles) { id = t.id;