Note that there are some explanatory texts on larger screens.

plurals
  1. PObool function taking array as argument
    primarykey
    data
    text
    <p>I have a bool function used in a test to see whether or not two objects are neighbours. If they are, a previous function InitFaceCheck() will write either 0 or 1 into a global array N[16] (16 cases to check for).</p> <pre><code>for (n = 0; n &lt; count; n++ ) { int l = 0; for (m = 0; m &lt; count; m++ ) { InitFaceCheck(tet[n], tet_copy[m]); // if( (tet[n].ID != tet_copy[m].ID) &amp;&amp; (isNeighbour(N) == 1) ) // if T's { for(j = 0; j &lt; 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 }; } } </code></pre> <p>The InitFaceCheck() function evaluates if any the two tetrahedra share any of their faces (i.e. they share a face if the share the x,y,z coords of the three vertices that constitute that face) in total there are 16 tests, only 2 are included here:</p> <pre><code>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) &amp;&amp; (a.vert[0].y == b.vert[0].y) &amp;&amp; (a.vert[0].z == b.vert[0].z) &amp;&amp; (a.vert[1].x == b.vert[1].x) &amp;&amp; (a.vert[1].y == b.vert[1].y) &amp;&amp; (a.vert[1].z == b.vert[1].z) &amp;&amp; (a.vert[2].x == b.vert[2].x) &amp;&amp; (a.vert[2].y == b.vert[2].y) &amp;&amp; (a.vert[2].z == b.vert[2].z) ); bool f12 = ( (a.vert[0].x == b.vert[0].x) &amp;&amp; (a.vert[0].y == b.vert[0].y) &amp;&amp; (a.vert[0].z == b.vert[0].z) &amp;&amp; (a.vert[1].x == b.vert[3].x) &amp;&amp; (a.vert[1].y == b.vert[3].y) &amp;&amp; (a.vert[1].z == b.vert[3].z) &amp;&amp; (a.vert[2].x == b.vert[2].x) &amp;&amp; (a.vert[2].y == b.vert[2].y) &amp;&amp; (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; </code></pre> <p>The isNeighbour function looks like this:</p> <pre><code>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 &lt; 16; i++) // { // if ( a[i] == 1 ) return true; // // } } </code></pre> <p>The output looks something like this:</p> <pre><code>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 </code></pre> <p>My questions are the following: </p> <ol> <li><p>why won't the commented out part of isNeighbour() work (it crashes) ? is the condition in the if loop correct ? (is it doing what I think it is doing?)</p> <p>why is N[] being rewritten as 0 when a tetrahedron has more than 1 neighbour (see T4169 with two lines of N[], in the second line, N[12] was previously evaluated to be true (=1), </p> <p>why is it when evaluating for the second time and it finds N[1]=1; N[12] is reset to 0.</p> <p>-and for the love of god is there anyway I could achieve a similar result but in a more elegant manner ? Also I am aware that I might be violating basic rules of coding so please do not hesitate to point them out!</p></li> </ol> <p>Thank you EDIT: this indeed C. I asked around and was told to include and bool should work just fine.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload