Simplify EdgeIterator implementation.

This commit is contained in:
wo80
2022-02-14 21:44:03 +01:00
parent 541e0b4e61
commit 5500ecc166
5 changed files with 78 additions and 132 deletions
@@ -1,58 +0,0 @@
namespace TriangleNet.Rendering.Text
{
using System.Collections.Generic;
using TriangleNet.Geometry;
static class EdgeIterator
{
/// <summary>
/// Enumerate the edges of the mesh.
/// </summary>
/// <param name="mesh"></param>
/// <param name="skipSegments"></param>
/// <returns></returns>
/// <remarks>
/// In contrast to the <see cref="TriangleNet.Meshing.Iterators.EdgeIterator"/> this
/// method will return objects that include the vertex information (and not only the
/// indices).
/// </remarks>
public static IEnumerable<ISegment> EnumerateEdges(Mesh mesh, bool skipSegments = true)
{
foreach (var t in mesh.Triangles)
{
for (int i = 0; i < 3; i++)
{
int nid = t.GetNeighborID(i);
if ((t.ID < nid) || (nid < 0))
{
var s = t.GetSegment(i);
if (skipSegments && s == null)
{
// Since segments will be processed separately, don't
// include them in the enumeration.
yield return new Segment(
t.GetVertex((i + 1) % 3),
t.GetVertex((i + 2) % 3));
}
else
{
if (s == null)
{
yield return new Segment(
t.GetVertex((i + 1) % 3),
t.GetVertex((i + 2) % 3));
}
else
{
yield return s;
}
}
}
}
}
}
}
}
+1 -1
View File
@@ -11,7 +11,7 @@ namespace TriangleNet.Rendering.Text
using System.IO;
using TriangleNet;
using TriangleNet.Geometry;
using TriangleNet.Meshing.Iterators;
using Color = System.Drawing.Color;
using IntPoint = System.Drawing.Point;
using IntRectangle = System.Drawing.Rectangle;
+1
View File
@@ -11,6 +11,7 @@ namespace TriangleNet.Rendering.Text
using System.Text;
using TriangleNet;
using TriangleNet.Geometry;
using TriangleNet.Meshing.Iterators;
/// <summary>
/// Writes a mesh to an SVG file.