diff --git a/src/Triangle.Rendering/Text/EdgeIterator.cs b/src/Triangle.Rendering/Text/EdgeIterator.cs
deleted file mode 100644
index 6f51b05..0000000
--- a/src/Triangle.Rendering/Text/EdgeIterator.cs
+++ /dev/null
@@ -1,58 +0,0 @@
-
-namespace TriangleNet.Rendering.Text
-{
- using System.Collections.Generic;
- using TriangleNet.Geometry;
-
- static class EdgeIterator
- {
- ///
- /// Enumerate the edges of the mesh.
- ///
- ///
- ///
- ///
- ///
- /// In contrast to the this
- /// method will return objects that include the vertex information (and not only the
- /// indices).
- ///
- public static IEnumerable 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;
- }
- }
- }
- }
- }
- }
- }
-}
diff --git a/src/Triangle.Rendering/Text/EpsImage.cs b/src/Triangle.Rendering/Text/EpsImage.cs
index b0c1456..5de9176 100644
--- a/src/Triangle.Rendering/Text/EpsImage.cs
+++ b/src/Triangle.Rendering/Text/EpsImage.cs
@@ -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;
diff --git a/src/Triangle.Rendering/Text/SvgImage.cs b/src/Triangle.Rendering/Text/SvgImage.cs
index 289f182..da19b3f 100644
--- a/src/Triangle.Rendering/Text/SvgImage.cs
+++ b/src/Triangle.Rendering/Text/SvgImage.cs
@@ -11,6 +11,7 @@ namespace TriangleNet.Rendering.Text
using System.Text;
using TriangleNet;
using TriangleNet.Geometry;
+ using TriangleNet.Meshing.Iterators;
///
/// Writes a mesh to an SVG file.
diff --git a/src/Triangle/Mesh.cs b/src/Triangle/Mesh.cs
index 94b2706..07214c0 100644
--- a/src/Triangle/Mesh.cs
+++ b/src/Triangle/Mesh.cs
@@ -124,11 +124,7 @@ namespace TriangleNet
{
get
{
- var e = new EdgeIterator(this);
- while (e.MoveNext())
- {
- yield return e.Current;
- }
+ return new EdgeIterator().EnumerateEdges(this);
}
}
diff --git a/src/Triangle/Meshing/Iterators/EdgeIterator.cs b/src/Triangle/Meshing/Iterators/EdgeIterator.cs
index 58d88bb..056b925 100644
--- a/src/Triangle/Meshing/Iterators/EdgeIterator.cs
+++ b/src/Triangle/Meshing/Iterators/EdgeIterator.cs
@@ -13,89 +13,96 @@ namespace TriangleNet.Meshing.Iterators
///
/// Enumerates the edges of a triangulation.
///
- public class EdgeIterator : IEnumerator
+ public class EdgeIterator
{
- IEnumerator triangles;
- Otri tri = default(Otri);
- Otri neighbor = default(Otri);
- Osub sub = default(Osub);
- Edge current;
- Vertex p1, p2;
+ public IEnumerable EnumerateEdges(Mesh mesh)
+ {
+ Otri tri = default;
+ Otri neighbor = default;
+ Osub sub = default;
+
+ Vertex p1, p2;
+
+ foreach (var t in mesh.triangles)
+ {
+ tri.tri = t;
+ tri.orient = 0;
+
+ for (int i = 0; i < 3; i++)
+ {
+ tri.Sym(ref neighbor);
+
+ int nid = neighbor.tri.id;
+
+ if ((tri.tri.id < nid) || (nid == Mesh.DUMMY))
+ {
+ p1 = tri.Org();
+ p2 = tri.Dest();
+
+ tri.Pivot(ref sub);
+
+ // Boundary mark of dummysub is 0, so we don't need to worry about that.
+ yield return new Edge(p1.id, p2.id, sub.seg.boundary);
+ }
+
+ tri.orient++;
+ }
+ }
+ }
///
- /// Initializes a new instance of the class.
+ /// Enumerate the edges of the mesh.
///
- public EdgeIterator(Mesh mesh)
+ ///
+ ///
+ ///
+ ///
+ /// In contrast to the this method will return
+ /// objects that include the vertex information (and not only the indices).
+ ///
+ public static IEnumerable EnumerateEdges(Mesh mesh, bool skipSegments = true)
{
- triangles = mesh.triangles.GetEnumerator();
- triangles.MoveNext();
+ Otri tri = default;
+ Otri neighbor = default;
+ Osub sub = default;
- tri.tri = triangles.Current;
- tri.orient = 0;
- }
+ Vertex p1, p2;
- public Edge Current
- {
- get { return current; }
- }
+ bool segments = !skipSegments;
- public void Dispose()
- {
- this.triangles.Dispose();
- }
-
- object System.Collections.IEnumerator.Current
- {
- get { return current; }
- }
-
- public bool MoveNext()
- {
- if (tri.tri == null)
+ foreach (var t in mesh.triangles)
{
- return false;
- }
+ tri.tri = t;
+ tri.orient = 0;
- current = null;
-
- while (current == null)
- {
- if (tri.orient == 3)
+ for (int i = 0; i < 3; i++)
{
- if (triangles.MoveNext())
+ tri.Sym(ref neighbor);
+
+ int nid = neighbor.tri.id;
+
+ if ((tri.tri.id < nid) || (nid == Mesh.DUMMY))
{
- tri.tri = triangles.Current;
- tri.orient = 0;
- }
- else
- {
- // Finally no more triangles
- return false;
+ p1 = tri.Org();
+ p2 = tri.Dest();
+
+ tri.Pivot(ref sub);
+
+ if (sub.seg.hash == Mesh.DUMMY)
+ {
+ yield return new Segment(p1, p2);
+ }
+ else if (segments)
+ {
+ // Segments might be processed separately, so only
+ // include them if requested.
+ yield return sub.seg;
+ }
}
+
+ tri.orient++;
}
-
- tri.Sym(ref neighbor);
-
- if ((tri.tri.id < neighbor.tri.id) || (neighbor.tri.id == Mesh.DUMMY))
- {
- p1 = tri.Org();
- p2 = tri.Dest();
-
- tri.Pivot(ref sub);
-
- // Boundary mark of dummysub is 0, so we don't need to worry about that.
- current = new Edge(p1.id, p2.id, sub.seg.boundary);
- }
-
- tri.orient++;
}
-
- return true;
- }
-
- public void Reset()
- {
- this.triangles.Reset();
}
}
}