Annotation of researchv9/jerq/src/lib/j/linesub.c, revision 1.1

1.1     ! root        1: #include <jerq.h>
        !             2: #include <line.h>
        !             3: static x0, y0;
        !             4: 
        !             5: segment(b, p, q, f)
        !             6:        Bitmap *b;
        !             7:        Point p, q;
        !             8: {
        !             9:        if(p.x==q.x && p.y==q.y)
        !            10:                return;
        !            11:        q=Jsetline(p, q);
        !            12:        Jclipline(b, b->rect, p, q, f);
        !            13: }
        !            14: floor(x,y)
        !            15:        register long x;
        !            16:        register y;
        !            17: {
        !            18:        if (y<=0) {
        !            19:                if (y==0) return((short) x);
        !            20:                y= -y; x= -x;
        !            21:        }
        !            22:        if (x<0) x -= y-1;
        !            23:        return((short) (x/y));
        !            24: }
        !            25: 
        !            26: ceil(x,y)
        !            27:        register long x;
        !            28:        register y;
        !            29: {
        !            30:        if (y<=0) {
        !            31:                if (y==0) return((short) x);
        !            32:                y= -y; x= -x;
        !            33:        }
        !            34:        if (x>0) x += y-1;
        !            35:        return((short) (x/y));
        !            36: }
        !            37: Jminor(x)
        !            38:        register x;
        !            39: {
        !            40:        register y;
        !            41:        y=floor(2*(long)(x-x0)*Jdminor+Jdmajor, 2*Jdmajor)+y0;
        !            42:        return Jslopeneg? -y : y;
        !            43: }
        !            44: Jmajor(y)
        !            45:        register y;
        !            46: {
        !            47:        register x;
        !            48:        x=ceil(2*(long)((Jslopeneg? -y : y)-y0)*Jdmajor-Jdminor, 2*Jdminor)+x0;
        !            49:        if(Jdminor)
        !            50:                while(Jminor(x-1)==y)
        !            51:                        x--;
        !            52:        return x;
        !            53: }
        !            54: Point
        !            55: Jsetline(p, q)
        !            56:        Point p, q;
        !            57: {
        !            58:        register dx, dy, t;
        !            59:        Point endpt;
        !            60:        short swapped=0;
        !            61:        Jxmajor=1;
        !            62:        Jslopeneg=0;
        !            63:        dx=q.x-p.x;
        !            64:        dy=q.y-p.y;
        !            65:        if(abs(dy) > abs(dx)){  /* Steep */
        !            66:                Jxmajor=0;
        !            67: #define XYswap(p)      t=p.x; p.x=p.y; p.y=t
        !            68:                XYswap(p);
        !            69:                XYswap(q);
        !            70: #define Swap(x, y)     t=x; x=y; y=t
        !            71:                Swap(dx, dy);
        !            72:        }
        !            73:        if(dx<0){
        !            74:                swapped++;
        !            75:                Swap(p.x, q.x); Swap(p.y, q.y);
        !            76:                dx= -dx; dy= -dy;
        !            77:        }
        !            78:        if(dy<0){
        !            79:                Jslopeneg++;
        !            80:                dy= -dy; p.y= -p.y; q.y= -q.y;
        !            81:        }
        !            82:        Jdminor=dy;
        !            83:        Jdmajor=dx;
        !            84:        x0=p.x;
        !            85:        y0=p.y;
        !            86:        endpt.x=swapped? p.x+1 : q.x-1;
        !            87:        endpt.y=Jminor(endpt.x);
        !            88:        if(!Jxmajor){
        !            89:                XYswap(endpt);
        !            90:        }
        !            91:        return(endpt);
        !            92: }
        !            93: Jsetdda(x)
        !            94:        register x;
        !            95: {
        !            96:        register y;
        !            97:        y=Jminor(x);
        !            98:        if(Jslopeneg)
        !            99:                y= -y;
        !           100:        return (short)((2*(x-x0)+2)*(long)Jdminor
        !           101:                -(2*(y-y0)+1)*(long)Jdmajor);
        !           102: }

unix.superglobalmegacorp.com

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