[BACK]Return to calc.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / plot

Annotation of OpenXM_contrib2/asir2000/plot/calc.c, Revision 1.9

1.2       noro        1: /*
                      2:  * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
                      3:  * All rights reserved.
                      4:  *
                      5:  * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
                      6:  * non-exclusive and royalty-free license to use, copy, modify and
                      7:  * redistribute, solely for non-commercial and non-profit purposes, the
                      8:  * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
                      9:  * conditions of this Agreement. For the avoidance of doubt, you acquire
                     10:  * only a limited right to use the SOFTWARE hereunder, and FLL or any
                     11:  * third party developer retains all rights, including but not limited to
                     12:  * copyrights, in and to the SOFTWARE.
                     13:  *
                     14:  * (1) FLL does not grant you a license in any way for commercial
                     15:  * purposes. You may use the SOFTWARE only for non-commercial and
                     16:  * non-profit purposes only, such as academic, research and internal
                     17:  * business use.
                     18:  * (2) The SOFTWARE is protected by the Copyright Law of Japan and
                     19:  * international copyright treaties. If you make copies of the SOFTWARE,
                     20:  * with or without modification, as permitted hereunder, you shall affix
                     21:  * to all such copies of the SOFTWARE the above copyright notice.
                     22:  * (3) An explicit reference to this SOFTWARE and its copyright owner
                     23:  * shall be made on your publication or presentation in any form of the
                     24:  * results obtained by use of the SOFTWARE.
                     25:  * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
1.3       noro       26:  * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.2       noro       27:  * for such modification or the source code of the modified part of the
                     28:  * SOFTWARE.
                     29:  *
                     30:  * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
                     31:  * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
                     32:  * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
                     33:  * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
                     34:  * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
                     35:  * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
                     36:  * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
                     37:  * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
                     38:  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
                     39:  * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
                     40:  * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
                     41:  * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
                     42:  * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
                     43:  * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
                     44:  * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
                     45:  * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
                     46:  * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
                     47:  *
1.9     ! saito      48:  * $OpenXM: OpenXM_contrib2/asir2000/plot/calc.c,v 1.8 2011/08/10 04:51:58 saito Exp $
1.2       noro       49: */
1.1       noro       50: #include "ca.h"
1.5       noro       51: #include "parse.h"
1.1       noro       52: #include "ifplot.h"
                     53: #include <math.h>
1.7       ohara      54: #if defined(PARI)
1.1       noro       55: #include "genpari.h"
                     56: #endif
                     57:
1.6       noro       58: #ifndef MAXSHORT
                     59: #define MAXSHORT ((short)0x7fff)
                     60: #endif
                     61:
