bool函数将数组作为参数

时间:2013-05-27 15:50:57

标签: c++ for-loop boolean

我在测试中使用bool函数来查看两个对象是否是邻居。如果是,则先前的函数InitFaceCheck()将0或1写入全局数组N [16](检查16个案例)。

for (n = 0; n < count; n++ )
{
int l = 0;
    for (m = 0; m < count; m++ )
    { InitFaceCheck(tet[n], tet_copy[m]); //
                if( (tet[n].ID != tet_copy[m].ID) && (isNeighbour(N) == 1) ) // if T's
                {
                    for(j = 0; j < 16; j++){
                        printf("N[%i] = %i ",j, N[j]);

                    }
                    printf("\n");
                    tet[n].next[l] = tet_copy[m].ID; // mark them as neighbours
                l++; // neighbour counter
                };

    }


}

InitFaceCheck()函数评估两个四面体是否共享任何面部(即,如果共享一个面,如果共享一个面,则构成该面的三个顶点的x,y,z坐标)总共有16个测试,这里只包含2个:

void InitFaceCheck (TETRA a, TETRA b)
{
/*... Setup of bool variables to be used in CheckFace ()  ....
      a bit tedious due to having .x .y .z components but it is solid for our purposes ... */

bool f11 = ( (a.vert[0].x == b.vert[0].x) && (a.vert[0].y == b.vert[0].y) && (a.vert[0].z == b.vert[0].z) &&
             (a.vert[1].x == b.vert[1].x) && (a.vert[1].y == b.vert[1].y) && (a.vert[1].z == b.vert[1].z) &&
             (a.vert[2].x == b.vert[2].x) && (a.vert[2].y == b.vert[2].y) && (a.vert[2].z == b.vert[2].z) );

bool f12 = ( (a.vert[0].x == b.vert[0].x) && (a.vert[0].y == b.vert[0].y) && (a.vert[0].z == b.vert[0].z) &&
             (a.vert[1].x == b.vert[3].x) && (a.vert[1].y == b.vert[3].y) && (a.vert[1].z == b.vert[3].z) &&
             (a.vert[2].x == b.vert[2].x) && (a.vert[2].y == b.vert[2].y) && (a.vert[2].z == b.vert[2].z) );

.......
// write output of tests to global array N, so as to make them accessible to all functions
N[0] = f11;
N[1] = f12;
N[2] = f13;
N[3] = f14;
N[4] = f21;
N[5] = f22;
N[6] = f23;
N[7] = f24;
N[8] = f31;
N[9] = f32;
N[10] = f33;
N[11] = f34;
N[12] = f41;
N[13] = f42;
N[14] = f43;
N[15] = f44;

isNeighbour函数如下所示:

bool isNeighbour (int a[16])
{
    return (a[0] || a[1] || a[2] || a[3] || a[4] || a[5] || a[6] || a[7] || a[8]
            || a[9] || a[10] || a[11] || a[12] || a[13] || a[14] || a[15]);
//  int i = 0;
//for (i = 0; i < 16; i++)
//  {
//  if ( a[i] == 1 )    return true;
//
//  }

}   

输出看起来像这样:

T4092
T4100
N[0] = 0 N[1] = 0 N[2] = 0 N[3] = 0 N[4] = 0 N[5] = 0 N[6] = 0 N[7] = 0 N[8] = 1 N[9] = 0 N[10] = 0 N[11] = 0 N[12] = 0 N[13] = 0 N[14] = 0 N[15] = 0 
T4101
T4120
N[0] = 0 N[1] = 0 N[2] = 1 N[3] = 0 N[4] = 0 N[5] = 0 N[6] = 0 N[7] = 0 N[8] = 0 N[9] = 0 N[10] = 0 N[11] = 0 N[12] = 0 N[13] = 0 N[14] = 0 N[15] = 0 
T4169
N[0] = 0 N[1] = 0 N[2] = 0 N[3] = 0 N[4] = 0 N[5] = 0 N[6] = 0 N[7] = 0 N[8] = 0 N[9] = 0 N[10] = 0 N[11] = 0 N[12] = 1 N[13] = 0 N[14] = 0 N[15] = 0 
N[0] = 0 N[1] = 1 N[2] = 0 N[3] = 0 N[4] = 0 N[5] = 0 N[6] = 0 N[7] = 0 N[8] = 0 N[9] = 0 N[10] = 0 N[11] = 0 N[12] = 0 N[13] = 0 N[14] = 0 N[15] = 0 

我的问题如下:

  1. 为什么赢得了isNeighbour()工作的注释部分(它崩溃了) ? if循环中的条件是否正确? (它是做我做的 认为它在做什么?)

    当四面体大于1时,为什么N []被重写为0 邻居(见T4169有两行N [],在第二行, N [12]之前被评估为真(= 1),

    为什么在第二次评估时发现N [1] = 1; N [12]重置为0.

    - 对于上帝的爱,无论如何我可以以更优雅的方式获得类似的结果?我也知道我可能 违反基本的编码规则所以请不要犹豫 指出他们!

  2. 谢谢 编辑:这确实是C.我四处询问并被告知要包含并且bool应该可以正常工作。

0 个答案:

没有答案