public void TestCellsCount() { List<Segment> input = new List<Segment>(); input.Add(new Segment(0, 0, 0, 10)); input.Add(new Segment(0, 10, 10, 10)); input.Add(new Segment(10, 10, 10, 0)); input.Add(new Segment(10, 0, 0, 0)); input.Add(new Segment(0, 0, 5, 5)); input.Add(new Segment(5, 5, 10, 10)); //Build the CLR voronoi VoronoiWrapper vw = new VoronoiWrapper(); foreach (var s in input) vw.AddSegment(s.Start.X, s.Start.Y, s.End.X, s.End.Y); vw.ConstructVoronoi(); List<Tuple<int, int, bool, bool, List<int>, bool, short>> clrCells = vw.GetCells(); //Build the C# Voronoi BoostVoronoi bv = new BoostVoronoi(); foreach (var s in input) bv.AddSegment(s.Start.X, s.Start.Y, s.End.X, s.End.Y); bv.Construct(); List<Cell> sharpCells = bv.Cells; //Test that the outputs have the same length Assert.AreEqual(clrCells.Count, sharpCells.Count); }
public void TestTupleCells() { VoronoiWrapper vw = new VoronoiWrapper(); vw.AddSegment(0, 0, 0, 10); vw.AddSegment(0, 10, 10, 10); vw.AddSegment(10, 10, 10, 0); vw.AddSegment(10, 0, 0, 0); vw.AddSegment(0, 0, 5, 5); vw.AddSegment(5, 5, 10, 10); vw.ConstructVoronoi(); List<Tuple<double, double>> vertices = vw.GetVertices(); List<Tuple<int, int, int, int, Tuple<bool, bool, bool, int, int>>> edges = vw.GetEdges(); List<Tuple<int, int, bool, bool, List<int>, bool, short>> cells = vw.GetCells(); for (int i = 0; i < vertices.Count; i++) { TestContext.WriteLine(String.Format("Vertex {0}. X: {1}, Y: {2}", i, vertices[i].Item1, vertices[i].Item2)); } foreach (var c in cells) { foreach (var s in c.Item5) { TestContext.WriteLine(String.Format("Cell: {0}, Segment: {1}, Start: {2}, End: {3}", c.Item1, s, edges[s].Item2, edges[s].Item3)); } } Assert.AreEqual(11, cells.Count); }
public void TestCellEndNodes() { VoronoiWrapper vw = new VoronoiWrapper(); vw.AddSegment(0, 0, 0, 10); vw.AddSegment(0, 10, 10, 10); vw.AddSegment(10, 10, 10, 0); vw.AddSegment(10, 0, 0, 0); vw.AddSegment(0, 0, 5, 5); vw.AddSegment(5, 5, 10, 10); vw.ConstructVoronoi(); List<Tuple<double, double>> vertices = vw.GetVertices(); List<Tuple<int, int, int, int, Tuple<bool, bool, bool, int, int>>> edges = vw.GetEdges(); List<Tuple<int, int, bool, bool, List<int>, bool, short>> cells = vw.GetCells(); foreach (var c in cells) { //Get first edge and last edge Tuple<int, int, int, int, Tuple<bool, bool, bool, int, int>> firstEdge = edges[c.Item5[0]]; Tuple<int, int, int, int, Tuple<bool, bool, bool, int, int>> lastEdge = edges[c.Item5[c.Item5.Count -1]]; Assert.AreEqual(firstEdge.Item2, lastEdge.Item3); } }
public void TestSegmentTwin() { 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, 10, 10, 10)); inputSegment.Add(new Segment(10, 10, 10, 0)); inputSegment.Add(new Segment(10, 0, 0, 0)); //Build the CLR voronoi VoronoiWrapper vw = new VoronoiWrapper(); foreach (var p in inputPoint) vw.AddPoint(p.X, p.Y); foreach (var s in inputSegment) vw.AddSegment(s.Start.X, s.Start.Y, s.End.X, s.End.Y); vw.ConstructVoronoi(); List<Tuple<int, int, bool, bool, List<int>, bool, short>> clrCells = vw.GetCells(); //Build the C# Voronoi 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(); List<Edge> sharpEdges = bv.Edges; //Test twin reciprocity for (int i = 0; i < sharpEdges.Count; i++) { Assert.AreEqual(i, sharpEdges[sharpEdges[i].Twin].Twin); } }
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 CLR voronoi VoronoiWrapper vw = new VoronoiWrapper(); foreach (var p in inputPoint) vw.AddPoint(p.X, p.Y); foreach (var s in inputSegment) vw.AddSegment(s.Start.X, s.Start.Y, s.End.X, s.End.Y); vw.ConstructVoronoi(); List<Tuple<int, int, bool, bool, List<int>, bool, short>> clrCells = vw.GetCells(); //Build the C# Voronoi 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(); List<Vertex> vertices = bv.Vertices; List<Edge> sharpEdges = bv.Edges; List<Cell> sharpCells = bv.Cells; int testEdgeIndex = 2; for (int i = 0; i < sharpEdges.Count; i++) { if (sharpCells[sharpEdges[sharpEdges[i].Twin].Cell].SourceCategory == CellSourceCatory.SinglePoint && sharpCells[sharpEdges[i].Cell].Site == 1) testEdgeIndex = i; } Edge testEdge = sharpEdges[testEdgeIndex]; Vertex startVertex = vertices[testEdge.Start]; Vertex endVertex = vertices[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); }
public void TestPrimaryEdges() { 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 CLR voronoi VoronoiWrapper vw = new VoronoiWrapper(); foreach (var p in inputPoint) vw.AddPoint(p.X, p.Y); foreach (var s in inputSegment) vw.AddSegment(s.Start.X, s.Start.Y, s.End.X, s.End.Y); vw.ConstructVoronoi(); List<Tuple<int, int, bool, bool, List<int>, bool, short>> clrCells = vw.GetCells(); //Build the C# Voronoi 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(); List<Vertex> vertices = bv.Vertices; List<Edge> sharpEdges = bv.Edges; int countPrimary = 0; int countSecondary = 0; int countFinite = 0; for (int i = 0; i < sharpEdges.Count; i++) { if (sharpEdges[i].IsPrimary) countPrimary++; if (sharpEdges[i].IsFinite) countFinite++; if (!sharpEdges[i].IsPrimary && sharpEdges[i].IsFinite) countSecondary++; } //8 finites from the center of the square corner + 8 edges arount the center point. Assert.AreEqual(countFinite, 16); //Check the number of secondary edge. Because this input is a square with a point in the center, the expected count is 0. Assert.AreEqual(countSecondary, 0); Assert.AreEqual(countPrimary, countFinite - countSecondary); }
public void TestVertexSequences() { VoronoiWrapper vw = new VoronoiWrapper(); vw.AddSegment(0, 0, 0, 10); vw.AddSegment(0, 10, 10, 10); vw.AddSegment(10, 10, 10, 0); vw.AddSegment(10, 0, 0, 0); vw.AddSegment(0, 0, 5, 5); vw.AddSegment(5, 5, 10, 10); vw.ConstructVoronoi(); List<Tuple<double, double>> vertices = vw.GetVertices(); List<Tuple<int, int, int, int, Tuple<bool, bool, bool, int, int>>> edges = vw.GetEdges(); List<Tuple<int, int, bool, bool, List<int>, bool, short>> cells = vw.GetCells(); foreach (var c in cells) { for (int i = 1; i < c.Item5.Count; i++) { Assert.AreEqual(edges[c.Item5[i - 1]].Item3, edges[c.Item5[i]].Item2); } } }