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