From 87f55dc43dacf5c3d7b3fa4f460de461c9030fa5 Mon Sep 17 00:00:00 2001 From: Koichi KAMICHI Date: Fri, 17 Mar 2006 14:05:11 +0000 Subject: [PATCH] Use polygon instead of polyline. Added data check. --- engine/polygon.js | 2 +- engine/polygons.js | 38 +++++++++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/engine/polygon.js b/engine/polygon.js index 526d0c4..c2e3907 100755 --- a/engine/polygon.js +++ b/engine/polygon.js @@ -23,7 +23,7 @@ function Polygon(number){ this.array = this.array.concat(poly.array); } Polygon.prototype.concat = concat; - + // property this.array = new Array(); diff --git a/engine/polygons.js b/engine/polygons.js index 38fe2b7..6e95331 100755 --- a/engine/polygons.js +++ b/engine/polygons.js @@ -1,7 +1,40 @@ function Polygons(){ // method function push(polygon){ // void - this.array.push(polygon); + // only a simple check + var minx = 200; + var maxx = 0; + var miny = 200; + var maxy = 0; + for(var i = 0; i < polygon.array.length; i++){ + if(polygon.array[i].x < minx){ + minx = polygon.array[i].x; + } + if(polygon.array[i].x > maxx){ + maxx = polygon.array[i].x; + } + if(polygon.array[i].y < miny){ + miny = polygon.array[i].y; + } + if(polygon.array[i].y > maxy){ + maxy = polygon.array[i].y; + } + } + if(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); + } + } + if(newArray.length >= 3){ + polygon.array = newArray; + this.array.push(polygon); + } + } } Polygons.prototype.push = push; @@ -10,11 +43,10 @@ function Polygons(){ buffer += "\n"; buffer += "\n"; for(var i = 0; i < this.array.length; i++){ - buffer += "\n"; } buffer += "\n"; -- 1.7.10.4