35 lines · 1.3 KB · C
RawDownload
/*  * This file is part of the UCB release of Plan 9. It is subject to the license * terms in the LICENSE file found in the top-level directory of this * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No * part of the UCB release of Plan 9, including this file, may be copied, * modified, propagated, or distributed except according to the terms contained * in the LICENSE file. */ #include "mplot.h"#define	code(x, y)	((x<clipminx?1:x>clipmaxx?2:0)|(y<clipminy?4:y>clipmaxy?8:0))void vec(double xx, double yy){	int x0, y0, x1, y1, c0, c1, c, tx, ty;	double t;	t=SCX(e1->copyx); if(fabs(t)>BIGINT) return; x0=t;	t=SCY(e1->copyy); if(fabs(t)>BIGINT) return; y0=t;	t=SCX(xx); if(fabs(t)>BIGINT) return; x1=t;	t=SCY(yy); if(fabs(t)>BIGINT) return; y1=t;	e1->copyx=xx;	e1->copyy=yy;	/* clipping -- what a concept */	c0=code(x0, y0);	c1=code(x1, y1);	while(c0|c1){		if(c0&c1) return;		c=c0?c0:c1;		if(c&1)      ty=y0+(y1-y0)*(clipminx-x0)/(x1-x0), tx=clipminx;		else if(c&2) ty=y0+(y1-y0)*(clipmaxx-x0)/(x1-x0), tx=clipmaxx;		else if(c&4) tx=x0+(x1-x0)*(clipminy-y0)/(y1-y0), ty=clipminy;		else         tx=x0+(x1-x0)*(clipmaxy-y0)/(y1-y0), ty=clipmaxy;		if(c==c0) x0=tx, y0=ty, c0=code(x0, y0);		else      x1=tx, y1=ty, c1=code(x1, y1);	}	m_vector(x0, y0, x1, y1, e1->foregr);}