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.
14 * Graphical routines for drawing lines.
41 Symmetric Double Step Line Algorithm
43 from "Graphics Gems", Academic Press, 1990
46 /* non-zero flag indicates the pixels needing EXCHG back. */
47 void plot(int x,int y,int flag)
54 int gr_hline(int x1, int x2, int y)
57 if (x1 > x2) EXCHG(x1,x2);
58 for (i=x1; i<=x2; i++ )
63 int gr_vline(int y1, int y2, int x)
65 if (y1 > y2) EXCHG(y1,y2);
66 for (i=y1; i<=y2; i++ )
71 void gr_universal_uline(int a1, int b1, int a2, int b2)
73 int dx, dy, incr1, incr2, D, x, y, xend, c, pixels_left;
75 int sign_x = 1, sign_y = 1, step, reverse, i;
99 /* decide increment sign by the slope sign */
100 if (sign_x == sign_y)
105 if (dy > dx) { /* chooses axis of greatest movement (make * dx) */
112 /* note error check for dx==0 should be included here */
113 if (a1 > a2) { /* start from the smaller coordinate */
126 /* Note dx=n implies 0 - n or (dx+1) pixels to be set */
127 /* Go round loop dx/4 times then plot last 0,1,2 or 3 pixels */
128 /* In fact (dx-1)/4 as 2 pixels are already plottted */
130 pixels_left = (dx - 1) % 4; /* number of pixels left over at the
133 plot(x1, y1, reverse); /* plot first two points */
134 incr2 = 4 * dy - 2 * dx;
135 if (incr2 < 0) { /* slope less than 1/2 */
140 for (i = 0; i < xend; i++) { /* plotting loop */
144 /* pattern 1 forwards */
146 plot(++x, y, reverse);
147 /* pattern 1 backwards */
148 plot(x1, y1, reverse);
149 plot(--x1, y1, reverse);
153 /* pattern 2 forwards */
155 plot(++x, y += step, reverse);
156 /* pattern 2 backwards */
157 plot(x1, y1, reverse);
158 plot(--x1, y1 -= step, reverse);
160 /* pattern 3 forwards */
161 plot(x, y += step, reverse);
162 plot(++x, y, reverse);
163 /* pattern 3 backwards */
164 plot(x1, y1 -= step, reverse);
165 plot(--x1, y1, reverse);
171 /* plot last pattern */
174 plot(++x, y, reverse); /* pattern 1 */
176 plot(++x, y, reverse);
178 plot(--x1, y1, reverse);
181 plot(++x, y, reverse); /* pattern 2 */
183 plot(++x, y += step, reverse);
185 plot(--x1, y1, reverse);
188 plot(++x, y += step, reverse);
190 plot(++x, y, reverse);
192 plot(--x1, y1 -= step, reverse);
195 } /* end if pixels_left */
197 /* end slope < 1/2 */
198 else { /* slope greater than 1/2 */
202 for (i = 0; i < xend; i++) {
206 /* pattern 4 forwards */
207 plot(x, y += step, reverse);
208 plot(++x, y += step, reverse);
209 /* pattern 4 backwards */
210 plot(x1, y1 -= step, reverse);
211 plot(--x1, y1 -= step, reverse);
215 /* pattern 2 forwards */
217 plot(++x, y += step, reverse);
219 /* pattern 2 backwards */
220 plot(x1, y1, reverse);
221 plot(--x1, y1 -= step, reverse);
223 /* pattern 3 forwards */
224 plot(x, y += step, reverse);
225 plot(++x, y, reverse);
226 /* pattern 3 backwards */
227 plot(x1, y1 -= step, reverse);
228 plot(--x1, y1, reverse);
233 /* plot last pattern */
236 plot(++x, y += step, reverse); /* pattern 4 */
238 plot(++x, y += step, reverse);
240 plot(--x1, y1 -= step, reverse);
243 plot(++x, y, reverse); /* pattern 2 */
245 plot(++x, y += step, reverse);
247 plot(--x1, y1, reverse);
250 plot(++x, y += step, reverse);
252 plot(++x, y, reverse);
253 if (pixels_left > 2) {
254 if (D > c) /* step 3 */
255 plot(--x1, y1 -= step, reverse);
257 plot(--x1, y1, reverse);
266 //unclipped version just calls clipping version for now
267 int gr_uline(fix _a1, fix _b1, fix _a2, fix _b2)
270 a1 = f2i(_a1); b1 = f2i(_b1); a2 = f2i(_a2); b2 = f2i(_b2);
275 ogl_ulinec(a1,b1,a2,b2,COLOR);
280 gr_universal_uline( a1,b1,a2,b2);
282 gr_linear_line( a1, b1, a2, b2 );
287 modex_line_x1 = a1+XOFFSET;
288 modex_line_y1 = b1+YOFFSET;
289 modex_line_x2 = a2+XOFFSET;
290 modex_line_y2 = b2+YOFFSET;
291 modex_line_Color = grd_curcanv->cv_color;
295 gr_universal_uline( a1, b1, a2, b2 );
302 // Returns 0 if drawn with no clipping, 1 if drawn but clipped, and
303 // 2 if not drawn at all.
305 int gr_line(fix a1, fix b1, fix a2, fix b2)
315 CLIPLINE(a1,b1,a2,b2,x1,y1,x2,y2,return 2,clipped=1, FSCALE );
317 gr_uline( a1, b1, a2, b2 );