phaser/v3/src/geom/circle/Circle.js

146 lines
2.2 KiB
JavaScript
Raw Normal View History

var Class = require('../../utils/Class');
var Random = require('./Random');
2016-12-28 23:40:47 +00:00
var Circle = new Class({
2016-12-28 23:40:47 +00:00
initialize:
2016-12-28 23:40:47 +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
this.x = x;
2016-12-28 23:40:47 +00:00
this.y = y;
this._radius = radius;
this._diameter = radius * 2;
},
2016-12-28 23:40:47 +00:00
getRandomPoint: function (point)
{
return Random(this, point);
},
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;
},
setEmpty: function ()
{
return this.setTo(0, 0, 0);
},
setPosition: function (x, y)
{
if (y === undefined) { y = x; }
this.x = x;
this.y = y;
return this;
},
isEmpty: function ()
{
return (this._radius <= 0);
},
2016-12-28 23:40:47 +00:00
radius: {
get: function ()
{
return this._radius;
},
set: function (value)
{
this._radius = value;
this._diameter = value * 2;
}
},
diameter: {
get: function ()
{
return this._diameter;
},
set: function (value)
{
this._diameter = value;
this._radius = value * 0.5;
}
},
left: {
get: function ()
{
return this.x - this._radius;
},
set: function (value)
{
this.x = value + this._radius;
}
},
right: {
get: function ()
{
return this.x + this._radius;
},
set: function (value)
{
this.x = value - this._radius;
}
},
top: {
get: function ()
{
return this.y - this._radius;
},
set: function (value)
{
this.y = value + this._radius;
}
},
bottom: {
get: function ()
{
return this.y + this._radius;
},
set: function (value)
{
this.y = value - this._radius;
}
}
});
module.exports = Circle;