-
Notifications
You must be signed in to change notification settings - Fork 14
/
polygon.js
executable file
·65 lines (56 loc) · 1.29 KB
/
polygon.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
function Polygon(number){
// resolution : 0.1
// method
function push(x, y, off){ // void
var temp = new Object();
temp.x = Math.floor(x*10)/10;
temp.y = Math.floor(y*10)/10;
if(off != 1){
off = 0;
}
temp.off = off;
this.array.push(temp);
}
Polygon.prototype.push = push;
function set(index, x, y, off){ // void
this.array[index].x = Math.floor(x*10)/10;
this.array[index].y = Math.floor(y*10)/10;
if(off != 1){
off = 0;
}
this.array[index].off = off;
}
Polygon.prototype.set = set;
function reverse(){ // void
this.array.reverse();
}
Polygon.prototype.reverse = reverse;
function concat(poly){ // void
this.array = this.array.concat(poly.array);
}
Polygon.prototype.concat = concat;
function shift(){ // void
this.array.shift();
}
Polygon.prototype.shift = shift;
function unshift(x, y, off){ // void
var temp = new Object();
temp.x = Math.floor(x*10)/10;
temp.y = Math.floor(y*10)/10;
if(off != 1){
off = 0;
}
temp.off = off;
this.array.unshift(temp);
}
Polygon.prototype.unshift = unshift;
// property
this.array = new Array();
// initialize
if(number){
for(var i = 0; i < number; i++){
this.push(0, 0, 0);
}
}
return this;
}