Annotation of researchv10no/libplot/lib4014/fill.c, revision 1.1

1.1     ! root        1: #include <stdio.h>
        !             2: #include <math.h>
        !             3: #include "tek.h"
        !             4: #define SEGS 256
        !             5: #define ROUND(a) a>0?a+.5:a-.5
        !             6: double sinp, cosp;
        !             7: int place();
        !             8: fill(num,ff)
        !             9: int num[];
        !            10: double *ff[];
        !            11: {
        !            12:        register struct seg *sp;
        !            13:        register double x, y;
        !            14:        int sgap;
        !            15:        double slant;
        !            16:        struct seg *in, *spend;
        !            17:        struct seg ss[4];
        !            18:        int     so;
        !            19:        double   X, Y, xyt, **fp;
        !            20:        int ymin;
        !            21:        int     M, *n;
        !            22:        double  *xpp, *ypp;
        !            23:        int fx, fy, flag;
        !            24: 
        !            25:        if(!internal){
        !            26:                in = (struct seg *)malloc((unsigned)(SEGS*sizeof(struct seg)));
        !            27:                if(in == 0){
        !            28:                        fprintf(stderr,"not enough space for fill segments\n");
        !            29:                        return(1);
        !            30:                }
        !            31:                spend = in + (SEGS-2);
        !            32:        }
        !            33:        else {
        !            34:                in = ss;
        !            35:                spend = &ss[3];
        !            36:        }
        !            37:        sinp = cos(e1->pslant);
        !            38:        cosp = sin(e1->pslant);
        !            39:        n = num;
        !            40:        fp = ff;
        !            41:        sp = in;
        !            42:        ymin = 4000;
        !            43:        while((M = *n++)){
        !            44:                xpp = *fp++;
        !            45:                ypp = xpp + 1;
        !            46:                x = normx(*xpp);
        !            47:                y = normy(*ypp);
        !            48:                if (cosp)  {
        !            49:                        xyt = sinp * x - cosp * y;
        !            50:                        y = cosp * x + sinp * y;
        !            51:                        y = ROUND(y);
        !            52:                        x = ROUND(xyt);
        !            53:                }
        !            54:                fx = x;
        !            55:                fy = y;
        !            56:                flag = 0;
        !            57:                while(--M){
        !            58:                        xpp += 2;
        !            59:                        ypp += 2;
        !            60:                        X = normx(*xpp);
        !            61:                        Y = normy(*ypp);
        !            62:                        if (cosp)  {
        !            63:                                xyt = sinp * X - cosp * Y;
        !            64:                                Y = cosp * X + sinp * Y;
        !            65:                                Y = ROUND(Y);
        !            66:                                X = ROUND(xyt);
        !            67:                        }
        !            68:        check:
        !            69:                        if ( (Y > y) || (Y==y && X > x)){
        !            70:                                sp->x = X;
        !            71:                                sp->y = Y;
        !            72:                                sp->X = x;
        !            73:                                sp->Y = y;
        !            74:                        }
        !            75:                        else {
        !            76:                                sp->x = x;
        !            77:                                sp->y = y;
        !            78:                                sp->X = X;
        !            79:                                sp->Y = Y;
        !            80:                        }
        !            81:                        x=X;
        !            82:                        y=Y;
        !            83:                        sp->stat = 1;
        !            84:                        if(Y < ymin)
        !            85:                                ymin = Y;
        !            86:                        if ( sp->y == sp->Y) {
        !            87:                                if(sp > in){
        !            88:                                if ((sp-1)->y == (sp-1)->Y && (sp-1)->y == sp->y) {
        !            89:                                        if (sp->x == (sp - 1)->X) {
        !            90:                                                (sp - 1)->X = sp->X;
        !            91:                                        sp--;
        !            92:                                        } else if (sp->X == (sp - 1)->x) {
        !            93:                                                (sp - 1)->x = sp->x;
        !            94:                                        sp--;
        !            95:                                        }
        !            96:                                }
        !            97:                                }
        !            98:                        }
        !            99:                        if(sp++ > spend){
        !           100:                                fprintf(stderr, "Too many sides\n");
        !           101:                                return(0);
        !           102:                        }
        !           103:                        if((M==1) && (flag == 0)){
        !           104:                                X = fx;
        !           105:                                Y = fy;
        !           106:                                flag = 1;
        !           107:                                goto check;
        !           108:                        }
        !           109:                }
        !           110:        }
        !           111:        sgap = e0->pgap;
        !           112:        slant = e0->pslant;
        !           113:        e0->pgap = e1->pgap;
        !           114:        e0->pslant = e1->pgap;
        !           115:        esave = e1;
        !           116:        putchar(ESC);
        !           117:        putchar(e1->pbrush);
        !           118:        e1 = e0;
        !           119:        so = sp - in;
        !           120:        realfill(so, in, ymin);
        !           121:        e0->pgap = sgap;
        !           122:        e0->pslant = slant;
        !           123:        e1 = esave;
        !           124:        putchar(ESC);
        !           125:        putchar(e1->ppink);
        !           126:        if(!internal)
        !           127:                free(in);
        !           128:        return(1);
        !           129: }
        !           130: double xcut();
        !           131: realfill(so, s, yymin)
        !           132: int    so, yymin;
        !           133: struct seg *s;
        !           134: {
        !           135:        register struct seg *sp, *s1, *s2, *st;
        !           136:        register int    yb;
        !           137:        struct seg *sfin;
        !           138: 
        !           139:        sfin = s1 = s + so - 1;
        !           140:        for (sp = s; sp <= sfin;  sp++) {
        !           141:                if (sp->stat){
        !           142:                        if (sp->y == sp->Y){
        !           143:                                if (sp < sfin) {
        !           144:                                        s2 = sp+1;
        !           145:                                        while(s2<=sfin && s2->y==s2->Y){
        !           146:                                                if (sp->X == s2->x)
        !           147:                                                        sp->X = s2->X;
        !           148:                                                else if (sp->x == s2->X)
        !           149:                                                        sp->x = s2->x;
        !           150:                                                s2++->stat = 0;
        !           151:                                        }
        !           152:                                }
        !           153:                                else s2 = sp;
        !           154:                                if (s1->y == sp->y &&s2->y == sp->y)
        !           155:                                        sp->stat = 0;
        !           156:                                else if (s1->Y == sp->y && s2->Y == sp->y)
        !           157:                                        sp->stat = 0;
        !           158:                        }
        !           159:                }
        !           160:                s1 = sp;
        !           161:        }
        !           162: 
        !           163:        qsort(s, so, sizeof(struct seg), place);
        !           164:        sfin++;
        !           165:        s1 = s;
        !           166:        yb = s1->y;
        !           167:        for(sp=s; yb <= sp->y;sp++);
        !           168:        s2 = sp - 1;
        !           169:        for (; yb >= yymin; yb--) {
        !           170:                if (!(yb % e1->pgap))
        !           171:                        draw(yb, s1, s2);
        !           172:                for (st = s1; st <= s2; st++) {
        !           173:                        if (st->stat)
        !           174:                                if (yb <= st->Y)
        !           175:                                        st->stat = 0;
        !           176:                }
        !           177:                if (sp >= sfin)
        !           178:                        continue;
        !           179:                for (; yb <= (sp->y + 1) && sp < sfin; sp++) {
        !           180:                        for (st = s1; st <= s2; st++) {
        !           181:                                if (sp->y == st->Y) {
        !           182:                                        if (sp->x == st->X)
        !           183:                                                st->stat = 0;
        !           184:                                        else if (sp->Y == sp->y && sp->X == st->X)
        !           185:                                                st->stat = 0;
        !           186:                                }
        !           187:                        }
        !           188:                }
        !           189: 
        !           190:                s2 = sp - 1;
        !           191:                while (!(s1->stat))
        !           192:                        s1++;
        !           193:        }
        !           194: }
        !           195: draw(y, pr1, pr2)
        !           196: int    y;
        !           197: struct seg *pr1, *pr2;
        !           198: {
        !           199:        register struct seg *pr;
        !           200:        register double *xp;
        !           201:        double  x[32], yy, yi, yii, xi, xii, xj;
        !           202:        double *xpe;
        !           203:        for(pr=pr1, xp=x; pr <= pr2;pr++){
        !           204:                if (pr->stat)
        !           205:                        if (pr->y != pr->Y){
        !           206:                                *xp++ = xcut(y, pr->x, pr->y, pr->X, pr->Y);
        !           207:                                if(xp > &x[31])
        !           208:                                        fprintf(stderr, "Too many intersections\n");
        !           209:                        }
        !           210:        }
        !           211:        xpe = xp;
        !           212:        if(xpe < &x[1])
        !           213:                return;
        !           214:        do {
        !           215:                xj = 0;
        !           216:                for(xp=x+1;xp<xpe;xp++){
        !           217:                        if(*(xp-1) > *xp){
        !           218:                                xj = *(xp-1);
        !           219:                                *(xp-1) = *xp;
        !           220:                                *xp = xj;
        !           221:                        }
        !           222:                }
        !           223:        } while(xj);
        !           224:        yy = y;
        !           225:        for(xp=x; xp<xpe;xp++){
        !           226:                xj = *xp++;
        !           227:                if (!cosp)
        !           228:                        line(xj, unorm(yy), *xp, unorm(yy));
        !           229:                else {
        !           230:                        xi = sinp * xj + cosp * yy;
        !           231:                        yi = -cosp * xj + sinp * yy;
        !           232:                        xii = sinp * *xp + cosp * yy;
        !           233:                        yii = -cosp * *xp + sinp * yy;
        !           234:                        line(xi, unorm(yi), xii, unorm(yii));
        !           235:                }
        !           236:        }
        !           237: 
        !           238: }
        !           239: 
        !           240: 
        !           241: double xcut(y, x1, y1, x2, y2)
        !           242: {
        !           243:        register double dx, dy, xy, x;
        !           244:        if (y1 == y2) {
        !           245:                x = x1 > x2 ? x1 : x2;
        !           246:                return(x);
        !           247:        }
        !           248:        dy = y1 - y2;
        !           249:        dx = x1 - x2;
        !           250:        xy = (float)y1 * x2 - x1 * (float)y2;
        !           251:        x = (y * dx + xy) / dy;
        !           252:        return(x);
        !           253: }
        !           254: place(p1, p2)
        !           255: struct seg *p1, *p2;
        !           256: {
        !           257:        if(p1->y > p2->y)
        !           258:                return(-1);
        !           259:        else if(p1->y < p2->y)
        !           260:                return(1);
        !           261:        else if(p1->x > p2->x)
        !           262:                return(-1);
        !           263:        else if(p1->x < p2->x)
        !           264:                return(1);
        !           265:        else if(p1->X > p2->X)
        !           266:                return(-1);
        !           267:        else if(p1->X < p2->X)
        !           268:                return(1);
        !           269:        else if(p1->Y > p2->Y)
        !           270:                return(-1);
        !           271:        else if(p1->Y < p2->Y)
        !           272:                return(1);
        !           273:        else return(0);
        !           274: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.