<commit_before>(function(exports) {
    function rgb_avg(a, b) {
        return new {
            r: (a.r + b.r) / 2,
            g: (a.g + b.g) / 2,
            b: (a.b + b.b) / 2                            
        }
    }
    
    function rgb_equal(a, b, tol) {
        tol = tol || 2;
    
        if (Math.abs(a.r - b.r) > tol) {
            return false;
        }
        if (Math.abs(a.g - b.g) > tol) {
            return false;
        }
        if (Math.abs(a.b - b.b) > tol) {
            return false;
        }
        
        return true;
    }
    
    function arrayToRgb(arr) {
        var ret = {
            r: array[0],
            g: array[1],
            b: array[2]        
        };
        
        if (array.length == 4) {
            ret.a = array[3];
        }

        return ret;
    };
    
    function calculateGradient(arr) {
        var ret = [];
        var height = arr.length;
        var width = arr[0].length;                        
        var t1 = arr[0][0];
        var tr = arr[0][width - 1];
        var b1 = arr[height - 1][0];
        var br = arr[height - 1][width - 1];  
        
        log(t1, tr, b1, br);

        // horizontal gradient
        if (rgb_equal(t1, tr)) {
            //g->start = top;
            //l=image->height;
            //if(l % 2 == 1) {
                //mid = getpixel(image, 0, l/2);
            //}
            //else {
                //mid = rgb_avg(getpixel(image, 0, l/2), getpixel(image, 0, l/2-1));
            //}
        }
        // vertical gradient
        else if(rgb_equal(tl, bl)) {
            //g->start = left;
            //l=image->width;
            //if(l % 2 == 1) {
                //mid = getpixel(image, l/2, 0);
            //}
            //else {
                //mid = rgb_avg(getpixel(image, l/2, 0), getpixel(image, l/2-1, 0));
            //}
        }
        // ltr diag
        else if(rgb_equal(tr, bl) && !rgb_equal(tl, br)) {
            //g->start = top_left;
            //l=image->height;
        }
        // rtl diag
        else if(rgb_equal(tl, br) && !rgb_equal(tr, bl)) {
            //g->start = top_right;
            //l=image->height;
            //tl = tr;
            //br = bl;
        }
        
        
        //g->colors = (rgb *)calloc(2, sizeof(rgb));
        //g->colors[0] = tl;
        //g->colors[1] = br;
        //g->ncolors = 2;
        
        // If it's a diagonal, we only support 2 colours 
        // If it's horizontal or vertical and the middle colour is the avg of the ends, then<commit_msg>correctly find orientation/midpoints<commit_after>(function(exports) {
    function rgb_avg(a, b) {
        return {
            r: (a.r + b.r) / 2,
            g: (a.g + b.g) / 2,
            b: (a.b + b.b) / 2                            
        };
    }
    
    function rgb_equal(a, b, tol) {
        tol = tol || 2;
    
        if (Math.abs(a.r - b.r) > tol) {
            return false;
        }
        if (Math.abs(a.g - b.g) > tol) {
            return false;
        }
        if (Math.abs(a.b - b.b) > tol) {
            return false;
        }
        
        return true;
    }
    
    function arrayToRgb(arr) {
        if (!arr) {
            //return;
        }
    
        var ret = {
            r: arr[0],
            g: arr[1],
            b: arr[2]        
        };
        
        if (arr.length == 4) {
            ret.a = arr[3];
        }

        return ret;
    };
    
    function getPixel(arr, x, y) {
        return arrayToRgb(arr[y][x]);
    }

    function calculateGradient(arr) {
        var ret = [];
        var height = arr.length;
        var width = arr[0].length;                        
        var tl = getPixel(arr, 0, 0);
        var tr = getPixel(arr, width - 1, 0);
        var bl = getPixel(arr, 0, height - 1);
        var br = getPixel(arr, width - 1, height - 1);  
      
        var grad_len;
        var grad;
        var mid;
        var grad_start;               

        // vertical gradient -- row[0][0] == row[0][height]
        if (rgb_equal(tl, tr)) {
            grad_start = "top";
            grad_len = height;
            if (grad_len % 2 === 0) {
                mid = getPixel(arr, 0, grad_len / 2);
            }
            else {                            
                mid = rgb_avg(getPixel(arr, 0, grad_len / 2), getPixel(image, 0, (grad_len / 2) - 1));
            }
        }
        // horizontal gradient
        else if (rgb_equal(tl, bl)) {
            grad_start = "left";
            grad_len = width;            
            if (grad_len % 2 === 0) {
                mid = getPixel(arr, grad_len / 2, 0);
            }
            else {          
                mid = rgb_avg(getPixel(arr, Math.floor(grad_len / 2), 0), getPixel(arr, Math.ceil(grad_len / 2), 0));
            }
        }
        // ltr diag
        else if(rgb_equal(tr, bl) && !rgb_equal(tl, br)) {
            grad_start = "top_left";
            grad_len = height;
        }
        // rtl diag
        else if(rgb_equal(tl, br) && !rgb_equal(tr, bl)) {
            grad_start = "top_right";
            grad_len = height;
            tl = tr;
            br = bl;
        }
        
        log(grad_len, grad, mid, grad_start);
                
        //g->colors = (rgb *)calloc(2, sizeof(rgb));
        //g->colors[0] = tl;
        //g->colors[1] = br;
        //g->ncolors = 2;
        
        // If it's a diagonal, we only support 2 colours 
        // If it's horizontal or vertical and the middle colour is the avg of the ends, then
{'fraction_non_alphanumeric': 0.14370396982216635, 'fraction_numerical': 0.015987066642716007, 'mean_word_length': 1.0195865070729053, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2673000', 'n_tokens_mistral': 1894, 'n_tokens_neox': 1801, 'n_words': 435}