<commit_before>var Geometry = Geometry || {};

Geometry.Polygon = function(verticies) {
    this.verticies = verticies;
}

// Provided an SVN.draw as an argument, draws the polygon onto that
// SVN canvas.  Returns the SVN object
Geometry.Polygon.prototype.draw = function(canvas) {
    return canvas.polygon(this.verticies);
}

// Given another Geometry.Polygon, returns true if the polygons intersect,
// false otherwise
Geometry.Polygon.prototype.intersects = function(other) {
    var vert1 = [];
    for(var i=0; i<this.verticies.length; i++) {
        vert1.push({x: this.verticies[i][0], y: this.verticies[i][1]});
    }
    var vert2 = [];
    for(var j=0; j<other.verticies.length; j++) {
        vert2.push({x: other.verticies[j][0], y: other.verticies[j][1]});
    }
    var intersection = intersectionPolygons(vert1, vert2);
    return intersection.length > 0;
}

// Get the area of this polygon
Geometry.Polygon.prototype.area = function() {
    var area = 0.0;
    var j = this.verticies.length-1;
    for(var i=0; i<this.verticies.length; i++) {
        area += (this.verticies[j][0]+this.verticies[i][0])*(this.verticies[j][1]-this.verticies[i][1]);
        j = i;
    }
    return Math.abs(area/2.0);
}

// Scales a polygon by factor relative to point (an array of two floats)
// Does NOT mutate the polygon, but rather returns a new one
Geometry.Polygon.prototype.scale = function(point, factor) {
    var newVerticies = [];
    for(var k=0; k<this.verticies.length; k++) {
        newVerticies[k] = [
            (this.verticies[k][0]-point[0])*factor + point[0],
            (this.verticies[k][1]-point[1])*factor + point[1]
        ];
    }
    return new Geometry.Polygon(newVerticies);
}



// minArea = if the area of a Sierpinski triangle is less than or equal to this area, then
//           we just draw a triangle instead of recursively drawing three new Sierpinskis.
Geometry.Sierpinski = function(verticies, minArea) {
    Geometry.Polygon.call(this, verticies);
    if(this.area() <= minArea) {
        this.nestedShapes = [new Geometry.Polygon(verticies)];
    } else {
        var midpoints = [
            [(verticies[0][0]+verticies[1][0])/2.0, (verticies[0][1]+verticies[1][1])/2.0],
            [(verticies[1][0]+verticies[2][0])/2.0, (verticies[1][1]+verticies[2][1])/2.0],
            [(verticies[2][0]+verticies[0][0])/2.0, (verticies[2][1]+verticies[0][1])/2.0],
        ];
        this.nestedShapes = [
            new Geometry.Sierpinski([verticies[0], midpoints[0], midpoints[2]], minArea),
            new Geometry.Sierpinski([midpoints[0], verticies[1], midpoints[1]], minArea),
            new Geometry.Sierpinski([midpoints[2], midpoints[1], verticies[2]], minArea)
        ];
    }
}

Geometry.Sierpinski.prototype = Object.create(Geometry.Polygon.prototype);

// Returns an array of drawn objects (nested)
Geometry.Sierpinski.prototype.draw = function(canvas) {
    var drawables = [];
    for(var i=0; i<this.nestedShapes.length; i++) {
        drawables[i] = this.nestedShapes[i].draw(canvas);
    }
    return drawables;
}



// This function takes an array of gaskets, splits gaskets which are partially or entirely off
// screen, then removes gaskets that are entirely off screen.  This allows us to infinitely zoom
// into a gasket while maintaining O(1) memory with respect to time.<commit_msg>Added scale for Sierpinski<commit_after>var Geometry = Geometry || {};

Geometry.Polygon = function(verticies) {
    this.verticies = verticies;
}

// Provided an SVN.draw as an argument, draws the polygon onto that
// SVN canvas.  Returns the SVN object
Geometry.Polygon.prototype.draw = function(canvas) {
    return canvas.polygon(this.verticies);
}

