public TpplPoly(TpplPoly src) { Clear(); Hole = src.Hole; if (src.Points != null) { Points = new List <TpplPoint>(src.Points.Count); for (int i = 0; i < Points.Count; i++) { Points[i] = new TpplPoint(src.Points[i]); } } }
public int Triangulate_EC(TpplPoly poly, List <TpplPoly> triangles) { int numvertices; List <PartitionVertex> vertices = null; PartitionVertex ear = null; TpplPoly triangle = new TpplPoly(); int i, j; bool earfound; if (poly.Count < 3) { return(0); } if (poly.Count == 3) { triangles.Add(poly); return(1); } numvertices = poly.Count; vertices = new List <PartitionVertex>(numvertices); for (i = 0; i < numvertices; i++) { vertices.Add(new PartitionVertex()); } for (i = 0; i < numvertices; i++) { vertices[i].IsActive = true; vertices[i].P = poly[i]; if (i == (numvertices - 1)) { vertices[i].Next = vertices[0]; } else { vertices[i].Next = vertices[i + 1]; } if (i == 0) { vertices[i].Previous = vertices[numvertices - 1]; } else { vertices[i].Previous = vertices[i - 1]; } } for (i = 0; i < numvertices; i++) { UpdateVertex(vertices[i], vertices); } for (i = 0; i < numvertices - 3; i++) { earfound = false; //find the most extruded ear for (j = 0; j < numvertices; j++) { if (!vertices[j].IsActive) { continue; } if (!vertices[j].IsEar) { continue; } if (!earfound) { earfound = true; ear = vertices[j]; } else { if (vertices[j].Angle > ear.Angle) { ear = vertices[j]; } } } if (!earfound) { vertices.Clear(); return(0); } triangle = new TpplPoly(ear.Previous.P, ear.P, ear.Next.P); triangles.Add(triangle); ear.IsActive = false; ear.Previous.Next = ear.Next; ear.Next.Previous = ear.Previous; if (i == numvertices - 4) { break; } UpdateVertex(ear.Previous, vertices); UpdateVertex(ear.Next, vertices); } for (i = 0; i < numvertices; i++) { if (vertices[i].IsActive) { triangle = new TpplPoly(vertices[i].Previous.P, vertices[i].P, vertices[i].Next.P); triangles.Add(triangle); break; } } vertices.Clear(); return(1); }