File: circle.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 (105 lines) | stat: -rw-r--r-- 2,124 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
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
103
104
105
#include "gedit.h"
#include <math.h>

#define NUM_POINTS	12

extern polygon_t *BeginPolygon();
extern void PointToXYZ();

static point_t	drag;

void
ScaleCircle(p, poly, scale)
view_info_t	*p;
polygon_t	*poly;
double		scale;
{
	double a = 0.0, a_incr = M_PI * 2.0 / NUM_POINTS;
	double other = 0.0, ocos, osin;
	int i;

	for (i=0; i<NUM_POINTS; ++i) {

		osin = sin (a);
		ocos = cos (a);
		poly->point[i] = drag;
		switch (p->layout) {
		case VL_NYX:
		case VL_NXNY:
			poly->point[i].point.x += osin * scale;
			poly->point[i].point.y += ocos * scale;
			poly->point[i].point.z += other;
			break;
		case VL_NYZ:
			poly->point[i].point.x += other;
			poly->point[i].point.y += ocos * scale;
			poly->point[i].point.z += osin * scale;
			break;
		case VL_NXZ:
			poly->point[i].point.x += osin * scale;
			poly->point[i].point.y += other;
			poly->point[i].point.z += ocos * scale;		
			break;
		default:
			poly->point[i].point.x += osin * scale;
			poly->point[i].point.y += ocos * scale;
			poly->point[i].point.z += other;
			break;	
		}
		a += a_incr;	
		PointToXYZ (p, &poly->point[i]);
	}
	
	if (scale > 0.0) {
		ComputePlaneEquation (poly);
	}
}

void
BeginCirclePoint (w, p, x, y)
Widget	 w;
view_info_t	*p;
int	x, y;
{
	polygon_t *poly;
	
	poly = BeginPolygon();
	poly->num_points = NUM_POINTS;
	drag_origin.x = x;
	drag_origin.y = y;
	PointXY (w, p, x, y, &drag);
	ScaleCircle (p, poly, 0.0);
}

void
DragCirclePoint(w, p, x, y)
Widget	 w;
view_info_t	*p;
int	x, y;
{
	double dx = x - drag_origin.x, dy = y - drag_origin.y;
	double scale = sqrt (dx * dx + dy * dy) * pixel_scale;
	Display *dpy = XtDisplay(w);

	XSetFunction (dpy, p->gc, GXxor);
	XSetFunction (dpy, p->other_view->gc, GXxor);
	
	DrawPolygon (w, cur_polygon, True);
	DrawPolygon (p->other_widget, cur_polygon, True);

	ScaleCircle (p, cur_polygon, scale);
	DrawPolygon (w, cur_polygon, True);
	DrawPolygon (p->other_widget, cur_polygon, True);

	XSetFunction (dpy, p->gc, GXcopy);
	XSetFunction (dpy, p->other_view->gc, GXcopy);
}

void
CompleteCirclePoint(w, p, x, y)
Widget	 w;
view_info_t	*p;
int	x, y;
{
	CompletePolygon (w, cur_polygon);
}