public void TestGetCellVertices() { List <Point> inputPoint = new List <Point>() { new Point(5, 5) }; List <Segment> inputSegment = new List <Segment>(); inputSegment.Add(new Segment(0, 0, 0, 10)); inputSegment.Add(new Segment(0, 0, 10, 0)); inputSegment.Add(new Segment(0, 10, 10, 10)); inputSegment.Add(new Segment(10, 0, 10, 10)); //Build the C# Voronoi using (BoostVoronoi bv = new BoostVoronoi()) { foreach (var p in inputPoint) { bv.AddPoint(p.X, p.Y); } foreach (var s in inputSegment) { bv.AddSegment(s.Start.X, s.Start.Y, s.End.X, s.End.Y); } bv.Construct(); for (long i = 0; i < bv.CountCells; i++) { Cell cell = bv.GetCell(i); if (!cell.IsOpen) { List <long> vertexIndexes = cell.VerticesIndex; Assert.AreEqual(vertexIndexes.Count, 5); Assert.AreEqual(vertexIndexes[0], vertexIndexes[vertexIndexes.Count - 1]); } } } }
public void TestFindInputPointSiteException() { List <Point> inputPoint = new List <Point>() { new Point(5, 5) }; List <Segment> inputSegment = new List <Segment>(); inputSegment.Add(new Segment(0, 0, 0, 10)); inputSegment.Add(new Segment(0, 0, 10, 0)); inputSegment.Add(new Segment(0, 10, 10, 10)); inputSegment.Add(new Segment(10, 0, 10, 10)); //Build the C# Voronoi using (BoostVoronoi bv = new BoostVoronoi()) { foreach (var p in inputPoint) { bv.AddPoint(p.X, p.Y); } foreach (var s in inputSegment) { bv.AddSegment(s.Start.X, s.Start.Y, s.End.X, s.End.Y); } bv.Construct(); for (long i = 0; i < bv.CountCells; i++) { Cell cell = bv.GetCell(i); if (cell.SourceCategory != CellSourceCatory.SegmentStartPoint && cell.SourceCategory != CellSourceCatory.SegmentEndPoint && cell.SourceCategory != CellSourceCatory.SinglePoint) { bv.RetrieveInputPoint(cell); } } } }
public void TestSegmentDicretization() { List <Point> inputPoint = new List <Point>() { new Point(5, 5) }; List <Segment> inputSegment = new List <Segment>(); inputSegment.Add(new Segment(0, 0, 0, 10)); inputSegment.Add(new Segment(0, 0, 10, 0)); inputSegment.Add(new Segment(0, 10, 10, 10)); inputSegment.Add(new Segment(10, 0, 10, 10)); //Build the C# Voronoi using (BoostVoronoi bv = new BoostVoronoi()) { foreach (var p in inputPoint) { bv.AddPoint(p.X, p.Y); } foreach (var s in inputSegment) { bv.AddSegment(s.Start.X, s.Start.Y, s.End.X, s.End.Y); } bv.Construct(); long testEdgeIndex = 2; for (long i = 0; i < bv.CountEdges; i++) { Edge edge = bv.GetEdge(i); Edge twin = bv.GetEdge(edge.Twin); Cell edgeCell = bv.GetCell(edge.Cell); Cell twinCell = bv.GetCell(twin.Cell); if (twinCell.SourceCategory == CellSourceCatory.SinglePoint && edgeCell.Site == 1) { testEdgeIndex = i; } } Edge testEdge = bv.GetEdge(testEdgeIndex); Vertex startVertex = bv.GetVertex(testEdge.Start); Vertex endVertex = bv.GetVertex(testEdge.End); List <Vertex> dvertices = bv.SampleCurvedEdge(testEdge, Distance.ComputeDistanceBetweenPoints(startVertex, endVertex) / 2); int lastDicretizedVertexIndex = dvertices.Count - 1; //Make sure that the end points are consistents Assert.AreEqual(dvertices[0].X, startVertex.X); Assert.AreEqual(dvertices[0].Y, startVertex.Y); Assert.AreEqual(dvertices[lastDicretizedVertexIndex].X, endVertex.X); Assert.AreEqual(dvertices[lastDicretizedVertexIndex].Y, endVertex.Y); Assert.AreEqual(dvertices[2].X, 2.5); Assert.AreEqual(dvertices[2].Y, 5); } }