|
|
1.1 ! root 1: /******************************************************************* ! 2: * * ! 3: * File: CIFPLOT/bbox.c * ! 4: * Written by Dan Fitzpatrick * ! 5: * copyright 1980 -- Regents of the University of California * ! 6: * * ! 7: ********************************************************************/ ! 8: ! 9: #include <stdio.h> ! 10: #include "defs.h" ! 11: #include "globals.h" ! 12: #include "parser_defs.h" ! 13: #include "structs.h" ! 14: #include "alloc.h" ! 15: ! 16: IMPORT transform *MakeTransform(); ! 17: IMPORT transform *Rotate(); ! 18: IMPORT transform *Translate(); ! 19: IMPORT point *MakePoint(); ! 20: IMPORT point *TransPt(); ! 21: IMPORT double cos(); ! 22: ! 23: ZeroBBox(bbox) ! 24: struct BBox *bbox; ! 25: /* Set bbox to the smallest possible value */ ! 26: { ! 27: bbox->xmin = bbox->ymin = INFINITY; ! 28: bbox->xmax = bbox->ymax = -INFINITY; ! 29: } ! 30: ! 31: ClearBBox(bbox) ! 32: struct BBox *bbox; ! 33: /* set all values to 0 */ ! 34: { ! 35: bbox->xmin = bbox->ymin = 0; ! 36: bbox->xmax = bbox->ymax = 0; ! 37: } ! 38: ! 39: MakeBBox(bbox,com) ! 40: Command *com; ! 41: struct BBox *bbox; ! 42: /* The bounding box for the Command 'com' is computed and ! 43: * stored in the location pointed to by 'bbox' */ ! 44: { ! 45: Command *q; ! 46: PointList *p; ! 47: point pt,*ptr; ! 48: transform *t,*t1; ! 49: struct BBox bb; ! 50: ! 51: ZeroBBox(bbox); ! 52: switch(com->type) { ! 53: case POINTNAME: ! 54: CompPtBBox(bbox,&(com->Ctype.PointName.loc)); ! 55: break; ! 56: case TEXT: ! 57: break; ! 58: case BOX: ! 59: bb.xmin = com->Ctype.Box.bcenter.x ! 60: - com->Ctype.Box.blength/2.0; ! 61: bb.xmax = com->Ctype.Box.bcenter.x ! 62: + com->Ctype.Box.blength/2.0; ! 63: bb.ymin = com->Ctype.Box.bcenter.y ! 64: - com->Ctype.Box.bwidth/2.0; ! 65: bb.ymax = com->Ctype.Box.bcenter.y ! 66: + com->Ctype.Box.bwidth/2.0; ! 67: t = MakeTransform(); ! 68: t1 = Translate(&(com->Ctype.Box.bcenter),t); ! 69: FreeTransform(t); ! 70: t = Rotate(&(com->Ctype.Box.bdirect),t1); ! 71: FreeTransform(t1); ! 72: ptr = MakePoint(-(com->Ctype.Box.bcenter.x),-(com->Ctype.Box.bcenter.y)); ! 73: t1 = Translate(ptr,t); ! 74: Free(ptr); FreeTransform(t); ! 75: BBoxTransform(bbox,&bb,t1); ! 76: FreeTransform(t1); ! 77: break; ! 78: case FLASH: ! 79: { ! 80: real radius; ! 81: radius = com->Ctype.Flash.fdia/2.0; ! 82: if(circle != 0) ! 83: radius = radius/cos(3.1415926535/(real) circle); ! 84: bbox->xmin = com->Ctype.Flash.fcenter.x ! 85: - radius; ! 86: bbox->xmax = com->Ctype.Flash.fcenter.x ! 87: + radius; ! 88: bbox->ymin = com->Ctype.Flash.fcenter.y ! 89: - radius; ! 90: bbox->ymax = com->Ctype.Flash.fcenter.y ! 91: + radius; ! 92: } ! 93: break; ! 94: case POLYGON: ! 95: /* The bounding box must surround every point in the polygon */ ! 96: for(p=com->Ctype.Path;p != NIL;p=p->PLink) ! 97: CompPtBBox(bbox,&(p->pt)); ! 98: break; ! 99: case WIRE: ! 100: { ! 101: real scale; ! 102: if(circle == 0) ! 103: scale = 1.0; ! 104: else ! 105: scale = 1.0/cos(3.1415926535/(real) circle); ! 106: /* The bounding box surrounds the wire */ ! 107: for(p=com->Ctype.Wire.WPath;p != NIL;p=p->PLink) ! 108: CompPtBBox(bbox,&(p->pt)); ! 109: bbox->xmin -= scale*com->Ctype.Wire.WWidth/2.0; ! 110: bbox->ymin -= scale*com->Ctype.Wire.WWidth/2.0; ! 111: bbox->xmax += scale*com->Ctype.Wire.WWidth/2.0; ! 112: bbox->ymax += scale*com->Ctype.Wire.WWidth/2.0; ! 113: } ! 114: break; ! 115: case SYMBOL: ! 116: /* The bounding box must surround every command in the symbol */ ! 117: for(q=com->Ctype.Symbl.CStart;q != NIL;q=q->CLink){ ! 118: CompBBox(bbox,&(q->CBBox)); ! 119: } ! 120: break; ! 121: case CALL: ! 122: if(com->Ctype.Call.CSymb == NIL) break; ! 123: /* The bounding box must contain all the corners of the ! 124: * symbol's bounding box after it has been transformed */ ! 125: BBoxTransform(bbox,&(com->Ctype.Call.CSymb->CBBox), ! 126: com->Ctype.Call.trans); ! 127: break; ! 128: case ARRAY: ! 129: q = com->Ctype.Array.ACom; ! 130: MakeBBox(&(q->CBBox),q); ! 131: MakeBBox(&(com->CBBox),q); ! 132: pt.x = (com->Ctype.Array.Adx < 0) ? ! 133: com->CBBox.xmin + com->Ctype.Array.Adx*(com->Ctype.Array.Am-1): ! 134: com->CBBox.xmax + com->Ctype.Array.Adx*(com->Ctype.Array.Am-1); ! 135: pt.y = (com->Ctype.Array.Ady < 0) ? ! 136: com->CBBox.ymin + com->Ctype.Array.Ady*(com->Ctype.Array.An-1): ! 137: com->CBBox.ymax + com->Ctype.Array.Ady*(com->Ctype.Array.An-1); ! 138: CompPtBBox(&(com->CBBox),&pt); ! 139: bbox->xmin = com->CBBox.xmin; ! 140: bbox->xmax = com->CBBox.xmax; ! 141: bbox->ymin = com->CBBox.ymin; ! 142: bbox->ymax = com->CBBox.ymax; ! 143: break; ! 144: default: ! 145: Error("Attempted to make bounding box for inappropriate command",INTERNAL); ! 146: } ! 147: } ! 148: ! 149: BBoxTransform(bb,sbb,trans) ! 150: struct BBox *bb; ! 151: struct BBox *sbb; ! 152: transform *trans; ! 153: /* Transform the bounding box 'sbb' by transform 'trans' and expand ! 154: * 'bb' till it contains the transformed 'sbb' bounding box. */ ! 155: { ! 156: real x,y; ! 157: ! 158: /* For every corner of bounding box 'sbb', transform it and ! 159: * make 'bb' contain that transformed corner */ ! 160: x = sbb->xmin; y = sbb->ymin; ! 161: Trans(&x,&y,trans); ! 162: CompNumBBox(bb,x,y); ! 163: ! 164: x = sbb->xmax; y = sbb->ymin; ! 165: Trans(&x,&y,trans); ! 166: CompNumBBox(bb,x,y); ! 167: ! 168: x = sbb->xmax; y = sbb->ymax; ! 169: Trans(&x,&y,trans); ! 170: CompNumBBox(bb,x,y); ! 171: ! 172: x = sbb->xmin; y = sbb->ymax; ! 173: Trans(&x,&y,trans); ! 174: CompNumBBox(bb,x,y); ! 175: ! 176: } ! 177: ! 178: CompBBox(bb1,bb2) ! 179: struct BBox *bb1,*bb2; ! 180: /* Expand bb1 so that it encloses bb2 */ ! 181: { ! 182: if (bb1->xmin > bb2->xmin) ! 183: bb1->xmin = bb2->xmin; ! 184: if (bb1->ymin > bb2->ymin) ! 185: bb1->ymin = bb2->ymin; ! 186: if (bb1->xmax < bb2->xmax) ! 187: bb1->xmax = bb2->xmax; ! 188: if (bb1->ymax < bb2->ymax) ! 189: bb1->ymax = bb2->ymax; ! 190: } ! 191: ! 192: CompPtBBox(bb,pt) ! 193: struct BBox *bb; ! 194: point *pt; ! 195: /* Expand bb so that it encloses pt */ ! 196: { ! 197: if (bb->xmin > pt->x) ! 198: bb->xmin = pt->x; ! 199: if (bb->ymin > pt->y) ! 200: bb->ymin = pt->y; ! 201: if (bb->xmax < pt->x) ! 202: bb->xmax = pt->x; ! 203: if (bb->ymax < pt->y) ! 204: bb->ymax = pt->y; ! 205: } ! 206: ! 207: CompNumBBox(bb,x,y) ! 208: struct BBox *bb; ! 209: real x,y; ! 210: /* Expand bb so that in encloses (x,y) */ ! 211: { ! 212: if (bb->xmin > x) ! 213: bb->xmin = x; ! 214: if (bb->ymin > y) ! 215: bb->ymin = y; ! 216: if (bb->xmax < x) ! 217: bb->xmax = x; ! 218: if (bb->ymax < y) ! 219: bb->ymax = y; ! 220: } ! 221:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.