xref: /original-bsd/lib/libplot/dumb/subr.c (revision 333da485)
1 /*-
2  * Copyright (c) 1980, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.proprietary.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)subr.c	8.2 (Berkeley) 01/07/94";
10 #endif /* not lint */
11 
12 #include "dumb.h"
13 
14 /* Does not plot first point -- assumed that it is already plotted */
15 dda_line(ch, x0, y0, x1, y1)
16 	char ch;
17 	int x0, y0;	/* already transformed to screen coords */
18 	int x1, y1;	/* untransformed */
19 {
20 	int length, i;
21 	double deltaX, deltaY;
22 	double x, y;
23 
24 	scale(x1, y1);
25 
26 	length = abs(x1 - x0);
27 	if (abs(y1 -y0) > length)
28 		length = abs(y1 - y0);
29 
30 	if (length == 0)
31 		return;
32 
33 	deltaX = (double) (x1 - x0)/(double) length;
34 	deltaY = (double) (y1 - y0)/(double) length;
35 
36 	x = (double) x0 + 0.5;
37 	y = (double) y0 + 0.5;
38 
39 	for (i=0; i < length; ++i) {
40 		x += deltaX;
41 		y += deltaY;
42 		x0 = floor(x);
43 		y0 = floor(y);
44 		currentx = x0;
45 		currenty = y0;
46 		screenmat[currentx][currenty] = ch;
47 	}
48 }
49