diff --git a/src/mesh.cpp b/src/mesh.cpp --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -1970,29 +1970,42 @@ void Mesh::StandardInit(void) { #include "hull.h" -double Mesh::Compactness(double *res_compactness, double *res_area, double *res_cell_area) { + +double Mesh::Compactness(double *res_compactness, double *res_area, double *res_cell_area, double *res_circumference) { // Calculate compactness using the convex hull of the cells // We use Andrew's Monotone Chain Algorithm (see hull.cpp) // Step 1. Prepare data for 2D hull code - get boundary polygon int pc=0; - Point *p=new Point[boundary_polygon->nodes.size()]; + Point *p=new Point[boundary_polygon->nodes.size()+1]; for (list::const_iterator i = boundary_polygon->nodes.begin(); i!=boundary_polygon->nodes.end(); i++) { p[pc++]=Point((*i)->x,(*i)->y); } + // chainHull algorithm requires sorted points + qSort( p, p+pc ); + + // Step 2: call 2D Hull code int np=boundary_polygon->nodes.size(); - Point *hull=new Point[np]; + Point *hull=new Point[np+1]; int nph=chainHull_2D(p,np,hull); - // Step 3: calculate area of convex hull + // Step 3: calculate area and circumference of convex hull double hull_area=0.; + double hull_circumference=0.; + for (int i=0;iExactCircumference(); + csv_stream << Area() << ", " << NCells() << ", " << NNodes() << ", " << res_compactness << ", " << res_area << ", " << morph_circumference << ", " << hull_circumference << endl; } /* finis */