ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/lib4014/arc.c
Revision: 1.3
Committed: Sat Nov 15 02:13:37 2003 UTC (20 years, 5 months ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R6P1, rad3R6
Changes since 1.2: +34 -8 lines
Log Message:
Continued ANSIfication, and reduced other compile warnings.

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: arc.c,v 1.2 2003/10/27 10:28:59 schorsch Exp $";
3 #endif
4
5 #include "local4014.h"
6 #include "lib4014.h"
7
8 int del = 20;
9
10 extern void
11 step(int d)
12 {
13 del = d;
14 }
15
16 extern void
17 arc(
18 int x,
19 int y,
20 int x0,
21 int y0,
22 int x1,
23 int y1
24 )
25 {
26 double pc;
27 double sqrt();
28 int flg,m,xc,yc,xs,ys,qs,qf;
29 float dx,dy,r;
30 char use;
31 dx = x-x0;
32 dy = y-y0;
33 r = dx*dx+dy*dy;
34 pc = r;
35 pc = sqrt(pc);
36 flg = pc/4;
37 if(flg == 0)step(1);
38 else if(flg < del)step(flg);
39 xc = xs = x0;
40 yc = ys = y0;
41 move(xs,ys);
42 if(x0 == x1 && y0 == y1)flg=0;
43 else flg=1;
44 qs = quad(x,y,x0,y0);
45 qf = quad(x,y,x1,y1);
46 if(abs_(x-x1) < abs_(y-y1)){
47 use = 'x';
48 if(qs == 2 || qs ==3)m = -1;
49 else m=1;
50 }
51 else {
52 use = 'y';
53 if(qs > 2)m= -1;
54 else m= 1;
55 }
56 while(1){
57 switch(use){
58 case 'x':
59 if(qs == 2 || qs == 3)yc -= del;
60 else yc += del;
61 dy = yc-y;
62 pc = r-dy*dy;
63 xc = m*sqrt(pc)+x;
64 if((x < xs && x >= xc) || ( x > xs && x <= xc) ||
65 (y < ys && y >= yc) || ( y > ys && y <= yc) )
66 {
67 if(++qs > 4)qs=1;
68 if(qs == 2 || qs == 3)m= -1;
69 else m=1;
70 flg=1;
71 }
72 cont(xc,yc);
73 xs = xc;
74 ys = yc;
75 if(qs == qf && flg == 1)
76 switch(qf){
77 case 3:
78 case 4:
79 if(xs >= x1)return;
80 continue;
81 case 1:
82 case 2:
83 if(xs <= x1)return;
84 }
85 continue;
86 case 'y':
87 if(qs > 2)xc += del;
88 else xc -= del;
89 dx = xc-x;
90 pc = r-dx*dx;
91 yc = m*sqrt(pc)+y;
92 if((x < xs && x >= xc) || ( x > xs && x <= xc ) ||
93 (y < ys && y >= yc) || (y > ys && y <= yc) )
94 {
95 if(++qs > 4)qs=1;
96 if(qs > 2)m = -1;
97 else m = 1;
98 flg=1;
99 }
100 cont(xc,yc);
101 xs = xc;
102 ys = yc;
103 if(qs == qf && flg == 1)
104 switch(qs){
105 case 1:
106 case 4:
107 if(ys >= y1)return;
108 continue;
109 case 2:
110 case 3:
111 if(ys <= y1)return;
112 }
113 }
114 }
115 }
116
117 extern int
118 quad(
119 int x,
120 int y,
121 int xp,
122 int yp
123 )
124 {
125 if(x < xp)
126 if(y <= yp)return(1);
127 else return(4);
128 else if(x > xp)
129 if(y < yp)return(2);
130 else return(3);
131 else if(y < yp)return(2);
132 else return(4);
133 }
134
135 extern int
136 abs_( /* Windows complains that abs() is an "internal function" */
137 int a
138 )
139 {
140 if(a < 0)return(-a);
141 return(a);
142 }