Cleanup and documentation.
This commit is contained in:
@@ -3,7 +3,6 @@ using System.Drawing;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using TriangleNet;
|
||||
using TriangleNet.Logging;
|
||||
|
||||
namespace MeshExplorer
|
||||
{
|
||||
|
||||
@@ -21,28 +21,16 @@ namespace TriangleNet.Geometry
|
||||
List<ISegment> segments;
|
||||
|
||||
/// <inheritdoc />
|
||||
public List<Vertex> Points
|
||||
{
|
||||
get { return points; }
|
||||
}
|
||||
public List<Vertex> Points => points;
|
||||
|
||||
/// <inheritdoc />
|
||||
public List<Point> Holes
|
||||
{
|
||||
get { return holes; }
|
||||
}
|
||||
public List<Point> Holes => holes;
|
||||
|
||||
/// <inheritdoc />
|
||||
public List<RegionPointer> Regions
|
||||
{
|
||||
get { return regions; }
|
||||
}
|
||||
public List<RegionPointer> Regions => regions;
|
||||
|
||||
/// <inheritdoc />
|
||||
public List<ISegment> Segments
|
||||
{
|
||||
get { return segments; }
|
||||
}
|
||||
public List<ISegment> Segments => segments;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool HasPointMarkers { get; set; }
|
||||
@@ -112,20 +100,13 @@ namespace TriangleNet.Geometry
|
||||
return bounds;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a vertex to the polygon.
|
||||
/// </summary>
|
||||
/// <param name="vertex">The vertex to insert.</param>
|
||||
/// <inheritdoc />
|
||||
public void Add(Vertex vertex)
|
||||
{
|
||||
this.points.Add(vertex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a segment to the polygon.
|
||||
/// </summary>
|
||||
/// <param name="segment">The segment to insert.</param>
|
||||
/// <param name="insert">If true, both endpoints will be added to the points list.</param>
|
||||
/// <inheritdoc />
|
||||
public void Add(ISegment segment, bool insert = false)
|
||||
{
|
||||
this.segments.Add(segment);
|
||||
@@ -137,11 +118,7 @@ namespace TriangleNet.Geometry
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a segment to the polygon.
|
||||
/// </summary>
|
||||
/// <param name="segment">The segment to insert.</param>
|
||||
/// <param name="index">The index of the segment endpoint to add to the points list (must be 0 or 1).</param>
|
||||
/// <inheritdoc />
|
||||
public void Add(ISegment segment, int index)
|
||||
{
|
||||
this.segments.Add(segment);
|
||||
@@ -149,11 +126,7 @@ namespace TriangleNet.Geometry
|
||||
this.points.Add(segment.GetVertex(index));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a contour to the polygon.
|
||||
/// </summary>
|
||||
/// <param name="contour">The contour to insert.</param>
|
||||
/// <param name="hole">Treat contour as a hole.</param>
|
||||
/// <inheritdoc />
|
||||
public void Add(Contour contour, bool hole = false)
|
||||
{
|
||||
if (hole)
|
||||
@@ -167,11 +140,7 @@ namespace TriangleNet.Geometry
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a contour to the polygon.
|
||||
/// </summary>
|
||||
/// <param name="contour">The contour to insert.</param>
|
||||
/// <param name="hole">Point inside the contour, making it a hole.</param>
|
||||
/// <inheritdoc />
|
||||
public void Add(Contour contour, Point hole)
|
||||
{
|
||||
this.points.AddRange(contour.Points);
|
||||
|
||||
@@ -6,6 +6,14 @@ namespace TriangleNet.Meshing
|
||||
/// </summary>
|
||||
public class ConstraintOptions
|
||||
{
|
||||
// TODO: remove ConstraintOptions.UseRegions
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether to use regions.
|
||||
/// </summary>
|
||||
[System.Obsolete("Not used anywhere, will be removed in beta 4.")]
|
||||
public bool UseRegions { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether to create a Conforming
|
||||
/// Delaunay triangulation.
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace TriangleNet.Meshing
|
||||
/// <summary>
|
||||
/// Reconstruct a triangulation from its raw data representation.
|
||||
/// </summary>
|
||||
public static Mesh ToMesh(Polygon polygon, IList<ITriangle> triangles)
|
||||
public static Mesh ToMesh(Polygon polygon, ICollection<ITriangle> triangles)
|
||||
{
|
||||
return ToMesh(polygon, triangles.ToArray());
|
||||
}
|
||||
|
||||
@@ -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()");
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -37,8 +37,7 @@ namespace TriangleNet.Voronoi
|
||||
/// <param name="generate">If set to true, the constuctor will call the Generate
|
||||
/// method, which builds the Voronoi diagram.</param>
|
||||
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<HalfEdge>[mesh.triangles.Count];
|
||||
|
||||
// Compue triangle circumcenters
|
||||
// Compute triangle circumcenters
|
||||
foreach (var t in mesh.triangles)
|
||||
{
|
||||
id = t.id;
|
||||
|
||||
Reference in New Issue
Block a user