Vertex.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // -----------------------------------------------------------------------
  2. // <copyright file="Vertex.cs" company="">
  3. // Original Triangle code by Jonathan Richard Shewchuk, http://www.cs.cmu.edu/~quake/triangle.html
  4. // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/
  5. // </copyright>
  6. // -----------------------------------------------------------------------
  7. namespace UnityEngine.U2D.Animation.TriangleNet
  8. .Geometry
  9. {
  10. using System;
  11. using Animation.TriangleNet.Topology;
  12. /// <summary>
  13. /// The vertex data structure.
  14. /// </summary>
  15. internal class Vertex : Point
  16. {
  17. // Hash for dictionary. Will be set by mesh instance.
  18. internal int hash;
  19. #if USE_ATTRIBS
  20. internal double[] attributes;
  21. #endif
  22. internal VertexType type;
  23. internal Otri tri;
  24. /// <summary>
  25. /// Initializes a new instance of the <see cref="Vertex" /> class.
  26. /// </summary>
  27. public Vertex()
  28. : this(0, 0, 0)
  29. {
  30. }
  31. /// <summary>
  32. /// Initializes a new instance of the <see cref="Vertex" /> class.
  33. /// </summary>
  34. /// <param name="x">The x coordinate of the vertex.</param>
  35. /// <param name="y">The y coordinate of the vertex.</param>
  36. public Vertex(double x, double y)
  37. : this(x, y, 0)
  38. {
  39. }
  40. /// <summary>
  41. /// Initializes a new instance of the <see cref="Vertex" /> class.
  42. /// </summary>
  43. /// <param name="x">The x coordinate of the vertex.</param>
  44. /// <param name="y">The y coordinate of the vertex.</param>
  45. /// <param name="mark">The boundary mark.</param>
  46. public Vertex(double x, double y, int mark)
  47. : base(x, y, mark)
  48. {
  49. this.type = VertexType.InputVertex;
  50. }
  51. #if USE_ATTRIBS
  52. /// <summary>
  53. /// Initializes a new instance of the <see cref="Vertex" /> class.
  54. /// </summary>
  55. /// <param name="x">The x coordinate of the vertex.</param>
  56. /// <param name="y">The y coordinate of the vertex.</param>
  57. /// <param name="mark">The boundary mark.</param>
  58. /// <param name="attribs">The number of point attributes.</param>
  59. public Vertex(double x, double y, int mark, int attribs)
  60. : this(x, y, mark)
  61. {
  62. if (attribs > 0)
  63. {
  64. this.attributes = new double[attribs];
  65. }
  66. }
  67. #endif
  68. #region Public properties
  69. #if USE_ATTRIBS
  70. /// <summary>
  71. /// Gets the vertex attributes (may be null).
  72. /// </summary>
  73. public double[] Attributes
  74. {
  75. get { return this.attributes; }
  76. }
  77. #endif
  78. /// <summary>
  79. /// Gets the vertex type.
  80. /// </summary>
  81. public VertexType Type
  82. {
  83. get { return this.type; }
  84. }
  85. /// <summary>
  86. /// Gets the specified coordinate of the vertex.
  87. /// </summary>
  88. /// <param name="i">Coordinate index.</param>
  89. /// <returns>X coordinate, if index is 0, Y coordinate, if index is 1.</returns>
  90. public double this[int i]
  91. {
  92. get
  93. {
  94. if (i == 0)
  95. {
  96. return x;
  97. }
  98. if (i == 1)
  99. {
  100. return y;
  101. }
  102. throw new ArgumentOutOfRangeException("Index must be 0 or 1.");
  103. }
  104. }
  105. #endregion
  106. public override int GetHashCode()
  107. {
  108. return this.hash;
  109. }
  110. }
  111. }