xref: /original-bsd/lib/libplot/t300/line.c (revision 831e3f9f)
1 /*-
2  * Copyright (c) 1983 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.proprietary.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)line.c	4.3 (Berkeley) 02/10/93";
10 #endif /* not lint */
11 
12 #include "con.h"
13 line(x0,y0,x1,y1){
14 	iline(xconv(xsc(x0)),yconv(ysc(y0)),xconv(xsc(x1)),yconv(ysc(y1)));
15 		return;
16 }
17 cont(x0,y0){
18 	iline(xnow,ynow,xconv(xsc(x0)),yconv(ysc(y0)));
19 	return;
20 }
21 iline(cx0,cy0,cx1,cy1){
22 	int maxp,tt,j,np;
23 	char chx,chy;
24 	float xd,yd;
25 	double dist2(),sqrt();
26 		movep(cx0,cy0);
27 		maxp = sqrt(dist2(cx0,cy0,cx1,cy1))/2.;
28 		xd = cx1-cx0;
29 		yd = cy1-cy0;
30 		if(xd >= 0)chx = RIGHT;
31 		else chx = LEFT;
32 		if(yd >= 0)chy = UP;
33 		else chy = DOWN;
34 		if(maxp==0){
35 			xd=0;
36 			yd=0;
37 		}
38 		else{
39 			xd /= maxp;
40 			yd /= maxp;
41 		}
42 		inplot();
43 		for (tt=0; tt<=maxp; tt++){
44 			j= cx0+xd*tt-xnow;
45 			xnow += j;
46 			j = abval(j);
47 			while(j-- > 0)spew(chx);
48 			j = cy0+yd*tt-ynow;
49 			ynow += j;
50 			j = abval(j);
51 			while(j-- > 0)spew(chy);
52 			spew ('.');
53 		}
54 		outplot();
55 		return;
56 }
57