Esempio n. 1
0
        private static void RandomPointsComparer(IPointDComparer comparer)
        {
            RectD bounds = new RectD(-100, -100, 200, 200);

            PointD[] points = GeoAlgorithms.RandomPoints(100, bounds, comparer, 2);

            for (int i = 0; i < points.Length; i++)
            {
                PointD p = points[i];
                Assert.IsTrue(bounds.Contains(p));
                if (i > 0)
                {
                    Assert.AreEqual(+1, comparer.Compare(p, points[i - 1]));
                }
                if (i < points.Length - 1)
                {
                    Assert.AreEqual(-1, comparer.Compare(p, points[i + 1]));
                }

                for (int j = 0; j < points.Length; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }
                    double distance = p.Subtract(points[j]).LengthSquared;
                    Assert.GreaterOrEqual(distance, 4);
                }
            }
        }
Esempio n. 2
0
        public void RandomPoints()
        {
            RectD bounds = new RectD(-100, -100, 200, 200);

            PointD[] points = GeoAlgorithms.RandomPoints(100, bounds);
            foreach (PointD p in points)
            {
                Assert.IsTrue(bounds.Contains(p));
            }
        }
Esempio n. 3
0
        private void DrawConvexHull(PointD[] points)
        {
            const double radius = 4.0;

            // generate new random point set if desired
            if (points == null)
            {
                Size  scale  = new Size(OutputBox.Width - 4 * radius, OutputBox.Height - 4 * radius);
                int   count  = MersenneTwister.Default.Next(4, 40);
                RectD bounds = new RectD(2 * radius, 2 * radius, scale.Width, scale.Height);
                points = GeoAlgorithms.RandomPoints(
                    count, bounds, new PointDComparerY(), 2 * radius);
            }

            _points = points;
            PointD[] polygon = GeoAlgorithms.ConvexHull(points);
            OutputBox.Children.Clear();

            // draw hull vertices filled, other points hollow
            for (int i = 0; i < points.Length; i++)
            {
                bool isVertex = polygon.Contains(points[i]);

                var circle = new Ellipse()
                {
                    Width  = 2 * radius, Height = 2 * radius,
                    Stroke = Brushes.Black,
                    Fill   = isVertex ? Brushes.Black : null
                };

                Canvas.SetLeft(circle, points[i].X - radius);
                Canvas.SetTop(circle, points[i].Y - radius);

                OutputBox.Children.Add(circle);
            }

            // draw edges of convex hull
            OutputBox.Children.Add(new Polygon()
            {
                Points = polygon.ToWpfPoints(),
                Stroke = Brushes.Red
            });
        }
Esempio n. 4
0
        public static GraphManager <PointD> CreateSubdivisionManager(GraphDialog dialog)
        {
            RectD output = new RectD(0, 0, dialog.OutputBox.Width, dialog.OutputBox.Height);
            RectD bounds = new RectD(8, 8, output.Width - 16, output.Height - 16);

            PointD[] points = GeoAlgorithms.RandomPoints(40, bounds, new PointDComparerX(), 20);

            VoronoiResults results  = Voronoi.FindAll(points, output);
            Subdivision    division = results.ToDelaunySubdivision(output, true);

            var manager = new GraphManager <PointD>(dialog, 8);

            manager.Graph    = division;
            manager.Renderer = new GraphRenderer <PointD>(manager);

            // scaling factor to keep step costs above node distance
            manager._scaleCost = output.Width + output.Height;
            return(manager);
        }