// Given another Geometry.Polygon, returns true if the polygons intersect,
// false otherwise
Geometry.Polygon.prototype.intersects = function(other) {
    var vert1 = [];
    for(var i=0; i<this.verticies.length; i++) {
        vert1.push({x: this.verticies[i][0], y: this.verticies[i][1]});
    }
    var vert2 = [];
    for(var j=0; j<other.verticies.length; j++) {
        vert2.push({x: other.verticies[j][0], y: other.verticies[j][1]});
    }
    var intersection = intersectionPolygons(vert1, vert2);
    return intersection.length > 0;
}

// Get the area of this polygon
Geometry.Polygon.prototype.area = function() {
    var area = 0.0;
    var j = this.verticies.length-1;
    for(var i=0; i<this.verticies.length; i++) {
        area += (this.verticies[j][0]+this.verticies[i][0])*(this.verticies[j][1]-this.verticies[i][1]);
        j = i;
    }
    return Math.abs(area/2.0);
}

// Scales a polygon by factor relative to point (an array of two floats)
// Does NOT mutate the polygon, but rather returns a new one
Geometry.Polygon.prototype.scale = function(point, factor) {
    var newVerticies = [];
    for(var k=0; k<this.verticies.length; k++) {
        newVerticies[k] = [
            (this.verticies[k][0]-point[0])*factor + point[0],
            (this.verticies[k][1]-point[1])*factor + point[1]
        ];
    }
    return new Geometry.Polygon(newVerticies);
}



// minArea = if the area of a Sierpinski triangle is less than or equal to this area, then
//           we just draw a triangle instead of recursively drawing three new Sierpinskis.
Geometry.Sierpinski = function(verticies, minArea) {
    Geometry.Polygon.call(this, verticies);
    this.minArea = minArea;
    if(this.area() <= minArea) {
        this.nestedShapes = [new Geometry.Polygon(verticies)];
    } else {
        var midpoints = [
            [(verticies[0][0]+verticies[1][0])/2.0, (verticies[0][1]+verticies[1][1])/2.0],
            [(verticies[1][0]+verticies[2][0])/2.0, (verticies[1][1]+verticies[2][1])/2.0],
            [(verticies[2][0]+verticies[0][0])/2.0, (verticies[2][1]+verticies[0][1])/2.0],
        ];
        this.nestedShapes = [
            new Geometry.Sierpinski([verticies[0], midpoints[0], midpoints[2]], minArea),
            new Geometry.Sierpinski([midpoints[0], verticies[1], midpoints[1]], minArea),
            new Geometry.Sierpinski([midpoints[2], midpoints[1], verticies[2]], minArea)
        ];
    }
}

Geometry.Sierpinski.prototype = Object.create(Geometry.Polygon.prototype);

// Returns an array of drawn objects (nested)
Geometry.Sierpinski.prototype.draw = function(canvas) {
    var drawables = [];
    for(var i=0; i<this.nestedShapes.length; i++) {
        drawables[i] = this.nestedShapes[i].draw(canvas);
    }
    return drawables;
}

// Returns a new Sierpinski gasket, scaled like above (small triangles that grow
// are resolved into gaskets)
Geometry.Sierpinski.prototype.scale = function(point, factor) {
    // Object.getPrototypeOf(...).scale.call(...) is like doing super(point, factor)
    return new Geometry.Sierpinski(
        Object.getPrototypeOf(Geometry.Sierpinski.prototype).scale.call(this, point, factor).verticies,
        this.minArea
    );
}



// This function takes an array of gaskets, splits gaskets which are partially or entirely off
// screen, then removes gaskets that are entirely off screen.  This allows us to infinitely zoom
// into a gasket while maintaining O(1) memory with respect to time.
{'fraction_non_alphanumeric': 0.15040423752439364, 'fraction_numerical': 0.02146640646780039, 'mean_word_length': 3.3118990384615383, 'pattern_counts': {'":': 0, '<': 15, '<?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': '1174536', 'n_tokens_mistral': 2415, 'n_tokens_neox': 2426, 'n_words': 554}