1 // Voro++, a cell-based Voronoi library
3 // Authors : Chris H. Rycroft (LBL / UC Berkeley)
4 // Cody Robert Dance (UC Berkeley)
5 // Email : chr@alum.mit.edu
6 // Date : August 30th 2011
8 /** \file cell_nc_2d.hh
9 * \brief Header file for the non-convex 2D Voronoi classes. */
11 #ifndef VORO_CELL_NC_2D_HH
12 #define VORO_CELL_NC_2D_HH
18 class voronoicell_nonconvex_base_2d
: public voronoicell_base_2d
{
20 using voronoicell_base_2d::nplane
;
23 template<class vc_class
>
24 inline bool nplane_base(vc_class
&vc
,double x
,double y
,double rs
,int p_id
) {
25 printf("plane %g %g %g\n",x
,y
,rs
);
26 return exclude
?(nonconvex
?
27 (-x
*reg
[3]+y
*reg
[2]<-tolerance
&&x
*reg
[5]-y
*reg
[4]<-tolerance
)||nplane_nonconvex(vc
,x
,y
,rs
,p_id
):
28 -x
*reg
[3]+y
*reg
[2]<-tolerance
||x
*reg
[5]-y
*reg
[4]<-tolerance
||nplane(vc
,x
,y
,rs
,p_id
)):
29 nplane(vc
,x
,y
,rs
,p_id
);
31 template<class vc_class
>
32 bool nplane_nonconvex(vc_class
&vc
,double x
,double y
,double rs
,int p_id
);
33 inline void vecs(const char *filename
) {
34 FILE *fp
=safe_fopen(filename
,"w");
36 for(int i
=0;i
<3;i
++) {
37 r
=1;//(0.6+0.2*i)/sqrt(reg[2*i]*reg[2*i]+reg[2*i+1]*reg[2*i+1]);
38 fprintf(fp
,"0 0\n%g %g\n\n\n",reg
[2*i
]*r
,reg
[2*i
+1]*r
);
42 void init_nonconvex_base(double xmin
,double xmax
,double ymin
,double ymax
,double wx0
,double wy0
,double wx1
,double wy1
);
45 inline int face(double xmin
,double xmax
,double ymin
,double ymax
,double &wx
,double &wy
);
48 class voronoicell_nonconvex_2d
: public voronoicell_nonconvex_base_2d
{
50 inline bool nplane(double x
,double y
,double rs
,int p_id
) {
51 return nplane_base(*this,x
,y
,rs
,0);
53 inline bool nplane(double x
,double y
,int p_id
) {
55 return nplane(x
,y
,rs
,0);
57 inline bool plane(double x
,double y
,double rs
) {
58 return nplane(x
,y
,rs
,0);
60 inline bool plane(double x
,double y
) {
62 return nplane(x
,y
,rs
,0);
64 inline void init(double xmin
,double xmax
,double ymin
,double ymax
) {
65 nonconvex
=exclude
=false;
66 init_base(xmin
,xmax
,ymin
,ymax
);
68 inline void init_nonconvex(double xmin
,double xmax
,double ymin
,double ymax
,double wx0
,double wy0
,double wx1
,double wy1
) {
69 init_nonconvex_base(xmin
,xmax
,ymin
,ymax
,wx0
,wy0
,wx1
,wy1
);
72 inline void n_add_memory_vertices() {}
73 inline void n_copy(int a
,int b
) {}
74 inline void n_set(int a
,int id
) {}
75 friend class voronoicell_base_2d
;
78 class voronoicell_nonconvex_neighbor_2d
: public voronoicell_nonconvex_base_2d
{
81 voronoicell_nonconvex_neighbor_2d() : ne(new int[init_vertices
]) {}
82 ~voronoicell_nonconvex_neighbor_2d() {delete [] ne
;}
83 inline bool nplane(double x
,double y
,double rs
,int p_id
) {
84 return nplane_base(*this,x
,y
,rs
,p_id
);
86 inline bool nplane(double x
,double y
,int p_id
) {
88 return nplane(x
,y
,rs
,p_id
);
90 inline bool plane(double x
,double y
,double rs
) {
91 return nplane(x
,y
,rs
,0);
93 inline bool plane(double x
,double y
) {
95 return nplane(x
,y
,rs
,0);
97 void init(double xmin
,double xmax
,double ymin
,double ymax
);
98 void init_nonconvex(double xmin
,double xmax
,double ymin
,double ymax
,double wx0
,double wy0
,double wx1
,double wy1
);
99 virtual void neighbors(vector
<int> &v
);
101 inline void n_add_memory_vertices() {
102 int *nne
=new int[current_vertices
],
103 *nee
=ne
+(current_vertices
>>1),
105 while(nep
<nee
) *(nnep
++)=*(nep
++);
108 inline void n_copy(int a
,int b
) {ne
[a
]=ne
[b
];}
109 inline void n_set(int a
,int id
) {ne
[a
]=id
;}
110 friend class voronoicell_base_2d
;