|
|
1.1 ! root 1: #include "ideal.h" ! 2: #include "y.tab.h" ! 3: ! 4: void linecall (linefax) ! 5: LINEPTR linefax; ! 6: { ! 7: printf ("...line %g %g %g %g\n", ! 8: linefax->x0, linefax->y0, ! 9: linefax->x1, linefax->y1 ! 10: ); ! 11: } ! 12: ! 13: void circcall (circfax) ! 14: CIRCPTR circfax; ! 15: { ! 16: printf ("...circle %g %g %g\n", ! 17: circfax->x0, circfax->y0, circfax->r ! 18: ); ! 19: } ! 20: ! 21: void arccall (arcfax) ! 22: ARCPTR arcfax; ! 23: { ! 24: printf ("...arc %g %g %g %g %g %g %g %g %g\n", ! 25: arcfax->x0, arcfax->y0, ! 26: arcfax->x1, arcfax->y1, ! 27: arcfax->x2, arcfax->y2, ! 28: arcfax->theta1, arcfax->theta2, ! 29: ! 30: fabs(arcfax->radius) ! 31: ); ! 32: } ! 33: ! 34: void textcall (textfax) ! 35: TEXTPTR textfax; ! 36: { ! 37: switch (textfax->command) { ! 38: case LEFT: ! 39: printf ("...left %g %g '%s\n", ! 40: textfax->x0, ! 41: textfax->y0, ! 42: textfax->string ! 43: ); ! 44: break; ! 45: case CENTER: ! 46: printf ("...center %g %g '%s\n", ! 47: textfax->x0, ! 48: textfax->y0, ! 49: textfax->string ! 50: ); ! 51: break; ! 52: case RIGHT: ! 53: printf ("...right %g %g '%s\n", ! 54: textfax->x0, ! 55: textfax->y0, ! 56: textfax->string ! 57: ); ! 58: break; ! 59: default: ! 60: fprintf (stderr, "ideal: textcall: can't happen\n"); ! 61: break; ! 62: } ! 63: } ! 64: ! 65: void splcall (knotlist) ! 66: EXPRPTR knotlist; ! 67: { ! 68: printf ("...spline %g %g\n", ! 69: Re(((INTLPTR) knotlist->expr)), ! 70: Im(((INTLPTR) knotlist->expr)) ! 71: ); ! 72: knotlist = knotlist->next; ! 73: while (knotlist) { ! 74: printf ("...knot %g %g\n", ! 75: Re(((INTLPTR) knotlist->expr)), ! 76: Im(((INTLPTR) knotlist->expr)) ! 77: ); ! 78: knotlist = knotlist->next; ! 79: } ! 80: printf ("...endspline\n"); ! 81: } ! 82: ! 83: #define maxx bounds[MAXX] ! 84: #define maxy bounds[MAXY] ! 85: #define minx bounds[MINX] ! 86: #define miny bounds[MINY] ! 87: ! 88: void boundscall (bounds) ! 89: double bounds[4]; ! 90: { ! 91: printf ("...maxx %g\n", maxx); ! 92: printf ("...maxy %g\n", maxy); ! 93: printf ("...minx %g\n", minx); ! 94: printf ("...miny %g\n", miny); ! 95: } ! 96: ! 97: void bbline (lineseg, bounds) ! 98: LINEPTR lineseg; ! 99: double bounds[4]; ! 100: { ! 101: maxx = max(maxx, max(lineseg->x0, lineseg->x1)); ! 102: maxy = max(maxy, max(lineseg->y0, lineseg->y1)); ! 103: minx = min(minx, min(lineseg->x0, lineseg->x1)); ! 104: miny = min(miny, min(lineseg->y0, lineseg->y1)); ! 105: } ! 106: ! 107: void bbcirc (circle, bounds) ! 108: CIRCPTR circle; ! 109: double bounds[4]; ! 110: { ! 111: maxx = max(maxx, circle->x0 + fabs(circle->r)); ! 112: minx = min(minx, circle->x0 - fabs(circle->r)); ! 113: maxy = max(maxy, circle->y0 + fabs(circle->r)); ! 114: miny = min(miny, circle->y0 - fabs(circle->r)); ! 115: } ! 116: ! 117: void bbstring (text, bounds) ! 118: TEXTPTR text; ! 119: double bounds[4]; ! 120: { ! 121: maxx = max(maxx, text->x0); ! 122: minx = min(minx, text->x0); ! 123: maxy = max(maxy, text->y0); ! 124: miny = min(miny, text->y0); ! 125: } ! 126: ! 127: /*************************************************************************** ! 128: bounding box of a circular arc Eric Grosse 24 May 84 ! 129: ! 130: Conceptually, this routine generates a list consisting of the start, ! 131: end, and whichever north, east, south, and west points lie on the arc. ! 132: The bounding box is then the range of this list. ! 133: list = {start,end} ! 134: j = quadrant(start) ! 135: k = quadrant(end) ! 136: if( j==k && long way 'round ) append north,west,south,east ! 137: else ! 138: while( j != k ) ! 139: append center+radius*[j-th of north,west,south,east unit vectors] ! 140: j += 1 (mod 4) ! 141: return( bounding box of list ) ! 142: The following code implements this, with simple optimizations. ! 143: ***********************************************************************/ ! 144: ! 145: bbarc(arc, bounds) ! 146: ARCPTR arc; ! 147: double bounds[4]; ! 148: { ! 149: double x0, y0, x1, y1, xc, yc; /* start, end, center */ ! 150: double xmin, xmax, ymin, ymax; ! 151: /* assumes center isn't too far out */ ! 152: double r, x, y; ! 153: int j, k; ! 154: int quadrant(); ! 155: x0 = arc->x1; ! 156: y0 = arc->y1; ! 157: x1 = arc->x2; ! 158: y1 = arc->y2; ! 159: xc = arc->x0; ! 160: yc = arc->y0; ! 161: x0 -= xc; y0 -= yc; ! 162: x1 -= xc; y1 -= yc; ! 163: xmin = (x0<x1)?x0:x1; ymin = (y0<y1)?y0:y1; ! 164: xmax = (x0>x1)?x0:x1; ymax = (y0>y1)?y0:y1; ! 165: r = sqrt(x0*x0+y0*y0); ! 166: if(r>0.){ ! 167: j = quadrant(x0,y0); ! 168: k = quadrant(x1,y1); ! 169: if((j==k)&&(y1*x0<x1*y0)){ ! 170: /* viewed as complex numbers, if Im(z1/z0)<0, arc is big */ ! 171: if( xmin > -r) xmin = -r; if( ymin > -r) ymin = -r; ! 172: if( xmax < r) xmax = r; if( ymax < r) ymax = r; ! 173: }else{ ! 174: while(j!=k){ ! 175: switch(j){ ! 176: case 1: if( ymax < r) ymax = r; break; /* north */ ! 177: case 2: if( xmin > -r) xmin = -r; break; /* west */ ! 178: case 3: if( ymin > -r) ymin = -r; break; /* south */ ! 179: case 4: if( xmax < r) xmax = r; break; /* east */ ! 180: } ! 181: j = j%4 + 1; ! 182: } ! 183: } ! 184: } ! 185: xmin += xc; ymin += yc; ! 186: xmax += xc; ymax += yc; ! 187: ! 188: maxx = max(maxx,xmax); ! 189: minx = min(minx,xmin); ! 190: maxy = max(maxy,ymax); ! 191: miny = min(miny,ymin); ! 192: } ! 193: ! 194: int ! 195: quadrant(x,y) ! 196: double x,y; ! 197: { ! 198: double z=0.; ! 199: if( (x>=z)&&(y> z) ){ return(1); } ! 200: else if( (x< z)&&(y>=z) ){ return(2); } ! 201: else if( (x<=z)&&(y< z) ){ return(3); } ! 202: else if( (x> z)&&(y<=z) ){ return(4); } ! 203: else{ fprintf(stderr,"can't happen: x,y=%g,%g",x,y); exit(1);} ! 204: } ! 205: ! 206: void bbspline (knotlist, bounds) ! 207: EXPRPTR knotlist; ! 208: double bounds[4]; ! 209: { ! 210: double xmin, xmax, ymin, ymax, x, y; ! 211: xmin = xmax = Re(((INTLPTR) knotlist->expr)); ! 212: ymin = ymax = Im(((INTLPTR) knotlist->expr)); ! 213: knotlist = knotlist->next; ! 214: while (knotlist) { ! 215: x = Re(((INTLPTR) knotlist->expr)); ! 216: xmin = min(xmin, x); ! 217: xmax = max(xmax, x); ! 218: y = Im(((INTLPTR) knotlist->expr)); ! 219: ymin = min(ymin, y); ! 220: ymax = max(ymax, y); ! 221: knotlist = knotlist->next; ! 222: } ! 223: minx = min(minx, xmin); ! 224: maxx = max(maxx, xmax); ! 225: miny = min(miny, ymin); ! 226: maxy = max(maxy, ymax); ! 227: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.