⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tvutil.c

📁 TV-tree的c实现源码
💻 C
📖 第 1 页 / 共 2 页
字号:
        count = (strlen(bitstr)) / 2;        convert(bitstr,string,count);        switches(string,count);        zvalue = compute(string,count);        return(zvalue);}*///*******************************************************************///  NCOMP :  Introduction procedure to calculate the zvalue of the  *///  curve.                                                          *///*******************************************************************//*int ncomp(char xcoor[], char ycoor[]){        char bstring[40];        int nvalue,n,i,count;        inleave(xcoor,ycoor,bstring);        count = strlen(bstring);        if (bstring[count-1] == '0')                nvalue = 0;        else nvalue = 1;        n = 2;        for (i=count-2; i>=0; i--)                {                if (bstring[i] == '1')                        nvalue = nvalue + n;                n = n * 2;                }        return(nvalue);}*///*******************************************************************///   ADDONE :  Adds one to a binary number                          *///*******************************************************************//*void addone(char coor[], char newbin[]){        int count;        count = strlen(coor);        newbin[count--] = '\0';        while ((coor[count] == '1') && (count > 0))                newbin[count--] = '0';        if (coor[count] == '0')                {                newbin[count--] = '1';                while (count >= 0)                        {                        newbin[count] = coor[count];                        count--;                        }                }        else if (count == 0)                newbin[count] = 'x';}*///*******************************************************************///   SUBONE :  Subtracts one from a binary number                   *///*******************************************************************//*void subone(char coor[], char newbin[]){        int count;        count = strlen(coor);        newbin[count--] = '\0';        while ((coor[count] == '0') && (count > 0))                newbin[count--] = '1';        if (coor[count] == '1')                {                newbin[count--] = '0';                while (count >= 0)                        {                        newbin[count] = coor[count];                        count--;                        }                }        else if (count == 0)                newbin[count] = 'x';}*///*******************************************************************///   ICONVERT :  Takes a binary number, divides it into 2-bit       *///   strings, and assigns a decimal value to each string.           *///   '00' gets 0; '01' gets 1; '10' gets 3, and '11' gets 2.        *///*******************************************************************//*void iconvert(int zcoors[], int string[], int count){       int t,n,i;        zcoors[0] = 0;        zcoors[1] = 0;        t = 1;        for (i=count-1;i>=0;i--)                {                if (string[i] == 1)                        zcoors[1] = zcoors[1] + t;                else if (string[i] == 2)                        {                        zcoors[0] = zcoors[0] + t;                        zcoors[1] = zcoors[1] + t;                        }                else if (string[i] == 3)                        {                        zcoors[0] = zcoors[0] + t;                        }                t = t * 10;                }        }*///*******************************************************************///   ISWITCHES :  Switches numbers to correspond with the rotation  *///   of Hilbert's curve.                                            *///*******************************************************************//*void iswitches(int string[], int count){       int i,j;        for (i=count-1;i>=0;i--)                {                if (string[i] == 0)                        {                        for(j=i+1;j<count;j++)                                {                                if (string[j] == 1)                                        string[j] = 3;                                else if (string[j] == 3)                                        string[j] = 1;                                }                        }                else if (string[i] == 3)                        {                        for (j=i+1;j<count;j++)                                {                                if (string[j] == 0)                                        string[j] = 2;                                else if (string[j] == 2)                                        string[j] = 0;                                }                        }                }}*///*******************************************************************///   ICOMPUTE :  Computes the zvalue, given an array of manipulated *///   numbers from SWITCHES.                                         *///*******************************************************************//*void icompute(int zvalue,int string[],int n,int degree){       int i,count;        if (zvalue >= (n*n))                string[0] = 9999;        else                {                count = (n*n)/4;                for (i=0;i<degree;i++)                        {                        string[i] = zvalue/count;                        zvalue = zvalue % count;                        count = count/4;                        }                }}*///*******************************************************************///   ZINVERSE  Introduction procedure to calculate the zvalue of    *///   the Hilbert curve.                                             *///*******************************************************************//*void zinverse(int zvalue,int n,int zcoors[]){        char xcoor[10],ycoor[10];        int count,i;        int string[20];        count = 0;        i=n;        while (i > 1)                {                i = i / 2;                count++;                }        icompute(zvalue,string,n,count);        if (string[0] != 9999)                {                iswitches(string,count);                iconvert(zcoors,string,count);                }        else zcoors[0] = 9999;}*///*******************************************************************///*******************************************************************//*void ninverse(int nvalue,int coors[]){        int i,y,x,n;        i = 1;        coors[0] = 0;        coors[1] = 0;        while (nvalue > 0)                {                y = nvalue % 2;                coors[1] = coors[1] + (y*i);                nvalue = nvalue / 2;                x = nvalue % 2;                coors[0] = coors[0] + (x*i);                nvalue = nvalue / 2;                i = i * 10;                }}int binary(int decvalue){        int i,x,binval;        i = 1;        binval = 0;        while (decvalue > 0)                {                x = decvalue % 2;                binval = binval + (x*i);                decvalue = decvalue / 2;                i = i * 10;                }        return(binval);}void binaryvec(int decvalue,char *zcoor, int degree)//convert decimal number decvalue into binary number stored in char array zcoor{int i,z[20]; for(i=degree-1;i>=0;i--)  {z[i]=decvalue%2;   decvalue=decvalue/2;  }; for (i=0;i<degree;i++)  if (z[i]==0)    zcoor[i]='0';  else zcoor[i]='1'; zcoor[degree]='\0';}// n=span of coordinateint hvalue(int x, int  y, int n)//return the hilbert curve value for coordinate (x,y){char xcoor[20],ycoor[20]; int i,degree, pow2; i=n; degree=0, pow2 = 1; while (i!=1)  {i=i/2;   degree++;   pow2 = pow2 * 2;  }; if (n != pow2)    degree++; binaryvec(x,xcoor,degree); binaryvec(y,ycoor,degree); return(zcomp(xcoor,ycoor));}*/int equal(float x, float y){   return ((abs(x - y) <= PRECISION * x) && (abs(y-x) <= PRECISION * y));}int equal(double x, double y){   return ((abs(x - y) <= PRECISION * x) && (abs(y-x) <= PRECISION * y));}// Check if alow..blow intersect with ahigh..bhigh// Return TRUE even if only touchingint intersect(float alow, float ahigh, float blow, float bhigh){   int result = TRUE;   if (alow < blow)      result = (blow <= ahigh);   else if (alow > blow)      result = (alow <= bhigh);   return result;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -