Simplify read_polygon

This commit is contained in:
Sebastian Morr 2014-06-24 11:40:00 +02:00
parent 07753267c3
commit 281f6be281
1 changed files with 4 additions and 30 deletions

View File

@ -14,43 +14,17 @@
template <class Kernel>
bool read_polygon (const char *filename, CGAL::Polygon_2<Kernel>& pgn)
{
// Open the input file.
std::ifstream ifile (filename);
if (! ifile.is_open())
{
std::cerr << "Failed to open <" << filename << ">." << std::endl;
return (false);
}
// Read the polygon.
int n_vertices = 0;
typename Kernel::FT x, y;
std::list<typename Kernel::Point_2> vertices;
int k;
// Read the number of polygon vertices.
ifile >> n_vertices;
// Read the vertices.
for (k = 0; k < n_vertices; k++)
{
ifile >> x >> y;
vertices.push_back (typename Kernel::Point_2 (x, y));
}
ifile.close();
pgn = CGAL::Polygon_2<Kernel> (vertices.begin(), vertices.end());
std::ifstream ifile(filename);
ifile >> pgn;
// Make sure the polygon is simple.
if (! pgn.is_simple())
{
std::cerr << "Error - the polygon is not simple." << std::endl;
return (false);
return false;
}
return (true);
return true;
}
template <class Kernel>