Bugfix in search_for_outside_edge routine.
[voro++.git] / branches / 2d_boundary / src / cell_2d.hh
blob6a396a6ac664fabb5727058d620aac02d4f72f7b
1 /** \file cell_2d.hh
2 * \brief Header file for the voronoicell_2d class. */
4 #ifndef VOROPP_CELL_2D_HH
5 #define VOROPP_CELL_2D_HH
7 #include <cstdio>
8 #include <cstdlib>
9 #include <cmath>
10 using namespace std;
12 #include "common.hh"
13 #include "config.hh"
15 /** \brief A class encapsulating all the routines for storing and calculating a
16 * single Voronoi cell. */
17 class voronoicell_2d {
18 public:
19 /** This holds the current size of the ed and pts arrays. If
20 * more vertices are created than can fit in these arrays, then
21 * they are dynamically extended using the add_memory_vertices
22 * routine. */
23 int current_vertices;
24 /** This sets the size of the current delete stack. */
25 int current_delete_size;
26 /** The total nuber of vertices in the current cell. */
27 int p;
28 /** An array with size 2*current_vertices holding information
29 * about edge connections between vertices.*/
30 int *ed;
31 /** An array with size 2*current_vertices for holding
32 * the positions of the vertices. */
33 double *pts;
34 /** Is true if this point lies at the vertex of a nonconvexity, false otherwise. */
35 bool nonconvexity;
36 /** If nonconvexity=true, these arrays hold the relevant information for determining which region
37 a cutting particle is in. They hold garbage otherwise.regx[0]and regx[1] contain the vector representing
38 the nonconvex edge of the cell. regx[2] and regx[3] contain the vector perpendicular to the previous one
39 representing the direction in which that region extends.*/
40 double reg1[4], reg2[4];
42 voronoicell_2d();
43 ~voronoicell_2d();
44 void init(double xmin,double xmax,double ymin,double ymax);
45 void init_nonconvex(double bnds_loc[], int noofbnds);
46 void initialize_regions(double x1, double y1, double x2, double y2, bool ext);
47 void draw_gnuplot(double x,double y,FILE *fp=stdout);
48 /** Outputs the edges of the Voronoi cell in gnuplot format to
49 * an output stream.
50 * \param[in] (x,y) a displacement vector to be added to the
51 * cell's position.
52 * \param[in] filename the file to write to. */
53 inline void draw_gnuplot(double x,double y,const char *filename) {
54 FILE *fp(voropp_safe_fopen(filename,"w"));
55 draw_gnuplot(x,y,fp);
56 fclose(fp);
58 void draw_pov(double x,double y,double z,FILE *fp=stdout);
59 /** Outputs the edges of the Voronoi cell in POV-Ray format to
60 * an open file stream, displacing the cell by given vector.
61 * \param[in] (x,y,z) a displacement vector to be added to the
62 * cell's position.
63 * \param[in] filename the file to write to. */
64 inline void draw_pov(double x,double y,double z,const char *filename) {
65 FILE *fp(voropp_safe_fopen(filename,"w"));
66 draw_pov(x,y,z,fp);
67 fclose(fp);
69 void output_custom(const char *format,int i,double x,double y,double r,FILE *fp=stdout);
70 /** Computes the Voronoi cells for all particles in the
71 * container, and for each cell, outputs a line containing
72 * custom information about the cell structure. The output
73 * format is specified using an input string with control
74 * sequences similar to the standard C printf() routine.
75 * \param[in] format the format of the output lines, using
76 * control sequences to denote the different
77 * cell statistics.
78 * \param[in] i the ID of the particle associated with this
79 * Voronoi cell.
80 * \param[in] (x,y) the position of the particle associated
81 * with this Voronoi cell.
82 * \param[in] r a radius associated with the particle.
83 * \param[in] filename the file to write to. */
84 inline void output_custom(const char *format,int i,double x,double y,double r,const char *filename) {
85 FILE *fp(voropp_safe_fopen(filename,"w"));
86 output_custom(format,i,x,y,r,fp);
87 fclose(fp);
89 double cell_area();
90 bool plane(double x,double y,double rs);
91 bool plane_nonconvex(double x, double y, double rs);
92 bool halfplane(double x1, double y1, double rs, double x2, double y2);
93 bool wallcut(double wx1, double wy1, double wx2, double wy2);
94 double max_radius_squared();
95 double perimeter();
96 double area();
97 void centroid(double &cx,double &cy);
98 private:
99 void add_memory_vertices();
100 void add_memory_ds(int *&stackp);
101 /** Computes the distance of a Voronoi cell vertex to a plane.
102 * \param[in] (x,y) the normal vector to the plane.
103 * \param[in] rsq the distance along this vector of the plane.
104 * \param[in] qp the index of the vertex to consider. */
105 inline double pos(double x,double y,double rsq,int qp) {
106 return x*pts[2*qp]+y*pts[2*qp+1]-rsq;//vector projection??? (x,y) would have to be normalized
108 /** The delete stack, used to store the vertices that are
109 * deleted during the plane cutting procedure. */
110 int *ds;
111 /** A pointer to the end of the delete stack, used to detect
112 * when it is full. */
113 int *stacke;
116 #endif