Segment.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // -----------------------------------------------------------------------
  2. // <copyright file="Segment.cs" company="">
  3. // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/
  4. // </copyright>
  5. // -----------------------------------------------------------------------
  6. namespace UnityEngine.U2D.Animation.TriangleNet
  7. .Geometry
  8. {
  9. using System;
  10. /// <summary>
  11. /// Represents a straight line segment in 2D space.
  12. /// </summary>
  13. internal class Segment : ISegment
  14. {
  15. Vertex v0;
  16. Vertex v1;
  17. int label;
  18. /// <summary>
  19. /// Gets or sets the segments boundary mark.
  20. /// </summary>
  21. public int Label
  22. {
  23. get { return label; }
  24. set { label = value; }
  25. }
  26. /// <summary>
  27. /// Gets the first endpoints index.
  28. /// </summary>
  29. public int P0
  30. {
  31. get { return v0.id; }
  32. }
  33. /// <summary>
  34. /// Gets the second endpoints index.
  35. /// </summary>
  36. public int P1
  37. {
  38. get { return v1.id; }
  39. }
  40. /// <summary>
  41. /// Initializes a new instance of the <see cref="Segment" /> class.
  42. /// </summary>
  43. public Segment(Vertex v0, Vertex v1)
  44. : this(v0, v1, 0)
  45. {
  46. }
  47. /// <summary>
  48. /// Initializes a new instance of the <see cref="Segment" /> class.
  49. /// </summary>
  50. public Segment(Vertex v0, Vertex v1, int label)
  51. {
  52. this.v0 = v0;
  53. this.v1 = v1;
  54. this.label = label;
  55. }
  56. /// <summary>
  57. /// Gets the specified segment endpoint.
  58. /// </summary>
  59. /// <param name="index">The endpoint index (0 or 1).</param>
  60. /// <returns></returns>
  61. public Vertex GetVertex(int index)
  62. {
  63. if (index == 0)
  64. {
  65. return v0;
  66. }
  67. if (index == 1)
  68. {
  69. return v1;
  70. }
  71. throw new IndexOutOfRangeException();
  72. }
  73. /// <summary>
  74. /// WARNING: not implemented.
  75. /// </summary>
  76. public ITriangle GetTriangle(int index)
  77. {
  78. throw new NotImplementedException();
  79. }
  80. }
  81. }