Ejemplo n.º 1
0
        public String DoItRight(INumericMethod <TFunc> method, IShape <TFunc> func, IPlot plotSpace, Conditions conditions, IReportGenerator reporter, bool stepByStep = false)
        {
            var actualPoints = conditions.InitialPoints.ToArray();

            UpdateDomain(func, actualPoints);
            reporter.Init(actualPoints, func, conditions);

            var iterationsCounter = 0;

            while (!IsAnyPointPrettyCloseToRoot(func.Generator, conditions, actualPoints) && iterationsCounter++ < conditions.MaxNumberOfIteration)
            {
                var newPoint = method.ComputeNext(actualPoints, func.Generator);

                if (!newPoint.Any())
                {
                    break;
                }

                actualPoints = actualPoints.Concat(newPoint).ToArray();
                UpdateDomain(func, actualPoints);

                var pictureOfStep = method.GenerateIllustrationForCurrentStep(actualPoints, func.Generator, iterationsCounter + conditions.InitialPoints.Count());

                reporter.AddIntermidiateStep(actualPoints, pictureOfStep, iterationsCounter);

                plotSpace.DrawShape(func);
                foreach (var shape in pictureOfStep)
                {
                    plotSpace.DrawShape(shape);
                    if (stepByStep)
                    {
                        Console.WriteLine("Press Enter to make step");
                        Console.ReadLine();
                    }
                }
            }

            return(reporter.GenerateReport(actualPoints.Last(), iterationsCounter, DistanceToRoot(func.Generator, actualPoints.Last(), conditions)));
        }