9 enum flag { POINT,ENDSEG,ENDSYM };
17 static double halfrange = 1;
21 static int getrange(FILE *);
22 static int getsymbol(FILE *, int);
23 static void setrot(struct place *, double, int);
24 static void dorot(struct symb *, double *, double *);
30 FILE *sf = fopen(file,"r");
32 filerror("cannot open", file);
33 while(nsymbol<NSYMBOL-1 && getsymbol(sf,nsymbol))
39 getsymbol(FILE *sf, int n)
46 if(fscanf(sf,"%1s",s)==EOF)
59 error("-y file syntax error");
63 sp = (struct symb*)malloc(sizeof(struct symb));
65 if(fscanf(sf,"%10s",sp->name)!=1)
68 while(fscanf(sf,"%1s",s)!=EOF) {
76 symbol[n][i-1].flag = ENDSEG;
84 if(fscanf(sf,"%lf %lf",&x,&y)!=2)
86 sp[i].x = x*halfwidth/halfrange;
87 sp[i].y = y*halfwidth/halfrange;
90 sp = symbol[n] = (struct symb*)realloc(symbol[n],
91 (i+1)*sizeof(struct symb));
97 symbol[n][i-1].flag = ENDSYM;
106 double x,y,xmin,ymin;
107 if(fscanf(sf,"%*s %lf %lf %lf %lf",
108 &xmin,&ymin,&x,&y)!=4)
112 halfrange = (x>y? x: y)/2;
114 error("bad ra command in -y file");
118 /* r=0 upright;=1 normal;=-1 reverse*/
120 putsym(struct place *p, char *name, double s, int r)
126 for(n=0; symbol[n]; n++)
127 if(strcmp(name,symbol[n]->name)==0)
132 if(doproj(p,&x,&y)*vflag <= 0)
137 conn = cpoint(x+(int)dx,y+(int)dy,conn);
152 static double rot[2][2];
155 setrot(struct place *p, double s, int r)
162 if(r&&(*projection)(p,&x0,&y0)) {
163 if((*projection)(&up,&x1,&y1)<=0) {
166 if((*projection)(&up,&x1,&y1)<=0)
182 rot[0][0] = rot[1][1] = s;
183 rot[0][1] = rot[1][0] = 0;
188 dorot(struct symb *sp, double *px, double *py)
190 *px = rot[0][0]*sp->x + rot[0][1]*sp->y;
191 *py = rot[1][0]*sp->x + rot[1][1]*sp->y;