1 /* 2 * Copyright (c) 1985 Regents of the University of California. 3 * All rights reserved. The Berkeley software License Agreement 4 * specifies the terms and conditions for redistribution. 5 */ 6 7 #ifndef lint 8 static char sccsid[] = "@(#)arc.c 5.1 (Berkeley) 09/21/85"; 9 #endif not lint 10 11 int del = 20; 12 step(d){ 13 del = d; 14 } 15 arc(x,y,x0,y0,x1,y1){ 16 double pc; 17 double sqrt(); 18 int flg,m,xc,yc,xs,ys,qs,qf; 19 float dx,dy,r; 20 char use; 21 dx = x-x0; 22 dy = y-y0; 23 r = dx*dx+dy*dy; 24 pc = r; 25 pc = sqrt(pc); 26 flg = pc/4; 27 if(flg == 0)step(1); 28 else if(flg < del)step(flg); 29 xc = xs = x0; 30 yc = ys = y0; 31 move(xs,ys); 32 if(x0 == x1 && y0 == y1)flg=0; 33 else flg=1; 34 qs = quad(x,y,x0,y0); 35 qf = quad(x,y,x1,y1); 36 if(abs(x-x1) < abs(y-y1)){ 37 use = 'x'; 38 if(qs == 2 || qs ==3)m = -1; 39 else m=1; 40 } 41 else { 42 use = 'y'; 43 if(qs > 2)m= -1; 44 else m= 1; 45 } 46 while(1){ 47 switch(use){ 48 case 'x': 49 if(qs == 2 || qs == 3)yc -= del; 50 else yc += del; 51 dy = yc-y; 52 pc = r-dy*dy; 53 xc = m*sqrt(pc)+x; 54 if((x < xs && x >= xc) || ( x > xs && x <= xc) || 55 (y < ys && y >= yc) || ( y > ys && y <= yc) ) 56 { 57 if(++qs > 4)qs=1; 58 if(qs == 2 || qs == 3)m= -1; 59 else m=1; 60 flg=1; 61 } 62 cont(xc,yc); 63 xs = xc; 64 ys = yc; 65 if(qs == qf && flg == 1) 66 switch(qf){ 67 case 3: 68 case 4: 69 if(xs >= x1)return; 70 continue; 71 case 1: 72 case 2: 73 if(xs <= x1)return; 74 } 75 continue; 76 case 'y': 77 if(qs > 2)xc += del; 78 else xc -= del; 79 dx = xc-x; 80 pc = r-dx*dx; 81 yc = m*sqrt(pc)+y; 82 if((x < xs && x >= xc) || ( x > xs && x <= xc ) || 83 (y < ys && y >= yc) || (y > ys && y <= yc) ) 84 { 85 if(++qs > 4)qs=1; 86 if(qs > 2)m = -1; 87 else m = 1; 88 flg=1; 89 } 90 cont(xc,yc); 91 xs = xc; 92 ys = yc; 93 if(qs == qf && flg == 1) 94 switch(qs){ 95 case 1: 96 case 4: 97 if(ys >= y1)return; 98 continue; 99 case 2: 100 case 3: 101 if(ys <= y1)return; 102 } 103 } 104 } 105 } 106 quad(x,y,xp,yp){ 107 if(x < xp) 108 if(y <= yp)return(1); 109 else return(4); 110 else if(x > xp) 111 if(y < yp)return(2); 112 else return(3); 113 else if(y < yp)return(2); 114 else return(4); 115 } 116 abs(a){ 117 if(a < 0)return(-a); 118 return(a); 119 } 120