EdgeIterator.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // -----------------------------------------------------------------------
  2. // <copyright file="EdgeEnumerator.cs" company="">
  3. // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/
  4. // </copyright>
  5. // -----------------------------------------------------------------------
  6. namespace UnityEngine.U2D.Animation.TriangleNet
  7. .Meshing.Iterators
  8. {
  9. using System.Collections.Generic;
  10. using Animation.TriangleNet.Topology;
  11. using Animation.TriangleNet.Geometry;
  12. /// <summary>
  13. /// Enumerates the edges of a triangulation.
  14. /// </summary>
  15. internal class EdgeIterator : IEnumerator<Edge>
  16. {
  17. IEnumerator<Triangle> triangles;
  18. Otri tri = default(Otri);
  19. Otri neighbor = default(Otri);
  20. Osub sub = default(Osub);
  21. Edge current;
  22. Vertex p1, p2;
  23. /// <summary>
  24. /// Initializes a new instance of the <see cref="EdgeIterator" /> class.
  25. /// </summary>
  26. public EdgeIterator(Mesh mesh)
  27. {
  28. triangles = mesh.triangles.GetEnumerator();
  29. triangles.MoveNext();
  30. tri.tri = triangles.Current;
  31. tri.orient = 0;
  32. }
  33. public Edge Current
  34. {
  35. get { return current; }
  36. }
  37. public void Dispose()
  38. {
  39. this.triangles.Dispose();
  40. }
  41. object System.Collections.IEnumerator.Current
  42. {
  43. get { return current; }
  44. }
  45. public bool MoveNext()
  46. {
  47. if (tri.tri == null)
  48. {
  49. return false;
  50. }
  51. current = null;
  52. while (current == null)
  53. {
  54. if (tri.orient == 3)
  55. {
  56. if (triangles.MoveNext())
  57. {
  58. tri.tri = triangles.Current;
  59. tri.orient = 0;
  60. }
  61. else
  62. {
  63. // Finally no more triangles
  64. return false;
  65. }
  66. }
  67. tri.Sym(ref neighbor);
  68. if ((tri.tri.id < neighbor.tri.id) || (neighbor.tri.id == Mesh.DUMMY))
  69. {
  70. p1 = tri.Org();
  71. p2 = tri.Dest();
  72. tri.Pivot(ref sub);
  73. // Boundary mark of dummysub is 0, so we don't need to worry about that.
  74. current = new Edge(p1.id, p2.id, sub.seg.boundary);
  75. }
  76. tri.orient++;
  77. }
  78. return true;
  79. }
  80. public void Reset()
  81. {
  82. this.triangles.Reset();
  83. }
  84. }
  85. }