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

1.1     ! root        1: #include <jerq.h>
        !             2: #include <line.h>
        !             3: static
        !             4: code(p, r)
        !             5:        Point p;
        !             6:        Rectangle r;
        !             7: {
        !             8:        return( (p.x<r.origin.x? 01 : p.x>=r.corner.x? 02 : 0) |
        !             9:                (p.y<r.origin.y? 04 : p.y>=r.corner.y?010 : 0));
        !            10: }
        !            11: 
        !            12: /*
        !            13:  * Modified clip-to-rectangle algorithm
        !            14:  *     works in bitmaps
        !            15:  *     Everything in SCREEN coordinates.
        !            16:  *
        !            17:  *     Newman & Sproull 124 (1st edition)
        !            18:  */
        !            19: Jclipline(b, r, p0, p1, f)
        !            20:        register Bitmap *b;
        !            21:        Rectangle r;
        !            22:        Point p0, p1;
        !            23: {
        !            24:        register c0, c1;
        !            25:        register xl, xr, yt, yb;
        !            26:        Point temp;
        !            27:        int swapxy=0;
        !            28: 
        !            29:        if(!Jxmajor){
        !            30: #define XYswap(p)      c0=p.x; p.x=p.y; p.y=c0
        !            31:                XYswap(p0); XYswap(p1); XYswap(r.origin); XYswap(r.corner);
        !            32:                swapxy++;
        !            33:        }
        !            34:        xl=r.origin.x; xr=r.corner.x;
        !            35:        yt=r.origin.y; yb=r.corner.y;
        !            36:        c0=code(p0, r);
        !            37:        c1=code(p1, r);
        !            38:        while(c0|c1){
        !            39:                if(c0&c1)
        !            40:                        return; /* no point of line in r */
        !            41:                if(c0==0){      /* swap points */
        !            42:                        short t;
        !            43:                        temp=p0; p0=p1; p1=temp;
        !            44:                        t=c0; c0=c1; c1=t;
        !            45:                }
        !            46:                if(c0==0)
        !            47:                        break;
        !            48:                if(c0&01)       /* push towards left edge */
        !            49:                        p0.y=Jminor(p0.x=xl);
        !            50:                else if(c0&02)  /* push towards right edge */
        !            51:                        p0.y=Jminor(p0.x=xr-1);
        !            52:                else if(c0&04){ /* push towards top edge */
        !            53:                        if(Jslopeneg)
        !            54:                                p0.x=Jmajor((p0.y=yt)-1)-1;
        !            55:                        else{
        !            56:                                p0.y=yt;
        !            57:                                p0.x=Jmajor(yt);
        !            58:                        }
        !            59:                }else if(c0&010){       /* push towards bottom edge */
        !            60:                        if(Jslopeneg){
        !            61:                                p0.y=yb-1;
        !            62:                                p0.x=Jmajor(yb-1);
        !            63:                        }
        !            64:                        else{
        !            65:                                p0.y=yb-1;
        !            66:                                p0.x=Jmajor(yb)-1;
        !            67:                        }
        !            68:                }
        !            69:                c0=code(p0, r);
        !            70:        }
        !            71:        if(swapxy){
        !            72:                XYswap(p0); XYswap(p1);
        !            73:        }
        !            74:        _line(b, p0, p1, f);
        !            75: }

unix.superglobalmegacorp.com

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