Face.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // -----------------------------------------------------------------------
  2. // <copyright file="Face.cs">
  3. // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/
  4. // </copyright>
  5. // -----------------------------------------------------------------------
  6. namespace UnityEngine.U2D.Animation.TriangleNet
  7. .Topology.DCEL
  8. {
  9. using System.Collections.Generic;
  10. using Animation.TriangleNet.Geometry;
  11. /// <summary>
  12. /// A face of DCEL mesh.
  13. /// </summary>
  14. internal class Face
  15. {
  16. #region Static initialization of "Outer Space" face
  17. internal static readonly Face Empty;
  18. static Face()
  19. {
  20. Empty = new Face(null);
  21. Empty.id = -1;
  22. }
  23. #endregion
  24. internal int id;
  25. internal int mark = 0;
  26. internal Point generator;
  27. internal HalfEdge edge;
  28. internal bool bounded;
  29. /// <summary>
  30. /// Gets or sets the face id.
  31. /// </summary>
  32. public int ID
  33. {
  34. get { return id; }
  35. set { id = value; }
  36. }
  37. /// <summary>
  38. /// Gets or sets a half-edge connected to the face.
  39. /// </summary>
  40. public HalfEdge Edge
  41. {
  42. get { return edge; }
  43. set { edge = value; }
  44. }
  45. /// <summary>
  46. /// Gets or sets a value, indicating if the face is bounded (for Voronoi diagram).
  47. /// </summary>
  48. public bool Bounded
  49. {
  50. get { return bounded; }
  51. set { bounded = value; }
  52. }
  53. /// <summary>
  54. /// Initializes a new instance of the <see cref="Face" /> class.
  55. /// </summary>
  56. /// <param name="generator">The generator of this face (for Voronoi diagram)</param>
  57. public Face(Point generator)
  58. : this(generator, null)
  59. {
  60. }
  61. /// <summary>
  62. /// Initializes a new instance of the <see cref="Face" /> class.
  63. /// </summary>
  64. /// <param name="generator">The generator of this face (for Voronoi diagram)</param>
  65. /// <param name="edge">The half-edge connected to this face.</param>
  66. public Face(Point generator, HalfEdge edge)
  67. {
  68. this.generator = generator;
  69. this.edge = edge;
  70. this.bounded = true;
  71. if (generator != null)
  72. {
  73. this.id = generator.ID;
  74. }
  75. }
  76. /// <summary>
  77. /// Enumerates all half-edges of the face boundary.
  78. /// </summary>
  79. /// <returns></returns>
  80. public IEnumerable<HalfEdge> EnumerateEdges()
  81. {
  82. var edge = this.Edge;
  83. int first = edge.ID;
  84. do
  85. {
  86. yield return edge;
  87. edge = edge.Next;
  88. }
  89. while (edge.ID != first);
  90. }
  91. public override string ToString()
  92. {
  93. return string.Format("F-ID {0}", id);
  94. }
  95. }
  96. }