File: VDrawArc.c

package info (click to toggle)
acm 5.0-19
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 7,852 kB
  • ctags: 4,792
  • sloc: ansic: 42,427; makefile: 706; cpp: 293; perl: 280; sh: 198
file content (54 lines) | stat: -rw-r--r-- 1,055 bytes parent folder | download | duplicates (9)
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
#include "Vlib.h"

#define TICKtoRAD(a)	(a * M_PI / (180.0 * 64.0))
#define INCR		(30 * 64)

void
VDrawArc(Viewport * v, int x, int y, int width, int height, int angle1, int angle2, Color color)
{

	register ZInfo *z;
	register double w, h, xc, yc;
	register int incr, x1, x2, y1, y2;

	if (v->ztop == v->zsize) {
		fprintf(stderr, "Z-information pool overflow\n");
		return;
	}

	z = &(v->zpool[(v->ztop)++]);
	z->depth = --v->depth;
	z->color = color;

	w = width / 2.0;
	h = height / 2.0;
	xc = x + width / 2.0;
	yc = y + height / 2.0;

	if (angle2 < 0) {
		incr = -INCR;
		angle2 = -angle2;
	}
	else
		incr = INCR;

	if (angle2 > 360 * 64)
		angle2 = 360 * 64;

	x1 = (int) (xc + (w * cos(TICKtoRAD(angle1))));
	y1 = (int) (yc - (h * sin(TICKtoRAD(angle1))));

	while (angle2 != 0) {
		angle1 += incr;
		angle2 -= INCR;
		if (angle2 < 0) {
			angle1 -= angle2;
			angle2 = 0;
		}
		x2 = (int) (xc + (w * cos(TICKtoRAD(angle1))));
		y2 = (int) (yc - (h * sin(TICKtoRAD(angle1))));
		v->DrawLine(v, x1, y1, x2, y2, z->color);
		x1 = x2;
		y1 = y2;
	}
}