File: DrawLine.c

package info (click to toggle)
acm4 4.7-18
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 4,776 kB
  • ctags: 1,621
  • sloc: ansic: 16,777; makefile: 364; sh: 31
file content (102 lines) | stat: -rw-r--r-- 1,850 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <Alib.h>
#include <stdio.h>

void DrawLine (w, x1, y1, x2, y2, zinfo)
AWindow	*w;
int	x1, y1, x2, y2;
ZInfo	*zinfo; {

	register int	t;
	register Edge	*e, *e1;

	zinfo->next = NotAnElement;

	if (ClipLine (w, &x1, &y1, &x2, &y2))
		return;

	if (y1 > y2) {
		t = x1;
		x1 = x2;
		x2 = t;
		t = y1;
		y1 = y2;
		y2 = t;
	}

	if ((x1 == x2) || (y1 == y2)) {

		if (w->EPTop >= w->EPSize - 1) {
			fprintf (stderr, "Edge Pool Overflow\n");
			return;
		}

		e = &(w->edgePool[(w->EPTop)++]);
		e1 = &(w->edgePool[(w->EPTop)++]);

		e->y2 = e1->y2 = y2 + 1;

#ifdef FLOAT_SLOPE
		if (x1 == x2)
			e->x1 = e1->x1 = x1;
		else {
			e->x1 = x1;
			e1->x1 = x2;
		}
		e->Dx = e1->Dx = 0;
#else
		if (x1 == x2)
			e->x1 = e1->x1 = x1 << 16;
		else {
			e->x1 = x1 << 16;
			e1->x1 = x2 << 16;
		}
		e->Dx = e1->Dx = 0;
#endif
		e->p = e1->p = zinfo;

		e1->nexte = w->edges[y1].head;
		e->nexte = e1;
		w->edges[y1].head = e;
	}

/*
 *  A non-trivial case.  The has a slope that is non-zero and not infinity.
 *  We will need one edge entry to hang off the line list at the strting y
 *  value of the line.  We will also pre-allocate two edge entries to be used
 *  as the line'e edges during the EdgeTableToScanLine procedure.  By our own
 *  convention, we'll place them in the two edge pool entries immediately
 *  following the line information entry. 
 */

	else {

		if (w->EPTop >= w->EPSize - 2) {
			fprintf (stderr, "Edge Pool Overflow\n");
			return;
		}

		e = &(w->edgePool[(w->EPTop)++]);
		w->EPTop += 2;

		e->y2 = y2;

#ifdef FLOAT_SLOPE
		e->x1 = x1;
		e->Dx = (x2 - x1) / (y2 - y1);
#else
		e->x1 = x1 << 16;
		e->Dx = ((x2 - x1) << 16) / (y2 - y1);
#endif

		e->p = (e+1)->p = (e+2)->p = zinfo;

		e->nexte = w->lines[y1].head;
		w->lines[y1].head = e;
	}

	if (y1 < w->ymin)
		w->ymin = y1;

	if (y2 > w->ymax)
		w->ymax = y2;
}