1.9     ! saito      62: void calc(double **tab,struct canvas *can,int nox){
        !            63:        //memory_plot,MODE_IFPLOTD,MODE_INEQND,MODE_INEQNANDD,MODE_INEQNORD
        !            64:        //MODE_INEQNXORD,conplotmainD
        !            65:        double x,y,xstep,ystep;
1.1       noro       66:        int ix,iy;
                     67:        Real r,rx,ry;
1.9     ! saito      68:        Obj fr,g,t,s;
1.1       noro       69:
1.9     ! saito      70:        if(!nox)initmarker(can,"Evaluating...");
1.1       noro       71:        MKReal(1.0,r); mulr(CO,(Obj)can->formula,(Obj)r,&fr);
1.9     ! saito      72:        xstep=(can->xmax-can->xmin)/can->width;
        !            73:        ystep=(can->ymax-can->ymin)/can->height;
        !            74:        MKReal(1.0,rx); MKReal(1.0,ry); // dummy real
        !            75:        BDY(rx)=can->xmin;
        !            76:        substr(CO,0,fr,can->vx,can->xmin?(Obj)rx:0,&t); devalr(CO,t,&g);
        !            77:        BDY(ry)=can->ymin;
        !            78:        substr(CO,0,g,can->vy,can->ymin?(Obj)ry:0,&t); devalr(CO,t,&s);
        !            79:        can->vmax=can->vmin=ToReal(s);
        !            80:        for(ix=0,x=can->xmin; ix<can->width; ix++,x+=xstep){
        !            81:                BDY(rx)=x; substr(CO,0,fr,can->vx,x?(Obj)rx:0,&t);
1.5       noro       82:                devalr(CO,t,&g);
1.9     ! saito      83:                if(!nox)marker(can,DIR_X,ix);
        !            84:                for(iy=0,y=can->ymin; iy<can->height; iy++,y+=ystep){
        !            85:                        BDY(ry)=y;
        !            86:                        substr(CO,0,g,can->vy,y?(Obj)ry:0,&t);
        !            87:                        devalr(CO,t,&s);
        !            88:                        tab[ix][iy]=ToReal(s);
        !            89:                        if(can->vmax<tab[ix][iy])can->vmax=tab[ix][iy];
        !            90:                        if(can->vmin>tab[ix][iy])can->vmin=tab[ix][iy];
        !            91:                }
        !            92:        }
        !            93: }
        !            94:
        !            95: void calcq(double **tab,struct canvas *can,int nox){
        !            96:        //MODE_IFPLOTQ,MODE_INEQNQ,MODE_INEQNANDQ,MODE_INEQNORQ,MODE_INEQNXORQ
        !            97:        //plotoverD
        !            98:        Q dx,dy,xstep,ystep,q1,w,h,c;
        !            99:        P g,g1,f1,f2,x,y;
        !           100:        int ix,iy;
        !           101:        Obj fr,gm,t,s;
        !           102:        Real r,rx,ry;
        !           103:
        !           104:        MKReal(1.0,r); mulr(CO,(Obj)can->formula,(Obj)r,&fr);
        !           105:        MKReal(1.0,rx); MKReal(1.0,ry); // dummy real
        !           106:        BDY(rx)=can->xmin;
        !           107:        substr(CO,0,fr,can->vx,can->xmin?(Obj)rx:0,&t); devalr(CO,t,&gm);
        !           108:        BDY(ry)=can->ymin;
        !           109:        substr(CO,0,gm,can->vy,can->ymin?(Obj)ry:0,&t); devalr(CO,t,&s);
        !           110:        can->vmax=can->vmin=ToReal(s);
        !           111:
        !           112:        subq(can->qxmax,can->qxmin,&dx); STOQ(can->width,w); divq(dx,w,&xstep);
        !           113:        subq(can->qymax,can->qymin,&dy); STOQ(can->height,h); divq(dy,h,&ystep);
        !           114:        MKV(can->vx,x); mulp(CO,(P)xstep,x,(P *)&t);
        !           115:        addp(CO,(P)can->qxmin,(P)t,(P *)&s); substp(CO,can->formula,can->vx,(P)s,&f1);
        !           116:        MKV(can->vy,y); mulp(CO,(P)ystep,y,(P *)&t);
        !           117:        addp(CO,(P)can->qymin,(P)t,(P *)&s); substp(CO,f1,can->vy,(P)s,&f2);
        !           118:        ptozp(f2,1,&c,&g);
        !           119:        if(!nox) initmarker(can,"Evaluating...");
        !           120:        for(iy=0;iy<can->height;iy++){
        !           121:                marker(can,DIR_Y,iy);
        !           122:                STOQ(iy,q1); substp(CO,g,can->vy,(P)q1,(P *)&t); ptozp((P)t,1,&c,&g1);
        !           123:                for(ix=0;ix<can->width;ix++){
        !           124:                        STOQ(ix,q1);substp(CO,g1,can->vx,(P)q1,(P *)&t);
1.5       noro      125:                        devalr(CO,t,&s);
1.9     ! saito     126:                        tab[ix][iy]=ToReal(s);
        !           127:                        if(can->vmax<tab[ix][iy])can->vmax=tab[ix][iy];
        !           128:                        if(can->vmin>tab[ix][iy])can->vmin=tab[ix][iy];
        !           129:                }
        !           130:        }
        !           131: }
        !           132:
        !           133: void calcb(double **tab,struct canvas *can,int nox){
        !           134:        //MODE_IFPLOTB,MODE_INEQNB,MODE_INEQNANDB,MODE_INEQNORB,MODE_INEQNXORB
        !           135:        Q dx,dy,xstep,ystep,q1,w,h,c;
        !           136:        P g,g1,f1,f2,x,y,t,s;
        !           137:        int ix,iy,*a,*pa;
        !           138:        VECT ss;
        !           139:        Obj fr,gm,tm,sm;
        !           140:        Real r,rx,ry;
        !           141:
        !           142:        MKReal(1.0,r); mulr(CO,(Obj)can->formula,(Obj)r,&fr);
        !           143:        MKReal(1.0,rx); MKReal(1.0,ry); // dummy real
        !           144:        BDY(rx)=can->xmin;
        !           145:        substr(CO,0,fr,can->vx,can->xmin?(Obj)rx:0,&tm); devalr(CO,tm,&gm);
        !           146:        BDY(ry)=can->ymin;
        !           147:        substr(CO,0,gm,can->vy,can->ymin?(Obj)ry:0,&tm); devalr(CO,tm,&sm);
        !           148:        can->vmax=can->vmin=ToReal(sm);
        !           149:
        !           150:        for(iy=0;iy<can->height;iy++)for(ix=0;ix<can->width;ix++)tab[ix][iy]=1.0;
        !           151:        subq(can->qxmax,can->qxmin,&dx); STOQ(can->width,w); divq(dx,w,&xstep);
        !           152:        subq(can->qymax,can->qymin,&dy); STOQ(can->height,h); divq(dy,h,&ystep);
        !           153:        MKV(can->vx,x); mulp(CO,(P)xstep,x,&t);
        !           154:        addp(CO,(P)can->qxmin,t,&s); substp(CO,can->formula,can->vx,s,&f1);
        !           155:        MKV(can->vy,y); mulp(CO,(P)ystep,y,&t);
        !           156:        addp(CO,(P)can->qymin,t,&s); substp(CO,f1,can->vy,s,&f2);
        !           157:        ptozp(f2,1,&c,&g);
        !           158:        a=(int *)ALLOCA((MAX(can->width,can->height)+1)*sizeof(int));
        !           159:        for(iy=0;iy<can->height;iy++)for(ix=0;ix<can->width;ix++)tab[ix][iy]=1.0;
        !           160:        subq(can->qxmax,can->qxmin,&dx); STOQ(can->width,w); divq(dx,w,&xstep);
        !           161:        subq(can->qymax,can->qymin,&dy); STOQ(can->height,h); divq(dy,h,&ystep);
        !           162:        MKV(can->vx,x); mulp(CO,(P)xstep,x,&t);
        !           163:        addp(CO,(P)can->qxmin,t,&s); substp(CO,can->formula,can->vx,s,&f1);
        !           164:        MKV(can->vy,y); mulp(CO,(P)ystep,y,&t);
        !           165:        addp(CO,(P)can->qymin,t,&s); substp(CO,f1,can->vy,s,&f2);
        !           166:        ptozp(f2,1,&c,&g);
        !           167:        a=(int *)ALLOCA((MAX(can->width,can->height)+1)*sizeof(int));
        !           168:        for(ix=0;ix<can->width;ix++){
        !           169:                STOQ(ix,q1); substp(CO,g,can->vx,(P)q1,&t); ptozp(t,1,&c,&g1);
        !           170:                if(!g1)for(iy=0;iy<can->height;iy++)tab[ix][iy]=0.0;
        !           171:                else if(!NUM(g1)){
        !           172:                        sturmseq(CO,g1,&ss);
        !           173:                        seproot(ss,0,can->width,a);
        !           174:                        for(iy=0,pa=a;iy<can->height;iy++,pa++){
        !           175:                                if(*pa<0||(*(pa+1)>=0&&(*pa>*(pa+1))))tab[ix][iy]=0.0;
        !           176:                                else {
        !           177:                                        STOQ(iy,q1);substp(CO,g1,can->vy,(P)q1,&t);
        !           178:                                        devalr(CO,(Obj)t,(Obj *)&s);
        !           179:                                        tab[ix][iy]=ToReal(s);
        !           180:                                        if(can->vmax<tab[ix][iy])can->vmax=tab[ix][iy];
        !           181:                                        if(can->vmin>tab[ix][iy])can->vmin=tab[ix][iy];
        !           182:                                }
        !           183:                        }
        !           184:                }
        !           185:        }
        !           186:        for(iy=0;iy<can->height;iy++){
        !           187:                STOQ(iy,q1); substp(CO,g,can->vy,(P)q1,&t); ptozp(t,1,&c,&g1);
        !           188:                if(!g1) for(ix=0;ix<can->width;ix++)tab[ix][iy]=0.0;
        !           189:                else if(!NUM(g1)){
        !           190:                        sturmseq(CO,g1,&ss);
        !           191:                        seproot(ss,0,can->height,a);
        !           192:                        for(ix=0,pa=a;ix<can->width;ix++,pa++){
        !           193:                                if(tab[ix][iy]!=0.0){
        !           194:                                        if(*pa<0||(*(pa+1)>=0&&(*pa>*(pa+1))))tab[ix][iy]=0.0;
        !           195:                                        else {
        !           196:                                                STOQ(ix,q1);substp(CO,g1,can->vx,(P)q1,&t);
        !           197:                                                devalr(CO,(Obj)t,(Obj *)&s);
        !           198:                                                tab[ix][iy]=ToReal(s);
        !           199:                                                if(can->vmax<tab[ix][iy])can->vmax=tab[ix][iy];
        !           200:                                                if(can->vmin>tab[ix][iy])can->vmin=tab[ix][iy];
        !           201:                                        }
        !           202:                                }
        !           203:                        }
1.1       noro      204:                }
                    205:        }
                    206: }
                    207:
