Added optimised point in circle test to CircleUtils

This commit is contained in:
Richard Davey
2013-07-27 10:57:54 +01:00
parent d80467a08a
commit 3038f6fcf8
6 changed files with 45 additions and 6 deletions
+12 -2
View File
@@ -20758,8 +20758,18 @@ var Phaser;
* @return {Boolean} True if the coordinates are within this circle, otherwise false.
**/
function contains(a, x, y) {
//return (a.radius * a.radius >= Collision.distanceSquared(a.x, a.y, x, y));
return true;
// Check if x/y are within the bounds first
if(x >= a.left && x <= a.right && y >= a.top && y <= a.bottom) {
var dx = a.x - x;
var dy = a.y - y;
dx *= dx;
dy *= dy;
var radSqr = a.radius * a.radius;
console.log('within bounds', dx, dy, radSqr);
return (dx + dy) <= radSqr;
//return (a.left * a.left + a.top * a.top) <= (a.radius * a.radius);
}
return false;
};
CircleUtils.containsPoint = /**
* Return true if the coordinates of the given Point object are within this Circle object.