xref: /csrg-svn/lib/libplot/t450/subr.c (revision 13374)
1*13374Ssam #ifndef lint
2*13374Ssam static char sccsid[] = "@(#)subr.c	4.1 (Berkeley) 06/27/83";
3*13374Ssam #endif
4*13374Ssam 
5*13374Ssam #include <stdio.h>
6*13374Ssam #include "con.h"
7*13374Ssam abval(q)
8*13374Ssam {
9*13374Ssam 	return (q>=0 ? q : -q);
10*13374Ssam }
11*13374Ssam 
12*13374Ssam xconv (xp)
13*13374Ssam {
14*13374Ssam 	/* x position input is -2047 to +2047, output must be 0 to PAGSIZ*HORZRES */
15*13374Ssam 	xp += 2048;
16*13374Ssam 	/* the computation is newx = xp*(PAGSIZ*HORZRES)/4096 */
17*13374Ssam 	return (xoffset + xp /xscale);
18*13374Ssam }
19*13374Ssam 
20*13374Ssam yconv (yp)
21*13374Ssam {
22*13374Ssam 	/* see description of xconv */
23*13374Ssam 	yp += 2048;
24*13374Ssam 	return (yp / yscale);
25*13374Ssam }
26*13374Ssam 
27*13374Ssam inplot()
28*13374Ssam {
29*13374Ssam 	spew (ESC);
30*13374Ssam 	spew(PLOTIN);
31*13374Ssam }
32*13374Ssam 
33*13374Ssam outplot()
34*13374Ssam {
35*13374Ssam 	spew(ESC);
36*13374Ssam 	spew(PLOTOUT);
37*13374Ssam 	fflush(stdout);
38*13374Ssam }
39*13374Ssam 
40*13374Ssam spew(ch)
41*13374Ssam {
42*13374Ssam 	if(ch == UP){
43*13374Ssam 		putc(ESC,stdout);
44*13374Ssam 		ch = DOWN;
45*13374Ssam 	}
46*13374Ssam 	putc(ch, stdout);
47*13374Ssam }
48*13374Ssam 
49*13374Ssam tobotleft ()
50*13374Ssam {
51*13374Ssam 	move(-2048,-2048);
52*13374Ssam }
53*13374Ssam reset()
54*13374Ssam {
55*13374Ssam 	signal(2,1);
56*13374Ssam 	outplot();
57*13374Ssam 	stty(OUTF,&ITTY);
58*13374Ssam 	exit();
59*13374Ssam }
60*13374Ssam 
61*13374Ssam float
62*13374Ssam dist2 (x1, y1, x2, y2)
63*13374Ssam {
64*13374Ssam 	float t,v;
65*13374Ssam 	t = x2-x1;
66*13374Ssam 	v = y1-y2;
67*13374Ssam 	return (t*t+v*v);
68*13374Ssam }
69*13374Ssam 
70*13374Ssam swap (pa, pb)
71*13374Ssam int *pa, *pb;
72*13374Ssam {
73*13374Ssam 	int t;
74*13374Ssam 	t = *pa;
75*13374Ssam 	*pa = *pb;
76*13374Ssam 	*pb = t;
77*13374Ssam }
78*13374Ssam movep (xg,yg)
79*13374Ssam {
80*13374Ssam 	int i,ch;
81*13374Ssam 	if((xg == xnow) && (yg == ynow))return;
82*13374Ssam 	/* if we need to go to left margin, just CR */
83*13374Ssam 	if (xg < xnow/2)
84*13374Ssam 	{
85*13374Ssam 		spew(CR);
86*13374Ssam 		xnow = 0;
87*13374Ssam 	}
88*13374Ssam 	i = (xg-xnow)/HORZRES;
89*13374Ssam 	if(xnow < xg)ch = RIGHT;
90*13374Ssam 	else ch = LEFT;
91*13374Ssam 	xnow += i*HORZRES;
92*13374Ssam 	i = abval(i);
93*13374Ssam 	while(i--)spew(ch);
94*13374Ssam 	i = abval(xg-xnow);
95*13374Ssam 	inplot();
96*13374Ssam 	while(i--) spew(ch);
97*13374Ssam 	outplot();
98*13374Ssam 	i=(yg-ynow)/VERTRES;
99*13374Ssam 	if(ynow < yg)ch = UP;
100*13374Ssam 	else ch = DOWN;
101*13374Ssam 	ynow += i*VERTRES;
102*13374Ssam 	i = abval(i);
103*13374Ssam 	while(i--)spew(ch);
104*13374Ssam 	i=abval(yg-ynow);
105*13374Ssam 	inplot();
106*13374Ssam 	while(i--)spew(ch);
107*13374Ssam 	outplot();
108*13374Ssam 	xnow = xg; ynow = yg;
109*13374Ssam }
110*13374Ssam 
111*13374Ssam xsc(xi){
112*13374Ssam 	int xa;
113*13374Ssam 	xa = (xi - obotx) * scalex + botx;
114*13374Ssam 	return(xa);
115*13374Ssam }
116*13374Ssam ysc(yi){
117*13374Ssam 	int ya;
118*13374Ssam 	ya = (yi - oboty) *scaley +boty;
119*13374Ssam 	return(ya);
120*13374Ssam }
121