Example #1
0
        public static bool IsInSet(Complex c, BailoutRange bailout)
        {
            if (MandelbulbChecker.IsInsideBulbs(c))
            {
                return true;
            }

            double re = 0;
            double im = 0;

            // Check for orbits
            // - Check re/im against an old point
            // - Only check every power of 2
            double oldRe = 0;
            double oldIm = 0;

            uint checkNum = 1;

            // Cache the squares
            // They are used to find the magnitude; reuse these values when computing the next re/im
            double re2 = 0;
            double im2 = 0;

            for (uint i = 0; i < bailout.Maximum; i++)
            {
                var reTemp = re2 - im2 + c.Real;
                im = 2 * re * im + c.Imaginary;
                re = reTemp;

                // Orbit check
                if (checkNum == i)
                {
                    if (IsPracticallyTheSame(oldRe, re) && IsPracticallyTheSame(oldIm, im))
                    {
                        return true;
                    }

                    oldRe = re;
                    oldIm = im;

                    checkNum = checkNum << 1;
                }

                re2 = re * re;
                im2 = im * im;

                // Check the magnitude squared against 2^2
                if ((re2 + im2) > 4)
                {
                    return false;
                }
            }

            return true;
        }
Example #2
0
        public void Start()
        {
            _log.Info("Starting to find points");
            _log.DebugFormat("Random Generator: {0}", _pointGenerator.GetType().Name);
            _log.DebugFormat("Minimum Threshold: {0:N0}", _minimum);
            _log.DebugFormat("Maximum Threshold: {0:N0}", _maximum);

            var bailout = new BailoutRange(
                minimum: _minimum,
                maximum: _maximum);

            var viewPort = AreaFactory.SearchArea;

            viewPort.LogViewport();

            var list = new ComplexNumberListWriter(_outputDirectory, _outputFile);

            int num = 0;

            Parallel.ForEach(_pointGenerator.GetRandomComplexNumbers(viewPort), new ParallelOptions { MaxDegreeOfParallelism = GlobalArguments.DegreesOfParallelism },
                (number, state) =>
                {
                    if (ValidatePoint(number, bailout))
                    {
                        Interlocked.Increment(ref num);
                        list.SaveNumber(number);

                        if (num % 100 == 0)
                        {
                            _log.DebugFormat("Found {0:N0} points", num);
                        }
                    }

                    if (ShouldStop)
                    {
                        state.Break();
                        _log.Debug("This process stopped");
                    }
                });

            _log.DebugFormat("Found {0:N0} points", num);
            _log.Info("Stopped finding points");
        }
 protected override bool ValidatePoint(Complex c, BailoutRange bailoutRange)
 {
     return MandelbrotFinder.IsInSet(c);
 }
Example #4
0
 protected abstract bool ValidatePoint(Complex c, BailoutRange bailoutRange);
 protected override bool ValidatePoint(Complex c, BailoutRange bailoutRange)
 {
     return IsPointInBuddhabrot(c, bailoutRange);
 }