improved automake config. make dist, VPATH builds, ...
[btb/d2x.git] / 2d / circle.c
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
11 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14 #ifdef RCS
15 static char rcsid[] = "$Id: circle.c,v 1.1.1.1 2001-01-19 03:29:57 bradleyb Exp $";
16 #endif
17
18 #include <conf.h>
19 #include "u_mem.h"
20
21 #include "gr.h"
22 #include "grdef.h"
23
24 #ifndef OGL
25
26 int gr_circle(fix xc1,fix yc1,fix r1)
27 {
28         int p,x, y, xc, yc, r;
29
30         r = f2i(r1);
31         xc = f2i(xc1);
32         yc = f2i(yc1);
33         p=3-(r*2);
34         x=0;
35         y=r;
36
37         // Big clip
38         if ( (xc+r) < 0 ) return 1;
39         if ( (xc-r) > GWIDTH ) return 1;
40         if ( (yc+r) < 0 ) return 1;
41         if ( (yc-r) > GHEIGHT ) return 1;
42
43         while(x<y)
44         {
45                 // Draw the first octant
46                 gr_pixel( xc-y, yc-x );
47                 gr_pixel( xc+y, yc-x );
48                 gr_pixel( xc-y, yc+x );
49                 gr_pixel( xc+y, yc+x );
50
51                 if (p<0) 
52                         p=p+(x<<2)+6;
53                 else    {
54                         // Draw the second octant
55                         gr_pixel( xc-x, yc-y );
56                         gr_pixel( xc+x, yc-y );
57                         gr_pixel( xc-x, yc+y );
58                         gr_pixel( xc+x, yc+y );
59                         p=p+((x-y)<<2)+10;
60                         y--;
61                 }
62                 x++;
63         }
64         if(x==y)        {
65                 gr_pixel( xc-x, yc-y );
66                 gr_pixel( xc+x, yc-y );
67                 gr_pixel( xc-x, yc+y );
68                 gr_pixel( xc+x, yc+y );
69         }
70         return 0;
71 }
72
73 int gr_ucircle(fix xc1,fix yc1,fix r1)
74 {
75         int p,x, y, xc, yc, r;
76
77         r = f2i(r1);
78         xc = f2i(xc1);
79         yc = f2i(yc1);
80         p=3-(r*2);
81         x=0;
82         y=r;
83
84         while(x<y)
85         {
86                 // Draw the first octant
87                 gr_upixel( xc-y, yc-x );
88                 gr_upixel( xc+y, yc-x );
89                 gr_upixel( xc-y, yc+x );
90                 gr_upixel( xc+y, yc+x );
91
92                 if (p<0) 
93                         p=p+(x<<2)+6;
94                 else    {
95                         // Draw the second octant
96                         gr_upixel( xc-x, yc-y );
97                         gr_upixel( xc+x, yc-y );
98                         gr_upixel( xc-x, yc+y );
99                         gr_upixel( xc+x, yc+y );
100                         p=p+((x-y)<<2)+10;
101                         y--;
102                 }
103                 x++;
104         }
105         if(x==y)        {
106                 gr_upixel( xc-x, yc-y );
107                 gr_upixel( xc+x, yc-y );
108                 gr_upixel( xc-x, yc+y );
109                 gr_upixel( xc+x, yc+y );
110         }
111         return 0;
112 }
113
114 #endif //!OGL