/// <summary> /// Impose alternating cuts on given vertex array. /// </summary> /// <param name="array">The vertex array.</param> /// <param name="length">The number of vertices to sort.</param> /// <param name="seed">Random seed used for pivoting.</param> public static void Alternate(Vertex[] array, int length, int seed = RANDOM_SEED) { var qs = new VertexSorter(array, seed); int divider = length >> 1; // Re-sort the array of vertices to accommodate alternating cuts. if (length - divider >= 2) { if (divider >= 2) { qs.AlternateAxes(0, divider - 1, 1); } qs.AlternateAxes(divider, length - 1, 1); } }
/// <summary> /// Test the polygon for duplicate vertices. /// </summary> public static bool HasDuplicateVertices(IPolygon poly) { var logger = Log.Instance; int horrors = 0; var points = poly.Points.ToArray(); VertexSorter.Sort(points); for (int i = 1; i < points.Length; i++) { if (points[i - 1] == points[i]) { horrors++; logger.Warning(String.Format("Found duplicate point {0}.", points[i]), "PolygonValidator.HasDuplicateVertices()"); } } return(horrors > 0); }
/// <summary> /// Sorts the given vertex array by x-coordinate. /// </summary> /// <param name="array">The vertex array.</param> /// <param name="seed">Random seed used for pivoting.</param> public static void Sort(Vertex[] array, int seed = RANDOM_SEED) { var qs = new VertexSorter(array, seed); qs.QuickSort(0, array.Length - 1); }