### Fixed small mistake in 2D Voronoi neighbour calculation. Added check for...

`Fixed small mistake in 2D Voronoi neighbour calculation. Added check for neighbour relations to unit test.`
parent 5b1895e3
 ... ... @@ -428,7 +428,7 @@ __attribute__((always_inline)) INLINE void voronoi_cell_interact( b2 * cell->vertices[index_above2]; vertices[nvert] = a2 * cell->vertices[index_below2] + b2 * cell->vertices[index_above2]; ngbs[nvert] = cell->ngbs[index_above1]; ngbs[nvert] = cell->ngbs[index_above2]; ++nvert; VORONOI_CHECK_SIZE(); ... ...
 ... ... @@ -34,6 +34,8 @@ int main() { /* test initialization and finalization algorithms */ { message("Testing initialization and finalization algorithm..."); struct voronoi_cell cell; double x = {0.5, 0.5, 0.5}; ... ... @@ -47,10 +49,15 @@ int main() { assert(cell.centroid == 0.5f); assert(cell.centroid == 0.5f); message("Done."); } /* test interaction algorithm: normal case */ { message("Testing %i cell grid with random positions...", TESTVORONOI2D_NUMCELL); /* create 100 cells with random positions in [0,1]x[0,1] */ struct voronoi_cell cells[TESTVORONOI2D_NUMCELL]; double x; ... ... @@ -102,16 +109,34 @@ int main() { /* print the cells to the stdout */ for (i = 0; i < TESTVORONOI2D_NUMCELL; ++i) { printf("Cell %i:\n", i); voronoi_print_cell(&cells[i]); voronoi_cell_finalize(&cells[i]); Atot += cells[i].volume; } /* Check the total surface area */ assert(fabs(Atot - 1.0f) < 1.e-6); /* Check the neighbour relations for an arbitrary cell: cell 44 We plotted the grid and manually found the correct neighbours and their order. */ assert(cells.nvert == 7); assert(cells.ngbs == 26); assert(cells.ngbs == 38); assert(cells.ngbs == 3); assert(cells.ngbs == 33); assert(cells.ngbs == 5); assert(cells.ngbs == 90); assert(cells.ngbs == 4); message("Done."); } /* test interaction algorithm */ { message("Testing 100 cell grid with Cartesian mesh positions..."); struct voronoi_cell cells; double x; float dx; ... ... @@ -161,12 +186,26 @@ int main() { /* print the cells to the stdout */ for (i = 0; i < 100; ++i) { printf("Cell %i:\n", i); voronoi_print_cell(&cells[i]); voronoi_cell_finalize(&cells[i]); Atot += cells[i].volume; } /* Check the total surface area */ assert(fabs(Atot - 1.0f) < 1.e-6); /* Check the neighbour relations for an arbitrary cell: cell 44 We plotted the grid and manually found the correct neighbours and their order. */ assert(cells.nvert == 5); assert(cells.ngbs == 34); assert(cells.ngbs == 35); assert(cells.ngbs == 45); assert(cells.ngbs == 54); assert(cells.ngbs == 43); message("Done."); } return 0; ... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!