From: Koichi KAMICHI Date: Mon, 29 Mar 2004 13:58:48 +0000 (+0000) Subject: Bugfix. X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=e70b10bbb8b683ef92123b9ee068efe2f4757b2b;p=chise%2Fkage.git Bugfix. --- diff --git a/kagecgi/kagepoly.c b/kagecgi/kagepoly.c index b5fe2a4..69e29fb 100755 --- a/kagecgi/kagepoly.c +++ b/kagecgi/kagepoly.c @@ -8,76 +8,83 @@ void fillPolygon(struct kPoint *p, int number, int col, unsigned char **image){ int miny, maxy; int cross[16], num; int i, j, k, l, m; + struct kPoint tpoly[kResolution + 2]; + int tnum; double a, b; - miny = 10000; - maxy = -10000; - //detect max/min y-point - for(i = 0; i < number; i++){ - if(p[i].Y < miny) miny = p[i].Y; - if(p[i].Y > maxy) maxy = p[i].Y; - //fprintf(stderr,"%.1f:%.1f\n",p[i].X,p[i].Y); + //copy to temp buffer and detect max/min y-point + tnum = 0; + tpoly[tnum].X = p[0].X; + tpoly[tnum].Y = p[0].Y; + miny = maxy = tpoly[tnum].Y; + tnum++; + for(i = 1; i < number; i++){ + if(p[i].X != tpoly[tnum - 1].X || p[i].Y != tpoly[tnum - 1].Y){ + tpoly[tnum].X = p[i].X; + tpoly[tnum].Y = p[i].Y; + if(tpoly[tnum].Y < miny) miny = tpoly[tnum].Y; + if(tpoly[tnum].Y > maxy) maxy = tpoly[tnum].Y; + tnum++; + } } + tpoly[tnum].X = tpoly[0].X; + tpoly[tnum].Y = tpoly[0].Y; + tpoly[tnum + 1].X = tpoly[1].X; + tpoly[tnum + 1].Y = tpoly[1].Y; + //detect crossing point of each y-point and draw for(j = miny; j <= maxy; j++){ num = 0; - for(i = 0; i < number; i++){ - //if two points are tha same position, do nothing - if(p[i].X == p[(i + 1) % number].X && - p[i].Y == p[(i + 1) % number].Y) continue; + for(i = 0; i < tnum; i++){ //if be parallel to x-axis - if(p[i].Y == p[(i + 1) % number].Y){ - if(p[i].Y == j){ - cross[num] = p[(i + 1) % number].X; - //fprintf(stderr,"[%d]",cross[num]); + if(tpoly[i].Y == tpoly[i + 1].Y){ + if(tpoly[i].Y == j){ + cross[num] = tpoly[i + 1].X; num++; } } //if be parallel to y-axis - else if(p[i].X == p[(i + 1) % number].X){ - if((p[i].Y < j && j <= p[(i + 1) % number].Y) || - (p[(i + 1) % number].Y <= j && j < p[i].Y)){ - cross[num] = p[i].X; - //fprintf(stderr,"[%d]",cross[num]); + else if(tpoly[i].X == tpoly[i + 1].X){ + if((tpoly[i].Y < j && j <= tpoly[i + 1].Y) || + (tpoly[i + 1].Y <= j && j < tpoly[i].Y)){ + cross[num] = tpoly[i].X; num++; //spearhead: add one more - if(p[(i + 1) % number].Y == j && - ((p[i].Y > p[(i + 1) % number].Y && - p[(i + 1) % number].Y < p[(i + 2) % number].Y) || - (p[i].Y < p[(i + 1) % number].Y && - p[(i + 1) % number].Y > p[(i + 2) % number].Y))){ - cross[num] = p[(i + 1) % number].X; - //fprintf(stderr,"[%d]",cross[num]); + if(tpoly[i + 1].Y == j && + ((tpoly[i].Y > tpoly[i + 1].Y && + tpoly[i + 1].Y < tpoly[i + 2].Y) || + (tpoly[i].Y < tpoly[i + 1].Y && + tpoly[i + 1].Y > tpoly[i + 2].Y))){ + cross[num] = tpoly[i + 1].X; num++; - //fprintf(stderr,"(add:%d)",j); } } } //detect crossing point of each vector - else if((p[i].Y < j && j <= p[(i + 1) % number].Y) || - (p[(i + 1) % number].Y <= j && j < p[i].Y)){ - a = (p[(i + 1) % number].Y - p[i].Y) - / (p[(i + 1) % number].X - p[i].X); - b = p[i].Y - a * p[i].X; + else if((tpoly[i].Y < j && j <= tpoly[i + 1].Y) || + (tpoly[i + 1].Y <= j && j < tpoly[i].Y)){ + a = (tpoly[i + 1].Y - tpoly[i].Y) + / (tpoly[i + 1].X - tpoly[i].X); + b = tpoly[i].Y - a * tpoly[i].X; cross[num] = (j - b) / a; - //fprintf(stderr,"[%d]",cross[num]); num++; //spearhead: add one more - if(p[(i + 1) % number].Y == j && - ((p[i].Y > p[(i + 1) % number].Y && - p[(i + 1) % number].Y < p[(i + 2) % number].Y) || - (p[i].Y < p[(i + 1) % number].Y && - p[(i + 1) % number].Y > p[(i + 2) % number].Y))){ - cross[num] = p[(i + 1) % number].X; - //fprintf(stderr,"[%d]",cross[num]); + if(tpoly[i + 1].Y == j && + ((tpoly[i].Y > tpoly[i + 1].Y && + tpoly[i + 1].Y < tpoly[i + 2].Y) || + (tpoly[i].Y < tpoly[i + 1].Y && + tpoly[i + 1].Y > tpoly[i + 2].Y))){ + cross[num] = tpoly[i + 1].X; num++; - //fprintf(stderr,"(add:%d)",j); } } } if(num != 0){ - if(num % 2 != 0)fprintf(stderr,"y:%d(%d)\n",j,num); - //if(num != 0 && num % 2 == 0){ + //(for debug) + if(num % 2 != 0){ + fprintf(stderr,"y:%d(%d)\n",j,num); + for(k=0;k k; l--){ @@ -88,17 +95,13 @@ void fillPolygon(struct kPoint *p, int number, int col, unsigned char **image){ } } } - //for(k=0;k