X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=engine%2Fpolygons.js;h=a52305c79846ffc41cc4a24f6640b53b048553e4;hb=6ed7b81dd59d5a537577ede2c2eda60b4dfe0640;hp=fed54a1cef20a8c2c7f252f5a03b4fbc6170408d;hpb=897e6744d4d38368e2773dcda1212128a6491f60;p=chise%2Fkage.git diff --git a/engine/polygons.js b/engine/polygons.js index fed54a1..a52305c 100755 --- a/engine/polygons.js +++ b/engine/polygons.js @@ -1,38 +1,47 @@ function Polygons(){ // method + function clear(){ // void + this.array = new Array(); + } + Polygons.prototype.clear = clear; + function push(polygon){ // void // only a simple check var minx = 200; var maxx = 0; var miny = 200; var maxy = 0; + var error = 0; for(var i = 0; i < polygon.array.length; i++){ if(polygon.array[i].x < minx){ - minx = polygon.array[i].x; + minx = polygon.array[i].x; } if(polygon.array[i].x > maxx){ - maxx = polygon.array[i].x; + maxx = polygon.array[i].x; } if(polygon.array[i].y < miny){ - miny = polygon.array[i].y; + miny = polygon.array[i].y; } if(polygon.array[i].y > maxy){ - maxy = polygon.array[i].y; + maxy = polygon.array[i].y; + } + if(isNaN(polygon.array[i].x) || isNaN(polygon.array[i].y)){ + error++; } } - if(minx != maxx && miny != maxy && polygon.array.length >= 3){ + if(error == 0 && minx != maxx && miny != maxy && polygon.array.length >= 3){ var newArray = new Array(); newArray.push(polygon.array.shift()); while(polygon.array.length != 0){ - var temp = polygon.array.shift(); - if(newArray[newArray.length - 1].x != temp.x || - newArray[newArray.length - 1].y != temp.y){ - newArray.push(temp); - } + var temp = polygon.array.shift(); + if(newArray[newArray.length - 1].x != temp.x || + newArray[newArray.length - 1].y != temp.y){ + newArray.push(temp); + } } if(newArray.length >= 3){ - polygon.array = newArray; - this.array.push(polygon); + polygon.array = newArray; + this.array.push(polygon); } } } @@ -54,36 +63,36 @@ function Polygons(){ return buffer; } Polygons.prototype.generateSVG = generateSVG; - - function generateEPS(){ // string - var buffer = ""; - buffer += "%!PS-Adobe-3.0 EPSF-3.0\n"; - buffer += "%%BoundingBox: 0 -208 1024 816\n"; - buffer += "%%Pages: 0\n"; - buffer += "%%Title: Kanji glyph\n"; - buffer += "%%Creator: GlyphWiki powered by KAGE system\n"; - buffer += "%%CreationDate: " + new Date() + "\n"; - buffer += "%%EndComments\n"; - buffer += "%%EndProlog\n"; - buffer += "newpath\n"; - - for(var i = 0; i < this.array.length; i++){ - for(var j = 0; j < this.array[i].array.length; j++){ - buffer += (this.array[i].array[j].x * 5) + " " + (1000 - this.array[i].array[j].y * 5 - 200) + " "; - if(j == 0){ - buffer += "moveto\n"; - } else { - buffer += "lineto\n"; - } - } - buffer += "closepath\n"; - } - buffer += "fill\n"; - buffer += "%%EOF\n"; - return buffer; + + function generateEPS(){ // string + var buffer = ""; + buffer += "%!PS-Adobe-3.0 EPSF-3.0\n"; + buffer += "%%BoundingBox: 0 -208 1024 816\n"; + buffer += "%%Pages: 0\n"; + buffer += "%%Title: Kanji glyph\n"; + buffer += "%%Creator: GlyphWiki powered by KAGE system\n"; + buffer += "%%CreationDate: " + new Date() + "\n"; + buffer += "%%EndComments\n"; + buffer += "%%EndProlog\n"; + buffer += "newpath\n"; + + for(var i = 0; i < this.array.length; i++){ + for(var j = 0; j < this.array[i].array.length; j++){ + buffer += (this.array[i].array[j].x * 5) + " " + (1000 - this.array[i].array[j].y * 5 - 200) + " "; + if(j == 0){ + buffer += "moveto\n"; + } else { + buffer += "lineto\n"; + } + } + buffer += "closepath\n"; } - Polygons.prototype.generateEPS = generateEPS; - + buffer += "fill\n"; + buffer += "%%EOF\n"; + return buffer; + } + Polygons.prototype.generateEPS = generateEPS; + // property this.array = new Array();