1.9     ! saito     208: double usubstrp(P p,double r){
1.1       noro      209:        DCP dc;
                    210:        int d;
1.9     ! saito     211:        double t,pwrreal0();
1.1       noro      212:
1.9     ! saito     213:        if(!p) t=0.0;
        !           214:        else if(NUM(p))t=BDY((Real)p);
1.1       noro      215:        else {
1.9     ! saito     216:                dc=DC(p); t=BDY((Real)COEF(dc));
        !           217:                for(d=QTOS(DEG(dc)),dc=NEXT(dc);dc;d=QTOS(DEG(dc)),dc=NEXT(dc)){
        !           218:                        t=t*pwrreal0(r,(d-QTOS(DEG(dc))))+BDY((Real)COEF(dc));
1.1       noro      219:                }
1.9     ! saito     220:                if(d)t*=pwrreal0(r,d);
1.1       noro      221:        }
                    222:        return t;
                    223: }
                    224:
1.9     ! saito     225: void qcalc(char **tab,struct canvas *can){
        !           226:        //qifplotmain(Old type)
1.5       noro      227:        Q dx,dy,w,h,xstep,ystep,c,q1;
1.1       noro      228:        P g,g1,f1,f2,x,y,t,s;
                    229:        int ix,iy;
                    230:        int *a,*pa;
                    231:        VECT ss;
                    232:
                    233:        subq(can->qxmax,can->qxmin,&dx); STOQ(can->width,w); divq(dx,w,&xstep);
                    234:        subq(can->qymax,can->qymin,&dy); STOQ(can->height,h); divq(dy,h,&ystep);
                    235:        MKV(can->vx,x); mulp(CO,(P)xstep,x,&t);
                    236:        addp(CO,(P)can->qxmin,t,&s); substp(CO,can->formula,can->vx,s,&f1);
                    237:        MKV(can->vy,y); mulp(CO,(P)ystep,y,&t);
                    238:        addp(CO,(P)can->qymin,t,&s); substp(CO,f1,can->vy,s,&f2);
                    239:        ptozp(f2,1,&c,&g);
1.9     ! saito     240:        a=(int *)ALLOCA((MAX(can->width,can->height)+1)*sizeof(int));
1.1       noro      241:        initmarker(can,"Horizontal scan...");
1.9     ! saito     242:        for( ix=0; ix < can->width; ix++ ){
1.1       noro      243:                marker(can,DIR_X,ix);
                    244:                STOQ(ix,q1); substp(CO,g,can->vx,(P)q1,&t); ptozp(t,1,&c,&g1);
1.9     ! saito     245:                if( !g1 )
        !           246:                        for(iy=0; iy < can->height; iy++ )
        !           247:                                tab[ix][iy]=1;
        !           248:                else if( !NUM(g1) ){
1.5       noro      249:                        sturmseq(CO,g1,&ss); seproot(ss,0,can->height,a);
1.9     ! saito     250:                        for(iy=0, pa=a; iy < can->height; iy++, pa++ )
        !           251:                                if( *pa < 0 || (*(pa+1) >= 0 && (*pa > *(pa+1))) )
        !           252:                                        tab[ix][iy]=1;
1.1       noro      253:                }
                    254:        }
                    255:        initmarker(can,"Vertical scan...");
1.9     ! saito     256:        for( iy=0; iy < can->height; iy++ ){
1.1       noro      257:                marker(can,DIR_Y,iy);
                    258:                STOQ(iy,q1); substp(CO,g,can->vy,(P)q1,&t); ptozp(t,1,&c,&g1);
1.9     ! saito     259:                if( !g1 )
        !           260:                        for(ix=0; ix < can->width; ix++ )
        !           261:                                tab[ix][iy]=1;
        !           262:                else if( !NUM(g1) ){
1.5       noro      263:                        sturmseq(CO,g1,&ss); seproot(ss,0,can->width,a);
1.9     ! saito     264:                        for(ix=0, pa=a; ix < can->width; ix++, pa++ )
        !           265:                                if( *pa < 0 || (*(pa+1) >= 0 && (*pa > *(pa+1))) )
        !           266:                                        tab[ix][iy]=1;
1.1       noro      267:                }
                    268:        }
                    269: }
                    270:
