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.
38 Symmetric Double Step Line Algorithm
40 from "Graphics Gems", Academic Press, 1990
43 /* non-zero flag indicates the pixels needing EXCHG back. */
44 void plot(int x,int y,int flag)
51 int gr_hline(int x1, int x2, int y)
54 if (x1 > x2) EXCHG(x1,x2);
55 for (i=x1; i<=x2; i++ )
60 int gr_vline(int y1, int y2, int x)
62 if (y1 > y2) EXCHG(y1,y2);
63 for (i=y1; i<=y2; i++ )
68 void gr_universal_uline(int a1, int b1, int a2, int b2)
70 int dx, dy, incr1, incr2, D, x, y, xend, c, pixels_left;
72 int sign_x = 1, sign_y = 1, step, reverse, i;
96 /* decide increment sign by the slope sign */
102 if (dy > dx) { /* chooses axis of greatest movement (make * dx) */
109 /* note error check for dx==0 should be included here */
110 if (a1 > a2) { /* start from the smaller coordinate */
123 /* Note dx=n implies 0 - n or (dx+1) pixels to be set */
124 /* Go round loop dx/4 times then plot last 0,1,2 or 3 pixels */
125 /* In fact (dx-1)/4 as 2 pixels are already plottted */
127 pixels_left = (dx - 1) % 4; /* number of pixels left over at the
130 plot(x1, y1, reverse); /* plot first two points */
131 incr2 = 4 * dy - 2 * dx;
132 if (incr2 < 0) { /* slope less than 1/2 */
137 for (i = 0; i < xend; i++) { /* plotting loop */
141 /* pattern 1 forwards */
143 plot(++x, y, reverse);
144 /* pattern 1 backwards */
145 plot(x1, y1, reverse);
146 plot(--x1, y1, reverse);
150 /* pattern 2 forwards */
152 plot(++x, y += step, reverse);
153 /* pattern 2 backwards */
154 plot(x1, y1, reverse);
155 plot(--x1, y1 -= step, reverse);
157 /* pattern 3 forwards */
158 plot(x, y += step, reverse);
159 plot(++x, y, reverse);
160 /* pattern 3 backwards */
161 plot(x1, y1 -= step, reverse);
162 plot(--x1, y1, reverse);
168 /* plot last pattern */
171 plot(++x, y, reverse); /* pattern 1 */
173 plot(++x, y, reverse);
175 plot(--x1, y1, reverse);
178 plot(++x, y, reverse); /* pattern 2 */
180 plot(++x, y += step, reverse);
182 plot(--x1, y1, reverse);
185 plot(++x, y += step, reverse);
187 plot(++x, y, reverse);
189 plot(--x1, y1 -= step, reverse);
192 } /* end if pixels_left */
194 /* end slope < 1/2 */
195 else { /* slope greater than 1/2 */
199 for (i = 0; i < xend; i++) {
203 /* pattern 4 forwards */
204 plot(x, y += step, reverse);
205 plot(++x, y += step, reverse);
206 /* pattern 4 backwards */
207 plot(x1, y1 -= step, reverse);
208 plot(--x1, y1 -= step, reverse);
212 /* pattern 2 forwards */
214 plot(++x, y += step, reverse);
216 /* pattern 2 backwards */
217 plot(x1, y1, reverse);
218 plot(--x1, y1 -= step, reverse);
220 /* pattern 3 forwards */
221 plot(x, y += step, reverse);
222 plot(++x, y, reverse);
223 /* pattern 3 backwards */
224 plot(x1, y1 -= step, reverse);
225 plot(--x1, y1, reverse);
230 /* plot last pattern */
233 plot(++x, y += step, reverse); /* pattern 4 */
235 plot(++x, y += step, reverse);
237 plot(--x1, y1 -= step, reverse);
240 plot(++x, y, reverse); /* pattern 2 */
242 plot(++x, y += step, reverse);
244 plot(--x1, y1, reverse);
247 plot(++x, y += step, reverse);
249 plot(++x, y, reverse);
250 if (pixels_left > 2) {
251 if (D > c) /* step 3 */
252 plot(--x1, y1 -= step, reverse);
254 plot(--x1, y1, reverse);
263 //unclipped version just calls clipping version for now
264 int gr_uline(fix _a1, fix _b1, fix _a2, fix _b2)
267 a1 = f2i(_a1); b1 = f2i(_b1); a2 = f2i(_a2); b2 = f2i(_b2);
272 ogl_ulinec(a1,b1,a2,b2,COLOR);
277 gr_universal_uline( a1,b1,a2,b2);
279 gr_linear_line( a1, b1, a2, b2 );
284 modex_line_x1 = a1+XOFFSET;
285 modex_line_y1 = b1+YOFFSET;
286 modex_line_x2 = a2+XOFFSET;
287 modex_line_y2 = b2+YOFFSET;
288 modex_line_Color = grd_curcanv->cv_color;
292 gr_universal_uline( a1, b1, a2, b2 );
299 // Returns 0 if drawn with no clipping, 1 if drawn but clipped, and
300 // 2 if not drawn at all.
302 int gr_line(fix a1, fix b1, fix a2, fix b2)
312 CLIPLINE(a1,b1,a2,b2,x1,y1,x2,y2,return 2,clipped=1, FSCALE );
314 gr_uline( a1, b1, a2, b2 );