{"size": 786, "ext": "js", "max_stars_repo_path": "flows/update-soul.js", "max_stars_repo_name": "jimkang/crowd", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "flows/update-soul.js", "max_issues_repo_name": "jimkang/crowd", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "flows/update-soul.js", "max_forks_repo_name": "jimkang/crowd", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 30.2307692308, "max_line_length": 74, "alphanum_fraction": 0.6730279898}
var findWhere = require('../findwhere');

function updateSoul(grids, targetTree, soul) {
  // Update position properties.
  var grid = findWhere(grids, { id: soul.grid.id });
  if (!grid) {
    console.log('Could not find grid', soul.grid.id, 'for', soul.id, '!');
    return;
  }

  var intersection = grid.rows[soul.grid.rowOnGrid][soul.grid.colOnGrid];
  soul.x = intersection.x;
  soul.y = intersection.y;
  soul.minX = soul.x - soul.sprite.width / 2;
  soul.maxX = soul.x + soul.sprite.width / 2;
  soul.minY = soul.y - soul.sprite.height / 2;
  soul.maxY = soul.y + soul.sprite.height / 2;

  // Update it the search tree.
  // Someday always removing and inserting may be a performance issue?
  targetTree.remove(soul);
  targetTree.insert(soul);
}

module.exports = updateSoul;
