int miny, maxy;\r
int cross[16], num;\r
int i, j, k, l, m;\r
+ struct kPoint tpoly[kResolution + 2];\r
+ int tnum;\r
double a, b;\r
\r
- miny = 10000;\r
- maxy = -10000;\r
- //detect max/min y-point\r
- for(i = 0; i < number; i++){\r
- if(p[i].Y < miny) miny = p[i].Y;\r
- if(p[i].Y > maxy) maxy = p[i].Y;\r
- //fprintf(stderr,"%.1f:%.1f\n",p[i].X,p[i].Y);\r
+ //copy to temp buffer and detect max/min y-point\r
+ tnum = 0;\r
+ tpoly[tnum].X = p[0].X;\r
+ tpoly[tnum].Y = p[0].Y;\r
+ miny = maxy = tpoly[tnum].Y;\r
+ tnum++;\r
+ for(i = 1; i < number; i++){\r
+ if(p[i].X != tpoly[tnum - 1].X || p[i].Y != tpoly[tnum - 1].Y){\r
+ tpoly[tnum].X = p[i].X;\r
+ tpoly[tnum].Y = p[i].Y;\r
+ if(tpoly[tnum].Y < miny) miny = tpoly[tnum].Y;\r
+ if(tpoly[tnum].Y > maxy) maxy = tpoly[tnum].Y;\r
+ tnum++;\r
+ }\r
}\r
+ tpoly[tnum].X = tpoly[0].X;\r
+ tpoly[tnum].Y = tpoly[0].Y;\r
+ tpoly[tnum + 1].X = tpoly[1].X;\r
+ tpoly[tnum + 1].Y = tpoly[1].Y;\r
+\r
//detect crossing point of each y-point and draw\r
for(j = miny; j <= maxy; j++){\r
num = 0;\r
- for(i = 0; i < number; i++){\r
- //if two points are tha same position, do nothing\r
- if(p[i].X == p[(i + 1) % number].X &&\r
- p[i].Y == p[(i + 1) % number].Y) continue;\r
+ for(i = 0; i < tnum; i++){\r
//if be parallel to x-axis\r
- if(p[i].Y == p[(i + 1) % number].Y){\r
- if(p[i].Y == j){\r
- cross[num] = p[(i + 1) % number].X;\r
- //fprintf(stderr,"[%d]",cross[num]);\r
+ if(tpoly[i].Y == tpoly[i + 1].Y){\r
+ if(tpoly[i].Y == j){\r
+ cross[num] = tpoly[i + 1].X;\r
num++;\r
}\r
}\r
//if be parallel to y-axis\r
- else if(p[i].X == p[(i + 1) % number].X){\r
- if((p[i].Y < j && j <= p[(i + 1) % number].Y) ||\r
- (p[(i + 1) % number].Y <= j && j < p[i].Y)){\r
- cross[num] = p[i].X;\r
- //fprintf(stderr,"[%d]",cross[num]);\r
+ else if(tpoly[i].X == tpoly[i + 1].X){\r
+ if((tpoly[i].Y < j && j <= tpoly[i + 1].Y) ||\r
+ (tpoly[i + 1].Y <= j && j < tpoly[i].Y)){\r
+ cross[num] = tpoly[i].X;\r
num++;\r
//spearhead: add one more\r
- if(p[(i + 1) % number].Y == j &&\r
- ((p[i].Y > p[(i + 1) % number].Y &&\r
- p[(i + 1) % number].Y < p[(i + 2) % number].Y) ||\r
- (p[i].Y < p[(i + 1) % number].Y &&\r
- p[(i + 1) % number].Y > p[(i + 2) % number].Y))){\r
- cross[num] = p[(i + 1) % number].X;\r
- //fprintf(stderr,"[%d]",cross[num]);\r
+ if(tpoly[i + 1].Y == j &&\r
+ ((tpoly[i].Y > tpoly[i + 1].Y &&\r
+ tpoly[i + 1].Y < tpoly[i + 2].Y) ||\r
+ (tpoly[i].Y < tpoly[i + 1].Y &&\r
+ tpoly[i + 1].Y > tpoly[i + 2].Y))){\r
+ cross[num] = tpoly[i + 1].X;\r
num++;\r
- //fprintf(stderr,"(add:%d)",j);\r
}\r
}\r
}\r
//detect crossing point of each vector\r
- else if((p[i].Y < j && j <= p[(i + 1) % number].Y) ||\r
- (p[(i + 1) % number].Y <= j && j < p[i].Y)){\r
- a = (p[(i + 1) % number].Y - p[i].Y) \r
- / (p[(i + 1) % number].X - p[i].X);\r
- b = p[i].Y - a * p[i].X;\r
+ else if((tpoly[i].Y < j && j <= tpoly[i + 1].Y) ||\r
+ (tpoly[i + 1].Y <= j && j < tpoly[i].Y)){\r
+ a = (tpoly[i + 1].Y - tpoly[i].Y) \r
+ / (tpoly[i + 1].X - tpoly[i].X);\r
+ b = tpoly[i].Y - a * tpoly[i].X;\r
cross[num] = (j - b) / a;\r
- //fprintf(stderr,"[%d]",cross[num]);\r
num++;\r
//spearhead: add one more\r
- if(p[(i + 1) % number].Y == j &&\r
- ((p[i].Y > p[(i + 1) % number].Y &&\r
- p[(i + 1) % number].Y < p[(i + 2) % number].Y) ||\r
- (p[i].Y < p[(i + 1) % number].Y &&\r
- p[(i + 1) % number].Y > p[(i + 2) % number].Y))){\r
- cross[num] = p[(i + 1) % number].X;\r
- //fprintf(stderr,"[%d]",cross[num]);\r
+ if(tpoly[i + 1].Y == j &&\r
+ ((tpoly[i].Y > tpoly[i + 1].Y &&\r
+ tpoly[i + 1].Y < tpoly[i + 2].Y) ||\r
+ (tpoly[i].Y < tpoly[i + 1].Y &&\r
+ tpoly[i + 1].Y > tpoly[i + 2].Y))){\r
+ cross[num] = tpoly[i + 1].X;\r
num++;\r
- //fprintf(stderr,"(add:%d)",j);\r
}\r
}\r
}\r
if(num != 0){\r
- if(num % 2 != 0)fprintf(stderr,"y:%d(%d)\n",j,num);\r
- //if(num != 0 && num % 2 == 0){\r
+ //(for debug)\r
+ if(num % 2 != 0){\r
+ fprintf(stderr,"y:%d(%d)\n",j,num);\r
+ for(k=0;k<num;k++) fprintf(stderr,"%d+",cross[k]);\r
+ }\r
//sort crossing point\r
for(k = 0; k < num - 1; k++){\r
for(l = num - 1; l > k; l--){\r
}\r
}\r
}\r
- //for(k=0;k<num;k++)fprintf(stderr,"%d:",cross[k]);\r
//draw to vram\r
for(k = 0 ; k < num; k = k + 2){\r
for(l = cross[k]; l <= cross[k + 1]; l++){\r
if(0 <= j && j < canvasHeight && 0 <= l && l < canvasWidth)\r
image[j][l] = col;\r
}\r
- //image[j][cross[k]] = col;\r
- //image[j][cross[k+1]] = col;\r
}\r
}\r
}\r
}\r
-\r