<commit_before>var Util = {};

Util.argmin = function(list, func) {
    if (typeof func === 'undefined') {
        func = function (x){return x;};
    }
    var minValue = Infinity,
        minIndex = -1;
    for (var i = 0; i < list.length; i++) {
        if (func(list[i]) < minValue) {
            minIndex = i;
            minValue = func(list[i]);
        }
    }
    return minIndex;
};

Util.argmax = function(list, func) {
    if (typeof func === 'undefined') {
        func = function (x){return x;};
    }
    var maxValue = -Infinity,
        maxIndex = -1;
    for (var i = 0; i < list.length; i++) {
        if (func(list[i]) > maxValue) {
            maxIndex = i;
            maxValue = func(list[i]);
        }
    }
    return maxIndex;
};


var Point = function(x, y) {
    if (typeof x === 'undefined' || typeof y === 'undefined'){
        throw new Error("Need to specify x and y");
    }

    this.x = x;
    this.y = y;
};

Point.getX = function(p) {
    return p.x;
};

Point.getY = function(p) {
    return p.y;
};

Point.prototype.toJSON = function() {
    return {
        x: this.x,
        y: this.y
    };
};

Point.prototype.equals = function(p) {
    return p.x === this.x && p.y === this.y;
};

var Zone = function(points) {
    if (typeof points === 'undefined'){
        this.points = [];
    } else {
        // list of point
        this.points = points;
    }

};

Zone.prototype.toJSON = function() {
    var json_points = [];
    for (var i = 0; i < this.points.length; i++) {
        json_points.push(this.points[i].toJSON());
    }

    return {
        points: json_points
    };
};

Zone.prototype.findPointIdx = function(x, y) {
    var p = new Point(x, y);
    for (var i = 0; i < this.points.length; i++) {
        if (this.points[i].equals(p)) {
            return i;
        }
    }
    // Point does not exist within collection
    return -1;
};

Zone.prototype.getPoints = function() {
    return this.points;
};

Zone.prototype.getTopLeftPoint = function() {
    var xIdx = Util.argmin(this.points, Point.getX),
        yIdx = Util.argmin(this.points, Point.getY);
    return this.points[this.findPointIdx(this.points[xIdx].x, this.points[yIdx].y)];
};

Zone.prototype.getTopRightPoint = function() {
    var xIdx = Util.argmax(this.points, Point.getX),
        yIdx = Util.argmin(this.points, Point.getY);
    return this.points[this.findPointIdx(this.points[xIdx].x, this.points[yIdx].y)];
};

Zone.prototype.getBottomRightPoint = function() {
    var xIdx = Util.argmax(this.points, Point.getX),
        yIdx = Util.argmax(this.points, Point.getY);
    return this.points[this.findPointIdx(this.points[xIdx].x, this.points[yIdx].y)];
};

Zone.prototype.getBottomLeftPoint = function() {
    var xIdx = Util.argmin(this.points, Point.getX),
        yIdx = Util.argmax(this.points, Point.getY);
    return this.points[this.findPointIdx(this.points[xIdx].x, this.points[yIdx].y)];
};

Zone.prototype.setPoints = function(points) {
    this.points = points;
};

Zone.prototype.setFromTopLeftPoint = function(x, y) {
    this.points = [
        new Point(x, y),
        new Point(x, y),
        new Point(x, y),
        new Point(x, y)
    ];
};<commit_msg>added expansion func for updating poitns<commit_after>var Util = {};

Util.argmin = function(list, func) {
    if (typeof func === 'undefined') {
        func = function (x){return x;};
    }
    var minValue = Infinity,
        minIndex = -1;
    for (var i = 0; i < list.length; i++) {
        if (func(list[i]) < minValue) {
            minIndex = i;
            minValue = func(list[i]);
        }
    }
    return minIndex;
};

Util.argmax = function(list, func) {
    if (typeof func === 'undefined') {
        func = function (x){return x;};
    }
    var maxValue = -Infinity,
        maxIndex = -1;
    for (var i = 0; i < list.length; i++) {
        if (func(list[i]) > maxValue) {
            maxIndex = i;
            maxValue = func(list[i]);
        }
    }
    return maxIndex;
};


var Point = function(x, y) {
    if (typeof x === 'undefined' || typeof y === 'undefined'){
        throw new Error("Need to specify x and y");
    }

    this.x = x;
    this.y = y;
};

Point.getX = function(p) {
    return p.x;
};

Point.getY = function(p) {
    return p.y;
};

Point.prototype.toJSON = function() {
    return {
        x: this.x,
        y: this.y
    };
};

Point.prototype.equals = function(p) {
    return p.x === this.x && p.y === this.y;
};

var Zone = function(points) {
    if (typeof points === 'undefined'){
        this.points = [];
    } else {
        // list of point
        this.points = points;
    }

};

Zone.prototype.toJSON = function() {
    var json_points = [];
    for (var i = 0; i < this.points.length; i++) {
        json_points.push(this.points[i].toJSON());
    }

    return {
        points: json_points
    };
};

Zone.prototype.findPointIdx = function(x, y) {
    var p = new Point(x, y);
    for (var i = 0; i < this.points.length; i++) {
        if (this.points[i].equals(p)) {
            return i;
        }
    }
    // Point does not exist within collection
    return -1;
};

Zone.prototype.getPoints = function() {
    return this.points;
};

Zone.prototype.getTopLeftPoint = function() {
    var xIdx = Util.argmin(this.points, Point.getX),
        yIdx = Util.argmin(this.points, Point.getY);
    return this.points[this.findPointIdx(this.points[xIdx].x, this.points[yIdx].y)];
};

Zone.prototype.getTopRightPoint = function() {
    var xIdx = Util.argmax(this.points, Point.getX),
        yIdx = Util.argmin(this.points, Point.getY);
    return this.points[this.findPointIdx(this.points[xIdx].x, this.points[yIdx].y)];
};

Zone.prototype.getBottomRightPoint = function() {
    var xIdx = Util.argmax(this.points, Point.getX),
        yIdx = Util.argmax(this.points, Point.getY);
    return this.points[this.findPointIdx(this.points[xIdx].x, this.points[yIdx].y)];
};

Zone.prototype.getBottomLeftPoint = function() {
    var xIdx = Util.argmin(this.points, Point.getX),
        yIdx = Util.argmax(this.points, Point.getY);
    return this.points[this.findPointIdx(this.points[xIdx].x, this.points[yIdx].y)];
};

Zone.prototype.setPoints = function(points) {
    this.points = points;
};

Zone.prototype.setFromTopLeftPoint = function(x, y) {
    this.points = [
        new Point(x, y),
        new Point(x, y),
        new Point(x, y),
        new Point(x, y)
    ];
};

Zone.prototype.updateFromBottomRight = function(x, y) {
    // top left
        // nothing
    // top right
    this.points[1].x = x;
    // bottom left
    this.points[2].y = y;
    // bottom right
    this.points[3].x = x;
    this.points[3].y = y;
};
{'fraction_non_alphanumeric': 0.16447564983567373, 'fraction_numerical': 0.00268897520167314, 'mean_word_length': 2.3525287931897845, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, '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': '7407698', 'n_tokens_mistral': 2342, 'n_tokens_neox': 2319, 'n_words': 503}