
/********************************************************/
/*							*/
/*	Line-Plotting Routines for MX-80 Graphics	*/
/*							*/
/*	Don Brittain		3 January 1983		*/
/*							*/
/********************************************************/

#define NO 0
#define YES 1
extern int horsize, versize, flag;
extern int pixplot(), unpixplot();


lineplot(x,y,h,v)	/* plots segment from (x,y) to (h,v) */

int x,y,h,v;

{
    if((x==h)&&(y==v)) noline(x,y);
    else
	if(abs(y-v)<abs(h-x))
	    if(x<h)
		horline(x,y,h,v);
	    else
		horline(h,v,x,y);
	else
	    if(y<v)
		vertline(x,y,h,v);
	    else
		vertline(h,v,x,y);
}


noline(x,y)	/* treats case where (x,y) = (h,v) */

int x,y;

{
    if(flag)
	pixplot(x,y);
    else
	unpixplot(x,y);
}


abs(x)		/* absolute-value function for integers */

int x;

{
    if(x>0)
	return(x);
    else
	return(-x);
}


horline(x,y,h,v) 	/* plots line having  abs(slope) <= 1  */
			/* assumes x < h   */
int x,y,h,v;

{
    register i;
    long k;
    short l;
    
    if(flag)
	for(i=x; i<=h; i++)	{
	    k=v;
	    k=(k-y)*(i-x);
	    l=k/(h-x)+y;
	    pixplot(i,l);	}
    else
	for(i=x; i<=h; i++)	{
	    k=v;
	    k=(k-y)*(i-x);
	    l=k/(h-x)+y;
	    unpixplot(i,l);	}
}

vertline(x,y,h,v)	/* plots line having abs(slope) >= 1 */
			/* assumes y < v */
int x,y,h,v;

{
    register i;
    long k;
    short l;
    
    if(flag)
	for(i=y; i<=v; i++)	{
	    k=h;
	    k=(k-x)*(i-y);
	    l=k/(v-y)+x;
	    pixplot(l,i);	}
    else
	for(i=y; i<=v; i++)	{
	    k=h;
	    k=(k-x)*(i-y);
	    l=k/(v-y)+x;
	    unpixplot(l,i);	}
    }
    
