|
|
1.1 root 1: /*******************************************************************
2: * *
3: * File: CIFPLOT/line.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 "out_structs.h"
15: #include <math.h>
16: #include "alloc.h"
17:
18: IMPORT point *MakePoint();
19: IMPORT point *TransPt();
20: IMPORT real ICompare();
21: IMPORT StartEdgePath();
22: IMPORT iedge *NextEdgePath();
23: IMPORT iedge *EndEdgePath();
24: IMPORT PolyDesc *MakeDesc();
25: IMPORT char *Concat();
26:
27: #define pi 3.1415926535
28:
29: MakeLine(rx1,ry1,rx2,ry2,trans)
30: real rx1,rx2,ry1,ry2;
31: transform *trans;
32: {
33: int i;
34: iedge *e1,*e2;
35: real t;
36:
37: Trans(&rx1,&ry1,trans);
38: Trans(&rx2,&ry2,trans);
39: if(rx1 > rx2) { SWAP(rx1,rx2,t); SWAP(ry1,ry2,t);}
40: /* Now rx1 <= rx2 */
41:
42: e1 = GetIEdge();
43: e1->type = EDGE;
44: e1->poly = MakeDesc(NIL);
45: (e1->poly->refs)++;
46:
47: e2 = GetIEdge();
48: e2->type = EDGE;
49: e2->poly = e1->poly;
50: (e1->poly->refs)++;
51:
52: /* Now convert from CIF units to plotter units */
53: e1->x1 = e2->x1 = CONVERT(rx1); e1->y1 = e2->y1 = CONVERT(ry1);
54: e1->x2 = e2->x2 = CONVERT(rx2); e1->y2 = e2->y2 = CONVERT(ry2);
55: e1->min = e1->x1;
56: e2->min = e1->x1;
57:
58: e1->dir = 1; e2->dir = -1;
59: if(e2->x1 == e2->x2) { SWAP(e2->y1,e2->y2,i); }
60: PutUnAct(e1);
61: PutUnAct(e2);
62: }
63:
64: DrawBBox(bb,trans)
65: struct BBox *bb;
66: transform *trans;
67: {
68:
69: MakeLine((real) bb->xmin,(real) bb->ymin,(real) bb->xmax,(real) bb->ymin,trans);
70: MakeLine((real) bb->xmax,(real) bb->ymin,(real) bb->xmax,(real) bb->ymax,trans);
71: MakeLine((real) bb->xmax,(real) bb->ymax,(real) bb->xmin,(real) bb->ymax,trans);
72: MakeLine((real) bb->xmin,(real) bb->ymax,(real) bb->xmin,(real) bb->ymin,trans);
73: }
74:
75: MakeNgon(n,center,radius,trans,poly)
76: int n;
77: point *center;
78: real radius;
79: transform *trans;
80: PolyDesc *poly;
81: {
82: real d;
83: int i;
84: real x,y;
85: iedge *e;
86:
87: d = -(pi/((real) n));
88: radius = radius/cos(-d);
89: x = radius*sin(d)+center->x; y = radius*cos(d)+center->y;
90:
91: StartEdgePath(x,y,trans,poly);
92: for((i=1,d += (2.0*pi)/((real) n));i<n;(i++,d += (2.0*pi)/((real) n))) {
93: x = radius*sin(d)+center->x; y = radius*cos(d)+center->y;
94: e = NextEdgePath(x,y);
95: Selector(e);
96: }
97: e = EndEdgePath();
98: Selector(e);
99: }
100:
101: Grid()
102: {
103: double x,y;
104: char s[512],*str;
105: if(grid != 0) {
106: /* Draw vertical grid lines */
107: x = ((int) (Window.xmin/grid)) * grid;
108: while(x<Window.xmax) {
109: if(Window.xmin < x) {
110: MakeLine(x,Window.ymin,x,Window.ymax,ident);
111: sprintf(s,"%d",(int) x);
112: str = Concat(s,0);
113: ClipText(str,x,Window.ymax,'r');
114: }
115: x += grid;
116: }
117: /* Draw horizontal grid lines */
118: y = ((int) (Window.ymin/grid)) * grid;
119: while(y<Window.ymax) {
120: if(Window.ymin < y) {
121: MakeLine(Window.xmin,y,Window.xmax,y,ident);
122: sprintf(s,"%d",(int) y);
123: str = Concat(s,0);
124: ClipText(str,Window.xmax,y,'r');
125: }
126: y += grid;
127: }
128: }
129: }
130:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.