Osub.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. // -----------------------------------------------------------------------
  2. // <copyright file="Osub.cs">
  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. /// An oriented subsegment.
  14. /// </summary>
  15. /// <remarks>
  16. /// Includes a pointer to a subsegment and an orientation. The orientation denotes a
  17. /// side of the edge. Hence, there are two possible orientations. By convention, the
  18. /// edge is always directed so that the "side" denoted is the right side of the edge.
  19. /// </remarks>
  20. internal struct Osub
  21. {
  22. internal SubSegment seg;
  23. internal int orient; // Ranges from 0 to 1.
  24. public SubSegment Segment
  25. {
  26. get { return seg; }
  27. }
  28. public override string ToString()
  29. {
  30. if (seg == null)
  31. {
  32. return "O-TID [null]";
  33. }
  34. return String.Format("O-SID {0}", seg.hash);
  35. }
  36. #region Osub primitives
  37. /// <summary>
  38. /// Reverse the orientation of a subsegment. [sym(ab) -> ba]
  39. /// </summary>
  40. public void Sym(ref Osub os)
  41. {
  42. os.seg = seg;
  43. os.orient = 1 - orient;
  44. }
  45. /// <summary>
  46. /// Reverse the orientation of a subsegment. [sym(ab) -> ba]
  47. /// </summary>
  48. public void Sym()
  49. {
  50. orient = 1 - orient;
  51. }
  52. /// <summary>
  53. /// Find adjoining subsegment with the same origin. [pivot(ab) -> a*]
  54. /// </summary>
  55. /// <remarks>spivot() finds the other subsegment (from the same segment)
  56. /// that shares the same origin.
  57. /// </remarks>
  58. public void Pivot(ref Osub os)
  59. {
  60. os = seg.subsegs[orient];
  61. }
  62. /// <summary>
  63. /// Finds a triangle abutting a subsegment.
  64. /// </summary>
  65. internal void Pivot(ref Otri ot)
  66. {
  67. ot = seg.triangles[orient];
  68. }
  69. /// <summary>
  70. /// Find next subsegment in sequence. [next(ab) -> b*]
  71. /// </summary>
  72. public void Next(ref Osub ot)
  73. {
  74. ot = seg.subsegs[1 - orient];
  75. }
  76. /// <summary>
  77. /// Find next subsegment in sequence. [next(ab) -> b*]
  78. /// </summary>
  79. public void Next()
  80. {
  81. this = seg.subsegs[1 - orient];
  82. }
  83. /// <summary>
  84. /// Get the origin of a subsegment
  85. /// </summary>
  86. public Vertex Org()
  87. {
  88. return seg.vertices[orient];
  89. }
  90. /// <summary>
  91. /// Get the destination of a subsegment
  92. /// </summary>
  93. public Vertex Dest()
  94. {
  95. return seg.vertices[1 - orient];
  96. }
  97. #endregion
  98. #region Osub primitives (internal)
  99. /// <summary>
  100. /// Set the origin or destination of a subsegment.
  101. /// </summary>
  102. internal void SetOrg(Vertex vertex)
  103. {
  104. seg.vertices[orient] = vertex;
  105. }
  106. /// <summary>
  107. /// Set destination of a subsegment.
  108. /// </summary>
  109. internal void SetDest(Vertex vertex)
  110. {
  111. seg.vertices[1 - orient] = vertex;
  112. }
  113. /// <summary>
  114. /// Get the origin of the segment that includes the subsegment.
  115. /// </summary>
  116. internal Vertex SegOrg()
  117. {
  118. return seg.vertices[2 + orient];
  119. }
  120. /// <summary>
  121. /// Get the destination of the segment that includes the subsegment.
  122. /// </summary>
  123. internal Vertex SegDest()
  124. {
  125. return seg.vertices[3 - orient];
  126. }
  127. /// <summary>
  128. /// Set the origin of the segment that includes the subsegment.
  129. /// </summary>
  130. internal void SetSegOrg(Vertex vertex)
  131. {
  132. seg.vertices[2 + orient] = vertex;
  133. }
  134. /// <summary>
  135. /// Set the destination of the segment that includes the subsegment.
  136. /// </summary>
  137. internal void SetSegDest(Vertex vertex)
  138. {
  139. seg.vertices[3 - orient] = vertex;
  140. }
  141. /* Unused primitives.
  142. /// <summary>
  143. /// Find adjoining subsegment with the same origin. [pivot(ab) -> a*]
  144. /// </summary>
  145. public void PivotSelf()
  146. {
  147. this = seg.subsegs[orient];
  148. }
  149. /// <summary>
  150. /// Read a boundary marker.
  151. /// </summary>
  152. /// <remarks>Boundary markers are used to hold user-defined tags for
  153. /// setting boundary conditions in finite element solvers.</remarks>
  154. public int Mark()
  155. {
  156. return seg.boundary;
  157. }
  158. /// <summary>
  159. /// Set a boundary marker.
  160. /// </summary>
  161. public void SetMark(int value)
  162. {
  163. seg.boundary = value;
  164. }
  165. /// <summary>
  166. /// Copy a subsegment.
  167. /// </summary>
  168. public void Copy(ref Osub o2)
  169. {
  170. o2.seg = seg;
  171. o2.orient = orient;
  172. }
  173. //*/
  174. /// <summary>
  175. /// Bond two subsegments together. [bond(abc, ba)]
  176. /// </summary>
  177. internal void Bond(ref Osub os)
  178. {
  179. seg.subsegs[orient] = os;
  180. os.seg.subsegs[os.orient] = this;
  181. }
  182. /// <summary>
  183. /// Dissolve a subsegment bond (from one side).
  184. /// </summary>
  185. /// <remarks>Note that the other subsegment will still think it's
  186. /// connected to this subsegment.</remarks>
  187. internal void Dissolve(SubSegment dummy)
  188. {
  189. seg.subsegs[orient].seg = dummy;
  190. }
  191. /// <summary>
  192. /// Test for equality of subsegments.
  193. /// </summary>
  194. internal bool Equal(Osub os)
  195. {
  196. return ((seg == os.seg) && (orient == os.orient));
  197. }
  198. /// <summary>
  199. /// Dissolve a bond (from the subsegment side).
  200. /// </summary>
  201. internal void TriDissolve(Triangle dummy)
  202. {
  203. seg.triangles[orient].tri = dummy;
  204. }
  205. /// <summary>
  206. /// Check a subsegment's deallocation.
  207. /// </summary>
  208. internal static bool IsDead(SubSegment sub)
  209. {
  210. return sub.subsegs[0].seg == null;
  211. }
  212. /// <summary>
  213. /// Set a subsegment's deallocation.
  214. /// </summary>
  215. internal static void Kill(SubSegment sub)
  216. {
  217. sub.subsegs[0].seg = null;
  218. sub.subsegs[1].seg = null;
  219. }
  220. #endregion
  221. }
  222. }