<commit_before>/**
 * An easy way to create path instructions for arbitrary shapes.
 *
 * @author Joschi <<EMAIL>>
 */

jkjs = window.jkjs || {}; // init namespace

jkjs.Path = function() {
  this.slack = "";
  this.strs = [];
};
jkjs.Path.prototype.isEmpty = function() {
  return !this.strs.length;
};
jkjs.Path.prototype.move = function(x, y) {
  if(!this.slack.length) {
    this.slack = "M".concat(x, " ", y);
  }
  this.strs.push(" M".concat(x, " ", y));
};
jkjs.Path.prototype.line = function(x, y) {
  this.strs.push(" L".concat(x, " ", y));
};
jkjs.Path.prototype.quad = function(mx, my, x, y) {
  this.strs.push(" Q".concat(mx, " ", my, " ", x, " ", y));
};
jkjs.Path.prototype.moveBy = function(dx, dy) {
  this.strs.push(" m".concat(dx, " ", dy));
};
jkjs.Path.prototype.lineBy = function(dx, dy) {
  this.strs.push(" l".concat(dx, " ", dy));
};
jkjs.Path.prototype.quadBy = function(dmx, dmy, dx, dy) {
  this.strs.push(" q".concat(dmx, " ", dmy, " ", dx, " ", dy));
};
jkjs.Path.prototype.close = function() {
  this.strs.push(" Z");
};
jkjs.Path.prototype.pointAdder = function(size) {
  // for tight loops
  var that = this;
  var s2 = size * 0.5;
  var down  = " l0 " + size;
  var right = " l" + size + " 0";
  var up    = " l0 " + (-size);
  var left  = " l" + (-size) + " 0";
  return function(x, y) {
    that.move(x - s2, y - s2);
    that.strs.push(down, right, up, left, " Z");
  };
};
jkjs.Path.prototype.toString = function() {
  // we always have a meaningless move before the actual path
  // so transitioning from an empty path will not try to animate
  // from an arbitrary position but will emerge at the correct position
  if(!this.slack.length) {
    if(!this.strs.length) {
      return "M0 0";
    }
    console.warn("meaningless start of path", this.strs);
  }
  // this.strs.length is larger than zero
  return String.prototype.concat.apply(this.slack, this.strs);
};
jkjs.Path.prototype.add = function(path) {
  if (path.isEmpty())
    return this;
  if (this.isEmpty()) {
    this.slack = path.slack;
  }
  this.strs = this.strs.concat(path.strs);
  return this;
};
// careful when using this method -- it just reverses the order of operations
jkjs.Path.prototype.reverse = function() {
  this.strs.reverse();
  return this;
};<commit_msg>handle many many path entries<commit_after>/**
 * An easy way to create path instructions for arbitrary shapes.
 *
 * @author Joschi <<EMAIL>>
 */

jkjs = window.jkjs || {}; // init namespace

jkjs.Path = function() {
  this.slack = "";
  this.strs = [];
};
jkjs.Path.prototype.isEmpty = function() {
  return !this.strs.length;
};
jkjs.Path.prototype.move = function(x, y) {
  if(!this.slack.length) {
    this.slack = "M".concat(x, " ", y);
  }
  this.strs.push(" M".concat(x, " ", y));
};
jkjs.Path.prototype.line = function(x, y) {
  this.strs.push(" L".concat(x, " ", y));
};
jkjs.Path.prototype.quad = function(mx, my, x, y) {
  this.strs.push(" Q".concat(mx, " ", my, " ", x, " ", y));
};
jkjs.Path.prototype.moveBy = function(dx, dy) {
  this.strs.push(" m".concat(dx, " ", dy));
};
jkjs.Path.prototype.lineBy = function(dx, dy) {
  this.strs.push(" l".concat(dx, " ", dy));
};
jkjs.Path.prototype.quadBy = function(dmx, dmy, dx, dy) {
  this.strs.push(" q".concat(dmx, " ", dmy, " ", dx, " ", dy));
};
jkjs.Path.prototype.close = function() {
  this.strs.push(" Z");
};
jkjs.Path.prototype.pointAdder = function(size) {
  // for tight loops
  var that = this;
  var s2 = size * 0.5;
  var down  = " l0 " + size;
  var right = " l" + size + " 0";
  var up    = " l0 " + (-size);
  var left  = " l" + (-size) + " 0";
  return function(x, y) {
    that.move(x - s2, y - s2);
    that.strs.push(down, right, up, left, " Z");
  };
};
jkjs.Path.prototype.toString = function() {
  // we always have a meaningless move before the actual path
  // so transitioning from an empty path will not try to animate
  // from an arbitrary position but will emerge at the correct position
  if(!this.slack.length) {
    if(!this.strs.length) {
      return "M0 0";
    }
    console.warn("meaningless start of path", this.strs);
  }
  // this.strs.length is larger than zero
  if(this.strs.length <= 100000) {
    return String.prototype.concat.apply(this.slack, this.strs);
  }
  console.warn("slow path");
  // slow concatenation for very long paths
  var res = this.slack;
  this.strs.forEach(function(s) {
    res += s;
  });
  return res;
};
jkjs.Path.prototype.add = function(path) {
  if (path.isEmpty())
    return this;
  if (this.isEmpty()) {
    this.slack = path.slack;
  }
  this.strs = this.strs.concat(path.strs);
  return this;
};
// careful when using this method -- it just reverses the order of operations
jkjs.Path.prototype.reverse = function() {
  this.strs.reverse();
  return this;
};
{'fraction_non_alphanumeric': 0.18878191712013395, 'fraction_numerical': 0.0058601925491837585, 'mean_word_length': 3.0881094952951242, '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': '6832917', 'n_tokens_mistral': 1785, 'n_tokens_neox': 1762, 'n_words': 428}