1.9     ! saito     271: void sturmseq(VL vl,P p,VECT *rp){
        !           272:        P g1,g2,q,r,s,*t;
1.1       noro      273:        V v;
                    274:        VECT ret;
                    275:        int i,j;
                    276:        Q a,b,c,d,h,l,m,x;
                    277:
1.9     ! saito     278:        v=VR(p);t=(P *)ALLOCA((deg(v,p)+1)*sizeof(P));
        !           279:        g1=t[0]=p;diffp(vl,p,v,(P *)&a);ptozp((P)a,1,&c,&g2);t[1]=g2;
        !           280:        for(i=1,h=ONE,x=ONE;;){
        !           281:                if(NUM(g2)) break;
1.1       noro      282:                subq(DEG(DC(g1)),DEG(DC(g2)),&d);
1.9     ! saito     283:                l=(Q)LC(g2);
        !           284:                if(SGN(l)<0){
        !           285:                        chsgnq(l,&a);l=a;
1.1       noro      286:                }
1.9     ! saito     287:                addq(d,ONE,&a);pwrq(l,a,&b);mulp(vl,(P)b,g1,(P *)&a);
1.1       noro      288:                divsrp(vl,(P)a,g2,&q,&r);
1.9     ! saito     289:                if(!r) break;
        !           290:                chsgnp(r,&s);r=s;i++;
        !           291:                if(NUM(r)){
        !           292:                        t[i]=r;break;
        !           293:                }
        !           294:                pwrq(h,d,&m);g1=g2;
        !           295:                mulq(m,x,&a);divsp(vl,r,(P)a,&g2);t[i]=g2;
        !           296:                x=(Q)LC(g1);
        !           297:                if(SGN(x)<0){
        !           298:                        chsgnq(x,&a);x=a;
1.1       noro      299:                }
1.9     ! saito     300:                pwrq(x,d,&a);mulq(a,h,&b);divq(b,m,&h);
1.1       noro      301:        }
                    302:        MKVECT(ret,i+1);
1.9     ! saito     303:        for(j=0;j<=i;j++)
        !           304:                ret->body[j]=(pointer)t[j];
        !           305:        *rp=ret;
1.1       noro      306: }
                    307:
