<commit_before>/*
 * Copyright (c) 2011 <NAME> (http://www.incaseofstairs.com/)
 * See LICENSE for license information
 */
var ColorStops = {};

(function() {
    function slopeChanged(oldDirv, newDirv) {
        if (!oldDirv[0] && !oldDirv[1] && !oldDirv[2] && !oldDirv[3]) {
            return false;
        }

        return (newDirv[0] && (oldDirv[0]<0 !== newDirv[0]<0))
            || (newDirv[1] && (oldDirv[1]<0 !== newDirv[1]<0))
            || (newDirv[2] && (oldDirv[2]<0 !== newDirv[2]<0))
            || (newDirv[3] && (oldDirv[3]<0 !== newDirv[3]<0));
    }
    function updateDirv(oldDirv, newDirv) {
        return [
                newDirv[0] || oldDirv[0],
                newDirv[1] || oldDirv[1],
                newDirv[2] || oldDirv[2],
                newDirv[3] || oldDirv[3],
            ];
    }

    function colorsApproxEqual(color1, color2) {
        const EPSILON = 256*0.01;

        return Math.abs(color1[0]-color2[0]) <= EPSILON
            && Math.abs(color1[1]-color2[1]) <= EPSILON
            && Math.abs(color1[2]-color2[2]) <= EPSILON
            && Math.abs(color1[3]-color2[3]) <= EPSILON;
    }
    function stopsLinear(prev, cur, next) {
        var deltaX = next.position-prev.position,
            slope = [
                (next.color[0]-prev.color[0])/deltaX,
                (next.color[1]-prev.color[1])/deltaX,
                (next.color[2]-prev.color[2])/deltaX,
                (next.color[3]-prev.color[3])/deltaX
            ],
            curDeltaX = cur.position-prev.position,
            curEstimate = [
                prev.color[0]+slope[0]*curDeltaX | 0,
                prev.color[1]+slope[1]*curDeltaX | 0,
                prev.color[2]+slope[2]*curDeltaX | 0,
                prev.color[3]+slope[3]*curDeltaX | 0
            ];

        return colorsApproxEqual(cur.color, curEstimate);
    }
    function cullDuplicates(stops) {
        if (stops.length < 2) {
            return;
        }

        // Special case for the first to remove any repeating sections
        if (colorsApproxEqual(stops[0].color, stops[1].color)) {
            stops.splice(0, 1);
        }

        // Check to see if the current element is on the same line as the previous and next. If so remove.
        var len = stops.length;
        for (var i = 1; i < len-1; i++) {
            if (stopsLinear(stops[i-1], stops[i], stops[i-1])) {
                stops.splice(i, 1);
                i--;    len--;
            }
        }

        // Another special case for the last to remove any repeating sections
        if (colorsApproxEqual(stops[len-2].color, stops[len-1].color)) {
            stops.splice(len-1, 1);
        }
    }

    ColorStops.extractColorStops = function(lineData) {
        var len = lineData.length,
            last = [lineData[0], lineData[1], lineData[2], lineData[3]],
            dirv = [0, 0, 0, 0],
            ret = [];

        // We always have a color stop on the first pixel
        ret.push({
            position: 0.0,<commit_msg>Do not attempt to cull the last color stop if there is only one left.<commit_after>/*
 * Copyright (c) 2011 <NAME> (http://www.incaseofstairs.com/)
 * See LICENSE for license information
 */
var ColorStops = {};

(function() {
    function slopeChanged(oldDirv, newDirv) {
        if (!oldDirv[0] && !oldDirv[1] && !oldDirv[2] && !oldDirv[3]) {
            return false;
        }

        return (newDirv[0] && (oldDirv[0]<0 !== newDirv[0]<0))
            || (newDirv[1] && (oldDirv[1]<0 !== newDirv[1]<0))
            || (newDirv[2] && (oldDirv[2]<0 !== newDirv[2]<0))
            || (newDirv[3] && (oldDirv[3]<0 !== newDirv[3]<0));
    }
    function updateDirv(oldDirv, newDirv) {
        return [
                newDirv[0] || oldDirv[0],
                newDirv[1] || oldDirv[1],
                newDirv[2] || oldDirv[2],
                newDirv[3] || oldDirv[3],
            ];
    }

    function colorsApproxEqual(color1, color2) {
        const EPSILON = 256*0.01;

        return Math.abs(color1[0]-color2[0]) <= EPSILON
            && Math.abs(color1[1]-color2[1]) <= EPSILON
            && Math.abs(color1[2]-color2[2]) <= EPSILON
            && Math.abs(color1[3]-color2[3]) <= EPSILON;
    }
    function stopsLinear(prev, cur, next) {
        var deltaX = next.position-prev.position,
            slope = [
                (next.color[0]-prev.color[0])/deltaX,
                (next.color[1]-prev.color[1])/deltaX,
                (next.color[2]-prev.color[2])/deltaX,
                (next.color[3]-prev.color[3])/deltaX
            ],
            curDeltaX = cur.position-prev.position,
            curEstimate = [
                prev.color[0]+slope[0]*curDeltaX | 0,
                prev.color[1]+slope[1]*curDeltaX | 0,
                prev.color[2]+slope[2]*curDeltaX | 0,
                prev.color[3]+slope[3]*curDeltaX | 0
            ];

        return colorsApproxEqual(cur.color, curEstimate);
    }
    function cullDuplicates(stops) {
        if (stops.length < 2) {
            return;
        }

        // Special case for the first to remove any repeating sections
        if (colorsApproxEqual(stops[0].color, stops[1].color)) {
            stops.splice(0, 1);
        }

        // Check to see if the current element is on the same line as the previous and next. If so remove.
        var len = stops.length;
        for (var i = 1; i < len-1; i++) {
            if (stopsLinear(stops[i-1], stops[i], stops[i-1])) {
                stops.splice(i, 1);
                i--;    len--;
            }
        }

        // Another special case for the last to remove any repeating sections
        if (len >= 2 && colorsApproxEqual(stops[len-2].color, stops[len-1].color)) {
            stops.splice(len-1, 1);
        }
    }

    ColorStops.extractColorStops = function(lineData) {
        var len = lineData.length,
            last = [lineData[0], lineData[1], lineData[2], lineData[3]],
            dirv = [0, 0, 0, 0],
            ret = [];

        // We always have a color stop on the first pixel
        ret.push({
            position: 0.0,
{'fraction_non_alphanumeric': 0.15557377049180326, 'fraction_numerical': 0.034262295081967216, 'mean_word_length': 1.7883912248628884, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3045205', 'n_tokens_mistral': 2135, 'n_tokens_neox': 2023, 'n_words': 403}