void testException(double[] coords, string msg) { QuickHull hull = null; Exception ex = null; try { hull = new QuickHull(coords); } catch (Exception e) { ex = e; } finally { hull?.Dispose(); } if (ex == null) { this.output.WriteLine("Expected exception " + msg); this.output.WriteLine("Got no exception"); this.output.WriteLine("Input pnts:"); printCoords(coords); Assert.NotNull(ex); } else if (ex.Message == null || !ex.Message.Equals(msg)) { this.output.WriteLine("Expected exception " + msg); this.output.WriteLine("Got exception " + ex.Message); this.output.WriteLine("Input pnts:"); printCoords(coords); Assert.False(true, "Expected exception " + msg + " \r\nGot exception " + ex.Message); } }
public void ConvexHull_OfConcaveShape() { var result = new QuickHull().FindConvexHull(TetrisL); result.IsConvex.Should().BeTrue("Convex hull isn't convex!"); VerifyContainment(result, TetrisL); }
static void Main() { var points4 = new[] { new Vector2(1, 0), new Vector2(0, 0), new Vector2(1, 1), new Vector2(0, 1) }; var points3 = new[] { new Vector2(1, 0), new Vector2(0, 0), new Vector2(1, 1) }; var hull4 = QuickHull.Compute(points4); var hull3 = QuickHull.Compute(points3); PrintHull(hull4); Console.WriteLine(); PrintHull(hull3);
void degenerateTest(QuickHull hull, double[] coords) { double[] coordsx = addDegeneracy(degeneracyTest, coords, hull); using var xhull = new QuickHull(coordsx); if (triangulate) { xhull.Triangulate(); } }
private void HandleQuickHull() { var results = QuickHull.BuildHull(origins); List <Vector3> vertices = new List <Vector3>(); List <int> indices = new List <int>(); GeoUtils.MeshVertexPrimitiveType(results, ref vertices, ref indices); GameObject res = new GameObject("QuickHull"); var filter = res.AddComponent <MeshFilter>(); var render = res.AddComponent <MeshRenderer>(); Mesh mesh = new Mesh(); mesh.SetVertices(vertices); mesh.SetTriangles(indices, 0); filter.mesh = mesh; }
void explicitFaceCheck(QuickHull hull, int[][] checkFaces) { int[][] faceIndices = hull.GetFaces(); if (faceIndices.Length != checkFaces.Length) { throw new Exception("Error: " + faceIndices.Length + " faces vs. " + checkFaces.Length); } // translate face indices back into original indices 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; } } } if (j == faceIndices.Length) { String s = ""; for (int k = 0; k < cf.Length; k++) { s += cf[k] + " "; } throw new Exception("Error: face " + s + " not found"); } } }
void singleTest(double[] coords, int[][] checkFaces) { using var hull = new QuickHull(coords); if (triangulate) { hull.Triangulate(); } if (checkFaces != null) { explicitFaceCheck(hull, checkFaces); } if (degeneracyTest != NO_DEGENERACY) { degenerateTest(hull, coords); } }
double[] addDegeneracy(int type, double[] coords, QuickHull 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.Tolerance; 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 button6_Click(object sender, EventArgs e) { QuickHull qn = new QuickHull(); IPositionSet ps = qn.ConvexHull(getPoints2((Bitmap)pictureBox1.Image)); Graphics g = Graphics.FromImage(pictureBox1.Image); IPosition p1 = ps.GetPosition(); IPosition p2 = ps.GetPosition(); while (p2 != null) { g.DrawLine(new Pen(Color.Green), new PointF(p1.GetX(), p1.GetY()), new PointF(p2.GetX(), p2.GetY())); p1 = p2; p2 = ps.GetPosition(); } ps.InitToTraverseSet(); p2 = ps.GetPosition(); g.DrawLine(new Pen(Color.Green), new PointF(p1.GetX(), p1.GetY()), new PointF(p2.GetX(), p2.GetY())); pictureBox1.Refresh(); }
private void button1_Click(object sender, EventArgs e) { PainterDialog painterDialog = new PainterDialog(); RandomPositionSet_InFixedDistribution randomPositionSet = new RandomPositionSet_InFixedDistribution(); new ConfiguratedByForm(randomPositionSet); randomPositionSet.Produce(); QuickHull quickHull = new QuickHull(); IPositionSet convexHull = quickHull.ConvexHull(randomPositionSet); painterDialog.Clear(); painterDialog.DrawConvexHull(convexHull); IPosition p = PositionSetAttribute.GetGravityCenter(convexHull); List <IPosition> pl = new List <IPosition>(); pl.Add(p); painterDialog.DrawPath(new PositionSet_ImplementByIEnumerableTemplate(pl)); }
public void QuickHullSpecialCaseTriangle() { convexHullTester = new QuickHull(); SpecialCaseTriangle(); }
public void QuickHullNormalTestCase10000Points() { convexHullTester = new QuickHull(); Case10000Points(); }
public void QuickHullTestCase9() { convexHullTester = new QuickHull(); Case9(); }
public void GrahamScanNormalTestCase10000Points() { convexHullTester = new QuickHull(); Case10000Points(); }
public void QuickHullSpecialCase10SamePoints() { convexHullTester = new QuickHull(); SpecialCase10SamePoints(); }
public void ConvexHull_ConvexShape() { var result = new QuickHull().FindConvexHull(Diamond); VerifyContainment(result, Diamond); }
public void QuickHullSpecialCaseConvexPolygon() { convexHullTester = new QuickHull(); SpecialCaseConvexPolygon(); }
void QHCH(double n, Object o) { QuickHull QH = new QuickHull(); QH.ConvexHull((IPositionSet)o); }
public override void Draw(Graphics graphics) { if (Visible) { SetDrawerGraphic(graphics); List <IPosition_Connected> PartMiddlePointList = new List <IPosition_Connected>(); List <PointF[]> PointArrayList = new List <PointF[]>(); ILevel level = m2mStructure.GetLevel(levelSequence); IPart rootPart = m2mStructure.GetLevel(0).GetPartRefByPartIndex(0, 0); IPositionSet positionSet = m2mStructure.GetDescendentPositionSetByAncestorPart(levelSequence, rootPart, 0); Dictionary <IPosition, IPosition_Connected_Edit> partToPositionDictionary = new Dictionary <IPosition, IPosition_Connected_Edit>(); positionSet.InitToTraverseSet(); while (positionSet.NextPosition()) { Position_Connected_Edit PartDeputyPosition_Connected = new Position_Connected_Edit(); partToPositionDictionary.Add(positionSet.GetPosition(), PartDeputyPosition_Connected); } positionSet.InitToTraverseSet(); while (positionSet.NextPosition()) { IPart_Connected currentPart = (IPart_Connected)positionSet.GetPosition(); IPositionSet bottomLevelPositionSet = m2mStructure.GetBottonLevelPositionSetByAncestorPart(currentPart, levelSequence); IPosition tempPoint = PositionSetAttribute.GetGravityCenter(bottomLevelPositionSet); IPosition_Connected_Edit PartDeputyPosition_Connected; partToPositionDictionary.TryGetValue(positionSet.GetPosition(), out PartDeputyPosition_Connected); PartDeputyPosition_Connected.SetX(tempPoint.GetX()); PartDeputyPosition_Connected.SetY(tempPoint.GetY()); currentPart.GetAdjacencyPositionSet().InitToTraverseSet(); while (currentPart.GetAdjacencyPositionSet().NextPosition()) { IPosition_Connected_Edit adjDeputy; partToPositionDictionary.TryGetValue(currentPart.GetAdjacencyPositionSet().GetPosition(), out adjDeputy); PartDeputyPosition_Connected.GetAdjacencyPositionSetEdit().AddAdjacency( adjDeputy, currentPart.GetAdjacencyPositionSet().GetDistanceToAdjacency()); } PartMiddlePointList.Add(PartDeputyPosition_Connected); IPositionSet ConvexHullPointSet = null; if (bottomLevelPositionSet.GetNum() > 1) { ConvexHullPointSet = new QuickHull().ConvexHull(bottomLevelPositionSet); } else { ConvexHullPointSet = bottomLevelPositionSet; } PointF[] tempArray = new PointF[ConvexHullPointSet.GetNum()]; int sequence = 0; ConvexHullPointSet.InitToTraverseSet(); while (ConvexHullPointSet.NextPosition()) { tempArray[sequence].X = ConvertRealXToScreenX(ConvexHullPointSet.GetPosition().GetX()); tempArray[sequence].Y = ConvertRealYToScreenY(ConvexHullPointSet.GetPosition().GetY()); sequence++; } PointArrayList.Add(tempArray); } Pen pen = new Pen(partColor, partBorderWidth); Brush brush = new SolidBrush(Color.FromArgb(alpha, partColor)); foreach (PointF[] pointArray in PointArrayList) { if (pointArray.Length >= 2) { graphics.DrawPolygon(pen, pointArray); graphics.FillPolygon(brush, pointArray); } } this.positionSet = new PositionSet_ConnectedEdit(PartMiddlePointList); positionSetDrawerPump.ResetPump(); positionSetDrawerPump.DrawCoordinate(pointCoordinateDrawer); positionSetDrawerPump.DrawPoint(pointDrawer); positionSetDrawerPump.DrawConnection(connectionDrawer); positionSetDrawerPump.Run(); } }