<commit_before>(function( globals ) {
  var Sprite = function( element, options ) {
    options = U.default_param( options, {} );

    // initialize it with an element
    this.element = element;
    this.message_bus = undefined;

    this.x = U.default_param( options.x, 0 );
    this.y = U.default_param( options.y, 0 );

    //velocities
    this.velocity_x = U.default_param( options.velocity_x, 0 );
    this.velocity_y = U.default_param( options.velocity_y, 0 );

    // tags:
    this.tags = {};
    var tags = U.default_param( options.tags, [] ),
        tag = null;

    for ( tag in tags ) {
      tag = tags[tag];
      this.addTag( tag );
    }

    // set this to true to have the element rotate
    this.use_rotation = U.default_param( options.use_rotation, false );

    // the angle to rotate the sprite when use_rotation is false
    this.rotation = 0;

    this.timestamp = Date.now(); // a timestamp of when it was created

    this.dead = false;

    this.move(); // force it to the right locaion
  }

  // return true if this sprite has the given tag
  Sprite.prototype.hasTag = function( tag ) {
    return typeof this.tags[tag] !== 'undefined';
  };

  // add a tag to this sprite, but only if it doesn't already have one
  // return this to enable chaining.
  Sprite.prototype.addTag = function( tag ) {
    this.tags[tag] = 1;

    if ( typeof this.message_bus !== 'undefined' ) {
      this.message_bus.publish( 'sprite_tag_added', { sprite: this, tag: tag } );
    }

    return this;
  }

  // remove the given tag
  // return this to enable chaining.
  Sprite.prototype.removeTag = function( tag ) {
    delete this.tags[tag];

    if ( typeof this.message_bus !== 'undefined' ) {
      this.message_bus.publish( 'sprite_tag_removed', { sprite: this, tag: tag } );
    }

    return this;
  }

  Sprite.prototype.coordinates = function( offset ) {
    var w = this.element.offsetWidth,
        h = this.element.offsetHeight;

    if ( typeof offset === 'undefined' ) {
      offset = 0;
    }

    return {
      x1: this.x + offset,
      y1: this.y + offset,
      x2: this.x + w - offset,
      y2: this.y + h - offset,
      width: w - offset * 2,
      height: h - offset * 2
    }
  }

  Sprite.prototype.isOverlapping = function( other_sprite, offset ) {
    var a = this.coordinates( offset ),
        b = other_sprite.coordinates( offset );

    return a.x1 < b.x2
      && a.x2 > b.x1
      && a.y1 < b.y2
      && a.y2 > b.y1;
  }

  // move this object to the given x,y coordinates
  Sprite.prototype.move_to = function( x, y, delay_move ) {<commit_msg>optimized Sprite.coordinates()<commit_after>(function( globals ) {
  var Sprite = function( element, options ) {
    options = U.default_param( options, {} );

    // initialize it with an element
    this.element = element;
    this.message_bus = undefined;

    this.x = U.default_param( options.x, 0 );
    this.y = U.default_param( options.y, 0 );

    // need to use setTimeout here because offsetWidth/Height
    // returns 0. using setTimeout(0) will allow time to update the DOM
    // and offsetWidth/Height will return correct values
    setTimeout(function() {
      this.width = this.element.offsetWidth;
      this.height = this.element.offsetHeight;
    }.bind(this), 0);

    //velocities
    this.velocity_x = U.default_param( options.velocity_x, 0 );
    this.velocity_y = U.default_param( options.velocity_y, 0 );

    // tags:
    this.tags = {};
    var tags = U.default_param( options.tags, [] ),
        tag = null;

    for ( tag in tags ) {
      tag = tags[tag];
      this.addTag( tag );
    }

    // set this to true to have the element rotate
    this.use_rotation = U.default_param( options.use_rotation, false );

    // the angle to rotate the sprite when use_rotation is false
    this.rotation = 0;

    this.timestamp = Date.now(); // a timestamp of when it was created

    this.dead = false;

    this.move(); // force it to the right locaion
  }

  // return true if this sprite has the given tag
  Sprite.prototype.hasTag = function( tag ) {
    return typeof this.tags[tag] !== 'undefined';
  };

  // add a tag to this sprite, but only if it doesn't already have one
  // return this to enable chaining.
  Sprite.prototype.addTag = function( tag ) {
    this.tags[tag] = 1;

    if ( typeof this.message_bus !== 'undefined' ) {
      this.message_bus.publish( 'sprite_tag_added', { sprite: this, tag: tag } );
    }

    return this;
  }

  // remove the given tag
  // return this to enable chaining.
  Sprite.prototype.removeTag = function( tag ) {
    delete this.tags[tag];

    if ( typeof this.message_bus !== 'undefined' ) {
      this.message_bus.publish( 'sprite_tag_removed', { sprite: this, tag: tag } );
    }

    return this;
  }

  Sprite.prototype.coordinates = function( offset ) {
    if ( typeof offset === 'undefined' ) {
      offset = 0;
    }

    return {
      x1: this.x + offset,
      y1: this.y + offset,
      x2: this.x + this.width - offset,
      y2: this.y + this.height - offset,
      width: this.width - offset * 2,
      height: this.height - offset * 2
    }
  }

  Sprite.prototype.isOverlapping = function( other_sprite, offset ) {
    var a = this.coordinates( offset ),
        b = other_sprite.coordinates( offset );

    return a.x1 < b.x2
      && a.x2 > b.x1
      && a.y1 < b.y2
      && a.y2 > b.y1;
  }

  // move this object to the given x,y coordinates
  Sprite.prototype.move_to = function( x, y, delay_move ) {
{'fraction_non_alphanumeric': 0.12529550827423167, 'fraction_numerical': 0.008183306055646482, 'mean_word_length': 2.3887861983980283, 'pattern_counts': {'":': 0, '<': 7, '<?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': '288172', 'n_tokens_mistral': 1847, 'n_tokens_neox': 1760, 'n_words': 513}