148525Sbostic /*-
2*61412Sbostic * Copyright (c) 1983, 1993
3*61412Sbostic * The Regents of the University of California. All rights reserved.
448525Sbostic *
548525Sbostic * %sccs.include.proprietary.c%
648525Sbostic */
748525Sbostic
813374Ssam #ifndef lint
9*61412Sbostic static char sccsid[] = "@(#)subr.c 8.1 (Berkeley) 06/04/93";
1048525Sbostic #endif /* not lint */
1113374Ssam
1213374Ssam #include <stdio.h>
1313374Ssam #include "con.h"
abval(q)1413374Ssam abval(q)
1513374Ssam {
1613374Ssam return (q>=0 ? q : -q);
1713374Ssam }
1813374Ssam
xconv(xp)1913374Ssam xconv (xp)
2013374Ssam {
2113374Ssam /* x position input is -2047 to +2047, output must be 0 to PAGSIZ*HORZRES */
2213374Ssam xp += 2048;
2313374Ssam /* the computation is newx = xp*(PAGSIZ*HORZRES)/4096 */
2413374Ssam return (xoffset + xp /xscale);
2513374Ssam }
2613374Ssam
yconv(yp)2713374Ssam yconv (yp)
2813374Ssam {
2913374Ssam /* see description of xconv */
3013374Ssam yp += 2048;
3113374Ssam return (yp / yscale);
3213374Ssam }
3313374Ssam
inplot()3413374Ssam inplot()
3513374Ssam {
3613374Ssam spew (ESC);
3713374Ssam spew(PLOTIN);
3813374Ssam }
3913374Ssam
outplot()4013374Ssam outplot()
4113374Ssam {
4213374Ssam spew(ESC);
4313374Ssam spew(PLOTOUT);
4413374Ssam fflush(stdout);
4513374Ssam }
4613374Ssam
spew(ch)4713374Ssam spew(ch)
4813374Ssam {
4913374Ssam if(ch == UP){
5013374Ssam putc(ESC,stdout);
5113374Ssam ch = DOWN;
5213374Ssam }
5313374Ssam putc(ch, stdout);
5413374Ssam }
5513374Ssam
tobotleft()5613374Ssam tobotleft ()
5713374Ssam {
5813374Ssam move(-2048,-2048);
5913374Ssam }
reset()6013374Ssam reset()
6113374Ssam {
6213374Ssam signal(2,1);
6313374Ssam outplot();
6413374Ssam stty(OUTF,&ITTY);
6513374Ssam exit();
6613374Ssam }
6713374Ssam
6857887Storek double
dist2(x1,y1,x2,y2)6913374Ssam dist2 (x1, y1, x2, y2)
7013374Ssam {
7113374Ssam float t,v;
7213374Ssam t = x2-x1;
7313374Ssam v = y1-y2;
7413374Ssam return (t*t+v*v);
7513374Ssam }
7613374Ssam
swap(pa,pb)7713374Ssam swap (pa, pb)
7813374Ssam int *pa, *pb;
7913374Ssam {
8013374Ssam int t;
8113374Ssam t = *pa;
8213374Ssam *pa = *pb;
8313374Ssam *pb = t;
8413374Ssam }
movep(xg,yg)8513374Ssam movep (xg,yg)
8613374Ssam {
8713374Ssam int i,ch;
8813374Ssam if((xg == xnow) && (yg == ynow))return;
8913374Ssam /* if we need to go to left margin, just CR */
9013374Ssam if (xg < xnow/2)
9113374Ssam {
9213374Ssam spew(CR);
9313374Ssam xnow = 0;
9413374Ssam }
9513374Ssam i = (xg-xnow)/HORZRES;
9613374Ssam if(xnow < xg)ch = RIGHT;
9713374Ssam else ch = LEFT;
9813374Ssam xnow += i*HORZRES;
9913374Ssam i = abval(i);
10013374Ssam while(i--)spew(ch);
10113374Ssam i = abval(xg-xnow);
10213374Ssam inplot();
10313374Ssam while(i--) spew(ch);
10413374Ssam outplot();
10513374Ssam i=(yg-ynow)/VERTRES;
10613374Ssam if(ynow < yg)ch = UP;
10713374Ssam else ch = DOWN;
10813374Ssam ynow += i*VERTRES;
10913374Ssam i = abval(i);
11013374Ssam while(i--)spew(ch);
11113374Ssam i=abval(yg-ynow);
11213374Ssam inplot();
11313374Ssam while(i--)spew(ch);
11413374Ssam outplot();
11513374Ssam xnow = xg; ynow = yg;
11613374Ssam }
11713374Ssam
xsc(xi)11813374Ssam xsc(xi){
11913374Ssam int xa;
12013374Ssam xa = (xi - obotx) * scalex + botx;
12113374Ssam return(xa);
12213374Ssam }
ysc(yi)12313374Ssam ysc(yi){
12413374Ssam int ya;
12513374Ssam ya = (yi - oboty) *scaley +boty;
12613374Ssam return(ya);
12713374Ssam }
128