From c683797c3befd065e472d6f087c718dda629569e Mon Sep 17 00:00:00 2001 From: Ron Wein Date: Thu, 9 Feb 2006 09:59:33 +0000 Subject: [PATCH] Separated the internal functions from the public global functions. --- .../include/CGAL/Boolean_set_operations_2.h | 904 ++++++++---------- .../Bso_internal_functions.h | 210 ++++ 2 files changed, 609 insertions(+), 505 deletions(-) create mode 100644 Packages/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Bso_internal_functions.h diff --git a/Packages/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2.h b/Packages/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2.h index 4ccc5088559..20d1afd9ae5 100644 --- a/Packages/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2.h +++ b/Packages/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2.h @@ -16,6 +16,7 @@ // $Name$ // // Author(s) : Baruch Zukerman +// Ron Wein #ifndef BOOLEAN_SET_OPERATIONS_H #define BOOLEAN_SET_OPERATIONS_H @@ -27,15 +28,14 @@ #include #include #include -#include #include +#include CGAL_BEGIN_NAMESPACE +/// \name do_intersect() functions. +//@{ -///////////////////// -// do_intersect // -/////////////////// template inline bool do_intersect(const Polygon_2& pgn1, const Polygon_2& pgn2) @@ -113,14 +113,16 @@ inline bool do_intersect(const General_polygon_2& pgn1, template inline bool do_intersect(const General_polygon_2& pgn1, - const General_polygon_with_holes_2 >& pgn2) + const General_polygon_with_holes_2 + >& pgn2) { return (_do_intersect(pgn1, pgn2)); } template inline bool do_intersect(const General_polygon_2& pgn1, - const General_polygon_with_holes_2 >& pgn2, + const General_polygon_with_holes_2 + >& pgn2, Gps_traits& tr) { return (_do_intersect(pgn1, pgn2, tr)); @@ -129,14 +131,16 @@ inline bool do_intersect(const General_polygon_2& pgn1, template -inline bool do_intersect(const General_polygon_with_holes_2 >& pgn1, +inline bool do_intersect(const General_polygon_with_holes_2 + >& pgn1, const General_polygon_2& pgn2) { return (_do_intersect(pgn1, pgn2)); } template -inline bool do_intersect(const General_polygon_with_holes_2 >& pgn1, +inline bool do_intersect(const General_polygon_with_holes_2 + >& pgn1, const General_polygon_2& pgn2, Gps_traits& tr) { @@ -158,29 +162,9 @@ inline bool do_intersect(const General_polygon_with_holes_2& pgn1, return (_do_intersect(pgn1, pgn2, tr)); } -template -inline bool _do_intersect(const Pgn1& pgn1, - const Pgn2& pgn2) -{ - typename Gps_default_traits::Traits tr; - return (_do_intersect(pgn1, pgn2, tr)); -} - -template -inline bool _do_intersect(const Pgn1& pgn1, - const Pgn2& pgn2, - Traits& tr) -{ - General_polygon_set_2 gps(tr); - gps.insert(pgn1); - return (gps.do_intersect(pgn2)); -} - - -///////////////////// -// intersection // -/////////////////// - +//@} +/// \name intersection() functions. +//@{ template inline OutputIterator intersection(const Polygon_2& pgn1, @@ -208,8 +192,9 @@ inline OutputIterator intersection(const Polygon_2& pgn1, } template -inline OutputIterator intersection(const Polygon_2& pgn1, - const Polygon_with_holes_2& pgn2, +inline OutputIterator +intersection (const Polygon_2& pgn1, + const Polygon_with_holes_2& pgn2, OutputIterator out, Traits& tr) { @@ -217,579 +202,526 @@ inline OutputIterator intersection(const Polygon_2& pgn1, } template -inline OutputIterator intersection(const Polygon_with_holes_2& pgn1, - const Polygon_2& pgn2, - OutputIterator out) +inline OutputIterator +intersection (const Polygon_with_holes_2& pgn1, + const Polygon_2& pgn2, + OutputIterator out) { return (_intersection(pgn1, pgn2, out)); } template -inline OutputIterator intersection(const Polygon_with_holes_2& pgn1, - const Polygon_2& pgn2, - OutputIterator out, - Traits& tr) +inline OutputIterator +intersection (const Polygon_with_holes_2& pgn1, + const Polygon_2& pgn2, + OutputIterator out, + Traits& tr) { return (_intersection(pgn1, pgn2, out, tr)); } template -inline OutputIterator intersection(const Polygon_with_holes_2& pgn1, - const Polygon_with_holes_2& pgn2, - OutputIterator out) +inline OutputIterator +intersection (const Polygon_with_holes_2& pgn1, + const Polygon_with_holes_2& pgn2, + OutputIterator out) { return (_intersection(pgn1, pgn2, out)); } template -inline OutputIterator intersection(const Polygon_with_holes_2& pgn1, - const Polygon_with_holes_2& pgn2, - OutputIterator out, - Traits& tr) +inline OutputIterator +intersection (const Polygon_with_holes_2& pgn1, + const Polygon_with_holes_2& pgn2, + OutputIterator out, + Traits& tr) { return (_intersection(pgn1, pgn2, out, tr)); } template -inline OutputIterator intersection(const General_polygon_2& pgn1, - const General_polygon_2& pgn2, - OutputIterator out) +inline OutputIterator intersection (const General_polygon_2& pgn1, + const General_polygon_2& pgn2, + OutputIterator out) { return (_intersection(pgn1, pgn2, out)); } template -inline OutputIterator intersection(const General_polygon_2& pgn1, - const General_polygon_2& pgn2, - OutputIterator out, - Traits& tr) +inline OutputIterator intersection (const General_polygon_2& pgn1, + const General_polygon_2& pgn2, + OutputIterator out, + Traits& tr) { return (_intersection(pgn1, pgn2, out, tr)); } template -inline OutputIterator intersection(const General_polygon_2& pgn1, - const General_polygon_with_holes_2 >& pgn2, - OutputIterator out) +inline OutputIterator +intersection (const General_polygon_2& pgn1, + const General_polygon_with_holes_2 + >& pgn2, + OutputIterator out) { return (_intersection(pgn1, pgn2, out)); } template -inline OutputIterator intersection(const General_polygon_2& pgn1, - const General_polygon_with_holes_2 >& pgn2, - OutputIterator out, - Traits& tr) +inline OutputIterator +intersection (const General_polygon_2& pgn1, + const General_polygon_with_holes_2 + >& pgn2, + OutputIterator out, + Traits& tr) { return (_intersection(pgn1, pgn2, out, tr)); } template -inline OutputIterator intersection(const General_polygon_with_holes_2 >& pgn1, - const General_polygon_2& pgn2, - OutputIterator out) +inline OutputIterator +intersection (const General_polygon_with_holes_2 + >& pgn1, + const General_polygon_2& pgn2, + OutputIterator out) { return (_intersection(pgn1, pgn2, out)); } template -inline OutputIterator intersection(const General_polygon_with_holes_2 >& pgn1, - const General_polygon_2& pgn2, - OutputIterator out, - Traits& tr) +inline OutputIterator +intersection (const General_polygon_with_holes_2 + >& pgn1, + const General_polygon_2& pgn2, + OutputIterator out, + Traits& tr) { return (_intersection(pgn1, pgn2, out, tr)); } template -inline OutputIterator intersection(const General_polygon_with_holes_2& pgn1, - const General_polygon_with_holes_2& pgn2, - OutputIterator out) +inline OutputIterator +intersection (const General_polygon_with_holes_2& pgn1, + const General_polygon_with_holes_2& pgn2, + OutputIterator out) { return (_intersection(pgn1, pgn2, out)); } template -inline OutputIterator intersection(const General_polygon_with_holes_2& pgn1, - const General_polygon_with_holes_2& pgn2, - OutputIterator out, - Traits& tr) +inline OutputIterator +intersection (const General_polygon_with_holes_2& pgn1, + const General_polygon_with_holes_2& pgn2, + OutputIterator out, + Traits& tr) { return (_intersection(pgn1, pgn2, out, tr)); } -template -inline OutputIterator _intersection(const Pgn1& pgn1, - const Pgn2& pgn2, - OutputIterator out) -{ - typedef typename Gps_default_traits::Traits Traits; - Traits tr; - return (_intersection(pgn1, pgn2, out, tr)); -} - -template -inline OutputIterator _intersection(const Pgn1& pgn1, - const Pgn2& pgn2, - OutputIterator out, - Traits& tr) -{ - General_polygon_set_2 gps(tr); - gps.insert(pgn1); - gps.intersection(pgn2); - return (gps.polygons_with_holes(out)); -} - - -///////////////////// -// join // -/////////////////// - -template -inline bool _is_empty(const typename Traits:: Polygon_2& pgn, Traits& tr) -{ - typedef typename Traits::Curve_const_iterator Curve_const_iterator; - const std::pair& itr_pair = - tr.construct_curves_2_object()(pgn); - return (itr_pair.first == itr_pair.second); -} - -template -inline bool _is_empty(const typename Traits::Polygon_with_holes_2& pgn, Traits& tr) -{ - return (false); -} +//@} +/// \name _join() functions. +//@{ template -inline bool join(const Polygon_2& pgn1, - const Polygon_2& pgn2, - Polygon_with_holes_2& res) +inline bool join (const Polygon_2& pgn1, + const Polygon_2& pgn2, + Polygon_with_holes_2& res) { return (_join(pgn1, pgn2, res)); } template -inline bool join(const Polygon_2& pgn1, - const Polygon_2& pgn2, - Polygon_with_holes_2& res, - Traits& tr) +inline bool join (const Polygon_2& pgn1, + const Polygon_2& pgn2, + Polygon_with_holes_2& res, + Traits& tr) { return (_join(pgn1, pgn2, res, tr)); } template -inline bool join(const Polygon_2& pgn1, - const Polygon_with_holes_2& pgn2, - Polygon_with_holes_2& res ) +inline bool join (const Polygon_2& pgn1, + const Polygon_with_holes_2& pgn2, + Polygon_with_holes_2& res ) { return (_join(pgn1, pgn2, res)); } template -inline bool join(const Polygon_2& pgn1, - const Polygon_with_holes_2& pgn2, - Polygon_with_holes_2& res, - Traits& tr) +inline bool join (const Polygon_2& pgn1, + const Polygon_with_holes_2& pgn2, + Polygon_with_holes_2& res, + Traits& tr) { return (_join(pgn1, pgn2, res, tr)); } template -inline bool join(const Polygon_with_holes_2& pgn1, - const Polygon_2& pgn2, - Polygon_with_holes_2& res ) +inline bool join (const Polygon_with_holes_2& pgn1, + const Polygon_2& pgn2, + Polygon_with_holes_2& res ) { return (_join(pgn1, pgn2, res)); } template -inline bool join(const Polygon_with_holes_2& pgn1, - const Polygon_2& pgn2, - Polygon_with_holes_2& res, - Traits& tr) +inline bool join (const Polygon_with_holes_2& pgn1, + const Polygon_2& pgn2, + Polygon_with_holes_2& res, + Traits& tr) { return (_join(pgn1, pgn2, res, tr)); } template -inline bool join(const Polygon_with_holes_2& pgn1, - const Polygon_with_holes_2& pgn2, - Polygon_with_holes_2& res ) +inline bool join (const Polygon_with_holes_2& pgn1, + const Polygon_with_holes_2& pgn2, + Polygon_with_holes_2& res ) { return (_join(pgn1, pgn2, res)); } template -inline bool join(const Polygon_with_holes_2& pgn1, - const Polygon_with_holes_2& pgn2, - Polygon_with_holes_2& res, +inline bool join (const Polygon_with_holes_2& pgn1, + const Polygon_with_holes_2& pgn2, + Polygon_with_holes_2& res, + Traits& tr) +{ + return (_join(pgn1, pgn2, res, tr)); +} + +template +inline bool +join (const General_polygon_2& pgn1, + const General_polygon_2& pgn2, + General_polygon_with_holes_2 >& res) +{ + return (_join(pgn1, pgn2, res)); +} + +template +inline bool +join (const General_polygon_2& pgn1, + const General_polygon_2& pgn2, + General_polygon_with_holes_2 >& res, Traits& tr) { return (_join(pgn1, pgn2, res, tr)); } template -inline bool join(const General_polygon_2& pgn1, - const General_polygon_2& pgn2, - General_polygon_with_holes_2 >& res) +inline bool +join (const General_polygon_2& pgn1, + const General_polygon_with_holes_2 >& pgn2, + General_polygon_with_holes_2 >& res) { return (_join(pgn1, pgn2, res)); } template -inline bool join(const General_polygon_2& pgn1, - const General_polygon_2& pgn2, - General_polygon_with_holes_2 >& res, - Traits& tr) +inline bool +join (const General_polygon_2& pgn1, + const General_polygon_with_holes_2 >& pgn2, + General_polygon_with_holes_2 >& res, + Traits& tr) { return (_join(pgn1, pgn2, res, tr)); } template -inline bool join(const General_polygon_2& pgn1, - const General_polygon_with_holes_2 >& pgn2, - General_polygon_with_holes_2 >& res) +inline bool +join (const General_polygon_with_holes_2 >& pgn1, + const General_polygon_2& pgn2, + General_polygon_with_holes_2 >& res) { return (_join(pgn1, pgn2, res)); } template -inline bool join(const General_polygon_2& pgn1, - const General_polygon_with_holes_2 >& pgn2, - General_polygon_with_holes_2 >& res, - Traits& tr) -{ - return (_join(pgn1, pgn2, res, tr)); -} - -template -inline bool join(const General_polygon_with_holes_2 >& pgn1, - const General_polygon_2& pgn2, - General_polygon_with_holes_2 >& res) -{ - return (_join(pgn1, pgn2, res)); -} - -template -inline bool join(const General_polygon_with_holes_2 >& pgn1, - const General_polygon_2& pgn2, - General_polygon_with_holes_2 >& res, - Traits& tr) +inline bool +join (const General_polygon_with_holes_2 >& pgn1, + const General_polygon_2& pgn2, + General_polygon_with_holes_2 >& res, + Traits& tr) { return (_join(pgn1, pgn2, res, tr)); } template -inline bool join(const General_polygon_with_holes_2& pgn1, - const General_polygon_with_holes_2& pgn2, - General_polygon_with_holes_2& res) +inline bool join (const General_polygon_with_holes_2& pgn1, + const General_polygon_with_holes_2& pgn2, + General_polygon_with_holes_2& res) { return (_join(pgn1, pgn2, res)); } template -inline bool join(const General_polygon_with_holes_2& pgn1, - const General_polygon_with_holes_2& pgn2, - General_polygon_with_holes_2& res, - Traits& tr) -{ - return (_join(pgn1, pgn2, res, tr)); -} - -template -inline bool _join(const Pgn1& pgn1, - const Pgn2& pgn2, - typename Gps_default_traits::Traits::Polygon_with_holes_2& res) -{ - typename Gps_default_traits::Traits tr; - return (_join(pgn1, pgn2, res, tr)); -} - -template -inline bool _join(const Pgn1& pgn1, - const Pgn2& pgn2, - typename Traits::Polygon_with_holes_2& res, +inline bool join (const General_polygon_with_holes_2& pgn1, + const General_polygon_with_holes_2& pgn2, + General_polygon_with_holes_2& res, Traits& tr) { - if(_is_empty(pgn1, tr) || _is_empty(pgn2, tr)) - return false; - - General_polygon_set_2 gps(tr); - gps.insert(pgn1); - gps.join(pgn2); - if(gps.number_of_polygons_with_holes() == 1) - { - Oneset_iterator oi (res); - gps.polygons_with_holes(oi); - return true; - } - - // the polygon doesnt intersect, the original pgn1, pgn2 contain the union - return false; + return (_join(pgn1, pgn2, res, tr)); } - -///////////////////// -// difference // -/////////////////// +//@} +/// \name difference() functions. +//@{ template -inline OutputIterator difference(const Polygon_2& pgn1, - const Polygon_2& pgn2, - OutputIterator oi) +inline OutputIterator difference (const Polygon_2& pgn1, + const Polygon_2& pgn2, + OutputIterator oi) { return(_difference(pgn1, pgn2, oi)); } template -inline OutputIterator difference(const Polygon_2& pgn1, - const Polygon_2& pgn2, - OutputIterator oi, - Traits& tr) +inline OutputIterator difference (const Polygon_2& pgn1, + const Polygon_2& pgn2, + OutputIterator oi, + Traits& tr) { return(_difference(pgn1, pgn2, oi, tr)); } template -inline OutputIterator difference(const Polygon_2& pgn1, - const Polygon_with_holes_2& pgn2, - OutputIterator oi) +inline OutputIterator +difference (const Polygon_2& pgn1, + const Polygon_with_holes_2& pgn2, + OutputIterator oi) { return(_difference(pgn1, pgn2, oi)); } template -inline OutputIterator difference(const Polygon_2& pgn1, - const Polygon_with_holes_2& pgn2, - OutputIterator oi, - Traits& tr) +inline OutputIterator +difference (const Polygon_2& pgn1, + const Polygon_with_holes_2& pgn2, + OutputIterator oi, + Traits& tr) { return(_difference(pgn1, pgn2, oi, tr)); } template -inline OutputIterator difference(const Polygon_with_holes_2& pgn1, - const Polygon_2& pgn2, - OutputIterator oi) +inline OutputIterator +difference (const Polygon_with_holes_2& pgn1, + const Polygon_2& pgn2, + OutputIterator oi) { return (_difference(pgn1, pgn2, oi)); } template -inline OutputIterator difference(const Polygon_with_holes_2& pgn1, - const Polygon_2& pgn2, - OutputIterator oi, - Traits& tr) +inline OutputIterator +difference (const Polygon_with_holes_2& pgn1, + const Polygon_2& pgn2, + OutputIterator oi, + Traits& tr) { return (_difference(pgn1, pgn2, oi, tr)); } template -inline OutputIterator difference(const Polygon_with_holes_2& pgn1, - const Polygon_with_holes_2& pgn2, - OutputIterator oi) +inline OutputIterator +difference (const Polygon_with_holes_2& pgn1, + const Polygon_with_holes_2& pgn2, + OutputIterator oi) { return (_difference(pgn1, pgn2, oi)); } template -inline OutputIterator difference(const Polygon_with_holes_2& pgn1, - const Polygon_with_holes_2& pgn2, - OutputIterator oi, - Traits& tr) +inline OutputIterator +difference (const Polygon_with_holes_2& pgn1, + const Polygon_with_holes_2& pgn2, + OutputIterator oi, + Traits& tr) { return (_difference(pgn1, pgn2, oi, tr)); } template -inline OutputIterator difference(const General_polygon_2& pgn1, - const General_polygon_2& pgn2, - OutputIterator oi) +inline OutputIterator difference (const General_polygon_2& pgn1, + const General_polygon_2& pgn2, + OutputIterator oi) { return (_difference(pgn1, pgn2, oi)); } template -inline OutputIterator difference(const General_polygon_2& pgn1, - const General_polygon_2& pgn2, - OutputIterator oi, - Traits& tr) +inline OutputIterator difference (const General_polygon_2& pgn1, + const General_polygon_2& pgn2, + OutputIterator oi, + Traits& tr) { return (_difference(pgn1, pgn2, oi, tr)); } template -inline OutputIterator difference(const General_polygon_2& pgn1, - const General_polygon_with_holes_2 >& pgn2, - OutputIterator oi) +inline OutputIterator difference (const General_polygon_2& pgn1, + const General_polygon_with_holes_2 + >& pgn2, + OutputIterator oi) { return (_difference(pgn1, pgn2, oi)); } template -inline OutputIterator difference(const General_polygon_2& pgn1, - const General_polygon_with_holes_2 >& pgn2, - OutputIterator oi, - Traits& tr) +inline OutputIterator difference (const General_polygon_2& pgn1, + const General_polygon_with_holes_2 + >& pgn2, + OutputIterator oi, + Traits& tr) { return (_difference(pgn1, pgn2, oi, tr)); } template -inline OutputIterator difference(const General_polygon_with_holes_2 >& pgn1, - const General_polygon_2& pgn2, - OutputIterator oi) +inline OutputIterator difference (const General_polygon_with_holes_2 + >& pgn1, + const General_polygon_2& pgn2, + OutputIterator oi) { return (_difference(pgn1, pgn2, oi)); } template -inline OutputIterator difference(const General_polygon_with_holes_2 >& pgn1, - const General_polygon_2& pgn2, - OutputIterator oi, - Traits& tr) +inline OutputIterator difference (const General_polygon_with_holes_2 + >& pgn1, + const General_polygon_2& pgn2, + OutputIterator oi, + Traits& tr) { return (_difference(pgn1, pgn2, oi, tr)); } template -inline OutputIterator difference(const General_polygon_with_holes_2& pgn1, - const General_polygon_with_holes_2& pgn2, - OutputIterator oi) +inline OutputIterator +difference (const General_polygon_with_holes_2& pgn1, + const General_polygon_with_holes_2& pgn2, + OutputIterator oi) { return (_difference(pgn1, pgn2, oi)); } template -inline OutputIterator difference(const General_polygon_with_holes_2& pgn1, - const General_polygon_with_holes_2& pgn2, - OutputIterator oi, - Traits& tr) +inline OutputIterator +difference (const General_polygon_with_holes_2& pgn1, + const General_polygon_with_holes_2& pgn2, + OutputIterator oi, + Traits& tr) { return (_difference(pgn1, pgn2, oi, tr)); } - -template -inline OutputIterator _difference(const Pgn1& pgn1, - const Pgn2& pgn2, - OutputIterator oi) -{ - typename Gps_default_traits::Traits tr; - return(_difference(pgn1, pgn2, oi, tr)); -} - -template -inline OutputIterator _difference(const Pgn1& pgn1, - const Pgn2& pgn2, - OutputIterator oi, - Traits& tr) -{ - General_polygon_set_2 gps(tr); - gps.insert(pgn1); - gps.difference(pgn2); - return (gps.polygons_with_holes(oi)); -} - - -///////////////////////////// -// symmetric_difference // -/////////////////////////// +//@} +/// \name symmetric_difference() functions. +//@{ template -inline OutputIterator symmetric_difference(const Polygon_2& pgn1, - const Polygon_2& pgn2, - OutputIterator oi, - Traits& tr) +inline OutputIterator +symmetric_difference (const Polygon_2& pgn1, + const Polygon_2& pgn2, + OutputIterator oi, + Traits& tr) { return (_symmetric_difference(pgn1, pgn2, oi, tr)); } template -inline OutputIterator symmetric_difference(const Polygon_2& pgn1, - const Polygon_2& pgn2, - OutputIterator oi) +inline OutputIterator +symmetric_difference (const Polygon_2& pgn1, + const Polygon_2& pgn2, + OutputIterator oi) { return (_symmetric_difference(pgn1, pgn2, oi)); } template -inline OutputIterator symmetric_difference(const Polygon_2& pgn1, - const Polygon_with_holes_2& pgn2, - OutputIterator oi, - Traits& tr) +inline OutputIterator +symmetric_difference (const Polygon_2& pgn1, + const Polygon_with_holes_2& pgn2, + OutputIterator oi, + Traits& tr) { return (_symmetric_difference(pgn1, pgn2, oi, tr)); } template -inline OutputIterator symmetric_difference(const Polygon_2& pgn1, - const Polygon_with_holes_2& pgn2, - OutputIterator oi) +inline OutputIterator +symmetric_difference (const Polygon_2& pgn1, + const Polygon_with_holes_2& pgn2, + OutputIterator oi) { return (_symmetric_difference(pgn1, pgn2, oi)); } template -inline OutputIterator symmetric_difference(const Polygon_with_holes_2& pgn1, - const Polygon_2& pgn2, - OutputIterator oi, - Traits& tr) +inline OutputIterator +symmetric_difference (const Polygon_with_holes_2& pgn1, + const Polygon_2& pgn2, + OutputIterator oi, + Traits& tr) { return (_symmetric_difference(pgn1, pgn2, oi, tr)); } template -inline OutputIterator symmetric_difference(const Polygon_with_holes_2& pgn1, - const Polygon_2& pgn2, - OutputIterator oi) +inline OutputIterator +symmetric_difference (const Polygon_with_holes_2& pgn1, + const Polygon_2& pgn2, + OutputIterator oi) { return (_symmetric_difference(pgn1, pgn2, oi)); } template -inline OutputIterator symmetric_difference(const Polygon_with_holes_2& pgn1, - const Polygon_with_holes_2& pgn2, - OutputIterator oi, - Traits& tr) +inline OutputIterator +symmetric_difference (const Polygon_with_holes_2& pgn1, + const Polygon_with_holes_2& pgn2, + OutputIterator oi, + Traits& tr) { return (_symmetric_difference(pgn1, pgn2, oi, tr)); } template -inline OutputIterator symmetric_difference(const Polygon_with_holes_2& pgn1, - const Polygon_with_holes_2& pgn2, - OutputIterator oi) +inline OutputIterator +symmetric_difference (const Polygon_with_holes_2& pgn1, + const Polygon_with_holes_2& pgn2, + OutputIterator oi) { return (_symmetric_difference(pgn1, pgn2, oi)); } template inline OutputIterator - symmetric_difference(const General_polygon_2& pgn1, - const General_polygon_2& pgn2, - OutputIterator oi, - Traits& tr) +symmetric_difference (const General_polygon_2& pgn1, + const General_polygon_2& pgn2, + OutputIterator oi, + Traits& tr) { return (_symmetric_difference(pgn1, pgn2, oi, tr)); } template inline OutputIterator - symmetric_difference(const General_polygon_2& pgn1, - const General_polygon_2& pgn2, - OutputIterator oi) +symmetric_difference (const General_polygon_2& pgn1, + const General_polygon_2& pgn2, + OutputIterator oi) { return (_symmetric_difference(pgn1, pgn2, oi)); } template inline OutputIterator -symmetric_difference(const General_polygon_2& pgn1, - const General_polygon_with_holes_2 >& pgn2, - OutputIterator oi, - Traits& tr) +symmetric_difference (const General_polygon_2& pgn1, + const General_polygon_with_holes_2 + >& pgn2, + OutputIterator oi, + Traits& tr) { return (_symmetric_difference(pgn1, pgn2, oi, tr)); } @@ -797,106 +729,93 @@ symmetric_difference(const General_polygon_2& pgn1, template inline OutputIterator symmetric_difference(const General_polygon_2& pgn1, - const General_polygon_with_holes_2 >& pgn2, + const General_polygon_with_holes_2 + >& pgn2, OutputIterator oi) { return (_symmetric_difference(pgn1, pgn2, oi)); } template -inline OutputIterator symmetric_difference(const General_polygon_with_holes_2 >& pgn1, - const General_polygon_2& pgn2, - OutputIterator oi, - Traits& tr) +inline OutputIterator +symmetric_difference (const General_polygon_with_holes_2 + >& pgn1, + const General_polygon_2& pgn2, + OutputIterator oi, + Traits& tr) { return (_symmetric_difference(pgn1, pgn2, oi, tr)); } template -inline OutputIterator symmetric_difference(const General_polygon_with_holes_2 >& pgn1, - const General_polygon_2& pgn2, - OutputIterator oi) +inline OutputIterator +symmetric_difference (const General_polygon_with_holes_2 + >& pgn1, + const General_polygon_2& pgn2, + OutputIterator oi) { return (_symmetric_difference(pgn1, pgn2, oi)); } template -inline OutputIterator symmetric_difference(const General_polygon_with_holes_2& pgn1, - const General_polygon_with_holes_2& pgn2, - OutputIterator oi, - Traits& tr) +inline OutputIterator +symmetric_difference (const General_polygon_with_holes_2& pgn1, + const General_polygon_with_holes_2& pgn2, + OutputIterator oi, + Traits& tr) { return (_symmetric_difference(pgn1, pgn2, oi, tr)); } template -inline OutputIterator symmetric_difference(const General_polygon_with_holes_2& pgn1, - const General_polygon_with_holes_2& pgn2, - OutputIterator oi) +inline OutputIterator +symmetric_difference (const General_polygon_with_holes_2& pgn1, + const General_polygon_with_holes_2& pgn2, + OutputIterator oi) { return (_symmetric_difference(pgn1, pgn2, oi)); } - -template -inline OutputIterator _symmetric_difference(const Pgn1& pgn1, - const Pgn2& pgn2, - OutputIterator oi, - Traits& tr) -{ - General_polygon_set_2 gps(tr); - gps.insert(pgn1); - gps.symmetric_difference(pgn2); - return (gps.polygons_with_holes(oi)); -} - -template -inline OutputIterator _symmetric_difference(const Pgn1& pgn1, - const Pgn2& pgn2, - OutputIterator oi) -{ - typename Gps_default_traits::Traits tr; - return (_symmetric_difference(pgn1, pgn2, oi, tr)); -} - -///////////////////////////// -// complement // -/////////////////////////// +//@} +/// \name complement() functions. +//@{ template -void complement(const Polygon_2& pgn, - Polygon_with_holes_2& res) +void complement (const Polygon_2& pgn, + Polygon_with_holes_2& res) { _complement(pgn, res); } template -void complement(const Polygon_2& pgn, - Polygon_with_holes_2& res, - Traits& tr) +void complement (const Polygon_2& pgn, + Polygon_with_holes_2& res, + Traits& tr) { _complement(pgn, res, tr); } template -void complement(const General_polygon_2& pgn, - General_polygon_with_holes_2 >& res) +void complement (const General_polygon_2& pgn, + General_polygon_with_holes_2 + >& res) { _complement(pgn, res); } template -void complement(const General_polygon_2& pgn, - General_polygon_with_holes_2 >& res, - Traits& tr) +void complement (const General_polygon_2& pgn, + General_polygon_with_holes_2 + >& res, + Traits& tr) { _complement(pgn, res, tr); } template -OutputIterator complement(const Polygon_with_holes_2& pgn, - OutputIterator oi, - Traits& tr) +OutputIterator complement (const Polygon_with_holes_2& pgn, + OutputIterator oi, + Traits& tr) { General_polygon_set_2 gps(tr); gps.insert(pgn); @@ -905,17 +824,17 @@ OutputIterator complement(const Polygon_with_holes_2& pgn, } template -OutputIterator complement(const Polygon_with_holes_2& pgn, - OutputIterator oi) +OutputIterator complement (const Polygon_with_holes_2& pgn, + OutputIterator oi) { typename Gps_default_traits >::Traits tr; return (complement(pgn, oi, tr)); } template -OutputIterator complement(const General_polygon_with_holes_2& pgn, - OutputIterator oi, - Traits& tr) +OutputIterator complement (const General_polygon_with_holes_2& pgn, + OutputIterator oi, + Traits& tr) { General_polygon_set_2 gps(tr); gps.insert(pgn); @@ -924,40 +843,17 @@ OutputIterator complement(const General_polygon_with_holes_2& pgn, } template -OutputIterator complement(General_polygon_with_holes_2 >& pgn, - OutputIterator oi) +OutputIterator complement (General_polygon_with_holes_2 + >& pgn, + OutputIterator oi) { typename Gps_default_traits >::Traits tr; return (complement(pgn, oi, tr)); } - - - -template -void _complement(const Pgn& pgn, - typename Traits::Polygon_with_holes_2& res, - Traits& tr) -{ - General_polygon_set_2 gps(tr); - gps.insert(pgn); - gps.complement(); - Oneset_iterator oi(res); - gps.polygons_with_holes(oi); - -} - -template -void _complement(const Pgn& pgn, - typename Gps_default_traits::Traits::Polygon_with_holes_2& res) -{ - typename Gps_default_traits::Traits tr; - _complement(pgn, res, tr); -} - - -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// +//@} +/// \name Aggregated join() functions. +//@{ template struct map_iterator_to_traits @@ -966,15 +862,6 @@ struct map_iterator_to_traits typedef typename Gps_default_traits::Traits Traits; }; -template -inline OutputIterator join(InputIterator begin, - InputIterator end, - OutputIterator oi) -{ - typename map_iterator_to_traits::Traits tr; - return join(begin, end, oi, tr); -} - template inline OutputIterator join(InputIterator begin, InputIterator end, @@ -989,21 +876,18 @@ inline OutputIterator join(InputIterator begin, return (gps.polygons_with_holes(oi)); } - -// join two ranges of simple polygons and polygons with holes -template -inline OutputIterator join(InputIterator1 begin1, - InputIterator1 end1, - InputIterator2 begin2, - InputIterator2 end2, +template +inline OutputIterator join(InputIterator begin, + InputIterator end, OutputIterator oi) { - typename map_iterator_to_traits::Traits tr; - return join(begin1, end1, begin2, end2, oi, tr); + typename map_iterator_to_traits::Traits tr; + return join(begin, end, oi, tr); } - -template +// Join two ranges of simple polygons and polygons with holes. +template inline OutputIterator join(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, @@ -1019,24 +903,25 @@ inline OutputIterator join(InputIterator1 begin1, return (gps.polygons_with_holes(oi)); } - -////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////// - -template -inline OutputIterator intersection(InputIterator begin, - InputIterator end, - OutputIterator oi) +template +inline OutputIterator join(InputIterator1 begin1, + InputIterator1 end1, + InputIterator2 begin2, + InputIterator2 end2, + OutputIterator oi) { - typename map_iterator_to_traits::Traits tr; - return intersection(begin, end, oi, tr); + typename map_iterator_to_traits::Traits tr; + return join(begin1, end1, begin2, end2, oi, tr); } +//@} +/// \name Aggregated intersection() functions. +//@{ template -inline OutputIterator intersection(InputIterator begin, - InputIterator end, - OutputIterator oi, - Traits& tr) +inline OutputIterator intersection (InputIterator begin, + InputIterator end, + OutputIterator oi, + Traits& tr) { if(begin == end) return (oi); @@ -1046,21 +931,18 @@ inline OutputIterator intersection(InputIterator begin, return (gps.polygons_with_holes(oi)); } - -// inersect two ranges of simple polygons and polygons with holes -template -inline OutputIterator intersection(InputIterator1 begin1, - InputIterator1 end1, - InputIterator2 begin2, - InputIterator2 end2, - OutputIterator oi) +template +inline OutputIterator intersection (InputIterator begin, + InputIterator end, + OutputIterator oi) { - typename map_iterator_to_traits::Traits tr; - return intersection(begin1, end1, begin2, end2, oi, tr); + typename map_iterator_to_traits::Traits tr; + return intersection(begin, end, oi, tr); } - -template +// Inersect two ranges of simple polygons and polygons with holes. +template inline OutputIterator intersection(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, @@ -1077,18 +959,20 @@ inline OutputIterator intersection(InputIterator1 begin1, } -////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////// - -template -inline OutputIterator symmetric_difference(InputIterator begin, - InputIterator end, - OutputIterator oi) +template +inline OutputIterator intersection(InputIterator1 begin1, + InputIterator1 end1, + InputIterator2 begin2, + InputIterator2 end2, + OutputIterator oi) { - typename map_iterator_to_traits::Traits tr; - return symmetric_difference(begin, end, oi, tr); + typename map_iterator_to_traits::Traits tr; + return intersection(begin1, end1, begin2, end2, oi, tr); } +//@} +/// \name Aggregated symmetric_difference() functions. +//@{ template inline OutputIterator symmetric_difference(InputIterator begin, InputIterator end, @@ -1104,27 +988,24 @@ inline OutputIterator symmetric_difference(InputIterator begin, return (gps.polygons_with_holes(oi)); } - -// inersect two ranges of simple polygons and polygons with holes -template -inline OutputIterator symmetric_difference(InputIterator1 begin1, - InputIterator1 end1, - InputIterator2 begin2, - InputIterator2 end2, - OutputIterator oi) +template +inline OutputIterator symmetric_difference (InputIterator begin, + InputIterator end, + OutputIterator oi) { - typename map_iterator_to_traits::Traits tr; - return symmetric_difference(begin1, end1, begin2, end2, oi, tr); + typename map_iterator_to_traits::Traits tr; + return symmetric_difference(begin, end, oi, tr); } - -template -inline OutputIterator symmetric_difference(InputIterator1 begin1, - InputIterator1 end1, - InputIterator2 begin2, - InputIterator2 end2, - OutputIterator oi, - Traits& tr) +// Xor two ranges of simple polygons and polygons with holes. +template +inline OutputIterator symmetric_difference (InputIterator1 begin1, + InputIterator1 end1, + InputIterator2 begin2, + InputIterator2 end2, + OutputIterator oi, + Traits& tr) { if(begin1 == end1) return (symmetric_difference(begin2, end2, oi, tr)); @@ -1136,8 +1017,20 @@ inline OutputIterator symmetric_difference(InputIterator1 begin1, } -////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////// +template +inline OutputIterator symmetric_difference (InputIterator1 begin1, + InputIterator1 end1, + InputIterator2 begin2, + InputIterator2 end2, + OutputIterator oi) +{ + typename map_iterator_to_traits::Traits tr; + return symmetric_difference(begin1, end1, begin2, end2, oi, tr); +} + +//@} +/// \name Aggregated do_intersect() functions. +//@{ template inline bool do_intersect(InputIterator begin, InputIterator end, Traits& tr) @@ -1159,9 +1052,9 @@ inline bool do_intersect(InputIterator begin, InputIterator end) } template -inline bool do_intersect(InputIterator1 begin1, InputIterator1 end1, - InputIterator2 begin2, InputIterator2 end2, - Traits& tr) +inline bool do_intersect (InputIterator1 begin1, InputIterator1 end1, + InputIterator2 begin2, InputIterator2 end2, + Traits& tr) { if(begin1 == end1) return (do_intersect(begin2, end2, tr)); @@ -1172,13 +1065,14 @@ inline bool do_intersect(InputIterator1 begin1, InputIterator1 end1, } template -inline bool do_intersect(InputIterator1 begin1, InputIterator1 end1, - InputIterator2 begin2, InputIterator2 end2) +inline bool do_intersect (InputIterator1 begin1, InputIterator1 end1, + InputIterator2 begin2, InputIterator2 end2) { typename map_iterator_to_traits::Traits tr; return do_intersect(begin1, end1, begin2, end2, tr); } +//@} CGAL_END_NAMESPACE diff --git a/Packages/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Bso_internal_functions.h b/Packages/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Bso_internal_functions.h new file mode 100644 index 00000000000..c02addac64b --- /dev/null +++ b/Packages/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Bso_internal_functions.h @@ -0,0 +1,210 @@ +// Copyright (c) 2005 Tel-Aviv University (Israel). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you may redistribute it under +// the terms of the Q Public License version 1.0. +// See the file LICENSE.QPL distributed with CGAL. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $Source$ +// $Revision$ $Date$ +// $Name$ +// +// Author(s) : Baruch Zukerman +// Ron Wein + +#ifndef CGAL_BSO_INTERNAL_FUCNTIONS_H +#define CGAL_BSO_INTERNAL_FUNCTIONS_H + +#include +#include + +CGAL_BEGIN_NAMESPACE + +/// \name _do_intersect() functions. +//@{ + +template +inline bool _do_intersect(const Pgn1& pgn1, + const Pgn2& pgn2, + Traits& tr) +{ + General_polygon_set_2 gps(tr); + gps.insert(pgn1); + return (gps.do_intersect(pgn2)); +} + +template +inline bool _do_intersect(const Pgn1& pgn1, + const Pgn2& pgn2) +{ + typename Gps_default_traits::Traits tr; + return (_do_intersect(pgn1, pgn2, tr)); +} + +//@} +/// \name _intersection() functions. +//@{ + +template +inline OutputIterator _intersection(const Pgn1& pgn1, + const Pgn2& pgn2, + OutputIterator out, + Traits& tr) +{ + General_polygon_set_2 gps(tr); + gps.insert(pgn1); + gps.intersection(pgn2); + return (gps.polygons_with_holes(out)); +} + +template +inline OutputIterator _intersection(const Pgn1& pgn1, + const Pgn2& pgn2, + OutputIterator out) +{ + typedef typename Gps_default_traits::Traits Traits; + Traits tr; + return (_intersection(pgn1, pgn2, out, tr)); +} + +//@} +/// \name _join() functions. +//@{ + +template +inline bool _is_empty (const typename Traits:: Polygon_2& pgn, + Traits& tr) +{ + typedef typename Traits::Curve_const_iterator Curve_const_iterator; + const std::pair& itr_pair = + tr.construct_curves_2_object()(pgn); + return (itr_pair.first == itr_pair.second); +} + +template +inline bool _is_empty (const typename Traits::Polygon_with_holes_2& pgn, + Traits& tr) +{ + return (false); +} + +template +inline bool _join(const Pgn1& pgn1, + const Pgn2& pgn2, + typename Traits::Polygon_with_holes_2& res, + Traits& tr) +{ + if (_is_empty(pgn1, tr) || _is_empty(pgn2, tr)) + return (false); + + General_polygon_set_2 gps(tr); + gps.insert(pgn1); + gps.join(pgn2); + if (gps.number_of_polygons_with_holes() == 1) + { + Oneset_iterator oi (res); + gps.polygons_with_holes(oi); + return (true); + } + + // the polygon doesnt intersect, the original pgn1, pgn2 contain the union + return (false); +} + +template +inline bool +_join(const Pgn1& pgn1, + const Pgn2& pgn2, + typename Gps_default_traits::Traits::Polygon_with_holes_2& res) +{ + typename Gps_default_traits::Traits tr; + return (_join(pgn1, pgn2, res, tr)); +} + +//@} +/// \name _difference() functions. +//@{ + +template +inline OutputIterator _difference(const Pgn1& pgn1, + const Pgn2& pgn2, + OutputIterator oi, + Traits& tr) +{ + General_polygon_set_2 gps(tr); + gps.insert(pgn1); + gps.difference(pgn2); + return (gps.polygons_with_holes(oi)); +} + +template +inline OutputIterator _difference(const Pgn1& pgn1, + const Pgn2& pgn2, + OutputIterator oi) +{ + typename Gps_default_traits::Traits tr; + return(_difference(pgn1, pgn2, oi, tr)); +} + +//@} +/// \name _symmetric_difference() functions. +//@{ + +template +inline OutputIterator _symmetric_difference(const Pgn1& pgn1, + const Pgn2& pgn2, + OutputIterator oi, + Traits& tr) +{ + General_polygon_set_2 gps(tr); + gps.insert(pgn1); + gps.symmetric_difference(pgn2); + return (gps.polygons_with_holes(oi)); +} + +template +inline OutputIterator _symmetric_difference(const Pgn1& pgn1, + const Pgn2& pgn2, + OutputIterator oi) +{ + typename Gps_default_traits::Traits tr; + return (_symmetric_difference(pgn1, pgn2, oi, tr)); +} + +//@} +/// \name _complement() functions. +//@{ + +template +void _complement(const Pgn& pgn, + typename Traits::Polygon_with_holes_2& res, + Traits& tr) +{ + General_polygon_set_2 gps(tr); + gps.insert(pgn); + gps.complement(); + Oneset_iterator oi(res); + gps.polygons_with_holes(oi); + +} + +template +void _complement(const Pgn& pgn, + typename Gps_default_traits::Traits:: + Polygon_with_holes_2& res) +{ + typename Gps_default_traits::Traits tr; + _complement(pgn, res, tr); +} + +//@} + +CGAL_END_NAMESPACE + +#endif