Skip to content

Instantly share code, notes, and snippets.

@ashblue
Created September 28, 2012 16:04
Show Gist options
  • Save ashblue/3800693 to your computer and use it in GitHub Desktop.
Save ashblue/3800693 to your computer and use it in GitHub Desktop.
Here's the circular radius test that we're doing upon mouse click. hitTest() is called for every entity upon click to determine a positive hit.
/**
* @author Kevin Moot
*/
Marker.prototype.hitTest = function(point) {
return Util.pointInCircle(point, this.positionCenter, this.radiusSquared);
};
Util.pointInCircle = function(point, circleCenter, circleRadiusSquared) {
// determine vector between center of circle and mouse position
var subX = circleCenter.x - point.x;
var subY = circleCenter.y - point.y;
var distance = Math.pow(subX, 2) + Math.pow(subY, 2);
return distance <= circleRadiusSquared;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment