/// <summary> /// Calculate the triangulation of the supplied vertices. /// /// This overload allows you to reuse the result object, to prevent /// garbage from being created. /// </summary> /// <param name="verts">List of vertices to use for calculation</param> /// <param name="result">Result object to store the triangulation in</param> public void CalculateTriangulation(IList <Vector2> verts, ref DelaunayTriangulation result) { if (verts == null) { throw new ArgumentNullException("points"); } if (verts.Count < 3) { throw new ArgumentException("You need at least 3 points for a triangulation"); } triangles.Clear(); this.verts = verts; highest = 0; for (int i = 0; i < verts.Count; i++) { if (Higher(highest, i)) { highest = i; } } //ShuffleIndices(); // Add first triangle, the bounding triangle. triangles.Add(new TriangleNode(-2, -1, highest)); RunBowyerWatson(); GenerateResult(ref result); this.verts = null; }
/// <summary> /// Filter the points array and triangle tree into a readable result. /// </summary> void GenerateResult(ref DelaunayTriangulation result) { if (result == null) { result = new DelaunayTriangulation(); } result.Clear(); for (int i = 0; i < verts.Count; i++) { result.Vertices.Add(verts[i]); } for (int i = 1; i < triangles.Count; i++) { var t = triangles[i]; if (t.IsLeaf && t.IsInner) { result.Triangles.Add(t.P0); result.Triangles.Add(t.P1); result.Triangles.Add(t.P2); } } }
/// <summary> /// Calculate the triangulation of the supplied vertices /// </summary> /// <param name="verts">List of vertices to use for calculation</param> /// <returns>The calculated Delaunay triangulation<returns> public DelaunayTriangulation CalculateTriangulation(IList <Vector2> verts) { DelaunayTriangulation result = null; CalculateTriangulation(verts, ref result); return(result); }
internal VoronoiDiagram() { Triangulation = new DelaunayTriangulation(); Sites = Triangulation.Vertices; Vertices = new List <Vector2>(); Edges = new List <Edge>(); FirstEdgeBySite = new List <int>(); }