SubSegment.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // -----------------------------------------------------------------------
  2. // <copyright file="Segment.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. .Topology
  9. {
  10. using System;
  11. using Animation.TriangleNet.Geometry;
  12. /// <summary>
  13. /// The subsegment data structure.
  14. /// </summary>
  15. internal class SubSegment : ISegment
  16. {
  17. // Hash for dictionary. Will be set by mesh instance.
  18. internal int hash;
  19. internal Osub[] subsegs;
  20. internal Vertex[] vertices;
  21. internal Otri[] triangles;
  22. internal int boundary;
  23. public SubSegment()
  24. {
  25. // Four NULL vertices.
  26. vertices = new Vertex[4];
  27. // Set the boundary marker to zero.
  28. boundary = 0;
  29. // Initialize the two adjoining subsegments to be the omnipresent
  30. // subsegment.
  31. subsegs = new Osub[2];
  32. // Initialize the two adjoining triangles to be "outer space."
  33. triangles = new Otri[2];
  34. }
  35. #region Public properties
  36. /// <summary>
  37. /// Gets the first endpoints vertex id.
  38. /// </summary>
  39. public int P0
  40. {
  41. get { return this.vertices[0].id; }
  42. }
  43. /// <summary>
  44. /// Gets the seconds endpoints vertex id.
  45. /// </summary>
  46. public int P1
  47. {
  48. get { return this.vertices[1].id; }
  49. }
  50. /// <summary>
  51. /// Gets the segment boundary mark.
  52. /// </summary>
  53. public int Label
  54. {
  55. get { return this.boundary; }
  56. }
  57. #endregion
  58. /// <summary>
  59. /// Gets the segments endpoint.
  60. /// </summary>
  61. public Vertex GetVertex(int index)
  62. {
  63. return this.vertices[index]; // TODO: Check range?
  64. }
  65. /// <summary>
  66. /// Gets an adjoining triangle.
  67. /// </summary>
  68. public ITriangle GetTriangle(int index)
  69. {
  70. return triangles[index].tri.hash == Mesh.DUMMY ? null : triangles[index].tri;
  71. }
  72. public override int GetHashCode()
  73. {
  74. return this.hash;
  75. }
  76. public override string ToString()
  77. {
  78. return String.Format("SID {0}", hash);
  79. }
  80. }
  81. }