From 0626eb0a2eec65f3dcbe1bcf974080ecef5923a7 Mon Sep 17 00:00:00 2001 From: Efi Fogel Date: Thu, 11 Jun 2020 12:32:33 +0300 Subject: [PATCH] First stage elliminating CGAL::Object --- .../Arr_extended_rational_arc_traits_d_1.h | 21 +- .../include/CGAL/Arr_rational_arc_traits_2.h | 19 +- .../tests/TestAlgebraic.cpp | 90 +++--- .../tests/TestRayPL.cpp | 33 +-- .../CGAL/Arr_polycurve_traits_2.h | 14 +- .../include/CGAL/Arr_Bezier_curve_traits_2.h | 33 +-- .../include/CGAL/Arr_accessor.h | 20 +- .../CGAL/Arr_algebraic_segment_traits_2.h | 259 +++++++++--------- .../include/CGAL/Arr_batched_point_location.h | 8 +- .../Arr_bounded_planar_topology_traits_2.h | 12 +- .../CGAL/Arr_circle_segment_traits_2.h | 88 +++--- .../CGAL/Arr_circular_line_arc_traits_2.h | 1 + .../include/CGAL/Arr_conic_traits_2.h | 20 +- .../include/CGAL/Arr_curve_data_traits_2.h | 17 +- .../Arr_geodesic_arc_on_sphere_traits_2.h | 15 +- .../Bezier_bounding_rational_traits.h | 42 ++- .../include/CGAL/Arr_linear_traits_2.h | 7 +- .../CGAL/Arr_non_caching_segment_traits_2.h | 8 +- .../Arr_landmarks_pl_impl.h | 17 +- .../Arr_simple_point_location_impl.h | 15 +- .../include/CGAL/Arr_point_location_result.h | 22 +- .../include/CGAL/Arr_polycurve_traits_2.h | 29 +- .../CGAL/Arr_rational_function_traits_2.h | 33 ++- .../include/CGAL/Arr_segment_traits_2.h | 12 +- .../include/CGAL/Arr_tracing_traits_2.h | 15 +- .../Arrangement_2/Arr_compute_zone_visitor.h | 88 +++--- .../Arrangement_on_surface_2_global.h | 75 ++--- ...ltered_curved_kernel_via_analysis_2_impl.h | 10 +- .../Arr_basic_insertion_traits_2.h | 1 - .../Arr_batched_pl_ss_visitor.h | 1 - .../Traits_base_test.h | 1 - .../Arrangement_on_surface_2/test_zone.cpp | 20 +- 32 files changed, 504 insertions(+), 542 deletions(-) diff --git a/Arrangement_on_surface_2/archive/include/CGAL/Arr_extended_rational_arc_traits_d_1.h b/Arrangement_on_surface_2/archive/include/CGAL/Arr_extended_rational_arc_traits_d_1.h index a4c447248b1..dbf564f5005 100644 --- a/Arrangement_on_surface_2/archive/include/CGAL/Arr_extended_rational_arc_traits_d_1.h +++ b/Arrangement_on_surface_2/archive/include/CGAL/Arr_extended_rational_arc_traits_d_1.h @@ -660,23 +660,33 @@ public: return Equal_2(_traits); } - /*! A functor that divides a curve into continues (x-monotone) curves. */ + //! A functor for subdividing curves into x-monotone curves. class Make_x_monotone_2 { private: Traits& _traits; + public: Make_x_monotone_2(Traits& traits) : _traits(traits) {} - template - OutputIterator operator() (const Curve_2& cv, OutputIterator oi) const + + /*! Subdivide a given curve into x-monotone subcurves and insert them into + * a given output iterator. + * \param cv the curve. + * \param oi an output iterator for the result. Its value type is a variant + * that wraps Point_2 or an X_monotone_curve_2 objects. + * \return The past-the-end iterator. + */ + template + OutputIterator operator()(const Curve_2& cv, OutputIterator oi) const { Object_vector res (boost::apply_visitor(Make_x_monotone_2_visitor(_traits),cv.variant())); re_cast_object_vector(res,oi); return (oi); } + private: - class Make_x_monotone_2_visitor - : public boost::static_visitor < Object_vector > + class Make_x_monotone_2_visitor : + public boost::static_visitor < Object_vector > { private: typedef boost::static_visitor Base; @@ -1787,4 +1797,3 @@ public: #endif // CGAL_DONT_SUBMIT #endif //CGAL_ARR_RATIONAL_ARC_TRAITS_D_1_H - diff --git a/Arrangement_on_surface_2/archive/include/CGAL/Arr_rational_arc_traits_2.h b/Arrangement_on_surface_2/archive/include/CGAL/Arr_rational_arc_traits_2.h index cd8d80f962f..2c25299c59b 100644 --- a/Arrangement_on_surface_2/archive/include/CGAL/Arr_rational_arc_traits_2.h +++ b/Arrangement_on_surface_2/archive/include/CGAL/Arr_rational_arc_traits_2.h @@ -80,7 +80,7 @@ public: Arr_rational_arc_traits_2 () {} - /// \name Functor definitions. + /// \name Basic functor definitions. //@{ /*! A functor that compares the x-coordinates of two points */ @@ -381,19 +381,22 @@ public: { return Equal_2(); } + //@} + + //! \name Intersections, subdivisions, and mergings + //@{ /*! A functor that divides a curve into continues (x-monotone) curves. */ class Make_x_monotone_2 { public: - /*! - * Cut the given conic curve (or conic arc) into x-monotone subcurves - * and insert them to the given output iterator. - * \param cv The curve. - * \param oi The output iterator, whose value-type is Object. The returned - * objects is a wrapper for an X_monotone_curve_2 object. - * \return The past-the-end iterator. + /*! Subdivide a given rational arc into x-monotone subcurves and insert them + * into a given output iterator. + * \param cv the arc. + * \param oi an output iterator for the result. Its value type is a variant + * that wraps Point_2 or an X_monotone_curve_2 objects. + * \return the past-the-end iterator. */ template OutputIterator operator() (const Curve_2& cv, OutputIterator oi) diff --git a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/tests/TestAlgebraic.cpp b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/tests/TestAlgebraic.cpp index 41acec251bb..dbe9e2dd917 100644 --- a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/tests/TestAlgebraic.cpp +++ b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/tests/TestAlgebraic.cpp @@ -25,26 +25,26 @@ typedef CGAL::Curved_kernel_via_analysis_2< Algebraic_kernel_d_2 > CKvA_2; Polynomial_2 makeParabola( ) { - Polynomial_2 x = CGAL::shift( Polynomial_2( 1 ), 1, 0 ); - Polynomial_2 y = CGAL::shift( Polynomial_2( 1 ), 1, 1 ); - Polynomial_2 parabola = y - x*x; + Polynomial_2 x = CGAL::shift( Polynomial_2( 1 ), 1, 0 ); + Polynomial_2 y = CGAL::shift( Polynomial_2( 1 ), 1, 1 ); + Polynomial_2 parabola = y - x*x; - return parabola; + return parabola; } X_monotone_curve_2 makeVerticalLine( Bound x ) { - Traits traits; - Traits::Construct_point_2 constructPoint = - traits.construct_point_2_object( ); - Traits::Construct_x_monotone_segment_2 constructSegment = - traits.construct_x_monotone_segment_2_object( ); + Traits traits; + Traits::Construct_point_2 constructPoint = + traits.construct_point_2_object( ); + Traits::Construct_x_monotone_segment_2 constructSegment = + traits.construct_x_monotone_segment_2_object( ); - std::vector< X_monotone_curve_2 > curves; - Point_2 p1 = constructPoint( Algebraic_real_1(x), Algebraic_real_1(Bound( -10000 )) ); - Point_2 p2 = constructPoint( x, Bound( +10000 ) ); - constructSegment( p1, p2, std::back_inserter( curves ) ); - return curves[ 0 ]; + std::vector< X_monotone_curve_2 > curves; + Point_2 p1 = constructPoint( Algebraic_real_1(x), Algebraic_real_1(Bound( -10000 )) ); + Point_2 p2 = constructPoint( x, Bound( +10000 ) ); + constructSegment( p1, p2, std::back_inserter( curves ) ); + return curves[ 0 ]; } typedef CGAL::Cartesian< Coefficient > Kernel; @@ -52,40 +52,38 @@ typedef Kernel::Point_2 Kernel_point_2; int main( ) { - Algebraic_real_1 real( 1 ); - //CGAL::Qt::Converter< Algebraic_kernel_d_2 > testConverter; - //CGAL::Qt::Converter< CKvA_2 > testConverter; + Algebraic_real_1 real( 1 ); + //CGAL::Qt::Converter< Algebraic_kernel_d_2 > testConverter; + //CGAL::Qt::Converter< CKvA_2 > testConverter; - //CGAL::Qt::Converter< Cartesian > testConverter; - Kernel_point_2 testPt( 1, 2 ); - Point_2 testPt2( testPt.x( ), testPt.y( ) ); - Traits traits; - Construct_curve_2 constructCurve = traits.construct_curve_2_object( ); - Curve_2 curve = constructCurve( makeParabola( ) ); - Make_x_monotone_2 mm = traits.make_x_monotone_2_object( ); - std::vector< CGAL::Object > curves; - mm( curve, std::back_inserter( curves ) ); - std::cout << curves.size( ) << std::endl; - X_monotone_curve_2 c1; - CGAL::assign( c1, curves[ 0 ] ); - double lb = -3; - double ub = 3; - double step = 6.0 / 1000; + //CGAL::Qt::Converter< Cartesian > testConverter; + Kernel_point_2 testPt( 1, 2 ); + Point_2 testPt2( testPt.x( ), testPt.y( ) ); + Traits traits; + Construct_curve_2 constructCurve = traits.construct_curve_2_object( ); + Curve_2 curve = constructCurve( makeParabola( ) ); + Make_x_monotone_2 mm = traits.make_x_monotone_2_object( ); + std::vector< CGAL::Object > curves; + mm( curve, std::back_inserter( curves ) ); + std::cout << curves.size( ) << std::endl; + X_monotone_curve_2 c1; + CGAL::assign( c1, curves[ 0 ] ); + double lb = -3; + double ub = 3; + double step = 6.0 / 1000; - for ( int i = 0; i < 1000; ++i ) - { - X_monotone_curve_2 c2 = makeVerticalLine( lb + step * i ); + for ( int i = 0; i < 1000; ++i ) { + X_monotone_curve_2 c2 = makeVerticalLine( lb + step * i ); - CGAL::Object o; - CGAL::Oneset_iterator< CGAL::Object > oi( o ); - Intersect_2 intersect = traits.intersect_2_object( ); - intersect( c1, c2, oi ); - std::pair< Point_2, Multiplicity > res; - CGAL::assign( res, o ); - std::pair< double, double > approx = res.first.to_double( ); - std::cout << approx.first << " " << approx.second << std::endl; - } + CGAL::Object o; + CGAL::Oneset_iterator< CGAL::Object > oi( o ); + Intersect_2 intersect = traits.intersect_2_object( ); + intersect( c1, c2, oi ); + std::pair< Point_2, Multiplicity > res; + CGAL::assign( res, o ); + std::pair< double, double > approx = res.first.to_double( ); + std::cout << approx.first << " " << approx.second << std::endl; + } - - return 0; + return 0; } diff --git a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/tests/TestRayPL.cpp b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/tests/TestRayPL.cpp index e2be25f6b52..120fdf7beea 100644 --- a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/tests/TestRayPL.cpp +++ b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/tests/TestRayPL.cpp @@ -6,28 +6,29 @@ #include #include -typedef CGAL::Gmpq NT; -typedef CGAL::Cartesian< NT > Kernel; -typedef CGAL::Arr_linear_traits_2< Kernel > Traits; -typedef CGAL::Arr_default_dcel< Traits > Dcel; -typedef CGAL::Arrangement_with_history_2< Traits, Dcel > Arrangement; -typedef CGAL::Arr_walk_along_line_point_location< Arrangement > WalkAlongLinePointLocationStrategy; -typedef Kernel::Point_2 Point_2; -typedef Kernel::Ray_2 Ray_2; -typedef Arrangement::Curve_2 Curve_2; +typedef CGAL::Gmpq NT; +typedef CGAL::Cartesian Kernel; +typedef CGAL::Arr_linear_traits_2 Traits; +typedef CGAL::Arr_default_dcel Dcel; +typedef CGAL::Arrangement_with_history_2< Traits, Dcel> Arrangement; +typedef CGAL::Arr_walk_along_line_point_location + Walk_along_line_pl; +typedef Kernel::Point_2 Point_2; +typedef Kernel::Ray_2 Ray_2; +typedef Arrangement::Curve_2 Curve_2; int main( ) { - Point_2 p1( 0, 0 ); - Point_2 p2( 1, 0 ); - Ray_2 ray( p1, p2 ); - Curve_2 curve( ray ); + Point_2 p1(0, 0); + Point_2 p2(1, 0); + Ray_2 ray(p1, p2); + Curve_2 curve(ray); Arrangement arr; - CGAL::insert( arr, curve ); + CGAL::insert(arr, curve); - WalkAlongLinePointLocationStrategy pl( arr ); - CGAL::Object o = pl.locate( Point_2( 1, -1 ) ); + Walk_along_line_pl pl(arr); + auto o = pl.locate(Point_2(1, -1)); return 0; } diff --git a/Arrangement_on_surface_2/doc/Arrangement_on_surface_2/CGAL/Arr_polycurve_traits_2.h b/Arrangement_on_surface_2/doc/Arrangement_on_surface_2/CGAL/Arr_polycurve_traits_2.h index fc41e4c1f97..16788a94596 100644 --- a/Arrangement_on_surface_2/doc/Arrangement_on_surface_2/CGAL/Arr_polycurve_traits_2.h +++ b/Arrangement_on_surface_2/doc/Arrangement_on_surface_2/CGAL/Arr_polycurve_traits_2.h @@ -239,19 +239,17 @@ namespace CGAL { const Point_2& tgt) const; }; - /*! Subdivide the given subcurve into x-monotone subcurves and insert them - * into the given output iterator. Since the subcurves that - * constitute a general polycurve are not necessarily - * \f$x\f$-monotone, this functor may break them. + /*! Subdivide a given subcurve into x-monotone subcurves and insert them + * into a given output iterator. */ class Make_x_monotone_2 { public: /*! * \pre if `cv` is not empty then it must be continuous and well-oriented. - * \param cv The subcurve. - * \param oi The output iterator, whose value-type is Object. The output - * object is a wrapper of a X_monotone_curve_2 objects. - * \return The past-the-end iterator. + * \param cv the subcurve. + * \param oi an output iterator for the result. Its value type is a variant + * that wraps Point_2 or an X_monotone_curve_2 objects. + * \return the past-the-end iterator. */ template OutputIterator operator()(const Curve_2& cv, OutputIterator oi) const; diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_Bezier_curve_traits_2.h b/Arrangement_on_surface_2/include/CGAL/Arr_Bezier_curve_traits_2.h index 36b46416572..2bb51edf525 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_Bezier_curve_traits_2.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_Bezier_curve_traits_2.h @@ -7,9 +7,9 @@ // $Id$ // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial // -// Author(s) : Ron Wein -// Iddo Hanniel -// Waqar Khan +// Author(s): Ron Wein +// Iddo Hanniel +// Waqar Khan #ifndef CGAL_ARR_BEZIER_CURVE_TRAITS_2_H #define CGAL_ARR_BEZIER_CURVE_TRAITS_2_H @@ -163,7 +163,7 @@ public: } //@} - /// \name Functor definitions for the arrangement traits. + /// \name Basic functor definitions for the arrangement traits //@{ /*! \class Compare_x_2 @@ -473,31 +473,33 @@ public: { return (Equal_2 (p_cache)); } + //@} + + //! \name Intersections, subdivisions, and mergings + //@{ /*! \class Make_x_monotone_2 - * The Make_x_monotone_2 functor. + * A functor for subdividing curves into x-monotone curves. */ class Make_x_monotone_2 { private: - Bezier_cache *p_cache; + Bezier_cache* p_cache; public: - /*! Constructor. */ Make_x_monotone_2 (Bezier_cache *cache) : p_cache (cache) {} - /*! - * Cut the given Bezier curve into x-monotone subcurves and insert them - * into the given output iterator. - * \param cv The curve. - * \param oi The output iterator, whose value-type is Object. The returned - * objects is a wrapper for an X_monotone_curve_2 object. - * \return The past-the-end iterator. + /*! Subdivide a given Bezier curve into x-monotone subcurves and insert them + * into a given output iterator. + * \param cv the curve. + * \param oi an output iterator for the result. Its value type is a variant + * that wraps Point_2 or an X_monotone_curve_2 objects. + * \return the past-the-end iterator. */ - template + template OutputIterator operator() (const Curve_2& B, OutputIterator oi) const { typedef typename Bounding_traits::Vertical_tangency_point @@ -756,7 +758,6 @@ public: { return Merge_2(this); } - //@} /// \name Functor definitions for the Boolean set-operation traits. diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_accessor.h b/Arrangement_on_surface_2/include/CGAL/Arr_accessor.h index 0397cd07f67..25aba48cefd 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_accessor.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_accessor.h @@ -22,6 +22,7 @@ */ #include +#include namespace CGAL { @@ -99,13 +100,16 @@ public: * This object may wrap a Face_const_handle (the general case), * or a Halfedge_const_handle (in case of an overlap). */ - CGAL::Object locate_curve_end(const X_monotone_curve_2& cv, - Arr_curve_end ind, - Arr_parameter_space ps_x, - Arr_parameter_space ps_y) const + typedef Arr_point_location_result Pl_result; + typename Pl_result::type locate_curve_end(const X_monotone_curve_2& cv, + Arr_curve_end ind, + Arr_parameter_space ps_x, + Arr_parameter_space ps_y) const { CGAL_precondition((ps_x != ARR_INTERIOR) || (ps_y != ARR_INTERIOR)); + typedef Arr_point_location_result Pl_result; + // Use the topology traits to locate the unbounded curve end. CGAL::Object obj = p_arr->topology_traits()->locate_curve_end(cv, ind, ps_x, ps_y); @@ -113,19 +117,19 @@ public: // Return a handle to the DCEL feature. DFace* f; if (CGAL::assign(f, obj)) - return (CGAL::make_object(p_arr->_const_handle_for(f))); + return (Pl_result::make_result(p_arr->_const_handle_for(f))); DHalfedge* he; if (CGAL::assign(he, obj)) - return (CGAL::make_object(p_arr->_const_handle_for(he))); + return (Pl_result::make_result(p_arr->_const_handle_for(he))); DVertex* v; if (CGAL::assign(v, obj)) - return (CGAL::make_object(p_arr->_const_handle_for(v))); + return (Pl_result::make_result(p_arr->_const_handle_for(v))); // We should never reach here: CGAL_error(); - return Object(); + return Pl_result::make_result(Vertex_const_handle()); } /*! diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_algebraic_segment_traits_2.h b/Arrangement_on_surface_2/include/CGAL/Arr_algebraic_segment_traits_2.h index 5a3384145d2..243320b5ed7 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_algebraic_segment_traits_2.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_algebraic_segment_traits_2.h @@ -264,138 +264,143 @@ public: } - template OutputIterator - x_monotone_segment (Curve_2 cv, - Point_2 p, - boost::optional start, - boost::optional end, - OutputIterator out) const { + template OutputIterator + x_monotone_segment(Curve_2 cv, + Point_2 p, + boost::optional start, + boost::optional end, + OutputIterator out) const + { + typedef boost::variant + Make_x_monotone_result; + //CGAL_assertion(is_one_one(cv,p)); - //CGAL_assertion(is_one_one(cv,p)); + std::list segs; - std::list segs; - - Is_on_2 on_arc - = this->_ckva()->is_on_2_object(); - Construct_min_vertex_2 left - = this->_ckva()->construct_min_vertex_2_object(); - Construct_max_vertex_2 right - = this->_ckva()->construct_max_vertex_2_object(); - Equal_2 equal = this->_ckva()->equal_2_object(); - - std::vector arcs; - this->_ckva()->make_x_monotone_2_object() - (cv,std::back_inserter(arcs)); - typename std::vector::const_iterator - it = arcs.begin(),helper; - X_monotone_curve_2 it_seg; - CGAL::assign(it_seg,*it); - while(it!=arcs.end()) { - if( on_arc(p,it_seg) ) { - break; - } - CGAL_assertion(it!=arcs.end()); - it++; - CGAL::assign(it_seg,*it); - } - - bool left_on_arc = start && on_arc(start.get(),it_seg); - bool right_on_arc = end && on_arc(end.get(),it_seg); - - if( left_on_arc && right_on_arc ) { - segs.push_back(it_seg.trim(start.get(),end.get())); - } - if(left_on_arc && (!right_on_arc)) { - if(!it_seg.is_finite(CGAL::ARR_MAX_END) || - !equal(start.get(),right(it_seg))) { - if(it_seg.is_finite(CGAL::ARR_MIN_END) && equal(start.get(),left(it_seg))) { - segs.push_back(it_seg); - } else { - X_monotone_curve_2 split1,split2; - it_seg.split(start.get(),split1,split2); - segs.push_back(split2); - } - } - } - if((!left_on_arc) && right_on_arc) { - if(!it_seg.is_finite(CGAL::ARR_MIN_END) || - ! equal(left(it_seg),end.get())) { - if(it_seg.is_finite(CGAL::ARR_MAX_END) && equal(end.get(),right(it_seg))) { - segs.push_back(it_seg); - } else { - X_monotone_curve_2 split1,split2; - it_seg.split(end.get(),split1,split2); - segs.push_back(split1); - } - } - } - if( (!left_on_arc) && (!right_on_arc)) { - segs.push_back(it_seg); - } - helper=it; // for later usage - - if(! left_on_arc) { - - Point_2 point_it; - while(true) { - if(it_seg.is_finite(CGAL::ARR_MIN_END) && - is_one_one(cv,left(it_seg) ) ) { - point_it=left(it_seg); - } else { - CGAL_assertion(! start); - break; - } - CGAL_assertion(it!=arcs.begin()); - it--; - CGAL::assign(it_seg,*it); - while(! on_arc(point_it,it_seg)) { - CGAL_assertion(it!=arcs.begin()); - it--; - CGAL::assign(it_seg,*it); - } - if(start && on_arc(start.get(),it_seg)) { - segs.push_front(it_seg.trim(start.get(), - right(it_seg))); - break; - } else { - segs.push_front(it_seg); - } - } - } - if(! right_on_arc) { - it=helper; // reset - CGAL::assign(it_seg,*it); - Point_2 point_it; - while(true) { - if(it_seg.is_finite(CGAL::ARR_MAX_END) && - is_one_one(cv,right(it_seg) ) ) { - point_it=right(it_seg); - } else { - CGAL_assertion(! end); - break; - } - it++; - CGAL_assertion(it!=arcs.end()); - CGAL::assign(it_seg,*it); - while(! on_arc(point_it,it_seg)) { - it++; - CGAL_assertion(it!=arcs.end()); - CGAL::assign(it_seg,*it); - } - if(end && on_arc(end.get(),it_seg)) { - segs.push_back(it_seg.trim(left(it_seg),end.get())); - break; - } else { - segs.push_back(it_seg); - } - } - } - - std::copy(segs.begin(),segs.end(),out); - return out; + Is_on_2 on_arc = this->_ckva()->is_on_2_object(); + auto left = this->_ckva()->construct_min_vertex_2_object(); + auto right = this->_ckva()->construct_max_vertex_2_object(); + Equal_2 equal = this->_ckva()->equal_2_object(); + std::vector arcs; + this->_ckva()->make_x_monotone_2_object()(cv, std::back_inserter(arcs)); + typename std::vector::const_iterator it = arcs.begin(); + typename std::vector::const_iterator helper; + X_monotone_curve_2 it_seg; + CGAL::assign(it_seg, *it); + while (it != arcs.end()) { + if ( on_arc(p,it_seg) ) break; + CGAL_assertion(it != arcs.end()); + it++; + CGAL::assign(it_seg, *it); } + bool left_on_arc = start && on_arc(start.get(), it_seg); + bool right_on_arc = end && on_arc(end.get(), it_seg); + + if ( left_on_arc && right_on_arc ) { + segs.push_back(it_seg.trim(start.get(),end.get())); + } + if (left_on_arc && (!right_on_arc)) { + if (!it_seg.is_finite(CGAL::ARR_MAX_END) || + !equal(start.get(),right(it_seg))) { + if (it_seg.is_finite(CGAL::ARR_MIN_END) && + equal(start.get(),left(it_seg))) + { + segs.push_back(it_seg); + } + else { + X_monotone_curve_2 split1,split2; + it_seg.split(start.get(),split1,split2); + segs.push_back(split2); + } + } + } + if ((!left_on_arc) && right_on_arc) { + if (!it_seg.is_finite(CGAL::ARR_MIN_END) || + ! equal(left(it_seg), end.get())) + { + if (it_seg.is_finite(CGAL::ARR_MAX_END) && + equal(end.get(), right(it_seg))) + { + segs.push_back(it_seg); + } + else { + X_monotone_curve_2 split1,split2; + it_seg.split(end.get(), split1, split2); + segs.push_back(split1); + } + } + } + if ( (!left_on_arc) && (!right_on_arc)) { + segs.push_back(it_seg); + } + helper = it; // for later usage + + if (! left_on_arc) { + + Point_2 point_it; + while (true) { + if (it_seg.is_finite(CGAL::ARR_MIN_END) && + is_one_one(cv, left(it_seg) ) ) { + point_it = left(it_seg); + } else { + CGAL_assertion(! start); + break; + } + CGAL_assertion(it != arcs.begin()); + it--; + CGAL::assign(it_seg, *it); + while (! on_arc(point_it, it_seg)) { + CGAL_assertion(it != arcs.begin()); + it--; + CGAL::assign(it_seg,*it); + } + if (start && on_arc(start.get(),it_seg)) { + segs.push_front(it_seg.trim(start.get(), right(it_seg))); + break; + } + else { + segs.push_front(it_seg); + } + } + } + if (! right_on_arc) { + it = helper; // reset + CGAL::assign(it_seg,*it); + Point_2 point_it; + while (true) { + if (it_seg.is_finite(CGAL::ARR_MAX_END) && + is_one_one(cv,right(it_seg) ) ) + { + point_it=right(it_seg); + } else { + CGAL_assertion(! end); + break; + } + it++; + CGAL_assertion(it != arcs.end()); + CGAL::assign(it_seg, *it); + while(! on_arc(point_it, it_seg)) { + it++; + CGAL_assertion(it != arcs.end()); + CGAL::assign(it_seg, *it); + } + if(end && on_arc(end.get(),it_seg)) { + segs.push_back(it_seg.trim(left(it_seg),end.get())); + break; + } + else { + segs.push_back(it_seg); + } + } + } + + std::copy(segs.begin(), segs.end(), out); + return out; + + } + public: template OutputIterator diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_batched_point_location.h b/Arrangement_on_surface_2/include/CGAL/Arr_batched_point_location.h index e526a7ae2b9..af328f1d6e6 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_batched_point_location.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_batched_point_location.h @@ -41,11 +41,9 @@ namespace Ss2 = Surface_sweep_2; * \param oi Output: An output iterator for the query results. * \pre The value-type of PointsIterator is Arrangement::Point_2, * and the value-type of OutputIterator is is pair, - * where Result is either - * (i) Object or - * (ii) boost::optional >. + * where Result is boost::optional >. * It represents the arrangement feature containing the point. */ template - OutputIterator operator() (const Curve_2& cv, OutputIterator oi) const + template + OutputIterator operator()(const Curve_2& cv, OutputIterator oi) const { // Increment the serial number of the curve cv, which will serve as its // unique identifier. - unsigned int index = 0; - if(m_use_cache) - index = Self::get_index(); + unsigned int index = 0; + if (m_use_cache) index = Self::get_index(); - if (cv.orientation() == COLLINEAR) - { + if (cv.orientation() == COLLINEAR) { // The curve is a line segment. - *oi = make_object (X_monotone_curve_2 (cv.supporting_line(), + *oi++ = make_object(X_monotone_curve_2(cv.supporting_line(), cv.source(), cv.target(), index)); - ++oi; - return (oi); + return oi; } // Check the case of a degenrate circle (a point). @@ -425,12 +420,10 @@ public: CGAL::Sign sign_rad = CGAL::sign (circ.squared_radius()); CGAL_precondition (sign_rad != NEGATIVE); - if (sign_rad == ZERO) - { + if (sign_rad == ZERO) { // Create an isolated point. - *oi = make_object (Point_2 (circ.center().x(), circ.center().y())); - ++oi; - return (oi); + *oi++ = make_object(Point_2 (circ.center().x(), circ.center().y())); + return oi; } // The curve is circular: compute the to vertical tangency points @@ -438,76 +431,63 @@ public: Point_2 vpts[2]; unsigned int n_vpts = cv.vertical_tangency_points (vpts); - if (cv.is_full()) - { + if (cv.is_full()) { CGAL_assertion (n_vpts == 2); // Subdivide the circle into two arcs (an upper and a lower half). - *oi = make_object (X_monotone_curve_2 (circ, + *oi++ = make_object(X_monotone_curve_2(circ, vpts[0], vpts[1], cv.orientation(), index)); - ++oi; - *oi = make_object (X_monotone_curve_2 (circ, + *oi++ = make_object(X_monotone_curve_2(circ, vpts[1], vpts[0], cv.orientation(), index)); - ++oi; } - else - { + else { // Act according to the number of vertical tangency points. - if (n_vpts == 2) - { + if (n_vpts == 2) { // Subdivide the circular arc into three x-monotone arcs. - *oi = make_object (X_monotone_curve_2 (circ, + *oi++ = make_object(X_monotone_curve_2(circ, cv.source(), vpts[0], cv.orientation(), index)); - ++oi; - *oi = make_object (X_monotone_curve_2 (circ, + *oi++ = make_object(X_monotone_curve_2(circ, vpts[0], vpts[1], cv.orientation(), index)); - ++oi; - *oi = make_object (X_monotone_curve_2 (circ, + *oi++ = make_object(X_monotone_curve_2(circ, vpts[1], cv.target(), cv.orientation(), index)); - ++oi; } - else if (n_vpts == 1) - { + else if (n_vpts == 1) { // Subdivide the circular arc into two x-monotone arcs. - *oi = make_object (X_monotone_curve_2 (circ, + *oi++ = make_object(X_monotone_curve_2(circ, cv.source(), vpts[0], cv.orientation(), index)); - ++oi; - *oi = make_object (X_monotone_curve_2 (circ, + *oi++ = make_object(X_monotone_curve_2(circ, vpts[0], cv.target(), cv.orientation(), index)); - ++oi; } - else - { - CGAL_assertion (n_vpts == 0); + else { + CGAL_assertion(n_vpts == 0); // The arc is already x-monotone: - *oi = make_object (X_monotone_curve_2 (circ, + *oi++ = make_object(X_monotone_curve_2(circ, cv.source(), cv.target(), cv.orientation(), index)); - ++oi; } } - return (oi); + return oi; } }; diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_circular_line_arc_traits_2.h b/Arrangement_on_surface_2/include/CGAL/Arr_circular_line_arc_traits_2.h index eb9acae74a8..e9dba84c472 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_circular_line_arc_traits_2.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_circular_line_arc_traits_2.h @@ -259,6 +259,7 @@ namespace CGAL { }; + //! A functor for subdividing curves into x-monotone curves. template class Make_x_monotone_2 { diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_conic_traits_2.h b/Arrangement_on_surface_2/include/CGAL/Arr_conic_traits_2.h index cc26c045a84..6511b422b23 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_conic_traits_2.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_conic_traits_2.h @@ -448,24 +448,24 @@ public: } //@} - /// \name Functor definitions for supporting intersections. + /// \name Intersections, subdivisions, and mergings //@{ + //! A functor for subdividing curves into x-monotone curves. class Make_x_monotone_2 { typedef Arr_conic_traits_2 Self; - public: - /*! - * Cut the given conic curve (or conic arc) into x-monotone subcurves - * and insert them to the given output iterator. - * \param cv The curve. - * \param oi The output iterator, whose value-type is Object. The returned - * objects are all wrappers X_monotone_curve_2 objects. - * \return The past-the-end iterator. + public: + /*! Subdivide a given conic curve (or conic arc) into x-monotone subcurves + * and insert them to a given output iterator. + * \param cv the curve. + * \param oi an output iterator for the result. Its value type is a variant + * that wraps Point_2 or an X_monotone_curve_2 objects. + * \return the past-the-end iterator. */ template - OutputIterator operator() (const Curve_2& cv, OutputIterator oi) const + OutputIterator operator()(const Curve_2& cv, OutputIterator oi) const { // Increment the serial number of the curve cv, which will serve as its // unique identifier. diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_curve_data_traits_2.h b/Arrangement_on_surface_2/include/CGAL/Arr_curve_data_traits_2.h index 7ed8e459334..b74f5d4d734 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_curve_data_traits_2.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_curve_data_traits_2.h @@ -101,6 +101,10 @@ public: /// \name Overriden functors. //@{ + //! \name Intersections & subdivisions + //@{ + + //! A functor for subdividing curves into x-monotone curves. class Make_x_monotone_2 { private: const Base_traits_2& m_base; @@ -109,12 +113,13 @@ public: /*! Constructor. */ Make_x_monotone_2(const Base_traits_2& base) : m_base(base) {} - /*! Cut the given curve into x-monotone subcurves and insert them to the - * given output iterator. As segments are always x_monotone, only one + /*! Subdivide a given curve into x-monotone subcurves and insert them into + * a given output iterator. As segments are always x_monotone, only one * x-monotone curve will be contained in the iterator. - * \param cv The curve. - * \param oi The output iterator, whose value-type is X_monotone_curve_2. - * \return The past-the-end iterator. + * \param cv the curve. + * \param oi an output iterator for the result. Its value type is a variant + * that wraps Point_2 or an X_monotone_curve_2 objects. + * \return the past-the-end iterator. */ template OutputIterator operator()(const Curve_2& cv, OutputIterator oi) const @@ -359,6 +364,8 @@ public: /*! Obtain a Merge_2 functor object. */ Merge_2 merge_2_object() const { return Merge_2(*this); } + //@} + class Construct_x_monotone_curve_2 { private: const Base_traits_2& m_base; diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_geodesic_arc_on_sphere_traits_2.h b/Arrangement_on_surface_2/include/CGAL/Arr_geodesic_arc_on_sphere_traits_2.h index 6ccd5d249bc..d0816e1477a 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_geodesic_arc_on_sphere_traits_2.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_geodesic_arc_on_sphere_traits_2.h @@ -1358,8 +1358,8 @@ public: /// \name Functor definitions for supporting intersections. //@{ - /*! A functor that divides an arc into x-monotone arcs. That are, arcs that - * do not cross the identification arc. + /*! Subdivide an arc into x-monotone arcs, that are, arcs that do not cross + * the identification arc. */ class Make_x_monotone_2 { protected: @@ -1376,13 +1376,12 @@ public: friend class Arr_geodesic_arc_on_sphere_traits_2; public: - /*! Cut the given curve into x-monotone subcurves and insert them into the - * given output iterator. As spherical_arcs are always x_monotone, only one - * object will be contained in the iterator. + /*! Subdivide a given curve into x-monotone subcurves and insert them into + * a given output iterator. As spherical_arcs are always x_monotone, only + * one object will be contained in the iterator. * \param xc the curve. - * \param oi the output iterator, whose value-type is Object. The output - * object is a wrapper of either an X_monotone_curve_2, or - in - * case the input spherical_arc is degenerate - a Point_2 object. + * \param oi an output iterator for the result. Its value type is a variant + * that wraps Point_2 or an X_monotone_curve_2 objects. * \return the past-the-end iterator. */ template diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_geometry_traits/Bezier_bounding_rational_traits.h b/Arrangement_on_surface_2/include/CGAL/Arr_geometry_traits/Bezier_bounding_rational_traits.h index 761710d8a89..bc7831ee95f 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_geometry_traits/Bezier_bounding_rational_traits.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_geometry_traits/Bezier_bounding_rational_traits.h @@ -1262,36 +1262,26 @@ private: // the intersection of the two skewed bounding boxes. Bez_point_bbox ipt_bbox; Control_points aux_vec; - CGAL::Object res; - Point_2 p; - res = f_intersect (skew1a, skew2a); - if (! assign (p, res)) - { - CGAL_error(); - } - aux_vec.push_back(p); + auto res1 = f_intersect(skew1a, skew2a); + const Point_2* p1 = boost::get(&*res1); + if (! p1) CGAL_error(); + aux_vec.push_back(*p1); - res = f_intersect (skew1a, skew2b); - if (! assign(p, res)) - { - CGAL_error(); - } - aux_vec.push_back(p); + auto res2 = f_intersect(skew1a, skew2b); + const Point_2* p2 = boost::get(&*res2); + if (! p2) CGAL_error(); + aux_vec.push_back(*p2); - res = f_intersect (skew1b, skew2a); - if (! assign(p, res)) - { - CGAL_error(); - } - aux_vec.push_back(p); + auto res3 = f_intersect(skew1b, skew2a); + const Point_2* p3 = boost::get(&*res3); + if (! p3) CGAL_error(); + aux_vec.push_back(*p3); - res = f_intersect (skew1b, skew2b); - if (!assign(p, res)) - { - CGAL_error(); - } - aux_vec.push_back(p); + auto res4 = f_intersect (skew1b, skew2b); + const Point_2* p4 = boost::get(&*res4); + if (! p4) CGAL_error(); + aux_vec.push_back(*p4); construct_bbox (aux_vec, ipt_bbox); diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_linear_traits_2.h b/Arrangement_on_surface_2/include/CGAL/Arr_linear_traits_2.h index 0e1262db0ec..6914625130b 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_linear_traits_2.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_linear_traits_2.h @@ -1239,9 +1239,10 @@ public: * given output iterator. As segments are always x_monotone, only one * object will be contained in the iterator. * \param cv The curve. - * \param oi The output iterator, whose value-type is Object. The output - * object is a wrapper of an X_monotone_curve_2 which is - * essentially the same as the input curve. + * \param oi The output iterator, whose value-type is a variant of either + * Point_2 or X_monotone_curve_2. The output object is a wrapper + * of an X_monotone_curve_2 which is essentially the same as the + * input curve. * \return The past-the-end iterator. */ template diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_non_caching_segment_traits_2.h b/Arrangement_on_surface_2/include/CGAL/Arr_non_caching_segment_traits_2.h index 3df642ba1e7..e9f0e8b40dc 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_non_caching_segment_traits_2.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_non_caching_segment_traits_2.h @@ -122,10 +122,10 @@ public: /*! Cut the given segment into x-monotone subcurves and insert them into * the given output iterator. As segments are always x_monotone, only one * x-monotone curve is inserted into the output iterator. - * \param cv The segment. - * \param oi The output iterator, whose value-type is Object. The output - * object is a wrapper of an X_monotone_curve_2 object. - * \return The past-the-end iterator. + * \param cv the segment. + * \param oi an output iterator for the result. Its value type is a variant + * that wraps Point_2 or an X_monotone_curve_2 objects. + * \return the past-the-end iterator. */ template OutputIterator operator()(const Curve_2& cv, OutputIterator oi) const diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Arr_landmarks_pl_impl.h b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Arr_landmarks_pl_impl.h index eb9679a8883..0a6fbc736b7 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Arr_landmarks_pl_impl.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Arr_landmarks_pl_impl.h @@ -56,15 +56,15 @@ Arr_landmarks_point_location::locate(const Point_2& p) const const Vertex_const_handle* vh; const Halfedge_const_handle* hh; const Face_const_handle* fh; - if ( ( vh = Result().template assign(lm_location_obj) ) ) + if ( ( vh = Result().template assign(&lm_location_obj) ) ) out_obj = _walk_from_vertex(*vh, p, crossed_edges); - else if ( ( hh = Result().template assign(lm_location_obj) ) ) + else if ( ( hh = Result().template assign(&lm_location_obj) ) ) out_obj = _walk_from_edge(*hh, landmark_point, p, crossed_edges); - else if ( ( fh = Result().template assign(lm_location_obj) ) ) + else if ( ( fh = Result().template assign(&lm_location_obj) ) ) out_obj = _walk_from_face(*fh, landmark_point, p, crossed_edges); else CGAL_error_msg("lm_location_obj of an unknown type."); - if ( ( fh = Result().template assign(out_obj) ) ) { + if ( ( fh = Result().template assign(&out_obj) ) ) { // If we reached here, we did not locate the query point in any of the // holes inside the current face, so we conclude it is contained in this // face. @@ -159,7 +159,7 @@ _walk_from_vertex(Vertex_const_handle nearest_vertex, if (new_vertex) { // We found a vertex closer to p; Continue using this vertex. const Vertex_const_handle* p_vh = - Result().template assign(obj); + Result().template assign(&obj); CGAL_assertion(p_vh != nullptr); vh = *p_vh; continue; @@ -167,11 +167,12 @@ _walk_from_vertex(Vertex_const_handle nearest_vertex, // If p is located on an edge or on a vertex, return the object // that wraps this arrangement feature. - if (Result().template assign(obj) || - Result().template assign(obj)) + if (Result().template assign(&obj) || + Result().template assign(&obj)) return obj; - const Face_const_handle* p_fh = Result().template assign(obj); + const Face_const_handle* p_fh = + Result().template assign(&obj); if (p_fh) // Walk to p from the face we have located: return _walk_from_face(*p_fh, vh->point(), p, crossed_edges); diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Arr_simple_point_location_impl.h b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Arr_simple_point_location_impl.h index 6b0820da97e..a5980967cb4 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Arr_simple_point_location_impl.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Arr_simple_point_location_impl.h @@ -44,10 +44,8 @@ Arr_simple_point_location::locate(const Point_2& p) const // Go over arrangement halfedges and check whether one of them contains // the query point in its interior. - typename Traits_adaptor_2::Is_in_x_range_2 is_in_x_range = - m_geom_traits->is_in_x_range_2_object(); - typename Traits_adaptor_2::Compare_y_at_x_2 cmp_y_at_x = - m_geom_traits->compare_y_at_x_2_object(); + auto is_in_x_range = m_geom_traits->is_in_x_range_2_object(); + auto cmp_y_at_x = m_geom_traits->compare_y_at_x_2_object(); typename Arrangement::Edge_const_iterator eit; for (eit = m_arr->edges_begin(); eit != m_arr->edges_end(); ++eit) { @@ -71,14 +69,14 @@ Arr_simple_point_location::locate(const Point_2& p) const // In case the ray-shooting returned a vertex, we have to locate the first // halfedge whose source vertex is v, rotating clockwise around the vertex // from "6 o'clock", and to return its incident face. - const Vertex_const_handle* vh = Result().template assign(obj); + const auto* vh = Result::template assign(&obj); if (vh) { Halfedge_const_handle hh = _first_around_vertex(*vh); Face_const_handle fh = hh->face(); return make_result(fh); } - const Halfedge_const_handle* hh = Result().template assign(obj); + const auto* hh = Result::template assign(&obj); if (hh) { // Make sure that the edge is directed from right to left, so that p // (which lies below it) is contained in its incident face. If necessary, @@ -288,14 +286,13 @@ Arr_simple_point_location::_vertical_ray_shoot(const Point_2& p, if (! optional_empty(optional_obj)) { const Result_type& obj = optional_assign(optional_obj); - const Vertex_const_handle* p_vh = Result().template assign(obj); + const auto* p_vh = Result::template assign(&obj); if (p_vh) { found_vertex = true; closest_v = *p_vh; } else { - const Halfedge_const_handle* p_hh = - Result().template assign(obj); + const auto* p_hh = Result::template assign(&obj); CGAL_assertion(p_hh != nullptr); found_halfedge = true; closest_he = *p_hh; diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_point_location_result.h b/Arrangement_on_surface_2/include/CGAL/Arr_point_location_result.h index 33aeb50201b..1fae9de1d30 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_point_location_result.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_point_location_result.h @@ -78,32 +78,34 @@ struct Arr_point_location_result { // lead to conversion overhead, and so we rather go for the real type. // Overloads for empty returns are also provided. #if CGAL_ARR_POINT_LOCATION_VERSION < 2 - template + template static - inline CGAL::Object make_result(T t) { return CGAL::make_object(t); } + inline Type make_result(T t) { return CGAL::make_object(t); } static inline CGAL::Object empty_optional_result() { return CGAL::Object(); } - template - const T* assign(CGAL::Object obj) const { return CGAL::object_cast(&obj); } + template + static + inline const T* assign(const Type* obj) { return CGAL::object_cast(obj); } #else - template + template static inline Type make_result(T t) { return Type(t); } - inline static - boost::optional empty_optional_result() { return boost::optional(); } + inline boost::optional empty_optional_result() + { return boost::optional(); } - template - const T* assign(const Type& obj) const { return boost::get(&obj); } + template + static + inline const T* assign(const Type* obj) { return boost::get(obj); } #endif // CGAL_ARR_POINT_LOCATION_VERSION < 2 //this one is only to remove warnings in functions static inline Type default_result(){ - CGAL_error_msg("This functions should never have been called!"); + CGAL_error_msg("This functions should have never been called!"); return Type(); } }; diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_polycurve_traits_2.h b/Arrangement_on_surface_2/include/CGAL/Arr_polycurve_traits_2.h index 6d61db9e61e..eaf9ff4150d 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_polycurve_traits_2.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_polycurve_traits_2.h @@ -7,10 +7,10 @@ // $Id$ // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial // -// Author(s) : Efi Fogel -// Ron Wein -// Dror Atariah -// Waqar Khan +// Author(s): Efi Fogel +// Ron Wein +// Dror Atariah +// Waqar Khan #ifndef CGAL_ARR_POLYCURVE_TRAITS_2_H #define CGAL_ARR_POLYCURVE_TRAITS_2_H @@ -160,10 +160,8 @@ public: #ifndef DOXYGEN_RUNNING class Push_back_2; #endif - /*! \class - * A functor that divides an arc into x-monotone arcs. That are, arcs that - * do not cross the identification arc. - */ + + //! A functor for subdividing curves into x-monotone curves. class Make_x_monotone_2 { protected: typedef Arr_polycurve_traits_2 Polycurve_traits_2; @@ -176,14 +174,14 @@ public: m_poly_traits(traits) {} - /*! Cut the given curve into x-monotone sub-curves and insert them into the - * given output iterator. + /*! Subdivide a given curve into x-monotone sub-curves and insert them into + * a given output iterator. * * \pre if `cv` is not empty then it must be continuous and well-oriented. - * \param cv The curve. - * \param oi The output iterator, whose value-type is Object. The output - * object is a wrapper of a X_monotone_curve_2. - * \return The past-the-end iterator. + * \param cv the curve. + * \param oi an output iterator for the result. Its value type is a variant + * that wraps Point_2 or an X_monotone_curve_2 objects. + * \return the past-the-end iterator. */ private: template @@ -476,7 +474,8 @@ public: x_seg_objects.clear(); return oi; } -public: + + public: template OutputIterator operator()(const Curve_2& cv, OutputIterator oi) const { return operator_impl(cv, oi, Are_all_sides_oblivious_tag()); } diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_rational_function_traits_2.h b/Arrangement_on_surface_2/include/CGAL/Arr_rational_function_traits_2.h index bff77f5f588..029914aedfb 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_rational_function_traits_2.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_rational_function_traits_2.h @@ -808,37 +808,34 @@ public: return Equal_2(this); } + //! \name Intersections & subdivisions + //@{ + /*! A functor that divides a curve into continues (x-monotone) curves. */ class Make_x_monotone_2 { public: - /*! - * Cut the given conic curve (or conic arc) into x-monotone subcurves - * and insert them to the given output iterator. - * \param cv The curve. - * \param oi The output iterator, whose value-type is Object. The returned - * objects is a wrapper for an X_monotone_curve_2 object. - * \return The past-the-end iterator. + /*! Subdivide a given rational-function curve into x-monotone subcurves + * and insert them to a given output iterator. + * \param cv the curve. + * \param oi an output iterator for the result. Its value type is a variant + * that wraps Point_2 or X_monotone_curve_2 objects. + * \return the past-the-end iterator. */ - template + template OutputIterator operator()(const Curve_2& cv, OutputIterator oi) const { // Make the rational arc continuous. - std::list arcs; + std::list arcs; cv.make_continuous(std::back_inserter(arcs)); // Create objects. - typename std::list::const_iterator iter; + for (auto it = arcs.begin(); it != arcs.end(); ++it) + *oi++ = make_object(*it); - for (iter = arcs.begin(); iter != arcs.end(); ++iter) - { - *oi = make_object (*iter); - ++oi; - } - - return (oi); + return oi; } }; @@ -975,6 +972,8 @@ public: return Merge_2(this); } + //@} + /// \name Functor definitions to handle boundaries //@{ diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_segment_traits_2.h b/Arrangement_on_surface_2/include/CGAL/Arr_segment_traits_2.h index a671a741f80..e8d4ab62cfb 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_segment_traits_2.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_segment_traits_2.h @@ -609,16 +609,18 @@ public: Equal_2 equal_2_object() const { return Equal_2(*this); } //@} - /// \name Functor definitions for supporting intersections. + //! \name Intersections, subdivisions, and mergings //@{ + //! A functor for subdividing curves into x-monotone curves. class Make_x_monotone_2 { public: - /*! Cut the given curve into x-monotone subcurves and insert them into the - * given output iterator. As segments are always x_monotone, only one + /*! Subdivide a given curve into x-monotone subcurves and insert them into + * a given output iterator. As segments are always x_monotone, only one * object will be contained in the iterator. - * \param cv The curve. - * \param oi The output iterator, whose value-type is variant<.... + * \param cv the curve. + * \param oi an output iterator for the result. Its value type is a variant + * that wraps Point_2 or an X_monotone_curve_2 objects. * \return The past-the-end iterator. */ template diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_tracing_traits_2.h b/Arrangement_on_surface_2/include/CGAL/Arr_tracing_traits_2.h index 5847dd43e02..fccfb3327ed 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_tracing_traits_2.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_tracing_traits_2.h @@ -504,7 +504,10 @@ public: } }; - /*! A functor that divides a curve into x-monotone curves. */ + //! \name Intersections & subdivisions + //@{ + + //! A functor for subdividing curves into x-monotone curves. class Make_x_monotone_2 { private: typename Base::Make_x_monotone_2 m_object; @@ -516,12 +519,12 @@ public: m_object(base->make_x_monotone_2_object()), m_enabled(enabled) {} /*! Operate - * \param cv the curve - * \param oi an output iterator that contains the result. It's value - * type is CGAL::Object, which wraps either an x-monotone curve or a point - * \return the output iterator + * \param cv the curve. + * \param oi an output iterator for the result. Its value type is a variant + * that wraps Point_2 or X_monotone_curve_2 objects. + * \return the output iterator. */ - template + template OutputIterator operator()(const Curve_2 & cv, OutputIterator oi) const { if (!m_enabled) return m_object(cv, oi); diff --git a/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arr_compute_zone_visitor.h b/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arr_compute_zone_visitor.h index b32ffa842c9..1d6bc8b97cd 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arr_compute_zone_visitor.h +++ b/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arr_compute_zone_visitor.h @@ -8,27 +8,29 @@ // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial // // -// Author(s) : Ophir Setter +// Author(s) : Ophir Setter +// Efi Fogel // #ifndef CGAL_ARR_COMPUTE_ZONE_VISITOR_H #define CGAL_ARR_COMPUTE_ZONE_VISITOR_H #include - /*! \file * Definition of the Arr_compute_zone_visitor class. */ +#include + namespace CGAL { /*! \class - * A visitor class for Arrangement_zone_2, which outputs the - * zone of an x-monotone curve. Meaning, it output the arrangment's - * vertices, edges and faces that the x-monotone curve intersects. + * A visitor class for Arrangement_zone_2 that outputs the zone of an + * x-monotone curve. Specifically, it outputs handles to the the arrangment + * cells that the x-monotone curve intersects. * The class should be templated by an Arrangement_2 class, and by an - * output iterator of CGAL Objects, where we store all arrangement - * features the x-monotone curve intersects. + * output iterator of a variant of types of handles to the arrangement cells + * that appear in the zone, namely, vertex, halfedge, and face handles. */ template class Arr_compute_zone_visitor @@ -53,7 +55,7 @@ private: const Vertex_handle invalid_v; // Invalid vertex. OutputIterator& out_iter; // for outputing the zone objects. - // Its value type is CGAL::Object. + // Its value type is boost::variant. bool output_left; // Determines wheter we should // output the left end point of a // subcurve (to avoid outputing @@ -65,8 +67,8 @@ public: Arr_compute_zone_visitor (OutputIterator& oi) : invalid_he(), invalid_v(), - out_iter (oi), - output_left (true) + out_iter(oi), + output_left(true) {} /*! Initialize the visitor. */ @@ -90,50 +92,35 @@ public: * \return A handle to the halfedge obtained from the insertion of the * subcurve into the arrangement. */ - Result found_subcurve (const X_monotone_curve_2&, - Face_handle face, - Vertex_handle left_v, Halfedge_handle left_he, - Vertex_handle right_v, Halfedge_handle right_he) + Result found_subcurve(const X_monotone_curve_2&, + Face_handle face, + Vertex_handle left_v, Halfedge_handle left_he, + Vertex_handle right_v, Halfedge_handle right_he) { - if (output_left) - { + typedef boost::variant + Zone_result; + + if (output_left) { // Only the first subcurve should output the arrangement feature incident // to its left endpoint. This way we avoid reporting the same feature // twice. - if (left_v != invalid_v) - { - *out_iter = CGAL::make_object (left_v); - ++out_iter; - } - else if (left_he != invalid_he) - { - *out_iter = CGAL::make_object (left_he); - ++out_iter; - } + if (left_v != invalid_v) *out_iter++ = Zone_result(left_v); + else if (left_he != invalid_he) *out_iter++ = Zone_result(left_he); output_left = false; } // Report the face that contains the interior of the subcurve. - *out_iter = CGAL::make_object (face); - ++out_iter; + *out_iter++ = Zone_result(face); // If the right endpoint of the subcurve is incident to an arrangement // vertex or an arrangement edge, report this feature. - if (right_v != invalid_v) - { - *out_iter = CGAL::make_object(right_v); - ++out_iter; - } - else if (right_he != invalid_he) - { - *out_iter = CGAL::make_object(right_he); - ++out_iter; - } + if (right_v != invalid_v) *out_iter++ = Zone_result(right_v); + else if (right_he != invalid_he) *out_iter++ = Zone_result(right_he); // We did not modify the arrangement, so we return an invalid handle // and a flag indicating that the zone-computation process should continue. - return (Result (invalid_he, false)); + return Result(invalid_he, false); } /*! @@ -151,35 +138,28 @@ public: Halfedge_handle he, Vertex_handle left_v, Vertex_handle right_v) { - if (output_left) - { + typedef boost::variant + Zone_result; + + if (output_left) { // Only the first subcurve should output the arrangement feature incident // to its left endpoint. This way we avoid reporting the same feature // twice. - if (left_v != invalid_v) - { - *out_iter = CGAL::make_object (left_v); - ++out_iter; - } + if (left_v != invalid_v) *out_iter++ = Zone_result(left_v); output_left = false; } // Report the arrangement edge the curve currently overlaps. - *out_iter = CGAL::make_object(he); - ++out_iter; + *out_iter++ = Zone_result(he); // If the right endpoint of the overlapping subcurve is incident to an // arrangement vertex, report this vertex as well. - if (right_v != invalid_v) - { - *out_iter = CGAL::make_object (right_v); - ++out_iter; - } + if (right_v != invalid_v) *out_iter++ = Zone_result(right_v); // We did not modify the arrangement, so we return an invalid handle // and a flag indicating that the zone-computation process should continue. - return (Result (invalid_he, false)); + return Result(invalid_he, false); } }; diff --git a/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_on_surface_2_global.h b/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_on_surface_2_global.h index 73fcc93fccc..cf6255b4930 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_on_surface_2_global.h +++ b/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_on_surface_2_global.h @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -89,7 +90,6 @@ void insert(Arrangement_on_surface_2& arr, // Break the input curve into x-monotone subcurves and isolated points. std::list x_objects; - std::list::const_iterator obj_iter; const typename Gt2::X_monotone_curve_2* x_curve; const typename Gt2::Point_2* iso_p; @@ -97,9 +97,9 @@ void insert(Arrangement_on_surface_2& arr, make_x_monotone_2_object()(c, std::back_inserter(x_objects)); // Insert each x-monotone curve into the arrangement. - for (obj_iter = x_objects.begin(); obj_iter != x_objects.end(); ++obj_iter) { + for (auto it = x_objects.begin(); it != x_objects.end(); ++it) { // Act according to the type of the current object. - x_curve = object_cast(&(*obj_iter)); + x_curve = object_cast(&(*it)); if (x_curve != nullptr) { // Inserting an x-monotone curve: @@ -118,7 +118,7 @@ void insert(Arrangement_on_surface_2& arr, arr_access.notify_after_global_change(); } else { - iso_p = object_cast(&(*obj_iter)); + iso_p = object_cast(&(*it)); CGAL_assertion(iso_p != nullptr); // Inserting a point into the arrangement: @@ -658,6 +658,7 @@ insert_non_intersecting_curve Traits_adaptor_2; typedef typename Arr::Vertex_const_handle Vertex_const_handle; typedef typename Arr::Halfedge_const_handle Halfedge_const_handle; + typedef typename Arr::Face_const_handle Face_const_handle; CGAL_USE_TYPE(Halfedge_const_handle); const Traits_adaptor_2* geom_traits = @@ -666,13 +667,13 @@ insert_non_intersecting_curve // Check whether the left end has boundary conditions, and locate it in the // arrangement accordingly. - const Arr_parameter_space bx1 = - geom_traits->parameter_space_in_x_2_object()(c, ARR_MIN_END); - const Arr_parameter_space by1 = - geom_traits->parameter_space_in_y_2_object()(c, ARR_MIN_END); - CGAL::Object obj1; + auto bx1 = geom_traits->parameter_space_in_x_2_object()(c, ARR_MIN_END); + auto by1 = geom_traits->parameter_space_in_y_2_object()(c, ARR_MIN_END); const Vertex_const_handle* vh1 = nullptr; + typedef Arr_point_location_result Pl_result; + + typename Pl_result::type obj1; if ((bx1 == ARR_INTERIOR) && (by1 == ARR_INTERIOR)) { // We have a normal left endpoint with no boundary conditions: // use a point-location query. @@ -680,33 +681,26 @@ insert_non_intersecting_curve // The endpoint must not lie on an existing edge, but may coincide with // and existing vertex vh1. - CGAL_precondition_msg - (object_cast(&obj1) == nullptr, - "The curve must not intersect an existing edge."); + CGAL_precondition_msg(boost::get(&obj1) == nullptr, + "The curve must not intersect an existing edge."); - vh1 = object_cast(&obj1); } else { // We have a left end with boundary conditions. Use the accessor to locate // the feature that contains it. obj1 = arr_access.locate_curve_end(c, ARR_MIN_END, bx1, by1); - - CGAL_precondition_msg - (object_cast(&obj1) == nullptr, - "The curve must not overlap an existing edge."); - - vh1 = object_cast(&obj1); + CGAL_precondition_msg(boost::get(&obj1) == nullptr, + "The curve must not overlap an existing edge."); } + vh1 = Pl_result::template assign(&obj1); // Check whether the right end has boundary conditions, and locate it in the // arrangement accordingly. - const Arr_parameter_space bx2 = - geom_traits->parameter_space_in_x_2_object()(c, ARR_MAX_END); - const Arr_parameter_space by2 = - geom_traits->parameter_space_in_y_2_object()(c, ARR_MAX_END); - CGAL::Object obj2; + auto bx2 = geom_traits->parameter_space_in_x_2_object()(c, ARR_MAX_END); + auto by2 = geom_traits->parameter_space_in_y_2_object()(c, ARR_MAX_END); const Vertex_const_handle* vh2 = nullptr; + typename Pl_result::type obj2; if ((bx2 == ARR_INTERIOR) && (by2 == ARR_INTERIOR)) { // We have a normal right endpoint with no boundary conditions: // use a point-location query. @@ -714,11 +708,8 @@ insert_non_intersecting_curve // The endpoint must not lie on an existing edge, but may coincide with // and existing vertex vh2. - CGAL_precondition_msg - (object_cast(&obj2) == nullptr, - "The curve must not intersect an existing edge."); - - vh2 = object_cast(&obj2); + CGAL_precondition_msg(boost::get(&obj2) == nullptr, + "The curve must not intersect an existing edge."); } else { // We have a right end with boundary conditions. Use the accessor to locate @@ -728,13 +719,10 @@ insert_non_intersecting_curve // << ", by2: " << by2 // << std::endl; obj2 = arr_access.locate_curve_end(c, ARR_MAX_END, bx2, by2); - - CGAL_precondition_msg - (object_cast(&obj2) == nullptr, - "The curve must not overlap an existing edge."); - - vh2 = object_cast(&obj2); + CGAL_precondition_msg(boost::get(&obj2) == nullptr, + "The curve must not overlap an existing edge."); } + vh2 = Pl_result::template assign(&obj2); // Notify the arrangement observers that a global operation is about to // take place. @@ -776,10 +764,8 @@ insert_non_intersecting_curve // we must insert the curve in the interior of a face. // In this case insert_in_face_interior() already returns a halfedge // directed from left to right. - const typename Arr::Face_const_handle* fh1 = - object_cast(&obj1); - const typename Arr::Face_const_handle* fh2 = - object_cast(&obj2); + const Face_const_handle* fh1 = boost::get(&obj1); + const Face_const_handle* fh2 = boost::get(&obj2); // std::cout << arr << std::endl; // std::cout << "(*fh1)->number_of_outer_ccbs(): " @@ -1147,7 +1133,7 @@ insert_point(Arrangement_on_surface_2& arr, typename Arr::Vertex_handle vh_for_p; // Locate the given point in the arrangement. - CGAL::Object obj = pl.locate (p); + CGAL::Object obj = pl.locate(p); // Notify the arrangement observers that a global operation is about to // take place. @@ -1615,28 +1601,27 @@ do_intersect(Arrangement_on_surface_2& arr, static_cast(arr.geometry_traits()); std::list x_objects; - std::list::const_iterator obj_iter; const typename Gt2::X_monotone_curve_2* x_curve; const typename Gt2::Point_2* iso_p; traits->make_x_monotone_2_object()(c, std::back_inserter(x_objects)); // Insert each x-monotone curve into the arrangement. - for (obj_iter = x_objects.begin(); obj_iter != x_objects.end(); ++obj_iter) { + for (auto it = x_objects.begin(); it != x_objects.end(); ++it) { // Act according to the type of the current object. - x_curve = object_cast(&(*obj_iter)); + x_curve = object_cast(&(*it)); if (x_curve != nullptr) { // Check if the x-monotone subcurve intersects the arrangement. if (do_intersect(arr, *x_curve, pl) == true) return true; } else { - iso_p = object_cast(&(*obj_iter)); + iso_p = object_cast(&(*it)); CGAL_assertion(iso_p != nullptr); // Check whether the isolated point lies inside a face (otherwise, // it conincides with a vertex or an edge). - CGAL::Object obj = pl.locate (*iso_p); + auto obj = pl.locate(*iso_p); return (object_cast(&obj) != nullptr); } diff --git a/Arrangement_on_surface_2/include/CGAL/Curved_kernel_via_analysis_2/Filtered_curved_kernel_via_analysis_2_impl.h b/Arrangement_on_surface_2/include/CGAL/Curved_kernel_via_analysis_2/Filtered_curved_kernel_via_analysis_2_impl.h index 38c8eda3412..dcd4bb372a0 100644 --- a/Arrangement_on_surface_2/include/CGAL/Curved_kernel_via_analysis_2/Filtered_curved_kernel_via_analysis_2_impl.h +++ b/Arrangement_on_surface_2/include/CGAL/Curved_kernel_via_analysis_2/Filtered_curved_kernel_via_analysis_2_impl.h @@ -169,12 +169,10 @@ public: Coordinate_1 asym_info1, asym_info2; CGAL::Arr_parameter_space ps1, ps2; - obj1 = cv1.curve().asymptotic_value_of_arc( - cv1.location(ce), cv1.arcno() - ); - obj2 = cv2.curve().asymptotic_value_of_arc( - cv2.location(ce), cv2.arcno() - ); + obj1 = + cv1.curve().asymptotic_value_of_arc(cv1.location(ce), cv1.arcno()); + obj2 = + cv2.curve().asymptotic_value_of_arc(cv2.location(ce), cv2.arcno()); CGAL::Comparison_result filter_res = CGAL::EQUAL; diff --git a/Arrangement_on_surface_2/include/CGAL/Surface_sweep_2/Arr_basic_insertion_traits_2.h b/Arrangement_on_surface_2/include/CGAL/Surface_sweep_2/Arr_basic_insertion_traits_2.h index 970f6a45227..ffa3d6eea01 100644 --- a/Arrangement_on_surface_2/include/CGAL/Surface_sweep_2/Arr_basic_insertion_traits_2.h +++ b/Arrangement_on_surface_2/include/CGAL/Surface_sweep_2/Arr_basic_insertion_traits_2.h @@ -23,7 +23,6 @@ * Defintion of the Arr_basic_insertion_traits_2 class. */ -#include #include #include diff --git a/Arrangement_on_surface_2/include/CGAL/Surface_sweep_2/Arr_batched_pl_ss_visitor.h b/Arrangement_on_surface_2/include/CGAL/Surface_sweep_2/Arr_batched_pl_ss_visitor.h index 4bd9e6acdff..e562f2be4ee 100644 --- a/Arrangement_on_surface_2/include/CGAL/Surface_sweep_2/Arr_batched_pl_ss_visitor.h +++ b/Arrangement_on_surface_2/include/CGAL/Surface_sweep_2/Arr_batched_pl_ss_visitor.h @@ -23,7 +23,6 @@ */ #include -#include #include #include diff --git a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Traits_base_test.h b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Traits_base_test.h index 1d95d3eefef..0ac8100431c 100644 --- a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Traits_base_test.h +++ b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Traits_base_test.h @@ -13,7 +13,6 @@ #include #include -#include #include #include #include diff --git a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/test_zone.cpp b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/test_zone.cpp index 7595a3e305a..54291b4bf5a 100644 --- a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/test_zone.cpp +++ b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/test_zone.cpp @@ -8,13 +8,17 @@ #include #include -typedef CGAL::Quotient Number_type; -typedef CGAL::Simple_cartesian Kernel; -typedef CGAL::Arr_segment_traits_2 Traits_2; -typedef Traits_2::Point_2 Point_2; -typedef Traits_2::X_monotone_curve_2 Segment_2; -typedef CGAL::Arrangement_2 Arrangement_2; -typedef Arrangement_2::Halfedge_handle Halfedge_handle; +typedef CGAL::Quotient Number_type; +typedef CGAL::Simple_cartesian Kernel; +typedef CGAL::Arr_segment_traits_2 Traits_2; +typedef Traits_2::Point_2 Point_2; +typedef Traits_2::X_monotone_curve_2 Segment_2; +typedef CGAL::Arrangement_2 Arrangement_2; +typedef Arrangement_2::Vertex_handle Vertex_handle; +typedef Arrangement_2::Halfedge_handle Halfedge_handle; +typedef Arrangement_2::Face_handle Face_handle; +typedef boost::variant + Zone_result; #define N_SEGMENTS 3 @@ -40,7 +44,7 @@ int main () for (k = 0; k < N_SEGMENTS; k++) { - std::list zone_elems; + std::list zone_elems; zone(arr, segs[k], std::back_inserter(zone_elems)); std::size_t zone_actual_comp = zone_elems.size();