// ECG: Exercise 11: Example program for 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() {
    // Constructing a triangle within the box [-1,+1]x[-1,+1]
    Point p1( -8,  8, 10);
    Point p2( -8, -8, 10);
    Point p3(  8, -8, 10);
    Nef_polyhedron nef1( Line( p1, p2));
    Nef_polyhedron nef2( Line( p2, p3));
    Nef_polyhedron nef3( Line( p3, p1));

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


