-
Notifications
You must be signed in to change notification settings - Fork 2
/
polygon.js
executable file
·95 lines (95 loc) · 2.46 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
export class Polygon{
// resolution : 0.0001
constructor(number){
this.array = new Array();
// initialize
if(number){
for(var i = 0; i < number; i++){
this.push(0, 0, 0);
}
}
}
push(x, y, off){ // void
var temp = new Object();
temp.x = x;
temp.y = y;
if(off != 1 && off != 2){
off = 0;
}
temp.off = off;
this.array.push(temp);
}
push2(p, off){
let [x, y] = p;
this.push(x, y, off);
}
set(index, x, y, off){ // void
this.array[index].x = x;
this.array[index].y = y;
if(off != 1 && off != 2){
off = 0;
}
this.array[index].off = off;
}
to_font1000(){
for(var j = 0; j < this.array.length; j++){
this.array[j].x = this.array[j].x*5;
this.array[j].y = this.array[j].y*-5 - 200;
}
}
reverse(){ // void
this.array.reverse();
}
concat(poly){ // void
this.array = this.array.concat(poly.array);
}
shift(){ // void
this.array.shift();
}
unshift(x, y, off){ // void
var temp = new Object();
temp.x = x;
temp.y = y;
if(off != 1 && off != 2){
off = 0;
}
temp.off = off;
this.array.unshift(temp);
}
get_sub_path_svg(){
let buffer = "";
buffer += "M";
buffer += this.array[0].x + "," + this.array[0].y + " ";
let mode = "";
for(var j = 1; j < this.array.length; j++){
if(this.array[j].off == 1 && mode != "Q"){
buffer += "Q"; mode = "Q";
} else if(this.array[j-1].off == 0 && this.array[j].off == 2 && mode != "C"){
buffer += "C"; mode = "C";
} else if(this.array[j-1].off == 0 && this.array[j].off == 0 && mode != "L"){
buffer += "L"; mode = "L";
}
buffer += this.array[j].x + "," + this.array[j].y + " ";
}
buffer += "Z";
return buffer;
}
get_sub_path_svg_font(){
let buffer = "";
buffer += "M";
buffer += (this.array[0].x*5.250 - 25) + "," + (916 - this.array[0].y*5.250) + " ";
let mode = "";
for(var j = 1; j < this.array.length; j++){
if(this.array[j].off == 1 && mode != "Q"){
buffer += "Q"; mode = "Q";
} else if(this.array[j-1].off == 0 && this.array[j].off == 2 && mode != "C"){
buffer += "C"; mode = "C";
} else if(this.array[j-1].off == 0 && this.array[j].off == 0 && mode != "L"){
buffer += "L"; mode = "L";
}
buffer += (this.array[j].x*5.250 - 25) + "," + (916 - this.array[j].y*5.250) + " ";
}
buffer += "Z";
return buffer;
}
}