#include <CGAL/Exact_rational.h>
#include <CGAL/Cartesian.h>
#include <CGAL/Arr_linear_traits_2.h>
#include <CGAL/Arr_curve_data_traits_2.h>
#include <CGAL/Envelope_diagram_1.h>
#include <CGAL/envelope_2.h>
#include <vector>
typedef CGAL::Exact_rational Number_type;
typedef Linear_traits_2::Point_2 Point_2;
typedef Linear_traits_2::Line_2 Line_2;
unsigned int> Traits_2;
typedef Traits_2::X_monotone_curve_2 Dual_line_2;
int main (int argc, char* argv[])
{
const char* filename = (argc > 1) ? argv[1] : "ch_points.dat";
std::ifstream in_file(filename);
if (!in_file.is_open()) {
std::cerr << "Failed to open " << filename << " ..." << std::endl;
return -1;
}
std::list<Dual_line_2> dual_lines;
unsigned int n;
in_file >> n;
std::vector<Point_2> points;
points.resize(n);
for (unsigned int k = 0; k < n; ++k) {
int px, py;
in_file >> px >> py;
points[k] = Point_2 (px, py);
Line_2 line = Line_2 (Number_type(px), Number_type(-1), Number_type(-py));
dual_lines.push_back (Dual_line_2 (line, k));
}
in_file.close();
Diagram_1 min_diag;
Diagram_1 max_diag;
std::cout << "The convex hull of " << points.size() << " input points:";
Diagram_1::Edge_const_handle e = min_diag.leftmost();
while (e != min_diag.rightmost()) {
std::cout << " (" << points[e->curve().data()] << ')';
e = e->right()->right();
}
if (e->curve().data() != max_diag.leftmost()->curve().data())
std::cout << " (" << points[e->curve().data()] << ')';
e = max_diag.leftmost();
while (e != max_diag.rightmost()) {
std::cout << " (" << points[e->curve().data()] << ')';
e = e->right()->right();
}
std::cout << std::endl;
return 0;
}