DataMuseum.dk

Presents historical artifacts from the history of:

ICL Comet 32

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about ICL Comet 32

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download

⟦fa64131d6⟧ TextFile

    Length: 6899 (0x1af3)
    Types: TextFile
    Notes: UNIX file
    Names: »cclipper.c«

Derivation

└─⟦26887b7e0⟧ Bits:30009717 Comet 32 harddisk image
    └─⟦28c352965⟧ »/a« UNIX Filesystem
        └─⟦this⟧ »usr/src/gks/comet/cclipper.c« 

TextFile

#include "../h/vdi.h"
#include "../h/vdii.h"

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* dt1clp      - Set the settable clipping boundary.
*
* rwsimon     - 21 Sep 82
*
* Environment - Computer-independent, system-independent, C, vdi.
*               Tektronix 4010 series, non-required.
*
* Input       - cl = clipping boundary.  Range: NDC.
*
* Process     - 
*
* Output      - 
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
dt1clp(cl)
Nrect	*cl;
{	ws->curc = *cl;

	/* Update the actual clipping boundary.*/
	t1cclp();
}


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* dt1cli      - Set clipping indicator.
*
* rwsimon     - 23 Sep 82
*               1 Feb 84 - Need to recompute the clipping boundary
*                          when the clipping indicator changes.
*
* Environment - Computer-independent, system-independent, C, vdi.
*               Tektronix 4010 series, non-required.
*
* Input       - in = clipping indicator.
*
* Process     - 
*
* Output      - 
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
dt1cli(in)
Bool	in;
{	ws->clpin = in;
	t1cclp();
}


#define	min(a,b)	((a) < (b)) ? (a) : (b)
#define max(a,b)	((a) > (b)) ? (a) : (b)

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* t1cclp     - Update the actual clipping boundary.
*
* rwsimon     - 21 Sep 82
*
* Environment - Computer-independent, system-independent, C, vdi.
*               Tektronix 4010 series, non-required.
*
* Input       - 
*
* Process     - 
*
* Output      - 
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
t1cclp()
{	Nrect	pp;	/* Clipping boundary in VDC.*/

	if (ws->clpin == TRUE)
	{	/* Compute the intersection of the settable clipping boundary
		   and the workstation window.*/
		pp.n_ll.n_x = max(ws->curc.n_ll.n_x, ws->ws_curw.n_ll.n_x);
		pp.n_ll.n_y = max(ws->curc.n_ll.n_y, ws->ws_curw.n_ll.n_y);
		pp.n_ur.n_x = min(ws->curc.n_ur.n_x, ws->ws_curw.n_ur.n_x);
		pp.n_ur.n_y = min(ws->curc.n_ur.n_y, ws->ws_curw.n_ur.n_y);
	}
	else
	{	/* Just use the workstation window.*/
		pp = ws->ws_curw;
	}

	/* Transform clipping boundary from VDC to AC.*/
	t1wstr(pp.n_ll, &(ws->clip.a_ll));
	t1wstr(pp.n_ur, &(ws->clip.a_ur));
}


