Exemplo n.º 1
0
    public void ShouldUseTopLeftAsPositionOrigin()
    {
        var viewPort = new ViewPort(
            new ComplexArea(
                new DoubleRange(-1, 1),
                new DoubleRange(-1, 1)),
            new Size(101, 101));

        var topLeft = viewPort.GetPosition(new Complex(-1, 1));

        Assert.That(topLeft, Is.EqualTo(new Point(0, 0)), "Incorrect position.");
    }
Exemplo n.º 2
0
    public void ShouldFigureOutMiddleOfSquareArea()
    {
        var viewPort = new ViewPort(
            new ComplexArea(
                new DoubleRange(-1, 1),
                new DoubleRange(-1, 1)),
            new Size(101, 101));

        var middle = viewPort.GetPosition(new Complex());

        Assert.That(middle, Is.EqualTo(new Point(50, 50)), "Incorrect position.");
    }
Exemplo n.º 3
0
    public void ShouldRoundTripComplexNumbers()
    {
        var viewPort = new ViewPort(
            new ComplexArea(
                new DoubleRange(-1, 1),
                new DoubleRange(-1, 1)),
            new Size(101, 101));

        var point = new Point(-1, 1);

        var roundTripped = viewPort.GetPosition(viewPort.GetComplex(point));

        Assert.That(roundTripped, Is.EqualTo(point), "Returned wrong position.");
    }
Exemplo n.º 4
0
    public void ShouldRoundTripPositions()
    {
        var viewPort = new ViewPort(
            new ComplexArea(
                new DoubleRange(-1, 1),
                new DoubleRange(-1, 1)),
            new Size(101, 101));

        var c = new Complex(-1, 1);

        var roundTripped = viewPort.GetComplex(viewPort.GetPosition(c));

        Assert.That(roundTripped, Is.EqualTo(c), "Returned wrong complex number.");
    }
Exemplo n.º 5
0
    public static void RenderSingleSpan(string edgeSpansPath, int spanIndex, int sideResolution)
    {
        var resolution = new Size(sideResolution, sideResolution);

        using var spans = EdgeSpanStream.Load(edgeSpansPath);
        using var timer = TimedOperation.Start("points", totalWork: resolution.Area());
        var random = new Random();

        var index = spanIndex >= 0 ? spanIndex : random.Next(0, spans.Count);

        var imageFilePath = Path.Combine(
            Path.GetDirectoryName(edgeSpansPath) ?? throw new Exception($"Could not get directory name: {edgeSpansPath}"),
            Path.GetFileNameWithoutExtension(edgeSpansPath) + $"_{index}_{sideResolution}x{sideResolution}.png");

        Log.Info($"Using edge span index {index:N0}");
        Log.Info($"Output file: {imageFilePath}");

        var span       = spans.ElementAt(index).ToConcreteDouble(spans.ViewPort);
        var spanLength = span.Length();

        Log.Info($"Edge span: {span} (length: {spanLength})");

        var image = new FastImage(resolution);

        var viewPort = new ViewPort(GetArea(span), resolution);

        Log.Info($"View port: {viewPort}");


        var positionInSet    = viewPort.GetPosition(span.InSet);
        var positionNotInSet = viewPort.GetPosition(span.NotInSet);

        var highlightPixelRadius = resolution.Width / 100;

        var borderPoint = span.FindBoundaryPoint(Constant.IterationRange.Max);

        Log.Info($"Border point: {borderPoint} (escape time: {ScalarDoubleKernel.FindEscapeTime(borderPoint)})");
        var borderPointPosition = viewPort.GetPosition(borderPoint);

        // TODO: Why is the inner loop parallelized?
        for (int row = 0; row < resolution.Height; row++)
        {
            Parallel.For(0, resolution.Width,
                         col =>
            {
                var position = new Point(col, row);

                var c = viewPort.GetComplex(position);

                Color PickColor()
                {
                    if (position.DistanceSquaredFrom(positionInSet) <= highlightPixelRadius)
                    {
                        return(Color.Red);
                    }

                    if (position.DistanceSquaredFrom(positionNotInSet) <= highlightPixelRadius)
                    {
                        return(Color.ForestGreen);
                    }

                    if (position.DistanceSquaredFrom(borderPointPosition) <= highlightPixelRadius)
                    {
                        return(Color.Fuchsia);
                    }

                    var isInSet = ScalarDoubleKernel.FindEscapeTime(c, Constant.IterationRange.Max).IsInfinite;
                    return(isInSet ? Color.FromArgb(0x20, 0x20, 0x20) : Color.White);
                }


                image.SetPixel(position, PickColor());
            });

            timer.AddWorkDone(resolution.Width);
        }

        image.Save(imageFilePath);
    }