Annotation of researchv8dc/cmd/map/libmap/hex.c, revision 1.1.1.1

1.1       root        1: #include "map.h"
                      2: #define HUGE 1.e15
                      3: #define HFUZZ .0001
                      4: static float hcut[3] ;
                      5: static float kr[3] = { .5, -1., .5 };
                      6: static float ki[3] = { -1., 0., 1. };  /*to multiply by sqrt(3)/2*/
                      7: static float cr[3];
                      8: static float ci[3];
                      9: static struct place hem;
                     10: static struct coord twist;
                     11: static double  rootroot3, hkc;
                     12: static float w2;
                     13: static double cubrt();
                     14: static double rootk;
                     15: 
                     16: Xhex(place,x,y)
                     17: struct place *place;
                     18: float *x, *y;
                     19: {
                     20:        int ns;
                     21:        register i;
                     22:        float reduce();
                     23:        float zr,zi;
                     24:        double sr,si,tr,ti,ur,ui,vr,vi,yr,yi;
                     25:        struct place p;
                     26:        copyplace(place,&p);
                     27:        ns = place->nlat.l >= 0;
                     28:        if(!ns) {
                     29:                p.nlat.l = -p.nlat.l;
                     30:                p.nlat.s = -p.nlat.s;
                     31:        }
                     32:        if(p.nlat.l<HFUZZ) {
                     33:                for(i=0;i<3;i++)
                     34:                        if(fabs(reduce(p.wlon.l-hcut[i]))<HFUZZ) {
                     35:                                if(i==2) {
                     36:                                        *x = 2*cr[0] - cr[1];
                     37:                                        *y = 0;
                     38:                                } else {
                     39:                                        *x = cr[1];
                     40:                                        *y = 2*ci[2*i];
                     41:                                }
                     42:                                return(1);
                     43:                        }
                     44:                p.nlat.l = HFUZZ;
                     45:                sincos(&p.nlat);
                     46:        }
                     47:        norm(&p,&hem,&twist);
                     48:        Xstereographic(&p,&zr,&zi);
                     49:        zr /= 2;
                     50:        zi /= 2;
                     51:        cdiv(1-zr,-zi,1+zr,zi,&sr,&si);
                     52:        csq(sr,si,&tr,&ti);
                     53:        ccubrt(1+3*tr,3*ti,&ur,&ui);
                     54:        csqrt(ur-1,ui,&vr,&vi);
                     55:        cdiv(rootroot3+vr,vi,rootroot3-vr,-vi,&yr,&yi);
                     56:        yr /= rootk;
                     57:        yi /= rootk;
                     58:        elco2(fabs(yr),yi,hkc,1.,1.,x,y);
                     59:        if(yr < 0)
                     60:                *x = w2 - *x;
                     61:        if(!ns) reflect(hcut[0]>place->wlon.l?0:
                     62:                        hcut[1]>=place->wlon.l?1:
                     63:                        2,*x,*y,x,y);
                     64:        return(1);
                     65: }
                     66: 
                     67: int (*hex())()
                     68: {
                     69:        register i;
                     70:        float t;
                     71:        double root3;
                     72:        float c,d;
                     73:        struct place p;
                     74:        hcut[2] = PI;
                     75:        hcut[1] = hcut[2]/3;
                     76:        hcut[0] = -hcut[1];
                     77:        root3 = sqrt(3.);
                     78:        rootroot3 = sqrt(root3);
                     79:        t = 15 -8*root3;
                     80:        hkc = t*(1-sqrt(1-1/(t*t)));
                     81:        elco2(HUGE,0.,hkc,1.,1.,&w2,&t);
                     82:        w2 *= 2;
                     83:        rootk = sqrt(hkc);
                     84:        latlon(90.,90.,&hem);
                     85:        latlon(90.,0.,&p);
                     86:        Xhex(&p,&c,&t);
                     87:        latlon(0.,0.,&p);
                     88:        Xhex(&p,&d,&t);
                     89:        for(i=0;i<3;i++) {
                     90:                ki[i] *= root3/2;
                     91:                cr[i] = c + (c-d)*kr[i];
                     92:                ci[i] = (c-d)*ki[i];
                     93:        }
                     94:        deg2rad(0.,&twist);
                     95:        return(Xhex);
                     96: }
                     97: 
                     98: reflect(i,wr,wi,x,y)
                     99: float wr,wi;
                    100: float *x,*y;
                    101: {
                    102:        float pr,pi,l;
                    103:        pr = cr[i]-wr;
                    104:        pi = ci[i]-wi;
                    105:        l = 2*(kr[i]*pr + ki[i]*pi);
                    106:        *x = wr + l*kr[i];
                    107:        *y = wi + l*ki[i];
                    108: }
                    109: 
                    110: hexcut(g,og,cutlon)
                    111: struct place *g,*og;
                    112: float *cutlon;
                    113: {
                    114:        register t,i;
                    115:        if(g->nlat.l>=-HFUZZ&&og->nlat.l>=-HFUZZ)
                    116:                return(1);
                    117:        for(i=0;i<3;i++) {
                    118:                t = ckcut(g,og,*cutlon=hcut[i]);
                    119:                if(t!=1) return(t);
                    120:        }
                    121:        return(1);
                    122: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.