Skip to content

Commit 8dae244

Browse files
committed
Added all the Circle functions.
1 parent 8c13257 commit 8dae244

22 files changed

Lines changed: 218 additions & 4 deletions

v3/src/geom/circle/Area.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var Area = function (circle)
2+
{
3+
return (circle.radius > 0) ? Math.PI * circle.radius * circle.radius : 0;
4+
};
5+
6+
module.exports = Area;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var Circumference = function (circle)
2+
{
3+
return 2 * (Math.PI * circle.radius);
4+
};
5+
6+
module.exports = Circumference;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Returns a Point object containing the coordinates of a point on the circumference of the Circle based on the given angle.
3+
* @method Phaser.Circle.circumferencePoint
4+
* @param {Phaser.Circle} a - The first Circle object.
5+
* @param {number} angle - The angle in radians (unless asDegrees is true) to return the point from.
6+
* @param {Phaser.Point} [out] - An optional Point object to put the result in to. If none specified a new Point object will be created.
7+
* @return {Phaser.Point} The Point object holding the result.
8+
*/
9+
var CircumferencePoint = function (circle, angle, out)
10+
{
11+
if (out === undefined) { out = { x: 0, y: 0 }; }
12+
13+
out.x = circle.x + (circle.radius * Math.cos(angle));
14+
out.y = circle.y + (circle.radius * Math.sin(angle));
15+
16+
return out;
17+
};
18+
19+
module.exports = CircumferencePoint;

v3/src/geom/circle/Clone.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var Circle = require('./Circle');
2+
3+
var Clone = function (source)
4+
{
5+
return new Circle(source.x, source.y, source.radius);
6+
};
7+
8+
module.exports = Clone;

v3/src/geom/circle/Contains.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var Contains = function (circle, x, y)
2+
{
3+
// Check if x/y are within the bounds first
4+
if (circle.radius > 0 && x >= circle.left && x <= circle.right && y >= circle.top && y <= circle.bottom)
5+
{
6+
var dx = (circle.x - x) * (circle.x - x);
7+
var dy = (circle.y - y) * (circle.y - y);
8+
9+
return (dx + dy) <= (circle.radius * circle.radius);
10+
}
11+
else
12+
{
13+
return false;
14+
}
15+
};
16+
17+
module.exports = Contains;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var Contains = require('./Contains');
2+
3+
var ContainsPoint = function (circle, point)
4+
{
5+
return Contains(circle, point.x, point.y);
6+
};
7+
8+
module.exports = ContainsPoint;

v3/src/geom/circle/ContainsRect.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var Contains = require('./Contains');
2+
3+
var ContainsRect = function (circle, rect)
4+
{
5+
return (
6+
Contains(circle, rect.x, rect.y) &&
7+
Contains(circle, rect.right, rect.y) &&
8+
Contains(circle, rect.x, rect.bottom) &&
9+
Contains(circle, rect.right, rect.bottom)
10+
);
11+
};
12+
13+
module.exports = ContainsRect;

v3/src/geom/circle/CopyFrom.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Copies the x, y and diameter properties from any given object to this Circle.
3+
* @method Phaser.Circle#copyFrom
4+
* @param {any} source - The object to copy from.
5+
* @return {Circle} This Circle object.
6+
*/
7+
var CopyFrom = function (source, dest)
8+
{
9+
return dest.setTo(source.x, source.y, source.radius);
10+
};
11+
12+
module.exports = CopyFrom;

v3/src/geom/circle/Equals.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var Equals = function (circle, toCompare)
2+
{
3+
return (
4+
circle.x === toCompare.x &&
5+
circle.y === toCompare.y &&
6+
circle.radius === toCompare.radius
7+
);
8+
};
9+
10+
module.exports = Equals;

v3/src/geom/circle/GetBounds.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var Rectangle = require('../rectangle/Rectangle');
2+
3+
var GetBounds = function (circle, out)
4+
{
5+
if (out === undefined) { out = new Rectangle(); }
6+
7+
out.x = circle.left;
8+
out.y = circle.top;
9+
out.width = circle.diameter;
10+
out.height = circle.diameter;
11+
12+
return out;
13+
};
14+
15+
module.exports = GetBounds;

0 commit comments

Comments
 (0)