/// <summary> /// Add a point to the list of input points /// </summary> /// <param name="x"></param> /// <param name="y"></param> //public void AddPoint(int x, int y) //{ // InputPoints.Add(new Point(x * ScaleFactor, y * ScaleFactor)); //} /// <summary> /// Add a point to the list of input points. The input points will be applied a scale factor /// </summary> /// <param name="x"></param> /// <param name="y"></param> public void AddPoint(double x, double y) { Point p = new Point(Convert.ToInt32(x * ScaleFactor), Convert.ToInt32(y * ScaleFactor)); InputPoints[InputPoints.Count] = p; VoronoiWrapper.AddPoint(p.X, p.Y); }
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 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 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); }