{"size": 913, "ext": "js", "max_stars_repo_path": "src/circleCircle.js", "max_stars_repo_name": "beeglebug/gm2-collision", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/circleCircle.js", "max_issues_repo_name": "beeglebug/gm2-collision", "max_issues_repo_issues_event_min_datetime": "2015-05-02T21:26:59.000Z", "max_issues_repo_issues_event_max_datetime": "2015-05-04T19:16:48.000Z", "max_forks_repo_path": "src/circleCircle.js", "max_forks_repo_name": "beeglebug/gm2-collision", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 24.6756756757, "max_line_length": 70, "alphanum_fraction": 0.5815991238}
var closestPointCircle = require('./closestPointCircle');
var Vector2 = require('gm2-vector2');

// temp vector
var _v1 = new Vector2();

/**
 * Check collision between two Circles
 * @param  {[type]} c1       [description]
 * @param  {[type]} c2       [description]
 * @param  {[type]} response [description]
 * @return {[type]}          [description]
 */
module.exports = function (c1, c2, response) {

    var dx = c1.position.x - c2.position.x;
    var dy = c1.position.y - c2.position.y;
    var dr = c1.radius + c2.radius;

    var distance = (dx * dx) + (dy * dy);

    if(distance < (dr * dr)) {

        if(response) {

            var near = closestPointCircle(c1.position, c2);

            response.point.set(near);
            response.normal.set(distance).normalize();
            response.depth = c1.radius - c1.position.distanceTo(near);
        }

        return true;
    }

    return false;
};