// -*- Mode: c++ -*- // ============================================================================ // // Copyright (c) 1997 The CGAL Consortium // // This software and related documentation is part of an INTERNAL release // of the Computational Geometry Algorithms Library (CGAL). It is not // intended for general use. // // ---------------------------------------------------------------------------- // // release : $CGAL_Revision: CGAL-1.0 $ // release_date : $CGAL_Date: 1998/09/12 $ // // file : demo/BooleanOperations/BooleanOperations_demo.C // source : demo/BooleanOperations/BooleanOperations_demo.C // revision : $Revision$ // revision_date : $Date$ // author(s) : Wolfgang Freiseisen // // coordinator : RISC Linz // (Wolfgang Freiseisen ) // // // ============================================================================ /* This is an example program for the usage of boolean opertations: The number type it uses is a non-exact one: Quotient --------- The coordinates are usually cartesian and if one wants to use homogeneous coordinates the compiler option -DCGAL_BOPS_HOMOGENEOUS has to be added. */ #include #include #include #include #include #include using CGAL::Object; using std::list; using std::vector; using std::cout; using std::endl; //#include //typedef Rational TestNum; // only with Leda usage //typedef double TestNum; // non exact typedef CGAL::Quotient TestNum; // exact, but very finite #ifdef BOPS_HOMOGENEOUS typedef CGAL::Homogeneous R_type; #else typedef CGAL::Cartesian R_type; #endif typedef CGAL::Point_2 Point_2; typedef CGAL::Segment_2 Segment_2; // Polygon_2 typedef list< Point_2 > Container; typedef CGAL::Polygon_traits_2 Polygon_traits_2; typedef CGAL::Polygon_2< Polygon_traits_2, Container > Polygon_2; #include "CGAL/example_io.h" /* I/O to cin/cout */ int test_intersection(void) { vector vA(6), vB(4); test_input( vA, vB); Polygon_2 A(vA.begin(), vA.end()), B(vB.begin(),vB.end()); cout << "INTERSECTION" << endl; cout << "============" << endl; cout << "polygon A: " << A << endl; cout << "polygon B: " << B << endl; list result; CGAL::intersection(A,B, back_inserter(result)); test_result_output(result); return 0; } int test_difference(void) { vector vA(6), vB(4); test_input( vA, vB); Polygon_2 A(vA.begin(), vA.end()), B(vB.begin(),vB.end()); cout << "DIFFERENCE" << endl; cout << "==========" << endl; cout << "polygon A: " << A << endl; cout << "polygon B: " << B << endl; list result; CGAL::difference(A,B, back_inserter(result) ); test_result_output(result); return 0; } int test_union(void) { vector vA(6), vB(4); test_input( vA, vB); Polygon_2 A(vA.begin(), vA.end()), B(vB.begin(),vB.end()); cout << "UNION" << endl; cout << "=====" << endl; cout << "polygon A: " << A << endl; cout << "polygon B: " << B << endl; list result; CGAL::Union(A,B, back_inserter(result) ); test_result_output(result); return 0; } int main(int argc, char *argv[]) { int s= -1; if( argc>1 ) s= atoi(argv[1]); switch(s) { case 1: test_intersection(); break; case 2: test_difference(); break; case 3: test_union(); break; default: test_intersection(); test_difference(); test_union(); } return 0; }