1.9     ! saito     308: void seproot(VECT s,int min,int max,int *ar){
        !           309:        P f,*ss;
1.1       noro      310:        Q q,t;
                    311:        int i,j,k;
                    312:
1.9     ! saito     313:        ss=(P *)s->body;f=ss[0];
        !           314:        for(i=min;i<=max;i++){
        !           315:                STOQ(i,q);usubstqp(f,q,&t);
        !           316:                if(!t)ar[i]=-1;
1.1       noro      317:                else {
1.9     ! saito     318:                        ar[i]=numch(s,q,t);break;
1.1       noro      319:                }
                    320:        }
1.9     ! saito     321:        if(i>max) return;
        !           322:        for(j=max;j>= min;j--){
1.1       noro      323:                STOQ(j,q); usubstqp(f,q,&t);
1.9     ! saito     324:                if(!t)ar[j]=-1;
1.1       noro      325:                else {
1.9     ! saito     326:                        if(i!=j)ar[j]=numch(s,q,t);
1.1       noro      327:                        break;
                    328:                }
                    329:        }
1.9     ! saito     330:        if(j<=i+1) return;
        !           331:        if(ar[i]==ar[j]){
        !           332:                for(k=i+1;k<j;k++)ar[k]=ar[i];
1.1       noro      333:                return;
                    334:        }
1.9     ! saito     335:        k=(i+j)/2;
1.1       noro      336:        seproot(s,i,k,ar);
                    337:        seproot(s,k,j,ar);
                    338: }
                    339:
