Annotation of researchv9/jerq/src/lib/pot/elarc.c, revision 1.1.1.1

1.1       root        1: #ifndef        MUX
                      2: #define        Jcursinhibit()  cursinhibit()
                      3: #define        Jcursallow()    cursallow()
                      4: #define        lrectf(l, r, f) rectf(l, r, f)
                      5: #define        lsegment(l, p, q, f)    segment(l, p, q, f)
                      6: #endif
                      7: 
                      8: #include       <CC/jerq.h>
                      9: #define HUGE 017777777777
                     10: #define        sgn(x)  ((x)<0? -1 : (x)==0? 0 : 1)
                     11: 
                     12: #ifdef MUX
                     13: #define        POINT   Ivoid(26)       /* really lpoint, but we're dealing with the cursor */
                     14: #else
                     15: extern void point();
                     16: #define        POINT   point
                     17: #endif
                     18: 
                     19: static struct dist {
                     20:        Point s;
                     21:        Point m;
                     22:        long e;
                     23: } d1, d2;
                     24: 
                     25: static void
                     26: test(Point x, register struct dist *p)
                     27: {
                     28:        register long dx = x.x - p->s.x;
                     29:        register long dy = x.y - p->s.y;
                     30:        register long e = dx*dx+dy*dy;
                     31: 
                     32:        if(e <= p->e) {
                     33:                p->m = x;
                     34:                p->e = e;
                     35:        }
                     36: }
                     37: 
                     38: static void
                     39: survey(Bitmap *, Point x, Code)
                     40: {
                     41:        test(x, &d1);
                     42:        test(x, &d2);
                     43: }
                     44: 
                     45: static long emask, enext;
                     46: 
                     47: static void
                     48: paint(Bitmap *bp, Point x, Code f)
                     49: {
                     50:        if(enext&emask) POINT(bp, x, f);
                     51:        enext <<= 1;
                     52:        if(enext == 0) enext = 1;
                     53: }
                     54: 
                     55: /*
                     56:  * elarc(bp,p0,a,b,p1,p2,f) draws in bitmap bp an arc of the ellipse
                     57:  * centered at p0 with half-axes a,b extending counterclockwise
                     58:  * from a point near p1 to a point near p2
                     59:  * args reversed because ellip1 draws clockwise 
                     60:  */
                     61: extern void
                     62: elarc(Bitmap *bp, Point p0, int a, int b, Point p1, Point p2, Code f, long mask)
                     63: {
                     64:        short inhibited;
                     65: 
                     66:        emask = mask;
                     67:        enext = 1;
                     68:        inhibited=0;
                     69:        if(f!=F_XOR){
                     70:                Jcursinhibit();
                     71:                inhibited=1;
                     72:        }
                     73:        if(a==0)
                     74:                lsegment(bp, Pt(p0.x, p1.y), Pt(p0.x, p2.y), f);
                     75:        else if(b==0)
                     76:                lsegment(bp, Pt(p1.x, p0.y), Pt(p2.x, p0.y), f);
                     77:        else {
                     78:                int sx1;
                     79:                int sy1;
                     80:                int sx2;
                     81:                int sy2;
                     82: 
                     83:                d1.s = sub(p1, p0);
                     84:                d2.s = sub(p2, p0);
                     85:                sx1 = sgn(d1.s.x);
                     86:                sy1 = sgn(d1.s.y);
                     87:                sx2 = sgn(d2.s.x);
                     88:                sy2 = sgn(d2.s.y);
                     89:                d1.s.x *= sx1;
                     90:                d1.s.y *= sy1;
                     91:                d2.s.x *= sx2;
                     92:                d2.s.y *= sy2;
                     93:                d1.e = d2.e = HUGE;
                     94:                survey(bp, Pt(0, b), f);
                     95:                ellip1(bp, Pt(0, 0), a, b, survey, Pt(0,b), Pt(a, 0), f);
                     96:                if(d1.m != d2.m)
                     97:                        paint(bp, d1.m, f);
                     98:                ellip1(bp, p0, a, b, paint,
                     99:                        Pt(d1.m.x*sx1, d1.m.y*sy1), Pt(d2.m.x*sx2, d2.m.y*sy2), f);
                    100:        }
                    101:        if(inhibited)
                    102:                Jcursallow();
                    103: }

unix.superglobalmegacorp.com

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