Exemple #1
0
        // ************************************************************************
        /// <summary>
        /// Test for online convex hull
        /// </summary>
        /// <param name="testSet"></param>
        private void ExecuteOneSetOfTest(TestSetOfPoint testSet)
        {
            ConvexHull ch;

            Permutations.ForAllPermutation(testSet.Points, points =>
            {
                bool isIntergrityExceptionHappen;
                do
                {
                    isIntergrityExceptionHappen = false;

                    ch = new ConvexHull();

                    try
                    {
                        foreach (Point pt in points)
                        {
                            ch.TryAddOnePoint(pt);

                            this.Dispatcher.BeginInvoke(new Action(() => DrawPoints(
                                                                       new DrawInfo(testSet.Points, DrawStyle.Point, OxyColors.Aqua),
                                                                       new DrawInfo(ch, DrawStyle.Line, OxyColors.Blue))), DispatcherPriority.Background);

                            Thread.Sleep(10);
                        }
                    }
                    catch (ConvexHullResultIntegrityException)
                    {
                        isIntergrityExceptionHappen = true;
                    }
                } while (isIntergrityExceptionHappen);


                var result = ch.GetResultsAsArrayOfPoint(true);

                DifferencesInPath diffs = ConvexHullUtil.GetPathDifferences("Online", points, testSet.ExpectedResult, result);
                if (diffs.HasErrors)
                {
                    Debugger.Break();
                }

                return(ExecutionState.Continue);
            });
        }
Exemple #2
0
        // ************************************************************************
        private void QuickTestClick(object sender, RoutedEventArgs e)
        {
            // Task.Run(new Action(() => QuickTestClickInternal()));
            List <Point> points = new List <Point>();

            points.Add(new Point(3, 3));
            points.Add(new Point(6, 3));

            ConvexHull ch = new ConvexHull();

            ch.CalcConvexHull(points);

            var diff = ConvexHullUtil.GetPathDifferences("", points, points, ch.GetResultsAsArrayOfPoint());

            Debug.Assert(diff.HasErrors == false);

            Debug.Assert(ch.GetNextPoint(new Point(3, 3)) == new Point(6, 3));
            Debug.Assert(ch.GetNextPoint(new Point(6, 3)) == new Point(3, 3));
            Debug.Assert(ch.GetNextPoint(new Point(4, 5)) == default(Point));
            Debug.Assert(ch.Count == 2);

            var neighbors = ch.GetNeighbors(points[0]);

            Debug.Assert(neighbors.Item1 == points[1]);
            Debug.Assert(neighbors.Item2 == points[1]);

            points = new List <Point>();
            ch     = new ConvexHull();
            points.Add(new Point(3, 5));
            points.Add(new Point(3, 3));

            ch = new ConvexHull();
            ch.CalcConvexHull(points);

            diff = ConvexHullUtil.GetPathDifferences("", points, points, ch.GetResultsAsArrayOfPoint());
            Debug.Assert(diff.HasErrors == false);

            Debug.Assert(ch.GetNextPoint(new Point(3, 3)) == new Point(3, 5));
            Debug.Assert(ch.GetNextPoint(new Point(3, 5)) == new Point(3, 3));
            Debug.Assert(ch.GetNextPoint(new Point(4, 5)) == default(Point));
            Debug.Assert(ch.Count == 2);

            neighbors = ch.GetNeighbors(points[0]);
            Debug.Assert(neighbors.Item1 == points[1]);
            Debug.Assert(neighbors.Item2 == points[1]);



            points = new List <Point>();
            ch     = new ConvexHull();
            points.Add(new Point(3, 3));
            points.Add(new Point(3, 5));

            ch = new ConvexHull();
            ch.CalcConvexHull(points);

            diff = ConvexHullUtil.GetPathDifferences("", points, points, ch.GetResultsAsArrayOfPoint());
            Debug.Assert(diff.HasErrors == false);

            Debug.Assert(ch.GetNextPoint(new Point(3, 3)) == new Point(3, 5));
            Debug.Assert(ch.GetNextPoint(new Point(3, 5)) == new Point(3, 3));
            Debug.Assert(ch.GetNextPoint(new Point(4, 5)) == default(Point));
            Debug.Assert(ch.Count == 2);

            neighbors = ch.GetNeighbors(points[0]);
            Debug.Assert(neighbors.Item1 == points[1]);
            Debug.Assert(neighbors.Item2 == points[1]);

            points = new List <Point>();
            ch     = new ConvexHull();
            points.Add(new Point(3, 3));

            ch = new ConvexHull();
            ch.CalcConvexHull(points);

            diff = ConvexHullUtil.GetPathDifferences("", points, points, ch.GetResultsAsArrayOfPoint());
            Debug.Assert(diff.HasErrors == false);

            Debug.Assert(ch.GetNextPoint(new Point(3, 3)) == new Point(3, 3));
            Debug.Assert(ch.GetNextPoint(new Point(4, 5)) == default(Point));
            Debug.Assert(ch.Count == 1);

            neighbors = ch.GetNeighbors(points[0]);
            Debug.Assert(neighbors.Item1 == points[0]);
            Debug.Assert(neighbors.Item2 == points[0]);

            Task.Run(new Action(() =>
            {
                for (; ;)
                {
                    Model.GeneratePoints();

                    ch = new ConvexHull();
                    ch.CalcConvexHull(Model.Points);
                    ch.CheckNextNodePreviousNodeCoherence();

                    Model.Iteration++;
                }
            }));
        }