Annotation of researchv9/jerq/src/lib/j/jlineto.c, revision 1.1.1.1

1.1       root        1: #include <jerq.h>
                      2: #include <line.h>
                      3: static x0, y0;
                      4: 
                      5: jmoveto(xy)
                      6:        Point xy;
                      7: {
                      8:        PtCurrent=xy;
                      9: }
                     10: jlineto(xy, f)
                     11:        Point xy;
                     12: {
                     13:        jsegment(PtCurrent, xy, f);
                     14:        PtCurrent=xy;
                     15: }
                     16: jmove(xy)
                     17:        Point xy;
                     18: {
                     19:        PtCurrent.x+=xy.x;
                     20:        PtCurrent.y+=xy.y;
                     21: }
                     22: jline(xy, f)
                     23:        Point xy;
                     24: {
                     25:        Point next;
                     26:        next=add(PtCurrent, xy);
                     27:        jsegment(PtCurrent, next, f);
                     28:        PtCurrent=next;
                     29: }
                     30: 
                     31: jsegment(p, q, f)
                     32:        Point p, q;
                     33: {
                     34:        segment(&display, p, q, f);
                     35:        PtCurrent=q;
                     36: }
                     37: 
                     38: segment(b, p, q, f)
                     39:        Bitmap *b;
                     40:        Point p, q;
                     41: {
                     42:        if(p.x==q.x && p.y==q.y)
                     43:                return;
                     44:        q=Jsetline(p, q);
                     45:        Jclipline(b, b->rect, p, q, f);
                     46: }
                     47: floor(x,y)
                     48:        register long x;
                     49:        register y;
                     50: {
                     51:        if (y<=0) {
                     52:                if (y==0) return((short) x);
                     53:                y= -y; x= -x;
                     54:        }
                     55:        if (x<0) x -= y-1;
                     56:        return((short) (x/y));
                     57: }
                     58: 
                     59: ceil(x,y)
                     60:        register long x;
                     61:        register y;
                     62: {
                     63:        if (y<=0) {
                     64:                if (y==0) return((short) x);
                     65:                y= -y; x= -x;
                     66:        }
                     67:        if (x>0) x += y-1;
                     68:        return((short) (x/y));
                     69: }
                     70: Jminor(x)
                     71:        register x;
                     72: {
                     73:        register y;
                     74:        y=floor(2*(long)(x-x0)*Jdminor+Jdmajor, 2*Jdmajor)+y0;
                     75:        return Jslopeneg? -y : y;
                     76: }
                     77: Jmajor(y)
                     78:        register y;
                     79: {
                     80:        register x;
                     81:        x=ceil(2*(long)((Jslopeneg? -y : y)-y0)*Jdmajor-Jdminor, 2*Jdminor)+x0;
                     82:        if(Jdminor)
                     83:                while(Jminor(x-1)==y)
                     84:                        x--;
                     85:        return x;
                     86: }
                     87: Point
                     88: Jsetline(p, q)
                     89:        Point p, q;
                     90: {
                     91:        register dx, dy, t;
                     92:        Point endpt;
                     93:        short swapped=0;
                     94:        Jxmajor=1;
                     95:        Jslopeneg=0;
                     96:        dx=q.x-p.x;
                     97:        dy=q.y-p.y;
                     98:        if(abs(dy) > abs(dx)){  /* Steep */
                     99:                Jxmajor=0;
                    100: #define XYswap(p)      t=p.x; p.x=p.y; p.y=t
                    101:                XYswap(p);
                    102:                XYswap(q);
                    103: #define Swap(x, y)     t=x; x=y; y=t
                    104:                Swap(dx, dy);
                    105:        }
                    106:        if(dx<0){
                    107:                swapped++;
                    108:                Swap(p.x, q.x); Swap(p.y, q.y);
                    109:                dx= -dx; dy= -dy;
                    110:        }
                    111:        if(dy<0){
                    112:                Jslopeneg++;
                    113:                dy= -dy; p.y= -p.y; q.y= -q.y;
                    114:        }
                    115:        Jdminor=dy;
                    116:        Jdmajor=dx;
                    117:        x0=p.x;
                    118:        y0=p.y;
                    119:        endpt.x=swapped? p.x+1 : q.x-1;
                    120:        endpt.y=Jminor(endpt.x);
                    121:        if(!Jxmajor){
                    122:                XYswap(endpt);
                    123:        }
                    124:        return(endpt);
                    125: }
                    126: Jsetdda(x)
                    127:        register x;
                    128: {
                    129:        register y;
                    130:        y=Jminor(x);
                    131:        if(Jslopeneg)
                    132:                y= -y;
                    133:        return (short)((2*(x-x0)+2)*(long)Jdminor
                    134:                -(2*(y-y0)+1)*(long)Jdmajor);
                    135: }

unix.superglobalmegacorp.com

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