|
|
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 <jerq.h>
9: #define DB ((Word *)0x700000)
10: #define ONSCREEN(b) (b->base>=DB && b->base<DB+XMAX/WORDSIZE*YMAX)
11: #define HUGE 017777777777
12: #define sgn(x) ((x)<0? -1 : (x)==0? 0 : 1)
13:
14: #ifdef MUX
15: #define POINT Tvoid(26) /* really lpoint, but we're dealing with the cursor */
16: #else
17: extern void point();
18: #define POINT point
19: #endif
20:
21: static struct dist {
22: Point s;
23: Point m;
24: long e;
25: } d1, d2;
26:
27: static void
28: test(x, p)
29: Point x;
30: register struct dist *p;
31: {
32: register long dx = x.x - p->s.x;
33: register long dy = x.y - p->s.y;
34: register long e = dx*dx+dy*dy;
35:
36: if(e <= p->e) {
37: p->m = x;
38: p->e = e;
39: }
40: }
41:
42: static void
43: survey(bp, x, f)
44: Bitmap *bp;
45: Point x;
46: Code f;
47: {
48: test(x, &d1);
49: test(x, &d2);
50: }
51: /*
52: * elarc(bp,p0,a,b,p1,p2,f) draws in bitmap bp an arc of the ellipse
53: * centered at p0 with half-axes a,b extending counterclockwise
54: * from a point near p1 to a point near p2
55: * args reversed because ellip1 draws clockwise
56: */
57: elarc(bp,p0,a,b,p1,p2,f)
58: Bitmap *bp;
59: Point p0, p1, p2;
60: Code f;
61: {
62: short inhibited;
63: inhibited=0;
64: if(f!=F_XOR && ONSCREEN(bp)){
65: Jcursinhibit();
66: inhibited=1;
67: }
68: if(a==0)
69: lsegment(bp, Pt(p0.x, p1.y), Pt(p0.x, p2.y), f);
70: else if(b==0)
71: lsegment(bp, Pt(p1.x, p0.y), Pt(p2.x, p0.y), f);
72: else {
73: int sx1;
74: int sy1;
75: int sx2;
76: int sy2;
77:
78: d1.s = sub(p1, p0);
79: d2.s = sub(p2, p0);
80: sx1 = sgn(d1.s.x);
81: sy1 = sgn(d1.s.y);
82: sx2 = sgn(d2.s.x);
83: sy2 = sgn(d2.s.y);
84: d1.s.x *= sx1;
85: d1.s.y *= sy1;
86: d2.s.x *= sx2;
87: d2.s.y *= sy2;
88: d1.e = d2.e = HUGE;
89: survey(bp, Pt(0, b), f);
90: ellip1(bp, Pt(0, 0), a, b, survey, Pt(0,b), Pt(a, 0), f);
91: if(!eqpt(d1.m, d2.m))
92: POINT(bp, d1.m, f);
93: ellip1(bp, p0, a, b, POINT,
94: Pt(d1.m.x*sx1, d1.m.y*sy1), Pt(d2.m.x*sx2, d2.m.y*sy2), f);
95: }
96: if(inhibited)
97: Jcursallow();
98: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.