|
|
1.1 root 1: #include <stdio.h>
2: #include "pic.h"
3: #include "y.tab.h"
4:
5: obj *circgen(type)
6: {
7: static float rad[2] = { HT2, WID2 };
8: static float rad2[2] = { HT2, HT2 };
9: static float x0, y0, x1, y1, x2, y2;
10: int i, at, t, invis, ddtype, with;
11: float xwith, ywith;
12: float r, r2, ddval;
13: obj *p, *ppos;
14: Attr *ap;
15:
16: at = invis = ddtype = 0;
17: with = xwith = ywith = 0;
18: t = (type == CIRCLE) ? 0 : 1;
19: if (type == CIRCLE)
20: r = r2 = getfval("circlerad");
21: else if (type == ELLIPSE) {
22: r = getfval("ellipsewid") / 2;
23: r2 = getfval("ellipseht") / 2;
24: }
25: for (i = 0; i < nattr; i++) {
26: ap = &attr[i];
27: switch (ap->a_type) {
28: case TEXTATTR:
29: savetext(ap->a_sub, ap->a_val.p);
30: break;
31: case RADIUS:
32: r = ap->a_val.f;
33: break;
34: case DIAMETER:
35: case WIDTH:
36: r = ap->a_val.f / 2;
37: break;
38: case HEIGHT:
39: r2 = ap->a_val.f / 2;
40: break;
41: case SAME:
42: r = rad[t];
43: r2 = rad2[t];
44: break;
45: case WITH:
46: with = ap->a_val.i;
47: break;
48: case AT:
49: ppos = ap->a_val.o;
50: curx = ppos->o_x;
51: cury = ppos->o_y;
52: at++;
53: break;
54: case INVIS:
55: invis = INVIS;
56: break;
57: case DOT:
58: case DASH:
59: ddtype = ap->a_type==DOT ? DOTBIT : DASHBIT;
60: if (ap->a_sub == DEFAULT)
61: ddval = getfval("dashwid");
62: else
63: ddval = ap->a_val.f;
64: break;
65: }
66: }
67: if (type == CIRCLE)
68: r2 = r; /* probably superfluous */
69: if (with) {
70: switch (with) {
71: case NORTH: ywith = -r2; break;
72: case SOUTH: ywith = r2; break;
73: case EAST: xwith = -r; break;
74: case WEST: xwith = r; break;
75: case NE: xwith = -r * 0.707; ywith = -r2 * 0.707; break;
76: case SE: xwith = -r * 0.707; ywith = r2 * 0.707; break;
77: case NW: xwith = r * 0.707; ywith = -r2 * 0.707; break;
78: case SW: xwith = r * 0.707; ywith = r2 * 0.707; break;
79: }
80: curx += xwith;
81: cury += ywith;
82: }
83: if (!at) {
84: if (isright(hvmode))
85: curx += r;
86: else if (isleft(hvmode))
87: curx -= r;
88: else if (isup(hvmode))
89: cury += r2;
90: else
91: cury -= r2;
92: }
93: p = makenode(type, 2);
94: p->o_val[0] = rad[t] = r;
95: p->o_val[1] = rad2[t] = r2;
96: if (r <= 0 || r2 <= 0) {
97: yyerror("%s has invalid radius %g\n", (type==CIRCLE) ? "circle" : "ellipse", r<r2 ? r : r2);
98: }
99: p->o_attr = invis | ddtype;
100: extreme(curx+r, cury+r2);
101: extreme(curx-r, cury-r2);
102: if (type == CIRCLE)
103: dprintf("C %g %g %g\n", curx, cury, r);
104: if (type == ELLIPSE)
105: dprintf("E %g %g %g %g\n", curx, cury, r, r2);
106: if (isright(hvmode))
107: curx += r;
108: else if (isleft(hvmode))
109: curx -= r;
110: else if (isup(hvmode))
111: cury += r2;
112: else
113: cury -= r2;
114: return(p);
115: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.