<commit_before>// cobweb.js

// Global shortcuts for important Math functions

// A graph for drawing mathy things.
function Graph(canvas,xmin,ymin,xmax,ymax){
    var vars=['canvas','xmin','ymin','xmax','ymax'];
    for(var i in vars){
        eval("var "+vars[i]+"="+vars[i]);
    }
    var ctx=canvas.getContext('2d');
    var h=canvas.height;
    var w=canvas.width;
    var borderSize=2; // a differently-colored area at the outermost part of the canvas to visually indicate the graph's border
    if(/*// Change the number of slashes before "*" to enable/disable the border.
        true ||//*/
        2*borderSize>h || 2*borderSize>w){ // disable border if it's going to cause a problem
        borderSize=0;
    }
    var edgeSize=borderSize+0.5; // This small buffer zone close to the border keeps the graph from going half a pixel too far, at least in Firefox.
    var fillColor='rgb(128,128,128)';
    var borderColor='rgb(0,255,0)';
    var drawColor='rgb(0,0,0)';

    // Blank out the canvas to a pristine state.
    this.resetCanvas=function(){
        ctx.fillStyle=borderColor;
        ctx.fillRect(0,0,w,h);
        ctx.fillStyle=fillColor;
        ctx.fillRect(borderSize,borderSize,w-2*borderSize,h-2*borderSize);
        ctx.strokeStyle=drawColor
    }

    // convert a mathematical x coordinate to a canvas x coordinate
    function mathToCanvasX(x){
        max=w-edgeSize*2;
        portion=(x-xmin)/(xmax-xmin);
        return portion*max+edgeSize;
    }
    // convert a mathematical y coordinate to a canvas y coordinate
    function mathToCanvasY(y){
        max=w-edgeSize*2;
        portion=(y-ymin)/(ymax-ymin);
        return h-(portion*max+edgeSize);
    }

    // Plot a line segment, using math function x and y coordinates (not canvas coordinates).
    this.plotLine=function(x1,y1,x2,y2){
        // convert coordinates
        var cx1=mathToCanvasX(x1);
        var cy1=mathToCanvasY(y1);
        var cx2=mathToCanvasX(x2);
        var cy2=mathToCanvasY(y2);

        // plot the line segment
        ctx.beginPath();
        ctx.moveTo(cx1,cy1);
        ctx.lineTo(cx2,cy2);
        ctx.stroke();
        ctx.closePath();
    }

    // Plot a function.
    this.plotFunction=function(f){
        // get initial point and distance between points
        x1=xmin;
        y1=f(x1);
        delta=(xmax-xmin)/(w-2*borderSize);
        // go thru all point values, with 'delta/2' to avoid rounding error preventing the last point from being drawn
        for(var x2=xmin+delta;x2<=xmax+delta/2;x2+=delta){
            y2=f(x2);<commit_msg>Fix infinite loop when xmin==xmax.<commit_after>// cobweb.js

// Global shortcuts for important Math functions

// A graph for drawing mathy things.
function Graph(canvas,xmin,ymin,xmax,ymax){
    var vars=['canvas','xmin','ymin','xmax','ymax'];
    for(var i in vars){
        eval("var "+vars[i]+"="+vars[i]);
    }
    var ctx=canvas.getContext('2d');
    var h=canvas.height;
    var w=canvas.width;
    var borderSize=2; // a differently-colored area at the outermost part of the canvas to visually indicate the graph's border
    if(/*// Change the number of slashes before "*" to enable/disable the border.
        true ||//*/
        2*borderSize>h || 2*borderSize>w){ // disable border if it's going to cause a problem
        borderSize=0;
    }
    var edgeSize=borderSize+0.5; // This small buffer zone close to the border keeps the graph from going half a pixel too far, at least in Firefox.
    var fillColor='rgb(128,128,128)';
    var borderColor='rgb(0,255,0)';
    var drawColor='rgb(0,0,0)';

    // Blank out the canvas to a pristine state.
    this.resetCanvas=function(){
        ctx.fillStyle=borderColor;
        ctx.fillRect(0,0,w,h);
        ctx.fillStyle=fillColor;
        ctx.fillRect(borderSize,borderSize,w-2*borderSize,h-2*borderSize);
        ctx.strokeStyle=drawColor
    }

    // convert a mathematical x coordinate to a canvas x coordinate
    function mathToCanvasX(x){
        max=w-edgeSize*2;
        portion=(x-xmin)/(xmax-xmin);
        return portion*max+edgeSize;
    }
    // convert a mathematical y coordinate to a canvas y coordinate
    function mathToCanvasY(y){
        max=w-edgeSize*2;
        portion=(y-ymin)/(ymax-ymin);
        return h-(portion*max+edgeSize);
    }

    // Plot a line segment, using math function x and y coordinates (not canvas coordinates).
    this.plotLine=function(x1,y1,x2,y2){
        // convert coordinates
        var cx1=mathToCanvasX(x1);
        var cy1=mathToCanvasY(y1);
        var cx2=mathToCanvasX(x2);
        var cy2=mathToCanvasY(y2);

        // plot the line segment
        ctx.beginPath();
        ctx.moveTo(cx1,cy1);
        ctx.lineTo(cx2,cy2);
        ctx.stroke();
        ctx.closePath();
    }

    // Plot a function.
    this.plotFunction=function(f){
        // get initial point and distance between points
        x1=xmin;
        y1=f(x1);
        delta=(xmax-xmin)/(w-2*borderSize);
        // Go thru all point values, with 'delta/2' to avoid rounding error preventing the last point from being drawn.
        // Note: Altho "<" vs "<=" is irrelevant with probability 1, only "<" avoids an infinite loop when xmin==xmax, like when their both zero from nothing being entered.
        for(var x2=xmin+delta;x2<xmax+delta/2;x2+=delta){
            y2=f(x2);
{'fraction_non_alphanumeric': 0.1251402918069585, 'fraction_numerical': 0.02151141040029929, 'mean_word_length': 2.6977869986168743, 'pattern_counts': {'":': 0, '<': 8, '<?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': '1934699', 'n_tokens_mistral': 1737, 'n_tokens_neox': 1682, 'n_words': 461}