private static ComplexArea GetArea(EdgeSpan span) { var middle = span.GetMidPoint(); var leftMost = Math.Min(span.NotInSet.Real, span.InSet.Real); var rightMost = Math.Max(span.NotInSet.Real, span.InSet.Real); var bottomMost = Math.Min(span.NotInSet.Imaginary, span.InSet.Imaginary); var topMost = Math.Max(span.NotInSet.Imaginary, span.InSet.Imaginary); var horizontalDistance = rightMost - leftMost; var verticalDistance = topMost - bottomMost; var horizontalLongest = horizontalDistance > verticalDistance; var paddingPercentage = 0.1; var sideLength = horizontalLongest ? horizontalDistance : verticalDistance; var paddingLength = paddingPercentage * sideLength; var paddedLength = sideLength + 2 * paddingLength; var halfPaddedLength = paddedLength / 2; return(new ComplexArea( realRange: new DoubleRange(middle.Real - halfPaddedLength, middle.Real + halfPaddedLength), imagRange: new DoubleRange(middle.Imaginary - halfPaddedLength, middle.Imaginary + halfPaddedLength))); }
public void ShouldFindMiddle(double aR, double aI, double bR, double bI, double expectedR, double expectedI) { var span = new EdgeSpan(new Complex(aR, aI), new Complex(bR, bI)); var middle = span.GetMidPoint(); Assert.That(middle.Real, Is.EqualTo(expectedR).Within(0.00000001f), "Incorrect real component."); Assert.That(middle.Imaginary, Is.EqualTo(expectedI).Within(0.00000001f), "Incorrect imaginary component."); }
static Complex FindBorderPointMagnitudeSquared(EdgeSpan span, int iterationLimit) { // var initialLength2 = span.LengthSquared(); int maxSubdivisions = 38; //double oldLength = 0; //while (oldLength != initialLength2) //{ // maxSubdivisions++; // oldLength = initialLength2; // initialLength2 /= 2; //} //Console.WriteLine(maxSubdivisions); double lastLength = 0; for (int i = 0; i < maxSubdivisions; i++) { //var length = span.LengthSquared(); //if (length == lastLength) //{ // return span.NotInSet; //} //lastLength = length; var middle = span.GetMidPoint(); var escapeTime = ScalarDoubleKernel.FindEscapeTime(middle, iterationLimit); span = escapeTime.IsInfinite ? new EdgeSpan(middle, span.NotInSet) : new EdgeSpan(span.InSet, middle); //if (i % 10 == 0) //{ // Console.WriteLine(i); //} } return(span.NotInSet); }