Cleanup and documentation.

This commit is contained in:
wo80
2022-02-14 13:59:16 +01:00
parent 5515941c4b
commit 66197a01e8
7 changed files with 44 additions and 66 deletions
+9 -6
View File
@@ -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
/// </summary>
/// <param name="poly">The polygon.</param>
/// <param name="threshold">The angle threshold.</param>
/// <remarks>
/// 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.
/// </remarks>
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()");
}
+15 -15
View File
@@ -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)
{