1*11974Sslatteng /* @(#)graphics2.c	1.2	04/18/83
211952Sslatteng  *
311952Sslatteng  * Copyright -C- 1982 Barry S. Roitblat
411952Sslatteng  *
511952Sslatteng  * This file contains more routines for implementing the graphics primitives
611952Sslatteng  * for the gremlin picture editor
711952Sslatteng  *
811952Sslatteng  * (Modified from software written by John Ousterhout for the caesar
911952Sslatteng  *  program)
1011952Sslatteng  */
1111952Sslatteng 
1211952Sslatteng #include "gremlin.h"
1311952Sslatteng #include "grem2.h"
1411952Sslatteng 
1511952Sslatteng /* imports from graphics1.c */
1611952Sslatteng 
1711952Sslatteng extern GRsetlinestyle(), GRsetcharstyle(), GRsetcharsize(),
1811952Sslatteng        GRsetpos(), GRoutxy20(), GRSetRead();
1911952Sslatteng extern FILE *display;
2011952Sslatteng extern int curx, cury, rmask, GrXMax, GrYMax, charysize, charxsize, descenders;
2111952Sslatteng 
2211952Sslatteng /* imports from main.c */
2311952Sslatteng 
2411952Sslatteng extern error();
2511952Sslatteng 
2611952Sslatteng /* The following is available to the outside world */
2711952Sslatteng 
2811952Sslatteng int artmode;
2911952Sslatteng 
GRVector(point1,point2,style)3011952Sslatteng GRVector(point1,point2,style)
3111952Sslatteng POINT *point1,*point2;
3211952Sslatteng int   style;
3311952Sslatteng {
3411952Sslatteng 	GRsetlinestyle(style);
3511952Sslatteng 	GRsetpos((int) point1->x,(int) point1->y);
3611952Sslatteng 	putc('A',display);       /* Draw vector absolute */
3711952Sslatteng 	GRoutxy20((int) point2->x,(int) point2->y);
3811952Sslatteng 	curx = point2->x;
3911952Sslatteng 	cury = point2->y;
4011952Sslatteng         (void) fflush(display);
4111952Sslatteng }
4211952Sslatteng 
43*11974Sslatteng 
RelativeVector(x,y)4411952Sslatteng static RelativeVector(x, y)
4511952Sslatteng float x, y;
4611952Sslatteng /*
4711952Sslatteng  *     This routine outputs the proper character sequence to the AED
4811952Sslatteng  * to draw a vector in the current line style and from the current position
4911952Sslatteng  * to the point (x, y).
5011952Sslatteng  */
5111952Sslatteng 
5211952Sslatteng {
5311952Sslatteng 	int nextx, nexty;
5411952Sslatteng 
5511952Sslatteng 	nextx = (int) x;
5611952Sslatteng 	nexty = (int) y;
5711952Sslatteng 
5811952Sslatteng 	putc('A', display);  /* draw vector absolute */
5911952Sslatteng 	GRoutxy20(nextx, nexty); /* output coordinates */
6011952Sslatteng 	curx = nextx;
6111952Sslatteng 	cury = nexty;
6211952Sslatteng }  /* end RelativeVector */
6311952Sslatteng 
64*11974Sslatteng 
6511952Sslatteng #define pi 3.14159265357
6611952Sslatteng #define log2_10 3.321915
6711952Sslatteng 
6811952Sslatteng int
GRArc(center,cpoint,angle,style)6911952Sslatteng GRArc(center,cpoint,angle,style)
7011952Sslatteng POINT *center, *cpoint;
7111952Sslatteng double angle;
7211952Sslatteng int   style;
7311952Sslatteng {
7411952Sslatteng 	double xs, ys, radius, resolution, t1, epsalon, fullcircle;
7511952Sslatteng 	double degreesperpoint;
7611952Sslatteng 	int    i, extent;
7711952Sslatteng 	POINT  next;
7811952Sslatteng 
7911952Sslatteng 	xs = cpoint->x - center->x;
8011952Sslatteng 	ys = cpoint->y - center->y;
8111952Sslatteng 	if ((xs == 0) && (ys == 0))       /* radius = 0 */
8211952Sslatteng 	{
8311952Sslatteng 		error("zero radius");
8411952Sslatteng 		return(-1);
8511952Sslatteng 	}
8611952Sslatteng 
8711952Sslatteng /* calculate drawing parameters */
8811952Sslatteng 
8911952Sslatteng 	radius = sqrt(xs * xs + ys * ys);
9011952Sslatteng 	t1 = floor(log10(radius) * log2_10);
9111952Sslatteng 	resolution = pow(2.0, t1);
9211952Sslatteng 	epsalon = 1.0 / resolution;
9311952Sslatteng 	fullcircle = ceil(2 * pi * resolution);
9411952Sslatteng 	degreesperpoint = 360.0 / fullcircle;
9511952Sslatteng 
9611952Sslatteng 	if (angle == 0)
9711952Sslatteng 	{
9811952Sslatteng 		extent = fullcircle;
9911952Sslatteng 		if ( (int) radius < 128)    /* manageable by AED hardware */
10011952Sslatteng 		{
10111952Sslatteng         		GRsetpos((int) center->x, (int) center->y);
10211952Sslatteng                 	GRsetlinestyle(style);
10311952Sslatteng 			putc('O',display);  /* draw circle */
10411952Sslatteng 			putc(((int) radius) &0377, display);
10511952Sslatteng 			return(0);
10611952Sslatteng 		}
10711952Sslatteng 	}
10811952Sslatteng 	else extent = angle/degreesperpoint;
10911952Sslatteng 
11011952Sslatteng         GRsetpos((int) cpoint->x, (int) cpoint->y);
11111952Sslatteng         GRsetlinestyle(style);
11211952Sslatteng 	for (i=0; i<extent; ++i)
11311952Sslatteng 	{
11411952Sslatteng 		xs -= epsalon * ys;
11511952Sslatteng 		next.x = xs + center->x ;   /* round */
11611952Sslatteng 		ys += epsalon * xs;
11711952Sslatteng 		next.y = ys + center->y ;   /* round */
11811952Sslatteng 		RelativeVector(next.x, next.y);
11911952Sslatteng 	}   /* end for */;
12011952Sslatteng 	return(0);
12111952Sslatteng }  /* end GRArc */;
12211952Sslatteng 
123*11974Sslatteng 
12411952Sslatteng #define MAXPOINTS 200
12511952Sslatteng 
Paramaterize(x,y,h,n)12611952Sslatteng static Paramaterize(x, y, h, n)
12711952Sslatteng float x[MAXPOINTS], y[MAXPOINTS], h[MAXPOINTS];
12811952Sslatteng int n;
12911952Sslatteng /*     This routine calculates parameteric values for use in calculating
13011952Sslatteng  * curves.  The parametric values are returned in the array u.  The values
13111952Sslatteng  * are an approximation of cumulative arc lengths of the curve (uses cord
13211952Sslatteng  * length).  For additional information, see paper cited below.
13311952Sslatteng  */
13411952Sslatteng 
13511952Sslatteng {
13611952Sslatteng 	int i,j;
13711952Sslatteng 	float u[MAXPOINTS];
13811952Sslatteng 
13911952Sslatteng 	for (i=1; i<=n; ++i)
14011952Sslatteng 	{
14111952Sslatteng 		u[i] = 0;
14211952Sslatteng 		for (j=1; j<i; ++j)
14311952Sslatteng 		{
14411952Sslatteng 			u[i] += sqrt(pow((double) (x[j+1] - x[j]), (double) 2.0)
14511952Sslatteng 			         + pow((double) (y[j+1] - y[j]), (double) 2.0));
14611952Sslatteng 		}
14711952Sslatteng 	}
14811952Sslatteng 	for (i=1; i<n; ++i)
14911952Sslatteng 		h[i] = u[i+1] - u[i];
15011952Sslatteng }  /* end Paramaterize */
15111952Sslatteng 
PeriodicSpline(h,z,dz,d2z,d3z,npoints)15211952Sslatteng static PeriodicSpline(h, z, dz, d2z, d3z, npoints)
15311952Sslatteng float h[MAXPOINTS], z[MAXPOINTS];	/* Point list and paramaterization  */
15411952Sslatteng float dz[MAXPOINTS];			/* to return the 1st derivative */
15511952Sslatteng float d2z[MAXPOINTS], d3z[MAXPOINTS];	/* 2nd and 3rd derivatives */
15611952Sslatteng int npoints;				/* number of valid points */
15711952Sslatteng /*
15811952Sslatteng  *     This routine solves for the cubic polynomial to fit a spline
15911952Sslatteng  * curve to the the points  specified by the list of values.
16011952Sslatteng  * The Curve generated is periodic.  The alogrithms for this
16111952Sslatteng  * curve are from the "Spline Curve Techniques" paper cited below.
16211952Sslatteng  */
16311952Sslatteng 
16411952Sslatteng {
16511952Sslatteng 	float d[MAXPOINTS];
16611952Sslatteng 	float deltaz[MAXPOINTS], a[MAXPOINTS], b[MAXPOINTS];
16711952Sslatteng 	float c[MAXPOINTS], r[MAXPOINTS], s[MAXPOINTS];
16811952Sslatteng 	int i;
16911952Sslatteng 
17011952Sslatteng 	            /* step 1 */
17111952Sslatteng 	for (i=1; i<npoints; ++i)
17211952Sslatteng 	{
17311952Sslatteng 		if (h[i] != 0)
17411952Sslatteng 			deltaz[i] = (z[i+1] - z[i]) / h[i];
17511952Sslatteng 		else
17611952Sslatteng 			deltaz[i] = 0;
17711952Sslatteng 	}
17811952Sslatteng 	h[0] = h[npoints-1];
17911952Sslatteng 	deltaz[0] = deltaz[npoints-1];
18011952Sslatteng 
18111952Sslatteng 	            /* step 2 */
18211952Sslatteng 	for (i=1; i<npoints-1; ++i)
18311952Sslatteng 	{
18411952Sslatteng 		d[i] = deltaz[i+1] - deltaz[i];
18511952Sslatteng 	}
18611952Sslatteng 	d[0] = deltaz[1] - deltaz[0];
18711952Sslatteng 
18811952Sslatteng 	            /* step 3a */
18911952Sslatteng 	a[1] = 2 * (h[0] + h[1]);
19011952Sslatteng 	if (a[1] == 0) return(-1);  /* 3 consecutive knots at same point */
19111952Sslatteng 	b[1] = d[0];
19211952Sslatteng 	c[1] = h[0];
19311952Sslatteng 	for (i=2; i<npoints-1; ++i)
19411952Sslatteng 	{
19511952Sslatteng 		a[i] = 2 * (h[i-1] + h[i]) - pow((double) h[i-1], (double) 2.0)
19611952Sslatteng 		            / a[i-1];
19711952Sslatteng 		if (a[i] == 0) return(-1);  /* 3 consec knots at same point */
19811952Sslatteng 		b[i] = d[i-1] - h[i-1] * b[i-1]/a[i-1];
19911952Sslatteng 		c[i] = -h[i-1] * c[i-1]/a[i-1];
20011952Sslatteng 	}
20111952Sslatteng 
20211952Sslatteng 	            /* step 3b */
20311952Sslatteng 	r[npoints-1] = 1;
20411952Sslatteng 	s[npoints-1] = 0;
20511952Sslatteng 	for (i=npoints-2; i>0; --i)
20611952Sslatteng 	{
20711952Sslatteng 		r[i] = -(h[i] * r[i+1] + c[i])/a[i];
20811952Sslatteng 		s[i] = (6 * b[i] - h[i] * s[i+1])/a[i];
20911952Sslatteng 	}
21011952Sslatteng 
21111952Sslatteng 	            /* step 4 */
21211952Sslatteng 	d2z[npoints-1] = (6 * d[npoints-2] - h[0] * s[1]
21311952Sslatteng 	                   - h[npoints-1] * s[npoints-2])
21411952Sslatteng 	                 / (h[0] * r[1] + h[npoints-1] * r[npoints-2]
21511952Sslatteng 	                    + 2 * (h[npoints-2] + h[0]));
21611952Sslatteng 	for (i=1; i<npoints-1; ++i)
21711952Sslatteng 	{
21811952Sslatteng 		d2z[i] = r[i] * d2z[npoints-1] + s[i];
21911952Sslatteng 	}
22011952Sslatteng 	d2z[npoints] = d2z[1];
22111952Sslatteng 
22211952Sslatteng 	            /* step 5 */
22311952Sslatteng 	for (i=1; i<npoints; ++i)
22411952Sslatteng 	{
22511952Sslatteng 		dz[i] = deltaz[i] - h[i] * (2 * d2z[i] + d2z[i+1])/6;
22611952Sslatteng 		if (h[i] != 0)
22711952Sslatteng 			d3z[i] = (d2z[i+1] - d2z[i])/h[i];
22811952Sslatteng 		else
22911952Sslatteng 			d3z[i] = 0;
23011952Sslatteng 	}
23111952Sslatteng 	return(0);
23211952Sslatteng }  /* end PeriodicSpline */
23311952Sslatteng 
234*11974Sslatteng 
NaturalEndSpline(h,z,dz,d2z,d3z,npoints)23511952Sslatteng static NaturalEndSpline(h, z, dz, d2z, d3z, npoints)
23611952Sslatteng float h[MAXPOINTS], z[MAXPOINTS];	/* Point list and parameterization */
23711952Sslatteng float dz[MAXPOINTS];			/* to return the 1st derivative */
23811952Sslatteng float d2z[MAXPOINTS], d3z[MAXPOINTS];	/* 2nd and 3rd derivatives */
23911952Sslatteng int npoints;				/* number of valid points */
24011952Sslatteng /*
24111952Sslatteng  *     This routine solves for the cubic polynomial to fit a spline
24211952Sslatteng  * curve the the points  specified by the list of values.  The alogrithms for
24311952Sslatteng  * this curve are from the "Spline Curve Techniques" paper cited below.
24411952Sslatteng  */
24511952Sslatteng 
24611952Sslatteng {
24711952Sslatteng 	float d[MAXPOINTS];
24811952Sslatteng 	float deltaz[MAXPOINTS], a[MAXPOINTS], b[MAXPOINTS];
24911952Sslatteng 	int i;
25011952Sslatteng 
25111952Sslatteng 	            /* step 1 */
25211952Sslatteng 	for (i=1; i<npoints; ++i)
25311952Sslatteng 	{
25411952Sslatteng 		if (h[i] != 0)
25511952Sslatteng 			deltaz[i] = (z[i+1] - z[i]) / h[i];
25611952Sslatteng 		else
25711952Sslatteng 			deltaz[i] = 0;
25811952Sslatteng 	}
25911952Sslatteng 	deltaz[0] = deltaz[npoints-1];
26011952Sslatteng 
26111952Sslatteng 	            /* step 2 */
26211952Sslatteng 	for (i=1; i<npoints-1; ++i)
26311952Sslatteng 	{
26411952Sslatteng 		d[i] = deltaz[i+1] - deltaz[i];
26511952Sslatteng 	}
26611952Sslatteng 	d[0] = deltaz[1] - deltaz[0];
26711952Sslatteng 
26811952Sslatteng 	            /* step 3 */
26911952Sslatteng 	a[0] = 2 * (h[2] + h[1]);
27011952Sslatteng 	if (a[0] == 0) return(-1);  /* 3 consec knots at same point */
27111952Sslatteng 	b[0] = d[1];
27211952Sslatteng 	for (i=1; i<npoints-2; ++i)
27311952Sslatteng 	{
27411952Sslatteng 		a[i] = 2 * (h[i+1] + h[i+2]) - pow((double) h[i+1],(double) 2.0)
27511952Sslatteng 		             / a[i-1];
27611952Sslatteng 		if (a[i] == 0) return(-1);  /* 3 consec knots at same point */
27711952Sslatteng 		b[i] = d[i+1] - h[i+1] * b[i-1]/a[i-1];
27811952Sslatteng 	}
27911952Sslatteng 
28011952Sslatteng 	            /* step 4 */
28111952Sslatteng 	d2z[npoints] = d2z[1] = 0;
28211952Sslatteng 	for (i=npoints-1; i>1; --i)
28311952Sslatteng 	{
28411952Sslatteng 		d2z[i] = (6 * b[i-2] - h[i] *d2z[i+1])/a[i-2];
28511952Sslatteng 	}
28611952Sslatteng 
28711952Sslatteng 	            /* step 5 */
28811952Sslatteng 	for (i=1; i<npoints; ++i)
28911952Sslatteng 	{
29011952Sslatteng 		dz[i] = deltaz[i] - h[i] * (2 * d2z[i] + d2z[i+1])/6;
29111952Sslatteng 		if (h[i] != 0)
29211952Sslatteng 			d3z[i] = (d2z[i+1] - d2z[i])/h[i];
29311952Sslatteng 		else
29411952Sslatteng 			d3z[i] = 0;
29511952Sslatteng 	}
29611952Sslatteng 	return(0);
29711952Sslatteng }  /* end NaturalEndSpline */
29811952Sslatteng 
299*11974Sslatteng 
30011952Sslatteng #define PointsPerInterval 16
30111952Sslatteng 
GRCurve(pointlist,style)30211952Sslatteng GRCurve(pointlist,style)
30311952Sslatteng POINT *pointlist;
30411952Sslatteng int   style;
30511952Sslatteng /*
30611952Sslatteng  *    This routine generates a smooth curve through a set of points.  The
30711952Sslatteng  * method used is the parametric spline curve on unit knot mesh described
30811952Sslatteng  * in "Spline Curve Techniques" by Patrick Baudelaire, Robert Flegal, and
30911952Sslatteng  * Robert Sproull -- Xerox Parc.
31011952Sslatteng  */
31111952Sslatteng {
31211952Sslatteng 	float h[MAXPOINTS];
31311952Sslatteng 	float x[MAXPOINTS], y[MAXPOINTS], dx[MAXPOINTS], dy[MAXPOINTS];
31411952Sslatteng 	float d2x[MAXPOINTS], d2y[MAXPOINTS], d3x[MAXPOINTS], d3y[MAXPOINTS];
31511952Sslatteng 	float t, t2, t3, xinter, yinter;
31611952Sslatteng 	POINT *ptr;
31711952Sslatteng 	int numpoints, i, j, k, stat;
31811952Sslatteng 
31911952Sslatteng 	GRsetlinestyle(style);
32011952Sslatteng 	GRsetpos((int) pointlist->x, (int) pointlist->y);
32111952Sslatteng 
32211952Sslatteng               /* Copy point list to array for easier access */
32311952Sslatteng 
32411952Sslatteng 	ptr = pointlist;
32511952Sslatteng 	for (i=1; (!Nullpoint(ptr)); ++i)
32611952Sslatteng 	{
32711952Sslatteng 		x[i] = ptr->x;
32811952Sslatteng 		y[i] = ptr->y;
32911952Sslatteng 		if (i >= MAXPOINTS - 1) break;
33011952Sslatteng 		ptr = PTNextPoint(ptr);
33111952Sslatteng 	}
33211952Sslatteng 
33311952Sslatteng 	     /* Solve for derivatives of the curve at each point
33411952Sslatteng               * separately for x and y (parametric).
33511952Sslatteng 	      */
33611952Sslatteng 	numpoints = i - 1;
33711952Sslatteng 	Paramaterize(x, y, h, numpoints);
33811952Sslatteng   	stat = 0;
33911952Sslatteng 	if ((x[1] == x[numpoints]) && (y[1] == y[numpoints]))/* closed curve */
34011952Sslatteng 	{
34111952Sslatteng 		stat |= PeriodicSpline(h, x, dx, d2x, d3x, numpoints);
34211952Sslatteng 		stat |= PeriodicSpline(h, y, dy, d2y, d3y, numpoints);
34311952Sslatteng 	}
34411952Sslatteng 	else
34511952Sslatteng 	{
34611952Sslatteng 		stat |= NaturalEndSpline(h, x, dx, d2x, d3x, numpoints);
34711952Sslatteng 		stat |= NaturalEndSpline(h, y, dy, d2y, d3y, numpoints);
34811952Sslatteng 	}
34911952Sslatteng 	if (stat != 0) return(-1);  /* error occurred */
35011952Sslatteng 
35111952Sslatteng 	      /* generate the curve using the above information and
35211952Sslatteng 	       * PointsPerInterval vectors between each specified knot.
35311952Sslatteng 	       */
35411952Sslatteng 
35511952Sslatteng 	for (j=1; j<numpoints; ++j)
35611952Sslatteng 	{
35711952Sslatteng 		for (k=0; k<=PointsPerInterval; ++k)
35811952Sslatteng 		{
35911952Sslatteng 			t = (float) k * h[j] / (float) PointsPerInterval;
36011952Sslatteng 			t2 = t * t;
36111952Sslatteng 			t3 = t * t * t;
36211952Sslatteng 			xinter = x[j] + t * dx[j] + t2 * d2x[j]/2.0
36311952Sslatteng 			       + t3 * d3x[j]/6.0;
36411952Sslatteng 			yinter = y[j] + t * dy[j] + t2 * d2y[j]/2.0
36511952Sslatteng 			       + t3 * d3y[j]/6.0;
36611952Sslatteng 			RelativeVector(xinter, yinter);
36711952Sslatteng 		}  /* end for k */
36811952Sslatteng 	}  /* end for j */
36911952Sslatteng 	return(0);
37011952Sslatteng }  /* end GRCurve */
37111952Sslatteng 
37211952Sslatteng 
373*11974Sslatteng 
GRPutText(justify,point1,font,size,string,pos)37411952Sslatteng GRPutText(justify,point1,font,size,string,pos)
37511952Sslatteng int justify, font, size;
37611952Sslatteng POINT *point1, *pos;
37711952Sslatteng char string[];
37811952Sslatteng {
37911952Sslatteng 	int length, nchars, i;
38011952Sslatteng 
38111952Sslatteng 	GRsetcharstyle(font);
38211952Sslatteng 	GRsetcharsize(size);
38311952Sslatteng 	nchars = strlen(string);
38411952Sslatteng 	length = nchars * charxsize ;
38511952Sslatteng         switch (justify)
38611952Sslatteng 	{
38711952Sslatteng 		  case BOTLEFT:	pos->x = point1->x;
38811952Sslatteng 				pos->y = point1->y;
38911952Sslatteng 				break;
39011952Sslatteng 		  case BOTCENT:	pos->x = point1->x - (length/2);
39111952Sslatteng 				pos->y = point1->y;
39211952Sslatteng 				break;
39311952Sslatteng 		 case BOTRIGHT:	pos->x = point1->x - length;
39411952Sslatteng 				pos->y = point1->y;
39511952Sslatteng 				break;
39611952Sslatteng 		 case CENTLEFT:	pos->x = point1->x;
39711952Sslatteng 				pos->y = point1->y - (charysize/2);
39811952Sslatteng 				break;
39911952Sslatteng 		 case CENTCENT:	pos->x = point1->x - (length/2);
40011952Sslatteng 				pos->y = point1->y - (charysize/2);
40111952Sslatteng 				break;
40211952Sslatteng 		case CENTRIGHT:	pos->x = point1->x - length;
40311952Sslatteng 				pos->y = point1->y - (charysize/2);
40411952Sslatteng 				break;
40511952Sslatteng 		  case TOPLEFT:	pos->x = point1->x;
40611952Sslatteng 				pos->y = point1->y - charysize + descenders;
40711952Sslatteng 				break;
40811952Sslatteng 		  case TOPCENT:	pos->x = point1->x - (length/2);
40911952Sslatteng 				pos->y = point1->y - charysize + descenders;
41011952Sslatteng 				break;
41111952Sslatteng 		 case TOPRIGHT:	pos->x = point1->x - length;
41211952Sslatteng 				pos->y = point1->y - charysize + descenders;
41311952Sslatteng 				break;
41411952Sslatteng 	}
41511952Sslatteng 	if ((pos->x < 0) || ((pos->x + length - charxsize) > GrXMax))
41611952Sslatteng 	{
41711952Sslatteng 		TxPutMsg("\7string too long");
41811952Sslatteng 	}
41911952Sslatteng 	if (( pos->y + charysize ) > GrYMax )
42011952Sslatteng 		pos->y = GrYMax - charysize;
42111952Sslatteng 	if (pos->y < 0) pos->y = 0;
42211952Sslatteng 	GRsetpos((int) pos->x, (int) pos->y);
42311952Sslatteng 	putc('\6',display);    /* enter text mode */
42411952Sslatteng 	for ( i=0; i<nchars; ++i )
42511952Sslatteng 	{
42611952Sslatteng 		putc(string[i],display);
42711952Sslatteng 	}
42811952Sslatteng 	fputs("\33Q", display);  /* re-enter graphics mode */
42911952Sslatteng 	GRoutxy20(curx,cury);
43011952Sslatteng 	(void) fflush(display);
43111952Sslatteng } /* end PutText */;
43211952Sslatteng 
433*11974Sslatteng 
GRClear(mask)43411952Sslatteng GRClear(mask)
43511952Sslatteng int mask;
43611952Sslatteng /*
43711952Sslatteng  *      This routine clears the memory planes enabled by mask.
43811952Sslatteng  * The read mask is first set to avoid an annoying flash when the
43911952Sslatteng  * clear is performed.
44011952Sslatteng  */
44111952Sslatteng 
44211952Sslatteng {
44311952Sslatteng 	int savemask;
44411952Sslatteng 
44511952Sslatteng 	savemask = rmask;
44611952Sslatteng 	GRSetRead(rmask & ~mask);
44711952Sslatteng 	GRsetwmask(mask);
44811952Sslatteng 	putc('~',display);
44911952Sslatteng 	GRSetRead(savemask);
45011952Sslatteng 	(void) fflush(display);
45111952Sslatteng }  /* end GRClear */
45211952Sslatteng 
GRDisplayPoint(x,y,number,mark)45311952Sslatteng GRDisplayPoint(x, y, number, mark)
45411952Sslatteng int x, y, number, mark;
45511952Sslatteng /*
45611952Sslatteng  *      This routine displays a point on the screen.  The point is
45711952Sslatteng  * displayed as a '+' centered about the point (x,y) and followed by
45811952Sslatteng  * number.
45911952Sslatteng  */
46011952Sslatteng 
46111952Sslatteng {
46211952Sslatteng 	POINT p1, p2;
46311952Sslatteng 	int psize;
46411952Sslatteng 
46511952Sslatteng 	if (artmode) psize = 1;
46611952Sslatteng 	else psize = halfpoint;
46711952Sslatteng 	GRsetwmask(pointmask);
46811952Sslatteng 	p1.y = p2.y = y;
46911952Sslatteng 	p1.x = x - psize;
47011952Sslatteng 	p2.x = x + psize;
47111952Sslatteng 	GRVector(&p1, &p2, mark);
47211952Sslatteng 	p1.x = p2.x = x;
47311952Sslatteng 	p1.y = y - psize;
47411952Sslatteng 	p2.y = y + psize;
47511952Sslatteng 	GRVector(&p1, &p2, mark);
47611952Sslatteng 	if ( !artmode )
47711952Sslatteng 	{
47811952Sslatteng 		GRsetcharsize(pointchar);
47911952Sslatteng 		GRsetpos( (x + numspace), (y - charysize/2 + 1) );
48011952Sslatteng 		fprintf(display,"\6%d\33",number);
48111952Sslatteng 	}
48211952Sslatteng 	GRsetpos(x, y);
48311952Sslatteng 	(void) fflush(display);
48411952Sslatteng }  /* end DisplayPoint */
48511952Sslatteng 
48611952Sslatteng 
487*11974Sslatteng 
GRErasePoint(x,y,number)48811952Sslatteng GRErasePoint(x, y, number)
48911952Sslatteng int x, y, number;
49011952Sslatteng /*
49111952Sslatteng  *      This routine erases the specified point by redrawing it in the
49211952Sslatteng  * background color
49311952Sslatteng  */
49411952Sslatteng 
49511952Sslatteng {
49611952Sslatteng 	GRDisplayPoint(x, y, number, eraseany);
49711952Sslatteng }  /* end ErasePoint */
49811952Sslatteng 
49911952Sslatteng 
GRBlankPoints()50011952Sslatteng GRBlankPoints()
50111952Sslatteng /*
50211952Sslatteng  *      This routine clears all displayed points by clearing
50311952Sslatteng  * the memory plane they are written on.
50411952Sslatteng  */
50511952Sslatteng 
50611952Sslatteng {
50711952Sslatteng 	GRClear(pointmask);
50811952Sslatteng }  /* end BlankPoints */
509