Rev 10 | Rev 7847 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 10 | Rev 7840 | ||
---|---|---|---|
Line 39... | Line 39... | ||
39 | 39 | ||
40 | static int _getlevel(leveldata *ld, int x, int y) |
40 | static int _getlevel(leveldata *ld, int x, int y) |
41 | { |
41 | { |
42 | double dd; |
42 | double dd; |
43 | int i; |
43 | int i; |
44 | 44 | ||
45 | eval_setval(ld->xevpos,lc_scalex(ld,x)); |
45 | eval_setval(ld->xevpos,lc_scalex(ld,x)); |
46 | eval_setval(ld->yevpos,lc_scaley(ld,y)); |
46 | eval_setval(ld->yevpos,lc_scaley(ld,y)); |
47 | set_evalue_error(0); set_evalue_pointer(ld->fn); dd=_evalue(10); |
47 | set_evalue_error(0); set_evalue_pointer(ld->fn); dd=_evalue(10); |
48 | for(i=0;i<ld->levelcnt && dd>ld->levels[i];i++); |
48 | for(i=0;i<ld->levelcnt && dd>ld->levels[i];i++); |
49 | return i; |
49 | return i; |
50 | } |
50 | } |
51 | 51 | ||
52 | static void lc_replacexy(leveldata *ld) |
52 | static void lc_replacexy(leveldata *ld) |
53 | { |
53 | { |
54 | char *pp; |
54 | char *pp; |
55 | for(pp=varchr(ld->fn,ld->xname);pp!=NULL;pp=varchr(pp,ld->xname)) { |
55 | for(pp=varchr(ld->fn,ld->xname);pp!=NULL;pp=varchr(pp,ld->xname)) { |
56 |
|
56 | string_modify(ld->fn,pp,pp+strlen(ld->xname),EV_X); |
57 |
|
57 | pp+=strlen(EV_X); |
58 | } |
58 | } |
59 | for(pp=varchr(ld->fn,ld->yname);pp!=NULL;pp=varchr(pp,ld->yname)) { |
59 | for(pp=varchr(ld->fn,ld->yname);pp!=NULL;pp=varchr(pp,ld->yname)) { |
60 |
|
60 | string_modify(ld->fn,pp,pp+strlen(ld->yname),EV_Y); |
61 |
|
61 | pp+=strlen(EV_Y); |
62 | } |
62 | } |
63 | } |
63 | } |
64 | 64 | ||
65 |
|
65 | /* produces level curve data. Returns non-zero if error. */ |
66 | int levelcurve(leveldata *ld) |
66 | int levelcurve(leveldata *ld) |
67 | { |
67 | { |
68 | int xx,yy,xi,yi,xsteps,ysteps; |
68 | int xx,yy,xi,yi,xsteps,ysteps; |
69 | int i,x,y,xt,yt; |
69 | int i,x,y,xt,yt; |
70 | short int l1[LEVELSIZE_LIM+16], l2[LEVELSIZE_LIM+16]; |
70 | short int l1[LEVELSIZE_LIM+16], l2[LEVELSIZE_LIM+16]; |
71 | short int l3[LEVELGRAIN_LIM+2][LEVELGRAIN_LIM+2]; |
71 | short int l3[LEVELGRAIN_LIM+2][LEVELGRAIN_LIM+2]; |
72 | char f[MAX_LINELEN+1]; |
72 | char f[MAX_LINELEN+1]; |
73 | 73 | ||
74 | ld->datacnt=0; |
74 | ld->datacnt=0; |
75 | if(ld->fn==NULL || *(ld->fn)==0 || ld->levelcnt<1) return 1; |
75 | if(ld->fn==NULL || *(ld->fn)==0 || ld->levelcnt<1) return 1; |
76 | if(ld->grain<1) ld->grain=4; |
76 | if(ld->grain<1) ld->grain=4; |
77 | if(ld->grain>LEVELGRAIN_LIM) ld->grain=LEVELGRAIN_LIM; |
77 | if(ld->grain>LEVELGRAIN_LIM) ld->grain=LEVELGRAIN_LIM; |
78 | if(ld->levelcnt>LEVEL_LIM) ld->levelcnt=LEVEL_LIM; |
78 | if(ld->levelcnt>LEVEL_LIM) ld->levelcnt=LEVEL_LIM; |
Line 91... | Line 91... | ||
91 | xsteps=(ld->xsize+ld->grain-1)/ld->grain+1; |
91 | xsteps=(ld->xsize+ld->grain-1)/ld->grain+1; |
92 | ysteps=(ld->ysize+ld->grain-1)/ld->grain+1; |
92 | ysteps=(ld->ysize+ld->grain-1)/ld->grain+1; |
93 | for(yy=yi=0;yi<ysteps;yy+=ld->grain,yi++) l2[yi]=_getlevel(ld,0,yy); |
93 | for(yy=yi=0;yi<ysteps;yy+=ld->grain,yi++) l2[yi]=_getlevel(ld,0,yy); |
94 | l2[ysteps]=l2[ysteps-1]; |
94 | l2[ysteps]=l2[ysteps-1]; |
95 | for(xi=1,xx=ld->grain;xi<xsteps && ld->datacnt<LEVELPOINT_LIM;xx+=ld->grain,xi++) { |
95 | for(xi=1,xx=ld->grain;xi<xsteps && ld->datacnt<LEVELPOINT_LIM;xx+=ld->grain,xi++) { |
96 |
|
96 | memmove(l1,l2,(ysteps+1)*sizeof(short int)); |
97 |
|
97 | for(yi=yy=0;yi<ysteps;yy+=ld->grain,yi++) l2[yi]=_getlevel(ld,xx,yy); |
98 |
|
98 | l2[ysteps]=l2[ysteps-1]; |
99 |
|
99 | for(yi=0;yi<ysteps && ld->datacnt<LEVELPOINT_LIM;yi++) |
100 |
|
100 | if(l1[yi]!=l1[yi+1] || l1[yi]!=l2[yi] || l1[yi]!=l2[yi+1]) { |
101 |
|
101 | for(x=0,xt=(xi-1)*ld->grain;x<=ld->grain;x++,xt++) |
102 |
|
102 | for(y=0,yt=yi*ld->grain;y<=ld->grain;y++,yt++) { |
103 |
|
103 | if(x==0 && y==0) {l3[x][y]=l1[yi]; continue;} |
104 |
|
104 | if(x==0 && y==ld->grain) {l3[x][y]=l1[yi+1]; continue;} |
105 |
|
105 | if(x==ld->grain && y==0) {l3[x][y]=l2[yi]; continue;} |
106 |
|
106 | if(x==ld->grain && y==ld->grain) {l3[x][y]=l2[yi+1]; continue;} |
107 |
|
107 | l3[x][y]=_getlevel(ld,xt,yt); |
108 |
|
108 | } |
109 |
|
109 | for(x=0,xt=(xi-1)*ld->grain;x<ld->grain;x++,xt++) |
110 |
|
110 | for(y=0,yt=yi*ld->grain;y<ld->grain;y++,yt++) { |
111 |
|
111 | i=l3[x][y]; |
112 |
|
112 | if((i!=l3[x][y+1] || i!=l3[x+1][y]) && |
113 |
|
113 | ld->datacnt<LEVELPOINT_LIM && |
114 |
|
114 | (i!=l3[x][y+1] || ld->datacnt==0 || |
115 |
|
115 | l3[x+1][y+1]==l3[x+1][y] || |
116 |
|
116 | ld->xdata[ld->datacnt-1]!=xt || |
117 |
|
117 | ld->ydata[ld->datacnt-1]!=yt-1)) { |
118 |
|
118 | ld->xdata[ld->datacnt]=xt; |
119 |
|
119 | ld->ydata[ld->datacnt++]=yt; |
120 |
|
120 | } |
121 |
|
121 | } |
122 |
|
122 | } |
123 | } |
123 | } |
124 | return 0; |
124 | return 0; |
125 | } |
125 | } |
126 | 126 |