Skip to content

Commit d0eab7a

Browse files
committed
Added Ellipse.circumferencePoint
1 parent f621f4a commit d0eab7a

1 file changed

Lines changed: 30 additions & 5 deletions

File tree

src/geom/Ellipse.js

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
* @param {number} [width=0] - The overall width of this ellipse.
1616
* @param {number} [height=0] - The overall height of this ellipse.
1717
*/
18-
Phaser.Ellipse = function (x, y, width, height) {
19-
18+
Phaser.Ellipse = function (x, y, width, height)
19+
{
2020
x = x || 0;
2121
y = y || 0;
2222
width = width || 0;
@@ -176,6 +176,30 @@ Phaser.Ellipse.prototype = {
176176

177177
},
178178

179+
/**
180+
* Returns a Point object containing the coordinates of a point on the circumference of the ellipse based on the given angle.
181+
*
182+
* @method Phaser.Ellipse#circumferencePoint
183+
* @param {number} angle - The angle in radians (unless asDegrees is true) to return the point from.
184+
* @param {boolean} [asDegrees=false] - Is the given angle in radians (false) or degrees (true)?
185+
* @param {Phaser.Point} [out] - An optional Point object to put the result in to. If none specified a new Point object will be created.
186+
* @return {Phaser.Point} The Point object holding the result.
187+
*/
188+
circumferencePoint: function (angle, asDegrees, out)
189+
{
190+
if (out === undefined) { out = new Phaser.Point(); }
191+
192+
if (asDegrees)
193+
{
194+
angle = Phaser.Math.degToRad(angle);
195+
}
196+
197+
out.x = this.x + (this.width * Math.cos(angle));
198+
out.y = this.y + (this.height * Math.sin(angle));
199+
200+
return out;
201+
},
202+
179203
/**
180204
* Returns a string representation of this object.
181205
* @method Phaser.Ellipse#toString
@@ -305,9 +329,10 @@ Object.defineProperty(Phaser.Ellipse.prototype, "empty", {
305329
* @param {number} y - The Y value of the coordinate to test.
306330
* @return {boolean} True if the coordinates are within this ellipse, otherwise false.
307331
*/
308-
Phaser.Ellipse.contains = function (a, x, y) {
309-
310-
if (a.width <= 0 || a.height <= 0) {
332+
Phaser.Ellipse.contains = function (a, x, y)
333+
{
334+
if (a.width <= 0 || a.height <= 0)
335+
{
311336
return false;
312337
}
313338

0 commit comments

Comments
 (0)