typedef	union
{	struct
	{	unsigned	left   : 1;
		unsigned	right  : 1;
		unsigned	bottom : 1;
		unsigned	top    : 1;
	} bits;
	int	word;
} Edgeset;


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* t1clln     - Clip a line and output it.
*
* rwsimon     - 20 Sep 82
*
* Environment - Computer-independent, system-independent, C, vdi.
*               Tektronix 4010 series, non-required.
*
* Input       - p1, p2 = endpoints of the line.  Range: AC.
*
* Process     - Use clipping algorithm from Newman & Sproull, pp. 65-67.
*
* Output      - 
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
t1clln(p1, p2)
Ac	p1, p2;
{	Edgeset	c, c1, c2;
	Ac	q;

	/* Find which clipping boundaries each point lies outside.*/
	c1.word = t1code(p1);
	c2.word = t1code(p2);

	/* Keep subdividing the line at clipping boundaries until both
	   endpoints are inside all boundaries.*/
	while ((c1.word != 0) || (c2.word != 0))
	{	/* If both points lie outside the same edge, none of
		   the line is visible.*/
		if ((c1.word & c2.word) != 0)
			return;

		/* Get a point that is outside.*/
		c.word = c1.word;
		if (c.word == 0)
			c.word = c2.word;

		/* Crosses left edge?*/
		if (c.left == 1)
		{	q.a_y = p1.a_y + (Int)((Real)(p2.a_y - p1.a_y)*
			    (Real)(ws->clip.a_ll.a_x - p1.a_x)/
			    (Real)(p2.a_x - p1.a_x));
			q.a_x = ws->clip.a_ll.a_x;
		}

		/* Crosses right edge?*/
		else if (c.right == 1)
		{	q.a_y = p1.a_y + (Int)((Real)(p2.a_y - p1.a_y)*
			    (Real)(ws->clip.a_ur.a_x - p1.a_x)/
			    (Real)(p2.a_x - p1.a_x));
			q.a_x = ws->clip.a_ur.a_x;
		}

		/* Crosses bottom edge?*/
		else if (c.bottom == 1)
		{	q.a_x = p1.a_x + (Int)((Real)(p2.a_x - p1.a_x)*
			    (Real)(ws->clip.a_ll.a_y - p1.a_y)/
			    (Real)(p2.a_y - p1.a_y));
			q.a_y = ws->clip.a_ll.a_y;
		}

		/* Crosses top edge?*/
		else if (c.top == 1)
		{	q.a_x = p1.a_x + (Int)((Real)(p2.a_x - p1.a_x)*
			    (Real)(ws->clip.a_ur.a_y - p1.a_y)/
			    (Real)(p2.a_y - p1.a_y));
			q.a_y = ws->clip.a_ur.a_y;
		}

		/* Update code for newly computed point.*/
		if (c.word == c1.word)
		{	p1 = q;
			c1.word = t1code(p1);
		}
		else
		{	p2 = q;
			c2.word = t1code(p2);
		}
	}
#if DBG > 0
	printf("call line\n");
#endif
	/* If we reach here, the line from p1 to p2 is visible.*/
	line(&p1, &p2);
}


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* t1code     - Code a point's position relative to each clipping boundary.
*
* rwsimon     - 20 Sep 82
*
* Environment - Computer-independent, system-independent, C, vdi.
*               Tektronix 4010 series, non-required.
*
* Input       - p = the point.  Range: AC.
*
* Process     - Use clipping algorithm from Newman & Sproull, pp. 65-67.
*
* Output      - 
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
t1code(p)
Ac	p;
{	Edgeset	c;

	c.word = 0;
	if (p.a_x < ws->clip.a_ll.a_x)
		c.left = 1;
	else if (p.a_x > ws->clip.a_ur.a_x)
		c.right = 1;

	if (p.a_y < ws->clip.a_ll.a_y)
		c.bottom = 1;
	else if (p.a_y > ws->clip.a_ur.a_y)
		c.top = 1;

	return (c.word);
}


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* t1clpt     - Clip a point and output it.
*
* rwsimon     - 20 Sep 82
*
* Environment - Computer-independent, system-independent, C, vdi.
*               Tektronix 4010 series, non-required.
*
* Input       - p = the point.  Range: AC.
*
* Process     - 
*
* Output      - 
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
t1clpt(p)
Ac	p;
{	/* If point lies inside all clipping boundaries, send it to device.*/
	if (t1code(p) == 0)
		plott(&p);
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* t1clch     - Clip a character and output it.
*
* rwsimon     - 20 Sep 82
*
* Environment - Computer-independent, system-independent, C, vdi.
*               Tektronix 4010 series, non-required.
*
* Input       - p = point at which character is to be output.  Range: AC.
*               ch = character to output.
*
* Process     - 
*
* Output      - 
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
t1clch(p, ch)
Ac	p;
char	ch;
{	Ac	r, q;	/* Lower left and upper right corners of character.*/

	/* Allow 1/4 of the total height for descenders.*/
	r.a_x = p.a_x;
	r.a_y = p.a_y + ws->csz.a_y - ws->csp.a_y;

	/* If lower left and upper right corners of character are inside
	   all clipping boundaries, then send it to the terminal.*/
	if (t1code(r) == 0)
	{	q.a_x = r.a_x + ws->csp.a_x;
		q.a_y = r.a_y + ws->csp.a_y;
	 	if (t1code(q) == 0)
			paintchar(&p, ch);
	}
}