private void explicitFaceCheck(QuickHull3D.Hull hull, int[][] checkFaces) { int[][] faceIndices = hull.GetFaces(); Assert.AreEqual(faceIndices.Length, checkFaces.Length, $"Error: {faceIndices.Length} faces vs. {checkFaces.Length}"); // translate face indices back into original indices Point3d[] pnts = hull.GetVertices(); int[] vtxIndices = hull.GetVertexPointIndices(); for (int j = 0; j < faceIndices.Length; j++) { int[] idxs = faceIndices[j]; for (int k = 0; k < idxs.Length; k++) { idxs[k] = vtxIndices[idxs[k]]; } } for (int i = 0; i < checkFaces.Length; i++) { int[] cf = checkFaces[i]; int j; for (j = 0; j < faceIndices.Length; j++) { if (faceIndices[j] != null) { if (faceIndicesEqual(cf, faceIndices[j])) { faceIndices[j] = null; break; } } } Assert.AreNotEqual(j, faceIndices.Length, $"Error: face {string.Join(" ", cf)} not found"); } }
public void TestDegenerateInput2() { QuickHull3D.Hull hull = new QuickHull3D.Hull(); for (int i = 0; i < 10; i++) { double[] coords = randomDegeneratePoints(10, 2); hull.Build(coords); } }
private double[] addDegeneracy(int type, double[] coords, QuickHull3D.Hull hull) { int numv = coords.Length / 3; int[][] faces = hull.GetFaces(); double[] coordsx = new double[coords.Length + faces.Length * 3]; for (int i = 0; i < coords.Length; i++) { coordsx[i] = coords[i]; } double[] lam = new double[3]; double eps = hull.DistanceTolerance; for (int i = 0; i < faces.Length; i++) { // random point on an edge lam[0] = rand.NextDouble(); lam[1] = 1 - lam[0]; lam[2] = 0.0; if (type == VERTEX_DEGENERACY && (i % 2 == 0)) { lam[0] = 1.0; lam[1] = lam[2] = 0; } for (int j = 0; j < 3; j++) { int vtxi = faces[i][j]; for (int k = 0; k < 3; k++) { coordsx[numv * 3 + k] += lam[j] * coords[vtxi * 3 + k] + epsScale * eps * (rand.NextDouble() - 0.5); } } numv++; } shuffleCoords(coordsx); return(coordsx); }
private void singleTest(double[] coords, int[][] checkFaces) { QuickHull3D.Hull hull = new QuickHull3D.Hull(); hull.Debug = debugEnable; hull.Build(coords, coords.Length / 3); if (triangulate) { hull.Triangulate(); } Assert.IsTrue(hull.Check(Console.Out)); if (checkFaces != null) { explicitFaceCheck(hull, checkFaces); } if (degeneracyTest != NO_DEGENERACY) { degenerateTest(hull, coords); } }
private void degenerateTest(QuickHull3D.Hull hull, double[] coords) { double[] coordsx = addDegeneracy(degeneracyTest, coords, hull); QuickHull3D.Hull xhull = new QuickHull3D.Hull(); xhull.Debug = debugEnable; try { xhull.Build(coordsx, coordsx.Length / 3); if (triangulate) { xhull.Triangulate(); } } catch (Exception) { for (int i = 0; i < coordsx.Length / 3; i++) { Console.Out.WriteLine($"{coordsx[i * 3 + 0]}, {coordsx[i * 3 + 1]}, {coordsx[i * 3 + 2]}, "); } } Assert.IsTrue(xhull.Check(Console.Out)); }