1.9     ! saito     340: int numch(VECT s,Q n,Q a0){
1.1       noro      341:        int len,i,c;
                    342:        Q a;
                    343:        P *ss;
                    344:
1.9     ! saito     345:        len=s->len;ss=(P *)s->body;
        !           346:        for(i=1,c=0;i<len;i++){
1.1       noro      347:                usubstqp(ss[i],n,&a);
1.9     ! saito     348:                if(a){
        !           349:                        if((SGN(a)>0 && SGN(a0)<0)||(SGN(a)<0&&SGN(a0)>0))c++;
        !           350:                        a0=a;
1.1       noro      351:                }
                    352:        }
                    353:        return c;
                    354: }
                    355:
1.9     ! saito     356: void usubstqp(P p,Q r,Q *v){
1.1       noro      357:        Q d,d1,a,b,t;
                    358:        DCP dc;
                    359:
1.9     ! saito     360:        if(!p)
        !           361:                *v=0;
        !           362:        else if(NUM(p))*v=(Q)p;
1.1       noro      363:        else {
1.9     ! saito     364:                dc=DC(p);t=(Q)COEF(dc);
        !           365:                for(d=DEG(dc),dc=NEXT(dc);dc;d=DEG(dc),dc=NEXT(dc)){
        !           366:                        subq(d,DEG(dc),&d1);pwrq(r,d1,&a);
        !           367:                        mulq(t,a,&b);addq(b,(Q)COEF(dc),&t);
1.1       noro      368:                }
1.9     ! saito     369:                if(d){
        !           370:                        pwrq(r,d,&a);mulq(t,a,&b);t=b;
1.1       noro      371:                }
1.9     ! saito     372:                *v=t;
1.1       noro      373:        }
                    374: }
                    375:
1.9     ! saito     376: void plotcalc(struct canvas *can){
        !           377:        //plot,memory_plot,plotover,plot_resize
        !           378:        double x,xmin,xstep,ymax,ymin,dy,*tab,usubstrp();
        !           379:        int ix,w,h;
        !           380:        Real r,rx;
        !           381:        Obj fr,t,s;
1.1       noro      382:        POINT *pa;
                    383:
                    384:        MKReal(1.0,r); mulr(CO,(Obj)can->formula,(Obj)r,&fr);
1.9     ! saito     385:        w=can->width;h=can->height;
        !           386:        xmin=can->xmin;xstep=(can->xmax-can->xmin)/w;
        !           387:        tab=(double *)ALLOCA(w*sizeof(double));
        !           388:        MKReal(1,rx); // dummy real number
        !           389:        for(ix=0,x=xmin;ix<w;ix++,x+=xstep){
        !           390:                // full substitution
        !           391:                BDY(rx)=x;
1.5       noro      392:                substr(CO,0,fr,can->vx,x?(Obj)rx:0,&s);
                    393:                devalr(CO,(Obj)s,&t);
1.9     ! saito     394:                if(t&&(OID(t)!=O_N||NID((Num)t)!=N_R))
1.1       noro      395:                        error("plotcalc : invalid evaluation");
1.9     ! saito     396:                tab[ix]=ToReal((Num)t);
1.1       noro      397:        }
1.9     ! saito     398:        if(can->ymax==can->ymin){
        !           399:                for(ymax=ymin=tab[0],ix=1;ix<w;ix++){
        !           400:                        if(tab[ix]>ymax)ymax=tab[ix];
        !           401:                        if(tab[ix]<ymin)ymin=tab[ix];
1.1       noro      402:                }
1.9     ! saito     403:                can->ymax=ymax;can->ymin=ymin;
1.1       noro      404:        } else {
1.9     ! saito     405:                ymax=can->ymax;ymin=can->ymin;
1.1       noro      406:        }
1.9     ! saito     407:        dy=ymax-ymin;
        !           408:        can->pa=(struct pa *)MALLOC(sizeof(struct pa));
        !           409:        can->pa[0].length=w;
        !           410:        can->pa[0].pos=pa=(POINT *)MALLOC(w*sizeof(POINT));
        !           411:        for(ix=0;ix<w;ix++){
1.1       noro      412:                double t;
1.9     ! saito     413:                XC(pa[ix])=ix;
        !           414:                t=(h-1)*(ymax-tab[ix])/dy;
        !           415:                if(t>MAXSHORT)YC(pa[ix])=MAXSHORT;
        !           416:                else if(t<-MAXSHORT)YC(pa[ix])=-MAXSHORT;
        !           417:                else YC(pa[ix])=(long)t;
1.6       noro      418:        }
                    419: }
                    420:
