// ECG: Exercise 11: Solution to exercise 2, 2D Nef-polyhedra
// ----------------------------------------------------------

#include <CGAL/basic.h>
#include <CGAL/leda_integer.h>
#include <CGAL/Extended_homogeneous.h>
#include <CGAL/Nef_polyhedron_2.h>
#include <CGAL/IO/Nef_polyhedron_2_Window_stream.h>

template <> // needed to use leda_integer with Extended_homogeneous
struct ring_or_field<leda_integer> {
    typedef ring_with_gcd kind;
    typedef leda_integer RT;
    static RT gcd(const RT& r1, const RT& r2) { return ::gcd(r1,r2); }
};

// Define the type of a Nef-polyhedron, its points and lines
typedef CGAL::Extended_homogeneous<leda_integer> Kernel;
typedef CGAL::Nef_polyhedron_2<Kernel>           Nef_polyhedron;
typedef Nef_polyhedron::Point                    Point;
typedef Nef_polyhedron::Line                     Line;


int main() {
    // we switch to an iterator based approach instead of creating
    // all halfspaces by hand
    Point points[7] = { Point(  8,  8, 10),
                        Point( -8,  8, 10),
                        Point( -8, -8, 10),
                        Point(  8, -8, 10),
                        Point( -4, -8, 10),
                        Point(  4, -8, 10),
                        Point(  0,  0, 10)};
    Nef_polyhedron box( points, points + 4);
    Nef_polyhedron triangle( points + 4, points + 7, Nef_polyhedron::EXCLUDED);
    Nef_polyhedron result = box - triangle;
    std::cout << "Number of edges = "
              << result.explorer().number_of_edges() << std::endl;

    // Visualize the result in a LEDA window
    CGAL::Window_stream* window = CGAL::create_and_display_demo_window();
    *window << result;
    window->read_mouse();
    return 0;
}


