<commit_before>
var Mandelbrot = {};

Mandelbrot.create = function (width, height, repeats, x1, y1, x2, y2) {
    var mandelbrot = {
        width: width,
        height: height,
        repeats: repeats,
        coords: { x1: x1, y1: y1, x2: x2, y2: y2 },
        values: new Float64Array(width * height)
    };

    return mandelbrot;
};

Mandelbrot.calculate = function (mandelbrot, smoothing) {

    var tempArray = new Float64Array(mandelbrot.width * mandelbrot.height);

    var highest = 0;
    var lowest = 1000;
    var value;

    var x, y;
    for (x = 0; x < mandelbrot.width; x += 1) {
        for (y = 0; y < mandelbrot.height; y += 1) {
            value = Mandelbrot.calculateValue(mandelbrot, x, y, smoothing);
            if (value > highest) {
                highest = value;
            }
            if (value > 0 && value < lowest) {
                lowest = value;
            }
            tempArray[y * mandelbrot.width + x] = value;
        }
    }

    // scaling from 0 to 1
    var diff = highest - lowest;
    var i;
    for (i = 0; i < tempArray.length; i += 1) {
        mandelbrot.values[i] = (tempArray[i] - lowest) / diff;
    }

    return mandelbrot;
};

Mandelbrot.calculateValue = function (mandelbrot, xPos, yPos, smoothing) {

    var xCoord = mandelbrot.coords.x1 + (
        (mandelbrot.coords.x2 - mandelbrot.coords.x1) * (xPos / mandelbrot.width)
    );
    var yCoord = mandelbrot.coords.y1 + (
        (mandelbrot.coords.y2 - mandelbrot.coords.y1) * (yPos / mandelbrot.height)
    );

    var x = 0;
    var y = 0;<commit_msg>small optimisations to mandelbrot calculations<commit_after>
var Mandelbrot = {};

Mandelbrot.create = function (width, height, repeats, x1, y1, x2, y2) {
    var mandelbrot = {
        width: width,
        height: height,
        repeats: repeats,
        coords: { x1: x1, y1: y1, x2: x2, y2: y2 },
        escapeValues: new Float64Array(width * height),
        values: new Float64Array(width * height)
    };

    return mandelbrot;
};

Mandelbrot.calculate = function (mandelbrot, smoothing) {

    var highest = 0;
    var lowest = 1000;
    var value;
    var xDistPerPixel  = (mandelbrot.coords.x2 - mandelbrot.coords.x1) / mandelbrot.width;
    var yDistPerPixel = (mandelbrot.coords.y2 - mandelbrot.coords.y1) / mandelbrot.height;

    var x, y, xCoord, yCoord;
    for (x = 0; x < mandelbrot.width; x += 1) {
        for (y = 0; y < mandelbrot.height; y += 1) {
            xCoord = mandelbrot.coords.x1 + (x * xDistPerPixel);
            yCoord = mandelbrot.coords.y1 + (y * yDistPerPixel);
            value = Mandelbrot.calculateValue(mandelbrot, xCoord, yCoord, smoothing);
            if (value > highest) {
                highest = value;
            }
            if (value > 0 && value < lowest) {
                lowest = value;
            }
            mandelbrot.escapeValues[y * mandelbrot.width + x] = value;
        }
    }

    // scaling from 0 to 1
    var diff = highest - lowest;
    var i;
    for (i = 0; i < mandelbrot.escapeValues.length; i += 1) {
        mandelbrot.values[i] = (mandelbrot.escapeValues[i] - lowest) / diff;
    }

    return mandelbrot;
};

Mandelbrot.calculateValue = function (mandelbrot, xCoord, yCoord, smoothing) {

    var x = 0;
    var y = 0;
{'fraction_non_alphanumeric': 0.12347560975609756, 'fraction_numerical': 0.023170731707317073, 'mean_word_length': 2.0807511737089204, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '64845', 'n_tokens_mistral': 1249, 'n_tokens_neox': 1174, 'n_words': 288}