function Polygons(){\r
// method\r
function push(polygon){ // void\r
- this.array.push(polygon);\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
+ }\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
buffer += "<svg 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 += "<polyline points=\"";\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 += this.array[i].array[0].x + "," + this.array[i].array[0].y + " ";\r
buffer += "\" />\n";\r
}\r
buffer += "</g>\n";\r