function Polygons(){\r
- // method\r
- function push(polygon){ // void\r
- // only a simple check\r
- var minx = 200;\r
- var maxx = 0;\r
- var miny = 200;\r
- var maxy = 0;\r
- for(var i = 0; i < polygon.array.length; i++){\r
- if(polygon.array[i].x < minx){\r
- minx = polygon.array[i].x;\r
- }\r
- if(polygon.array[i].x > maxx){\r
- maxx = polygon.array[i].x;\r
- }\r
- if(polygon.array[i].y < miny){\r
- miny = polygon.array[i].y;\r
- }\r
- if(polygon.array[i].y > maxy){\r
- maxy = polygon.array[i].y;\r
- }\r
+ // method\r
+ function push(polygon){ // void\r
+ // only a simple check\r
+ var minx = 200;\r
+ var maxx = 0;\r
+ var miny = 200;\r
+ var maxy = 0;\r
+ var error = 0;\r
+ for(var i = 0; i < polygon.array.length; i++){\r
+ if(polygon.array[i].x < minx){\r
+ minx = polygon.array[i].x;\r
+ }\r
+ if(polygon.array[i].x > maxx){\r
+ maxx = polygon.array[i].x;\r
+ }\r
+ if(polygon.array[i].y < miny){\r
+ miny = polygon.array[i].y;\r
+ }\r
+ if(polygon.array[i].y > maxy){\r
+ maxy = polygon.array[i].y;\r
+ }\r
+ if(isNaN(polygon.array[i].x) || isNaN(polygon.array[i].y)){\r
+ error++;\r
+ }\r
+ }\r
+ if(error == 0 && minx != maxx && miny != maxy && polygon.array.length >= 3){\r
+ var newArray = new Array();\r
+ newArray.push(polygon.array.shift());\r
+ while(polygon.array.length != 0){\r
+ var temp = polygon.array.shift();\r
+ if(newArray[newArray.length - 1].x != temp.x ||\r
+ newArray[newArray.length - 1].y != temp.y){\r
+ newArray.push(temp);\r
+ }\r
+ }\r
+ if(newArray.length >= 3){\r
+ polygon.array = newArray;\r
+ this.array.push(polygon);\r
+ }\r
+ }\r
+ }\r
+ Polygons.prototype.push = push;\r
+ \r
+ function generateSVG(){ // string\r
+ var buffer = "";\r
+ buffer += "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" version=\"1.1\" baseProfile=\"full\" viewBox=\"0 0 199 199\">\n";\r
+ buffer += "<g fill=\"black\">\n";\r
+ for(var i = 0; i < this.array.length; i++){\r
+ buffer += "<polygon points=\"";\r
+ for(var j = 0; j < this.array[i].array.length; j++){\r
+ buffer += this.array[i].array[j].x + "," + this.array[i].array[j].y + " ";\r
+ }\r
+ buffer += "\" />\n";\r
+ }\r
+ buffer += "</g>\n";\r
+ buffer += "</svg>\n";\r
+ return buffer;\r
+ }\r
+ Polygons.prototype.generateSVG = generateSVG;\r
+ \r
+ function generateEPS(){ // string\r
+ var buffer = "";\r
+ buffer += "%!PS-Adobe-3.0 EPSF-3.0\n";\r
+ buffer += "%%BoundingBox: 0 -208 1024 816\n";\r
+ buffer += "%%Pages: 0\n";\r
+ buffer += "%%Title: Kanji glyph\n";\r
+ buffer += "%%Creator: GlyphWiki powered by KAGE system\n";\r
+ buffer += "%%CreationDate: " + new Date() + "\n";\r
+ buffer += "%%EndComments\n";\r
+ buffer += "%%EndProlog\n";\r
+ buffer += "newpath\n";\r
+ \r
+ for(var i = 0; i < this.array.length; i++){\r
+ for(var j = 0; j < this.array[i].array.length; j++){\r
+ buffer += (this.array[i].array[j].x * 5) + " " + (1000 - this.array[i].array[j].y * 5 - 200) + " ";\r
+ if(j == 0){\r
+ buffer += "moveto\n";\r
+ } else {\r
+ buffer += "lineto\n";\r
+ }\r
+ }\r
+ buffer += "closepath\n";\r
+ }\r
+ buffer += "fill\n";\r
+ buffer += "%%EOF\n";\r
+ return buffer;\r
}\r
- if(minx != maxx && miny != maxy && polygon.array.length >= 3){\r
- var newArray = new Array();\r
- newArray.push(polygon.array.shift());\r
- while(polygon.array.length != 0){\r
- var temp = polygon.array.shift();\r
- if(newArray[newArray.length - 1].x != temp.x ||\r
- newArray[newArray.length - 1].y != temp.y){\r
- newArray.push(temp);\r
- }\r
- }\r
- if(newArray.length >= 3){\r
- polygon.array = newArray;\r
- this.array.push(polygon);\r
- }\r
- }\r
- }\r
- Polygons.prototype.push = push;\r
- \r
- function generateSVG(){ // string\r
- var buffer = "";\r
- buffer += "<?xml version=\"1.0\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n";\r
- buffer += "<svg width=\"200\" height=\"200\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" version=\"1.1\" baseProfile=\"full\">\n";\r
- buffer += "<g fill=\"black\">\n";\r
- for(var i = 0; i < this.array.length; i++){\r
- buffer += "<polygon points=\"";\r
- for(var j = 0; j < this.array[i].array.length; j++){\r
- buffer += this.array[i].array[j].x + "," + this.array[i].array[j].y + " ";\r
- }\r
- buffer += "\" />\n";\r
- }\r
- buffer += "</g>\n";\r
- buffer += "</svg>\n";\r
- return buffer;\r
- }\r
- Polygons.prototype.generateSVG = generateSVG;\r
- \r
- // property\r
- this.array = new Array();\r
- \r
- return this;\r
+ Polygons.prototype.generateEPS = generateEPS;\r
+ \r
+ // property\r
+ this.array = new Array();\r
+ \r
+ return this;\r
}\r