2017-06-30 14:47:51 +00:00
|
|
|
var Class = require('../../utils/Class');
|
2017-10-25 15:06:52 +00:00
|
|
|
var GetPoint = require('./GetPoint');
|
|
|
|
var GetPoints = require('./GetPoints');
|
2017-09-25 17:10:01 +00:00
|
|
|
var Random = require('./Random');
|
2016-12-28 23:40:47 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
var Circle = new Class({
|
2016-12-28 23:40:47 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
initialize:
|
2016-12-28 23:40:47 +00:00
|
|
|
|
2017-10-04 23:58:42 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @class Circle
|
|
|
|
* @memberOf Phaser.Geom
|
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {number} [x=0] - [description]
|
|
|
|
* @param {number} [y=0] - [description]
|
|
|
|
* @param {number} [radius=0] - [description]
|
|
|
|
*/
|
2017-06-30 14:47:51 +00:00
|
|
|
function Circle (x, y, radius)
|
|
|
|
{
|
|
|
|
if (x === undefined) { x = 0; }
|
|
|
|
if (y === undefined) { y = 0; }
|
|
|
|
if (radius === undefined) { radius = 0; }
|
2016-12-28 23:40:47 +00:00
|
|
|
|
2017-10-04 23:58:42 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @property {number} x
|
|
|
|
*/
|
2017-06-30 14:47:51 +00:00
|
|
|
this.x = x;
|
2016-12-28 23:40:47 +00:00
|
|
|
|
2017-10-04 23:58:42 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @property {number} y
|
|
|
|
*/
|
2017-06-30 14:47:51 +00:00
|
|
|
this.y = y;
|
|
|
|
|
2017-10-04 23:58:42 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @property {number} _radius
|
|
|
|
* @private
|
|
|
|
*/
|
2017-06-30 14:47:51 +00:00
|
|
|
this._radius = radius;
|
2017-10-04 23:58:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @property {number} _diameter
|
|
|
|
* @private
|
|
|
|
*/
|
2017-06-30 14:47:51 +00:00
|
|
|
this._diameter = radius * 2;
|
|
|
|
},
|
2016-12-28 23:40:47 +00:00
|
|
|
|
2017-10-25 15:06:52 +00:00
|
|
|
getPoint: function (position, point)
|
|
|
|
{
|
|
|
|
return GetPoint(this, position, point);
|
|
|
|
},
|
|
|
|
|
2017-10-26 15:37:00 +00:00
|
|
|
getPoints: function (quantity, stepRate, output)
|
2017-10-25 15:06:52 +00:00
|
|
|
{
|
2017-10-26 15:37:00 +00:00
|
|
|
return GetPoints(this, quantity, stepRate, output);
|
2017-10-25 15:06:52 +00:00
|
|
|
},
|
|
|
|
|
2017-10-04 23:58:42 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Geom.Circle#getRandomPoint
|
|
|
|
*
|
|
|
|
* @param {Phaser.Geom.Point|object} point - [description]
|
|
|
|
*
|
|
|
|
* @return {Phaser.Geom.Point|object} [description]
|
|
|
|
*/
|
2017-09-25 17:10:01 +00:00
|
|
|
getRandomPoint: function (point)
|
|
|
|
{
|
|
|
|
return Random(this, point);
|
|
|
|
},
|
|
|
|
|
2017-10-04 23:58:42 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Geom.Circle#setTo
|
|
|
|
*
|
|
|
|
* @param {number} x - [description]
|
|
|
|
* @param {number} y - [description]
|
|
|
|
* @param {number} radius - [description]
|
|
|
|
*
|
|
|
|
* @return {Phaser.Geom.Circle} [description]
|
|
|
|
*/
|
2016-12-28 23:40:47 +00:00
|
|
|
setTo: function (x, y, radius)
|
|
|
|
{
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
this._radius = radius;
|
|
|
|
this._diameter = radius * 2;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-10-04 23:58:42 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Geom.Circle#setEmpty
|
|
|
|
*
|
|
|
|
* @return {Phaser.Geom.Circle} [description]
|
|
|
|
*/
|
2016-12-28 23:40:47 +00:00
|
|
|
setEmpty: function ()
|
|
|
|
{
|
|
|
|
return this.setTo(0, 0, 0);
|
|
|
|
},
|
|
|
|
|
2017-10-04 23:58:42 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Geom.Circle#setPosition
|
|
|
|
*
|
|
|
|
* @param {number} x - [description]
|
|
|
|
* @param {number} [y=x] - [description]
|
|
|
|
*
|
|
|
|
* @return {Phaser.Geom.Circle} [description]
|
|
|
|
*/
|
2016-12-28 23:40:47 +00:00
|
|
|
setPosition: function (x, y)
|
|
|
|
{
|
|
|
|
if (y === undefined) { y = x; }
|
|
|
|
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
|
|
|
|
return this;
|
2017-01-01 14:33:41 +00:00
|
|
|
},
|
|
|
|
|
2017-10-04 23:58:42 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Geom.Circle#isEmpty
|
|
|
|
*
|
|
|
|
* @return {boolean} [description]
|
|
|
|
*/
|
2017-01-01 14:33:41 +00:00
|
|
|
isEmpty: function ()
|
|
|
|
{
|
|
|
|
return (this._radius <= 0);
|
2017-06-30 14:47:51 +00:00
|
|
|
},
|
2016-12-28 23:40:47 +00:00
|
|
|
|
2017-10-04 23:58:42 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @property {number} radius
|
|
|
|
*/
|
2016-12-28 23:40:47 +00:00
|
|
|
radius: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this._radius;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this._radius = value;
|
|
|
|
this._diameter = value * 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2017-10-04 23:58:42 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @property {number} diameter
|
|
|
|
*/
|
2016-12-28 23:40:47 +00:00
|
|
|
diameter: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this._diameter;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this._diameter = value;
|
|
|
|
this._radius = value * 0.5;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2017-10-04 23:58:42 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @property {number} left
|
|
|
|
*/
|
2016-12-28 23:40:47 +00:00
|
|
|
left: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.x - this._radius;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this.x = value + this._radius;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2017-10-04 23:58:42 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @property {number} right
|
|
|
|
*/
|
2016-12-28 23:40:47 +00:00
|
|
|
right: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.x + this._radius;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this.x = value - this._radius;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2017-10-04 23:58:42 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @property {number} top
|
|
|
|
*/
|
2016-12-28 23:40:47 +00:00
|
|
|
top: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.y - this._radius;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this.y = value + this._radius;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2017-10-04 23:58:42 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @property {number} bottom
|
|
|
|
*/
|
2016-12-28 23:40:47 +00:00
|
|
|
bottom: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.y + this._radius;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this.y = value - this._radius;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Circle;
|