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