This commit is contained in:
Efi Fogel 2009-07-12 07:02:38 +00:00
parent 7710492e9f
commit 7c643baa6f
1 changed files with 25 additions and 28 deletions

View File

@ -1,5 +1,3 @@
/*! \file test_connect_holes.cpp /*! \file test_connect_holes.cpp
* Connecting a polygon with holes. * Connecting a polygon with holes.
*/ */
@ -21,7 +19,6 @@
#endif #endif
#endif #endif
#include <CGAL/Cartesian.h> #include <CGAL/Cartesian.h>
#include <CGAL/connect_holes.h> #include <CGAL/connect_holes.h>
#include <list> #include <list>
@ -38,29 +35,29 @@ typedef Polygon_with_holes_2::Hole_const_iterator Hole_const_iterator;
typedef Polygon_with_holes_2::Hole_iterator Hole_iterator; typedef Polygon_with_holes_2::Hole_iterator Hole_iterator;
//compute the area of a polygon with holes //compute the area of a polygon with holes
FT pwh_area(Polygon_with_holes_2 pwh) { FT pwh_area(Polygon_with_holes_2 pwh)
Polygon_2 outerP = pwh.outer_boundary(); {
FT result = outerP.area(); Polygon_2 outerP = pwh.outer_boundary();
if (! pwh.has_holes()) FT result = outerP.area();
return result; if (! pwh.has_holes())
Hole_const_iterator hit = pwh.holes_begin(); return result;
while (hit != pwh.holes_end()) { Hole_const_iterator hit = pwh.holes_begin();
FT curHoleArea= (*hit).area(); while (hit != pwh.holes_end()) {
result = result + curHoleArea; FT curHoleArea= (*hit).area();
++hit; result = result + curHoleArea;
} ++hit;
//std::cout<< "The input pwh area is: " << result << std::endl; }
return result; //std::cout<< "The input pwh area is: " << result << std::endl;
return result;
} }
bool testExampleFile(const char* filename)
bool testExampleFile(const char* filename) { {
// Read a polygon with holes from a file. // Read a polygon with holes from a file.
std::ifstream input_file (filename); std::ifstream input_file (filename);
if (! input_file.is_open()) if (! input_file.is_open())
{ {
std::cerr << "Failed to open the " << filename <<std::endl; std::cerr << "Failed to open the " << filename << std::endl;
return false; return false;
} }
Polygon_2 outerP; Polygon_2 outerP;
@ -97,28 +94,28 @@ signature. The input polygon with holes area is calculated, and then
after the holes are connected, an output polygon is created, and its after the holes are connected, an output polygon is created, and its
area is calculated area is calculated
*/ */
int main (int argc, char **argv) int main()
{ {
std::string testfilePrefix = "data/pgn_holes"; std::string testfilePrefix = "data/pgn_holes";
std::string testfileSuffix = ".dat"; std::string testfileSuffix = ".dat";
int result = 0; int result = 0;
for (int i=1;i<6;i++) { for (int i = 1; i < 6; ++i) {
std::stringstream strs; std::stringstream strs;
std::string si; std::string si;
strs << i; strs << i;
strs >> si; strs >> si;
std::string filename = testfilePrefix + si + testfileSuffix; std::string filename = testfilePrefix + si + testfileSuffix;
const char *cfilename = filename.c_str(); const char * cfilename = filename.c_str();
bool res = testExampleFile(cfilename); bool res = testExampleFile(cfilename);
if (!res) { if (!res) {
std::cout << "test " << i << " was a bitter failure" << std::endl; std::cout << "test " << i << " was a bitter failure" << std::endl;
result=1; result = 1;
} }
else { else {
std::cout <<"test " << i << " was a great success" << std::endl; std::cout <<"test " << i << " was a great success" << std::endl;
} }
} }
if (result==0) if (result == 0)
std::cout << "ALL TESTS SUCCEEDED!" << std::endl; std::cout << "ALL TESTS SUCCEEDED!" << std::endl;
return result; return result;
} }