Bugfix in search_for_outside_edge routine.
[voro++.git] / branches / 2d_boundary / examples / test_ctr.cc
blob4bd4afa34a5b5e78067b4967aa5d23ee5f278288
1 #include "voro++_2d.hh"
3 // This function returns a random floating point number between 0 and 1
4 double rnd() {return double(rand())/RAND_MAX;}
6 int main() {
7 int i;double x,y;
9 // Initialize the container class to be the unit square, with
10 // non-periodic boundary conditions. Divide it into a 6 by 6 grid, with
11 // an initial memory allocation of 16 particles per grid square.
12 container_2d con(0,1,0,1,6,6,true,true,false,16);
14 // Add 1000 random points to the container
15 for(i=0;i<1000;i++) {
16 x=rnd();
17 y=rnd();
18 con.put(i,x,y,-1);
21 // Output the particle positions to a file
22 con.draw_particles("test_ctr.par");
24 // Output the Voronoi cells to a file, in the gnuplot format
25 con.draw_cells_gnuplot("test_ctr.gnu");
27 // Sum the Voronoi cell areas and compare to the container area
28 double carea(1),varea(con.sum_cell_areas());
29 printf("Total container area : %g\n"
30 "Total Voronoi cell area : %g\n"
31 "Difference : %g\n",carea,varea,varea-carea);