Added a function to clear data of polygons array.
[chise/kage.git] / engine / polygon.js
1 function Polygon(number){\r
2   // resolution : 0.1\r
3   \r
4   // method\r
5   function push(x, y){ // void\r
6     var temp = new Object();\r
7     temp.x = Math.floor(x*10)/10;\r
8     temp.y = Math.floor(y*10)/10;\r
9     this.array.push(temp);\r
10   }\r
11   Polygon.prototype.push = push;\r
12   \r
13   function set(index, x, y){ // void\r
14     this.array[index].x = Math.floor(x*10)/10;\r
15     this.array[index].y = Math.floor(y*10)/10;\r
16   }\r
17   Polygon.prototype.set = set;\r
18   \r
19   function reverse(){ // void\r
20     this.array.reverse();\r
21   }\r
22   Polygon.prototype.reverse = reverse;\r
23   \r
24   function concat(poly){ // void\r
25     this.array = this.array.concat(poly.array);\r
26   }\r
27   Polygon.prototype.concat = concat;\r
28         \r
29   function shift(){ // void\r
30     this.array.shift();\r
31   }\r
32   Polygon.prototype.shift = shift;\r
33         \r
34   function unshift(x, y){ // void\r
35     var temp = new Object();\r
36     temp.x = Math.floor(x*10)/10;\r
37     temp.y = Math.floor(y*10)/10;\r
38     this.array.unshift(temp);\r
39   }\r
40   Polygon.prototype.unshift = unshift;\r
41         \r
42   // property\r
43   this.array = new Array();\r
44   \r
45   // initialize\r
46   if(number){\r
47     for(var i = 0; i < number; i++){\r
48       this.push(0, 0);\r
49     }\r
50   }\r
51   \r
52   return this;\r
53 }\r