mirror of https://github.com/CGAL/cgal
Simplify read_polygon
This commit is contained in:
parent
07753267c3
commit
281f6be281
|
|
@ -14,43 +14,17 @@
|
||||||
template <class Kernel>
|
template <class Kernel>
|
||||||
bool read_polygon (const char *filename, CGAL::Polygon_2<Kernel>& pgn)
|
bool read_polygon (const char *filename, CGAL::Polygon_2<Kernel>& pgn)
|
||||||
{
|
{
|
||||||
// Open the input file.
|
|
||||||
std::ifstream ifile(filename);
|
std::ifstream ifile(filename);
|
||||||
|
ifile >> pgn;
|
||||||
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());
|
|
||||||
|
|
||||||
// Make sure the polygon is simple.
|
// Make sure the polygon is simple.
|
||||||
if (! pgn.is_simple())
|
if (! pgn.is_simple())
|
||||||
{
|
{
|
||||||
std::cerr << "Error - the polygon is not simple." << std::endl;
|
std::cerr << "Error - the polygon is not simple." << std::endl;
|
||||||
return (false);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (true);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Kernel>
|
template <class Kernel>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue