Blob


1 #include <math.h>
2 #include <stdio.h>
3 #include "tex.h"
5 void
6 devarc(double x1, double y1, double x2, double y2, double xc, double yc, int r)
7 {
8 double t, start, stop;
9 int rad;
11 /* tpic arcs go clockwise, and angles are measured clockwise */
12 start = atan2(y2-yc, x2-xc);
13 stop = atan2(y1-yc, x1-xc);
14 if (r<0) {
15 t = start; start = stop; stop = t;
16 }
17 rad = SCX(sqrt((x1-xc)*(x1-xc)+(y1-yc)*(y1-yc)));
18 fprintf(TEXFILE, " \\special{ar %d %d %d %d %6.3f %6.3f}%%\n",
19 TRX(xc), TRY(yc), rad, rad, -start, -stop);
20 }
22 void
23 box(double x0, double y0, double x1, double y1)
24 {
25 fprintf(TEXFILE," \\special{pa %d %d}",TRX(x0),TRY(y0));
26 fprintf(TEXFILE,"\\special{pa %d %d}",TRX(x1),TRY(y0));
27 fprintf(TEXFILE,"\\special{pa %d %d}",TRX(x1),TRY(y1));
28 fprintf(TEXFILE,"\\special{pa %d %d}",TRX(x0),TRY(y1));
29 fprintf(TEXFILE,"\\special{pa %d %d}",TRX(x0),TRY(y0));
30 switch(e1->pen){
31 case DASHPEN:
32 fprintf(TEXFILE,"\\special{da %6.3f}%%\n", e1->dashlen); break;
33 case DOTPEN:
34 fprintf(TEXFILE,"\\special{dt %6.3f}%%\n", e1->dashlen); break;
35 case SOLIDPEN:
36 default:
37 fprintf(TEXFILE,"\\special{fp}%%\n"); break;
38 }
39 }
41 void
42 circle(double xc, double yc, double r)
43 {
44 int rad = SCX(r);
46 fprintf(TEXFILE, " \\special{ar %d %d %d %d 0.0 6.2832}%%\n",
47 TRX(xc), TRY(yc), rad, rad);
48 }
50 void
51 closepl(void)
52 {
53 fprintf(TEXFILE, " \\kern %6.3fin\n }\\vss}%%\n", INCHES(e1->sidex));
54 fprintf(TEXFILE, " \\kern %6.3fin\n}\n", INCHES(e1->sidey));
55 }
57 void
58 disc(double xc, double yc, double r)
59 {
60 fprintf(TEXFILE, " \\special{bk}%%\n");
61 circle(xc, yc, r);
62 }
64 void
65 erase(void)
66 {
67 }
69 void
70 fill(int num[], double *ff[])
71 {
72 double *xp, *yp, **fp, x0, y0;
73 int i, *n;
74 n = num;
75 fp = ff;
76 while((i = *n++)){
77 xp = *fp++;
78 yp = xp+1;
79 x0 = *xp;
80 y0 = *yp;
81 move(x0, y0);
82 while(--i){
83 xp += 2;
84 yp += 2;
85 vec(*xp, *yp);
86 }
87 if (*(xp-2) != x0 || *(yp-2) != y0)
88 vec(x0, y0);
89 }
90 }
92 void
93 frame(double xs, double ys, double xf, double yf)
94 {
95 double osidex, osidey;
96 osidex = e1->sidex;
97 osidey = e1->sidey;
98 e1->left = xs * (e0->left + e0->sidex);
99 e1->bottom = ys* (e0->bottom + e0->sidey);
100 e1->sidex = (xf-xs) * e0->sidex;
101 e1->sidey = (yf-ys) * e0->sidey;
102 e1->scalex *= (e1->sidex / osidex);
103 e1->scaley *= (e1->sidey / osidey);
106 void
107 line(double x0, double y0, double x1, double y1)
109 move(x0, y0);
110 vec(x1, y1);
113 void
114 move(double xx, double yy)
116 e1->copyx = xx;
117 e1->copyy = yy;
120 extern double xmin, ymin, xmax, ymax;
122 /* tpic TeX coord system uses millinches, printer's points for pensize */
123 /* positive y downward, origin at upper left */
125 #define pHEIGHT 5000.
126 #define pWIDTH 5000.
127 #define pPENSIZE 9
128 #define pPSIZE 10
129 #define pDLEN .05
130 struct penvir E[2] = {
131 {0.,pHEIGHT,0.,0.,1.,-1.,pWIDTH,pHEIGHT,0.,0.,0,pPSIZE,SOLIDPEN,pPENSIZE,pDLEN},
132 {0.,pHEIGHT,0.,0.,1.,-1.,pWIDTH,pHEIGHT,0.,0.,0,pPSIZE,SOLIDPEN,pPENSIZE,pDLEN}
133 };
134 struct penvir *e0 = E, *e1 = &E[1];
135 FILE *TEXFILE;
137 void
138 openpl(void)
140 TEXFILE = stdout;
142 space(xmin, ymin, xmax, ymax);
143 fprintf(TEXFILE,"\\catcode`@=11\n");
144 fprintf(TEXFILE, "\\expandafter\\ifx\\csname graph\\endcsname\\relax");
145 fprintf(TEXFILE, " \\alloc@4\\box\\chardef\\insc@unt\\graph\\fi\n");
146 fprintf(TEXFILE, "\\catcode`@=12\n");
147 fprintf(TEXFILE, "\\setbox\\graph=\\vtop{%%\n");
148 fprintf(TEXFILE, " \\baselineskip=0pt \\lineskip=0pt ");
149 fprintf(TEXFILE, "\\lineskiplimit=0pt\n");
150 fprintf(TEXFILE, " \\vbox to0pt{\\hbox{%%\n");
151 fprintf(TEXFILE, " \\special{pn %d}%%\n", e1->pdiam);
154 void
155 range(double x0, double y0, double x1, double y1)
157 e1->xmin = x0;
158 e1->ymin = y0;
159 if (x1-x0 < .0000001*e1->sidex)
160 x1=x0+.0000001;
161 if (y1-y0 < .0000001*e1->sidey)
162 y1=y0+.0000001;
163 e1->scalex = e0->scalex*e1->sidex / (x1 - x0);
164 e1->scaley = e0->scaley*e1->sidey / (y1 - y0);
167 void
168 rmove(double xx, double yy)
170 e1->copyx += xx;
171 e1->copyy += yy;
174 void
175 rvec(double xx, double yy)
177 vec(xx+e1->copyx, yy+e1->copyy);
180 void
181 sbox(double x0, double y0, double x1, double y1)
183 fprintf(TEXFILE," \\special{bk}%%\n");
184 box(x0, y0, x1, y1);
187 void
188 vec(double xx, double yy)
190 fprintf(TEXFILE," \\special{pa %d %d}",TRX(e1->copyx),TRY(e1->copyy));
191 e1->copyx = xx;
192 e1->copyy = yy;
193 fprintf(TEXFILE,"\\special{pa %d %d}",TRX(xx),TRY(yy));
194 switch(e1->pen){
195 case DASHPEN:
196 fprintf(TEXFILE,"\\special{da %6.3f}%%\n", e1->dashlen); break;
197 case DOTPEN:
198 fprintf(TEXFILE,"\\special{dt %6.3f}%%\n", e1->dashlen); break;
199 case SOLIDPEN:
200 default:
201 fprintf(TEXFILE,"\\special{fp}%%\n"); break;