<commit_before>var TegakiBrush;

TegakiBrush = {
  name: 'brush',
  
  brushFn: function(x, y) {
    var i, ctx, dest, data, len, kernel;
    
    x = 0 | x;
    y = 0 | y;
    
    ctx = Tegaki.ghostCtx;
    dest = ctx.getImageData(x, y, this.brushSize, this.brushSize);
    data = dest.data;
    kernel = this.kernel;
    len = kernel.length;
    
    i = 0;
    while (i < len) {
      data[i] = this.rgb[0]; ++i;
      data[i] = this.rgb[1]; ++i;
      data[i] = this.rgb[2]; ++i;
      data[i] += kernel[i] * (1.0 - data[i] / 255); ++i;
    }
    
    ctx.putImageData(dest, x, y);
  },
  
  generateBrushCache: function() {
    var i, tmp;
    
    tmp = this.size;
    
    for (i = this.pressureCache.length; i < tmp; ++i) {
      this.size = i + 1;
      this.generateBrush();
      this.pressureCache.push(this.kernel);
    }
    
    this.size = tmp;
  },
  
  updateDynamics: function(t) {
    var pressure, size, d;
    
    pressure = TegakiPressure.lerp(t);
    
    if (this.sizePressureCtrl === true) {
      size = 0 | Math.round(pressure * this.size);
      
      if (size === 0) {
        return false;
      }
      
      d = 0 | Math.round((size - this.size) / 2);
      
      this.center = 0 | (size / 2);
      
      this.kernel = this.pressureCache[size - 1];
      
      this.stepSize = 0 | Math.min(Math.floor(size * this.step), 8);
      
      this.brushSize = size;
    }
    
    return true;
  },
  
  commit: function() {
    Tegaki.activeCtx.drawImage(Tegaki.ghostCanvas, 0, 0);
    Tegaki.clearCtx(Tegaki.ghostCtx);
  },
  
  draw: function(posX, posY, pt) {
    var mx, my, fromX, fromY, dx, dy, err, derr, stepAcc,
      distBase, distLeft;
    
    stepAcc = this.stepAcc;
    
    if (pt === true) {
      this.stepAcc = 0;
      this.posX = posX; 
      this.posY = posY;
      
      if (!this.sizePressureCtrl || this.updateDynamics(1.0)) {
        this.brushFn(posX - this.center, posY - this.center);
      }
      return;
    }
    
    fromX = this.posX;
    fromY = this.posY;
    
    if (fromX < posX) { dx = posX - fromX; mx = 1; }
    else { dx = fromX - posX; mx = -1; }
    if (fromY < posY) { dy = posY - fromY; my = 1; }
    else { dy = fromY - posY; my = -1; }
    
    err = (dx > dy ? dx : -dy) / 2;
    
    dx = -dx;
    
    if (this.sizePressureCtrl) {
      distBase = (posX - fromX) * (posX - fromX) + (posY - fromY) * (posY - fromY);
    }
    
    while (true) {
      ++stepAcc;
      
      if (stepAcc > this.stepSize) {
        if (this.sizePressureCtrl) {
          distLeft = (posX - fromX) * (posX - fromX) + (posY - fromY) * (posY - fromY);
          if (this.updateDynamics(1.0 - (distLeft / distBase))) {
            this.brushFn(fromX - this.center, fromY - this.center);
          }
        }
        else {
          this.brushFn(fromX - this.center, fromY - this.center);
        }
        
        stepAcc = 0;
      }
      
      if (fromX === posX && fromY === posY) {
        break;<commit_msg>Less sloppy pressure lerping<commit_after>var TegakiBrush;

TegakiBrush = {
  name: 'brush',
  
  brushFn: function(x, y) {
    var i, ctx, dest, data, len, kernel;
    
    x = 0 | x;
    y = 0 | y;
    
    ctx = Tegaki.ghostCtx;
    dest = ctx.getImageData(x, y, this.brushSize, this.brushSize);
    data = dest.data;
    kernel = this.kernel;
    len = kernel.length;
    
    i = 0;
    while (i < len) {
      data[i] = this.rgb[0]; ++i;
      data[i] = this.rgb[1]; ++i;
      data[i] = this.rgb[2]; ++i;
      data[i] += kernel[i] * (1.0 - data[i] / 255); ++i;
    }
    
    ctx.putImageData(dest, x, y);
  },
  
  generateBrushCache: function() {
    var i, tmp;
    
    tmp = this.size;
    
    for (i = this.pressureCache.length; i < tmp; ++i) {
      this.size = i + 1;
      this.generateBrush();
      this.pressureCache.push(this.kernel);
    }
    
    this.size = tmp;
  },
  
  updateDynamics: function(t) {
    var pressure, size, d;
    
    pressure = TegakiPressure.lerp(t);
    
    if (this.sizePressureCtrl === true) {
      size = 0 | Math.round(pressure * this.size);
      
      if (size === 0) {
        return false;
      }
      
      d = 0 | Math.round((size - this.size) / 2);
      
      this.center = 0 | (size / 2);
      
      this.kernel = this.pressureCache[size - 1];
      
      this.stepSize = 0 | Math.min(Math.floor(size * this.step), 8);
      
      this.brushSize = size;
    }
    
    return true;
  },
  
  commit: function() {
    Tegaki.activeCtx.drawImage(Tegaki.ghostCanvas, 0, 0);
    Tegaki.clearCtx(Tegaki.ghostCtx);
  },
  
  draw: function(posX, posY, pt) {
    var mx, my, fromX, fromY, dx, dy, err, derr, stepAcc,
      distBase, distLeft;
    
    stepAcc = this.stepAcc;
    
    if (pt === true) {
      this.stepAcc = 0;
      this.posX = posX; 
      this.posY = posY;
      
      if (!this.sizePressureCtrl || this.updateDynamics(1.0)) {
        this.brushFn(posX - this.center, posY - this.center);
      }
      return;
    }
    
    fromX = this.posX;
    fromY = this.posY;
    
    if (fromX < posX) { dx = posX - fromX; mx = 1; }
    else { dx = fromX - posX; mx = -1; }
    if (fromY < posY) { dy = posY - fromY; my = 1; }
    else { dy = fromY - posY; my = -1; }
    
    err = (dx > dy ? dx : -dy) / 2;
    
    dx = -dx;
    
    if (this.sizePressureCtrl) {
      distBase = Math.sqrt((posX - fromX) * (posX - fromX) + (posY - fromY) * (posY - fromY));
    }
    
    while (true) {
      ++stepAcc;
      
      if (stepAcc > this.stepSize) {
        if (this.sizePressureCtrl) {
          distLeft = Math.sqrt((posX - fromX) * (posX - fromX) + (posY - fromY) * (posY - fromY));
          if (this.updateDynamics(1.0 - (distLeft / distBase))) {
            this.brushFn(fromX - this.center, fromY - this.center);
          }
        }
        else {
          this.brushFn(fromX - this.center, fromY - this.center);
        }
        
        stepAcc = 0;
      }
      
      if (fromX === posX && fromY === posY) {
        break;
{'fraction_non_alphanumeric': 0.15587010824313072, 'fraction_numerical': 0.011323896752706078, 'mean_word_length': 1.68125, 'pattern_counts': {'":': 0, '<': 11, '<?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': '3051424', 'n_tokens_mistral': 2356, 'n_tokens_neox': 2289, 'n_words': 498}