1.9     ! saito     421: void polarplotcalc(struct canvas *can){
        !           422:        //polarplotNG
        !           423:        double xmax,xmin,ymax,ymin,dx,dy,pmin,pstep,tr,p, *tabx,*taby;
1.6       noro      424:        double usubstrp();
1.9     ! saito     425:        int i,nstep,w,h;
1.6       noro      426:        POINT *pa;
                    427:        Real r;
                    428:        Obj fr,t,s;
                    429:
                    430:        MKReal(1.0,r); mulr(CO,(Obj)can->formula,(Obj)r,&fr);
1.9     ! saito     431:        w=can->width; h=can->height; nstep=can->nzstep;
        !           432:        pmin=can->zmin; pstep=(can->zmax-can->zmin)/nstep;
        !           433:        tabx=(double *)ALLOCA(nstep*sizeof(double));
        !           434:        taby=(double *)ALLOCA(nstep*sizeof(double));
        !           435:        MKReal(1,r); // dummy real number
        !           436:        for(i=0,p=pmin;i<nstep;i++,p+= pstep){
        !           437:                // full substitution
        !           438:                BDY(r)=p;
1.6       noro      439:                substr(CO,0,fr,can->vx,p?(Obj)r:0,&s);
                    440:                devalr(CO,(Obj)s,&t);
1.9     ! saito     441:                if(t&&(OID(t)!=O_N||NID((Num)t)!=N_R))
1.6       noro      442:                        error("polarplotcalc : invalid evaluation");
1.9     ! saito     443:                tr=ToReal((Num)t);
        !           444:                tabx[i]=tr*cos(p);
        !           445:                taby[i]=tr*sin(p);
        !           446:        }
        !           447:        xmax=xmin=tabx[0];
        !           448:        ymax=ymin=taby[0];
        !           449:        for(i=1;i<nstep;i++){
        !           450:                if(tabx[i]>xmax)xmax=tabx[i];
        !           451:                if(tabx[i]<xmin)xmin=tabx[i];
        !           452:                if(taby[i]>ymax)ymax=taby[i];
        !           453:                if(taby[i]<ymin)ymin=taby[i];
        !           454:        }
        !           455:        can->xmax=xmax;can->xmin=xmin;
        !           456:        can->ymax=ymax;can->ymin=ymin;
        !           457:        dx=xmax-xmin;
        !           458:        dy=ymax-ymin;
        !           459:        can->pa=(struct pa *)MALLOC(sizeof(struct pa));
        !           460:        can->pa[0].length=nstep;
        !           461:        can->pa[0].pos=pa=(POINT *)MALLOC(w*sizeof(POINT));
        !           462:        for(i=0;i<nstep;i++){
        !           463:                XC(pa[i])=(w-1)*(tabx[i]-xmin)/dx;
        !           464:                YC(pa[i])=(h-1)*(ymax-taby[i])/dy;
1.1       noro      465:        }
                    466: }
