Rev 18523 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
17676 | bpr | 1 | /* Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis |
10 | reyssat | 2 | * |
3 | * This program is free software; you can redistribute it and/or modify |
||
4 | * it under the terms of the GNU General Public License as published by |
||
5 | * the Free Software Foundation; either version 2 of the License, or |
||
6 | * (at your option) any later version. |
||
7 | * |
||
8 | * This program is distributed in the hope that it will be useful, |
||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
11 | * GNU General Public License for more details. |
||
12 | * |
||
13 | * You should have received a copy of the GNU General Public License |
||
14 | * along with this program; if not, write to the Free Software |
||
15 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
||
16 | */ |
||
8177 | bpr | 17 | |
18 | #include <errno.h> |
||
8102 | bpr | 19 | #include "flydraw.h" |
18317 | bpr | 20 | const double DEG=M_PI/180; |
8177 | bpr | 21 | |
17574 | bpr | 22 | /* Tikz things */ |
17599 | bpr | 23 | |
17608 | bpr | 24 | static char *tikz_color (int the_color) |
25 | { |
||
26 | static char buf[50]; |
||
27 | int r=gdImageRed(image,the_color); |
||
28 | int g=gdImageGreen(image,the_color); |
||
29 | int b=gdImageBlue(image,the_color); |
||
30 | sprintf(buf, "{rgb,255:red,%i;green,%i;blue,%i}",r,g,b); |
||
31 | return buf; |
||
32 | } |
||
33 | |||
17574 | bpr | 34 | static char *tikz_options (int the_color, int the_fill) |
35 | { |
||
36 | static char buf[100]; |
||
37 | if (the_color == gdBrushed) |
||
38 | the_color = tikz_brushColor; |
||
17608 | bpr | 39 | sprintf (buf, "draw=%s,cap=round",tikz_color(the_color)); |
17574 | bpr | 40 | if (the_color != tikz_brushColor) strcat(buf, ",thin"); |
18125 | bpr | 41 | if (the_fill == -1 || the_fill == 2) strcat(buf, ",dashed"); |
42 | if (the_fill == 1 || the_fill == 2) |
||
17608 | bpr | 43 | sprintf(buf+strlen(buf), ",fill=%s", tikz_color(the_color)); |
17574 | bpr | 44 | return buf; |
45 | } |
||
46 | |||
17662 | bpr | 47 | #define flip(y) (sizey-1-(y)) |
17574 | bpr | 48 | |
8010 | bpr | 49 | /* bug in gdImageFillToBorder */ |
10 | reyssat | 50 | |
8162 | bpr | 51 | void patchgdImageFillToBorder (gdImagePtr im, int x, int y, int border, int color) |
8076 | bpr | 52 | { |
12473 | bpr | 53 | if(x>=im->sx || x<0 || y>=im->sy || y<0) return; |
54 | gdImageFillToBorder(im,x,y,border,color); |
||
8076 | bpr | 55 | } |
56 | |||
8162 | bpr | 57 | void patchgdImageFill (gdImagePtr im, int x, int y, int color) |
8156 | bpr | 58 | { |
12473 | bpr | 59 | if(x>=im->sx || x<0 || y>=im->sy || y<0) return; |
60 | gdImageFill(im,x,y,color); |
||
8156 | bpr | 61 | } |
8076 | bpr | 62 | |
9651 | georgesk | 63 | #define DASHPIXELS 8 |
64 | |||
65 | void myDashedLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color){ |
||
66 | /** |
||
67 | * emulates gdImageDashedLine with gdImageSetStyle and gdImageLine |
||
68 | * GK: As gdImageDashedLine is slightly broken in latest libgd libraries, |
||
69 | * GK: I implemented an emulation named "myDashedLine" |
||
70 | **/ |
||
71 | |||
72 | int styleDashed[DASHPIXELS],i; |
||
73 | for (i=0; i< DASHPIXELS/2; i++) styleDashed[i]=color; |
||
74 | for (; i< DASHPIXELS; i++) styleDashed[i]=gdTransparent; |
||
75 | gdImageSetStyle(im, styleDashed, DASHPIXELS); |
||
76 | gdImageLine(im, x1, y1, x2, y2, gdStyled); |
||
77 | } |
||
78 | |||
79 | |||
7675 | bpr | 80 | /* File opening: with security */ |
10 | reyssat | 81 | FILE *open4read(char *n) |
82 | { |
||
12473 | bpr | 83 | char *p, *p1, *p2, namebuf[2048]; |
84 | int t; |
||
85 | FILE *f; |
||
86 | n=find_word_start(n); |
||
87 | if(*n==0) return NULL; |
||
88 | p=getenv("flydraw_filebase"); |
||
89 | p1=n+strlen(n)-4;if(p1<n || strcasecmp(p1,".gif")!=0) t=1; else t=0; |
||
90 | if(p!=NULL && *p!=0) { |
||
91 | char pbuf[MAX_LINELEN+1]; |
||
92 | snprintf(pbuf,sizeof(pbuf),"%s",p); |
||
93 | p=find_word_start(pbuf); if(strstr(p,"..")!=NULL) return NULL; |
||
94 | if(*n=='/' || strstr(n,"..")!=NULL) return NULL; |
||
95 | /* prohibit unusual file/dir names */ |
||
96 | for(p1=p;*p1;p1++) |
||
97 | if(!isalnum(*p1) && !isspace(*p1) && strchr("~_-/.",*p1)==NULL) |
||
98 | return NULL; |
||
99 | for(p1=n;*p1;p1++) |
||
100 | if(!isalnum(*p1) && !isspace(*p1) && strchr("~_-/.",*p1)==NULL) |
||
101 | return NULL; |
||
102 | f=NULL; |
||
103 | for(p1=p; *p1; p1=find_word_start(p2)) { |
||
104 | p2=find_word_end(p1); |
||
105 | if(*p2) *p2++=0; |
||
106 | snprintf(namebuf,sizeof(namebuf),"%s/%s",p1,n); |
||
107 | f=fopen(namebuf,"r"); if(f!=NULL) goto imgtype; |
||
10 | reyssat | 108 | } |
12473 | bpr | 109 | p1=getenv("w_wims_session"); |
110 | if(p1!=NULL && strncmp(n,"insert",6)==0) { |
||
111 | snprintf(namebuf,sizeof(namebuf),"../s2/%s/%s",p1,n); |
||
7675 | bpr | 112 | f=fopen(namebuf,"r"); |
10 | reyssat | 113 | } |
12473 | bpr | 114 | } |
115 | else { |
||
116 | snprintf(namebuf,sizeof(namebuf),"%s",n); |
||
117 | f=fopen(namebuf,"r"); |
||
118 | } |
||
119 | imgtype: |
||
120 | if(t && f!=NULL) { |
||
121 | char tbuf[1024],sbuf[4096]; |
||
122 | fclose(f); f=NULL; |
||
123 | p1=getenv("TMPDIR"); if(p1==NULL || *p1==0) p1="."; |
||
124 | snprintf(tbuf,sizeof(tbuf),"%s/drawfile_.gif",p1); |
||
125 | snprintf(sbuf,sizeof(sbuf),"convert %s %s",namebuf,tbuf); |
||
126 | if (system(sbuf)) fly_error("system_failed"); |
||
127 | f=fopen(tbuf,"r"); |
||
128 | } |
||
129 | return f; |
||
10 | reyssat | 130 | } |
131 | |||
7675 | bpr | 132 | /* Does nothing; just a comment. */ |
10 | reyssat | 133 | void obj_comment(objparm *pm) |
134 | { |
||
12473 | bpr | 135 | return; |
10 | reyssat | 136 | } |
137 | |||
7675 | bpr | 138 | /* define image size */ |
10 | reyssat | 139 | void obj_size(objparm *pm) |
140 | { |
||
12473 | bpr | 141 | sizex=rint(pm->pd[0]); sizey=rint(pm->pd[1]); |
142 | if(sizex<0 || sizey<0 || sizex>MAX_SIZE || sizey>MAX_SIZE) { |
||
143 | fly_error("bad_size"); return; |
||
144 | } |
||
145 | if(image!=NULL) { |
||
146 | fly_error("size_already_defined"); return; |
||
147 | } |
||
148 | image=gdImageCreate(sizex,sizey); |
||
17574 | bpr | 149 | if(tikz_file) fprintf(tikz_file,"\\clip (0,0) rectangle (%i, %i);\n", sizex, sizey); |
12473 | bpr | 150 | if(image==NULL) fly_error("image_creation_failure"); |
151 | else { |
||
152 | color_white=gdImageColorAllocate(image,255,255,255); |
||
153 | color_black=gdImageColorAllocate(image,0,0,0); |
||
154 | color_bounder=gdImageColorAllocate(image,1,2,3); |
||
155 | color_frame=gdImageColorAllocate(image,254,254,254); |
||
156 | } |
||
10 | reyssat | 157 | } |
158 | |||
7675 | bpr | 159 | /* new image */ |
10 | reyssat | 160 | void obj_new(objparm *pm) |
161 | { |
||
12473 | bpr | 162 | if(image) { |
163 | gdImageDestroy(image);image=NULL; |
||
164 | } |
||
165 | if(pm->pcnt>=2) { obj_size(pm); gdImageRectangle(image,0,0,sizex-1,sizey-1,color_frame);} |
||
166 | else sizex=sizey=0; |
||
167 | saved=0; |
||
10 | reyssat | 168 | } |
169 | |||
7675 | bpr | 170 | /* new image */ |
10 | reyssat | 171 | void obj_existing(objparm *pm) |
172 | { |
||
12473 | bpr | 173 | FILE *inf; |
174 | char *pp; |
||
7615 | bpr | 175 | |
12473 | bpr | 176 | if(image) { |
177 | gdImageDestroy(image);image=NULL; |
||
178 | } |
||
179 | pp=find_word_start(pm->str);*find_word_end(pp)=0; |
||
180 | inf=open4read(pp); |
||
181 | if(inf==NULL) { |
||
182 | fly_error("file_not_exist"); return; |
||
183 | } |
||
184 | image=gdImageCreateFromGif(inf); fclose(inf); |
||
185 | if(image==NULL) { |
||
186 | fly_error("bad_gif"); return; |
||
187 | } |
||
188 | sizex=image->sx; sizey=image->sy; |
||
189 | saved=0; |
||
10 | reyssat | 190 | } |
18066 | bpr | 191 | /* tikzfile */ |
192 | void obj_tikzfile(objparm *pm) |
||
193 | { |
||
194 | char *p; |
||
195 | if(tikz_file){ |
||
196 | fprintf(tikz_file,"\\end{tikzpicture}\n"); |
||
197 | fclose(tikz_file); |
||
198 | } |
||
199 | p=find_word_start(pm->str); *find_word_end(p)=0; |
||
200 | snprintf(tikzfilename,sizeof(tikzfilename),"%s",p); |
||
201 | tikz_file=fopen(tikzfilename,"w"); |
||
202 | if(!tikz_file) |
||
203 | fly_error("tikz_nopen"); |
||
204 | fprintf(tikz_file,"\\begin{tikzpicture}\[x=0.02cm, y=0.02cm]\n"); |
||
205 | } |
||
10 | reyssat | 206 | |
18123 | bpr | 207 | /* segment */ |
10 | reyssat | 208 | void obj_line(objparm *pm) |
209 | { |
||
12473 | bpr | 210 | scale(pm->pd,pm->p,2); |
18125 | bpr | 211 | if(pm->fill==-1 || pm->fill==2 ) |
18123 | bpr | 212 | myDashedLine(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],pm->color[0]); |
213 | else |
||
214 | gdImageLine(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],pm->color[0]); |
||
17574 | bpr | 215 | if (tikz_file) |
216 | fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n", |
||
217 | tikz_options(pm->color[0],pm->fill),pm->p[0],flip(pm->p[1]),pm->p[2],flip(pm->p[3])); |
||
12473 | bpr | 218 | if(vimg_enable) vimg_line(scale_buf[0],scale_buf[1],scale_buf[2],scale_buf[3]); |
10 | reyssat | 219 | } |
220 | |||
1024 | bpr | 221 | void _obj_arrow(objparm *pm, int twoside) |
10 | reyssat | 222 | { |
12473 | bpr | 223 | int l,xx,yy; |
224 | gdPoint ii[3]; |
||
225 | double dx,dy,length,dd[6]; |
||
226 | scale(pm->pd,pm->p,2); |
||
227 | xx=ii[0].x=pm->p[2];yy=ii[0].y=pm->p[3]; |
||
228 | l=pm->pd[4];if(l<0) l=0; if(l>200) l=200; |
||
229 | scale2(pm->pd[0]-pm->pd[2],pm->pd[1]-pm->pd[3],&dx,&dy); |
||
230 | length=sqrt(dx*dx+dy*dy); |
||
231 | if(length<3 || l<5) goto stem; |
||
232 | dd[0]=l*dx/length; dd[1]=l*dy/length; |
||
233 | #define fat 0.27 |
||
234 | dd[2]=dd[0]+dd[1]*fat; dd[3]=dd[1]-dd[0]*fat; |
||
235 | dd[4]=dd[0]-dd[1]*fat; dd[5]=dd[1]+dd[0]*fat; |
||
236 | ii[1].x=rint(dd[2])+ii[0].x; ii[1].y=rint(dd[3])+ii[0].y; |
||
237 | ii[2].x=rint(dd[4])+ii[0].x; ii[2].y=rint(dd[5])+ii[0].y; |
||
238 | gdImageFilledPolygon(image, ii,3,pm->color[0]); |
||
17578 | bpr | 239 | if(tikz_file) |
240 | fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i) -- (%i, %i) -- cycle;\n", |
||
241 | tikz_options(pm->color[0],1),ii[0].x,flip(ii[0].y),ii[1].x,flip(ii[1].y),ii[2].x,flip(ii[2].y)); |
||
242 | if(vimg_enable) vimg_polyline(scale_buf,3,1); |
||
12473 | bpr | 243 | xx=rint(dd[0])+ii[0].x;yy=rint(dd[1])+ii[0].y; |
244 | if(twoside) { |
||
245 | ii[0].x=pm->p[0]; ii[0].y=pm->p[1]; |
||
246 | ii[1].x=-rint(dd[2])+ii[0].x; ii[1].y=-rint(dd[3])+ii[0].y; |
||
247 | ii[2].x=-rint(dd[4])+ii[0].x; ii[2].y=-rint(dd[5])+ii[0].y; |
||
8163 | bpr | 248 | gdImageFilledPolygon(image, ii,3,pm->color[0]); |
17578 | bpr | 249 | if(tikz_file) |
250 | fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i) -- (%i, %i) -- cycle;\n", |
||
251 | tikz_options(pm->color[0],1),ii[0].x,flip(ii[0].y),ii[1].x,flip(ii[1].y),ii[2].x,flip(ii[2].y)); |
||
12473 | bpr | 252 | } |
18125 | bpr | 253 | stem: if(pm->fill==-1 || pm->fill==2) |
12473 | bpr | 254 | myDashedLine(image,pm->p[0],pm->p[1],xx,yy,pm->color[0]); |
255 | else |
||
256 | gdImageLine(image,pm->p[0],pm->p[1],xx,yy,pm->color[0]); |
||
17578 | bpr | 257 | if(tikz_file) |
258 | fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n", |
||
17584 | bpr | 259 | tikz_options(pm->color[0],pm->fill),pm->p[0],flip(pm->p[1]),xx,flip(yy)); |
12473 | bpr | 260 | if(vimg_enable) vimg_line(scale_buf[0],scale_buf[1],scale_buf[2],scale_buf[3]); |
10 | reyssat | 261 | } |
262 | |||
7675 | bpr | 263 | /* Arrow */ |
1024 | bpr | 264 | void obj_arrow(objparm *pm) |
265 | { |
||
12473 | bpr | 266 | _obj_arrow(pm,0); |
1024 | bpr | 267 | } |
268 | |||
7675 | bpr | 269 | /* 2-sided arrow */ |
1024 | bpr | 270 | void obj_arrow2(objparm *pm) |
271 | { |
||
12473 | bpr | 272 | _obj_arrow(pm,1); |
1024 | bpr | 273 | } |
274 | |||
18047 | bpr | 275 | void _obj_arrows(objparm *pm, int twoside) |
276 | { |
||
277 | #define fat 0.27 |
||
278 | int i,l,xx,yy; |
||
279 | gdPoint ii[3]; |
||
280 | double dx,dy,length,dd[6]; |
||
281 | l=pm->pd[0];if(l<0) l=0; if(l>200) l=200; |
||
282 | scale(pm->pd+1,pm->p+1,pm->pcnt/2); |
||
283 | for (i=1;i<pm->pcnt;i+=4){ |
||
18119 | bpr | 284 | xx=ii[0].x=pm->p[i+2];yy=ii[0].y=pm->p[i+3]; |
285 | scale2(pm->pd[i]-pm->pd[i+2],pm->pd[i+1]-pm->pd[i+3],&dx,&dy); |
||
286 | length=sqrt(dx*dx+dy*dy); |
||
287 | if(length<3 || l<5) goto stem; |
||
288 | dd[0]=l*dx/length; dd[1]=l*dy/length; |
||
289 | dd[2]=dd[0]+dd[1]*fat; dd[3]=dd[1]-dd[0]*fat; |
||
290 | dd[4]=dd[0]-dd[1]*fat; dd[5]=dd[1]+dd[0]*fat; |
||
291 | ii[1].x=rint(dd[2])+ii[0].x; ii[1].y=rint(dd[3])+ii[0].y; |
||
292 | ii[2].x=rint(dd[4])+ii[0].x; ii[2].y=rint(dd[5])+ii[0].y; |
||
293 | gdImageFilledPolygon(image, ii,3,pm->color[0]); |
||
294 | if(tikz_file) |
||
18065 | bpr | 295 | fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i) -- (%i, %i) -- cycle;\n", |
296 | tikz_options(pm->color[0],1),ii[0].x,flip(ii[0].y),ii[1].x,flip(ii[1].y),ii[2].x,flip(ii[2].y)); |
||
297 | xx=rint(dd[0])+ii[0].x;yy=rint(dd[1])+ii[0].y; |
||
298 | if(twoside) { |
||
299 | ii[0].x=pm->p[i]; ii[0].y=pm->p[i+1]; |
||
300 | ii[1].x=-rint(dd[2])+ii[0].x; ii[1].y=-rint(dd[3])+ii[0].y; |
||
301 | ii[2].x=-rint(dd[4])+ii[0].x; ii[2].y=-rint(dd[5])+ii[0].y; |
||
302 | gdImageFilledPolygon(image, ii,3,pm->color[0]); |
||
303 | if(tikz_file) |
||
304 | fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i) -- (%i, %i) -- cycle;\n", |
||
305 | tikz_options(pm->color[0],1),ii[0].x,flip(ii[0].y),ii[1].x,flip(ii[1].y),ii[2].x,flip(ii[2].y)); |
||
18047 | bpr | 306 | } |
18125 | bpr | 307 | stem: if(pm->fill==-1 || pm->fill==2) |
18065 | bpr | 308 | myDashedLine(image,pm->p[i],pm->p[i+1],xx,yy,pm->color[0]); |
309 | else |
||
310 | gdImageLine(image,pm->p[i],pm->p[i+1],xx,yy,pm->color[0]); |
||
311 | if(tikz_file) |
||
312 | fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n", |
||
313 | tikz_options(pm->color[0],pm->fill),pm->p[i],flip(pm->p[i+1]),xx,flip(yy)); |
||
314 | } |
||
18047 | bpr | 315 | } |
316 | |||
317 | /* Arrows */ |
||
318 | void obj_arrows(objparm *pm) |
||
319 | { |
||
320 | _obj_arrows(pm,0); |
||
321 | } |
||
322 | |||
323 | /* 2-sided arrows */ |
||
324 | void obj_arrows2(objparm *pm) |
||
325 | { |
||
326 | _obj_arrows(pm,1); |
||
327 | } |
||
328 | |||
7675 | bpr | 329 | /* horizontal line */ |
10 | reyssat | 330 | void obj_hline(objparm *pm) |
331 | { |
||
12473 | bpr | 332 | scale(pm->pd,pm->p,1); |
18125 | bpr | 333 | if(pm->fill==-1 || pm->fill==2) |
12473 | bpr | 334 | myDashedLine(image,0,pm->p[1],sizex,pm->p[1],pm->color[0]); |
335 | else |
||
336 | gdImageLine(image,0,pm->p[1],sizex,pm->p[1],pm->color[0]); |
||
17574 | bpr | 337 | if (tikz_file) |
338 | fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n", |
||
339 | tikz_options(pm->color[0],pm->fill),0,flip(pm->p[1]),sizex,flip(pm->p[1])); |
||
10 | reyssat | 340 | } |
341 | |||
18119 | bpr | 342 | static void line_extend(int x1, int y1, int x2, int y2, int* xend, int *yend) |
343 | { |
||
344 | double t1, t2, t3; |
||
345 | if (x2 != x1){t1 = (x2 > x1) ? sizex : 0; t1 = (t1 - x1)/(x2 - x1);} |
||
346 | else t1 = INFINITY; |
||
347 | if (y2 != y1){t2 = (y2 > y1) ? sizey : 0; t2 = (t2 - y1)/(y2 - y1);} |
||
348 | else t2 = INFINITY; |
||
349 | t3 = (t1 < t2) ? t1 : t2; |
||
350 | *xend = x1+t3*(x2-x1); |
||
351 | *yend = y1+t3*(y2-y1); |
||
352 | } |
||
18066 | bpr | 353 | |
18065 | bpr | 354 | /* halfline */ |
355 | void obj_halfline(objparm *pm) |
||
356 | { |
||
18119 | bpr | 357 | int xend,yend; |
18065 | bpr | 358 | scale(pm->pd,pm->p,2); |
18119 | bpr | 359 | line_extend(pm->p[0],pm->p[1],pm->p[2],pm->p[3],&xend,¥d); |
18125 | bpr | 360 | if(pm->fill==-1 || pm->fill==2) |
18119 | bpr | 361 | myDashedLine(image,pm->p[0],pm->p[1],xend,yend,pm->color[0]); |
18065 | bpr | 362 | else |
18119 | bpr | 363 | gdImageLine(image,pm->p[0],pm->p[1],xend,yend,pm->color[0]); |
18065 | bpr | 364 | if (tikz_file) |
365 | fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n", |
||
366 | tikz_options(pm->color[0],pm->fill), |
||
18119 | bpr | 367 | pm->p[0],flip(pm->p[1]),xend,flip(yend)); |
18065 | bpr | 368 | } |
17574 | bpr | 369 | |
18119 | bpr | 370 | void obj_fullline(objparm *pm) |
371 | { |
||
372 | int xstart,ystart,xend,yend; |
||
373 | scale(pm->pd,pm->p,2); |
||
374 | line_extend(pm->p[0],pm->p[1],pm->p[2],pm->p[3],&xend,¥d); |
||
375 | line_extend(pm->p[2],pm->p[3],pm->p[0],pm->p[1],&xstart,&ystart); |
||
18125 | bpr | 376 | if(pm->fill==-1 || pm->fill==2) |
18119 | bpr | 377 | myDashedLine(image,xstart,ystart,xend,yend,pm->color[0]); |
378 | else |
||
379 | gdImageLine(image,xstart,ystart,xend,yend,pm->color[0]); |
||
380 | if (tikz_file) |
||
381 | fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n", |
||
382 | tikz_options(pm->color[0],pm->fill),xstart,flip(ystart),xend,flip(yend)); |
||
383 | } |
||
384 | |||
385 | void obj_fulllines(objparm *pm) |
||
386 | { |
||
387 | int i,xstart,ystart,xend,yend; |
||
388 | scale(pm->pd,pm->p,pm->pcnt/2); |
||
389 | if (tikz_file) |
||
390 | fprintf(tikz_file, "\\draw\[%s]",tikz_options(pm->color[0],pm->fill)); |
||
391 | for (i=0;i<pm->pcnt;i+=4){ |
||
392 | line_extend(pm->p[i],pm->p[i+1],pm->p[i+2],pm->p[i+3],&xend,¥d); |
||
393 | line_extend(pm->p[i+2],pm->p[i+3],pm->p[i],pm->p[i+1],&xstart,&ystart); |
||
18125 | bpr | 394 | if(pm->fill==-1 || pm->fill==2) |
18119 | bpr | 395 | myDashedLine(image,xstart,ystart,xend,yend,pm->color[0]); |
396 | else |
||
397 | gdImageLine(image,xstart,ystart,xend,yend,pm->color[0]); |
||
398 | if (tikz_file) |
||
399 | fprintf(tikz_file, "(%i,%i)--(%i, %i)",xstart,flip(ystart),xend,flip(yend)); |
||
400 | } |
||
401 | if (tikz_file) |
||
402 | fprintf(tikz_file, ";\n"); |
||
403 | } |
||
404 | |||
7675 | bpr | 405 | /* vertical line */ |
10 | reyssat | 406 | void obj_vline(objparm *pm) |
407 | { |
||
12473 | bpr | 408 | scale(pm->pd,pm->p,1); |
18125 | bpr | 409 | if(pm->fill==-1 || pm->fill==2) |
12473 | bpr | 410 | myDashedLine(image,pm->p[0],0,pm->p[0],sizey,pm->color[0]); |
411 | else |
||
412 | gdImageLine(image,pm->p[0],0,pm->p[0],sizey,pm->color[0]); |
||
17574 | bpr | 413 | if (tikz_file) |
414 | fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n", |
||
415 | tikz_options(pm->color[0],pm->fill),pm->p[0],0,pm->p[0],sizey); |
||
10 | reyssat | 416 | } |
417 | |||
7675 | bpr | 418 | /* dashed line */ |
10 | reyssat | 419 | void obj_dline(objparm *pm) |
420 | { |
||
12473 | bpr | 421 | scale(pm->pd,pm->p,2); |
422 | myDashedLine(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3], pm->color[0]); |
||
17574 | bpr | 423 | if (tikz_file) |
424 | fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n", |
||
425 | tikz_options(pm->color[0],-1), |
||
426 | pm->p[0],flip(pm->p[1]),pm->p[2],flip(pm->p[3])); |
||
10 | reyssat | 427 | } |
428 | |||
7675 | bpr | 429 | /* parallel lines. |
430 | * x1,y1,x2,y2,xv,yv,n,color */ |
||
10 | reyssat | 431 | void obj_parallel(objparm *pm) |
432 | { |
||
18123 | bpr | 433 | int i, n, xi,yi; |
434 | double xv,yv; |
||
435 | n=pm->pd[6]; if(n<0) return; if(n>256) n=256; |
||
436 | scale(pm->pd,pm->p,3); |
||
437 | scale2(pm->pd[4],pm->pd[5],&xv,&yv); |
||
438 | if (tikz_file) |
||
439 | fprintf(tikz_file, "\\draw\[%s]", tikz_options(pm->color[0],pm->fill)); |
||
440 | for(i=0;i<n;i++) { |
||
441 | xi=rint(i*xv); yi=rint(i*yv); |
||
18125 | bpr | 442 | if(pm->fill==-1 || pm->fill==2) |
18123 | bpr | 443 | myDashedLine(image,pm->p[0]+xi,pm->p[1]+yi,pm->p[2]+xi,pm->p[3]+yi, |
444 | pm->color[0]); |
||
445 | else |
||
446 | gdImageLine(image,pm->p[0]+xi,pm->p[1]+yi,pm->p[2]+xi,pm->p[3]+yi, |
||
447 | pm->color[0]); |
||
448 | if (tikz_file) |
||
449 | fprintf(tikz_file, "(%i,%i)--(%i, %i)", |
||
450 | pm->p[0]+xi,flip(pm->p[1]+yi),pm->p[2]+xi,flip(pm->p[3]+yi)); |
||
451 | if(vimg_enable) vimg_line(scale_buf[0]+i*(scale_buf[4]-transx), |
||
452 | scale_buf[1]+i*(scale_buf[5]-transy), |
||
453 | scale_buf[2]+i*(scale_buf[4]-transx), |
||
454 | scale_buf[3]+i*(scale_buf[5]-transy)); |
||
455 | } |
||
17914 | bpr | 456 | if(tikz_file) fprintf(tikz_file,";\n"); |
10 | reyssat | 457 | } |
458 | |||
7675 | bpr | 459 | /* rectangle */ |
10 | reyssat | 460 | void obj_rect(objparm *pm) |
461 | { |
||
12473 | bpr | 462 | int x1,y1,x2,y2; |
463 | scale(pm->pd,pm->p,2); |
||
464 | x1=min(pm->p[0],pm->p[2]); x2=max(pm->p[0],pm->p[2]); |
||
465 | y1=min(pm->p[1],pm->p[3]); y2=max(pm->p[1],pm->p[3]); |
||
18140 | bpr | 466 | if(pm->fill!=0){ |
467 | if(pm->fill==-1 || pm->fill==2){ |
||
468 | myDashedLine(image,x1,y1,x1,y2,pm->color[0]); |
||
469 | myDashedLine(image,x1,y2,x2,y2,pm->color[0]); |
||
470 | myDashedLine(image,x2,y2,x2,y1,pm->color[0]); |
||
471 | myDashedLine(image,x2,y1,x1,y1,pm->color[0]); |
||
472 | } |
||
473 | if(pm->fill==1 || pm->fill==2) |
||
474 | gdImageFilledRectangle(image,x1,y1,x2,y2,pm->color[0]); |
||
475 | } |
||
12473 | bpr | 476 | else |
477 | gdImageRectangle(image,x1,y1,x2,y2,pm->color[0]); |
||
17584 | bpr | 478 | if(tikz_file) |
479 | fprintf(tikz_file, |
||
480 | "\\draw\[%s] (%i,%i) rectangle (%i,%i);\n", |
||
481 | tikz_options(pm->color[0],pm->fill),x1,flip(y1),x2,flip(y2)); |
||
12473 | bpr | 482 | if(vimg_enable) vimg_rect(scale_buf[0],scale_buf[1],scale_buf[2],scale_buf[3]); |
10 | reyssat | 483 | } |
484 | |||
7675 | bpr | 485 | /* square */ |
10 | reyssat | 486 | void obj_square(objparm *pm) |
487 | { |
||
12473 | bpr | 488 | int w,h; |
489 | scale(pm->pd,pm->p,1); |
||
490 | w=rint(pm->pd[2]); h=rint(pm->pd[2]); |
||
18142 | bpr | 491 | if(pm->fill!=0){ |
492 | if(pm->fill==-1 || pm->fill==2){ |
||
493 | myDashedLine(image,pm->p[0],pm->p[1],pm->p[0]+w,pm->p[1],pm->color[0]); |
||
494 | myDashedLine(image,pm->p[0]+w,pm->p[1],pm->p[0]+w,pm->p[1]+h,pm->color[0]); |
||
495 | myDashedLine(image,pm->p[0]+w,pm->p[1]+h,pm->p[0],pm->p[1]+h,pm->color[0]); |
||
496 | myDashedLine(image,pm->p[0],pm->p[1]+h,pm->p[0],pm->p[1],pm->color[0]); |
||
497 | } |
||
498 | if(pm->fill==1 || pm->fill==2) |
||
12473 | bpr | 499 | gdImageFilledRectangle(image,pm->p[0],pm->p[1], |
18123 | bpr | 500 | pm->p[0]+w,pm->p[1]+h,pm->color[0]); |
18142 | bpr | 501 | } |
12473 | bpr | 502 | else |
503 | gdImageRectangle(image,pm->p[0],pm->p[1], |
||
504 | pm->p[0]+w,pm->p[1]+h,pm->color[0]); |
||
17574 | bpr | 505 | if(tikz_file){ |
506 | fprintf(tikz_file, |
||
507 | "\\draw\[%s] (%i,%i) rectangle (%i,%i);\n", |
||
508 | tikz_options(pm->color[0],pm->fill),pm->p[0],flip(pm->p[1]), |
||
509 | pm->p[0]+w,flip(pm->p[1]+h)); |
||
510 | } |
||
12473 | bpr | 511 | if(vimg_enable) vimg_rect(scale_buf[0],scale_buf[1], |
512 | scale_buf[0]+pm->pd[2],scale_buf[1]+pm->pd[2]); |
||
10 | reyssat | 513 | } |
514 | |||
7675 | bpr | 515 | /* triangle */ |
10 | reyssat | 516 | void obj_triangle(objparm *pm) |
517 | { |
||
12473 | bpr | 518 | scale(pm->pd,pm->p,3); |
18131 | bpr | 519 | int i,n=2; |
520 | if(pm->fill!=0){ |
||
521 | if(pm->fill==-1 || pm->fill==2){ |
||
522 | for(i=0;i<n;i+=1) |
||
523 | myDashedLine(image,pm->p[2*i],pm->p[2*i+1],pm->p[2*i+2],pm->p[2*i+3],pm->color[0]); |
||
524 | myDashedLine(image,pm->p[2*n],pm->p[2*n+1],pm->p[0],pm->p[1],pm->color[0]); |
||
525 | } |
||
526 | if(pm->fill==1 || pm->fill==2) |
||
527 | gdImageFilledPolygon(image,(gdPointPtr) pm->p,3,pm->color[0]); |
||
528 | } |
||
12473 | bpr | 529 | else |
530 | gdImagePolygon(image,(gdPointPtr) pm->p,3,pm->color[0]); |
||
17574 | bpr | 531 | if (tikz_file) |
532 | fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i) -- (%i, %i) -- cycle;\n", |
||
533 | tikz_options(pm->color[0],pm->fill),pm->p[0],flip(pm->p[1]),pm->p[2],flip(pm->p[3]),pm->p[4],flip(pm->p[5])); |
||
12473 | bpr | 534 | if(vimg_enable) vimg_polyline(scale_buf,3,1); |
10 | reyssat | 535 | } |
536 | |||
7675 | bpr | 537 | /* polygon */ |
10 | reyssat | 538 | void obj_poly(objparm *pm) |
539 | { |
||
17574 | bpr | 540 | int cnt,i; |
12473 | bpr | 541 | cnt=(pm->pcnt)/2; |
542 | scale(pm->pd,pm->p,cnt); |
||
18125 | bpr | 543 | if(pm->fill==1 || pm->fill==2) |
12473 | bpr | 544 | gdImageFilledPolygon(image,(gdPointPtr) pm->p,cnt,pm->color[0]); |
545 | else |
||
546 | gdImagePolygon(image,(gdPointPtr) pm->p,cnt,pm->color[0]); |
||
17614 | bpr | 547 | if(tikz_file){ |
548 | fprintf(tikz_file,"\\draw\[%s] (%i,%i) --",tikz_options(pm->color[0],pm->fill),pm->p[0],flip(pm->p[1])); |
||
549 | for (i= 1; i<cnt; i++) |
||
550 | fprintf(tikz_file,"(%i,%i)--", pm->p[2*i],flip(pm->p[2*i+1])); |
||
551 | fprintf(tikz_file," cycle;\n"); |
||
552 | } |
||
12473 | bpr | 553 | if(vimg_enable) vimg_polyline(scale_buf,cnt,1); |
10 | reyssat | 554 | } |
555 | |||
7675 | bpr | 556 | /* rays */ |
10 | reyssat | 557 | void obj_rays(objparm *pm) |
558 | { |
||
12473 | bpr | 559 | int i, n; |
560 | n=(pm->pcnt)/2; |
||
561 | scale(pm->pd,pm->p,n); |
||
17920 | bpr | 562 | if (tikz_file) |
563 | fprintf(tikz_file, "\\draw\[%s]",tikz_options(pm->color[0],pm->fill)); |
||
12473 | bpr | 564 | for(i=2;i<2*n;i+=2) { |
18125 | bpr | 565 | if(pm->fill==-1 || pm->fill==2) |
18123 | bpr | 566 | myDashedLine(image,pm->p[0],pm->p[1],pm->p[i],pm->p[i+1],pm->color[0]); |
567 | else |
||
568 | gdImageLine(image,pm->p[0],pm->p[1],pm->p[i],pm->p[i+1],pm->color[0]); |
||
17574 | bpr | 569 | if (tikz_file) |
17920 | bpr | 570 | fprintf(tikz_file, "(%i,%i) -- (%i,%i)", |
571 | pm->p[0],flip(pm->p[1]),pm->p[i],flip(pm->p[i+1])); |
||
12473 | bpr | 572 | if(vimg_enable) vimg_line(scale_buf[0],scale_buf[1], |
573 | scale_buf[i],scale_buf[i+1]); |
||
574 | } |
||
17920 | bpr | 575 | if (tikz_file) fprintf(tikz_file,";\n"); |
10 | reyssat | 576 | } |
8414 | bpr | 577 | /* crosshair */ |
578 | void obj_crosshair(objparm *pm) |
||
579 | { |
||
12473 | bpr | 580 | scale(pm->pd,pm->p,2); |
581 | gdImageLine(image,pm->p[0]+width2,pm->p[1]+width2,pm->p[0]-width2,pm->p[1]-width2,pm->color[0]); |
||
582 | gdImageLine(image,pm->p[0]-width2,pm->p[1]+width2,pm->p[0]+width2,pm->p[1]-width2,pm->color[0]); |
||
17574 | bpr | 583 | if (tikz_file){ |
584 | fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n", |
||
585 | tikz_options(pm->color[0],pm->fill),pm->p[0]+width2,flip(pm->p[1]+width2),pm->p[0]-width2,flip(pm->p[1]-width2)); |
||
586 | fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n", |
||
587 | tikz_options(pm->color[0],pm->fill),pm->p[0]-width2,flip(pm->p[1]+width2),pm->p[0]+width2,flip(pm->p[1]-width2)); |
||
588 | } |
||
8414 | bpr | 589 | } |
590 | /* crosshairs */ |
||
10 | reyssat | 591 | |
8414 | bpr | 592 | void obj_crosshairs(objparm *pm) |
593 | { |
||
12473 | bpr | 594 | int i, n; |
595 | n=(pm->pcnt)/2; |
||
596 | scale(pm->pd,pm->p,n); |
||
17921 | bpr | 597 | if (tikz_file) |
598 | fprintf(tikz_file, "\\draw\[%s]",tikz_options(pm->color[0],pm->fill)); |
||
12473 | bpr | 599 | for(i=0;i<2*n;i+=2) { |
600 | gdImageLine(image,pm->p[i]+width2,pm->p[i+1]+width2,pm->p[i]-width2,pm->p[i+1]-width2,pm->color[0]); |
||
601 | gdImageLine(image,pm->p[i]-width2,pm->p[i+1]+width2,pm->p[i]+width2,pm->p[i+1]-width2,pm->color[0]); |
||
17574 | bpr | 602 | if (tikz_file){ |
17921 | bpr | 603 | fprintf(tikz_file, "(%i, %i) -- (%i, %i) ", |
604 | pm->p[i]+width2,flip(pm->p[i+1]+width2),pm->p[i]-width2,flip(pm->p[i+1]-width2)); |
||
605 | fprintf(tikz_file, "(%i, %i) -- (%i, %i)", |
||
606 | pm->p[i]-width2,flip(pm->p[i+1]+width2),pm->p[i]+width2,flip(pm->p[i+1]-width2)); |
||
17574 | bpr | 607 | } |
12473 | bpr | 608 | } |
17921 | bpr | 609 | if (tikz_file) fprintf(tikz_file,";\n"); |
8414 | bpr | 610 | } |
611 | |||
612 | |||
7675 | bpr | 613 | /* segments */ |
10 | reyssat | 614 | void obj_lines(objparm *pm) |
615 | { |
||
17914 | bpr | 616 | int i, n; |
617 | n=(pm->pcnt)/2; |
||
618 | scale(pm->pd,pm->p,n); |
||
18123 | bpr | 619 | if (tikz_file){ |
17914 | bpr | 620 | fprintf(tikz_file,"\\draw\[%s] (%i,%i)", |
621 | tikz_options(pm->color[0],pm->fill),pm->p[0],flip(pm->p[1])); |
||
622 | for(i=2;i<2*n;i+=2) |
||
623 | fprintf(tikz_file, "--(%i,%i)",pm->p[i],flip(pm->p[i+1])); |
||
624 | fprintf(tikz_file, ";\n"); |
||
625 | } |
||
626 | for(i=2;i<2*n;i+=2){ |
||
18125 | bpr | 627 | if(pm->fill==-1 || pm->fill==2 ) |
18123 | bpr | 628 | myDashedLine(image,pm->p[i-2],pm->p[i-1],pm->p[i],pm->p[i+1],pm->color[0]); |
629 | else |
||
630 | gdImageLine(image,pm->p[i-2],pm->p[i-1],pm->p[i],pm->p[i+1],pm->color[0]); |
||
17914 | bpr | 631 | if(vimg_enable) vimg_polyline(scale_buf,n,0); |
17574 | bpr | 632 | } |
10 | reyssat | 633 | } |
16344 | bpr | 634 | /*segments from x1,y1 to x2,y2, x3,y3 to x4,y4, etc */ |
635 | void obj_segments(objparm *pm) |
||
636 | { |
||
637 | int i, n; |
||
18317 | bpr | 638 | n=(pm->pcnt)/2; |
639 | scale(pm->pd,pm->p,n); |
||
17914 | bpr | 640 | if (tikz_file) |
641 | fprintf(tikz_file, "\\draw\[%s]",tikz_options(pm->color[0],pm->fill)); |
||
18317 | bpr | 642 | for(i=0;i<2*n;i+=4){ |
18125 | bpr | 643 | if(pm->fill==-1 || pm->fill==2) |
18123 | bpr | 644 | myDashedLine(image,pm->p[i],pm->p[i+1],pm->p[i+2],pm->p[i+3],pm->color[0]); |
645 | else |
||
646 | gdImageLine(image,pm->p[i],pm->p[i+1],pm->p[i+2],pm->p[i+3],pm->color[0]); |
||
17914 | bpr | 647 | if (tikz_file) |
648 | fprintf(tikz_file, "(%i,%i)--(%i,%i)", |
||
649 | pm->p[i],flip(pm->p[i+1]),pm->p[i+2],flip(pm->p[i+3])); |
||
17574 | bpr | 650 | } |
17914 | bpr | 651 | if(tikz_file) fprintf(tikz_file, ";\n"); |
16344 | bpr | 652 | } |
18317 | bpr | 653 | |
7675 | bpr | 654 | /* segments */ |
10 | reyssat | 655 | void obj_dlines(objparm *pm) |
656 | { |
||
17914 | bpr | 657 | int i, n; |
658 | n=(pm->pcnt)/2; |
||
659 | scale(pm->pd,pm->p,n); |
||
18123 | bpr | 660 | if (tikz_file){ |
17914 | bpr | 661 | fprintf(tikz_file,"\\draw\[%s] (%i,%i)", |
662 | tikz_options(pm->color[0],pm->fill),pm->p[0],flip(pm->p[1])); |
||
663 | for(i=2;i<2*n;i+=2) |
||
664 | fprintf(tikz_file, "--(%i,%i)",pm->p[i],flip(pm->p[i+1])); |
||
665 | fprintf(tikz_file, ";\n"); |
||
666 | } |
||
667 | for(i=2;i<2*n;i+=2) |
||
668 | myDashedLine(image,pm->p[i-2],pm->p[i-1],pm->p[i],pm->p[i+1],pm->color[0]); |
||
669 | if(vimg_enable) vimg_polyline(scale_buf,n,0); |
||
10 | reyssat | 670 | } |
671 | |||
7675 | bpr | 672 | /* points */ |
10 | reyssat | 673 | void obj_points(objparm *pm) |
674 | { |
||
17914 | bpr | 675 | int i, n; |
676 | n=(pm->pcnt)/2; |
||
677 | scale(pm->pd,pm->p,n); |
||
678 | for(i=0;i<2*n;i+=2) gdImageSetPixel(image,pm->p[i],pm->p[i+1],pm->color[0]); |
||
679 | if(tikz_file) { |
||
680 | fprintf(tikz_file, "\\draw\[%s]", tikz_options(pm->color[0],pm->fill)); |
||
681 | for(i=0;i<2*n;i+=2) |
||
682 | fprintf(tikz_file,"(%i,%i)circle(1pt)",pm->p[i],flip(pm->p[i+1])); |
||
683 | fprintf(tikz_file,";\n"); |
||
684 | } |
||
10 | reyssat | 685 | } |
686 | |||
7675 | bpr | 687 | /* lattice. |
688 | * x0,y0,xv1,yv1,xv2,yv2,n1,n2,color */ |
||
10 | reyssat | 689 | void obj_lattice(objparm *pm) |
690 | { |
||
17914 | bpr | 691 | int n1,n2,i1,i2,xi1,yi1,xi2,yi2; |
692 | double xv1,xv2,yv1,yv2; |
||
693 | n1=pm->pd[6];n2=pm->pd[7]; if(n1<0 || n2<0) return; |
||
694 | if(n1>256) n1=256; |
||
695 | if(n2>256) n2=256; |
||
696 | scale(pm->pd,pm->p,1); |
||
697 | scale2(pm->pd[2],pm->pd[3],&xv1,&yv1); |
||
698 | scale2(pm->pd[4],pm->pd[5],&xv2,&yv2); |
||
699 | if(tikz_file) |
||
700 | fprintf(tikz_file,"\\draw[%s]", tikz_options(pm->color[0],0)); |
||
701 | for(i1=0;i1<n1;i1++) { |
||
702 | xi1=rint(i1*xv1)+pm->p[0]; yi1=rint(i1*yv1)+pm->p[1]; |
||
703 | for(i2=0;i2<n2;i2++) { |
||
704 | xi2=i2*xv2+xi1;yi2=i2*yv2+yi1; |
||
705 | gdImageSetPixel(image,xi2,yi2,pm->color[0]); |
||
706 | if(tikz_file) fprintf(tikz_file,"(%i,%i)circle(1pt)",xi2,flip(yi2)); |
||
707 | } |
||
708 | } |
||
709 | if(tikz_file) fprintf(tikz_file,";\n"); |
||
10 | reyssat | 710 | } |
711 | |||
7675 | bpr | 712 | /* arc */ |
18317 | bpr | 713 | /*trouble with gdImageArc as the angles are of type int */ |
18350 | bpr | 714 | void myGdImageArc(gdImagePtr im, double cx, double cy, double rx, double ry, double t1, double t2, int color) |
10 | reyssat | 715 | { |
18308 | bpr | 716 | int i,nb; |
18317 | bpr | 717 | double dt, r=rx>ry?rx:ry; |
18308 | bpr | 718 | t2-=t1; |
18455 | bpr | 719 | if(t2==0) return; |
18317 | bpr | 720 | t2-=360*floor(t2/360); |
18325 | bpr | 721 | if(t2==0) t2=360; |
18317 | bpr | 722 | t1*=DEG;t2*=DEG; |
18308 | bpr | 723 | nb = r*t2/3; |
724 | dt = t2/nb; |
||
725 | for (i=0; i<nb; ++i,t1+=dt) |
||
18350 | bpr | 726 | gdImageLine(im,rint(cx+rx*cos(t1)),rint(cy+ry*sin(t1)), |
727 | rint(cx+rx*cos(t1+dt)),rint(cy+ry*sin(t1+dt)),color); |
||
18317 | bpr | 728 | } |
729 | |||
730 | void obj_arc(objparm *pm) |
||
731 | { |
||
732 | scale(pm->pd,pm->p,1); |
||
733 | int rx=pm->pd[2]*xscale/2, ry=pm->pd[3]*yscale/2; |
||
734 | myGdImageArc(image, pm->p[0], pm->p[1], rx, ry, pm->pd[4],pm->pd[5],pm->color[0]); |
||
735 | if(tikz_file){ |
||
736 | pm->pd[5]-=pm->pd[4]; |
||
18455 | bpr | 737 | if (pm->pd[5]==0) return; |
18317 | bpr | 738 | pm->pd[5]-=360*floor(pm->pd[5]/360); |
18455 | bpr | 739 | if (pm->pd[5]==0) pm->pd[5]=360; |
18317 | bpr | 740 | pm->pd[5]+=pm->pd[4]; |
17914 | bpr | 741 | fprintf(tikz_file, |
18317 | bpr | 742 | "\\draw \[%s] (%i,%i) arc (%f:%f:%i and %i);\n", |
743 | tikz_options(pm->color[0],pm->fill), |
||
744 | (int)rint(pm->p[0]+rx*cos(DEG*pm->pd[4])), |
||
745 | flip((int)rint(pm->p[1]+ry*sin(DEG*pm->pd[4]))), |
||
746 | pm->pd[4],pm->pd[5],rx,-ry); |
||
17574 | bpr | 747 | } |
748 | /*FIXME echelle mauvaise*/ |
||
12473 | bpr | 749 | if(vimg_enable) vimg_arc(scale_buf[0],scale_buf[1], |
750 | 0.5*pm->pd[2],0.5*pm->pd[3],pm->pd[4],pm->pd[5]); |
||
10 | reyssat | 751 | } |
752 | |||
17676 | bpr | 753 | void obj_angle(objparm *pm) |
754 | { |
||
18320 | bpr | 755 | /* dans la doc: mettre les angles dans l'ordre ???? demander qu'ils soient entre 0 et 360 */ |
17676 | bpr | 756 | double dpts[6]; |
757 | int pts[6], wx=rint(2*pm->pd[2]*xscale), wy=rint(2*pm->pd[2]*yscale); |
||
758 | dpts[0]=pm->pd[0]; |
||
759 | dpts[1]=pm->pd[1]; |
||
760 | dpts[2]=pm->pd[0]+pm->pd[2]*cos(DEG*pm->pd[3]); |
||
761 | dpts[3]=pm->pd[1]+pm->pd[2]*sin(DEG*pm->pd[3]); |
||
762 | dpts[4]=pm->pd[0]+pm->pd[2]*cos(DEG*pm->pd[4]); |
||
763 | dpts[5]=pm->pd[1]+pm->pd[2]*sin(DEG*pm->pd[4]); |
||
764 | scale(dpts, pts, 3); |
||
18350 | bpr | 765 | gdImageLine(image,pts[0],pts[1],pts[2],pts[3],pm->color[0]); |
766 | gdImageLine(image,pts[0],pts[1],pts[4],pts[5],pm->color[0]); |
||
18308 | bpr | 767 | gdImageArc(image,pts[0],pts[1],wx,wy,pm->pd[3],pm->pd[4],pm->color[0]); |
17676 | bpr | 768 | if(tikz_file) { |
769 | fprintf(tikz_file, "\\draw\[%s, domain=%f:%f] plot ({%i+%f*cos(\\x)}, {%i+%f*sin(\\x)});\n", |
||
770 | tikz_options(pm->color[0],pm->fill),pm->pd[3],pm->pd[4],pts[0],wx*0.5,flip(pts[1]),wy*(-0.5)); |
||
17950 | bpr | 771 | fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i) (%i, %i) -- (%i, %i);\n", |
772 | tikz_options(pm->color[0],pm->fill),pts[0],flip(pts[1]),pts[2],flip(pts[3]),pts[0],flip(pts[1]),pts[4],flip(pts[5])); |
||
17676 | bpr | 773 | } |
774 | } |
||
7675 | bpr | 775 | /* Ellipse: centre 0,1, width 2, hight 3, color 4,5,6 */ |
10 | reyssat | 776 | void obj_ellipse(objparm *pm) |
777 | { |
||
12473 | bpr | 778 | scale(pm->pd,pm->p,1); |
17676 | bpr | 779 | pm->p[2]=pm->pd[2]*xscale; pm->p[3]=pm->pd[3]*yscale; |
18125 | bpr | 780 | if(pm->fill==1 || pm->fill==2) { |
12473 | bpr | 781 | gdImageArc(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],0,360, |
782 | color_bounder); |
||
783 | patchgdImageFillToBorder(image,pm->p[0],pm->p[1], |
||
784 | color_bounder,pm->color[0]); |
||
785 | } |
||
17676 | bpr | 786 | gdImageArc(image,pm->p[0],pm->p[1],rint(pm->p[2]),rint(pm->p[3]),0,360,pm->color[0]); |
787 | if(tikz_file) fprintf(tikz_file,"\\draw\[%s] (%i,%i) ellipse (%i and %i);\n\n", |
||
17912 | bpr | 788 | tikz_options(pm->color[0],pm->fill),pm->p[0],flip(pm->p[1]),(int) rint(0.5*pm->p[2]),(int) rint(0.5*pm->p[3])); |
17574 | bpr | 789 | if(vimg_enable) vimg_ellipse(scale_buf[0],scale_buf[1],0.5*pm->pd[2],0.5*pm->pd[3]); |
10 | reyssat | 790 | } |
791 | |||
17656 | bpr | 792 | /* Circle radius in pixels*/ |
10 | reyssat | 793 | void obj_circle(objparm *pm) |
794 | { |
||
12473 | bpr | 795 | scale(pm->pd,pm->p,1); |
796 | pm->p[2]=rint(pm->pd[2]); pm->p[3]=rint(pm->pd[2]); |
||
18125 | bpr | 797 | if(pm->fill==1 || pm->fill==2) { |
12473 | bpr | 798 | gdImageArc(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],0,360, |
799 | color_bounder); |
||
800 | patchgdImageFillToBorder(image,pm->p[0],pm->p[1], |
||
801 | color_bounder,pm->color[0]); |
||
802 | } |
||
803 | gdImageArc(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],0,360,pm->color[0]); |
||
17676 | bpr | 804 | if(tikz_file) fprintf(tikz_file, "\\draw\[%s] (%i, %i) circle (%i);\n", |
805 | tikz_options(pm->color[0],pm->fill),pm->p[0],flip(pm->p[1]),(int) rint(pm->pd[2]/2.)); |
||
10 | reyssat | 806 | } |
17656 | bpr | 807 | /* Circle, radius in xrange */ |
808 | void obj_circles(objparm *pm) |
||
809 | { |
||
810 | int i, n; |
||
811 | n=(pm->pcnt)/3; |
||
812 | for (i=0; i<n; ++i) scale(pm->pd+3*i, pm->p+3*i, 1); |
||
17942 | bpr | 813 | if (tikz_file) fprintf(tikz_file,"\\draw\[%s]",tikz_options(pm->color[0],pm->fill)); |
17656 | bpr | 814 | for(i=0;i<3*n;i+=3){ |
18125 | bpr | 815 | if(pm->fill==1 || pm->fill==2) { |
18118 | bpr | 816 | gdImageArc(image,pm->p[i],pm->p[i+1], |
817 | rint(2*pm->pd[i+2]*xscale),rint(2*pm->pd[i+2]*xscale),0,360, |
||
818 | color_bounder); |
||
819 | patchgdImageFillToBorder(image,pm->p[i],pm->p[i+1], |
||
820 | color_bounder,pm->color[0]); |
||
821 | } |
||
17656 | bpr | 822 | gdImageArc(image,pm->p[i],pm->p[i+1], |
18118 | bpr | 823 | rint(2*pm->pd[i+2]*xscale),rint(2*pm->pd[i+2]*xscale),0,360,pm->color[0]); |
17656 | bpr | 824 | if (tikz_file){ |
17942 | bpr | 825 | fprintf(tikz_file, "(%i, %i) circle (%i and %i)", |
826 | pm->p[i],flip(pm->p[i+1]),(int) rint(pm->pd[i+2]*xscale),(int) rint(pm->pd[i+2]*xscale)); |
||
17656 | bpr | 827 | } |
828 | } |
||
17942 | bpr | 829 | if (tikz_file) fprintf(tikz_file,";\n"); |
17656 | bpr | 830 | } |
17676 | bpr | 831 | /* ellipse, width in xrange,height in yrange */ |
17656 | bpr | 832 | void obj_ellipses(objparm *pm) |
833 | { |
||
834 | int i, n; |
||
835 | n=(pm->pcnt)/4; |
||
836 | for (i=0; i<n; ++i) scale(pm->pd+4*i, pm->p+4*i, 1); |
||
17943 | bpr | 837 | if (tikz_file) fprintf(tikz_file,"\\draw\[%s]",tikz_options(pm->color[0],pm->fill)); |
17656 | bpr | 838 | for(i=0;i<4*n;i+=4){ |
18125 | bpr | 839 | if(pm->fill==1 || pm->fill==2){ |
18123 | bpr | 840 | gdImageArc(image,pm->p[i],pm->p[i+1], |
841 | rint(pm->pd[i+2]*xscale),rint(pm->pd[i+2]*xscale),0,360, |
||
842 | color_bounder); |
||
843 | patchgdImageFillToBorder(image,pm->p[i],pm->p[i+1], |
||
844 | color_bounder,pm->color[0]); |
||
845 | } else |
||
846 | gdImageArc(image,pm->p[i],pm->p[i+1],rint(pm->pd[i+2]*xscale),rint(pm->pd[i+3]*yscale),0,360,pm->color[0]); |
||
17656 | bpr | 847 | if (tikz_file){ |
17943 | bpr | 848 | fprintf(tikz_file, "(%i, %i) circle (%i and %i)", |
849 | pm->p[i],flip(pm->p[i+1]),(int) rint(pm->pd[i+2]*xscale/2),(int) rint(pm->pd[i+3]*yscale/2)); |
||
17656 | bpr | 850 | } |
851 | } |
||
17943 | bpr | 852 | if (tikz_file) fprintf(tikz_file,";\n"); |
17656 | bpr | 853 | } |
17940 | bpr | 854 | typedef enum tikz_fill_options {grid, dot, hatch, diamond} tfo; |
17599 | bpr | 855 | int compar(const void *a, const void *b) {return *(int *)b - *(int *)a;} |
856 | |||
17662 | bpr | 857 | static void tikz_fill(int x, int y, int nx, int ny, int wall, int the_color, tfo opt) |
17599 | bpr | 858 | { |
17662 | bpr | 859 | int numpix=sizex*sizey, top = 0, a, c, cy, lx=0, rx=0, seed, nt,ct=0; |
17599 | bpr | 860 | int *stack = xmalloc(numpix*sizeof(int)); |
861 | int *stack2 = xmalloc(numpix*sizeof(int)); |
||
18132 | bpr | 862 | if (nx==0) nx=1; |
863 | if (ny==0) ny=1; |
||
864 | nt = abs(nx*ny); |
||
17599 | bpr | 865 | seed = gdImageGetPixel(image,x,y); |
866 | char *check = xmalloc(numpix); |
||
867 | while (numpix--) check[numpix]=0; |
||
868 | a=x+y*sizex; |
||
869 | check[a]=1; |
||
870 | stack[top++]=a; |
||
871 | while(top) |
||
872 | { |
||
873 | a = stack[--top]; |
||
874 | x = a%sizex; y = a/sizex; |
||
17662 | bpr | 875 | c = gdImageGetPixel(image,x,y); |
876 | if ((wall && (c == wall))||(!wall && c!=seed)) |
||
877 | continue; |
||
17599 | bpr | 878 | if (x>0 && !check[a-1]) {check[a-1]=1; stack[top++]=a-1;} |
879 | if (x+1<sizex && !check[a+1]) {check[a+1]=1; stack[top++]=a+1;} |
||
880 | if (y>0 && !check[a-sizex]) {check[a-sizex]=1; stack[top++]=a-sizex;} |
||
881 | if (y+1<sizey && !check[a+sizex]) {check[a+sizex]=1; stack[top++]=a+sizex;} |
||
882 | switch(opt) |
||
17621 | bpr | 883 | { |
17940 | bpr | 884 | case grid: if(((x%nx)!=(nx/2))&&((y%ny)!=(ny/2))) continue; break; |
885 | case dot: if(x%nx!=nx/2||y%ny!=ny/2) continue; break; |
||
17939 | bpr | 886 | case hatch: if((ny*x-nx*y+nt)%nt) continue; break; |
17940 | bpr | 887 | case diamond: if((ny*x+nx*y)%nt && (ny*x-nx*y+nt)%nt)continue; |
17621 | bpr | 888 | default: break; |
889 | } |
||
17599 | bpr | 890 | stack2[ct++]=a; |
891 | } |
||
892 | free(stack); |
||
893 | free(check); |
||
894 | if (ct==0) return; |
||
17938 | bpr | 895 | fprintf(tikz_file,"\\draw\[%s]", tikz_options(the_color,1)); |
17599 | bpr | 896 | qsort(stack2, ct, sizeof(int), compar); |
897 | cy=-1; |
||
898 | while (ct--) |
||
899 | { |
||
900 | a = stack2[ct]; |
||
901 | x = a%sizex; y = a/sizex; |
||
902 | if (y != cy || x != rx+1) |
||
903 | { |
||
17621 | bpr | 904 | if (cy >= 0) |
905 | fprintf(tikz_file, |
||
17933 | bpr | 906 | "(%.2f,%.2f)rectangle(%.2f,%.2f)", |
907 | lx-0.0,flip(cy-0.0),rx+0.0,flip(cy+0.0)); |
||
17621 | bpr | 908 | cy = y; |
909 | lx = rx = x; |
||
17599 | bpr | 910 | } |
911 | else |
||
17621 | bpr | 912 | rx++; |
17599 | bpr | 913 | } |
914 | fprintf(tikz_file, |
||
17933 | bpr | 915 | "(%.2f,%.2f)rectangle(%.2f,%.2f);\n", |
916 | lx-0.0,flip(cy-0.0),rx+0.0,flip(cy+0.0)); |
||
17599 | bpr | 917 | free(stack2); |
918 | } |
||
18125 | bpr | 919 | void obj_dashed(objparm *pm){ dashed=1;} |
920 | void obj_filled(objparm *pm){ filled=1;} |
||
18159 | bpr | 921 | void obj_noreset(objparm *pm){ noreset=1;} |
922 | void obj_reset(objparm *pm){ noreset=0;dashed=0;filled=0;} |
||
17599 | bpr | 923 | |
7675 | bpr | 924 | /* flood fill */ |
10 | reyssat | 925 | void obj_fill(objparm *pm) |
926 | { |
||
12473 | bpr | 927 | scale(pm->pd,pm->p,1); |
17940 | bpr | 928 | if (tikz_file) tikz_fill(pm->p[0],pm->p[1],1,1,0,pm->color[0],grid); |
12473 | bpr | 929 | patchgdImageFill(image,pm->p[0],pm->p[1],pm->color[0]); |
10 | reyssat | 930 | } |
931 | |||
7675 | bpr | 932 | /* flood fill to border*/ |
10 | reyssat | 933 | void obj_fillb(objparm *pm) |
934 | { |
||
12473 | bpr | 935 | scale(pm->pd,pm->p,1); |
17940 | bpr | 936 | if (tikz_file) tikz_fill(pm->p[0],pm->p[1],1,1,pm->color[0],pm->color[1],grid); |
12473 | bpr | 937 | patchgdImageFillToBorder(image,pm->p[0],pm->p[1],pm->color[0],pm->color[1]); |
10 | reyssat | 938 | } |
939 | |||
940 | gdImagePtr himg; |
||
941 | |||
942 | int makehatchimage(int x, int y, int px, int py, int col) |
||
943 | { |
||
12473 | bpr | 944 | int c1,c2,r,g,b; |
945 | gdImagePtr saveimg; |
||
946 | himg=gdImageCreate(x,y); |
||
947 | c1=gdImageGetPixel(image,px,py); |
||
948 | r=gdImageRed(image,c1); g=gdImageGreen(image,c1); b=gdImageBlue(image,c1); |
||
949 | if(r>=255) r--; else r++; if(g>=255) g--; else g++; if(b>=255) b--; else b++; |
||
950 | c1=gdImageColorAllocate(himg,r,g,b); |
||
951 | r=gdImageRed(image,col); g=gdImageGreen(image,col); b=gdImageBlue(image,col); |
||
952 | c2=gdImageColorAllocate(himg,r,g,b); |
||
953 | if(width>1) { |
||
954 | savew=-1; saveimg=image; |
||
955 | image=himg; c2=widthcolor(width,c2); image=saveimg; |
||
956 | c2=gdBrushed; savew=-1; |
||
957 | } |
||
958 | return c2; |
||
10 | reyssat | 959 | } |
960 | |||
7675 | bpr | 961 | /* flood fill with hatching */ |
10 | reyssat | 962 | void obj_hatchfill(objparm *pm) |
963 | { |
||
12473 | bpr | 964 | int nx,ny,ax,ay, dir, c; |
965 | scale(pm->pd,pm->p,1); |
||
966 | nx=pm->pd[2]; ny=pm->pd[3]; ax=abs(nx); ay=abs(ny); |
||
967 | if(nx==0 && ny==0) {fly_error("bad displacement vector"); return;} |
||
968 | if((nx>0 && ny>0) || (nx<0 && ny<0)) dir=1; else dir=-1; |
||
969 | if(ax==0) {ax=100; dir=2;} |
||
970 | if(ay==0) {ay=100; dir=3;} |
||
971 | c=makehatchimage(ax,ay,pm->p[0],pm->p[1],pm->color[0]); |
||
972 | switch(dir) { |
||
973 | case -1: { |
||
974 | gdImageLine(himg,0,ay-1,ax-1,0,c); |
||
975 | if(width>1) { |
||
976 | gdImageLine(himg,-ax,ay-1,-1,0,c); |
||
977 | gdImageLine(himg,ax,ay-1,2*ax-1,0,c); |
||
978 | gdImageLine(himg,0,-1,ax-1,-ay,c); |
||
979 | gdImageLine(himg,0,2*ay-1,ax-1,ay,c); |
||
7675 | bpr | 980 | } |
12473 | bpr | 981 | break; |
982 | } |
||
983 | case 1: { |
||
984 | gdImageLine(himg,0,0,ax-1,ay-1,c); |
||
985 | if(width>1) { |
||
986 | gdImageLine(himg,-ax,0,-1,ay-1,c); |
||
987 | gdImageLine(himg,ax,0,2*ax-1,ay-1,c); |
||
988 | gdImageLine(himg,0,-ay,ax-1,-1,c); |
||
989 | gdImageLine(himg,0,ay,ax-1,2*ay-1,c); |
||
7675 | bpr | 990 | } |
12473 | bpr | 991 | break; |
992 | } |
||
993 | case 2: gdImageLine(himg,0,ay/2,ax-1,ay/2,c); break; |
||
17574 | bpr | 994 | case 3: gdImageLine(himg,ax/2,0,ax/2,ay-1,c); break; |
12473 | bpr | 995 | } |
17662 | bpr | 996 | if (tikz_file) tikz_fill(pm->p[0],pm->p[1],nx,ny,0,pm->color[0],hatch); |
12473 | bpr | 997 | gdImageSetTile(image,himg); |
998 | patchgdImageFill(image,pm->p[0],pm->p[1],gdTiled); |
||
999 | gdImageDestroy(himg); |
||
1000 | if(tiled) gdImageSetTile(image,tileimg); |
||
10 | reyssat | 1001 | } |
1002 | |||
7675 | bpr | 1003 | /* flood fill with grid */ |
10 | reyssat | 1004 | void obj_gridfill(objparm *pm) |
1005 | { |
||
12473 | bpr | 1006 | int nx,ny, c; |
1007 | scale(pm->pd,pm->p,1); |
||
1008 | nx=pm->pd[2]; ny=pm->pd[3]; nx=abs(nx); ny=abs(ny); |
||
1009 | if(nx==0 && ny==0) {fly_error("bad grid size"); return;} |
||
1010 | c=makehatchimage(nx,ny,pm->p[0],pm->p[1],pm->color[0]); |
||
17940 | bpr | 1011 | if (tikz_file) tikz_fill(pm->p[0],pm->p[1],nx,ny,0,pm->color[0],grid); |
12473 | bpr | 1012 | gdImageLine(himg,0,ny/2,nx-1,ny/2,c); gdImageLine(himg,nx/2,0,nx/2,ny-1,c); |
1013 | gdImageSetTile(image,himg); |
||
1014 | patchgdImageFill(image,pm->p[0],pm->p[1],gdTiled); |
||
1015 | gdImageDestroy(himg); |
||
1016 | if(tiled) gdImageSetTile(image,tileimg); |
||
10 | reyssat | 1017 | } |
1018 | |||
7675 | bpr | 1019 | /* flood fill with double hatching */ |
10 | reyssat | 1020 | void obj_diafill(objparm *pm) |
1021 | { |
||
12473 | bpr | 1022 | int nx,ny, c; |
1023 | scale(pm->pd,pm->p,1); |
||
1024 | nx=pm->pd[2]; ny=pm->pd[3]; nx=abs(nx); ny=abs(ny); |
||
1025 | if(nx==0 && ny==0) {fly_error("bad grid size"); return;} |
||
1026 | c=makehatchimage(nx,ny,pm->p[0],pm->p[1],pm->color[0]); |
||
17940 | bpr | 1027 | if (tikz_file) tikz_fill(pm->p[0],pm->p[1],nx,ny,0,pm->color[0],diamond); |
12473 | bpr | 1028 | gdImageLine(himg,0,0,nx-1,ny-1,c); gdImageLine(himg,0,ny-1,nx-1,0,c); |
1029 | gdImageSetTile(image,himg); |
||
1030 | patchgdImageFill(image,pm->p[0],pm->p[1],gdTiled); |
||
1031 | gdImageDestroy(himg); |
||
1032 | if(tiled) gdImageSetTile(image,tileimg); |
||
10 | reyssat | 1033 | } |
1034 | |||
17599 | bpr | 1035 | /* flood fill with dots */ |
10 | reyssat | 1036 | void obj_dotfill(objparm *pm) |
1037 | { |
||
12473 | bpr | 1038 | int nx,ny, c; |
1039 | scale(pm->pd,pm->p,1); |
||
1040 | nx=pm->pd[2]; ny=pm->pd[3]; nx=abs(nx); ny=abs(ny); |
||
1041 | if(nx==0 && ny==0) {fly_error("bad grid size"); return;} |
||
1042 | c=makehatchimage(nx,ny,pm->p[0],pm->p[1],pm->color[0]); |
||
17940 | bpr | 1043 | if (tikz_file) tikz_fill(pm->p[0],pm->p[1],nx,ny,0,pm->color[0],dot); |
12473 | bpr | 1044 | gdImageSetPixel(himg,nx/2,ny/2,c); |
1045 | gdImageSetTile(image,himg); |
||
1046 | patchgdImageFill(image,pm->p[0],pm->p[1],gdTiled); |
||
1047 | gdImageDestroy(himg); |
||
1048 | if(tiled) gdImageSetTile(image,tileimg); |
||
10 | reyssat | 1049 | } |
1050 | |||
1051 | struct { |
||
12473 | bpr | 1052 | char *name; |
1053 | gdFontPtr *fpt; |
||
17964 | bpr | 1054 | char *ftikz; |
10 | reyssat | 1055 | } fonttab[]={ |
17964 | bpr | 1056 | {"tiny", &gdFontTiny,"0.3"}, |
1057 | {"small", &gdFontSmall,"0.5"}, |
||
1058 | {"medium",&gdFontMediumBold,"0.7"}, |
||
1059 | {"large", &gdFontLarge,"0.9"}, |
||
1060 | {"giant", &gdFontGiant,"1"}, |
||
1061 | {"huge", &gdFontGiant,"1"} |
||
10 | reyssat | 1062 | }; |
1063 | |||
1064 | #define fonttab_no (sizeof(fonttab)/sizeof(fonttab[0])) |
||
1065 | |||
7675 | bpr | 1066 | /* string */ |
10 | reyssat | 1067 | void obj_string(objparm *pm) |
1068 | { |
||
12473 | bpr | 1069 | char *pp, *pe, *p2; |
1070 | int i; |
||
1071 | pp=pm->str; pe=strchr(pp,','); if(pe==NULL) { |
||
1072 | fly_error("too_few_parms"); return; |
||
1073 | } |
||
1074 | *pe++=0; pp=find_word_start(pp); *find_word_end(pp)=0; |
||
1075 | pe=find_word_start(pe); strip_trailing_spaces(pe); |
||
1076 | if(*pp) { |
||
1077 | for(i=0;i<fonttab_no && strcmp(pp,fonttab[i].name)!=0; i++); |
||
1078 | if(i>=fonttab_no) i=1; |
||
1079 | } |
||
1080 | else i=1; |
||
1081 | scale(pm->pd,pm->p,1); |
||
1082 | if(*pe=='"') { |
||
1083 | p2=strchr(pe+1,'"'); |
||
1084 | if(p2 && *(p2+1)==0) {*p2=0; pe++;} |
||
1085 | } |
||
17585 | bpr | 1086 | if(pm->fill){ |
12473 | bpr | 1087 | gdImageStringUp(image,*(fonttab[i].fpt),pm->p[0],pm->p[1], (unsigned char*) pe, |
1088 | pm->color[0]); |
||
17964 | bpr | 1089 | if(tikz_file) fprintf(tikz_file,"\\draw (%i,%i) node[scale=%s,rotate=90,color=%s,anchor=north west,inner sep=0pt] {\\(%s\\)};\n", |
1090 | pm->p[0],flip(pm->p[1]),fonttab[i].ftikz,tikz_color(pm->color[0]),(unsigned char*) pe); |
||
17585 | bpr | 1091 | } |
1092 | else { |
||
12473 | bpr | 1093 | gdImageString(image,*(fonttab[i].fpt),pm->p[0],pm->p[1], (unsigned char*) pe, |
1094 | pm->color[0]); |
||
17964 | bpr | 1095 | if(tikz_file) fprintf(tikz_file,"\\draw (%i,%i) node[scale=%s,color=%s,anchor=north west,inner sep=0pt] {\\(%s\\)};\n", |
1096 | pm->p[0],flip(pm->p[1]),fonttab[i].ftikz,tikz_color(pm->color[0]),(unsigned char*) pe); |
||
17585 | bpr | 1097 | } |
10 | reyssat | 1098 | } |
17585 | bpr | 1099 | /*FIXME; giant does not exist in tikz and ... samething as huge */ |
7675 | bpr | 1100 | /* point */ |
10 | reyssat | 1101 | void obj_point(objparm *pm) |
1102 | { |
||
12473 | bpr | 1103 | scale(pm->pd,pm->p,1); |
1104 | gdImageSetPixel(image,pm->p[0],pm->p[1],pm->color[0]); |
||
17917 | bpr | 1105 | if(tikz_file) fprintf(tikz_file,"\\draw[%s] (%i,%i) circle (1pt);\n", |
17574 | bpr | 1106 | tikz_options(pm->color[0],0),pm->p[0],flip(pm->p[1])); |
10 | reyssat | 1107 | } |
1108 | |||
7675 | bpr | 1109 | /* copy an image file */ |
10 | reyssat | 1110 | void obj_copy(objparm *pm) |
1111 | { |
||
12473 | bpr | 1112 | char *pp; |
1113 | FILE *inf; |
||
1114 | gdImagePtr insimg; |
||
7615 | bpr | 1115 | |
12473 | bpr | 1116 | pp=find_word_start(pm->str);*find_word_end(pp)=0; |
1117 | inf=open4read(pp); |
||
1118 | if(inf==NULL) { |
||
17599 | bpr | 1119 | fly_error("file_does_not_exist"); return; |
12473 | bpr | 1120 | } |
1121 | insimg=gdImageCreateFromGif(inf); fclose(inf); |
||
1122 | if(insimg==NULL) { |
||
1123 | fly_error("bad_gif"); return; |
||
1124 | } |
||
1125 | scale(pm->pd,pm->p,1); |
||
1126 | if(pm->pd[2]<0 && pm->pd[3]<0 && pm->pd[4]<0 && pm->pd[5]<0) |
||
1127 | gdImageCopy(image,insimg,pm->p[0],pm->p[1],0,0, |
||
1128 | insimg->sx,insimg->sy); |
||
1129 | else |
||
1130 | gdImageCopy(image,insimg,pm->p[0],pm->p[1],pm->pd[2],pm->pd[3], |
||
1131 | pm->pd[4]-pm->pd[2],pm->pd[5]-pm->pd[3]); |
||
17587 | bpr | 1132 | if(tikz_file) fprintf(tikz_file, |
17618 | bpr | 1133 | "\\node[anchor=north west,inner sep=0pt] at (%i,%i) {\\includegraphics\[width=.05\\linewidth]{%s}};\n", |
17587 | bpr | 1134 | pm->p[0],flip(pm->p[1]),pm->str); |
1135 | gdImageDestroy(insimg); |
||
1136 | /*FIXME position non correcte; on ne peut pas utiliser une image gif */ |
||
10 | reyssat | 1137 | } |
1138 | |||
7675 | bpr | 1139 | /* copy an image file, with resizing */ |
10 | reyssat | 1140 | void obj_copyresize(objparm *pm) |
1141 | { |
||
12473 | bpr | 1142 | char *pp; |
1143 | FILE *inf; |
||
1144 | gdImagePtr insimg; |
||
7615 | bpr | 1145 | |
12473 | bpr | 1146 | pp=find_word_start(pm->str);*find_word_end(pp)=0; |
1147 | inf=open4read(pp); |
||
1148 | if(inf==NULL) { |
||
1149 | fly_error("file_not_found"); return; |
||
1150 | } |
||
1151 | insimg=gdImageCreateFromGif(inf); fclose(inf); |
||
1152 | if(insimg==NULL) { |
||
1153 | fly_error("bad_gif"); return; |
||
1154 | } |
||
1155 | scale(pm->pd+4,pm->p+4,2); |
||
1156 | if(pm->pd[0]<0 && pm->pd[1]<0 && pm->pd[2]<0 && pm->pd[3]<0) |
||
1157 | gdImageCopyResized(image,insimg,pm->p[4],pm->p[5],0,0, |
||
1158 | pm->p[6]-pm->p[4]+1,pm->p[7]-pm->p[5]+1, |
||
1159 | insimg->sx,insimg->sy); |
||
1160 | else |
||
1161 | gdImageCopyResized(image,insimg,pm->p[4],pm->p[5],pm->pd[0],pm->pd[1], |
||
1162 | pm->p[6]-pm->p[4]+1,pm->p[7]-pm->p[5]+1, |
||
1163 | pm->pd[2]-pm->pd[0]+1,pm->pd[3]-pm->pd[1]+1); |
||
1164 | gdImageDestroy(insimg); |
||
10 | reyssat | 1165 | } |
1166 | |||
7675 | bpr | 1167 | /* set brush or tile */ |
10 | reyssat | 1168 | void obj_setbrush(objparm *pm) |
1169 | { |
||
12473 | bpr | 1170 | char *pp; |
1171 | FILE *inf; |
||
1172 | gdImagePtr insimg; |
||
10 | reyssat | 1173 | |
12473 | bpr | 1174 | pp=find_word_start(pm->str); *find_word_end(pp)=0; |
1175 | inf=open4read(pp); if(inf==NULL) { |
||
1176 | fly_error("file_not_found"); return; |
||
1177 | } |
||
1178 | insimg=gdImageCreateFromGif(inf); fclose(inf); |
||
1179 | if(insimg==NULL) { |
||
1180 | fly_error("bad_gif"); return; |
||
1181 | } |
||
1182 | if(pm->fill) { |
||
1183 | gdImageSetTile(image,insimg); tiled=1; tileimg=insimg; |
||
1184 | } |
||
1185 | else { |
||
1186 | gdImageSetBrush(image,insimg);brushed=1; brushimg=insimg; |
||
1187 | } |
||
10 | reyssat | 1188 | } |
1189 | |||
7675 | bpr | 1190 | /* kill brush */ |
10 | reyssat | 1191 | void obj_killbrush(objparm *pm) |
1192 | { |
||
12473 | bpr | 1193 | if(brushimg) gdImageDestroy(brushimg); |
1194 | brushed=0; brushimg=NULL; |
||
10 | reyssat | 1195 | } |
1196 | |||
7675 | bpr | 1197 | /* kill tile */ |
10 | reyssat | 1198 | void obj_killtile(objparm *pm) |
1199 | { |
||
12473 | bpr | 1200 | if(tileimg) gdImageDestroy(tileimg); |
1201 | tiled=0; tileimg=NULL; |
||
10 | reyssat | 1202 | } |
1203 | |||
7675 | bpr | 1204 | /* set style */ |
10 | reyssat | 1205 | void obj_setstyle(objparm *pm) |
1206 | { |
||
12473 | bpr | 1207 | int i,t; |
1208 | t=pm->pcnt/3; if(t<=0) { |
||
1209 | fly_error("too_few_parms"); return; |
||
1210 | } |
||
1211 | for(i=0;i<t;i++) { |
||
1212 | if(pm->pd[3*i]<0 || pm->pd[3*i+1]<0 || pm->pd[3*i+2]<0) |
||
1213 | pm->p[i]=gdTransparent; |
||
1214 | else |
||
1215 | pm->p[i]=getcolor(pm->pd[3*i],pm->pd[3*i+1],pm->pd[3*i+2]); |
||
1216 | } |
||
1217 | gdImageSetStyle(image,pm->p,t); styled=1; |
||
10 | reyssat | 1218 | } |
1219 | |||
7675 | bpr | 1220 | /* kill style */ |
10 | reyssat | 1221 | void obj_killstyle(objparm *pm) |
1222 | { |
||
12473 | bpr | 1223 | styled=0; |
10 | reyssat | 1224 | } |
1225 | |||
7675 | bpr | 1226 | /* set transparent */ |
10 | reyssat | 1227 | void obj_transp(objparm *pm) |
1228 | { |
||
12473 | bpr | 1229 | gdImageColorTransparent(image,pm->color[0]); |
10 | reyssat | 1230 | } |
1231 | |||
7675 | bpr | 1232 | /* set interlace */ |
10 | reyssat | 1233 | void obj_interlace(objparm *pm) |
1234 | { |
||
12473 | bpr | 1235 | gdImageInterlace(image,1); |
10 | reyssat | 1236 | } |
1237 | |||
7675 | bpr | 1238 | /* set linewidth */ |
10 | reyssat | 1239 | void obj_linewidth(objparm *pm) |
1240 | { |
||
12473 | bpr | 1241 | if(pm->pd[0]<1 || pm->pd[0]>255) fly_error("bad_parms"); |
17574 | bpr | 1242 | width=pm->pd[0]; |
17612 | bpr | 1243 | if(tikz_file) fprintf(tikz_file,"\\pgfsetlinewidth{%fpt}\n",width*0.7); |
10 | reyssat | 1244 | } |
1245 | |||
8414 | bpr | 1246 | /* set crosshairsize */ |
1247 | void obj_crosshairsize(objparm *pm) |
||
1248 | { |
||
12473 | bpr | 1249 | if(pm->pd[0]<1 || pm->pd[0]>255) fly_error("bad_parms"); |
1250 | else width2=pm->pd[0]; |
||
8414 | bpr | 1251 | } |
1252 | |||
7675 | bpr | 1253 | /* set x range */ |
10 | reyssat | 1254 | void obj_xrange(objparm *pm) |
1255 | { |
||
12473 | bpr | 1256 | double dd; |
1257 | dd=pm->pd[1]-pm->pd[0]; |
||
1258 | xstart=pm->pd[0]; xscale=sizex/dd; |
||
10 | reyssat | 1259 | } |
1260 | |||
7675 | bpr | 1261 | /* set y range */ |
10 | reyssat | 1262 | void obj_yrange(objparm *pm) |
1263 | { |
||
12473 | bpr | 1264 | double dd; |
1265 | dd=pm->pd[1]-pm->pd[0]; |
||
1266 | ystart=pm->pd[1]; yscale=-sizey/dd; |
||
10 | reyssat | 1267 | } |
1268 | |||
7675 | bpr | 1269 | /* set x et y range */ |
10 | reyssat | 1270 | void obj_range(objparm *pm) |
1271 | { |
||
12473 | bpr | 1272 | double d1,d2; |
1273 | d1=pm->pd[1]-pm->pd[0]; d2=pm->pd[3]-pm->pd[2]; |
||
1274 | xstart=pm->pd[0]; xscale=(sizex-1)/d1; |
||
1275 | ystart=pm->pd[3]; yscale=-(sizey-1)/d2; |
||
10 | reyssat | 1276 | } |
1277 | |||
7675 | bpr | 1278 | /* set t range */ |
10 | reyssat | 1279 | void obj_trange(objparm *pm) |
1280 | { |
||
12473 | bpr | 1281 | /*double dd; |
1282 | dd=pm->pd[1]-pm->pd[0];*/ |
||
1283 | tstart=pm->pd[0]; tend=pm->pd[1]; |
||
1284 | tranged=1; |
||
10 | reyssat | 1285 | } |
1286 | |||
7675 | bpr | 1287 | /* set tstep (plotting step) */ |
10 | reyssat | 1288 | void obj_tstep(objparm *pm) |
1289 | { |
||
12473 | bpr | 1290 | int dd; |
1291 | dd=pm->pd[0]; |
||
1292 | if(dd<3) { |
||
1293 | fly_error("bad_step"); return; |
||
1294 | } |
||
1295 | if(dd>2000) dd=2000; |
||
1296 | tstep=dd; |
||
10 | reyssat | 1297 | } |
1298 | |||
7675 | bpr | 1299 | /* set plotjump (plot jump break threashold) */ |
10 | reyssat | 1300 | void obj_plotjump(objparm *pm) |
1301 | { |
||
12473 | bpr | 1302 | int dd; |
1303 | dd=pm->pd[0]; |
||
1304 | if(dd<3) dd=3; |
||
1305 | if(dd>MAX_SIZE) dd=MAX_SIZE; |
||
1306 | plotjump=dd; |
||
10 | reyssat | 1307 | } |
1308 | |||
7675 | bpr | 1309 | /* plot a curve, either parametric or explicit */ |
6578 | bpr | 1310 | void _obj_plot(objparm *pm,int dash) |
10 | reyssat | 1311 | { |
12473 | bpr | 1312 | int i,j,n,dist,xx,yy,varpos; |
1313 | char p1[MAX_LINELEN+1], p2[MAX_LINELEN+1]; |
||
1314 | char *varn, *pp; |
||
1315 | double dc[2],t,v; |
||
1316 | int ic[2],oc[2]; |
||
10 | reyssat | 1317 | |
12473 | bpr | 1318 | n=itemnum(pm->str); |
1319 | if(n<1) { |
||
1320 | fly_error("bad_parms"); return; |
||
1321 | } |
||
1322 | fnd_item(pm->str,1,p1); fnd_item(pm->str,2,p2); |
||
1323 | if(n==1 && !tranged) v=sizex/xscale/tstep; |
||
1324 | else v=(tend-tstart)/tstep; |
||
1325 | if(n==1) varn="x"; else varn="t"; |
||
1326 | for(pp=varchr(p1,varn); pp; pp=varchr(pp,varn)) { |
||
1327 | string_modify(p1,pp,pp+strlen(varn),EV_T); |
||
1328 | pp+=strlen(EV_T); |
||
1329 | } |
||
1330 | for(pp=varchr(p2,varn); pp; pp=varchr(pp,varn)) { |
||
1331 | string_modify(p2,pp,pp+strlen(varn),EV_T); |
||
7675 | bpr | 1332 | pp+=strlen(EV_T); |
12473 | bpr | 1333 | } |
1334 | varpos=eval_getpos(EV_T); |
||
1335 | if(varpos<0) return; /* unknown error */ |
||
1336 | evalue_compile(p1); evalue_compile(p2); |
||
1337 | if(vimg_enable) vimg_plotstart(); |
||
17933 | bpr | 1338 | if (tikz_file) fprintf(tikz_file,"\%\%begin plot\n\\draw\[%s]", |
1339 | tikz_options(pm->color[0],-dash)); |
||
12473 | bpr | 1340 | for(i=j=0;i<=tstep;i++) { |
1341 | if(n==1) { |
||
1342 | if(tranged) t=tstart+i*v; else t=xstart+i*v; |
||
1343 | eval_setval(varpos,t); dc[0]=t; dc[1]=strevalue(p1); |
||
10 | reyssat | 1344 | } |
17621 | bpr | 1345 | else { |
1346 | t=tstart+i*v; eval_setval(varpos,t); |
||
1347 | dc[0]=strevalue(p1); dc[1]=strevalue(p2); |
||
10 | reyssat | 1348 | } |
17621 | bpr | 1349 | if(!isfinite(dc[0]) || !isfinite(dc[1])) ic[0]=ic[1]=-BOUND; |
1350 | else scale(dc,ic,1); |
||
1351 | if(vimg_enable) vimg_plot1 (scale_buf[0],scale_buf[1]); |
||
18019 | bpr | 1352 | if(j==0) { |
1353 | gdImageSetPixel(image,ic[0],ic[1],pm->color[0]); j++; |
||
1354 | if (tikz_file) |
||
1355 | fprintf(tikz_file,"(%i,%i)rectangle(%i,%i)", |
||
1356 | ic[0],flip(ic[1]),ic[0]+1,flip(ic[1]+1)); |
||
1357 | } |
||
1358 | else { |
||
1359 | xx=ic[0]-oc[0]; yy=ic[1]-oc[1]; |
||
1360 | dist=sqrt(xx*xx+yy*yy); |
||
1361 | if(dist>0){ |
||
1362 | if(dist>plotjump || dist==1) { |
||
1363 | gdImageSetPixel(image,ic[0],ic[1],pm->color[0]); |
||
1364 | if (tikz_file) |
||
1365 | fprintf(tikz_file,"(%i,%i)rectangle(%i,%i)", |
||
1366 | ic[0],flip(ic[1]),ic[0]+1,flip(ic[1]+1)); |
||
1367 | } |
||
1368 | else { |
||
1369 | if (dash==1) |
||
18105 | georgesk | 1370 | myDashedLine(image,oc[0],oc[1],ic[0],ic[1],pm->color[0]); |
18019 | bpr | 1371 | else |
1372 | gdImageLine(image,oc[0],oc[1],ic[0],ic[1],pm->color[0]); |
||
1373 | if (tikz_file) |
||
1374 | fprintf(tikz_file, "(%i,%i)--(%i,%i)", |
||
17932 | bpr | 1375 | oc[0],flip(oc[1]),ic[0],flip(ic[1])); |
18019 | bpr | 1376 | } |
17621 | bpr | 1377 | } |
1378 | } |
||
18019 | bpr | 1379 | memmove(oc,ic,sizeof(oc)); |
12473 | bpr | 1380 | } |
17932 | bpr | 1381 | if (tikz_file) fprintf(tikz_file,";\n\%\%end plot\n"); |
12473 | bpr | 1382 | if(vimg_enable) vimg_plotend(); |
10 | reyssat | 1383 | } |
1384 | |||
6578 | bpr | 1385 | void obj_plot(objparm *pm) { _obj_plot( pm,0) ;} |
18352 | bpr | 1386 | void obj_dplot(objparm *pm) { _obj_plot( pm,1) ;} |
6578 | bpr | 1387 | |
7675 | bpr | 1388 | /* set levelcurve granularity */ |
10 | reyssat | 1389 | void obj_levelstep(objparm *pm) |
1390 | { |
||
12473 | bpr | 1391 | int dd; |
1392 | dd=pm->pd[0]; |
||
1393 | if(dd<1) return; |
||
1394 | if(dd>16) dd=16; |
||
1395 | lstep=dd; |
||
10 | reyssat | 1396 | } |
1397 | |||
7675 | bpr | 1398 | /* level curve */ |
10 | reyssat | 1399 | void obj_levelcurve(objparm *pm) |
1400 | { |
||
12473 | bpr | 1401 | char fn[MAX_LINELEN+1],tc[MAX_LINELEN+1]; |
1402 | int n,i; |
||
1403 | double d; |
||
1404 | leveldata *ld; |
||
7615 | bpr | 1405 | |
12473 | bpr | 1406 | ld=xmalloc(sizeof(leveldata)+16); |
1407 | ld->xname="x"; ld->yname="y"; |
||
1408 | ld->xsize=sizex; ld->ysize=sizey; ld->datacnt=0; |
||
1409 | ld->xrange[0]=xstart; ld->xrange[1]=sizex/xscale+xstart; |
||
1410 | ld->yrange[0]=sizey/yscale+ystart; ld->yrange[1]=ystart; |
||
1411 | ld->grain=lstep; |
||
1412 | fnd_item(pm->str,1,fn); ld->fn=fn; |
||
1413 | n=itemnum(pm->str); |
||
1414 | if(n<=1) {ld->levelcnt=1; ld->levels[0]=0;} |
||
1415 | else { |
||
1416 | if(n>LEVEL_LIM+1) n=LEVEL_LIM+1; |
||
1417 | for(i=0;i<n-1;i++) { |
||
1418 | fnd_item(pm->str,i+2,tc); |
||
1419 | d=strevalue(tc); |
||
1420 | if(isfinite(d)) ld->levels[i]=d; else ld->levels[i]=0; |
||
10 | reyssat | 1421 | } |
12473 | bpr | 1422 | ld->levelcnt=n-1; |
1423 | } |
||
1424 | levelcurve(ld); |
||
17932 | bpr | 1425 | if (tikz_file) |
1426 | fprintf(tikz_file,"\%\%begin levelcurve\n\\draw\[%s]" |
||
18065 | bpr | 1427 | ,tikz_options(pm->color[0],1)); |
12473 | bpr | 1428 | for(i=0;i<ld->datacnt;i++) { |
1429 | gdImageSetPixel(image,ld->xdata[i],ld->ydata[i],pm->color[0]); |
||
17584 | bpr | 1430 | if (tikz_file) |
1431 | fprintf(tikz_file, |
||
17933 | bpr | 1432 | "(%i,%i)rectangle(%i,%i)", |
1433 | ld->xdata[i],flip(ld->ydata[i]),ld->xdata[i]+1,flip(ld->ydata[i]+1)); |
||
12473 | bpr | 1434 | } |
17932 | bpr | 1435 | if (tikz_file) fprintf(tikz_file,";\n\%\%end levelcurve\n"); |
12473 | bpr | 1436 | free(ld); |
10 | reyssat | 1437 | } |
1438 | |||
7675 | bpr | 1439 | /* set animation step */ |
10 | reyssat | 1440 | void obj_animstep(objparm *pm) |
1441 | { |
||
12473 | bpr | 1442 | animstep=pm->pd[0]; |
1443 | setvar("animstep",pm->pd[0]); |
||
10 | reyssat | 1444 | } |
1445 | |||
7675 | bpr | 1446 | /* Starts a line counting */ |
10 | reyssat | 1447 | void obj_linecount(objparm *pm) |
1448 | { |
||
12473 | bpr | 1449 | linecnt=pm->pd[0]; |
10 | reyssat | 1450 | } |
1451 | |||
7675 | bpr | 1452 | /* marks end of execution */ |
10 | reyssat | 1453 | void obj_end(objparm *pm) |
1454 | { |
||
12473 | bpr | 1455 | fly_error("successful_end_of_execution"); |
10 | reyssat | 1456 | } |
1457 | |||
7675 | bpr | 1458 | /* output */ |
10 | reyssat | 1459 | void obj_output(objparm *pm) |
1460 | { |
||
12473 | bpr | 1461 | char *p, namebuf[1024]; |
1462 | p=find_word_start(pm->str); *find_word_end(p)=0; |
||
1463 | snprintf(namebuf,sizeof(namebuf),"%s",imagefilename); |
||
1464 | snprintf(imagefilename,sizeof(imagefilename),"%s",p); |
||
1465 | output(); |
||
1466 | snprintf(imagefilename,sizeof(imagefilename),"%s",namebuf); |
||
10 | reyssat | 1467 | } |
1468 | |||
7675 | bpr | 1469 | /* vimgfile */ |
1024 | bpr | 1470 | void obj_vimgfile(objparm *pm) |
1471 | { |
||
12473 | bpr | 1472 | char *p; |
1473 | p=find_word_start(pm->str); *find_word_end(p)=0; |
||
1474 | snprintf(vimgfilename,sizeof(vimgfilename),"%s",p); |
||
1475 | if(vimg_ready) vimg_close(); |
||
1024 | bpr | 1476 | } |
1477 | |||
7675 | bpr | 1478 | /* vimg enable/disable */ |
1024 | bpr | 1479 | void obj_vimg(objparm *pm) |
1480 | { |
||
12473 | bpr | 1481 | vimg_enable=pm->pd[0]; |
1482 | if(vimg_enable>0 && vimg_ready==0) vimg_init(); |
||
1024 | bpr | 1483 | } |
1484 | |||
7675 | bpr | 1485 | /* Set affine transformation */ |
10 | reyssat | 1486 | void obj_affine(objparm *pm) |
1487 | { |
||
12473 | bpr | 1488 | int i; |
1489 | for(i=0;i<4;i++) matrix[i]=pm->pd[i]; |
||
1490 | transx=pm->pd[4]; transy=pm->pd[5]; |
||
1491 | transform=1; |
||
10 | reyssat | 1492 | } |
1493 | |||
7675 | bpr | 1494 | /* Set affine transformation */ |
10 | reyssat | 1495 | void obj_rotation(objparm *pm) |
1496 | { |
||
12473 | bpr | 1497 | double r; |
1498 | r=M_PI*pm->pd[0]/180; |
||
1499 | matrix[0]=matrix[3]=cos(r); |
||
1500 | matrix[1]=-sin(r); matrix[2]=sin(r); |
||
1501 | transform=1; |
||
10 | reyssat | 1502 | } |
1503 | |||
8419 | bpr | 1504 | /* Set linear transformation */ |
10 | reyssat | 1505 | void obj_linear(objparm *pm) |
1506 | { |
||
12473 | bpr | 1507 | int i; |
1508 | for(i=0;i<4;i++) matrix[i]=pm->pd[i]; |
||
1509 | transform=1; |
||
10 | reyssat | 1510 | } |
1511 | |||
8419 | bpr | 1512 | /* Set translation transformation */ |
10 | reyssat | 1513 | void obj_translation(objparm *pm) |
1514 | { |
||
12473 | bpr | 1515 | transx=pm->pd[0]; transy=pm->pd[1]; |
10 | reyssat | 1516 | } |
1517 | |||
8419 | bpr | 1518 | /* kill affine transformation */ |
10 | reyssat | 1519 | void obj_killaffine(objparm *pm) |
1520 | { |
||
12473 | bpr | 1521 | matrix[0]=matrix[3]=1; |
1522 | matrix[1]=matrix[2]=transx=transy=0; |
||
1523 | transform=0; |
||
10 | reyssat | 1524 | } |
1525 | |||
8419 | bpr | 1526 | /* kill affine transformation */ |
10 | reyssat | 1527 | void obj_killlinear(objparm *pm) |
1528 | { |
||
12473 | bpr | 1529 | matrix[0]=matrix[3]=1; |
1530 | matrix[1]=matrix[2]=0; |
||
1531 | transform=0; |
||
10 | reyssat | 1532 | } |
1533 | |||
8419 | bpr | 1534 | /* kill affine transformation */ |
10 | reyssat | 1535 | void obj_killtranslation(objparm *pm) |
1536 | { |
||
12473 | bpr | 1537 | transx=transy=0; |
10 | reyssat | 1538 | } |
1539 | |||
1540 | /***** Les modifs de Jean-Christophe Leger Fev 2006 *****/ |
||
1541 | |||
7615 | bpr | 1542 | /* arguments: un numero de matrice entre 1 et JC_NB_MATRICES, une liste de 4 nombres reels pour la matrice */ |
10 | reyssat | 1543 | void obj_setmatrix(objparm *pm) |
1544 | { |
||
1545 | int nummatrix = (int) (pm->pd[0]); |
||
1546 | if((nummatrix < 1) ||(nummatrix>JC_NB_MATRICES)) { |
||
8195 | bpr | 1547 | fly_error("bad_matrix_number"); |
10 | reyssat | 1548 | return; |
1549 | } |
||
1550 | matrices_pavage[nummatrix][0] = pm->pd[1]; |
||
1551 | matrices_pavage[nummatrix][1] = pm->pd[2]; |
||
1552 | matrices_pavage[nummatrix][2] = pm->pd[3]; |
||
1553 | matrices_pavage[nummatrix][3] = pm->pd[4]; |
||
1554 | } |
||
1555 | |||
7615 | bpr | 1556 | /* arguments: un numero de matrice entre 1 et JC_NB_MATRICES */ |
10 | reyssat | 1557 | void obj_resetmatrix(objparm *pm) |
1558 | { |
||
1559 | int nummatrix = (int) (pm->pd[0]); |
||
1560 | if((nummatrix < 1) ||(nummatrix>JC_NB_MATRICES)) { |
||
8195 | bpr | 1561 | fly_error("bad_matrix_number"); |
10 | reyssat | 1562 | return; |
1563 | } |
||
1564 | matrices_pavage[nummatrix][0] = 1; |
||
1565 | matrices_pavage[nummatrix][1] = 0; |
||
1566 | matrices_pavage[nummatrix][2] = 0; |
||
1567 | matrices_pavage[nummatrix][3] = 1; |
||
1568 | |||
1569 | } |
||
7615 | bpr | 1570 | /* arguments: un numero de vecteur entre 1 et JC_NB_MATRICES, une liste de 2 nombres reels pour le vecteur */ |
10 | reyssat | 1571 | void obj_setvector(objparm *pm) |
1572 | { |
||
1573 | int nummatrix = (int) (pm->pd[0]); |
||
1574 | if((nummatrix < 1) ||(nummatrix>JC_NB_MATRICES)) { |
||
8195 | bpr | 1575 | fly_error("bad_vector_number"); |
10 | reyssat | 1576 | return; |
1577 | } |
||
1578 | vecteurs_pavage[nummatrix][0] = pm->pd[1]; |
||
1579 | vecteurs_pavage[nummatrix][1] = pm->pd[2]; |
||
1580 | } |
||
1581 | |||
7615 | bpr | 1582 | /* arguments: un numero de matrice entre 1 et JC_NB_MATRICES */ |
10 | reyssat | 1583 | void obj_resetvector(objparm *pm) |
1584 | { |
||
1585 | int nummatrix = (int) (pm->pd[0]); |
||
1586 | if((nummatrix < 1) ||(nummatrix>JC_NB_MATRICES)) { |
||
8195 | bpr | 1587 | fly_error("bad_vector_number"); |
10 | reyssat | 1588 | return; |
1589 | } |
||
1590 | vecteurs_pavage[nummatrix][0] = 0; |
||
1591 | vecteurs_pavage[nummatrix][1] = 0; |
||
1592 | } |
||
1593 | |||
7615 | bpr | 1594 | /* arguments: un numero de vecteur entre 1 et JC_NB_MATRICES, une liste de 6 nombres reels pour la matrice et le vecteur */ |
10 | reyssat | 1595 | void obj_settransform(objparm *pm) |
1596 | { |
||
1597 | int nummatrix = (int) (pm->pd[0]); |
||
1598 | if((nummatrix < 1) ||(nummatrix>JC_NB_MATRICES)) { |
||
8195 | bpr | 1599 | fly_error("bad_vector_number"); |
10 | reyssat | 1600 | return; |
1601 | } |
||
1602 | matrices_pavage[nummatrix][0] = pm->pd[1]; |
||
1603 | matrices_pavage[nummatrix][1] = pm->pd[2]; |
||
1604 | matrices_pavage[nummatrix][2] = pm->pd[3]; |
||
1605 | matrices_pavage[nummatrix][3] = pm->pd[4]; |
||
1606 | vecteurs_pavage[nummatrix][0] = pm->pd[5]; |
||
1607 | vecteurs_pavage[nummatrix][1] = pm->pd[6]; |
||
1608 | } |
||
1609 | |||
1610 | |||
7615 | bpr | 1611 | /* arguments: un numero de matrice entre 1 et JC_NB_MATRICES */ |
10 | reyssat | 1612 | void obj_resettransform(objparm *pm) |
1613 | { |
||
1614 | int nummatrix = (int) (pm->pd[0]); |
||
1615 | if((nummatrix < 1) ||(nummatrix>JC_NB_MATRICES)) { |
||
8195 | bpr | 1616 | fly_error("bad_vector_number"); |
10 | reyssat | 1617 | return; |
1618 | } |
||
1619 | vecteurs_pavage[nummatrix][0] = 0; |
||
1620 | vecteurs_pavage[nummatrix][1] = 0; |
||
1621 | matrices_pavage[nummatrix][0] = 1; |
||
1622 | matrices_pavage[nummatrix][1] = 0; |
||
1623 | matrices_pavage[nummatrix][2] = 0; |
||
1624 | matrices_pavage[nummatrix][3] = 1; |
||
1625 | } |
||
1626 | |||
7615 | bpr | 1627 | /* arguments: une liste de 6 nombres reels pour les coordonnees de l'origine et des vecteurs de base */ |
10 | reyssat | 1628 | void obj_setparallelogram(objparm *pm) |
1629 | { |
||
1630 | int i; |
||
1631 | for(i=0;i<6;i++) parallogram_fonda[i]=pm->pd[i]; |
||
1632 | } |
||
1633 | |||
1634 | /* arguments :aucun */ |
||
1635 | void obj_resetparallelogram(objparm *pm) |
||
1636 | { |
||
1637 | parallogram_fonda[0]=0; |
||
1638 | parallogram_fonda[1]=0; |
||
1639 | parallogram_fonda[2]=100; |
||
1640 | parallogram_fonda[3]=0; |
||
1641 | parallogram_fonda[4]=0; |
||
1642 | parallogram_fonda[5]=100; |
||
1643 | } |
||
1644 | |||
1645 | /* argument : la liste des numeros des matrices a faire agir, le nom du fichier de l'image a inclure */ |
||
1646 | void obj_multicopy(objparm *pm) |
||
1647 | { |
||
12473 | bpr | 1648 | char *pp,*pe,*cptr; |
1649 | FILE *inf; |
||
1650 | gdImagePtr insimg; |
||
1651 | int i,j; |
||
1652 | int imax,jmax; |
||
1653 | int c; /* la couleur reperee */ |
||
1654 | int mat; |
||
1655 | int nummatrices[JC_NB_MATRICES]; |
||
1656 | double pt[2]; /* les coordonnees math. du point repere dans le parallelogramme */ |
||
1657 | double ptr[2]; /* les coordonnees math. du point transforme */ |
||
1658 | int pti[2]; /* les coordonnees img du point a placer sur le canevas */ |
||
1659 | int t; |
||
1660 | /* gestion palette de couleur de l'image a inserer */ |
||
1661 | int colorMap[gdMaxColors]; |
||
1662 | int comptmat=0; /* combien de matrices en tout ? */ |
||
7615 | bpr | 1663 | |
12473 | bpr | 1664 | for (i=0; (i<gdMaxColors); i++) { |
1665 | colorMap[i] = (-1); |
||
1666 | } |
||
10 | reyssat | 1667 | |
12473 | bpr | 1668 | /* Gestion des parametres la liste est censee finir avec le nom du fichier */ |
1669 | t=pm->pcnt-1; /* il faut enlever le nom de fichier ! c'est le nombre de parametres en plus */ |
||
1670 | pp=find_word_start(pm->str); |
||
1671 | /* visiblement find_word_start n'arrive pas a trouver le dernier mot dans un contexte ou le nombre de parameters est variable |
||
10 | reyssat | 1672 | * on cherche donc l'emplacement de la derniere virgule: |
1673 | * il y en a une car t>0, on retrouve ensuite le debut de mot |
||
1674 | */ |
||
12473 | bpr | 1675 | for(pe=pp;*pe!=0;pe++);/* trouve la fin de la chaine */ |
1676 | if(t>0){ |
||
1677 | for(cptr = pe; cptr > pp && *cptr != ','; cptr--); |
||
1678 | pp=find_word_start(cptr+1); |
||
1679 | } |
||
1680 | pe=find_word_end(pp);*pe=0; /* strip junk final */ |
||
1681 | // printf("pp contient %s\n",pp); |
||
10 | reyssat | 1682 | |
1683 | |||
12473 | bpr | 1684 | inf=open4read(pp); |
1685 | if(inf==NULL) { |
||
1686 | fly_error("file_not_exist"); return; |
||
1687 | } |
||
1688 | insimg=gdImageCreateFromGif(inf); fclose(inf); |
||
1689 | if(insimg==NULL) { |
||
1690 | fly_error("bad_gif"); return; |
||
1691 | } |
||
10 | reyssat | 1692 | |
12473 | bpr | 1693 | /* On recupere les numeros des matrices/vecteurs a faire agir, |
1694 | * s'il n'y en a pas, on les fait toutes agir |
||
1695 | */ |
||
1696 | for(i=0;i<t && i< JC_NB_MATRICES;i++) { |
||
1697 | if(pm->pd[i]>=1 && pm->pd[i]<=JC_NB_MATRICES){ |
||
1698 | nummatrices[comptmat] = pm->pd[i]; |
||
1699 | comptmat++; |
||
10 | reyssat | 1700 | } |
12473 | bpr | 1701 | } |
1702 | if(t<=0){ |
||
1703 | for(i=0;i<JC_NB_MATRICES;i++) { |
||
1704 | nummatrices[i] = i+1; |
||
10 | reyssat | 1705 | } |
12473 | bpr | 1706 | comptmat=JC_NB_MATRICES; |
1707 | } |
||
10 | reyssat | 1708 | |
7615 | bpr | 1709 | |
12473 | bpr | 1710 | imax = gdImageSX(insimg); |
1711 | jmax = gdImageSY(insimg); |
||
10 | reyssat | 1712 | |
12473 | bpr | 1713 | for(i=0;i<imax;i++){ |
1714 | for(j=0;j<jmax;j++){ |
||
1715 | int nc; |
||
1716 | c=gdImageGetPixel(insimg,i,j); |
||
1717 | /* Le code suivant est une copie du code dans gdImageCopy Added 7/24/95: support transparent copies */ |
||
1718 | if (gdImageGetTransparent(insimg) != c) { |
||
1719 | /* Have we established a mapping for this color? */ |
||
1720 | if (colorMap[c] == (-1)) { |
||
1721 | /* If it's the same image, mapping is trivial, dans notre cas ca n'arrive jamais... */ |
||
1722 | if (image == insimg) { |
||
1723 | nc = c; |
||
1724 | } else { |
||
1725 | /* First look for an exact match */ |
||
1726 | nc = gdImageColorExact(image, |
||
1727 | insimg->red[c], insimg->green[c], |
||
1728 | insimg->blue[c]); |
||
1729 | } |
||
1730 | if (nc == (-1)) { |
||
1731 | /* No, so try to allocate it */ |
||
1732 | nc = gdImageColorAllocate(image, |
||
1733 | insimg->red[c], insimg->green[c], |
||
7675 | bpr | 1734 | insimg->blue[c]); |
12473 | bpr | 1735 | /* If we're out of colors, go for the closest color */ |
1736 | if (nc == (-1)) { |
||
1737 | nc = gdImageColorClosest(image, |
||
7675 | bpr | 1738 | insimg->red[c], insimg->green[c], |
1739 | insimg->blue[c]); |
||
12473 | bpr | 1740 | } |
1741 | } |
||
1742 | colorMap[c] = nc; |
||
1743 | } |
||
10 | reyssat | 1744 | |
12473 | bpr | 1745 | pt[0]= i*(parallogram_fonda[2])/(imax-1)+(jmax-j)*(parallogram_fonda[4])/(jmax-1)+parallogram_fonda[0]; |
1746 | pt[1]= i*(parallogram_fonda[3])/(imax-1)+(jmax-j)*(parallogram_fonda[5])/(jmax-1)+parallogram_fonda[1]; |
||
1747 | for(mat=0;mat<comptmat;mat++){ |
||
7675 | bpr | 1748 | double *matricecourante = matrices_pavage[nummatrices[mat]]; |
1749 | double *vecteurcourant = vecteurs_pavage[nummatrices[mat]]; |
||
1750 | ptr[0] = matricecourante[0]*pt[0]+matricecourante[1]*pt[1]+vecteurcourant[0]; |
||
1751 | ptr[1] = matricecourante[2]*pt[0]+matricecourante[3]*pt[1]+vecteurcourant[1]; |
||
1752 | scale(ptr,pti,1); |
||
1753 | gdImageSetPixel(image,pti[0],pti[1],colorMap[c]); |
||
12473 | bpr | 1754 | } |
10 | reyssat | 1755 | } |
1756 | } |
||
12473 | bpr | 1757 | } |
1758 | gdImageDestroy(insimg); |
||
10 | reyssat | 1759 | } |
1760 | |||
1761 | /**** Fin modifs JC Fev 06 ******/ |
||
1762 | |||
7675 | bpr | 1763 | /* get color from value */ |
10 | reyssat | 1764 | int calc_color(char *p, struct objtab *o) |
1765 | { |
||
12473 | bpr | 1766 | int k, cc[3]; |
1767 | char buf[MAX_LINELEN+1]; |
||
1768 | for(k=0;k<3;k++) { |
||
1769 | fnd_item(p,k+1,buf); |
||
1770 | cc[k]=strevalue(buf); |
||
1771 | } |
||
1772 | collapse_item(p,3); |
||
1773 | if(cc[0]==-1 && cc[1]==-1 && cc[2]==-255) { |
||
10 | reyssat | 1774 | |
12473 | bpr | 1775 | if(brushed && o->subst&1) return gdBrushed; |
1776 | else return color_black; |
||
1777 | } |
||
1778 | if(cc[0]==-1 && cc[1]==-255 && cc[2]==-1) { |
||
1779 | if(styled && o->subst&2) return gdStyled; |
||
1780 | else return color_black; |
||
1781 | } |
||
1782 | if(cc[0]==-255 && cc[1]==-1 && cc[2]==-1) { |
||
1783 | if(tiled && o->fill_tag==1) return gdTiled; |
||
1784 | else return color_black; |
||
1785 | } |
||
1786 | return getcolor(cc[0],cc[1],cc[2]); |
||
10 | reyssat | 1787 | } |
1788 | |||
7675 | bpr | 1789 | /* Routine to parse parameters */ |
10 | reyssat | 1790 | int parse_parms(char *p,objparm *pm,struct objtab *o) |
1791 | { |
||
12473 | bpr | 1792 | char buf[MAX_LINELEN+1]; |
1793 | char *p1, *p2; |
||
1794 | int j,t,c,c1,c2; |
||
7615 | bpr | 1795 | |
12473 | bpr | 1796 | c=o->color_pos;c1=c2=0; |
1797 | pm->color[0]=pm->color[1]=0; |
||
1798 | if(c>0) c1=c; |
||
1799 | if(c<0) c2=-c; |
||
1800 | c=c1+c2; |
||
1801 | t=itemnum(p);if(t<o->required_parms+3*c) return -1; |
||
1802 | if(c1>0 && t>o->required_parms+3*c) t=o->required_parms+3*c; |
||
1803 | pm->pcnt=t-3*c; |
||
1804 | if(pm->pcnt>MAX_PARMS) pm->pcnt=MAX_PARMS; |
||
1805 | if(c2>0) { |
||
1806 | for(j=0;j<2 && j<c2; j++) pm->color[j]=calc_color(p,o); |
||
1807 | } |
||
1808 | snprintf(buf,sizeof(buf),"%s",p); |
||
1809 | for(j=0, p1=buf; j<pm->pcnt; j++, p1=p2) { |
||
1810 | p2=find_item_end(p1); if(*p2) *p2++=0; |
||
1811 | p1=find_word_start(p1); |
||
1812 | if(*p1) pm->pd[j]=strevalue(p1); else pm->pd[j]=0; |
||
1813 | if(!isfinite(pm->pd[j])) { |
||
1814 | if(j<o->required_parms) return -1; |
||
1815 | else {pm->pd[j]=0;break;} |
||
10 | reyssat | 1816 | } |
12473 | bpr | 1817 | } |
1818 | collapse_item(p,o->required_parms); |
||
1819 | if(c1>0) { |
||
1820 | for(j=0;j<c1 && j<2; j++) pm->color[j]=calc_color(p,o); |
||
1821 | } |
||
1822 | if(width>1 && o->subst&1 && pm->color[0]!=gdBrushed |
||
1823 | && pm->color[0]!=gdStyled && pm->color[0]!=gdTiled) { |
||
1824 | pm->color[1]=pm->color[0]; |
||
1825 | pm->color[0]=widthcolor(width,pm->color[0]); |
||
1826 | } |
||
1827 | pm->fill=o->fill_tag; |
||
18131 | bpr | 1828 | if(o->required_parms!=0){ |
1829 | if(dashed) { |
||
1830 | if(pm->fill==1) pm->fill=2; |
||
1831 | if(pm->fill==0) pm->fill=-1; |
||
18159 | bpr | 1832 | if(noreset==0) dashed=0; |
18131 | bpr | 1833 | } |
1834 | if(filled) { |
||
1835 | if(pm->fill==-1) pm->fill=2; |
||
1836 | if(pm->fill==0) pm->fill=1; |
||
18159 | bpr | 1837 | if(noreset==0) filled=0; |
18131 | bpr | 1838 | } |
1839 | } |
||
12473 | bpr | 1840 | ovlstrcpy(pm->str,p); return 0; |
10 | reyssat | 1841 | } |
1842 | |||
8068 | bpr | 1843 | /* Create the struct objparm pm corresponding to the objparm p |
1844 | * Execute a command. Returns 0 if OK. |
||
1845 | */ |
||
10 | reyssat | 1846 | int obj_main(char *p) |
1847 | { |
||
12473 | bpr | 1848 | int i; |
1849 | char *pp,*name,*pt; |
||
1850 | char tbuf2[MAX_LINELEN+1]; |
||
1851 | struct objparm pm; |
||
10 | reyssat | 1852 | |
12473 | bpr | 1853 | p=find_word_start(p); |
1854 | if(*p==exec_prefix_char || *p==0) return 0; /* comment */ |
||
1855 | name=p; |
||
1856 | pp=find_name_end(p); |
||
1857 | pt=find_word_start(pp); if(*pt=='=') *pt=' '; |
||
1858 | if(*pt==':' && *(pt+1)=='=') *pt=*(pt+1)=' '; |
||
1859 | pp=find_word_end(p); |
||
1860 | if(*pp!=0) { |
||
1861 | *(pp++)=0; pp=find_word_start(pp); |
||
1862 | } |
||
1863 | if(strlen(p)==1 || (strlen(p)==2 && isdigit(*(p+1)))) { |
||
1864 | setvar(p,strevalue(pp)); return 0; |
||
1865 | } |
||
1866 | /* search the number of the object */ |
||
1867 | i=search_list(objtab,obj_no,sizeof(objtab[0]),name); |
||
1868 | if(i<0) { |
||
1869 | fly_error("bad_cmd"); return 1; |
||
1870 | } |
||
1871 | if(image==NULL && (objtab[i].color_pos || objtab[i].required_parms>2)) { |
||
1872 | fly_error("image_not_defined"); return 1; |
||
1873 | } |
||
1874 | ovlstrcpy(tbuf2,pp); |
||
1875 | if(objtab[i].color_pos || objtab[i].routine==obj_setstyle) { |
||
1876 | substit(tbuf2); |
||
1877 | } |
||
1878 | if(parse_parms(tbuf2,&pm,objtab+i)!=0) fly_error("bad_parms"); |
||
1879 | else objtab[i].routine(&pm); |
||
1880 | return 0; |
||
10 | reyssat | 1881 | } |
18352 | bpr | 1882 | |
1883 | /* for hyperbolic geodesics, return data for obj_hypgeods + a point on the arc |
||
1884 | to be used for filling hyperbolic triangle*/ |
||
1885 | int hypgeodaux(double *q, double* res) |
||
1886 | { |
||
1887 | double r,cx,cy,a1,a2,a3,tmp, |
||
1888 | nx = -q[0]*q[2]*q[2]+(q[0]*q[0]+q[1]*q[1]+1)*q[2]-q[0]*q[3]*q[3]-q[0], |
||
1889 | ny = -q[1]*q[2]*q[2]-q[1]*q[3]*q[3]+(q[0]*q[0]+q[1]*q[1]+1)*q[3]-q[1], |
||
1890 | dy = -2*q[1]*q[2]+2*q[0]*q[3]; |
||
18447 | bpr | 1891 | if (dy*dy*1e4 <= nx*nx+ny*ny){ |
18352 | bpr | 1892 | res[5]=(q[0]+q[2])/2; |
1893 | res[6]=(q[1]+q[3])/2; |
||
1894 | return 0;} |
||
1895 | cx = ny/dy; cy=-nx/dy; |
||
1896 | a1 = atan2(q[1]-cy, q[0]-cx); |
||
1897 | a2 = atan2(q[3]-cy, q[2]-cx); |
||
1898 | if (fabs(a2-a1)>M_PI){if(a1<a2) a1+=2*M_PI; else a2+=2*M_PI;}; |
||
1899 | a3 = (a1+a2)/2; |
||
1900 | if(a1>a2) {tmp=a1; a1=a2; a2=tmp;} |
||
1901 | r = sqrt(cx*cx+cy*cy-1); |
||
1902 | res[0]=cx; |
||
1903 | res[1]=cy; |
||
1904 | res[2]=r; |
||
1905 | res[3]=a1; |
||
1906 | res[4]=a2; |
||
1907 | res[5]=cx+r*cos(a3); |
||
1908 | res[6]=cy+r*sin(a3); |
||
1909 | return 1; |
||
1910 | } |
||
1911 | /* hyperbolic geodesics from x1,y1 to x2,y2, x3,y3 to x4,y4 in Poincaré disk */ |
||
1912 | void obj_hypgeods(objparm *pm) |
||
1913 | { |
||
1914 | int i, *qq=pm->p; |
||
1915 | double rx,ry,res[7]; |
||
1916 | if (tikz_file) fprintf(tikz_file, "\\draw[%s]",tikz_options(pm->color[0],pm->fill)); |
||
1917 | for (i = 0; i < pm->pcnt; i+=4) |
||
1918 | if (hypgeodaux(pm->pd+i,res)){ |
||
1919 | scale2(res[2],res[2],&rx,&ry); |
||
1920 | scale(res,qq,1); |
||
1921 | myGdImageArc(image,qq[0],qq[1],rx,ry,res[3]/DEG,res[4]/DEG,pm->color[0]); |
||
18353 | bpr | 1922 | if(tikz_file) |
1923 | fprintf(tikz_file,"(%i,%i)arc(%f:%f:%i and %i)", |
||
1924 | (int)rint(qq[0]+rx*cos(res[3])), |
||
1925 | flip((int)rint(qq[1]+ry*sin(res[3]))), |
||
1926 | res[3]/DEG,res[4]/DEG,(int)rint(rx),-(int)rint(ry)); |
||
1927 | } |
||
18352 | bpr | 1928 | else { |
1929 | scale(pm->pd+i,qq,2); |
||
1930 | gdImageLine(image,qq[0],qq[1],qq[2],qq[3],pm->color[0]); |
||
1931 | if(tikz_file) fprintf(tikz_file,"(%i,%i)--(%i,%i)", |
||
1932 | qq[0],flip(qq[1]),qq[2],flip(qq[3])); |
||
1933 | } |
||
1934 | if(tikz_file) fprintf(tikz_file,";\n"); |
||
1935 | } |
||
1936 | |||
1937 | /* hyperbolic triangle, can be filled */ |
||
1938 | void obj_hyptriangle(objparm *pm) |
||
1939 | { |
||
1940 | double rx,ry,data[8],res[7]; |
||
18518 | bpr | 1941 | int i,*qq=pm->p; |
1942 | int cnt=3; |
||
1943 | scale(pm->pd,pm->p,cnt); |
||
1944 | for(i=0; i<pm->pcnt+2; i++) data[i]=pm->pd[i%pm->pcnt]; |
||
18358 | bpr | 1945 | if (tikz_file) fprintf(tikz_file, "\\draw[%s]",tikz_options(pm->color[0],0)); |
18518 | bpr | 1946 | for(i=0; i<cnt; i++){ |
18352 | bpr | 1947 | if(hypgeodaux(data+2*i,res)){ |
1948 | scale2(res[2],res[2],&rx,&ry); |
||
1949 | scale(res,qq,1); |
||
1950 | myGdImageArc(image,qq[0],qq[1],rx,ry,res[3]/DEG,res[4]/DEG,pm->color[0]); |
||
1951 | if(tikz_file) |
||
1952 | fprintf(tikz_file, "(%i,%i) arc (%f:%f:%i and %i)", |
||
1953 | (int)rint(qq[0]+rx*cos(res[3])), |
||
1954 | flip((int)rint(qq[1]+ry*sin(res[3]))), |
||
1955 | res[3]/DEG,res[4]/DEG,(int)rint(rx),-(int)rint(ry)); |
||
1956 | } |
||
1957 | else { |
||
1958 | scale(data+2*i,qq,2); |
||
1959 | gdImageLine(image,qq[0],qq[1],qq[2],qq[3],pm->color[0]); |
||
1960 | if(tikz_file) fprintf(tikz_file,"(%i,%i)--(%i,%i)", |
||
1961 | qq[0],flip(qq[1]),qq[2],flip(qq[3])); |
||
1962 | } |
||
18518 | bpr | 1963 | } |
18352 | bpr | 1964 | if(tikz_file) fprintf(tikz_file,";\n"); |
1965 | if(pm->fill){ |
||
1966 | data[0]=res[5]; |
||
1967 | data[1]=res[6]; |
||
1968 | hypgeodaux(data,res); |
||
1969 | scale(res+5,qq,1); |
||
1970 | //patchgdImageFill(image,qq[0],qq[1],pm->color[0]); |
||
1971 | patchgdImageFillToBorder(image,qq[0],qq[1],pm->color[0],pm->color[0]); |
||
1972 | if(tikz_file) tikz_fill(qq[0],qq[1],1,1,0,pm->color[0],grid); |
||
1973 | } |
||
1974 | } |
||
1975 | |||
18516 | bpr | 1976 | /* hyperbolic polygon */ |
18432 | bpr | 1977 | void obj_hyppoly(objparm *pm) |
1978 | { |
||
1979 | double rx,ry,data[1000],res[7]; |
||
1980 | int i,*qq=pm->p; |
||
1981 | int cnt=(pm->pcnt)/2; |
||
1982 | scale(pm->pd,pm->p,cnt); |
||
1983 | for(i=0; i<pm->pcnt+2; i++) data[i]=pm->pd[i%pm->pcnt]; |
||
1984 | if (tikz_file) fprintf(tikz_file, "\\draw[%s]",tikz_options(pm->color[0],0)); |
||
1985 | for(i=0; i<cnt; i++){ |
||
1986 | if(hypgeodaux(data+2*i,res)){ |
||
1987 | scale2(res[2],res[2],&rx,&ry); |
||
1988 | scale(res,qq,1); |
||
1989 | myGdImageArc(image,qq[0],qq[1],rx,ry,res[3]/DEG,res[4]/DEG,pm->color[0]); |
||
1990 | if(tikz_file) |
||
1991 | fprintf(tikz_file, "(%i,%i) arc (%f:%f:%i and %i)", |
||
1992 | (int)rint(qq[0]+rx*cos(res[3])), |
||
1993 | flip((int)rint(qq[1]+ry*sin(res[3]))), |
||
1994 | res[3]/DEG,res[4]/DEG,(int)rint(rx),-(int)rint(ry)); |
||
1995 | } |
||
1996 | else { |
||
1997 | scale(data+2*i,qq,2); |
||
1998 | gdImageLine(image,qq[0],qq[1],qq[2],qq[3],pm->color[0]); |
||
1999 | if(tikz_file) fprintf(tikz_file,"(%i,%i)--(%i,%i)", |
||
2000 | qq[0],flip(qq[1]),qq[2],flip(qq[3])); |
||
2001 | } |
||
2002 | } |
||
2003 | if(tikz_file) fprintf(tikz_file,";\n"); |
||
2004 | if(pm->fill){ |
||
2005 | data[0]=res[5]; |
||
2006 | data[1]=res[6]; |
||
2007 | hypgeodaux(data,res); |
||
2008 | scale(res+5,qq,1); |
||
2009 | //patchgdImageFill(image,qq[0],qq[1],pm->color[0]); |
||
2010 | patchgdImageFillToBorder(image,qq[0],qq[1],pm->color[0],pm->color[0]); |
||
2011 | if(tikz_file) tikz_fill(qq[0],qq[1],1,1,0,pm->color[0],grid); |
||
2012 | } |
||
2013 | } |
||
18516 | bpr | 2014 | |
18352 | bpr | 2015 | /* complete hyperbolic geodesic through the two first points, then the following two points, etc */ |
2016 | void obj_hyplines(objparm *pm) |
||
2017 | { |
||
2018 | double rx,ry,res[7],*pd = pm->pd; |
||
2019 | int i; |
||
2020 | if (tikz_file) fprintf(tikz_file, "\\draw[%s]",tikz_options(pm->color[0],0)); |
||
2021 | for (i=0; i < pm->pcnt; i+=4,pd+=4) |
||
2022 | if (hypgeodaux(pd,res)) { |
||
2023 | double alpha=atan(1/res[2]), beta = atan2(res[1],res[0]); |
||
2024 | scale(res,pm->p,1); |
||
2025 | scale2(res[2],res[2],&rx,&ry); |
||
2026 | myGdImageArc(image,pm->p[0],pm->p[1],rx,ry,180+(beta-alpha)/DEG,180+(beta+alpha)/DEG,pm->color[0]); |
||
2027 | if (tikz_file) fprintf(tikz_file, "(%i,%i) arc (%f:%f:%i and %i);\n", |
||
2028 | (int)rint(pm->p[0]-rx*cos(beta-alpha)), flip((int)rint(pm->p[1]-ry*sin(beta-alpha))), |
||
18356 | bpr | 2029 | 180+(beta-alpha)/DEG,180+(beta+alpha)/DEG, (int)rint(rx),-(int)rint(ry)); |
18455 | bpr | 2030 | } |
18352 | bpr | 2031 | else { |
2032 | double gamma; |
||
2033 | if (pd[1]*pd[1]+pd[0]*pd[0] > pd[2]*pd[2]+pd[3]*pd[3]) |
||
2034 | gamma = atan2(pd[1],pd[0]); |
||
2035 | else |
||
2036 | gamma = atan2(pd[3],pd[2]); |
||
18521 | bpr | 2037 | res[0]=cos(gamma); |
2038 | res[1]=sin(gamma); |
||
2039 | res[2]=-cos(gamma); |
||
2040 | res[3]=-sin(gamma); |
||
2041 | scale(res,pm->p,2); |
||
2042 | gdImageLine(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],pm->color[0]); |
||
2043 | if(tikz_file) fprintf(tikz_file, "(%i,%i)--(%i,%i)", |
||
18352 | bpr | 2044 | pm->p[0],flip(pm->p[1]),pm->p[2],flip(pm->p[3])); |
2045 | } |
||
18521 | bpr | 2046 | if (tikz_file) fprintf(tikz_file, ";\n"); |
18352 | bpr | 2047 | } |
18521 | bpr | 2048 | /* R=tanh(rhyp/2), z=\frac{1-R^2}{1-R^2|Z|^2} Z, r=\frac{1-|Z|^2}{1-R^2|Z|^2} R */ |
2049 | void obj_hypcircles(objparm *pm) |
||
2050 | { |
||
2051 | int i, intbuf[2]; |
||
2052 | double R,Z2,R2,den,r,XY,dbuf[2],*pd=pm->pd; |
||
2053 | if (tikz_file) fprintf(tikz_file,"\\draw\[%s]",tikz_options(pm->color[0],pm->fill)); |
||
2054 | for(i=0;i<pm->pcnt;i+=3){ |
||
2055 | Z2=pd[i]*pd[i]+pd[i+1]*pd[i+1]; |
||
2056 | R=tanh(pd[i+2]/2); R2=R*R; |
||
2057 | den=1-R2*Z2; XY=(1-R2)/den; |
||
2058 | dbuf[0]=XY*pd[i]; dbuf[1]=XY*pd[i+1]; |
||
2059 | scale(dbuf,intbuf,1); |
||
2060 | r=(1-Z2)/den*R; |
||
18523 | bpr | 2061 | if(pm->fill==1 || pm->fill==2) { |
2062 | gdImageArc(image,intbuf[0],intbuf[1], |
||
2063 | rint(2*r*xscale),rint(2*r*xscale),0,360,color_bounder); |
||
2064 | patchgdImageFillToBorder(image,intbuf[0],intbuf[1], |
||
2065 | color_bounder,pm->color[0]); |
||
2066 | } |
||
2067 | gdImageArc(image,intbuf[0],intbuf[1],rint(2*r*xscale),rint(2*r*xscale),0,360, |
||
2068 | pm->color[0]); |
||
18521 | bpr | 2069 | if (tikz_file){ |
2070 | fprintf(tikz_file, "(%i, %i) circle (%i and %i)", |
||
2071 | intbuf[0],flip(intbuf[1]),(int) rint(r*xscale),(int) rint(r*xscale)); |
||
2072 | } |
||
2073 | } |
||
2074 | if (tikz_file) fprintf(tikz_file, ";\n"); |
||
2075 | } |
||
18527 | bpr | 2076 | |
2077 | /* hyperbolic rays from x1,y1 to x2,y2, x1,y1 to x3,y3 in Poincaré disk */ |
||
2078 | void obj_hyprays(objparm *pm) |
||
2079 | { |
||
2080 | double rx,ry,data[4],res[7]; |
||
2081 | int i,*qq=pm->p; |
||
2082 | int cnt=(pm->pcnt)/2; |
||
2083 | scale(pm->pd,pm->p,cnt); |
||
2084 | if (tikz_file) |
||
2085 | fprintf(tikz_file, "\\draw\[%s]",tikz_options(pm->color[0],pm->fill)); |
||
2086 | for(i=2;i<pm->pcnt;i+=2) { |
||
2087 | data[0]=pm->pd[0];data[1]=pm->pd[1];data[2]=pm->pd[i];data[3]=pm->pd[i+1]; |
||
2088 | if (hypgeodaux(data,res)) { |
||
2089 | scale2(res[2],res[2],&rx,&ry); |
||
2090 | scale(res,qq,1); |
||
2091 | myGdImageArc(image,qq[0],qq[1],rx,ry,res[3]/DEG,res[4]/DEG,pm->color[0]); |
||
2092 | if(tikz_file) |
||
2093 | fprintf(tikz_file,"(%i,%i)arc(%f:%f:%i and %i)", |
||
2094 | (int)rint(qq[0]+rx*cos(res[3])), |
||
2095 | flip((int)rint(qq[1]+ry*sin(res[3]))), |
||
2096 | res[3]/DEG,res[4]/DEG,(int)rint(rx),-(int)rint(ry)); |
||
2097 | } |
||
2098 | else { |
||
2099 | scale(data,qq,2); |
||
2100 | gdImageLine(image,qq[0],qq[1],qq[2],qq[3],pm->color[0]); |
||
2101 | if (tikz_file) |
||
2102 | fprintf(tikz_file, "(%i,%i) -- (%i,%i)", |
||
2103 | pm->p[0],flip(pm->p[1]),pm->p[i],flip(pm->p[i+1])); |
||
2104 | } |
||
2105 | } |
||
2106 | if (tikz_file) fprintf(tikz_file,";\n"); |
||
2107 | } |