<commit_before>class TrackPen {
  constructor(){
    this.activePath = undefined;
    this.paths = [];
    this.initTool();
  }

  initTool(){
    this.tool = new paper.Tool();

    // This appears to be necesary because the paper.Tool is not
    // a ES6 Class, but rather a function which returns an object
    // and so can't use ' extend paper.Tool'
    this.tool.onMouseDown = this.onMouseDown.bind(this);
    this.tool.onMouseDrag = this.onMouseDrag.bind(this);
    this.tool.onKeyDown = this.onKeyDown.bind(this);
  }

  onMouseDown(event){
    this.activePath = new paper.Path();
    this.activePath.strokeColor = 'black';
    this.activePath.add(event.point);
    this.paths.push(this.activePath);
  }

  onMouseDrag(event){
    this.activePath.add(event.point);
  }

  onKeyDown(event){
    console.log('The ' + event.key + ' key was pressed!');

    if (event.key == 'backspace') {
      this.clearPaths();
    }
  }

  clearPaths(){
    this.paths.forEach(p => p.remove());
    this.paths = [];
  }
}
<commit_msg>paperjs/race-track - Refine drawing after lifting mouse<commit_after>class TrackPen {
  constructor(){
    this.activePath = undefined;
    this.paths = [];
    this.initTool();
  }

  initTool(){
    this.tool = new paper.Tool();
    this.tool.minDistance = 40;

    // This appears to be necesary because the paper.Tool is not
    // a ES6 Class, but rather a function which returns an object
    // and so can't use ' extend paper.Tool'
    this.tool.onMouseDown = this.onMouseDown.bind(this);
    this.tool.onMouseDrag = this.onMouseDrag.bind(this);
    this.tool.onMouseUp = this.onMouseUp.bind(this);
    this.tool.onKeyDown = this.onKeyDown.bind(this);
  }

  onMouseDown(event){
    this.activePath = new paper.Path();
    this.activePath.strokeColor = 'black';
    this.activePath.add(event.point);
    this.paths.push(this.activePath);
  }

  onMouseDrag(event){
    this.activePath.add(event.point);
    this.activePath.smooth();
  }

  onMouseUp(event){
    this.activePath.closed = true;
    this.activePath.smooth();
    this.activePath.flatten();
    this.activePath.simplify();
  }

  onKeyDown(event){
    console.log('The ' + event.key + ' key was pressed!');

    if (event.key == 'backspace') {
      this.clearPaths();
    } else if (event.key == 's'){
      this.activePath.simplify();
    } else if (event.key == 'm'){
      this.activePath.smooth();
    } else if (event.key == 'f'){
      this.activePath.flatten(1);
    }
  }

  clearPaths(){
    this.paths.forEach(p => p.remove());
    this.paths = [];
  }
}

{'fraction_non_alphanumeric': 0.1526151444184231, 'fraction_numerical': 0.00195160031225605, 'mean_word_length': 2.8951367781155017, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4878205', 'n_tokens_mistral': 878, 'n_tokens_neox': 852, 'n_words': 167}