private void CreateHighlightEffect(double x, double y) { Point?point = _voronoi.NearestSitePoint(x, y); if (point.HasValue) { List <LineSegment> boundaries = _voronoi.VoronoiBoundaryForSite(point.Value); IEnumerable <Line> lines = ShapeSegments.Where(segment => segment is Line).Cast <Line>(); } }
private void CreateVoronoiDiagram() { double width = Application.Current.MainWindow.Width; double height = Application.Current.MainWindow.Height; List <Color> colors = ColorUtils.GenerateRandomColors(MaxPoints); List <Point> points = CreateRandomPoints(width, height); _voronoi = new Voronoi(points, colors, new Rect(0, 0, width, height)); foreach (LineSegment lineSegment in _voronoi.VoronoiDiagram()) { if (!lineSegment.P0.HasValue || !lineSegment.P1.HasValue) { continue; } ShapeSegments.Add(new Line { X1 = lineSegment.P0.Value.X, X2 = lineSegment.P1.Value.X, Y1 = lineSegment.P0.Value.Y, Y2 = lineSegment.P1.Value.Y, Stroke = new SolidColorBrush(Colors.Black), StrokeThickness = 1 }); } int index = 0; foreach (List <Point> point in _voronoi.Regions()) { Polygon polygon = new Polygon { Stroke = new SolidColorBrush(Colors.Black), StrokeThickness = 1, Fill = new SolidColorBrush(colors[index % colors.Count]), Points = new PointCollection(point) }; ShapeSegments.Add(polygon); index++; } foreach (LineSegment lineSegment in _voronoi.DelaunayTriangulation()) { if (!lineSegment.P0.HasValue || !lineSegment.P1.HasValue) { continue; } ShapeSegments.Add(new Line { X1 = lineSegment.P0.Value.X, X2 = lineSegment.P1.Value.X, Y1 = lineSegment.P0.Value.Y, Y2 = lineSegment.P1.Value.Y, Stroke = new SolidColorBrush(Colors.Azure), StrokeThickness = 1 }); } foreach (Point point in points) { var ellipse = new Ellipse { Stroke = new SolidColorBrush(Colors.OrangeRed), StrokeThickness = 5 }; Canvas.SetLeft(ellipse, point.X - ellipse.StrokeThickness / 2); Canvas.SetTop(ellipse, point.Y - ellipse.StrokeThickness / 2); ShapeSegments.Add(ellipse); } }