2017-06-30 14:47:51 +00:00
|
|
|
var Class = require('../../utils/Class');
|
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-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-06-30 14:47:51 +00:00
|
|
|
this.x = x;
|
2016-12-28 23:40:47 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
this.y = y;
|
|
|
|
|
|
|
|
this._radius = radius;
|
|
|
|
this._diameter = radius * 2;
|
|
|
|
},
|
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;
|
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
|
|
|
|
|
|
|
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;
|