<commit_before>Physics.Constraint = function(config) {
  this.one = config.one;
  this.two = config.two;
  
  this.rigidity = config.rigidity || config.rgd || 1/3;
  this.length = config.length || 100;
  
  this.one.constraints.push(this);
  this.two.constraints.push(this);
};
Physics.Constraint.prototype.springEffect = function() {
  var distance = Vector2.dist(this.one.pos, this.two.pos);
  var difference = Vector2.mult(Vector2.normalize(Vector2.sub(this.one.pos, this.two.pos)), this.rigidity * (distance/this.length - 1));
  
  this.one.applyForce(Vector2.mult(difference, -1));
  this.two.applyForce(difference);
};
Physics.Constraint.prototype.forceCompensate = function() {
  var distance = Vector2.dist(this.one.pos, this.two.pos);
  var difference = Vector2.mult(Vector2.normalize(Vector2.normalize(this.one.pos, this.two.pos)), this.length/2);
  var mid = Vector2.mid(this.one.pos, this.two.pos);
  
  if(!this.one.fixed) {
    this.one.posAdjustments.push(Vector2.add(mid, difference));
    this.one.pos = Vector2.lerp(
      this.one.pos,
      Vector2.add(mid, difference),
      Physics.constraintCompensationStrength
    );
  }
  
  if(!this.two.fixed) {
    this.two.posAdjustments.push(Vector2.sub(mid, difference));
    this.two.pos = Vector2.lerp(
      this.two.pos,
      Vector2.sub(mid, difference),
      Physics.constraintCompensationStrength
    );
  }
};
Physics.Constraint.prototype.draw = function() {
  ctx.beginPath();
  ctx.strokeStyle = "#000";
  ctx.lineWidth = 5;
  ctx.moveTo(this.one.pos.x, this.one.pos.y);
  ctx.lineTo(this.two.pos.x, this.two.pos.y);
  ctx.stroke();
};
Physics.Constraint.prototype.display = function() {
  if(this.update) {
    this.update();
  }
  this.draw();
};<commit_msg>Update constraint.js<commit_after>if (!Physics.Constraint) {
  Physics.Constraint = function(config) {
    this.one = config.one;
    this.two = config.two;

    this.rigidity = config.rigidity || config.rgd || 1 / 3;
    this.length = config.length || 100;

    this.one.constraints.push(this);
    this.two.constraints.push(this);
  };
  Physics.Constraint.prototype.springEffect = function() {
    var distance = Vector2.dist(this.one.pos, this.two.pos);
    var difference = Vector2.mult(Vector2.normalize(Vector2.sub(this.one.pos, this.two.pos)), this.rigidity * (distance / this.length - 1));

    this.one.applyForce(Vector2.mult(difference, -1));
    this.two.applyForce(difference);
  };
  Physics.Constraint.prototype.forceCompensate = function() {
    var distance = Vector2.dist(this.one.pos, this.two.pos);
    var difference = Vector2.mult(Vector2.normalize(Vector2.normalize(this.one.pos, this.two.pos)), this.length / 2);
    var mid = Vector2.mid(this.one.pos, this.two.pos);

    if (!this.one.fixed) {
      this.one.posAdjustments.push(Vector2.add(mid, difference));
      this.one.pos = Vector2.lerp(
        this.one.pos,
        Vector2.add(mid, difference),
        Physics.constraintCompensationStrength
      );
    }

    if (!this.two.fixed) {
      this.two.posAdjustments.push(Vector2.sub(mid, difference));
      this.two.pos = Vector2.lerp(
        this.two.pos,
        Vector2.sub(mid, difference),
        Physics.constraintCompensationStrength
      );
    }
  };
  Physics.Constraint.prototype.draw = function() {
    ctx.beginPath();
    ctx.strokeStyle = "#000";
    ctx.lineWidth = 5;
    ctx.moveTo(this.one.pos.x, this.one.pos.y);
    ctx.lineTo(this.two.pos.x, this.two.pos.y);
    ctx.stroke();
  };
  Physics.Constraint.prototype.display = function() {
    if (this.update) {
      this.update();
    }
    this.draw();
  };
}
{'fraction_non_alphanumeric': 0.16154059296203935, 'fraction_numerical': 0.015516763646439457, 'mean_word_length': 3.2823250296559907, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1072730', 'n_tokens_mistral': 1290, 'n_tokens_neox': 1254, 'n_words': 171}