Skip to content

Commit

Permalink
Added optimised point in circle test to CircleUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
photonstorm committed Jul 27, 2013
1 parent d80467a commit 3038f6f
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 6 deletions.
Binary file added Docs/logo/phaser space paint 08.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 11 additions & 2 deletions Phaser/utils/CircleUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,17 @@ module Phaser {
* @return {Boolean} True if the coordinates are within this circle, otherwise false.
**/
static contains(a: Circle, x: number, y: number): bool {
//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: number = (a.x - x) * (a.x - x);
var dy: number = (a.y - y) * (a.y - y);
return (dx + dy) <= (a.radius * a.radius);
}

return false;

}

/**
Expand Down
8 changes: 8 additions & 0 deletions Phaser/utils/DebugUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ module Phaser {

}

static renderCircle(circle: Phaser.Circle, fillStyle: string = 'rgba(0,255,0,0.3)') {

DebugUtils.context.fillStyle = fillStyle;
DebugUtils.context.arc(circle.x, circle.y, circle.radius, 0, Math.PI * 2, false);
DebugUtils.context.fill();

}

static renderPhysicsBody(body: Phaser.Physics.Body, lineWidth: number = 1, fillStyle: string = 'rgba(0,255,0,0.2)', sleepStyle: string = 'rgba(100,100,100,0.2)') {

for (var s = 0; s < body.shapesLength; s++)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ TODO:
* Stage CSS3 Transforms?
* Ability to layer another DOM object and have it controlled by the game somehow. Can then do stacked canvas effects.
* Stage lost to mute
* When game is paused Pointer shouldn't process targetObjects / change cursor



Expand Down Expand Up @@ -157,6 +158,7 @@ V1.0.0
* Dropped the StageScaleMode.setScreenSize iterations count from 40 down to 10 and document min body height to 2000px.
* Added Phaser.Net for browser and network specific functions, currently includes query string parsing and updating methods.
* Added a new CSS3 Filters component. Apply blur, grayscale, sepia, brightness, contrast, hue rotation, invert, opacity and saturate filters to the games stage.
* Fixed the CircleUtils.contains and containsPoint methods



Expand Down
14 changes: 12 additions & 2 deletions Tests/phaser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 12 additions & 2 deletions build/phaser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 3038f6f

Please sign in to comment.