// ----------------------------------------------------------------------- // // Original Triangle code by Jonathan Richard Shewchuk, http://www.cs.cmu.edu/~quake/triangle.html // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/ // // ----------------------------------------------------------------------- namespace UnityEngine.U2D.Animation.TriangleNet .Topology { using System; using Animation.TriangleNet.Geometry; /// /// The triangle data structure. /// internal class Triangle : ITriangle { // Hash for dictionary. Will be set by mesh instance. internal int hash; // The ID is only used for mesh output. internal int id; internal Otri[] neighbors; internal Vertex[] vertices; internal Osub[] subsegs; internal int label; internal double area; internal bool infected; /// /// Initializes a new instance of the class. /// public Triangle() { // Three NULL vertices. vertices = new Vertex[3]; // Initialize the three adjoining subsegments to be the omnipresent subsegment. subsegs = new Osub[3]; // Initialize the three adjoining triangles to be "outer space". neighbors = new Otri[3]; // area = -1.0; } #region Public properties /// /// Gets or sets the triangle id. /// public int ID { get { return this.id; } set { this.id = value; } } /// /// Region ID the triangle belongs to. /// public int Label { get { return this.label; } set { this.label = value; } } /// /// Gets the triangle area constraint. /// public double Area { get { return this.area; } set { this.area = value; } } /// /// Gets the specified corners vertex. /// public Vertex GetVertex(int index) { return this.vertices[index]; // TODO: Check range? } public int GetVertexID(int index) { return this.vertices[index].id; } /// /// Gets a triangles' neighbor. /// /// The neighbor index (0, 1 or 2). /// The neigbbor opposite of vertex with given index. public ITriangle GetNeighbor(int index) { return neighbors[index].tri.hash == Mesh.DUMMY ? null : neighbors[index].tri; } /// public int GetNeighborID(int index) { return neighbors[index].tri.hash == Mesh.DUMMY ? -1 : neighbors[index].tri.id; } /// /// Gets a triangles segment. /// /// The vertex index (0, 1 or 2). /// The segment opposite of vertex with given index. public ISegment GetSegment(int index) { return subsegs[index].seg.hash == Mesh.DUMMY ? null : subsegs[index].seg; } #endregion public override int GetHashCode() { return this.hash; } public override string ToString() { return String.Format("TID {0}", hash); } } }