/// <summary> /// Form a Delaunay triangulation by the divide-and-conquer method. /// </summary> /// <returns></returns> /// <remarks> /// Sorts the vertices, calls a recursive procedure to triangulate them, and /// removes the bounding box, setting boundary markers as appropriate. /// </remarks> public IMesh Triangulate(IList <Vertex> points, Configuration config) { this.predicates = config.Predicates(); this.mesh = new Mesh(config); this.mesh.TransferNodes(points); Otri hullleft = default(Otri), hullright = default(Otri); int i, j, n = points.Count; // Allocate an array of pointers to vertices for sorting. this.sortarray = new Vertex[n]; i = 0; foreach (var v in points) { sortarray[i++] = v; } // Sort the vertices. VertexSorter.Sort(sortarray); // Discard duplicate vertices, which can really mess up the algorithm. i = 0; for (j = 1; j < n; j++) { if ((sortarray[i].x == sortarray[j].x) && (sortarray[i].y == sortarray[j].y)) { if (Log.Verbose) { Log.Instance.Warning( String.Format("A duplicate vertex appeared and was ignored (ID {0}).", sortarray[j].id), "Dwyer.Triangulate()"); } sortarray[j].type = VertexType.UndeadVertex; mesh.undeads++; } else { i++; sortarray[i] = sortarray[j]; } } i++; if (UseDwyer) { // Re-sort the array of vertices to accommodate alternating cuts. VertexSorter.Alternate(sortarray, i); } // Form the Delaunay triangulation. DivconqRecurse(0, i - 1, 0, ref hullleft, ref hullright); this.mesh.hullsize = RemoveGhosts(ref hullleft); return(this.mesh); }
public void IdentifiesTopLeftIndex3() { var points = new List <Point> { new Point(0, 1), new Point(-1, 0), new Point(1, 0), }; int tl = VertexSorter.GetTopLeftIndex(points); Assert.AreEqual(0, tl); }
public void IdentifiesTopLeftPoint4() { var points = new List <Point> { new Point(1, 1), new Point(-1, 0), new Point(1, 0), }; Point tl = VertexSorter.GetTopLeft(points); Assert.AreEqual(1, tl.X); Assert.AreEqual(1, tl.Y); }