Skip to content

Commit ecffffc

Browse files
committed
Added Circle class.
1 parent f49a229 commit ecffffc

1 file changed

Lines changed: 148 additions & 0 deletions

File tree

v3/src/geom/circle/Circle.js

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
var Circle = function (x, y, radius)
2+
{
3+
if (x === undefined) { x = 0; }
4+
if (y === undefined) { y = 0; }
5+
if (radius === undefined) { radius = 0; }
6+
7+
this.x = x;
8+
9+
this.y = y;
10+
11+
this._radius = radius;
12+
this._diameter = radius * 2;
13+
};
14+
15+
Circle.prototype.constructor = Circle;
16+
17+
Circle.prototype = {
18+
19+
setTo: function (x, y, radius)
20+
{
21+
this.x = x;
22+
this.y = y;
23+
this._radius = radius;
24+
this._diameter = radius * 2;
25+
26+
return this;
27+
},
28+
29+
setEmpty: function ()
30+
{
31+
return this.setTo(0, 0, 0);
32+
},
33+
34+
setPosition: function (x, y)
35+
{
36+
if (y === undefined) { y = x; }
37+
38+
this.x = x;
39+
this.y = y;
40+
41+
return this;
42+
}
43+
44+
};
45+
46+
Object.defineProperties(Circle.prototype, {
47+
48+
radius: {
49+
50+
enumerable: true,
51+
52+
get: function ()
53+
{
54+
return this._radius;
55+
},
56+
57+
set: function (value)
58+
{
59+
this._radius = value;
60+
this._diameter = value * 2;
61+
}
62+
63+
},
64+
65+
diameter: {
66+
67+
enumerable: true,
68+
69+
get: function ()
70+
{
71+
return this._diameter;
72+
},
73+
74+
set: function (value)
75+
{
76+
this._diameter = value;
77+
this._radius = value * 0.5;
78+
}
79+
80+
},
81+
82+
left: {
83+
84+
enumerable: true,
85+
86+
get: function ()
87+
{
88+
return this.x - this._radius;
89+
},
90+
91+
set: function (value)
92+
{
93+
this.x = value + this._radius;
94+
}
95+
96+
},
97+
98+
right: {
99+
100+
enumerable: true,
101+
102+
get: function ()
103+
{
104+
return this.x + this._radius;
105+
},
106+
107+
set: function (value)
108+
{
109+
this.x = value - this._radius;
110+
}
111+
112+
},
113+
114+
top: {
115+
116+
enumerable: true,
117+
118+
get: function ()
119+
{
120+
return this.y - this._radius;
121+
},
122+
123+
set: function (value)
124+
{
125+
this.y = value + this._radius;
126+
}
127+
128+
},
129+
130+
bottom: {
131+
132+
enumerable: true,
133+
134+
get: function ()
135+
{
136+
return this.y + this._radius;
137+
},
138+
139+
set: function (value)
140+
{
141+
this.y = value - this._radius;
142+
}
143+
144+
}
145+
146+
});
147+
148+
module.exports = Circle;

0 commit comments

Comments
 (0)