1.8       saito     467:
1.9     ! saito     468: /*
        !           469: void ineqncalc(double **tab,struct canvas *can,int nox){
        !           470:        double x,y,xmin,ymin,xstep,ystep;
        !           471:        int ix,iy,w,h;
        !           472:        Real r,rx,ry;
        !           473:        Obj fr,g,t,s;
        !           474:        V vx,vy;
1.8       saito     475:
1.9     ! saito     476:        if(!nox) initmarker(can,"Evaluating...");
1.8       saito     477:        MKReal(1.0,r); mulr(CO,(Obj)can->formula,(Obj)r,&fr);
1.9     ! saito     478:        vx=can->vx;vy=can->vy;
        !           479:        w=can->width;h=can->height;
        !           480:        xmin=can->xmin;xstep=(can->xmax-can->xmin)/w;
        !           481:        ymin=can->ymin;ystep=(can->ymin-can->ymin)/h;
        !           482:        MKReal(1.0,rx); MKReal(1.0,ry); // dummy real
1.8       saito     483:
1.9     ! saito     484:        for(ix=0,x=xmin;ix<=w;ix++,x+=xstep){
        !           485:                BDY(rx)=x; substr(CO,0,fr,vx,x?(Obj)rx:0,&t);
1.8       saito     486:                devalr(CO,t,&g);
1.9     ! saito     487:                if(!nox) marker(can,DIR_X,ix);
        !           488:                for(iy=0,y=ymin;iy<=h;iy++,y+=ystep){
        !           489:                        BDY(ry)=y;
        !           490:                        substr(CO,0,g,vy,y?(Obj)ry:0,&t);
1.8       saito     491:                        devalr(CO,t,&s);
1.9     ! saito     492:                        tab[ix][iy]=ToReal(s);
1.8       saito     493:                }
                    494:        }
                    495: }
1.9     ! saito     496: */
1.8       saito     497:
1.9     ! saito     498: #if defined(INTERVAL)
        !           499: void itvcalc(double **mask, struct canvas *can, int nox){
        !           500:        //MODE_ITVIFPLOT
        !           501:        double x,y,xstep,ystep,dx,dy,wx,wy;
        !           502:        int idv,ix,iy,idx,idy;
        !           503:        Itv ity,itx,ddx,ddy;
        !           504:        Real r,rx,ry,rx1,ry1,rdx,rdy,rdx1,rdy1;
        !           505:        V vx,vy;
        !           506:        Obj fr,g,t,s;
1.8       saito     507:
1.9     ! saito     508:        idv=can->division;
1.8       saito     509:        MKReal(1.0,r); mulr(CO,(Obj)can->formula,(Obj)r,&fr);
1.9     ! saito     510:        vx=can->vx; vy=can->vy;
        !           511:        xstep=(can->xmax-can->xmin)/can->width;
        !           512:        ystep=(can->ymax-can->ymin)/can->height;
        !           513:        if(idv!=0){
        !           514:                wx=xstep/can->division;
        !           515:                wy=ystep/can->division;
        !           516:        }
        !           517:        MKReal(can->ymin,ry1);
        !           518:        for(iy=0,y=can->ymin; iy<can->height; iy++,y+=ystep){
        !           519:                ry=ry1;
        !           520:                MKReal(y+ystep,ry1);
1.8       saito     521:                istoitv((Num)(ry1),(Num)ry,&ity);
                    522:                substr(CO,0,(Obj)fr,vy,(Obj)ity,&t);
1.9     ! saito     523:                MKReal(can->xmin,rx1);
        !           524:                for(ix=0,x=can->xmin; ix<can->width; ix++,x+=xstep){
        !           525:                        rx=rx1;
1.8       saito     526:                        MKReal(x+xstep,rx1);
1.9     ! saito     527:                        istoitv((Num)(rx1),(Num)rx,&itx);
        !           528:                        substr(CO,0,(Obj)fr,vx,(Obj)itx,&t);
        !           529:                        MKReal(can->ymin,ry1);
        !           530:                        for(iy=0,y=can->ymin; iy<can->height; iy++,y+=ystep){
        !           531:                                ry=ry1;
        !           532:                                MKReal(y+ystep,ry1);
        !           533:                                istoitv((Num)ry,(Num)ry1,&ity);
        !           534:                                substr(CO,0,(Obj)t,vy,(Obj)ity,&g);
        !           535:                                if(compnum(0,0,(Num)g))mask[ix][iy]=-1;
        !           536:                                else {
        !           537:                                        mask[ix][iy]=0;
        !           538: /*
        !           539:                                        if(idv==0) mask[ix][iy]=0;
        !           540:                                        else {
        !           541:                                                MKReal(y,rdy1);
        !           542:                                                for(idy=0,dy=y;idy<idv;dy+=wy,idy++){
        !           543:                                                        rdy=rdy1;
        !           544:                                                        MKReal(dy+wy,rdy1);
        !           545:                                                        istoitv((Num)rdy,(Num)rdy1,&ddy);
        !           546:                                                        substr(CO,0,(Obj)fr,vy,(Obj)ddy,&t);
        !           547:                                                        MKReal(x,rdx1);
        !           548:                                                        for(idx=0,dx=x;idx<idx;dx+=wx,idx++){
        !           549:                                                                rdx=rdx1;
        !           550:                                                                MKReal(dx+wx,rdx1);
        !           551:                                                                istoitv((Num)rdx,(Num)rdx1,&ddx);
        !           552:                                                                substr(CO,0,(Obj)t,vx,(Obj)ddx,&g);
        !           553:                                                                if(!compnum(0,0,(Num)g)){
        !           554:                                                                        mask[ix][iy]=0;
        !           555:                                                                        break;
        !           556:                                                                }
        !           557:                                                        }
        !           558:                                                        if(mask[ix][iy]==0)break;
        !           559:                                                }
        !           560:                                        }
        !           561: */
        !           562:                                }
        !           563:                        }
1.8       saito     564:                }
                    565:        }
                    566: }
                    567: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>