diff --git a/.gitattributes b/.gitattributes index 35a3066ee9c..38320ad4f0b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,7 +5,7 @@ # to native line endings on checkout. *.cpp text *.c text -*.h text +*.h text linguist-language=C++ *.hpp text *.tex text *.txt text @@ -18,7 +18,6 @@ *.js text *.hmtl text *.bib text -*.sh text *.css text *.ui text *.qrc text @@ -29,13 +28,18 @@ *.xyz text *.qhcp text *.qhp text -*.pwn text +*.pwn text linguist-detectable=false *.poly text *.rb text *.perl text *.pdb text +# Nef_3 data files +*.EH linguist-detectable=false +*.SH linguist-detectable=false + # Declare files that will always have LF line endings on checkout. +*.sh text eol=lf Documentation/Doxyfile text eol=lf Documentation/pkglist_filter text eol=lf Installation/update_CHANGES text eol=lf diff --git a/.travis.yml b/.travis.yml index 67ef61cbf57..2c2fe62d3f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,10 +49,10 @@ env: - PACKAGE='Surface_mesh_parameterization Surface_mesh_segmentation Surface_mesh_shortest_path ' - PACKAGE='Surface_mesh_simplification Surface_mesh_skeletonization Surface_mesh_topology ' - PACKAGE='Surface_mesher Surface_sweep_2 TDS_2 ' - - PACKAGE='TDS_3 Testsuite Three ' - - PACKAGE='Triangulation Triangulation_2 Triangulation_3 ' - - PACKAGE='Union_find Visibility_2 Voronoi_diagram_2 ' - - PACKAGE='wininst ' + - PACKAGE='TDS_3 Testsuite Tetrahedral_remeshing ' + - PACKAGE='Three Triangulation Triangulation_2 ' + - PACKAGE='Triangulation_3 Union_find Visibility_2 ' + - PACKAGE='Voronoi_diagram_2 wininst ' compiler: clang install: - echo "$PWD" diff --git a/.travis/build_package.sh b/.travis/build_package.sh index 7fbe3c29aa2..cb046d1e29f 100755 --- a/.travis/build_package.sh +++ b/.travis/build_package.sh @@ -28,7 +28,7 @@ function build_demo { EXTRA_CXX_FLAGS="-Werror=inconsistent-missing-override" ;; esac - mytime cmake -DCGAL_DIR="/usr/local/lib/cmake/CGAL" -DCGAL_DONT_OVERRIDE_CMAKE_FLAGS:BOOL=ON -DCMAKE_CXX_FLAGS="${CXX_FLAGS} ${EXTRA_CXX_FLAGS}" .. + mytime cmake -DCGAL_DIR="/usr/local/lib/cmake/CGAL" -DCGAL_DONT_OVERRIDE_CMAKE_FLAGS:BOOL=ON -DCMAKE_CXX_FLAGS="${CXX_FLAGS} ${EXTRA_CXX_FLAGS}" .. mytime make -j2 VERBOSE=1 } old_IFS=$IFS @@ -57,41 +57,41 @@ cd $ROOT cd .. IFS=$old_IFS mytime zsh $ROOT/Scripts/developer_scripts/test_merge_of_branch HEAD - #test dependencies + #test dependencies cd $ROOT mytime bash Scripts/developer_scripts/cgal_check_dependencies.sh --check_headers /usr/bin/doxygen cd .travis - #parse current matrix and check that no package has been forgotten + #parse current matrix and check that no package has been forgotten - IFS=$'\n' - COPY=0 - MATRIX=() - for LINE in $(cat "$PWD/packages.txt") - do - MATRIX+="$LINE " - done - - PACKAGES=() - cd .. - for f in * - do - if [ -d "$f/package_info/$f" ] - then - PACKAGES+="$f " - fi - done - - DIFFERENCE=$(echo ${MATRIX[@]} ${PACKAGES[@]} | tr ' ' '\n' | sort | uniq -u) - IFS=$' ' - if [ "${DIFFERENCE[0]}" != "" ] - then - echo "The matrix and the actual package list differ : ." - echo ${DIFFERENCE[*]} + IFS=$'\n' + COPY=0 + MATRIX=() + for LINE in $(cat "$PWD/packages.txt") + do + MATRIX+="$LINE " + done + + PACKAGES=() + cd .. + for f in * + do + if [ -d "$f/package_info/$f" ] + then + PACKAGES+="$f " + fi + done + + DIFFERENCE=$(echo ${MATRIX[@]} ${PACKAGES[@]} | tr ' ' '\n' | sort | uniq -u) + IFS=$' ' + if [ "${DIFFERENCE[0]}" != "" ] + then + echo "The matrix and the actual package list differ : ." + echo ${DIFFERENCE[*]} echo "You should run generate_travis.sh." - exit 1 - fi - echo "Matrix is up to date." + exit 1 + fi + echo "Matrix is up to date." #check if non standard cgal installation works cd $ROOT mkdir build_test @@ -126,7 +126,7 @@ cd $ROOT fi IFS=$' ' EXAMPLES="$ARG/examples/$ARG" - TEST="$ARG/test/$ARG" + TEST="$ARG/test/$ARG" DEMOS=$ROOT/$ARG/demo/* if [ -d "$ROOT/$EXAMPLES" ] @@ -168,17 +168,17 @@ cd $ROOT for DEMO in $DEMOS; do DEMO=${DEMO#"$ROOT"} echo $DEMO - #If there is no demo subdir, try in GraphicsView + #If there is no demo subdir, try in GraphicsView if [ ! -d "$ROOT/$DEMO" ] || [ ! -f "$ROOT/$DEMO/CMakeLists.txt" ]; then DEMO="GraphicsView/demo/$ARG" fi - if [ "$ARG" != Polyhedron ] && [ -d "$ROOT/$DEMO" ] - then + if [ "$ARG" != Polyhedron ] && [ -d "$ROOT/$DEMO" ] + then cd $ROOT/$DEMO build_demo elif [ "$ARG" != Polyhedron_demo ]; then echo "No demo found for $ARG" - fi + fi done if [ "$ARG" = Polyhedron_demo ]; then DEMO=Polyhedron/demo/Polyhedron diff --git a/.travis/packages.txt b/.travis/packages.txt index 69e4f85c73a..6e75cd0ad14 100644 --- a/.travis/packages.txt +++ b/.travis/packages.txt @@ -129,6 +129,7 @@ Surface_sweep_2 TDS_2 TDS_3 Testsuite +Tetrahedral_remeshing Three Triangulation Triangulation_2 diff --git a/.travis/windows.h b/.travis/windows.h new file mode 100644 index 00000000000..a774a068df3 --- /dev/null +++ b/.travis/windows.h @@ -0,0 +1,12 @@ +#define MAX(a,b) (((a) > (b)) ? (a) : (b)) +#define max(a,b) (((a) > (b)) ? (a) : (b)) + +#define MIN(a,b) (((a) < (b)) ? (a) : (b)) +#define min(a,b) (((a) < (b)) ? (a) : (b)) + + +#define FAR #error named reserved in windows.h +#define far #error named reserved in windows.h + +#define Polyline #error named reserved in windows.h +#define Polygon #error named reserved in windows.h diff --git a/AABB_tree/demo/AABB_tree/Scene.cpp b/AABB_tree/demo/AABB_tree/Scene.cpp index b28368d39a6..69ba683a21b 100644 --- a/AABB_tree/demo/AABB_tree/Scene.cpp +++ b/AABB_tree/demo/AABB_tree/Scene.cpp @@ -45,8 +45,7 @@ Scene::Scene() m_blue_ramp.build_blue(); m_max_distance_function = (FT)0.0; texture = new Texture(m_grid_size,m_grid_size); - startTimer(0); - ready_to_cut = false; + ready_to_cut = true; are_buffers_initialized = false; gl_init = false; @@ -519,6 +518,7 @@ void Scene::changed() compute_elements(_UNSIGNED); else compute_elements(_SIGNED); + ready_to_cut=false; are_buffers_initialized = false; } @@ -1226,12 +1226,16 @@ void Scene::cut_segment_plane() m_cut_plane = CUT_SEGMENTS; changed(); } +void Scene::updateCutPlane() +{ + ready_to_cut = true; + QTimer::singleShot(0,this,SLOT(cutting_plane())); +} void Scene::cutting_plane(bool override) { if(ready_to_cut || override) { - ready_to_cut = false; switch( m_cut_plane ) { case UNSIGNED_FACETS: @@ -1304,13 +1308,13 @@ void Scene::refine_loop() void Scene::activate_cutting_plane() { - connect(m_frame, SIGNAL(modified()), this, SLOT(cutting_plane())); + connect(m_frame, SIGNAL(modified()), this, SLOT(updateCutPlane())); m_view_plane = true; } void Scene::deactivate_cutting_plane() { - disconnect(m_frame, SIGNAL(modified()), this, SLOT(cutting_plane())); + disconnect(m_frame, SIGNAL(modified()), this, SLOT(updateCutPlane())); m_view_plane = false; } void Scene::initGL() @@ -1326,10 +1330,3 @@ void Scene::initGL() compile_shaders(); gl_init = true; } - -void Scene::timerEvent(QTimerEvent *) -{ - if(manipulatedFrame()->isSpinning()) - set_fast_distance(true); - ready_to_cut = true; -} diff --git a/AABB_tree/demo/AABB_tree/Scene.h b/AABB_tree/demo/AABB_tree/Scene.h index 4e9fabd735b..95ea74cdc33 100644 --- a/AABB_tree/demo/AABB_tree/Scene.h +++ b/AABB_tree/demo/AABB_tree/Scene.h @@ -173,6 +173,8 @@ private: void attrib_buffers(CGAL::QGLViewer*); void compile_shaders(); void compute_texture(int, int, Color_ramp, Color_ramp); +private slots: + void updateCutPlane(); public: // file menu @@ -251,8 +253,6 @@ public: void activate_cutting_plane(); void deactivate_cutting_plane(); - //timer sends a top when all the events are finished - void timerEvent(QTimerEvent *); public slots: diff --git a/Advancing_front_surface_reconstruction/examples/Advancing_front_surface_reconstruction/reconstruction_structured.cpp b/Advancing_front_surface_reconstruction/examples/Advancing_front_surface_reconstruction/reconstruction_structured.cpp index d944cf985df..d2dda3af49c 100644 --- a/Advancing_front_surface_reconstruction/examples/Advancing_front_surface_reconstruction/reconstruction_structured.cpp +++ b/Advancing_front_surface_reconstruction/examples/Advancing_front_surface_reconstruction/reconstruction_structured.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -36,7 +37,7 @@ typedef CGAL::Triangulation_data_structure_3 Tds; typedef CGAL::Delaunay_triangulation_3 Triangulation_3; typedef Triangulation_3::Vertex_handle Vertex_handle; -typedef CGAL::cpp11::array Facet; +typedef std::array Facet; // Functor to init the advancing front algorithm with indexed points diff --git a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ArrangementDemoGraphicsView.cpp b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ArrangementDemoGraphicsView.cpp index 050a97e81df..cc08513c55b 100644 --- a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ArrangementDemoGraphicsView.cpp +++ b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ArrangementDemoGraphicsView.cpp @@ -22,8 +22,8 @@ ArrangementDemoGraphicsView::ArrangementDemoGraphicsView( QWidget* parent ) : gridColor( ::Qt::black ), backgroundColor( ::Qt::white ) { - QMatrix m( 1.0, 0.0, 0.0, -1.0, 0.0, 0.0 ); - this->setMatrix( m ); + QTransform m( 1.0, 0.0, 0.0, -1.0, 0.0, 0.0 ); + this->setTransform( m ); this->setBackgroundBrush( QBrush( backgroundColor ) ); } diff --git a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ArrangementDemoPropertiesDialog.h b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ArrangementDemoPropertiesDialog.h index 4e20f9c7835..dd6158edd48 100644 --- a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ArrangementDemoPropertiesDialog.h +++ b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ArrangementDemoPropertiesDialog.h @@ -43,7 +43,7 @@ class ArrangementDemoPropertiesDialog : public QDialog }; ArrangementDemoPropertiesDialog( ArrangementDemoWindow* parent_ = 0, - Qt::WindowFlags f = 0 ); + Qt::WindowFlags f = Qt::WindowType(0)); QVariant property( int index ); protected: diff --git a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/NewTabDialog.cpp b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/NewTabDialog.cpp index cf40a748f04..f0daef178fc 100644 --- a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/NewTabDialog.cpp +++ b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/NewTabDialog.cpp @@ -14,7 +14,7 @@ #include "ui_NewTabDialog.h" #include -NewTabDialog::NewTabDialog( QWidget* parent, Qt::WindowFlags f ) : +NewTabDialog::NewTabDialog( QWidget* parent, Qt::WindowFlags f) : QDialog( parent, f ), ui( new Ui::NewTabDialog ), buttonGroup( new QButtonGroup ) diff --git a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/NewTabDialog.h b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/NewTabDialog.h index 2121d5daac2..679f30a7887 100644 --- a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/NewTabDialog.h +++ b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/NewTabDialog.h @@ -23,7 +23,7 @@ namespace Ui class NewTabDialog : public QDialog { public: - NewTabDialog( QWidget* parent = 0, Qt::WindowFlags f = 0 ); + NewTabDialog( QWidget* parent = 0, Qt::WindowFlags f = Qt::WindowType(0) ); int checkedId( ) const; protected: diff --git a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/OverlayDialog.h b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/OverlayDialog.h index fc80dc35336..fb1c45ea1bb 100644 --- a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/OverlayDialog.h +++ b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/OverlayDialog.h @@ -29,7 +29,7 @@ class OverlayDialog : public QDialog ARRANGEMENT = 32 } OverlayDialogRole; - OverlayDialog( ArrangementDemoWindow* parent, Qt::WindowFlags f = 0 ); + OverlayDialog( ArrangementDemoWindow* parent, Qt::WindowFlags f = Qt::WindowType(0) ); std::vector< CGAL::Object > selectedArrangements( ) const; diff --git a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/VerticalRayShootCallback.h b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/VerticalRayShootCallback.h index 53cb0fcb76e..00b841f2d6f 100644 --- a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/VerticalRayShootCallback.h +++ b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/VerticalRayShootCallback.h @@ -127,7 +127,11 @@ protected: void highlightPointLocation( QGraphicsSceneMouseEvent *event ); Face_const_handle getFace( const CGAL::Object& o ); CGAL::Object rayShootUp( const Kernel_point_2& point ); + CGAL::Object rayShootUp( const Kernel_point_2& point, CGAL::Tag_true ); + CGAL::Object rayShootUp( const Kernel_point_2& point, CGAL::Tag_false ); CGAL::Object rayShootDown( const Kernel_point_2& point ); + CGAL::Object rayShootDown( const Kernel_point_2& point, CGAL::Tag_true ); + CGAL::Object rayShootDown( const Kernel_point_2& point, CGAL::Tag_false ); using Superclass::scene; using Superclass::shootingUp; @@ -304,6 +308,14 @@ VerticalRayShootCallback< Arr_ >::getFace( const CGAL::Object& obj ) template < typename Arr_ > CGAL::Object VerticalRayShootCallback< Arr_ >::rayShootUp( const Kernel_point_2& pt ) +{ + typename Supports_landmarks< Arrangement >::Tag supportsLandmarks; + return this->rayShootUp( pt, supportsLandmarks ); +} + +template < typename Arr_ > +CGAL::Object VerticalRayShootCallback< Arr_ >::rayShootUp( const Kernel_point_2& pt, + CGAL::Tag_true ) { CGAL::Object pointLocationResult; Walk_pl_strategy* walkStrategy; @@ -334,9 +346,48 @@ VerticalRayShootCallback< Arr_ >::rayShootUp( const Kernel_point_2& pt ) return pointLocationResult; } +template < typename Arr_ > +CGAL::Object VerticalRayShootCallback< Arr_ >::rayShootUp( const Kernel_point_2& pt, + CGAL::Tag_false ) +{ + CGAL::Object pointLocationResult; + Walk_pl_strategy* walkStrategy; + TrapezoidPointLocationStrategy* trapezoidStrategy; + SimplePointLocationStrategy* simpleStrategy; + + Point_2 point = this->toArrPoint( pt ); + + if ( CGAL::assign( walkStrategy, this->pointLocationStrategy ) ) + { + pointLocationResult = walkStrategy->ray_shoot_up( point ); + } + else if ( CGAL::assign( trapezoidStrategy, this->pointLocationStrategy ) ) + { + pointLocationResult = trapezoidStrategy->ray_shoot_up( point ); + } + else if ( CGAL::assign( simpleStrategy, this->pointLocationStrategy ) ) + { + pointLocationResult = simpleStrategy->ray_shoot_up( point ); + } + else + { + std::cout<<"Didn't find the right strategy\n"; + } + + return pointLocationResult; +} + template < typename Arr_ > CGAL::Object VerticalRayShootCallback< Arr_ >::rayShootDown( const Kernel_point_2& pt ) +{ + typename Supports_landmarks< Arrangement >::Tag supportsLandmarks; + return this->rayShootDown( pt, supportsLandmarks ); +} + +template < typename Arr_ > +CGAL::Object +VerticalRayShootCallback< Arr_ >::rayShootDown( const Kernel_point_2& pt, CGAL::Tag_true ) { CGAL::Object pointLocationResult; Walk_pl_strategy* walkStrategy; @@ -367,4 +418,30 @@ VerticalRayShootCallback< Arr_ >::rayShootDown( const Kernel_point_2& pt ) return pointLocationResult; } +template < typename Arr_ > +CGAL::Object +VerticalRayShootCallback< Arr_ >::rayShootDown( const Kernel_point_2& pt, CGAL::Tag_false ) +{ + CGAL::Object pointLocationResult; + Walk_pl_strategy* walkStrategy; + TrapezoidPointLocationStrategy* trapezoidStrategy; + SimplePointLocationStrategy* simpleStrategy; + + Point_2 point = this->toArrPoint( pt ); + + if ( CGAL::assign( walkStrategy, this->pointLocationStrategy ) ) + { + pointLocationResult = walkStrategy->ray_shoot_down( point ); + } + else if ( CGAL::assign( trapezoidStrategy, this->pointLocationStrategy ) ) + { + pointLocationResult = trapezoidStrategy->ray_shoot_down( point ); + } + else if ( CGAL::assign( simpleStrategy, this->pointLocationStrategy ) ) + { + pointLocationResult = simpleStrategy->ray_shoot_down( point ); + } + return pointLocationResult; +} + #endif // VERTICAL_RAY_SHOOT_CALLBACK_H diff --git a/Arrangement_on_surface_2/doc/Arrangement_on_surface_2/Concepts/ArrTraits--Intersect_2.h b/Arrangement_on_surface_2/doc/Arrangement_on_surface_2/Concepts/ArrTraits--Intersect_2.h index 3af9a106877..146eb151548 100644 --- a/Arrangement_on_surface_2/doc/Arrangement_on_surface_2/Concepts/ArrTraits--Intersect_2.h +++ b/Arrangement_on_surface_2/doc/Arrangement_on_surface_2/Concepts/ArrTraits--Intersect_2.h @@ -16,21 +16,19 @@ public: /// A model of this concept must provide: /// @{ -/*! -computes the intersections of `xc1` and `xc2` and -inserts them in an ascending lexicographic \f$ xy\f$-order into the -output iterator `oi`. The value-type of `Output_iterator` is -`CGAL::Object`, where each `Object` wraps either a -`pair` object, which -represents an intersection point with its multiplicity (in case the -multiplicity is undefined or unknown, it should be set to \f$ 0\f$) or an -`ArrTraits::X_monotone_curve_2` object, representing an -overlapping subcurve of `xc1` and `xc2`. The operator -returns a past-the-end iterator for the output sequence. -*/ -Output_iterator operator()(ArrTraits::X_monotone_curve_2 xc1, -ArrTraits::X_monotone_curve_2 xc2, -Output_iterator& oi); +/*! computes the intersections of `xc1` and `xc2` and inserts them in an + * ascending lexicographic \f$ xy\f$-order into a range begining at + * `oi`. The type `OutputIterator` dereferences a `boost::variant` of either the + * type `pair` or the type + * `ArrTraits::X_monotone_curve_2`. An object of the former type represents an + * intersection point with its multiplicity (in case the multiplicity is + * undefined or unknown, it should be set to \f$ 0\f$). An object of the latter + * type representing an overlapping subcurve of `xc1` and `xc2`. The operator + * returns a past-the-end iterator of the destination range. + */ +OutputIterator operator()(ArrTraits::X_monotone_curve_2 xc1, + ArrTraits::X_monotone_curve_2 xc2, + Output_iterator& oi); /// @} diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_circle_segment_traits_2.h b/Arrangement_on_surface_2/include/CGAL/Arr_circle_segment_traits_2.h index dc8dc0d5e78..2b5a25cd5e0 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_circle_segment_traits_2.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_circle_segment_traits_2.h @@ -7,9 +7,10 @@ // $Id$ // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial // -// Author(s) : Ron Wein -// Baruch Zukerman -// Waqar Khan +// Author(s): Ron Wein +// Baruch Zukerman +// Waqar Khan +// Efi Fogel #ifndef CGAL_ARR_CIRCLE_SEGMENT_TRAITS_2_H #define CGAL_ARR_CIRCLE_SEGMENT_TRAITS_2_H @@ -546,21 +547,15 @@ public: return Split_2(); } - class Intersect_2 - { + class Intersect_2 { private: - - Intersection_map& _inter_map; // The map of intersection points. + Intersection_map& _inter_map; // The map of intersection points. public: - /*! Constructor. */ - Intersect_2 (Intersection_map& map) : - _inter_map (map) - {} + Intersect_2(Intersection_map& map) : _inter_map(map) {} - /*! - * Find the intersections of the two given curves and insert them to the + /*! Find the intersections of the two given curves and insert them to the * given output iterator. As two segments may itersect only once, only a * single will be contained in the iterator. * \param cv1 The first curve. @@ -568,20 +563,15 @@ public: * \param oi The output iterator. * \return The past-the-end iterator. */ - template - OutputIterator operator() (const X_monotone_curve_2& cv1, - const X_monotone_curve_2& cv2, - OutputIterator oi) const - { - return (cv1.intersect (cv2, oi, &_inter_map)); - } + template + OutputIterator operator()(const X_monotone_curve_2& cv1, + const X_monotone_curve_2& cv2, + OutputIterator oi) const + { return (cv1.intersect(cv2, oi, &_inter_map)); } }; /*! Get an Intersect_2 functor object. */ - Intersect_2 intersect_2_object () const - { - return (Intersect_2 (inter_map)); - } + Intersect_2 intersect_2_object() const { return (Intersect_2(inter_map)); } class Are_mergeable_2 { @@ -706,14 +696,11 @@ public: friend class Arr_circle_segment_traits_2; public: - /*!\brief - * Returns a trimmed version of an arc - * + /*! Obtain a trimmed version of an arc * \param xcv The arc * \param src the new first endpoint * \param tgt the new second endpoint * \return The trimmed arc - * * \pre src != tgt * \pre both points must be interior and must lie on \c cv */ 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 654f86e3e30..eb9acae74a8 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 @@ -22,7 +22,6 @@ #include - /*! \file * This file was developed at Inria, France, and copied over to the * Arrangement_2 package, which it is now part of. It contains a traits @@ -30,12 +29,13 @@ * It is based on the circular kernel. */ -#include -#include -#include - #include +#include + +#include +#include + namespace CGAL { namespace VariantFunctors{ @@ -47,9 +47,9 @@ namespace CGAL { object_to_object_variant(const std::vector& res1, OutputIterator res2) { - for(std::vector::const_iterator it = res1.begin(); - it != res1.end(); ++it ){ - if(const Arc1 *arc = CGAL::object_cast< Arc1 >(&*it)){ + for (std::vector::const_iterator it = res1.begin(); + it != res1.end(); ++it ) { + if (const Arc1 *arc = CGAL::object_cast< Arc1 >(&*it)){ boost::variant< Arc1, Arc2 > v = *arc; *res2++ = make_object(v); } @@ -64,29 +64,27 @@ namespace CGAL { return res2; } - - template - class In_x_range_2 + template + OutputIterator + object_to_object_variant1(const std::vector& res, + OutputIterator oi) { - public: - typedef typename CircularKernel::Circular_arc_point_2 - Circular_arc_point_2; - typedef bool result_type; + typedef IntersectionPoint Intersection_point; + typedef XMonotoneCurve X_monotone_curve_2; + typedef boost::variant + Intersection_result; - result_type - operator()(const boost::variant< Arc1, Arc2 > &a, - const Circular_arc_point_2 &p) const - { - if ( const Arc1* arc1 = boost::get( &a ) ){ - return CircularKernel().in_x_range_2_object()(*arc1, p); - } - else { - const Arc2* arc2 = boost::get( &a ); - return CircularKernel().in_x_range_2_object()(*arc2, p); + for (auto it = res.begin(); it != res.end(); ++it) { + if (const Arc* arc = boost::get(&*it)) { + X_monotone_curve_2 cv = *arc; + *oi++ = Intersection_result(cv); } + else *oi++ = Intersection_result(*it); } - }; - + return oi; + } template class Compare_y_to_right_2 @@ -277,7 +275,7 @@ namespace CGAL { CircularKernel() .make_x_monotone_2_object()(*arc1,std::back_inserter(container)); return object_to_object_variant - (container, res); + (container, res); } else { const Arc2* arc2 = boost::get( &A ); @@ -285,65 +283,42 @@ namespace CGAL { CircularKernel() .make_x_monotone_2_object()(*arc2,std::back_inserter(container)); return object_to_object_variant - (container, res); + (container, res); } } }; - - template class Intersect_2 { public: - typedef typename CircularKernel::Circular_arc_point_2 - Circular_arc_point_2; + typedef typename CircularKernel::Circular_arc_point_2 + Circular_arc_point_2; template < class OutputIterator > OutputIterator operator()(const boost::variant< Arc1, Arc2 > &c1, const boost::variant< Arc1, Arc2 > &c2, - OutputIterator res) const + OutputIterator oi) const { if ( const Arc1* arc1 = boost::get( &c1 ) ){ if ( const Arc1* arc2 = boost::get( &c2 ) ){ - std::vector container; - CircularKernel() - .intersect_2_object()(*arc1,*arc2,std::back_inserter(container)); - return object_to_object_variant - (container, res); - } - else if ( const Arc2* arc2 = boost::get( &c2 ) ){ - std::vector container; - CircularKernel() - .intersect_2_object()(*arc1,*arc2,std::back_inserter(container)); - return object_to_object_variant - (container, res); - } - } - else { - const Arc2* arc1e = boost::get( &c1 ); - if ( const Arc1* arc2 = boost::get( &c2 ) ){ - std::vector container; - CircularKernel() - .intersect_2_object()(*arc1e,*arc2,std::back_inserter(container)); - return object_to_object_variant - (container, res); + return CircularKernel().intersect_2_object()(*arc1, *arc2, oi); } const Arc2* arc2 = boost::get( &c2 ); - std::vector container; - CircularKernel() - .intersect_2_object()(*arc1e,*arc2,std::back_inserter(container)); - return object_to_object_variant - (container, res); + return CircularKernel().intersect_2_object()(*arc1, *arc2, oi); } - CGAL_error(); - return res;//for no warning + + const Arc2* arc1e = boost::get( &c1 ); + if ( const Arc1* arc2 = boost::get( &c2 ) ){ + return CircularKernel().intersect_2_object()(*arc1e, *arc2, oi); + } + const Arc2* arc2 = boost::get( &c2 ); + return CircularKernel().intersect_2_object()(*arc1e, *arc2, oi); } }; - template class Split_2 { @@ -533,7 +508,7 @@ namespace CGAL { typedef unsigned int Multiplicity; typedef CGAL::Tag_false Has_left_category; - typedef CGAL::Tag_false Has_merge_category; + typedef CGAL::Tag_false Has_merge_category; typedef CGAL::Tag_false Has_do_intersect_category; typedef Arr_oblivious_side_tag Left_side_category; 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 f1640b280b0..cc26c045a84 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 @@ -8,8 +8,8 @@ // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial // // -// Author(s) : Ron Wein -// Waqar Khan +// Author(s): Ron Wein +// Waqar Khan #ifndef CGAL_ARR_CONIC_TRAITS_2_H #define CGAL_ARR_CONIC_TRAITS_2_H @@ -22,6 +22,8 @@ * The conic traits-class for the arrangement package. */ +#include + #include #include #include @@ -29,8 +31,6 @@ #include #include -#include - namespace CGAL { /*! @@ -88,8 +88,7 @@ private: // Type definition for the intersection points mapping. typedef typename X_monotone_curve_2::Conic_id Conic_id; - typedef typename X_monotone_curve_2::Intersection_point_2 - Intersection_point_2; + typedef typename X_monotone_curve_2::Intersection_point Intersection_point; typedef typename X_monotone_curve_2::Intersection_map Intersection_map; mutable Intersection_map inter_map; // Mapping conic pairs to their @@ -604,21 +603,15 @@ public: return Split_2(); } - class Intersect_2 - { + class Intersect_2 { private: - - Intersection_map& _inter_map; // The map of intersection points. + Intersection_map& _inter_map; // The map of intersection points. public: - /*! Constructor. */ - Intersect_2 (Intersection_map& map) : - _inter_map (map) - {} + Intersect_2(Intersection_map& map) : _inter_map(map) {} - /*! - * Find the intersections of the two given curves and insert them to the + /*! Find the intersections of the two given curves and insert them to the * given output iterator. As two segments may itersect only once, only a * single will be contained in the iterator. * \param cv1 The first curve. @@ -626,20 +619,15 @@ public: * \param oi The output iterator. * \return The past-the-end iterator. */ - template - OutputIterator operator() (const X_monotone_curve_2& cv1, - const X_monotone_curve_2& cv2, - OutputIterator oi) const - { - return (cv1.intersect (cv2, _inter_map, oi)); - } + template + OutputIterator operator()(const X_monotone_curve_2& cv1, + const X_monotone_curve_2& cv2, + OutputIterator oi) const + { return (cv1.intersect(cv2, _inter_map, oi)); } }; /*! Get an Intersect_2 functor object. */ - Intersect_2 intersect_2_object () const - { - return (Intersect_2 (inter_map)); - } + Intersect_2 intersect_2_object () const { return (Intersect_2(inter_map)); } class Are_mergeable_2 { 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 877444cb066..7ed8e459334 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 @@ -7,8 +7,8 @@ // $Id$ // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial // -// Author(s) : Ron Wein -// Efi Fogel +// Author(s): Ron Wein +// Efi Fogel #ifndef CGAL_ARR_CURVE_DATA_TRAITS_2_H #define CGAL_ARR_CURVE_DATA_TRAITS_2_H @@ -22,6 +22,8 @@ */ #include + +#include #include #include @@ -193,35 +195,40 @@ public: * \param oi The output iterator. * \return The past-the-end iterator. */ - template + template OutputIterator operator()(const X_monotone_curve_2& cv1, const X_monotone_curve_2& cv2, OutputIterator oi) const { + typedef std::pair Intersection_point; + typedef boost::variant + Intersection_result; + typedef boost::variant + Intersection_base_result; + // Use the base functor to obtain all intersection objects. - std::list base_objects; + std::list base_objects; m_base.intersect_2_object()(cv1, cv2, std::back_inserter(base_objects)); // Stop if the list is empty: if (base_objects.empty()) return oi; // Go over all intersection objects and prepare the output. - const Base_x_monotone_curve_2* base_cv; - for (typename std::list::const_iterator it = - base_objects.begin(); it != base_objects.end(); ++it) - { - if ((base_cv = object_cast(&(*it))) != nullptr) { + for (const auto& item : base_objects) { + const Base_x_monotone_curve_2* base_cv = + boost::get(&item); + if (base_cv != nullptr) { // The current intersection object is an overlapping x-monotone // curve: Merge the data fields of both intersecting curves and // associate the result with the overlapping curve. - X_monotone_curve_2 cv(*base_cv, Merge() (cv1.data(), cv2.data())); - *oi++ = make_object(cv); - } - else { - // The current intersection object is an intersection point: - // Copy it as is. - *oi++ = *it; + X_monotone_curve_2 cv(*base_cv, Merge()(cv1.data(), cv2.data())); + *oi++ = Intersection_result(cv); + continue; } + // The current intersection object is an intersection point: + // Copy it as is. + const Intersection_point* ip = boost::get(&item); + *oi++ = Intersection_result(*ip); } return oi; 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 3c21ac9026d..6ccd5d249bc 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 @@ -7,7 +7,7 @@ // $Id$ // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial // -// Author(s) : Efi Fogel +// Author(s) : Efi Fogel #ifndef CGAL_ARR_GEODESIC_ARC_ON_SPHERE_TRAITS_2_H #define CGAL_ARR_GEODESIC_ARC_ON_SPHERE_TRAITS_2_H @@ -25,6 +25,8 @@ #include +#include + #include #include #include @@ -1646,7 +1648,10 @@ public: Project project, OutputIterator oi) const { - typedef std::pair Point_2_pair; + typedef std::pair Intersection_point; + typedef boost::variant + Intersection_result; + const Kernel* kernel = m_traits; typename Kernel::Equal_2 equal = kernel->equal_2_object(); @@ -1658,7 +1663,7 @@ public: if (equal(l1, l2)) { const Point_2& trg = (in_between(r1, l2, r2)) ? r1_3 : r2_3; X_monotone_curve_2 xc(l1_3, trg, normal, vertical, true); - *oi++ = make_object(xc); + *oi++ = Intersection_result(xc); return oi; } @@ -1668,29 +1673,29 @@ public: if (l1_eq_start || (!l2_eq_start && in_between(l1, start, l2))) { // The following applies only to full circles: if (l1_eq_start && equal(r2, start)) - *oi++ = make_object(Point_2_pair(r2_3, 1)); + *oi++ = Intersection_result(Intersection_point(r2_3, 1)); if (in_between(r1, l1, l2)) return oi; // no intersection if (equal(r1, l2)) { - *oi++ = make_object(Point_2_pair(r1_3, 1)); + *oi++ = Intersection_result(Intersection_point(r1_3, 1)); return oi; } const Point_2& trg = (in_between(r1, l2, r2)) ? r1_3 : r2_3; X_monotone_curve_2 xc(l2_3, trg, normal, vertical, true); - *oi++ = make_object(xc); + *oi++ = Intersection_result(xc); return oi; } CGAL_assertion(l2_eq_start || in_between(l2, start, l1)); // The following applies only to full circles: if (l2_eq_start && equal(r1, start)) - *oi++ = make_object(Point_2_pair(r1_3, 1)); + *oi++ = Intersection_result(Intersection_point(r1_3, 1)); if (in_between(r2, l2, l1)) return oi; // no intersection if (equal(r2, l1)) { - *oi++ = make_object(Point_2_pair(r2_3, 1)); + *oi++ = Intersection_result(Intersection_point(r2_3, 1)); return oi; } const Point_2& trg = (in_between(r1, l2, r2)) ? r1_3 : r2_3; X_monotone_curve_2 xc(l1_3, trg, normal, vertical, true); - *oi++ = make_object(xc); + *oi++ = Intersection_result(xc); return oi; } @@ -1784,9 +1789,12 @@ public: typedef Arr_geodesic_arc_on_sphere_traits_2 Traits; typedef typename Kernel::Counterclockwise_in_between_2 Counterclockwise_in_between_2; - typedef typename Kernel::Equal_3 Equal_3; + typedef typename Kernel::Equal_3 Equal_3; + + typedef std::pair Intersection_point; + typedef boost::variant + Intersection_result; - typedef std::pair Point_2_pair; const Kernel* kernel = m_traits; Equal_3 equal_3 = kernel->equal_3_object(); @@ -1810,9 +1818,9 @@ public: (res && (xc1.is_directed_right() != xc2.is_directed_right()))) { if (xc1.left().is_min_boundary() && xc2.left().is_min_boundary()) - *oi++ = make_object(Point_2_pair(xc1.left(), 1)); + *oi++ = Intersection_result(Intersection_point(xc1.left(), 1)); if (xc1.right().is_max_boundary() && xc2.right().is_max_boundary()) - *oi++ = make_object(Point_2_pair(xc1.right(), 1)); + *oi++ = Intersection_result(Intersection_point(xc1.right(), 1)); return oi; } @@ -1820,11 +1828,11 @@ public: * the other arc is completely overlapping. */ if (xc1.left().is_min_boundary() && xc1.right().is_max_boundary()) { - *oi++ = make_object(xc2); + *oi++ = Intersection_result(xc2); return oi; } if (xc2.left().is_min_boundary() && xc2.right().is_max_boundary()) { - *oi++ = make_object(xc1); + *oi++ = Intersection_result(xc1); return oi; } /*! Find an endpoint that does not coincide with a pole, and project @@ -1877,14 +1885,14 @@ public: // Determine which one of the two directions: Point_2 ed(v.direction()); if (is_in_between(ed, xc1) && is_in_between(ed, xc2)) { - *oi++ = make_object(Point_2_pair(ed, 1)); + *oi++ = Intersection_result(Intersection_point(ed, 1)); return oi; } Vector_3 vo(kernel->construct_opposite_vector_3_object()(v)); Point_2 edo(vo.direction()); if (is_in_between(edo, xc1) && is_in_between(edo, xc2)) { - *oi++ = make_object(Point_2_pair(edo, 1)); + *oi++ = Intersection_result(Intersection_point(edo, 1)); return oi; } return oi; diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_geometry_traits/Bezier_cache.h b/Arrangement_on_surface_2/include/CGAL/Arr_geometry_traits/Bezier_cache.h index 87a104c032f..62c7950a028 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_geometry_traits/Bezier_cache.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_geometry_traits/Bezier_cache.h @@ -52,11 +52,11 @@ public: /// \name Type definitions for the intersection-point mapping. //@{ - /*! \struct Intersection_point_2 + /*! \struct Intersection_point * Representation of an intersection point (in both parameter and physical * spaces). */ - struct Intersection_point_2 + struct Intersection_point { Algebraic s; // The parameter for the first curve. Algebraic t; // The parameter for the second curve. @@ -64,7 +64,7 @@ public: Algebraic y; // The y-coordinate. /*! Constructor. */ - Intersection_point_2 (const Algebraic& _s, const Algebraic& _t, + Intersection_point (const Algebraic& _s, const Algebraic& _t, const Algebraic& _x, const Algebraic& _y) : s(_s), t(_t), x(_x), y(_y) @@ -73,7 +73,7 @@ public: typedef std::pair Curve_pair; typedef std::pair Parameter_pair; - typedef std::list Intersection_list; + typedef std::list Intersection_list; typedef typename Intersection_list::const_iterator Intersection_iter; @@ -251,7 +251,7 @@ private: const Polynomial& polyY_1, const Integer& normY_1, const Polynomial& polyX_2, const Integer& normX_2, const Polynomial& polyY_2, const Integer& normY_2, - Parameter_list& s_vals) const; + Parameter_list& s_vals, bool find_out_of_range=false) const; /*! * Compute all s-parameter values of the self intersection of (X(s), Y(s)) @@ -378,7 +378,7 @@ _Bezier_cache::get_intersections CGAL::compare (nt_traits.evaluate_at (polyY_1, *t_it), y) == EQUAL) { - info.first.push_back (Intersection_point_2 (*s_it, *t_it, + info.first.push_back (Intersection_point (*s_it, *t_it, x / denX, y / denY)); } } @@ -407,7 +407,7 @@ _Bezier_cache::get_intersections do_ovlp = _intersection_params (polyX_2, normX_2, polyY_2, normY_2, polyX_1, normX_1, polyY_1, normY_1, - t_vals); + t_vals, true); CGAL_assertion (! do_ovlp); @@ -457,21 +457,14 @@ _Bezier_cache::get_intersections const Algebraic one (1); unsigned int k; - //pointers are used to set the list pts1_ptr as the one with the less values - Point_list* pts1_ptr=&pts1; - Point_list* pts2_ptr=&pts2; - bool swapt=pts1.size() > pts2.size(); - if (swapt) - std::swap(pts1_ptr,pts2_ptr); - - for (pit1 = pts1_ptr->begin(); pit1 != pts1_ptr->end(); ++pit1) + for (pit1 = pts1.begin(); pit1 != pts1.end(); ++pit1) { // Construct a vector of distances from the current point to all other // points in the pts2 list. - const int n_pts2 = static_cast(pts2_ptr->size()); + const int n_pts2 = static_cast(pts2.size()); std::vector dist_vec (n_pts2); - for (k = 0, pit2 = pts2_ptr->begin(); pit2 != pts2_ptr->end(); k++, ++pit2) + for (k = 0, pit2 = pts2.begin(); pit2 != pts2.end(); k++, ++pit2) { // Compute the approximate distance between the teo current points. dx = pit1->app_x - pit2->app_x; @@ -508,7 +501,7 @@ _Bezier_cache::get_intersections pit1->y = pit2->y; // Remove this point from pts2, as we found a match for it. - pts2_ptr->erase (pit2); + pts2.erase (pit2); found = true; } } @@ -528,17 +521,15 @@ _Bezier_cache::get_intersections pit1->y = pit2->y; // Remove this point from pts2, as we found a match for it. - pts2_ptr->erase (pit2); + pts2.erase (pit2); } // Check that s- and t-values both lie in the legal range of [0,1]. - CGAL_assertion(CGAL::sign (s) != NEGATIVE && CGAL::compare (s, one) != LARGER && - CGAL::sign (t) != NEGATIVE && CGAL::compare (t, one) != LARGER); - - if (!swapt) - info.first.push_back (Intersection_point_2 (s, t,pit1->x, pit1->y)); - else - info.first.push_back (Intersection_point_2 (t, s,pit1->x, pit1->y)); + if(CGAL::sign (s) != NEGATIVE && CGAL::compare (s, one) != LARGER && + CGAL::sign (t) != NEGATIVE && CGAL::compare (t, one) != LARGER) + { + info.first.push_back(Intersection_point(s, t,pit1->x, pit1->y)); + } } info.second = false; @@ -582,7 +573,7 @@ bool _Bezier_cache::_intersection_params const Polynomial& polyY_1, const Integer& normY_1, const Polynomial& polyX_2, const Integer& normX_2, const Polynomial& polyY_2, const Integer& normY_2, - Parameter_list& s_vals) const + Parameter_list& s_vals, bool find_out_of_range) const { // Clear the output parameter list. if (! s_vals.empty()) @@ -633,8 +624,12 @@ bool _Bezier_cache::_intersection_params } // Compute the roots of the resultant polynomial and mark that the curves do - // not overlap. The roots we are interested in must be in the interval [0,1]. - nt_traits.compute_polynomial_roots (res,0,1,std::back_inserter (s_vals)); + // not overlap. The roots we are interested in are usually in the interval [0,1]. + if (find_out_of_range) + nt_traits.compute_polynomial_roots (res,std::back_inserter (s_vals)); + else + nt_traits.compute_polynomial_roots (res,0,1,std::back_inserter (s_vals)); + return (false); } diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_geometry_traits/Bezier_x_monotone_2.h b/Arrangement_on_surface_2/include/CGAL/Arr_geometry_traits/Bezier_x_monotone_2.h index 25a1c51dbab..5397a42062f 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_geometry_traits/Bezier_x_monotone_2.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_geometry_traits/Bezier_x_monotone_2.h @@ -7,8 +7,8 @@ // $Id$ // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial // -// Author(s) : Ron Wein -// Iddo Hanniel +// Author(s): Ron Wein +// Iddo Hanniel #ifndef CGAL_BEZIER_X_MONOTONE_2_H #define CGAL_BEZIER_X_MONOTONE_2_H @@ -85,27 +85,24 @@ private: typedef typename Bezier_cache::Intersection_iter Intersect_iter; // Representation of an intersection point with its multiplicity: - typedef std::pair Intersection_point_2; + typedef std::pair Intersection_point; /*! \class Less_intersection_point * Comparison functor for intersection points. */ - class Less_intersection_point - { + class Less_intersection_point { private: - Bezier_cache *p_cache; + Bezier_cache* p_cache; public: - Less_intersection_point (Bezier_cache& cache) : - p_cache (&cache) - {} + Less_intersection_point(Bezier_cache& cache) : p_cache(&cache) {} - bool operator() (const Intersection_point_2& ip1, - const Intersection_point_2& ip2) const + bool operator()(const Intersection_point& ip1, + const Intersection_point& ip2) const { // Use an xy-lexicographic comparison. - return (ip1.first.compare_xy (ip2.first, *p_cache) == SMALLER); + return (ip1.first.compare_xy(ip2.first, *p_cache) == SMALLER); } }; @@ -117,7 +114,7 @@ private: */ struct Less_curve_pair { - bool operator() (const Curve_pair& cp1, const Curve_pair& cp2) const + bool operator()(const Curve_pair& cp1, const Curve_pair& cp2) const { // Compare the pairs of IDs lexicographically. return (cp1.first < cp2.first || @@ -128,34 +125,32 @@ private: /*! \struct Subcurve * For the usage of the _exact_vertical_position() function. */ - struct Subcurve - { - std::list control_points; - Rational t_min; - Rational t_max; + struct Subcurve { + std::list control_points; + Rational t_min; + Rational t_max; /*! Get the rational bounding box of the subcurve. */ - void bbox (Rational& x_min, Rational& y_min, - Rational& x_max, Rational& y_max) const + void bbox(Rational& x_min, Rational& y_min, + Rational& x_max, Rational& y_max) const { - typename std::list::const_iterator pit = + typename std::list::const_iterator pit = control_points.begin(); - CGAL_assertion (pit != control_points.end()); + CGAL_assertion(pit != control_points.end()); x_min = x_max = pit->x(); y_min = y_max = pit->y(); - for (++pit; pit != control_points.end(); ++pit) - { - if (CGAL::compare (x_min, pit->x()) == LARGER) + for (++pit; pit != control_points.end(); ++pit) { + if (CGAL::compare(x_min, pit->x()) == LARGER) x_min = pit->x(); - else if (CGAL::compare (x_max, pit->x()) == SMALLER) + else if (CGAL::compare(x_max, pit->x()) == SMALLER) x_max = pit->x(); - if (CGAL::compare (y_min, pit->y()) == LARGER) + if (CGAL::compare(y_min, pit->y()) == LARGER) y_min = pit->y(); - else if (CGAL::compare (y_max, pit->y()) == SMALLER) + else if (CGAL::compare(y_max, pit->y()) == SMALLER) y_max = pit->y(); } @@ -189,10 +184,10 @@ private: public: /*! Default constructor. */ - _Bezier_x_monotone_2 () : + _Bezier_x_monotone_2() : _xid(0), - _dir_right (false), - _is_vert (false) + _dir_right(false), + _is_vert(false) {} /*! @@ -209,80 +204,56 @@ public: * \pre B should be an originator of both ps and pt. * \pre xid is a non-zero serial number. */ - _Bezier_x_monotone_2 (const Curve_2& B, unsigned int xid, - const Point_2& ps, const Point_2& pt, - Bezier_cache& cache); + _Bezier_x_monotone_2(const Curve_2& B, unsigned int xid, + const Point_2& ps, const Point_2& pt, + Bezier_cache& cache); /*! * Get the supporting Bezier curve. */ - const Curve_2& supporting_curve () const - { - return (_curve); - } + const Curve_2& supporting_curve() const { return (_curve); } /*! * Get the x-monotone ID of the curve. */ - unsigned int xid () const - { - return (_xid); - } + unsigned int xid() const { return (_xid); } /*! * Get the source point. */ - const Point_2& source () const - { - return (_ps); - } + const Point_2& source() const { return (_ps); } /*! * Get the target point. */ - const Point_2& target () const - { - return (_pt); - } + const Point_2& target() const { return (_pt); } /*! * Get the left endpoint (the lexicographically smaller one). */ - const Point_2& left () const - { - return (_dir_right ? _ps : _pt); - } + const Point_2& left() const { return (_dir_right ? _ps : _pt); } /*! * Get the right endpoint (the lexicographically larger one). */ - const Point_2& right () const - { - return (_dir_right ? _pt : _ps); - } + const Point_2& right() const { return (_dir_right ? _pt : _ps); } /*! * Check if the subcurve is a vertical segment. */ - bool is_vertical () const - { - return (_is_vert); - } + bool is_vertical() const { return (_is_vert); } /*! * Check if the subcurve is directed from left to right. */ - bool is_directed_right () const - { - return (_dir_right); - } + bool is_directed_right() const { return (_dir_right); } /*! * Get the approximate parameter range defining the curve. * \return A pair of t_src and t_trg, where B(t_src) is the source point * and B(t_trg) is the target point. */ - std::pair parameter_range () const; + std::pair parameter_range() const; /*! * Get the relative position of the query point with respect to the subcurve. @@ -293,8 +264,8 @@ public: * LARGER if the point is above the arc; * EQUAL if p lies on the arc. */ - Comparison_result point_position (const Point_2& p, - Bezier_cache& cache) const; + Comparison_result point_position(const Point_2& p, + Bezier_cache& cache) const; /*! * Compare the relative y-position of two x-monotone subcurve to the right @@ -307,9 +278,9 @@ public: * EQUAL in case of an overlap (should not happen); * LARGER if (*this) lies above cv to the right of p. */ - Comparison_result compare_to_right (const Self& cv, - const Point_2& p, - Bezier_cache& cache) const; + Comparison_result compare_to_right(const Self& cv, + const Point_2& p, + Bezier_cache& cache) const; /*! * Compare the relative y-position of two x-monotone subcurve to the left @@ -322,106 +293,90 @@ public: * EQUAL in case of an overlap (should not happen); * LARGER if (*this) lies above cv to the right of p. */ - Comparison_result compare_to_left (const Self& cv, - const Point_2& p, - Bezier_cache& cache) const; + Comparison_result compare_to_left(const Self& cv, + const Point_2& p, + Bezier_cache& cache) const; - /*! - * Check whether the two subcurves are equal (have the same graph). + /*! Check whether the two subcurves are equal (have the same graph). * \param cv The other subcurve. * \param cache Caches the vertical tangency points and intersection points. * \return (true) if the two subcurves have the same graph; * (false) otherwise. */ - bool equals (const Self& cv, - Bezier_cache& cache) const; + bool equals(const Self& cv, Bezier_cache& cache) const; - /*! - * Compute the intersections with the given subcurve. + /*! Compute the intersections with the given subcurve. * \param cv The other subcurve. * \param inter_map Caches the bounded intersection points. * \param cache Caches the vertical tangency points and intersection points. * \param oi The output iterator. * \return The past-the-end iterator. */ - template - OutputIterator intersect (const Self& cv, - Intersection_map& inter_map, - Bezier_cache& cache, - OutputIterator oi) const + template + OutputIterator intersect(const Self& cv, + Intersection_map& inter_map, + Bezier_cache& cache, + OutputIterator oi) const { + typedef boost::variant Intersection_result; + // In case we have two x-monotone subcurves of the same Bezier curve, // check if they have a common left endpoint. - if (_curve.is_same (cv._curve)) - { - if (left().is_same (cv.left()) || left().is_same (cv.right())) - { - *oi = CGAL::make_object (Intersection_point_2 (left(), 0)); - ++oi; - } + if (_curve.is_same(cv._curve)) { + if (left().is_same(cv.left()) || left().is_same(cv.right())) + *oi++ = Intersection_result(Intersection_point(left(), 0)); } // Compute the intersections of the two sucurves. Note that for caching // purposes we always apply the _intersect() function on the subcurve whose // curve ID is smaller. - std::vector ipts; - Self ovlp_cv; - bool do_ovlp; + std::vector ipts; + Self ovlp_cv; + bool do_ovlp; if (_curve.id() <= cv._curve.id()) - do_ovlp = _intersect (cv, inter_map, cache, ipts, ovlp_cv); + do_ovlp = _intersect(cv, inter_map, cache, ipts, ovlp_cv); else - do_ovlp = cv._intersect (*this, inter_map, cache, ipts, ovlp_cv); + do_ovlp = cv._intersect(*this, inter_map, cache, ipts, ovlp_cv); // In case of overlap, just report the overlapping subcurve. - if (do_ovlp) - { - *oi = CGAL::make_object (ovlp_cv); - ++oi; - return (oi); + if (do_ovlp) { + *oi++ = Intersection_result(ovlp_cv); + return oi; } // If we have a set of intersection points, sort them in ascending // xy-lexicorgraphical order, and insert them to the output iterator. - typename std::vector::const_iterator ip_it; - - std::sort (ipts.begin(), ipts.end(), Less_intersection_point (cache)); - for (ip_it = ipts.begin(); ip_it != ipts.end(); ++ip_it) - { - *oi = CGAL::make_object (*ip_it); - ++oi; + std::sort(ipts.begin(), ipts.end(), Less_intersection_point(cache)); + for (auto ip_it = ipts.begin(); ip_it != ipts.end(); ++ip_it) { + *oi++ = Intersection_result(*ip_it); } // In case we have two x-monotone subcurves of the same Bezier curve, // check if they have a common right endpoint. - if (_curve.is_same (cv._curve)) - { - if (right().is_same (cv.left()) || right().is_same (cv.right())) - { - *oi = CGAL::make_object (Intersection_point_2 (right(), 0)); - ++oi; + if (_curve.is_same(cv._curve)) { + if (right().is_same(cv.left()) || right().is_same(cv.right())) { + *oi++ = Intersection_result(Intersection_point(right(), 0)); } } - return (oi); + return oi; } - /*! - * Split the subcurve into two at a given split point. + /*! Split the subcurve into two at a given split point. * \param p The split point. * \param c1 Output: The first resulting arc, lying to the left of p. * \param c2 Output: The first resulting arc, lying to the right of p. * \pre p lies in the interior of the subcurve (not one of its endpoints). */ - void split (const Point_2& p, - Self& c1, Self& c2) const; + void split(const Point_2& p, Self& c1, Self& c2) const; /*! * Check if the two subcurves are mergeable. * \param cv The other subcurve. * \return Whether the two subcurves can be merged. */ - bool can_merge_with (const Self& cv) const; + bool can_merge_with(const Self& cv) const; /*! * Merge the current arc with the given arc. @@ -429,13 +384,13 @@ public: * \pre The two arcs are mergeable. * \return The merged arc. */ - Self merge (const Self& cv) const; + Self merge(const Self& cv) const; /*! * Flip the subcurve (swap its source and target points). * \return The flipped subcurve. */ - Self flip () const + Self flip() const { // Note that we just swap the source and target of the original subcurve // and do not touch the supporting Beizer curve. @@ -445,7 +400,7 @@ public: cv._pt = this->_ps; cv._dir_right = ! this->_dir_right; - return (cv); + return cv; } Self trim(const Point_2& src, const Point_2& tgt) const @@ -460,26 +415,21 @@ public: } private: - - /*! - * Check if the given t-value is in the range of the subcurve. + /*! Check if the given t-value is in the range of the subcurve. * \param t The parameter value. * \param cache Caches the vertical tangency points and intersection points. * \return If t in the parameter-range of the subcurve. */ - bool _is_in_range (const Algebraic& t, - Bezier_cache& cache) const; + bool _is_in_range(const Algebraic& t, Bezier_cache& cache) const; - /*! - * Check if the given point lies in the range of this x-monotone subcurve. + /*! Check if the given point lies in the range of this x-monotone subcurve. * \param p The point, which lies on the supporting Bezier curve. * \param is_certain Output: Is the answer we provide is certain. * \return Whether p is on the x-monotone subcurve. */ - bool _is_in_range (const Point_2& p, bool& is_certain) const; + bool _is_in_range(const Point_2& p, bool& is_certain) const; - /*! - * Given a point p that lies on the supporting Bezier curve (X(t), Y(t)), + /*! Given a point p that lies on the supporting Bezier curve (X(t), Y(t)), * determine whether p lies within the t-range of the x-monotone subcurve. * If so, the value t0 such that p = (X(t0), Y(t0)) is also computed. * \param p The point, which lies on the supporting Bezier curve. @@ -488,23 +438,20 @@ private: * \param is_endpoint Output: Whether p equals on the of the endpoints. * \return Whether p lies in the t-range of the subcurve. */ - bool _is_in_range (const Point_2& p, - Bezier_cache& cache, - Algebraic& t0, - bool& is_endpoint) const; + bool _is_in_range(const Point_2& p, + Bezier_cache& cache, + Algebraic& t0, + bool& is_endpoint) const; - /*! - * Compute a y-coordinate of a point on the x-monotone subcurve with a + /*! Compute a y-coordinate of a point on the x-monotone subcurve with a * given x-coordinate. * \param x0 The given x-coodinate. * \param cache Caches the vertical tangency points and intersection points. * \return The y-coordinate. */ - Algebraic _get_y (const Rational& x0, - Bezier_cache& cache) const; + Algebraic _get_y(const Rational& x0, Bezier_cache& cache) const; - /*! - * Compare the slopes of the subcurve with another given Bezier subcurve at + /*! Compare the slopes of the subcurve with another given Bezier subcurve at * their given intersection point. * \param cv The other subcurve. * \param p The intersection point. @@ -515,20 +462,18 @@ private: * EQUAL if the two slopes are equal; * LARGER if (*this) slope is greater than cv's. */ - Comparison_result _compare_slopes (const Self& cv, - const Point_2& p, - Bezier_cache& cache) const; + Comparison_result _compare_slopes(const Self& cv, + const Point_2& p, + Bezier_cache& cache) const; - /*! - * Get the range of t-value over which the subcurve is defined. + /*! Get the range of t-value over which the subcurve is defined. * \param cache Caches the vertical tangency points and intersection points. * \return A pair comprised of the t-value for the source point and the * t-value for the target point. */ - std::pair _t_range (Bezier_cache& cache) const; + std::pair _t_range(Bezier_cache& cache) const; - /*! - * Compare the relative y-position of two x-monotone subcurve to the right + /*! Compare the relative y-position of two x-monotone subcurve to the right * (or to the left) of their intersection point, whose multiplicity is * greater than 1. * \param cv The other subcurve. @@ -543,25 +488,22 @@ private: * EQUAL in case of an overlap (should not happen); * LARGER if (*this) lies above cv next to p. */ - Comparison_result _compare_to_side (const Self& cv, - const Point_2& p, - bool to_right, - Bezier_cache& cache) const; + Comparison_result _compare_to_side(const Self& cv, + const Point_2& p, + bool to_right, + Bezier_cache& cache) const; - /*! - * Clip the control polygon of the supporting Bezier curve such that it + /*! Clip the control polygon of the supporting Bezier curve such that it * fits the current x-monotone subcurve. * \param ctrl Output: The clipped control polygon. * \param t_min Output: The minimal t-value of the clipped curve. * \param t_max Output: The maximal t-value of the clipped curve. */ - void _clip_control_polygon - (typename Bounding_traits::Control_points& ctrl, - typename Bounding_traits::NT& t_min, - typename Bounding_traits::NT& t_max) const; + void _clip_control_polygon(typename Bounding_traits::Control_points& ctrl, + typename Bounding_traits::NT& t_min, + typename Bounding_traits::NT& t_max) const; - /*! - * Approximate the intersection points between the supporting Bezier curves + /*! Approximate the intersection points between the supporting Bezier curves * of the given x-monotone curves. * \param cv The x-monotone curve we intersect. * \param inter_pts Output: An output list of intersection points between @@ -571,11 +513,10 @@ private: * between the subcurves are approximated. * \return Whether all intersection points where successfully approximated. */ - bool _approximate_intersection_points (const Self& cv, - std::list& inter_pts) const; + bool _approximate_intersection_points(const Self& cv, + std::list& inter_pts) const; - /*! - * Compute the intersections with the given subcurve. + /*! Compute the intersections with the given subcurve. * \param cv The other subcurve. * \param inter_map Caches the bounded intersection points. * \param cache Caches the vertical tangency points and intersection points. @@ -583,14 +524,13 @@ private: * \param ovlp_cv Output: An overlapping subcurve (if exists). * \return Whether an overlap has occurred. */ - bool _intersect (const Self& cv, - Intersection_map& inter_map, - Bezier_cache& cache, - std::vector& ipts, - Self& ovlp_cv) const; + bool _intersect(const Self& cv, + Intersection_map& inter_map, + Bezier_cache& cache, + std::vector& ipts, + Self& ovlp_cv) const; - /*! - * Compute the exact vertical position of the given point with respect to + /*! Compute the exact vertical position of the given point with respect to * the x-monotone curve. * \param p The point. * \param force_exact Sould we force an exact result. @@ -598,64 +538,63 @@ private: * LARGER if the point is above the curve; * EQUAL if p lies on the curve. */ - Comparison_result _exact_vertical_position (const Point_2& p, - bool + Comparison_result _exact_vertical_position(const Point_2& p, + bool #if !defined(CGAL_NO_ASSERTIONS) - force_exact + force_exact #endif - ) const; + ) const; }; /*! * Exporter for Bezier curves. */ -template +template std::ostream& -operator<< (std::ostream& os, - const _Bezier_x_monotone_2& cv) +operator<<(std::ostream& os, + const _Bezier_x_monotone_2 + & cv) { os << cv.supporting_curve() << " [" << cv.xid() << "] | " << cv.source() << " --> " << cv.target(); - return (os); + return os; } // --------------------------------------------------------------------------- // Constructor given two endpoints. // -template -_Bezier_x_monotone_2::_Bezier_x_monotone_2 - (const Curve_2& B, unsigned int xid, - const Point_2& ps, const Point_2& pt, - Bezier_cache& cache) : - _curve (B), - _xid (xid), - _ps (ps), - _pt (pt), - _is_vert (false) +template +_Bezier_x_monotone_2:: +_Bezier_x_monotone_2(const Curve_2& B, unsigned int xid, + const Point_2& ps, const Point_2& pt, + Bezier_cache& cache) : + _curve(B), + _xid(xid), + _ps(ps), + _pt(pt), + _is_vert(false) { - CGAL_precondition (xid > 0); + CGAL_precondition(xid > 0); // Get the originators of the point that correspond to the curve B. - Originator_iterator ps_org = ps.get_originator (B, _xid); - CGAL_precondition (ps_org != ps.originators_end()); + Originator_iterator ps_org = ps.get_originator(B, _xid); + CGAL_precondition(ps_org != ps.originators_end()); - Originator_iterator pt_org = pt.get_originator (B, _xid); - CGAL_precondition (pt_org != pt.originators_end()); + Originator_iterator pt_org = pt.get_originator(B, _xid); + CGAL_precondition(pt_org != pt.originators_end()); // Check if the subcurve is directed left or right. - const Comparison_result res = _ps.compare_x (_pt, cache); + const Comparison_result res = _ps.compare_x(_pt, cache); - if (res == EQUAL) - { + if (res == EQUAL) { // We have a vertical segment. Check if the source is below the target. _is_vert = true; - _dir_right = (CGAL::compare (_ps.y(), _pt.y()) == SMALLER); + _dir_right = (CGAL::compare(_ps.y(), _pt.y()) == SMALLER); } else { @@ -665,89 +604,83 @@ _Bezier_x_monotone_2::_Bezier_x_monotone_2 // Check if the value of the parameter t increases when we traverse the // curve from left to right: If the curve is directed to the right, we // check if t_src < t_trg, otherwise we check whether t_src > t_trg. - Comparison_result t_res; + Comparison_result t_res; - if (CGAL::compare (ps_org->point_bound().t_max, - pt_org->point_bound().t_min) == SMALLER || - CGAL::compare (ps_org->point_bound().t_min, - pt_org->point_bound().t_max) == LARGER) + if (CGAL::compare(ps_org->point_bound().t_max, + pt_org->point_bound().t_min) == SMALLER || + CGAL::compare(ps_org->point_bound().t_min, + pt_org->point_bound().t_max) == LARGER) { // Perform the comparison assuming that the possible parameter // values do not overlap. - t_res = CGAL::compare (ps_org->point_bound().t_min, + t_res = CGAL::compare(ps_org->point_bound().t_min, pt_org->point_bound().t_min); } - else - { + else { // In this case both exact parameter values must be known. // We use them to perform an exact comparison. - CGAL_assertion (ps_org->has_parameter() && pt_org->has_parameter()); + CGAL_assertion(ps_org->has_parameter() && pt_org->has_parameter()); - t_res = CGAL::compare (ps_org->parameter(), pt_org->parameter()); + t_res = CGAL::compare(ps_org->parameter(), pt_org->parameter()); } - CGAL_precondition (t_res != EQUAL); + CGAL_precondition(t_res != EQUAL); - if (_dir_right) - _inc_to_right = (t_res == SMALLER); - else - _inc_to_right = (t_res == LARGER); + if (_dir_right) _inc_to_right = (t_res == SMALLER); + else _inc_to_right = (t_res == LARGER); } // --------------------------------------------------------------------------- // Get the approximate parameter range defining the curve. // -template +template std::pair -_Bezier_x_monotone_2::parameter_range () const +_Bezier_x_monotone_2::parameter_range() const { // First try to use the approximate representation of the endpoints. - Originator_iterator s_org = _ps.get_originator (_curve, _xid); - CGAL_assertion (s_org != _ps.originators_end()); + Originator_iterator s_org = _ps.get_originator(_curve, _xid); + CGAL_assertion(s_org != _ps.originators_end()); - Originator_iterator t_org = _pt.get_originator (_curve, _xid); - CGAL_assertion (t_org != _pt.originators_end()); + Originator_iterator t_org = _pt.get_originator(_curve, _xid); + CGAL_assertion(t_org != _pt.originators_end()); - double t_src = (CGAL::to_double (s_org->point_bound().t_min) + - CGAL::to_double (s_org->point_bound().t_max)) / 2; - double t_trg = (CGAL::to_double (t_org->point_bound().t_min) + - CGAL::to_double (t_org->point_bound().t_max)) / 2; + double t_src = (CGAL::to_double(s_org->point_bound().t_min) + + CGAL::to_double(s_org->point_bound().t_max)) / 2; + double t_trg = (CGAL::to_double(t_org->point_bound().t_min) + + CGAL::to_double(t_org->point_bound().t_max)) / 2; - return (std::make_pair (t_src, t_trg)); + return (std::make_pair(t_src, t_trg)); } // --------------------------------------------------------------------------- // Get the relative position of the query point with respect to the subcurve. // -template +template Comparison_result -_Bezier_x_monotone_2::point_position - (const Point_2& p, - Bezier_cache& cache) const +_Bezier_x_monotone_2:: +point_position(const Point_2& p, Bezier_cache& cache) const { Nt_traits nt_traits; //First check if the bezier is a vertical segment - if (is_vertical()) - { - if (! p.is_exact()) p.make_exact (cache); - if (! _ps.is_exact()) _ps.make_exact (cache); - if (! _pt.is_exact()) _ps.make_exact (cache); + if (is_vertical()) { + if (! p.is_exact()) p.make_exact(cache); + if (! _ps.is_exact()) _ps.make_exact(cache); + if (! _pt.is_exact()) _ps.make_exact(cache); - if (p.is_rational() && _ps.is_rational() && _pt.is_rational()) - { + if (p.is_rational() && _ps.is_rational() && _pt.is_rational()) { const Rat_point_2& rat_p = (Rat_point_2) p; const Rat_point_2& rat_ps = (Rat_point_2) _ps; const Rat_point_2& rat_pt = (Rat_point_2) _pt; - Comparison_result res1 = (CGAL::compare (rat_p.y(), rat_ps.y())); - Comparison_result res2 = (CGAL::compare (rat_p.y(), rat_pt.y())); - return (res1==res2 ? res1:EQUAL); + Comparison_result res1 = (CGAL::compare(rat_p.y(), rat_ps.y())); + Comparison_result res2 = (CGAL::compare(rat_p.y(), rat_pt.y())); + return (res1== res2 ? res1:EQUAL); } - Comparison_result res1 = (CGAL::compare (p.y(), _ps.y())); - Comparison_result res2 = (CGAL::compare (p.y(), _pt.y())); - return (res1==res2 ? res1:EQUAL); + Comparison_result res1 = (CGAL::compare(p.y(), _ps.y())); + Comparison_result res2 = (CGAL::compare(p.y(), _pt.y())); + return (res1== res2 ? res1:EQUAL); } if (p.identical(_ps)) { @@ -757,106 +690,99 @@ _Bezier_x_monotone_2::point_position // Then check whether the bezier is an horizontal segment or // if p has the same x-coordinate as one of the endpoint - const Comparison_result res1 = p.compare_x (_ps, cache); + const Comparison_result res1 = p.compare_x(_ps, cache); if (res1 == EQUAL || nt_traits.degree(_curve.y_polynomial()) <= 0) { - if (! p.is_exact()) p.make_exact (cache); - if (! _ps.is_exact()) _ps.make_exact (cache); + if (! p.is_exact()) p.make_exact(cache); + if (! _ps.is_exact()) _ps.make_exact(cache); // If both point are rational, compare their rational y-coordinates. if (p.is_rational() && _ps.is_rational()) { - const Rat_point_2& rat_p = (Rat_point_2) p; - const Rat_point_2& rat_ps = (Rat_point_2) _ps; + const Rat_point_2& rat_p = (Rat_point_2) p; + const Rat_point_2& rat_ps = (Rat_point_2) _ps; - return (CGAL::compare (rat_p.y(), rat_ps.y())); + return (CGAL::compare(rat_p.y(), rat_ps.y())); } // Compare the algebraic y-coordinates. - return (CGAL::compare (p.y(), _ps.y())); + return (CGAL::compare(p.y(), _ps.y())); } - if (p.identical(_pt)) { - return EQUAL; - } + if (p.identical(_pt)) return EQUAL; - const Comparison_result res2 = p.compare_x (_pt, cache); + const Comparison_result res2 = p.compare_x(_pt, cache); - if (res2 == EQUAL) - { + if (res2 == EQUAL) { // In this case both points must be exact. - CGAL_assertion (p.is_exact() && _pt.is_exact()); + CGAL_assertion(p.is_exact() && _pt.is_exact()); // If both point are rational, compare their rational y-coordinates. - if (p.is_rational() && _pt.is_rational()) - { - const Rat_point_2& rat_p = (Rat_point_2) p; - const Rat_point_2& rat_pt = (Rat_point_2) _pt; + if (p.is_rational() && _pt.is_rational()) { + const Rat_point_2& rat_p = (Rat_point_2) p; + const Rat_point_2& rat_pt = (Rat_point_2) _pt; - return (CGAL::compare (rat_p.y(), rat_pt.y())); + return (CGAL::compare(rat_p.y(), rat_pt.y())); } // Compare the algebraic y-coordinates. - return (CGAL::compare (p.y(), _pt.y())); + return (CGAL::compare(p.y(), _pt.y())); } // Make sure that p is in the x-range of our subcurve. - CGAL_precondition (res1 != res2); + CGAL_precondition(res1 != res2); // Check for the case when curve is an originator of the point. - Originator_iterator p_org = p.get_originator (_curve, _xid); + Originator_iterator p_org = p.get_originator(_curve, _xid); - if (p_org != p.originators_end()) - { + if (p_org != p.originators_end()) { CGAL_assertion_code - (Originator_iterator ps_org = _ps.get_originator (_curve, _xid); + (Originator_iterator ps_org = _ps.get_originator(_curve, _xid); CGAL_assertion(ps_org != _ps.originators_end()); - Originator_iterator pt_org = _pt.get_originator (_curve, _xid); + Originator_iterator pt_org = _pt.get_originator(_curve, _xid); CGAL_assertion(pt_org != _pt.originators_end())); // Check if the point is in the parameter range of this subcurve. // First try an approximate check of the parameter bounds. - bool correct_res; - bool in_range = false; + bool correct_res; + bool in_range = false; - in_range = _is_in_range (p, correct_res); + in_range = _is_in_range(p, correct_res); - if (! correct_res) - { + if (! correct_res) { // Perform the comparsion in an exact manner. if (! p.is_exact()) - p.make_exact (cache); + p.make_exact(cache); - CGAL_assertion (p_org->has_parameter()); + CGAL_assertion(p_org->has_parameter()); - in_range = _is_in_range (p_org->parameter(), cache); + in_range = _is_in_range(p_org->parameter(), cache); } - if (in_range) - return (EQUAL); + if (in_range) return (EQUAL); } // Call the vertical-position function that uses the bounding-boxes // to evaluate the comparsion result. - typename Bounding_traits::Control_points cp; + typename Bounding_traits::Control_points cp; - std::copy (_curve.control_points_begin(), _curve.control_points_end(), - std::back_inserter(cp)); + std::copy(_curve.control_points_begin(), _curve.control_points_end(), + std::back_inserter(cp)); - Originator_iterator ps_org = _ps.get_originator (_curve, _xid); - CGAL_assertion (ps_org != _ps.originators_end()); + Originator_iterator ps_org = _ps.get_originator(_curve, _xid); + CGAL_assertion(ps_org != _ps.originators_end()); - Originator_iterator pt_org = _pt.get_originator (_curve, _xid); - CGAL_assertion (pt_org != _pt.originators_end()); + Originator_iterator pt_org = _pt.get_originator(_curve, _xid); + CGAL_assertion(pt_org != _pt.originators_end()); - Comparison_result res_bound = EQUAL; - typename Bounding_traits::NT x_min, y_min, x_max, y_max; - bool can_refine; + Comparison_result res_bound = EQUAL; + typename Bounding_traits::NT x_min, y_min, x_max, y_max; + bool can_refine; - p.get_bbox (x_min, y_min, x_max, y_max); + p.get_bbox(x_min, y_min, x_max, y_max); - if (CGAL::compare (ps_org->point_bound().t_max, + if (CGAL::compare(ps_org->point_bound().t_max, pt_org->point_bound().t_min) == SMALLER) { // Examine the parameter range of the originator of the source point @@ -866,14 +792,13 @@ _Bezier_x_monotone_2::point_position can_refine = ! _ps.is_exact(); do { - const Rat_point_2& ps = _curve (ps_org->point_bound().t_max); + const Rat_point_2& ps = _curve(ps_org->point_bound().t_max); - if ((_dir_right && CGAL::compare (ps.x(), x_min) != LARGER) || - (! _dir_right && CGAL::compare (ps.x(), x_max) != SMALLER)) + if ((_dir_right && CGAL::compare(ps.x(), x_min) != LARGER) || + (! _dir_right && CGAL::compare(ps.x(), x_max) != SMALLER)) break; - if (can_refine) - can_refine = _ps.refine(); + if (can_refine) can_refine = _ps.refine(); } while (can_refine); // Examine the parameter range of the originator of the target point @@ -883,10 +808,10 @@ _Bezier_x_monotone_2::point_position can_refine = ! _pt.is_exact(); do { - const Rat_point_2& pt = _curve (pt_org->point_bound().t_min); + const Rat_point_2& pt = _curve(pt_org->point_bound().t_min); - if ((_dir_right && CGAL::compare (pt.x(), x_max) != SMALLER) || - (! _dir_right && CGAL::compare (pt.x(), x_min) != LARGER)) + if ((_dir_right && CGAL::compare(pt.x(), x_max) != SMALLER) || + (! _dir_right && CGAL::compare(pt.x(), x_min) != LARGER)) break; if (can_refine) @@ -896,11 +821,11 @@ _Bezier_x_monotone_2::point_position // In this case the parameter value of the source is smaller than the // target's, so we compare the point with the subcurve of B defined over // the proper parameter range. - res_bound = p.vertical_position (cp, + res_bound = p.vertical_position(cp, ps_org->point_bound().t_max, pt_org->point_bound().t_min); } - else if (CGAL::compare (pt_org->point_bound().t_max, + else if (CGAL::compare(pt_org->point_bound().t_max, ps_org->point_bound().t_min) == SMALLER) { // Examine the parameter range of the originator of the source point @@ -908,12 +833,11 @@ _Bezier_x_monotone_2::point_position // lies to the left of p if the curve is directed from left to right // (or to the right of p, if the subcurve is directed from right to left). can_refine = ! _ps.is_exact(); - do - { - const Rat_point_2& ps = _curve (ps_org->point_bound().t_min); + do { + const Rat_point_2& ps = _curve(ps_org->point_bound().t_min); - if ((_dir_right && CGAL::compare (ps.x(), x_min) != LARGER) || - (! _dir_right && CGAL::compare (ps.x(), x_max) != SMALLER)) + if ((_dir_right && CGAL::compare(ps.x(), x_min) != LARGER) || + (! _dir_right && CGAL::compare(ps.x(), x_max) != SMALLER)) break; if (can_refine) @@ -925,12 +849,11 @@ _Bezier_x_monotone_2::point_position // lies to the right of p if the curve is directed from left to right // (or to the left of p, if the subcurve is directed from right to left). can_refine = ! _pt.is_exact(); - do - { - const Rat_point_2& pt = _curve (pt_org->point_bound().t_max); + do { + const Rat_point_2& pt = _curve(pt_org->point_bound().t_max); - if ((_dir_right && CGAL::compare (pt.x(), x_max) != SMALLER) || - (! _dir_right && CGAL::compare (pt.x(), x_min) != LARGER)) + if ((_dir_right && CGAL::compare(pt.x(), x_max) != SMALLER) || + (! _dir_right && CGAL::compare(pt.x(), x_min) != LARGER)) break; if (can_refine) @@ -940,7 +863,7 @@ _Bezier_x_monotone_2::point_position // In this case the parameter value of the source is large than the // target's, so we compare the point with the subcurve of B defined over // the proper parameter range. - res_bound = p.vertical_position (cp, + res_bound = p.vertical_position(cp, pt_org->point_bound().t_max, ps_org->point_bound().t_min); } @@ -960,13 +883,14 @@ _Bezier_x_monotone_2::point_position std::vector roots; std::pair prange = parameter_range(); - nt_traits.compute_polynomial_roots (poly_x,prange.first,prange.second,std::back_inserter(roots)); + nt_traits.compute_polynomial_roots(poly_x,prange.first,prange.second, std::back_inserter(roots)); - CGAL_assertion(roots.size()==1); //p is in the range and the curve is x-monotone + //p is in the range and the curve is x-monotone + CGAL_assertion(roots.size() == 1); return CGAL::compare( ((Rat_point_2) p).y(), - nt_traits.evaluate_at (_curve.y_polynomial(), *roots.begin()) + nt_traits.evaluate_at(_curve.y_polynomial(), *roots.begin()) ); } @@ -974,22 +898,22 @@ _Bezier_x_monotone_2::point_position // p lies of the given subcurve. We take one of p's originating curves and // compute its intersections with our x-monotone curve. if (! p.is_exact()) - p.make_exact (cache); + p.make_exact(cache); - CGAL_assertion (p.originators_begin() != p.originators_end()); + CGAL_assertion(p.originators_begin() != p.originators_end()); Originator org = *(p.originators_begin()); bool do_ovlp; bool swap_order = (_curve.id() > org.curve().id()); const Intersect_list& inter_list = (! swap_order ? - (cache.get_intersections (_curve.id(), + (cache.get_intersections(_curve.id(), _curve.x_polynomial(), _curve.x_norm(), _curve.y_polynomial(), _curve.y_norm(), org.curve().id(), org.curve().x_polynomial(), org.curve().x_norm(), org.curve().y_polynomial(), org.curve().y_norm(), do_ovlp)) : - (cache.get_intersections (org.curve().id(), + (cache.get_intersections(org.curve().id(), org.curve().x_polynomial(), org.curve().x_norm(), org.curve().y_polynomial(), org.curve().y_norm(), _curve.id(), @@ -997,29 +921,24 @@ _Bezier_x_monotone_2::point_position _curve.y_polynomial(), _curve.y_norm(), do_ovlp))); - if (do_ovlp) - return (EQUAL); + if (do_ovlp) return EQUAL; // Go over the intersection points and look for p there. - Intersect_iter iit; - - for (iit = inter_list.begin(); iit != inter_list.end(); ++iit) - { + for (auto iit = inter_list.begin(); iit != inter_list.end(); ++iit) { // Get the parameter of the originator and compare it to p's parameter. - const Algebraic& s = swap_order ? iit->s : iit->t; + const Algebraic& s = swap_order ? iit->s : iit->t; - if (CGAL::compare (s, org.parameter()) == EQUAL) - { + if (CGAL::compare(s, org.parameter()) == EQUAL) { // Add this curve as an originator for p. - const Algebraic& t = swap_order ? iit->t : iit->s; + const Algebraic& t = swap_order ? iit->t : iit->s; - CGAL_assertion (_is_in_range (t, cache)); + CGAL_assertion(_is_in_range(t, cache)); - Point_2& pt = const_cast (p); + Point_2& pt = const_cast(p); pt.add_originator (Originator (_curve, _xid, t)); // The point p lies on the subcurve. - return (EQUAL); + return EQUAL; } } @@ -1028,21 +947,14 @@ _Bezier_x_monotone_2::point_position // between the curve and the point. (This case should be very rare.) // Note that we first try to work with inexact endpoint representation, and // only if we fail we make the endpoints of the x-monotone curves exact. - if (! p.is_exact()) - p.make_exact (cache); + if (! p.is_exact()) p.make_exact (cache); - Comparison_result exact_res = _exact_vertical_position (p, false); + Comparison_result exact_res = _exact_vertical_position(p, false); + if (exact_res != EQUAL) return (exact_res); + if (! _ps.is_exact()) _ps.make_exact(cache); + if (! _pt.is_exact()) _pt.make_exact(cache); - if (exact_res != EQUAL) - return (exact_res); - - if (! _ps.is_exact()) - _ps.make_exact (cache); - - if (! _pt.is_exact()) - _pt.make_exact (cache); - - return (_exact_vertical_position (p, true)); + return (_exact_vertical_position(p, true)); } // --------------------------------------------------------------------------- @@ -1051,57 +963,45 @@ _Bezier_x_monotone_2::point_position // template Comparison_result -_Bezier_x_monotone_2::compare_to_right - (const Self& cv, - const Point_2& p, - Bezier_cache& cache) const +_Bezier_x_monotone_2:: +compare_to_right(const Self& cv, + const Point_2& p, + Bezier_cache& cache) const { CGAL_precondition (p.compare_xy (right(), cache) != LARGER); CGAL_precondition (p.compare_xy (cv.right(), cache) != LARGER); - if (this == &cv) - return (EQUAL); + if (this == &cv) return EQUAL; // Make sure that p is incident to both curves (either equals the left // endpoint or lies in the curve interior). Note that this is important to // carry out these tests, as it assures us the eventually both curves are // originators of p. - if (! p.equals (left(), cache)) - { - if (point_position (p, cache) != EQUAL) - { + if (! p.equals (left(), cache)) { + if (point_position (p, cache) != EQUAL) { CGAL_precondition_msg (false, "p is not on cv1"); } } - if (! p.equals (cv.left(), cache)) - { - if (cv.point_position (p, cache) != EQUAL) - { + if (! p.equals (cv.left(), cache)) { + if (cv.point_position (p, cache) != EQUAL) { CGAL_precondition_msg (false, "p is not on cv2"); } } // Check for vertical subcurves. A vertical segment is above any other // x-monotone subcurve to the right of their common endpoint. - if (is_vertical()) - { - if (cv.is_vertical()) - // Both are vertical segments with a common endpoint, so they overlap: - return (EQUAL); - + if (is_vertical()) { + // Both are vertical segments with a common endpoint, so they overlap: + if (cv.is_vertical()) return (EQUAL); return (LARGER); } - else if (cv.is_vertical()) - { - return (SMALLER); - } + else if (cv.is_vertical()) return (SMALLER); // Check if both subcurves originate from the same Bezier curve. - Nt_traits nt_traits; + Nt_traits nt_traits; - if (_curve.is_same (cv._curve)) - { + if (_curve.is_same (cv._curve)) { // Get the originator, and check whether p is a vertical tangency // point of this originator (otherwise it is a self-intersection point, // and we proceed as if it is a regular intersection point). @@ -1109,24 +1009,20 @@ _Bezier_x_monotone_2::compare_to_right CGAL_assertion (org != p.originators_end()); - if (org->point_bound().type == Bez_point_bound::VERTICAL_TANGENCY_PT) - { + if (org->point_bound().type == Bez_point_bound::VERTICAL_TANGENCY_PT) { CGAL_assertion (_inc_to_right != cv._inc_to_right); - if (! p.is_exact()) - { + if (! p.is_exact()) { // Comparison based on the control polygon of the bounded vertical // tangency point, using the fact this polygon is y-monotone. const typename Bounding_traits::Control_points& cp = org->point_bound().ctrl; - if (_inc_to_right) - { - return (CGAL::compare (cp.back().y(), cp.front().y())); + if (_inc_to_right) { + return (CGAL::compare(cp.back().y(), cp.front().y())); } - else - { - return (CGAL::compare (cp.front().y(), cp.back().y())); + else { + return (CGAL::compare(cp.front().y(), cp.back().y())); } } @@ -1135,14 +1031,14 @@ _Bezier_x_monotone_2::compare_to_right // In this case we know that we have a vertical tangency at t0, so // X'(t0) = 0. We evaluate the sign of Y'(t0) in order to find the // vertical position of the two subcurves to the right of this point. - CGAL_assertion (org->has_parameter()); + CGAL_assertion(org->has_parameter()); - const Algebraic& t0 = org->parameter(); - Polynomial polyY_der = nt_traits.derive (_curve.y_polynomial()); - const CGAL::Sign sign_der = - CGAL::sign (nt_traits.evaluate_at (polyY_der, t0)); + const Algebraic& t0 = org->parameter(); + Polynomial polyY_der = nt_traits.derive(_curve.y_polynomial()); + const CGAL::Sign sign_der = + CGAL::sign(nt_traits.evaluate_at(polyY_der, t0)); - CGAL_assertion (sign_der != CGAL::ZERO); + CGAL_assertion(sign_der != CGAL::ZERO); if (_inc_to_right) return ((sign_der == CGAL::POSITIVE) ? LARGER : SMALLER); @@ -1154,28 +1050,27 @@ _Bezier_x_monotone_2::compare_to_right // Compare the slopes of the two supporting curves at p. In the general // case, the slopes are not equal and their comparison gives us the // vertical order to p's right. - Comparison_result slope_res = _compare_slopes (cv, p, cache); + Comparison_result slope_res = _compare_slopes(cv, p, cache); - if (slope_res != EQUAL) - return (slope_res); + if (slope_res != EQUAL) return (slope_res); // Compare the two subcurves by choosing some point to the right of p // and comparing the vertical position there. Comparison_result right_res; - if (right().compare_x (cv.right(), cache) != LARGER) + if (right().compare_x(cv.right(), cache) != LARGER) { - right_res = _compare_to_side (cv, p, + right_res = _compare_to_side(cv, p, true, // Compare to p's right. cache); } else { - right_res = cv._compare_to_side (*this, p, + right_res = cv._compare_to_side(*this, p, true, // Compare to p's right. cache); - right_res = CGAL::opposite (right_res); + right_res = CGAL::opposite(right_res); } return (right_res); @@ -1192,8 +1087,8 @@ _Bezier_x_monotone_2::compare_to_left const Point_2& p, Bezier_cache& cache) const { - CGAL_precondition (p.compare_xy (left(), cache) != SMALLER); - CGAL_precondition (p.compare_xy (cv.left(), cache) != SMALLER); + CGAL_precondition(p.compare_xy(left(), cache) != SMALLER); + CGAL_precondition(p.compare_xy(cv.left(), cache) != SMALLER); if (this == &cv) return (EQUAL); @@ -1202,19 +1097,19 @@ _Bezier_x_monotone_2::compare_to_left // endpoint or lies in the curve interior). Note that this is important to // carry out these tests, as it assures us the eventually both curves are // originators of p. - if (! p.equals (right(), cache)) + if (! p.equals(right(), cache)) { - if (point_position (p, cache) != EQUAL) + if (point_position(p, cache) != EQUAL) { - CGAL_precondition_msg (false, "p is not on cv1"); + CGAL_precondition_msg(false, "p is not on cv1"); } } - if (! p.equals (cv.right(), cache)) + if (! p.equals(cv.right(), cache)) { - if (cv.point_position (p, cache) != EQUAL) + if (cv.point_position(p, cache) != EQUAL) { - CGAL_precondition_msg (false, "p is not on cv2"); + CGAL_precondition_msg(false, "p is not on cv2"); } } @@ -1236,15 +1131,15 @@ _Bezier_x_monotone_2::compare_to_left // Check if both subcurves originate from the same Bezier curve. Nt_traits nt_traits; - if (_curve.is_same (cv._curve)) + if (_curve.is_same(cv._curve)) { // Get the originator, and check whether p is a vertical tangency // point of this originator (otherwise it is a self-intersection point, // and we proceed as if it is a regular intersection point). - Originator_iterator org = p.get_originator (_curve, _xid); + Originator_iterator org = p.get_originator(_curve, _xid); - CGAL_assertion (org != p.originators_end()); - CGAL_assertion (_inc_to_right != cv._inc_to_right); + CGAL_assertion(org != p.originators_end()); + CGAL_assertion(_inc_to_right != cv._inc_to_right); if (org->point_bound().type == Bez_point_bound::VERTICAL_TANGENCY_PT) { @@ -1270,14 +1165,14 @@ _Bezier_x_monotone_2::compare_to_left // In this case we know that we have a vertical tangency at t0, so // X'(t0) = 0. We evaluate the sign of Y'(t0) in order to find the // vertical position of the two subcurves to the right of this point. - CGAL_assertion (org->has_parameter()); + CGAL_assertion(org->has_parameter()); const Algebraic& t0 = org->parameter(); - Polynomial polyY_der = nt_traits.derive (_curve.y_polynomial()); + Polynomial polyY_der = nt_traits.derive(_curve.y_polynomial()); const CGAL::Sign sign_der = - CGAL::sign (nt_traits.evaluate_at (polyY_der, t0)); + CGAL::sign(nt_traits.evaluate_at(polyY_der, t0)); - CGAL_assertion (sign_der != CGAL::ZERO); + CGAL_assertion(sign_der != CGAL::ZERO); if (_inc_to_right) return ((sign_der == CGAL::NEGATIVE) ? LARGER : SMALLER); @@ -1290,7 +1185,7 @@ _Bezier_x_monotone_2::compare_to_left // case, the slopes are not equal and their comparison gives us the // vertical order to p's right; note that we swap the order of the curves // to obtains their position to the left. - Comparison_result slope_res = cv._compare_slopes (*this, p, cache); + Comparison_result slope_res = cv._compare_slopes(*this, p, cache); if (slope_res != EQUAL) return (slope_res); @@ -1299,18 +1194,18 @@ _Bezier_x_monotone_2::compare_to_left // and compareing the vertical position there. Comparison_result left_res; - if (left().compare_x (cv.left(), cache) != SMALLER) + if (left().compare_x(cv.left(), cache) != SMALLER) { - left_res = _compare_to_side (cv, p, + left_res = _compare_to_side(cv, p, false, // Compare to p's left. cache); } else { - left_res = cv._compare_to_side (*this, p, + left_res = cv._compare_to_side(*this, p, false, // Compare to p's left. cache); - left_res = CGAL::opposite (left_res); + left_res = CGAL::opposite(left_res); } return (left_res); @@ -1325,7 +1220,7 @@ bool _Bezier_x_monotone_2::equals Bezier_cache& cache) const { // Check if the two subcurves have overlapping supporting curves. - if (! _curve.is_same (cv._curve)) + if (! _curve.is_same(cv._curve)) { //special case when curves are vertical if (cv.is_vertical()){ @@ -1335,7 +1230,7 @@ bool _Bezier_x_monotone_2::equals } // Check whether the two curves have the same support: - if (! _curve.has_same_support (cv._curve)) + if (! _curve.has_same_support(cv._curve)) return (false); // Mark that the two curves overlap in the cache. @@ -1343,14 +1238,14 @@ bool _Bezier_x_monotone_2::equals const Curve_id id2 = cv._curve.id(); if (id1 < id2) - cache.mark_as_overlapping (id1, id2); + cache.mark_as_overlapping(id1, id2); else - cache.mark_as_overlapping (id2, id1); + cache.mark_as_overlapping(id2, id1); } // Check for equality of the endpoints. - return (left().equals (cv.left(), cache) && - right().equals (cv.right(), cache)); + return (left().equals(cv.left(), cache) && + right().equals(cv.right(), cache)); } // --------------------------------------------------------------------------- @@ -1406,9 +1301,9 @@ bool _Bezier_x_monotone_2::can_merge_with { // Note that we only allow merging subcurves of the same originating // Bezier curve (overlapping curves will not do in this case). - return (_curve.is_same (cv._curve) && + return (_curve.is_same(cv._curve) && _xid == cv._xid && - (right().is_same (cv.left()) || left().is_same (cv.right()))); + (right().is_same(cv.left()) || left().is_same(cv.right()))); return (false); } @@ -1421,28 +1316,22 @@ typename _Bezier_x_monotone_2::Self _Bezier_x_monotone_2::merge (const Self& cv) const { - CGAL_precondition (_curve.is_same (cv._curve)); - CGAL_precondition (_xid == cv._xid); + CGAL_precondition(_curve.is_same(cv._curve)); + CGAL_precondition(_xid == cv._xid); - Self res = *this; + Self res = *this; - if (right().is_same (cv.left())) - { + if (right().is_same(cv.left())) { // Extend the subcurve to the right. - if (_dir_right) - res._pt = cv.right(); - else - res._ps = cv.right(); + if (_dir_right) res._pt = cv.right(); + else res._ps = cv.right(); } - else - { - CGAL_precondition (left().is_same (cv.right())); + else { + CGAL_precondition(left().is_same(cv.right())); // Extend the subcurve to the left. - if (_dir_right) - res._ps = cv.left(); - else - res._pt = cv.left(); + if (_dir_right) res._ps = cv.left(); + else res._pt = cv.left(); } return (res); @@ -1451,42 +1340,35 @@ _Bezier_x_monotone_2::merge // --------------------------------------------------------------------------- // Check if the given t-value is in the range of the subcurve. // -template -bool _Bezier_x_monotone_2::_is_in_range - (const Algebraic& t, - Bezier_cache& cache) const +template +bool _Bezier_x_monotone_2:: +_is_in_range(const Algebraic& t, Bezier_cache& cache) const { // First try to use the approximate representation of the endpoints. - Originator_iterator s_org = _ps.get_originator (_curve, _xid); - CGAL_assertion (s_org != _ps.originators_end()); + Originator_iterator s_org = _ps.get_originator(_curve, _xid); + CGAL_assertion(s_org != _ps.originators_end()); - Originator_iterator t_org = _pt.get_originator (_curve, _xid); - CGAL_assertion (t_org != _pt.originators_end()); + Originator_iterator t_org = _pt.get_originator (_curve, _xid); + CGAL_assertion(t_org != _pt.originators_end()); - Nt_traits nt_traits; + Nt_traits nt_traits; - bool p_lt_ps = - (CGAL::compare (t, nt_traits.convert (s_org->point_bound().t_min)) == - SMALLER); - bool p_gt_ps = - (CGAL::compare (t, nt_traits.convert (s_org->point_bound().t_max)) == - LARGER); - bool p_lt_pt = - (CGAL::compare (t, nt_traits.convert (t_org->point_bound().t_min)) == - SMALLER); - bool p_gt_pt = - (CGAL::compare (t, nt_traits.convert (t_org->point_bound().t_max)) == - LARGER); + bool p_lt_ps = + CGAL::compare(t, nt_traits.convert(s_org->point_bound().t_min)) == SMALLER; + bool p_gt_ps = + CGAL::compare(t, nt_traits.convert(s_org->point_bound().t_max)) == LARGER; + bool p_lt_pt = + CGAL::compare(t, nt_traits.convert(t_org->point_bound().t_min)) == SMALLER; + bool p_gt_pt = + CGAL::compare(t, nt_traits.convert(t_org->point_bound().t_max)) == LARGER; - if ((p_gt_ps && p_lt_pt) || (p_lt_ps && p_gt_pt)) - { + if ((p_gt_ps && p_lt_pt) || (p_lt_ps && p_gt_pt)) { // The point p is definitely in the x-range of the subcurve, as its // parameter is between the source and target parameters. - return (true); + return true; } - if ((p_lt_ps && p_lt_pt) || (p_gt_ps && p_gt_pt)) - { + if ((p_lt_ps && p_lt_pt) || (p_gt_ps && p_gt_pt)) { // The point p is definitely not in the x-range of the subcurve, // as its parameter is smaller than both source and target parameter // (or greater than both of them). @@ -1507,60 +1389,54 @@ bool _Bezier_x_monotone_2::_is_in_range // --------------------------------------------------------------------------- // Check if the given point lies in the range of this x-monotone subcurve. // -template -bool _Bezier_x_monotone_2::_is_in_range - (const Point_2& p, - bool& is_certain) const +template +bool _Bezier_x_monotone_2:: +_is_in_range(const Point_2& p, bool& is_certain) const { is_certain = true; // Check the easy case that p is one of the subcurve endpoints. - if (p.is_same(_ps) || p.is_same(_pt)) - return true; + if (p.is_same(_ps) || p.is_same(_pt)) return true; // Compare the parameter of p with the parameters of the endpoints. - Originator_iterator p_org = p.get_originator (_curve, _xid); + Originator_iterator p_org = p.get_originator(_curve, _xid); - if (p_org == p.originators_end()) - { - CGAL_assertion (p.get_originator (_curve) != p.originators_end()); + if (p_org == p.originators_end()) { + CGAL_assertion(p.get_originator(_curve) != p.originators_end()); // In this case a different x-monotone curve of the supporting Bezier // curve is an originator of the point, so we know that p does not // lie in the range of our x-monotone subcurve. - return (false); + return false; } - Originator_iterator s_org = _ps.get_originator (_curve, _xid); - CGAL_assertion (s_org != _ps.originators_end()); + Originator_iterator s_org = _ps.get_originator(_curve, _xid); + CGAL_assertion(s_org != _ps.originators_end()); - Originator_iterator t_org = _pt.get_originator (_curve, _xid); - CGAL_assertion (t_org != _pt.originators_end()); + Originator_iterator t_org = _pt.get_originator(_curve, _xid); + CGAL_assertion(t_org != _pt.originators_end()); - bool can_refine_p = ! p.is_exact(); - bool can_refine_s = ! _ps.is_exact(); - bool can_refine_t = ! _pt.is_exact(); + bool can_refine_p = ! p.is_exact(); + bool can_refine_s = ! _ps.is_exact(); + bool can_refine_t = ! _pt.is_exact(); - while (can_refine_p || can_refine_s || can_refine_t) - { - bool p_lt_ps = (CGAL::compare (p_org->point_bound().t_max, - s_org->point_bound().t_min) == SMALLER); - bool p_gt_ps = (CGAL::compare (p_org->point_bound().t_min, - s_org->point_bound().t_max) == LARGER); - bool p_lt_pt = (CGAL::compare (p_org->point_bound().t_max, - t_org->point_bound().t_min) == SMALLER); - bool p_gt_pt = (CGAL::compare (p_org->point_bound().t_min, - t_org->point_bound().t_max) == LARGER); + while (can_refine_p || can_refine_s || can_refine_t) { + bool p_lt_ps = (CGAL::compare(p_org->point_bound().t_max, + s_org->point_bound().t_min) == SMALLER); + bool p_gt_ps = (CGAL::compare(p_org->point_bound().t_min, + s_org->point_bound().t_max) == LARGER); + bool p_lt_pt = (CGAL::compare(p_org->point_bound().t_max, + t_org->point_bound().t_min) == SMALLER); + bool p_gt_pt = (CGAL::compare(p_org->point_bound().t_min, + t_org->point_bound().t_max) == LARGER); - if ((p_gt_ps && p_lt_pt) || (p_lt_ps && p_gt_pt)) - { + if ((p_gt_ps && p_lt_pt) || (p_lt_ps && p_gt_pt)) { // The point p is definitely in the x-range of the subcurve, as its // parameter is between the source and target parameters. return (true); } - if ((p_lt_ps && p_lt_pt) || (p_gt_ps && p_gt_pt)) - { + if ((p_lt_ps && p_lt_pt) || (p_gt_ps && p_gt_pt)) { // The point p is definitely not in the x-range of the subcurve, // as its parameter is smaller than both source and target parameter // (or greater than both of them). @@ -1568,19 +1444,14 @@ bool _Bezier_x_monotone_2::_is_in_range } // Try to refine the points. - if (can_refine_p) - can_refine_p = p.refine(); - - if (can_refine_s) - can_refine_s = _ps.refine(); - - if (can_refine_t) - can_refine_t = _pt.refine(); + if (can_refine_p) can_refine_p = p.refine(); + if (can_refine_s) can_refine_s = _ps.refine(); + if (can_refine_t) can_refine_t = _pt.refine(); } // If we reached here, we do not have a certain answer. is_certain = false; - return (false); + return false; } // --------------------------------------------------------------------------- @@ -1588,35 +1459,32 @@ bool _Bezier_x_monotone_2::_is_in_range // determine whether p lies within the t-range of the x-monotone subcurve. // If so, the value t0 such that p = (X(t0), Y(t0)) is also computed. // -template -bool _Bezier_x_monotone_2::_is_in_range - (const Point_2& p, - Bezier_cache& cache, - Algebraic& t0, - bool& is_endpoint) const +template +bool _Bezier_x_monotone_2:: +_is_in_range(const Point_2& p, + Bezier_cache& cache, + Algebraic& t0, + bool& is_endpoint) const { // The given point p must be rational, otherwise there is no point checking // whether it lies in the interior of the curve. - if (! p.is_rational()) - { + if (! p.is_rational()) { is_endpoint = false; - return (false); + return false; } - const Rat_point_2& rat_p = (Rat_point_2) p; + const Rat_point_2& rat_p = (Rat_point_2) p; // Determine the parameter range [t_min, t_max] for our x-monotone // subcurve. - std::pair t_range = _t_range (cache); - Algebraic t_min, t_max; + std::pair t_range = _t_range (cache); + Algebraic t_min, t_max; - if ((_dir_right && _inc_to_right) || (! _dir_right && ! _inc_to_right)) - { + if ((_dir_right && _inc_to_right) || (! _dir_right && ! _inc_to_right)) { t_min = t_range.first; t_max = t_range.second; } - else - { + else { t_min = t_range.second; t_max = t_range.first; } @@ -1624,90 +1492,78 @@ bool _Bezier_x_monotone_2::_is_in_range // The given point p must lie on (X(t), Y(t)) for some t-value. Obtain the // parameter value t0 for that point. We start by computing all t-values // such that X(t) equals the x-coordinate of p. - Nt_traits nt_traits; - std::list t_vals; - typename std::list::iterator t_iter; - Comparison_result res1, res2; - Algebraic y0; + Nt_traits nt_traits; + std::list t_vals; + typename std::list::iterator t_iter; + Comparison_result res1, res2; + Algebraic y0; - if ( is_vertical() ){ - if ( compare(rat_p.x(),left().x())==EQUAL ){ - _curve.get_t_at_y (rat_p.y(), std::back_inserter(t_vals)); + if (is_vertical()){ + if ( compare(rat_p.x(),left().x()) == EQUAL) { + _curve.get_t_at_y(rat_p.y(), std::back_inserter(t_vals)); - for (t_iter = t_vals.begin(); t_iter != t_vals.end(); ++t_iter) - { + for (t_iter = t_vals.begin(); t_iter != t_vals.end(); ++t_iter) { // Compare the current t-value with t_min. - res1 = CGAL::compare (t_min, *t_iter); + res1 = CGAL::compare(t_min, *t_iter); - if (res1 == LARGER) - continue; + if (res1 == LARGER) continue; - - if (res1 == EQUAL) - { + if (res1 == EQUAL) { t0 = t_min; is_endpoint = true; return (true); } // Compare the current t-value with t_max. - res2 = CGAL::compare (t_max, *t_iter); + res2 = CGAL::compare(t_max, *t_iter); - if (res2 == EQUAL) - { + if (res2 == EQUAL) { t0 = t_max; is_endpoint = true; - return (true); + return true; } - if (res2 == LARGER) - { + if (res2 == LARGER) { t0 = *t_iter; is_endpoint = false; - return (true); + return true; } } } is_endpoint = false; - return (false); + return false; } - _curve.get_t_at_x (rat_p.x(), std::back_inserter(t_vals)); - CGAL_assertion (! t_vals.empty() ); + _curve.get_t_at_x(rat_p.x(), std::back_inserter(t_vals)); + CGAL_assertion(! t_vals.empty() ); - for (t_iter = t_vals.begin(); t_iter != t_vals.end(); ++t_iter) - { + for (t_iter = t_vals.begin(); t_iter != t_vals.end(); ++t_iter) { // Compare the current t-value with t_min. res1 = CGAL::compare (t_min, *t_iter); - if (res1 == LARGER) - continue; + if (res1 == LARGER) continue; // Make sure the y-coordinates match. - y0 = nt_traits.evaluate_at (_curve.y_polynomial(), *t_iter) / - nt_traits.convert (_curve.y_norm()); + y0 = nt_traits.evaluate_at(_curve.y_polynomial(), *t_iter) / + nt_traits.convert(_curve.y_norm()); - if (CGAL::compare (nt_traits.convert (rat_p.y()), y0) == EQUAL) - { - if (res1 == EQUAL) - { + if (CGAL::compare(nt_traits.convert(rat_p.y()), y0) == EQUAL) { + if (res1 == EQUAL) { t0 = t_min; is_endpoint = true; - return (true); + return true; } // Compare the current t-value with t_max. res2 = CGAL::compare (t_max, *t_iter); - if (res2 == EQUAL) - { + if (res2 == EQUAL) { t0 = t_max; is_endpoint = true; return (true); } - if (res2 == LARGER) - { + if (res2 == LARGER) { t0 = *t_iter; is_endpoint = false; return (true); @@ -1718,53 +1574,48 @@ bool _Bezier_x_monotone_2::_is_in_range // In this case, we have not found a t-value in the range of our subcurve, // so p does not lie on the subcurve: is_endpoint = false; - return (false); + return false; } // --------------------------------------------------------------------------- // Compute a y-coordinate of a point on the x-monotone subcurve with a // given x-coordinate. // -template +template typename _Bezier_x_monotone_2::Algebraic -_Bezier_x_monotone_2::_get_y - (const Rational& x0, - Bezier_cache& cache) const +_Bezier_x_monotone_2:: +_get_y(const Rational& x0, Bezier_cache& cache) const { // Obtain the t-values for with the x-coordinates of the supporting // curve equal x0. - std::list t_vals; + std::list t_vals; - _curve.get_t_at_x (x0, std::back_inserter(t_vals)); + _curve.get_t_at_x(x0, std::back_inserter(t_vals)); // Find a t-value that is in the range of the current curve. - Nt_traits nt_traits; - typename std::list::iterator t_iter; - std::pair t_range = _t_range (cache); - const Algebraic& t_src = t_range.first; - const Algebraic& t_trg = t_range.second; - Comparison_result res1, res2; + Nt_traits nt_traits; + typename std::list::iterator t_iter; + std::pair t_range = _t_range (cache); + const Algebraic& t_src = t_range.first; + const Algebraic& t_trg = t_range.second; + Comparison_result res1, res2; - for (t_iter = t_vals.begin(); t_iter != t_vals.end(); ++t_iter) - { + for (t_iter = t_vals.begin(); t_iter != t_vals.end(); ++t_iter) { res1 = CGAL::compare (*t_iter, t_src); - if (res1 == EQUAL) - { + if (res1 == EQUAL) { // Return the y-coordinate of the source point: return (_ps.y()); } res2 = CGAL::compare (*t_iter, t_trg); - if (res2 == EQUAL) - { + if (res2 == EQUAL) { // Return the y-coordinate of the source point: return (_pt.y()); } - if (res1 != res2) - { + if (res1 != res2) { // We found a t-value in the range of our x-monotone subcurve. // Use this value to compute the y-coordinate. return (nt_traits.evaluate_at (_curve.y_polynomial(), *t_iter) / @@ -1774,42 +1625,38 @@ _Bezier_x_monotone_2::_get_y // If we reached here, x0 is not in the x-range of our subcurve. CGAL_error(); - return (0); + return 0; } // --------------------------------------------------------------------------- // Compare the slopes of the subcurve with another given Bezier subcurve at // their given intersection point. // -template +template Comparison_result -_Bezier_x_monotone_2::_compare_slopes - (const Self& cv, - const Point_2& p, - Bezier_cache& cache) const +_Bezier_x_monotone_2:: +_compare_slopes(const Self& cv, const Point_2& p, Bezier_cache& cache) const { // Get the originators of p. - Originator_iterator org1 = p.get_originator (_curve, _xid); - const bool valid_org1 = (org1 != p.originators_end()); + Originator_iterator org1 = p.get_originator(_curve, _xid); + const bool valid_org1 = (org1 != p.originators_end()); - Originator_iterator org2 = p.get_originator (cv._curve, cv._xid); - const bool valid_org2 = (org2 != p.originators_end()); + Originator_iterator org2 = p.get_originator(cv._curve, cv._xid); + const bool valid_org2 = (org2 != p.originators_end()); - CGAL_assertion (valid_org1 || valid_org2); + CGAL_assertion(valid_org1 || valid_org2); // If the point is only approximated, we can carry out a comparison using // an approximate number type. - if (valid_org1 && valid_org2 && ! p.is_exact()) - { + if (valid_org1 && valid_org2 && ! p.is_exact()) { // If the point is inexact, we assume it is a bounded intersection // point of two curves, and therefore the bounding angle these curves // span do not overlap. - const Bez_point_bound& bound1 = org1->point_bound(); - const Bez_point_bound& bound2 = org2->point_bound(); - Bounding_traits bound_tr; + const Bez_point_bound& bound1 = org1->point_bound(); + const Bez_point_bound& bound2 = org2->point_bound(); + Bounding_traits bound_tr; - return (bound_tr.compare_slopes_at_intersection_point (bound1, - bound2)); + return (bound_tr.compare_slopes_at_intersection_point(bound1, bound2)); } // Obtain the parameter values t1 and t2 that correspond to the point p. @@ -1818,17 +1665,15 @@ _Bezier_x_monotone_2::_compare_slopes // it must be a ratioal point!) and lies in its interior. In this // (degenerate) case we compute the parameter value and set the appropriate // originator for p. - Nt_traits nt_traits; - Algebraic t1; - Algebraic t2; + Nt_traits nt_traits; + Algebraic t1; + Algebraic t2; - if (valid_org1) - { + if (valid_org1) { CGAL_assertion (org1->has_parameter()); t1 = org1->parameter(); } - else - { + else { bool is_endpoint1; CGAL_assertion_code (bool in_range1 =) _is_in_range (p, cache, t1, is_endpoint1); @@ -1836,66 +1681,60 @@ _Bezier_x_monotone_2::_compare_slopes p.add_originator (Originator (_curve, _xid, t1)); } - if (valid_org2) - { + if (valid_org2) { CGAL_assertion (org2->has_parameter()); t2 = org2->parameter(); } - else - { - bool is_endpoint2; - CGAL_assertion_code (bool in_range2 =) - cv._is_in_range (p, cache, t2, is_endpoint2); - CGAL_assertion (in_range2); - p.add_originator (Originator (cv._curve, cv._xid, t2)); + else { + bool is_endpoint2; + CGAL_assertion_code(bool in_range2 =) + cv._is_in_range(p, cache, t2, is_endpoint2); + CGAL_assertion(in_range2); + p.add_originator(Originator (cv._curve, cv._xid, t2)); } // The slope of (X(t), Y(t)) at t0 is given by Y'(t0)/X'(t0). // Compute the slope of (*this). // Note that we take special care of the case X'(t0) = 0, when the tangent // is vertical and its slope is +/- oo. - Polynomial derivX = nt_traits.derive (_curve.x_polynomial()); - Polynomial derivY = nt_traits.derive (_curve.y_polynomial()); - Algebraic numer1 = nt_traits.evaluate_at (derivY, t1) * - nt_traits.convert (_curve.x_norm()); - Algebraic denom1 = nt_traits.evaluate_at (derivX, t1) * - nt_traits.convert (_curve.y_norm()); - CGAL::Sign inf_slope1 = CGAL::ZERO; - Algebraic slope1; + Polynomial derivX = nt_traits.derive(_curve.x_polynomial()); + Polynomial derivY = nt_traits.derive(_curve.y_polynomial()); + Algebraic numer1 = nt_traits.evaluate_at(derivY, t1) * + nt_traits.convert (_curve.x_norm()); + Algebraic denom1 = nt_traits.evaluate_at(derivX, t1) * + nt_traits.convert (_curve.y_norm()); + CGAL::Sign inf_slope1 = CGAL::ZERO; + Algebraic slope1; - if (CGAL::sign (denom1) == CGAL::ZERO) - { - inf_slope1 = is_directed_right() ? CGAL::sign (numer1) : CGAL::opposite( CGAL::sign (numer1) ); + if (CGAL::sign (denom1) == CGAL::ZERO) { + inf_slope1 = is_directed_right() ? + CGAL::sign(numer1) : CGAL::opposite(CGAL::sign(numer1)); // If both derivatives are zero, we cannot perform the comparison: - if (inf_slope1 == CGAL::ZERO) - return (EQUAL); + if (inf_slope1 == CGAL::ZERO) return EQUAL; } - else - { + else { slope1 = numer1 / denom1; } // Compute the slope of the other subcurve. derivX = nt_traits.derive (cv._curve.x_polynomial()); derivY = nt_traits.derive (cv._curve.y_polynomial()); - Algebraic numer2 = nt_traits.evaluate_at (derivY, t2) * - nt_traits.convert (cv._curve.x_norm()); - Algebraic denom2 = nt_traits.evaluate_at (derivX, t2) * - nt_traits.convert (cv._curve.y_norm()); - CGAL::Sign inf_slope2 = CGAL::ZERO; - Algebraic slope2; + Algebraic numer2 = nt_traits.evaluate_at (derivY, t2) * + nt_traits.convert (cv._curve.x_norm()); + Algebraic denom2 = nt_traits.evaluate_at (derivX, t2) * + nt_traits.convert (cv._curve.y_norm()); + CGAL::Sign inf_slope2 = CGAL::ZERO; + Algebraic slope2; - if (CGAL::sign (denom2) == CGAL::ZERO) - { - inf_slope2 = cv.is_directed_right() ? CGAL::sign (numer2) : CGAL::opposite( CGAL::sign (numer2) ); + if (CGAL::sign (denom2) == CGAL::ZERO) { + inf_slope2 = cv.is_directed_right() ? + CGAL::sign (numer2) : CGAL::opposite( CGAL::sign (numer2) ); // If both derivatives are zero, we cannot perform the comparison: - if (inf_slope2 == CGAL::ZERO) - return (EQUAL); + if (inf_slope2 == CGAL::ZERO) return (EQUAL); } - else - { + else { slope2 = numer2 / denom2; } @@ -1906,11 +1745,9 @@ _Bezier_x_monotone_2::_compare_slopes if (inf_slope1 == CGAL::NEGATIVE) return (inf_slope2 == CGAL::NEGATIVE ? EQUAL : SMALLER); - if (inf_slope2 == CGAL::POSITIVE) - return (SMALLER); + if (inf_slope2 == CGAL::POSITIVE) return (SMALLER); - if (inf_slope2 == CGAL::NEGATIVE) - return (LARGER); + if (inf_slope2 == CGAL::NEGATIVE) return (LARGER); // Compare the slopes. return (CGAL::compare (slope1, slope2)); @@ -1919,29 +1756,25 @@ _Bezier_x_monotone_2::_compare_slopes // --------------------------------------------------------------------------- // Get the range of t-value over which the subcurve is defined. // -template +template std::pair::Algebraic, typename _Bezier_x_monotone_2::Algebraic> -_Bezier_x_monotone_2::_t_range - (Bezier_cache& cache) const +_Bezier_x_monotone_2:: +_t_range(Bezier_cache& cache) const { - Originator_iterator ps_org = _ps.get_originator (_curve, _xid); + Originator_iterator ps_org = _ps.get_originator(_curve, _xid); CGAL_assertion(ps_org != _ps.originators_end()); - Originator_iterator pt_org = _pt.get_originator (_curve, _xid); + Originator_iterator pt_org = _pt.get_originator(_curve, _xid); CGAL_assertion(pt_org != _pt.originators_end()); // Make sure that the two endpoints are exact. - if (! ps_org->has_parameter()) - _ps.make_exact (cache); + if (! ps_org->has_parameter()) _ps.make_exact (cache); + if (! pt_org->has_parameter()) _pt.make_exact (cache); - if (! pt_org->has_parameter()) - _pt.make_exact (cache); - - return (std::make_pair (ps_org->parameter(), - pt_org->parameter())); + return (std::make_pair(ps_org->parameter(), pt_org->parameter())); } // --------------------------------------------------------------------------- @@ -1949,18 +1782,18 @@ _Bezier_x_monotone_2::_t_range // (or to the left) of their intersection point, whose multiplicity is // greater than 1. // -template +template Comparison_result -_Bezier_x_monotone_2::_compare_to_side - (const Self& cv, - const Point_2& p, - bool to_right, - Bezier_cache& cache) const +_Bezier_x_monotone_2:: +_compare_to_side(const Self& cv, + const Point_2& p, + bool to_right, + Bezier_cache& cache) const { // Get the intersection points of the two curves from the cache. Note that // we make sure that the ID of this->_curve is smaller than of cv's curve ID. - const bool no_swap_curves = (_curve.id() <= cv._curve.id()); - bool do_ovlp; + const bool no_swap_curves = (_curve.id() <= cv._curve.id()); + bool do_ovlp; const Intersect_list& inter_list = (no_swap_curves ? (cache.get_intersections (_curve.id(), @@ -1984,40 +1817,36 @@ _Bezier_x_monotone_2::_compare_to_side CGAL_assertion (org != p.originators_end()); CGAL_assertion (org->has_parameter()); - const Algebraic& t0 = org->parameter(); + const Algebraic& t0 = org->parameter(); // Get the parameter range of the curve. - const std::pair& range = _t_range (cache); - const Algebraic& t_src = range.first; - const Algebraic& t_trg = range.second; + const std::pair& range = _t_range (cache); + const Algebraic& t_src = range.first; + const Algebraic& t_trg = range.second; // Find the next intersection point that lies to the right of p. - Intersect_iter iit; - Algebraic next_t; - Comparison_result res = CGAL::EQUAL; - bool found = false; + Intersect_iter iit; + Algebraic next_t; + Comparison_result res = CGAL::EQUAL; + bool found = false; - for (iit = inter_list.begin(); iit != inter_list.end(); ++iit) - { + for (iit = inter_list.begin(); iit != inter_list.end(); ++iit) { // Check if the current point lies to the right (left) of p. We do so by // considering its originating parameter value s (or t, if we swapped // the curves). - const Algebraic& t = (no_swap_curves ? (iit->s) : iit->t); + const Algebraic& t = (no_swap_curves ? (iit->s) : iit->t); - res = CGAL::compare (t, t0); + res = CGAL::compare(t, t0); if ((to_right && ((_inc_to_right && res == LARGER) || (! _inc_to_right && res == SMALLER))) || (! to_right && ((_inc_to_right && res == SMALLER) || (! _inc_to_right && res == LARGER)))) { - if (! found) - { + if (! found) { next_t = t; found = true; } - else - { + else { // If we have already located an intersection point to the right // (left) of p, choose the leftmost (rightmost) of the two points. res = CGAL::compare (t, next_t); @@ -2035,12 +1864,9 @@ _Bezier_x_monotone_2::_compare_to_side // If the next intersection point occurs before the right (left) endpoint // of the subcurve, keep it. Otherwise, take the parameter value at // the endpoint. - if (found) - { - if (to_right == _dir_right) - res = CGAL::compare (t_trg, next_t); - else - res = CGAL::compare (t_src, next_t); + if (found) { + if (to_right == _dir_right) res = CGAL::compare (t_trg, next_t); + else res = CGAL::compare (t_src, next_t); } if (! found || @@ -2055,10 +1881,10 @@ _Bezier_x_monotone_2::_compare_to_side // Find a rational value between t0 and t_next. Using this value, we // a point with rational coordinates on our subcurve. We also locate a point // on the other curve with the same x-coordinates. - Nt_traits nt_traits; - const Rational& mid_t = nt_traits.rational_in_interval (t0, next_t); - const Rat_point_2& q1 = _curve (mid_t); - const Algebraic& y2 = cv._get_y (q1.x(), cache); + Nt_traits nt_traits; + const Rational& mid_t = nt_traits.rational_in_interval(t0, next_t); + const Rat_point_2& q1 = _curve(mid_t); + const Algebraic& y2 = cv._get_y(q1.x(), cache); // We now just have to compare the y-coordinates of the two points we have // computed. @@ -2069,33 +1895,32 @@ _Bezier_x_monotone_2::_compare_to_side // Clip the control polygon of the supporting Bezier curve such that it fits // the current x-monotone subcurve. // -template -void _Bezier_x_monotone_2::_clip_control_polygon - (typename Bounding_traits::Control_points& ctrl, - typename Bounding_traits::NT& t_min, - typename Bounding_traits::NT& t_max) const +template +void _Bezier_x_monotone_2:: +_clip_control_polygon(typename Bounding_traits::Control_points& ctrl, + typename Bounding_traits::NT& t_min, + typename Bounding_traits::NT& t_max) const { // Start from the control polygon of the supporting curve. ctrl.clear(); - std::copy (_curve.control_points_begin(), _curve.control_points_end(), - std::back_inserter (ctrl)); + std::copy(_curve.control_points_begin(), _curve.control_points_end(), + std::back_inserter(ctrl)); // The x-monotone subcurve is defined over a parameter range // 0 <= t_min < t_max <= 1. Determine the endpoint with minimal t-value and // the one with maximal t-value. - const Point_2& p_min = (_inc_to_right ? left() : right()); - Originator_iterator org_min = p_min.get_originator (_curve, _xid); - const Point_2& p_max = (_inc_to_right ? right() : left()); - Originator_iterator org_max = p_max.get_originator (_curve, _xid); - bool clipped_min = false; + const Point_2& p_min = (_inc_to_right ? left() : right()); + Originator_iterator org_min = p_min.get_originator(_curve, _xid); + const Point_2& p_max = (_inc_to_right ? right() : left()); + Originator_iterator org_max = p_max.get_originator(_curve, _xid); + bool clipped_min = false; - CGAL_assertion (org_min != p_min.originators_end()); - CGAL_assertion (org_max != p_max.originators_end()); + CGAL_assertion(org_min != p_min.originators_end()); + CGAL_assertion(org_max != p_max.originators_end()); // Check if t_min = 0. If so, there is no need to clip. if (! (org_min->point_bound().type == Bez_point_bound::RATIONAL_PT && - CGAL::sign (org_min->point_bound().t_min) == CGAL::ZERO)) + CGAL::sign(org_min->point_bound().t_min) == CGAL::ZERO)) { // It is possible that the paramater range of the originator is too large. // We therefore make sure it fits the current bounding box of the point @@ -2104,22 +1929,20 @@ void _Bezier_x_monotone_2point_bound().t_max; - de_Casteljau_2 (ctrl.begin(), ctrl.end(), - t_min, - std::back_inserter(cp_a), - std::front_inserter(cp_b)); + de_Casteljau_2(ctrl.begin(), ctrl.end(), + t_min, + std::back_inserter(cp_a), + std::front_inserter(cp_b)); ctrl.clear(); - std::copy (cp_b.begin(), cp_b.end(), - std::back_inserter (ctrl)); + std::copy(cp_b.begin(), cp_b.end(), std::back_inserter (ctrl)); clipped_min = true; } - else - { + else { t_min = 0; } @@ -2137,27 +1960,21 @@ void _Bezier_x_monotone_2point_bound().t_min - t_min) / (1 - t_min); } - else - { + else { t_max = org_max->point_bound().t_min; } - de_Casteljau_2 (ctrl.begin(), ctrl.end(), - t_max, - std::back_inserter(cp_a), - std::front_inserter(cp_b)); + de_Casteljau_2(ctrl.begin(), ctrl.end(), t_max, + std::back_inserter(cp_a), std::front_inserter(cp_b)); ctrl.clear(); - std::copy (cp_a.begin(), cp_a.end(), - std::back_inserter (ctrl)); + std::copy(cp_a.begin(), cp_a.end(), std::back_inserter (ctrl)); t_max = org_max->point_bound().t_min; } - else - { + else { t_max = 1; } @@ -2167,11 +1984,10 @@ void _Bezier_x_monotone_2 -bool _Bezier_x_monotone_2::_approximate_intersection_points - (const Self& cv, - std::list& inter_pts) const +template +bool _Bezier_x_monotone_2:: +_approximate_intersection_points(const Self& cv, + std::list& inter_pts) const { typedef typename Bounding_traits::Intersection_point Intersection_point; @@ -2179,16 +1995,15 @@ bool _Bezier_x_monotone_2_curve; - const Curve_2& B2 = cv._curve; - typename Bounding_traits::Control_points cp1; - typename Bounding_traits::NT t_min1 = 0, t_max1 = 1; + const Curve_2& B1 = this->_curve; + const Curve_2& B2 = cv._curve; + typename Bounding_traits::Control_points cp1; + typename Bounding_traits::NT t_min1 = 0, t_max1 = 1; typename Bounding_traits::Control_points cp2; - typename Bounding_traits::NT t_min2 = 0, t_max2 = 1; - bool is_self_intersection = false; + typename Bounding_traits::NT t_min2 = 0, t_max2 = 1; + bool is_self_intersection = false; - if (! B1.is_same (B2)) - { + if (! B1.is_same (B2)) { // In case B1 and B2 are different curves, use their full control polygons // in order to approximate all intersection points between the two // supporting Bezier curves. @@ -2197,8 +2012,7 @@ bool _Bezier_x_monotone_2 ipt_bounds; + Bounding_traits bound_tr; + std::list ipt_bounds; - bound_tr.compute_intersection_points (cp1, cp2, - std::back_inserter (ipt_bounds)); + bound_tr.compute_intersection_points(cp1, cp2, std::back_inserter(ipt_bounds)); // Construct the approximated points. - typename std::list::const_iterator iter; - - for (iter = ipt_bounds.begin(); iter != ipt_bounds.end(); ++iter) - { + for (auto iter = ipt_bounds.begin(); iter != ipt_bounds.end(); ++iter) { const Bez_point_bound& bound1 = iter->bound1; const Bez_point_bound& bound2 = iter->bound2; const Bez_point_bbox& bbox = iter->bbox; // In case it is impossible to further refine the point, stop here. - if (! bound1.can_refine || ! bound2.can_refine) - return (false); + if (! bound1.can_refine || ! bound2.can_refine) return false; // Create the approximated intersection point. - Point_2 pt; + Point_2 pt; if (bound1.type == Bounding_traits::Bez_point_bound::RATIONAL_PT && bound2.type == Bounding_traits::Bez_point_bound::RATIONAL_PT) { - CGAL_assertion (CGAL::compare (bound1.t_min, bound1.t_max) == EQUAL); - CGAL_assertion (CGAL::compare (bound2.t_min, bound2.t_max) == EQUAL); - Rational t1 = bound1.t_min; - Rational t2 = bound2.t_min; - Nt_traits nt_traits; + CGAL_assertion (CGAL::compare(bound1.t_min, bound1.t_max) == EQUAL); + CGAL_assertion (CGAL::compare(bound2.t_min, bound2.t_max) == EQUAL); + Rational t1 = bound1.t_min; + Rational t2 = bound2.t_min; + Nt_traits nt_traits; - if (is_self_intersection) - { + if (is_self_intersection) { // Set the originators with the curve x-monotone IDs. // Note that the parameter values we have computed relate to the // parameter range [t_min1, t_max1] and [t_min2, t_max2], respectively, @@ -2249,63 +2057,60 @@ bool _Bezier_x_monotone_2 -bool _Bezier_x_monotone_2::_intersect - (const Self& cv, - Intersection_map& inter_map, - Bezier_cache& cache, - std::vector& ipts, - Self& ovlp_cv) const +template +bool _Bezier_x_monotone_2:: +_intersect(const Self& cv, + Intersection_map& inter_map, + Bezier_cache& cache, + std::vector& ipts, + Self& ovlp_cv) const { - CGAL_precondition (_curve.id() <= cv._curve.id()); + CGAL_precondition(_curve.id() <= cv._curve.id()); ipts.clear(); @@ -2313,115 +2118,96 @@ bool _Bezier_x_monotone_2::_intersect // first check if this base curve is not self-intersecting. If this is the // case we can avoid any attempt of computing intersection points between // the two subcurves. - const bool self_intersect = (_curve.id() == cv._curve.id()); + const bool self_intersect = (_curve.id() == cv._curve.id()); - if (self_intersect) - { - if (_xid == cv._xid) - return (false); - - if (_curve.has_no_self_intersections()) - return (false); + if (self_intersect) { + if (_xid == cv._xid) return false; + if (_curve.has_no_self_intersections()) return false; } // Construct the pair of curve IDs and look for it in the intersection map. - Curve_pair curve_pair (_curve.id(), cv._curve.id()); - Intersection_map_iterator map_iter = inter_map.find (curve_pair); - std::list inter_pts; - bool app_ok = true; + Curve_pair curve_pair(_curve.id(), cv._curve.id()); + Intersection_map_iterator map_iter = inter_map.find(curve_pair); + std::list inter_pts; + bool app_ok = true; - if (map_iter != inter_map.end()) - { + if (map_iter != inter_map.end()) { // Get the intersection points between the two supporting curves as stored // in the map. inter_pts = map_iter->second; } - else - { + else { // Approximate the intersection points and store them in the map. // Note that we do not store approximated self-intersections in the map, // as they realte only to the pecific x-monotone curves, and not to the // entire curve. - app_ok = _approximate_intersection_points (cv, - inter_pts); + app_ok = _approximate_intersection_points(cv, inter_pts); - if (app_ok && ! self_intersect) - inter_map[curve_pair] = inter_pts; + if (app_ok && ! self_intersect) inter_map[curve_pair] = inter_pts; } // Try to approximate the intersection points. - bool in_range1, in_range2; - bool correct_res; + bool in_range1, in_range2; + bool correct_res; - if (app_ok) - { + if (app_ok) { // Approximations are computed using de Casteljau subdivision and // filtering using skewed bounding boxes. A property of these bboxes - // if that it can fail in the following cases: (i) there are two intersection - // points lying very close together, (ii) there exists an intersection point - // whose multiplicity is greater than 1, or (iii) the curves overlap. - // If the approximation went OK, then we know that we have a simple - // intersection point (with multiplicity 1) if intersection point - // is not rational (otherwise it is unknown: at this point, an intersection point - // is rational if it was found as a control point during the de Casteljau subdivision) + // if that it can fail in the following cases: (i) there are two + // intersection points lying very close together, (ii) there exists an + // intersection point whose multiplicity is greater than 1, or (iii) the + // curves overlap. If the approximation went OK, then we know that we have + // a simple intersection point (with multiplicity 1) if intersection point + // is not rational (otherwise it is unknown: at this point, an intersection + // point is rational if it was found as a control point during the de + // Casteljau subdivision) // We go over the points and report the ones lying in the parameter // ranges of both curves. Note that in case of self-intersections, // all points we get are in the respective parameter range of the curves. typename std::list::iterator pit; - for (pit = inter_pts.begin(); pit != inter_pts.end(); ++pit) - { + for (pit = inter_pts.begin(); pit != inter_pts.end(); ++pit) { // Check if the point is in the range of this curve - first using // its parameter bounds, and if we fail we perform an exact check. - if (! self_intersect) - { - in_range1 = _is_in_range (*pit, correct_res); + if (! self_intersect) { + in_range1 = _is_in_range(*pit, correct_res); } - else - { + else { in_range1 = true; correct_res = true; } - if (! correct_res) - { - if (! pit->is_exact()) - pit->make_exact (cache); + if (! correct_res) { + if (! pit->is_exact()) pit->make_exact(cache); - Originator_iterator p_org = pit->get_originator (_curve, _xid); + Originator_iterator p_org = pit->get_originator (_curve, _xid); CGAL_assertion (p_org != pit->originators_end()); - in_range1 = _is_in_range (p_org->parameter(), cache); + in_range1 = _is_in_range(p_org->parameter(), cache); } - if (! in_range1) - continue; + if (! in_range1) continue; // Check if the point is in the range of the other curve - first using // its parameter bounds, and if we fail we perform an exact check. - if (! self_intersect) - { + if (! self_intersect) { in_range2 = cv._is_in_range (*pit, correct_res); } - else - { + else { in_range2 = true; correct_res = true; } - if (! correct_res) - { - if (! pit->is_exact()) - pit->make_exact (cache); + if (! correct_res) { + if (! pit->is_exact()) pit->make_exact (cache); Originator_iterator p_org = pit->get_originator (cv._curve, cv._xid); - CGAL_assertion (p_org != pit->originators_end()); + CGAL_assertion(p_org != pit->originators_end()); - in_range2 = cv._is_in_range (p_org->parameter(), cache); + in_range2 = cv._is_in_range(p_org->parameter(), cache); } - if (in_range1 && in_range2) - { + if (in_range1 && in_range2) { // In case the originators of the intersection point are not marked // with x-monotone identifiers, mark them now as we know in which // subcurves they lie. @@ -2429,17 +2215,17 @@ bool _Bezier_x_monotone_2::_intersect CGAL_assertion (p_org1 != pit->originators_end()); if (p_org1->xid() == 0) - pit->update_originator_xid (*p_org1, _xid); + pit->update_originator_xid(*p_org1, _xid); Originator_iterator p_org2 = pit->get_originator (cv._curve, cv._xid); CGAL_assertion (p_org2 != pit->originators_end()); if (p_org2->xid() == 0) - pit->update_originator_xid (*p_org2, cv._xid); + pit->update_originator_xid(*p_org2, cv._xid); // The point lies within the parameter range of both curves, so we // report it as a valid intersection point with multiplicity 1 or unknown. - ipts.push_back (Intersection_point_2 (*pit, pit->is_rational()?0:1)); + ipts.push_back(Intersection_point(*pit, pit->is_rational() ? 0 : 1)); } } @@ -2449,34 +2235,30 @@ bool _Bezier_x_monotone_2::_intersect // We did not succeed in isolate the approximate intersection points. // We therefore resort to the exact procedure and exactly compute them. - bool do_ovlp; - const Intersect_list& inter_list = - cache.get_intersections (_curve.id(), - _curve.x_polynomial(), _curve.x_norm(), - _curve.y_polynomial(), _curve.y_norm(), - cv._curve.id(), - cv._curve.x_polynomial(), cv._curve.x_norm(), - cv._curve.y_polynomial(), cv._curve.y_norm(), - do_ovlp); + bool do_ovlp; + const Intersect_list& inter_list = + cache.get_intersections(_curve.id(), + _curve.x_polynomial(), _curve.x_norm(), + _curve.y_polynomial(), _curve.y_norm(), + cv._curve.id(), + cv._curve.x_polynomial(), cv._curve.x_norm(), + cv._curve.y_polynomial(), cv._curve.y_norm(), + do_ovlp); - if (do_ovlp) - { + if (do_ovlp) { // Check the case of co-inciding endpoints - if (left().equals (cv.left(), cache)) - { - if (right().equals (cv.right(), cache)) - { + if (left().equals (cv.left(), cache)) { + if (right().equals (cv.right(), cache)) { // The two curves entirely overlap one another: ovlp_cv = cv; - return (true); + return true; } - Algebraic t_right; - bool is_endpoint; + Algebraic t_right; + bool is_endpoint; - if (_is_in_range (cv.right(), cache, t_right, is_endpoint)) - { - CGAL_assertion (! is_endpoint); + if (_is_in_range(cv.right(), cache, t_right, is_endpoint)) { + CGAL_assertion(! is_endpoint); // Case 1 - *this: s +-----------+ t // cv: s'+=====+ t' @@ -2484,13 +2266,12 @@ bool _Bezier_x_monotone_2::_intersect // Take cv as the overlapping subcurve, and add originators for its // right endpoint referring to *this. ovlp_cv = cv; - ovlp_cv.right().add_originator (Originator (_curve, _xid, t_right)); + ovlp_cv.right().add_originator(Originator(_curve, _xid, t_right)); - return (true); + return true; } - else if (cv._is_in_range (right(), cache, t_right, is_endpoint)) - { - CGAL_assertion (! is_endpoint); + else if (cv._is_in_range(right(), cache, t_right, is_endpoint)) { + CGAL_assertion(! is_endpoint); // Case 2 - *this: s +----+ t // cv: s'+==========+ t' @@ -2498,24 +2279,21 @@ bool _Bezier_x_monotone_2::_intersect // Take this as the overlapping subcurve, and add originators for its // right endpoint referring to cv. ovlp_cv = *this; - ovlp_cv.right().add_originator (Originator (cv._curve, cv._xid, - t_right)); + ovlp_cv.right().add_originator(Originator(cv._curve, cv._xid, t_right)); - return (true); + return true; } // In this case the two curves do not overlap, but have a common left // endpoint. - ipts.push_back (Intersection_point_2 (left(), 0)); + ipts.push_back(Intersection_point(left(), 0)); return (false); } - else if (right().equals (cv.right(), cache)) - { - Algebraic t_left; - bool is_endpoint; + else if (right().equals (cv.right(), cache)) { + Algebraic t_left; + bool is_endpoint; - if (_is_in_range (cv.left(), cache, t_left, is_endpoint)) - { + if (_is_in_range (cv.left(), cache, t_left, is_endpoint)) { CGAL_assertion (! is_endpoint); // Case 3 - *this: s +-----------+ t @@ -2528,9 +2306,8 @@ bool _Bezier_x_monotone_2::_intersect return (true); } - else if (cv._is_in_range (left(), cache, t_left, is_endpoint)) - { - CGAL_assertion (! is_endpoint); + else if (cv._is_in_range(left(), cache, t_left, is_endpoint)) { + CGAL_assertion(! is_endpoint); // Case 4 - *this: s +----+ t // cv: s'+==========+ t' @@ -2538,30 +2315,26 @@ bool _Bezier_x_monotone_2::_intersect // Take this as the overlapping subcurve, and add originators for its // left endpoint referring to cv. ovlp_cv = *this; - ovlp_cv.left().add_originator (Originator (cv._curve, cv._xid, - t_left)); + ovlp_cv.left().add_originator(Originator(cv._curve, cv._xid, t_left)); - return (true); + return true; } // In this case the two curves do not overlap, but have a common right // endpoint. - ipts.push_back (Intersection_point_2 (right(), 0)); - return (false); + ipts.push_back(Intersection_point(right(), 0)); + return false; } // If we reached here, none of the endpoints coincide. // Check the possible overlap scenarios. - Point_2 ovrp_src, ovlp_trg; - Algebraic t_cv_src; - Algebraic t_cv_trg; - bool is_endpoint = false; + Point_2 ovrp_src, ovlp_trg; + Algebraic t_cv_src; + Algebraic t_cv_trg; + bool is_endpoint = false; - if (_is_in_range (cv._ps, cache, t_cv_src, is_endpoint) && - ! is_endpoint) - { - if (_is_in_range (cv._pt, cache, t_cv_trg, is_endpoint) && - ! is_endpoint) + if (_is_in_range (cv._ps, cache, t_cv_src, is_endpoint) && ! is_endpoint) { + if (_is_in_range (cv._pt, cache, t_cv_trg, is_endpoint) && ! is_endpoint) { // Case 5 - *this: s +-----------+ t // cv: s' +=====+ t' @@ -2569,32 +2342,30 @@ bool _Bezier_x_monotone_2::_intersect // Take cv as the overlapping subcurve, and add originators for its // endpoints referring to *this. ovlp_cv = cv; - ovlp_cv._ps.add_originator (Originator (_curve, _xid, t_cv_src)); - ovlp_cv._pt.add_originator (Originator (_curve, _xid, t_cv_trg)); + ovlp_cv._ps.add_originator(Originator (_curve, _xid, t_cv_src)); + ovlp_cv._pt.add_originator(Originator (_curve, _xid, t_cv_trg)); - return (true); + return true; } - else - { + else { // Case 6 - *this: s +-----------+ t // cv: s' +=====+ t' // // Use *this as a base, and replace its source point. ovlp_cv = *this; ovlp_cv._ps = cv._ps; - ovlp_cv._ps.add_originator (Originator (_curve, _xid, t_cv_src)); + ovlp_cv._ps.add_originator(Originator (_curve, _xid, t_cv_src)); // Add an originator to the target point, referring to cv: - CGAL_assertion_code (bool pt_in_cv_range =) - cv._is_in_range (ovlp_cv._pt, cache, t_cv_trg, is_endpoint); - CGAL_assertion (pt_in_cv_range); - ovlp_cv._pt.add_originator (Originator (cv._curve, cv._xid, t_cv_trg)); + CGAL_assertion_code(bool pt_in_cv_range =) + cv._is_in_range(ovlp_cv._pt, cache, t_cv_trg, is_endpoint); + CGAL_assertion(pt_in_cv_range); + ovlp_cv._pt.add_originator(Originator(cv._curve, cv._xid, t_cv_trg)); - return (true); + return true; } } - else if (_is_in_range (cv._pt, cache, t_cv_trg, is_endpoint) && - ! is_endpoint) + else if (_is_in_range(cv._pt, cache, t_cv_trg, is_endpoint) && ! is_endpoint) { // Case 7 - *this: s +-----------+ t // cv: s' +=====+ t' @@ -2606,14 +2377,14 @@ bool _Bezier_x_monotone_2::_intersect // Add an originator to the source point, referring to cv: CGAL_assertion_code (bool ps_in_cv_range =) - cv._is_in_range (ovlp_cv._ps, cache, t_cv_src, is_endpoint); + cv._is_in_range(ovlp_cv._ps, cache, t_cv_src, is_endpoint); CGAL_assertion (ps_in_cv_range); - ovlp_cv._ps.add_originator (Originator (cv._curve, cv._xid, t_cv_src)); + ovlp_cv._ps.add_originator(Originator(cv._curve, cv._xid, t_cv_src)); return (true); } - else if (cv._is_in_range (_ps, cache, t_cv_src, is_endpoint) && - cv._is_in_range (_pt, cache, t_cv_trg, is_endpoint)) + else if (cv._is_in_range(_ps, cache, t_cv_src, is_endpoint) && + cv._is_in_range(_pt, cache, t_cv_trg, is_endpoint)) { // Case 8 - *this: s +---------+ t // cv: s' +================+ t' @@ -2621,38 +2392,32 @@ bool _Bezier_x_monotone_2::_intersect // Take *this as the overlapping subcurve, and add originators for its // endpoints referring to cv. ovlp_cv = *this; - ovlp_cv._ps.add_originator (Originator (cv._curve, cv._xid, t_cv_src)); - ovlp_cv._pt.add_originator (Originator (cv._curve, cv._xid, t_cv_trg)); + ovlp_cv._ps.add_originator(Originator(cv._curve, cv._xid, t_cv_src)); + ovlp_cv._pt.add_originator(Originator(cv._curve, cv._xid, t_cv_trg)); - return (true); + return true; } // If we reached here, there are no overlaps: - return (false); + return false; } // Go over the points and report the ones lying in the parameter ranges // of both curves. - Intersect_iter iit; - - for (iit = inter_list.begin(); iit != inter_list.end(); ++iit) - { - if (_is_in_range (iit->s, cache) && - cv._is_in_range (iit->t, cache)) - { + for (auto iit = inter_list.begin(); iit != inter_list.end(); ++iit) { + if (_is_in_range (iit->s, cache) && cv._is_in_range(iit->t, cache)) { // Construct an intersection point with unknown multiplicity. - Point_2 pt (iit->x, iit->y, - true); // Dummy parameter. + Point_2 pt (iit->x, iit->y, true); // Dummy parameter. - pt.add_originator (Originator (_curve, _xid, iit->s)); - pt.add_originator (Originator (cv._curve, cv._xid, iit->t)); + pt.add_originator(Originator(_curve, _xid, iit->s)); + pt.add_originator(Originator(cv._curve, cv._xid, iit->t)); - ipts.push_back (Intersection_point_2 (pt, 0)); + ipts.push_back(Intersection_point(pt, 0)); } } // Mark that there is no overlap: - return (false); + return false; } // --------------------------------------------------------------------------- @@ -2676,23 +2441,22 @@ _exact_vertical_position(const Point_2& p, rat_p = (Rat_point_2) p; // Get a rational approximation of the parameter values at the endpoints. - Nt_traits nt_traits; - Originator_iterator ps_org = _ps.get_originator (_curve, _xid); + Nt_traits nt_traits; + Originator_iterator ps_org = _ps.get_originator(_curve, _xid); CGAL_assertion (ps_org != _ps.originators_end()); - Originator_iterator pt_org = _pt.get_originator (_curve, _xid); - CGAL_assertion (pt_org != _pt.originators_end()); + Originator_iterator pt_org = _pt.get_originator(_curve, _xid); + CGAL_assertion(pt_org != _pt.originators_end()); - Rational my_t_min; - Rational my_t_max; + Rational my_t_min; + Rational my_t_max; - - bool can_refine_s = ! _ps.is_exact(); - bool can_refine_t = ! _pt.is_exact(); + bool can_refine_s = ! _ps.is_exact(); + bool can_refine_t = ! _pt.is_exact(); do { - if (CGAL::compare (ps_org->point_bound().t_max, - pt_org->point_bound().t_min) == SMALLER) + if (CGAL::compare(ps_org->point_bound().t_max, + pt_org->point_bound().t_min) == SMALLER) { // In case the parameter value of the source is smaller than the target's. my_t_min = ps_org->point_bound().t_max; @@ -2719,14 +2483,14 @@ _exact_vertical_position(const Point_2& p, while(can_refine_s || can_refine_t); // Start the subdivision process from the entire supporting curve. - std::list subcurves; - Subcurve init_scv; - Rational x_min, y_min, x_max, y_max; - bool no_x_ovlp; - Comparison_result res_y_min, res_y_max; + std::list subcurves; + Subcurve init_scv; + Rational x_min, y_min, x_max, y_max; + bool no_x_ovlp; + Comparison_result res_y_min, res_y_max; - std::copy (_curve.control_points_begin(), _curve.control_points_end(), - std::back_inserter (init_scv.control_points)); + std::copy(_curve.control_points_begin(), _curve.control_points_end(), + std::back_inserter(init_scv.control_points)); init_scv.t_min = 0; init_scv.t_max = 1; subcurves.push_back (init_scv); @@ -2735,13 +2499,12 @@ _exact_vertical_position(const Point_2& p, { // Go over the list of subcurves and consider only those lying in the // given [t_min, t_max] bound. - typename std::list::iterator iter = subcurves.begin(); - bool is_fully_in_range; + typename std::list::iterator iter = subcurves.begin(); + bool is_fully_in_range; - while (iter != subcurves.end()) - { - if (CGAL::compare (iter->t_max, my_t_min) == SMALLER || - CGAL::compare (iter->t_min, my_t_max) == LARGER) + while (iter != subcurves.end()) { + if (CGAL::compare(iter->t_max, my_t_min) == SMALLER || + CGAL::compare(iter->t_min, my_t_max) == LARGER) { // Subcurve out of bounds of the x-monotone curve we consider - erase // it and continue to next subcurve. @@ -2753,43 +2516,37 @@ _exact_vertical_position(const Point_2& p, // the bounding box of the point. iter->bbox (x_min, y_min, x_max, y_max); - if (p.is_rational()) - { - no_x_ovlp = (CGAL::compare (x_min, rat_p.x()) == LARGER || - CGAL::compare (x_max, rat_p.x()) == SMALLER); + if (p.is_rational()) { + no_x_ovlp = (CGAL::compare(x_min, rat_p.x()) == LARGER || + CGAL::compare(x_max, rat_p.x()) == SMALLER); } - else - { - no_x_ovlp = (CGAL::compare (nt_traits.convert (x_min), - p.x()) == LARGER || - CGAL::compare (nt_traits.convert (x_max), - p.x()) == SMALLER); + else { + no_x_ovlp = (CGAL::compare(nt_traits.convert (x_min), + p.x()) == LARGER || + CGAL::compare(nt_traits.convert (x_max), + p.x()) == SMALLER); } - if (no_x_ovlp) - { + if (no_x_ovlp) { // Subcurve out of x-bounds - erase it and continue to next subcurve. subcurves.erase(iter++); continue; } // In this case, check if there is an overlap in the y-range. - if (p.is_rational()) - { - res_y_min = CGAL::compare (rat_p.y(), y_min); - res_y_max = CGAL::compare (rat_p.y(), y_max); + if (p.is_rational()) { + res_y_min = CGAL::compare(rat_p.y(), y_min); + res_y_max = CGAL::compare(rat_p.y(), y_max); } - else - { - res_y_min = CGAL::compare (p.y(), nt_traits.convert (y_min)); - res_y_max = CGAL::compare (p.y(), nt_traits.convert (y_max)); + else { + res_y_min = CGAL::compare(p.y(), nt_traits.convert (y_min)); + res_y_max = CGAL::compare(p.y(), nt_traits.convert (y_max)); } - is_fully_in_range = (CGAL::compare (iter->t_min, my_t_min) != SMALLER) && - (CGAL::compare (iter->t_max, my_t_max) != LARGER); + is_fully_in_range = (CGAL::compare(iter->t_min, my_t_min) != SMALLER) && + (CGAL::compare(iter->t_max, my_t_max) != LARGER); - if (res_y_min != res_y_max || ! is_fully_in_range) - { + if (res_y_min != res_y_max || ! is_fully_in_range) { // Subdivide the current subcurve and replace iter with the two // resulting subcurves using de Casteljau's algorithm. Subcurve scv_l, scv_r; @@ -2798,21 +2555,20 @@ _exact_vertical_position(const Point_2& p, scv_r.t_max = iter->t_max; scv_l.t_max = scv_r.t_min = (iter->t_min + iter->t_max) / 2; - bisect_control_polygon_2 (iter->control_points.begin(), - iter->control_points.end(), - std::back_inserter(scv_l.control_points), - std::front_inserter(scv_r.control_points)); + bisect_control_polygon_2(iter->control_points.begin(), + iter->control_points.end(), + std::back_inserter(scv_l.control_points), + std::front_inserter(scv_r.control_points)); - subcurves.insert (iter, scv_l); - subcurves.insert (iter, scv_r); + subcurves.insert(iter, scv_l); + subcurves.insert(iter, scv_r); subcurves.erase(iter++); continue; } - if (res_y_min == res_y_max) - { - CGAL_assertion (res_y_min != EQUAL); + if (res_y_min == res_y_max) { + CGAL_assertion(res_y_min != EQUAL); // We reached a separation, as p is either strictly above or strictly // below the bounding box of the current subcurve. @@ -2826,8 +2582,8 @@ _exact_vertical_position(const Point_2& p, } // We can reach here only if we do not force an exact result. - CGAL_assertion (! force_exact); - return (EQUAL); + CGAL_assertion(! force_exact); + return EQUAL; } } //namespace CGAL diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_geometry_traits/Circle_segment_2.h b/Arrangement_on_surface_2/include/CGAL/Arr_geometry_traits/Circle_segment_2.h index f1bdb72d62b..2d94e51f820 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_geometry_traits/Circle_segment_2.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_geometry_traits/Circle_segment_2.h @@ -8,16 +8,16 @@ // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial // // -// Author(s) : Ron Wein -// Baruch Zukerman -// Waqar Khan +// Author(s): Ron Wein +// Baruch Zukerman +// Waqar Khan +// Efi Fogel #ifndef CGAL_CIRCLE_SEGMENT_2_H #define CGAL_CIRCLE_SEGMENT_2_H #include - /*! \file * Header file for the _Circle_segment_2 class. */ @@ -31,126 +31,103 @@ namespace CGAL { // Forward declaration: -template class _One_root_point_2; +template class _One_root_point_2; /*! \class * Representation of a point whose coordinates are one-root numbers. */ -template -class _One_root_point_2_rep //: public Ref_counted -{ +template +class _One_root_point_2_rep { friend class _One_root_point_2; public: - typedef NumberType_ NT; typedef _One_root_point_2_rep Self; - typedef Sqrt_extension > CoordNT; + typedef Sqrt_extension > CoordNT; private: - - CoordNT _x; // The coordinates. - CoordNT _y; + CoordNT _x; // The coordinates. + CoordNT _y; public: - /*! Default constructor. */ - _One_root_point_2_rep () : - _x (0), - _y (0) + _One_root_point_2_rep() : + _x(0), + _y(0) {} /*! Constructor of a point with one-root coefficients. This constructor of a point can also be used with rational coefficients thanks to convertor of CoordNT. */ - _One_root_point_2_rep (const CoordNT& x, const CoordNT& y) : - _x (x), - _y (y) + _One_root_point_2_rep(const CoordNT& x, const CoordNT& y) : + _x(x), + _y(y) {} }; /*! \class * A handle for a point whose coordinates are one-root numbers. */ -template +template class _One_root_point_2 : public Handle_for<_One_root_point_2_rep > { public: - typedef NumberType_ NT; typedef _One_root_point_2 Self; private: - typedef _One_root_point_2_rep Point_rep; typedef Handle_for Point_handle; public: - typedef typename Point_rep::CoordNT CoordNT; /*! Default constructor. */ - _One_root_point_2 () : - Point_handle (Point_rep()) - {} + _One_root_point_2() : Point_handle(Point_rep()) {} /*! Copy constructor. */ - _One_root_point_2 (const Self& p) : - Point_handle (p) - {} + _One_root_point_2(const Self& p) : Point_handle(p) {} _One_root_point_2& operator=(const _One_root_point_2&)=default; /*! Constructor of a point with one-root coefficients. This constructor of a point can also be used with rational coefficients thanks to convertor of CoordNT. */ - _One_root_point_2 (const CoordNT& x, const CoordNT& y) : - Point_handle (Point_rep (x, y)) + _One_root_point_2(const CoordNT& x, const CoordNT& y) : + Point_handle(Point_rep(x, y)) {} /*! Get the x-coordinate. */ - const CoordNT& x () const - { - return (this->ptr()->_x); - } + const CoordNT& x() const { return (this->ptr()->_x); } /*! Get the y-coordinate. */ - const CoordNT& y () const - { - return (this->ptr()->_y); - } + const CoordNT& y() const { return (this->ptr()->_y); } /*! Check for equality. */ - bool equals (const Self& p) const + bool equals(const Self& p) const { - if (this->identical (p)) - return (true); + if (this->identical(p)) return (true); - return (CGAL::compare (this->ptr()->_x, p.ptr()->_x) == EQUAL && - CGAL::compare (this->ptr()->_y, p.ptr()->_y) == EQUAL); + return (CGAL::compare(this->ptr()->_x, p.ptr()->_x) == EQUAL && + CGAL::compare(this->ptr()->_y, p.ptr()->_y) == EQUAL); } - bool operator != (const Self& p) const - { - return !equals(p); - } + bool operator != (const Self& p) const { return ! equals(p); } + + bool operator == (const Self& p) const { return equals(p); } - bool operator == (const Self& p) const - { - return equals(p); - } /*! Set the point coordinates. */ - void set (const NT& x, const NT& y) + void set(const NT& x, const NT& y) { this->copy_on_write(); - this->ptr()->_x = CoordNT (x); - this->ptr()->_y = CoordNT (y); + this->ptr()->_x = CoordNT(x); + this->ptr()->_y = CoordNT(y); return; } /*! Set the point coordinates. */ - void set (const CoordNT& x, const CoordNT& y) + void set(const CoordNT& x, const CoordNT& y) { this->copy_on_write(); this->ptr()->_x = x; @@ -162,10 +139,9 @@ public: /*! * Exporter for conic arcs. */ -template -std::ostream& -operator<< (std::ostream& os, - const _One_root_point_2& p) +template +std::ostream& operator<<(std::ostream& os, + const _One_root_point_2& p) { os << CGAL::to_double(p.x()) << ' ' << CGAL::to_double(p.y()); return (os); @@ -186,11 +162,9 @@ std::istream & operator >> (std::istream & is, /*! \class * Representation of a circle, a circular arc or a line segment. */ -template -class _Circle_segment_2 -{ +template +class _Circle_segment_2 { public: - typedef Kernel_ Kernel; typedef typename Kernel::FT NT; typedef _One_root_point_2 Point_2; @@ -199,114 +173,101 @@ public: typedef typename Kernel::Line_2 Line_2; protected: - typedef typename Point_2::CoordNT CoordNT; // Data members: - Line_2 _line; // The supporting line (for line segments). - Circle_2 _circ; // The supporting circle (for circular arcs). - bool _is_full; // Whether we have a full circle. - bool _has_radius; // Is the radius (not just the squared radius) + Line_2 m_line; // The supporting line (for line segments). + Circle_2 m_circ; // The supporting circle (for circular arcs). + bool m_is_full; // Whether we have a full circle. + bool m_has_radius; // Is the radius (not just the squared radius) // explicitly specified). - NT _radius; // The radius, in case it is specified. - Point_2 _source; // The source point. - Point_2 _target; // The target point. - Orientation _orient; // The orientation (COLLINEAR for line segments). + NT m_radius; // The radius, in case it is specified. + Point_2 m_source; // The source point. + Point_2 m_target; // The target point. + Orientation m_orient; // The orientation (COLLINEAR for line segments). public: - /*! Default constructor. */ - _Circle_segment_2 () : - _is_full (false), - _has_radius (false), - _orient (COLLINEAR) + _Circle_segment_2() : + m_is_full(false), + m_has_radius(false), + m_orient(COLLINEAR) {} - /*! - * Constructor from a line segment. + /*! Constructor from a line segment. * \param seg The segment. */ - _Circle_segment_2 (const Segment_2& seg) : - _line (seg), - _is_full (false), - _has_radius (false), - _source (seg.source().x(), seg.source().y()), - _target (seg.target().x(), seg.target().y()), - _orient (COLLINEAR) + _Circle_segment_2(const Segment_2& seg) : + m_line(seg), + m_is_full(false), + m_has_radius(false), + m_source(seg.source().x(), seg.source().y()), + m_target(seg.target().x(), seg.target().y()), + m_orient(COLLINEAR) {} - /*! - * Constructor from of a line segment. + /*! Constructor from of a line segment. * \param ps The source point. * \param pt The target point. */ - _Circle_segment_2 (const typename Kernel::Point_2& ps, - const typename Kernel::Point_2& pt) : - _line (ps, pt), - _is_full (false), - _has_radius (false), - _source (ps.x(), ps.y()), - _target (pt.x(), pt.y()), - _orient (COLLINEAR) + _Circle_segment_2(const typename Kernel::Point_2& ps, + const typename Kernel::Point_2& pt) : + m_line(ps, pt), + m_is_full(false), + m_has_radius(false), + m_source(ps.x(), ps.y()), + m_target(pt.x(), pt.y()), + m_orient(COLLINEAR) {} - /*! - * Constructor of a segment, given a supporting line and two endpoints, + /*! Constructor of a segment, given a supporting line and two endpoints, * which need not necessarily have rational coordinates. * \param line The supporting line. * \param source The source point. * \param target The target point. * \pre Both endpoints lie on the supporting line. */ - _Circle_segment_2 (const Line_2& line, - const Point_2& source, const Point_2& target) : - _line (line), - _is_full (false), - _has_radius (false), - _source (source), - _target (target), - _orient (COLLINEAR) + _Circle_segment_2(const Line_2& line, + const Point_2& source, const Point_2& target) : + m_line(line), + m_is_full(false), + m_has_radius(false), + m_source(source), + m_target(target), + m_orient(COLLINEAR) { - CGAL_precondition (CGAL::compare (source.x()*line.a() + line.c(), - -source.y()*line.b()) == EQUAL); + CGAL_precondition(CGAL::compare(source.x() * line.a() + line.c(), + -source.y() * line.b()) == EQUAL); - CGAL_precondition (CGAL::compare (target.x()*line.a() + line.c(), - -target.y()*line.b()) == EQUAL); + CGAL_precondition(CGAL::compare(target.x() * line.a() + line.c(), + -target.y() * line.b()) == EQUAL); } - /*! - * Constructor from a circle. + /*! Constructor from a circle. * \param circ The circle. */ - _Circle_segment_2 (const Circle_2& circ) : - _circ (circ), - _is_full (true), - _has_radius (false), - _orient (circ.orientation()) - { - CGAL_assertion (_orient != COLLINEAR); - } + _Circle_segment_2(const Circle_2& circ) : + m_circ(circ), + m_is_full(true), + m_has_radius(false), + m_orient(circ.orientation()) + { CGAL_assertion(m_orient != COLLINEAR); } - /*! - * Constructor from a circle. + /*! Constructor from a circle. * \param c The circle center. * \param r The radius. * \param orient The orientation of the circle. */ - _Circle_segment_2 (const typename Kernel::Point_2& c, - const NT& r, - Orientation orient = COUNTERCLOCKWISE) : - _circ (c, r*r, orient), - _is_full (true), - _has_radius (true), - _radius (r), - _orient (orient) - { - CGAL_assertion (orient != COLLINEAR); - } + _Circle_segment_2(const typename Kernel::Point_2& c, const NT& r, + Orientation orient = COUNTERCLOCKWISE) : + m_circ(c, r*r, orient), + m_is_full(true), + m_has_radius(true), + m_radius(r), + m_orient(orient) + { CGAL_assertion (orient != COLLINEAR); } - /*! - * Constructor of a circular arc, given a supporting circle and two + /*! Constructor of a circular arc, given a supporting circle and two * endpoints, which need not necessarily have rational coordinates. * The orientation of the circle determines the orientation of the arc. * \param circ The supporting circle. @@ -314,30 +275,29 @@ public: * \param target The target point. * \pre Both endpoints lie on the supporting circle. */ - _Circle_segment_2 (const Circle_2& circ, - const Point_2& source, const Point_2& target) : - _circ (circ), - _is_full (false), - _has_radius (false), - _source (source), - _target (target), - _orient (circ.orientation()) + _Circle_segment_2(const Circle_2& circ, + const Point_2& source, const Point_2& target) : + m_circ(circ), + m_is_full(false), + m_has_radius(false), + m_source(source), + m_target(target), + m_orient(circ.orientation()) { - CGAL_assertion (_orient != COLLINEAR); + CGAL_assertion(m_orient != COLLINEAR); CGAL_precondition - (CGAL::compare (CGAL::square (source.x() - circ.center().x()), - circ.squared_radius() - - CGAL::square (source.y() - circ.center().y())) == EQUAL); + (CGAL::compare(CGAL::square(source.x() - circ.center().x()), + circ.squared_radius() - + CGAL::square(source.y() - circ.center().y())) == EQUAL); CGAL_precondition - (CGAL::compare (CGAL::square (target.x() - circ.center().x()), - circ.squared_radius() - - CGAL::square (target.y() - circ.center().y())) == EQUAL); + (CGAL::compare(CGAL::square(target.x() - circ.center().x()), + circ.squared_radius() - + CGAL::square(target.y() - circ.center().y())) == EQUAL); } - /*! - * Constructor of a circular arc, given a supporting circle and two + /*! Constructor of a circular arc, given a supporting circle and two * endpoints, which need not necessarily have rational coordinates. * \param c The circle center. * \param r The radius. @@ -346,86 +306,83 @@ public: * \param target The target point. * \pre Both endpoints lie on the supporting circle. */ - _Circle_segment_2 (const typename Kernel::Point_2& c, - const NT& r, Orientation orient, - const Point_2& source, const Point_2& target) : - _circ (c, r*r, orient), - _is_full (false), - _has_radius (true), - _radius (r), - _source (source), - _target (target), - _orient (orient) + _Circle_segment_2(const typename Kernel::Point_2& c, + const NT& r, Orientation orient, + const Point_2& source, const Point_2& target) : + m_circ(c, r*r, orient), + m_is_full(false), + m_has_radius(true), + m_radius(r), + m_source(source), + m_target(target), + m_orient(orient) { - CGAL_assertion (orient != COLLINEAR); + CGAL_assertion(orient != COLLINEAR); CGAL_precondition - (CGAL::compare (CGAL::square (source.x() - c.x()), - CGAL::square (r) - - CGAL::square (source.y() - c.y())) == EQUAL); + (CGAL::compare(CGAL::square(source.x() - c.x()), + CGAL::square(r) - + CGAL::square(source.y() - c.y())) == EQUAL); CGAL_precondition - (CGAL::compare (CGAL::square (target.x() - c.x()), - CGAL::square (r) - - CGAL::square (target.y() - c.y())) == EQUAL); + (CGAL::compare(CGAL::square(target.x() - c.x()), + CGAL::square(r) - + CGAL::square(target.y() - c.y())) == EQUAL); } - /*! - * Constructor of a circular arc, from the given three points, in case of + /*! Constructor of a circular arc, from the given three points, in case of * three collinear points, a segment will be constructed. * \param p1 The arc source. * \param p2 A point in the interior of the arc. * \param p3 The arc target. * \pre p1 and p3 are not equal. */ - _Circle_segment_2 (const typename Kernel::Point_2& p1, - const typename Kernel::Point_2& p2, - const typename Kernel::Point_2& p3) : - _is_full(false), - _has_radius(false), - _source(p1.x(), p1.y()), - _target(p3.x(), p3.y()) + _Circle_segment_2(const typename Kernel::Point_2& p1, + const typename Kernel::Point_2& p2, + const typename Kernel::Point_2& p3) : + m_is_full(false), + m_has_radius(false), + m_source(p1.x(), p1.y()), + m_target(p3.x(), p3.y()) { // Set the source and target. - NT x1 = p1.x(); - NT y1 = p1.y(); - NT x2 = p2.x(); - NT y2 = p2.y(); - NT x3 = p3.x(); - NT y3 = p3.y(); - + NT x1 = p1.x(); + NT y1 = p1.y(); + NT x2 = p2.x(); + NT y2 = p2.y(); + NT x3 = p3.x(); + NT y3 = p3.y(); // Make sure that the source and the target are not the same. - CGAL_precondition (Kernel().compare_xy_2_object() (p1, p3) != EQUAL); + CGAL_precondition(Kernel().compare_xy_2_object()(p1, p3) != EQUAL); // Compute the lines: A1*x + B1*y + C1 = 0, // and: A2*x + B2*y + C2 = 0, // where: - const NT _two = 2; + const NT _two = 2; - const NT A1 = _two*(x1 - x2); - const NT B1 = _two*(y1 - y2); - const NT C1 = CGAL::square(y2) - CGAL::square(y1) + - CGAL::square(x2) - CGAL::square(x1); + const NT A1 = _two*(x1 - x2); + const NT B1 = _two*(y1 - y2); + const NT C1 = + CGAL::square(y2) - CGAL::square(y1) + CGAL::square(x2) - CGAL::square(x1); - const NT A2 = _two*(x2 - x3); - const NT B2 = _two*(y2 - y3); - const NT C2 = CGAL::square(y3) - CGAL::square(y2) + - CGAL::square(x3) - CGAL::square(x2); + const NT A2 = _two*(x2 - x3); + const NT B2 = _two*(y2 - y3); + const NT C2 = + CGAL::square(y3) - CGAL::square(y2) + CGAL::square(x3) - CGAL::square(x2); // Compute the coordinates of the intersection point between the // two lines, given by (Nx / D, Ny / D), where: - const NT Nx = B1*C2 - B2*C1; - const NT Ny = A2*C1 - A1*C2; - const NT D = A1*B2 - A2*B1; + const NT Nx = B1*C2 - B2*C1; + const NT Ny = A2*C1 - A1*C2; + const NT D = A1*B2 - A2*B1; // Make sure the three points are not collinear. - const bool points_collinear = (CGAL::sign (D) == ZERO); + const bool points_collinear = (CGAL::sign (D) == ZERO); - if (points_collinear) - { - _line = Line_2(p1, p3); - _orient = COLLINEAR; + if (points_collinear) { + m_line = Line_2(p1, p3); + m_orient = COLLINEAR; return; } @@ -436,145 +393,118 @@ public: typename Kernel::Point_2 circ_center(x_center, y_center); - - - NT sqr_rad = (CGAL::square(D*x2 - Nx) + CGAL::square(D*y2 - Ny)) / - CGAL::square(D); + NT sqr_rad = + (CGAL::square(D*x2 - Nx) + CGAL::square(D*y2 - Ny)) / CGAL::square(D); // Determine the orientation: If the mid-point forms a left-turn with // the source and the target points, the orientation is positive (going // counterclockwise). // Otherwise, it is negative (going clockwise). - Kernel ker; + Kernel ker; typename Kernel::Orientation_2 orient_f = ker.orientation_2_object(); - if (orient_f(p1, p2, p3) == LEFT_TURN) - _orient = COUNTERCLOCKWISE; - else - _orient = CLOCKWISE; - - _circ = Circle_2(circ_center, sqr_rad, _orient); + if (orient_f(p1, p2, p3) == LEFT_TURN) m_orient = COUNTERCLOCKWISE; + else m_orient = CLOCKWISE; + m_circ = Circle_2(circ_center, sqr_rad, m_orient); } - /*! - * Get the orientation of the curve. + /*! Get the orientation of the curve. * \return COLLINEAR in case of a line segment, * CLOCKWISE or COUNTERCLOCKWISE for circular curves. */ - inline Orientation orientation () const - { - return (_orient); - } + inline Orientation orientation() const { return (m_orient); } /*! Check if the arc is linear. */ - inline bool is_linear () const - { - return (_orient == COLLINEAR); - } + inline bool is_linear() const { return (m_orient == COLLINEAR); } /*! Check if the arc is circular. */ - inline bool is_circular () const - { - return (_orient != COLLINEAR); - } + inline bool is_circular() const { return (m_orient != COLLINEAR); } - /*! - * Get the supporting line. + /*! Obtain the supporting line. * \pre The curve orientation is COLLINEAR. */ - const Line_2& supporting_line () const + const Line_2& supporting_line() const { - CGAL_precondition (_orient == COLLINEAR); - return (_line); + CGAL_precondition(m_orient == COLLINEAR); + return m_line; } - /*! - * Get the supporting circle. + /*! Obtain the supporting circle. * \pre The curve orientation is not COLLINEAR. */ - const Circle_2& supporting_circle () const + const Circle_2& supporting_circle() const { - CGAL_precondition (_orient != COLLINEAR); - return (_circ); + CGAL_precondition(m_orient != COLLINEAR); + return m_circ; } /*! Check if the curve is a full circle. */ - bool is_full () const - { - return (_is_full); - } + bool is_full() const { return (m_is_full); } /*! * Get the source point. * \pre The curve is not a full circle. */ - const Point_2& source () const + const Point_2& source() const { - CGAL_precondition (! _is_full); - return (_source); + CGAL_precondition(! m_is_full); + return (m_source); } /*! * Get the target point. * \pre The curve is not a full circle. */ - const Point_2& target () const + const Point_2& target() const { - CGAL_precondition (! _is_full); - return (_target); + CGAL_precondition(! m_is_full); + return (m_target); } - /*! - * Get the vertical tangency points the arc contains. + /*! Get the vertical tangency points the arc contains. * \param vpts Output: The vertical tangency points. * \pre The curve is circular. * \return The number of points (0, 1, or 2). */ - unsigned int vertical_tangency_points (Point_2 *vpts) const + unsigned int vertical_tangency_points(Point_2* vpts) const { - CGAL_precondition (_orient != COLLINEAR); - unsigned int n_vpts = 0; + CGAL_precondition(m_orient != COLLINEAR); + unsigned int n_vpts = 0; - if (_is_full) - { + if (m_is_full) { // In case of a full circle, create both vertical tangency points: - const NT& x0 = _circ.center().x(); - const NT& y0 = _circ.center().y(); - CoordNT xv_left; - CoordNT xv_right; + const NT& x0 = m_circ.center().x(); + const NT& y0 = m_circ.center().y(); + CoordNT xv_left; + CoordNT xv_right; - if (_has_radius) - { + if (m_has_radius) { // In case the radius is explicitly given: - xv_left = CoordNT (x0 - _radius); - xv_right = CoordNT (x0 + _radius); + xv_left = CoordNT(x0 - m_radius); + xv_right = CoordNT(x0 + m_radius); } - else - { + else { // In case only the squared root is given: - xv_left = CoordNT (x0, NT(-1), _circ.squared_radius()); - xv_right = CoordNT (x0, NT(1), _circ.squared_radius()); + xv_left = CoordNT(x0, NT(-1), m_circ.squared_radius()); + xv_right = CoordNT(x0, NT(1), m_circ.squared_radius()); } - vpts[0] = Point_2 (xv_left, y0); - vpts[1] = Point_2 (xv_right, y0); + vpts[0] = Point_2(xv_left, y0); + vpts[1] = Point_2(xv_right, y0); return (2); } - if (_orient == COUNTERCLOCKWISE) - { + if (m_orient == COUNTERCLOCKWISE) { // Compute the vertical tangency points for the arc: - n_vpts = _ccw_vertical_tangency_points (_source, _target, vpts); + n_vpts = _ccw_vertical_tangency_points(m_source, m_target, vpts); } - else - { + else { // Compute the vertical tangency points for the opposite arc: - n_vpts = _ccw_vertical_tangency_points (_target, _source, vpts); + n_vpts = _ccw_vertical_tangency_points(m_target, m_source, vpts); // Swap their order, if necessary. - if (n_vpts == 2) - { - Point_2 temp = vpts[0]; + if (n_vpts == 2) { + Point_2 temp = vpts[0]; vpts[0] = vpts[1]; vpts[1] = temp; } @@ -584,69 +514,62 @@ public: } private: - - /*! - * Get the vertical tangency points the arc contains, assuming it is + /*! Obtain the vertical tangency points the arc contains, assuming it is * counterclockwise oriented. * \param vpts Output: The vertical tangency points. * \return The number of points (0, 1, or 2). */ - unsigned int _ccw_vertical_tangency_points (const Point_2& src, - const Point_2& trg, - Point_2 *vpts) const + unsigned int _ccw_vertical_tangency_points(const Point_2& src, + const Point_2& trg, + Point_2* vpts) const { - unsigned int n_vpts = 0; - const NT& x0 = _circ.center().x(); - const NT& y0 = _circ.center().y(); - int qs = _quart_index (src); - int qt = _quart_index (trg); + unsigned int n_vpts = 0; + const NT& x0 = m_circ.center().x(); + const NT& y0 = m_circ.center().y(); + int qs = _quart_index(src); + int qt = _quart_index(trg); - if (qs == qt) - { - if ((qs == 0 || qs == 1) && CGAL::compare (src.x(), trg.x()) == LARGER) + if (qs == qt) { + if ((qs == 0 || qs == 1) && CGAL::compare(src.x(), trg.x()) == LARGER) // We have an x-monotone arc lying on the upper half of the circle: return (0); - if ((qs == 2 || qs == 3) && CGAL::compare (src.x(), trg.x()) == SMALLER) + if ((qs == 2 || qs == 3) && CGAL::compare(src.x(), trg.x()) == SMALLER) // We have an x-monotone arc lying on the lower half of the circle: return (0); } // Make sure the target quarter is larger than the source quarter, by // adding 4 to its index, if necessary. - if (qt <= qs) - qt += 4; + if (qt <= qs) qt += 4; // Start traversing the quarter-planes and collect the vertical tangency // points we encounter. - while (qs < qt) - { - if ((qs % 4) == 1) - { + while (qs < qt) { + if ((qs % 4) == 1) { // We collect the left tangency point when going from Q[1] to Q[2]: - if (CGAL::compare (x0, trg.x()) != LARGER || - CGAL::compare (y0, trg.y()) != EQUAL) + if (CGAL::compare(x0, trg.x()) != LARGER || + CGAL::compare(y0, trg.y()) != EQUAL) { - if (_has_radius) - vpts[n_vpts] = Point_2 (CoordNT (x0 - _radius), y0); + if (m_has_radius) + vpts[n_vpts] = Point_2(CoordNT(x0 - m_radius), y0); else - vpts[n_vpts] = Point_2 (CoordNT (x0, NT(-1), _circ.squared_radius()), - y0); + vpts[n_vpts] = + Point_2(CoordNT(x0, NT(-1), m_circ.squared_radius()), y0); n_vpts++; } } - else if ((qs % 4) == 3) - { + else if ((qs % 4) == 3) { // We collect the right tangency point when going from Q[3] to Q[0]: - if (CGAL::compare (x0, trg.x()) != SMALLER || - CGAL::compare (y0, trg.y()) != EQUAL) + if (CGAL::compare(x0, trg.x()) != SMALLER || + CGAL::compare(y0, trg.y()) != EQUAL) { - if (_has_radius) - vpts[n_vpts] = Point_2 (CoordNT (x0 + _radius), y0); + if (m_has_radius) + vpts[n_vpts] = Point_2(CoordNT(x0 + m_radius), y0); else - vpts[n_vpts] = Point_2 (CoordNT (x0, NT(1), _circ.squared_radius()), - y0); + vpts[n_vpts] = + Point_2(CoordNT(x0, NT(1), m_circ.squared_radius()), y0); n_vpts++; } } @@ -657,11 +580,10 @@ private: return (n_vpts); } - /*! - * Get the index of the quarter-plane containing the given point, + /*! Obtain the index of the quarter-plane containing the given point, * where the circle center is considered to be the origin. */ - int _quart_index (const Point_2& p) const + int _quart_index(const Point_2& p) const { // The plane looks like: // @@ -673,44 +595,32 @@ private: // x < 0 | x >= 0 // y <= 0 | y < 0 // - const CGAL::Sign sign_x = CGAL::sign (p.x() - _circ.center().x()); - const CGAL::Sign sign_y = CGAL::sign (p.y() - _circ.center().y()); + const CGAL::Sign sign_x = CGAL::sign(p.x() - m_circ.center().x()); + const CGAL::Sign sign_y = CGAL::sign(p.y() - m_circ.center().y()); - if (sign_x == POSITIVE) - { - return ((sign_y == NEGATIVE) ? 3 : 0); - } - else if (sign_x == NEGATIVE) - { - return ((sign_y == POSITIVE) ? 1 : 2); - } + if (sign_x == POSITIVE) return ((sign_y == NEGATIVE) ? 3 : 0); + else if (sign_x == NEGATIVE) return ((sign_y == POSITIVE) ? 1 : 2); CGAL_assertion (sign_y != ZERO); return ((sign_y == POSITIVE) ? 1 : 3); } }; -/*! - * Exporter for line segments and circular arcs. +/*! Exporter for line segments and circular arcs. */ -template +template std::ostream& -operator<< (std::ostream& os, - const _Circle_segment_2& c) +operator<<(std::ostream& os, const _Circle_segment_2& c) { - if (c.orientation() == COLLINEAR) - { + if (c.orientation() == COLLINEAR) { os<< "segment: " << c.source() << " -> " << c.target(); } - else - { - if(!c.is_full()) - { + else { + if (! c.is_full()) { os << "circular arc: " << c.supporting_circle() << ' ' << c.source() << " -> " << c.target(); } - else - { + else { os << "circular arc: " << c.supporting_circle(); } } @@ -721,11 +631,9 @@ operator<< (std::ostream& os, /*! \class * Representation of an x-monotone circular arc. */ -template -class _X_monotone_circle_segment_2 -{ +template +class _X_monotone_circle_segment_2 { public: - typedef Kernel_ Kernel; typedef _X_monotone_circle_segment_2 Self; typedef typename Kernel::FT NT; @@ -735,17 +643,16 @@ public: typedef typename Point_2::CoordNT CoordNT; // Type definition for the intersection points mapping. - typedef std::pair Curve_id_pair; - typedef unsigned int Multiplicity; - typedef std::pair Intersection_point_2; - typedef std::list Intersection_list; + typedef std::pair Curve_id_pair; + typedef unsigned int Multiplicity; + typedef std::pair Intersection_point; + typedef std::list Intersection_list; /*! * \struct Less functor for Curve_id_pair. */ - struct Less_id_pair - { - bool operator() (const Curve_id_pair& ip1, const Curve_id_pair& ip2) const + struct Less_id_pair { + bool operator()(const Curve_id_pair& ip1, const Curve_id_pair& ip2) const { // Compare the pairs of IDs lexicographically. return (ip1.first < ip2.first || @@ -753,25 +660,20 @@ public: } }; - typedef std::map Intersection_map; + typedef std::map + Intersection_map; typedef typename Intersection_map::value_type Intersection_map_entry; typedef typename Intersection_map::iterator Intersection_map_iterator; protected: - - NT _first; // The x-coordinate of the circle center. - // Or: the coefficient of x in the line equation. - - NT _second; // The y-coordinate of the circle center. - // Or: the coefficient of y in the line equation. - - NT _third; // The squared radius of the supporting circle. - // Or: the free coefficient in the line equation. - - Point_2 _source; // The source point. - Point_2 _target; // The target point. + NT m_first; // The x-coordinate of the circle center. + // Or: the coefficient of x in the line equation. + NT m_second; // The y-coordinate of the circle center. + // Or: the coefficient of y in the line equation. + NT m_third; // The squared radius of the supporting circle. + // Or: the free coefficient in the line equation. + Point_2 m_source; // The source point. + Point_2 m_target; // The target point. enum { IS_DIRECTED_RIGHT_MASK = 1, @@ -782,7 +684,7 @@ protected: INDEX_SHIFT_BITS = 4 }; - unsigned int _info; // A bit vector, where: + unsigned int m_info; // A bit vector, where: // Bit 0 (the LSB): marks if the arc is directed // from left to right. // Bit 1: marks if the arc is a vertical segment. @@ -790,408 +692,321 @@ protected: // The rest of the bits represent the curve index. public: - - /*! - * Default constructor. + /*! Default constructor. */ - _X_monotone_circle_segment_2 () : - _first(), - _second(), - _third(), - _source(), - _target(), - _info (0) + _X_monotone_circle_segment_2() : + m_first(), + m_second(), + m_third(), + m_source(), + m_target(), + m_info(0) {} - /*! - * Construct an arc from a line segment. + /*! Construct an arc from a line segment. * \param line The supporting line. * \param source The source point. * \param target The target point. */ - _X_monotone_circle_segment_2 (const Line_2& line, - const Point_2& source, const Point_2& target, - unsigned int index = 0) : - _first (line.a()), - _second (line.b()), - _third (line.c()), - _source (source), - _target(target), - _info (index << INDEX_SHIFT_BITS) + _X_monotone_circle_segment_2(const Line_2& line, + const Point_2& source, const Point_2& target, + unsigned int index = 0) : + m_first(line.a()), + m_second(line.b()), + m_third(line.c()), + m_source(source), + m_target(target), + m_info(index << INDEX_SHIFT_BITS) { // Check if the segment is directed left or right: - Comparison_result res = CGAL::compare (source.x(), target.x()); + Comparison_result res = CGAL::compare(source.x(), target.x()); - if (res == EQUAL) - { - CGAL_precondition (CGAL::sign(_second) == ZERO); + if (res == EQUAL) { + CGAL_precondition(CGAL::sign(m_second) == ZERO); // We have a vertical segment - compare the points by their // y-coordinates: - _info = (_info | IS_VERTICAL_SEGMENT_MASK); - res = CGAL::compare (source.y(), target.y()); + m_info = (m_info | IS_VERTICAL_SEGMENT_MASK); + res = CGAL::compare(source.y(), target.y()); } - CGAL_precondition (res != EQUAL); - if (res == SMALLER) - _info = (_info | IS_DIRECTED_RIGHT_MASK); + CGAL_precondition(res != EQUAL); + if (res == SMALLER) m_info = (m_info | IS_DIRECTED_RIGHT_MASK); } - /*! - * Construct a segment arc from two kernel points + /*! Construct a segment arc from two kernel points * \param source the source point. * \ param target the target point. * \pre source and target are not equal. */ - _X_monotone_circle_segment_2 (const typename Kernel::Point_2& source, - const typename Kernel::Point_2& target) : - _source(source.x(), source.y()), - _target(target.x(), target.y()), - _info (0) + _X_monotone_circle_segment_2(const typename Kernel::Point_2& source, + const typename Kernel::Point_2& target) : + m_source(source.x(), source.y()), + m_target(target.x(), target.y()), + m_info(0) { Line_2 line(source, target); - _first = line.a(); - _second = line.b(); - _third = line.c(); + m_first = line.a(); + m_second = line.b(); + m_third = line.c(); // Check if the segment is directed left or right: - Comparison_result res = CGAL::compare (source.x(), target.x()); + Comparison_result res = CGAL::compare(source.x(), target.x()); - if (res == EQUAL) - { - CGAL_precondition (CGAL::sign(_second) == ZERO); + if (res == EQUAL) { + CGAL_precondition(CGAL::sign(m_second) == ZERO); // We have a vertical segment - compare the points by their // y-coordinates: - _info = (_info | IS_VERTICAL_SEGMENT_MASK); - res = CGAL::compare (source.y(), target.y()); + m_info = (m_info | IS_VERTICAL_SEGMENT_MASK); + res = CGAL::compare(source.y(), target.y()); } - CGAL_precondition (res != EQUAL); - if (res == SMALLER) - _info = (_info | IS_DIRECTED_RIGHT_MASK); + CGAL_precondition(res != EQUAL); + if (res == SMALLER) m_info = (m_info | IS_DIRECTED_RIGHT_MASK); } - /*! - * Construct a circular arc. + /*! Construct a circular arc. * \param line The supporting line. * \param source The source point. * \param target The target point. * \param orient The orientation of the arc. */ - _X_monotone_circle_segment_2 (const Circle_2& circ, - const Point_2& source, const Point_2& target, - Orientation orient, - unsigned int index = 0) : - _first (circ.center().x()), - _second (circ.center().y()), - _third (circ.squared_radius()), - _source (source), - _target(target), - _info (index << INDEX_SHIFT_BITS) + _X_monotone_circle_segment_2(const Circle_2& circ, + const Point_2& source, const Point_2& target, + Orientation orient, + unsigned int index = 0) : + m_first(circ.center().x()), + m_second(circ.center().y()), + m_third(circ.squared_radius()), + m_source(source), + m_target(target), + m_info(index << INDEX_SHIFT_BITS) { // Check if the segment is directed left or right: - Comparison_result res = CGAL::compare (source.x(), target.x()); + Comparison_result res = CGAL::compare (source.x(), target.x()); - CGAL_precondition (res != EQUAL); - if (res == SMALLER) - _info = (_info | IS_DIRECTED_RIGHT_MASK); + CGAL_precondition(res != EQUAL); + if (res == SMALLER) m_info = (m_info | IS_DIRECTED_RIGHT_MASK); // Set the orientation. CGAL_precondition (orient != COLLINEAR); - if (orient == COUNTERCLOCKWISE) - _info = (_info | COUNTERCLOCKWISE_CODE); - else - _info = (_info | CLOCKWISE_CODE); + if (orient == COUNTERCLOCKWISE) m_info = (m_info | COUNTERCLOCKWISE_CODE); + else m_info = (m_info | CLOCKWISE_CODE); } /*! Check if the arc is linear. */ - inline bool is_linear () const - { - return ((_info & ORIENTATION_MASK) == 0); - } + inline bool is_linear () const { return ((m_info & ORIENTATION_MASK) == 0); } /*! Check if the arc is circular. */ inline bool is_circular () const - { - return ((_info & ORIENTATION_MASK) != 0); - } + { return ((m_info & ORIENTATION_MASK) != 0); } - /*! - * Get the supporting line. + /*! Obtain the supporting line. * \pre The arc is linear (a line segment). */ - Line_2 supporting_line () const + Line_2 supporting_line() const { CGAL_precondition (is_linear()); - return (Line_2 (a(), b(), c())); } - /*! - * Get the supporting circle. + /*! Obtain the supporting circle. * \pre The arc is circular. */ - Circle_2 supporting_circle () const + Circle_2 supporting_circle() const { CGAL_precondition (is_circular()); - typename Kernel::Point_2 center (x0(), y0()); - return (Circle_2 (center , sqr_r(), orientation())); + typename Kernel::Point_2 center(x0(), y0()); + return (Circle_2(center , sqr_r(), orientation())); } /*! Get the source point. */ - inline const Point_2& source () const - { - return (_source); - } + inline const Point_2& source() const { return (m_source); } /*! Get the target point. */ - inline const Point_2& target () const - { - return (_target); - } + inline const Point_2& target() const { return (m_target); } /*! True if the arc is directed right, false otherwise. */ - bool is_directed_right () const - { - return ((_info & IS_DIRECTED_RIGHT_MASK) != 0); - } + bool is_directed_right() const + { return ((m_info & IS_DIRECTED_RIGHT_MASK) != 0); } - bool has_left() const - { - return true; - } + bool has_left() const { return true; } - bool has_right() const - { - return true; - } + bool has_right() const { return true; } /*! Get the left endpoint of the arc. */ - inline const Point_2& left () const - { - return (((_info & IS_DIRECTED_RIGHT_MASK) != 0) ? _source : _target); - } + inline const Point_2& left() const + { return (((m_info & IS_DIRECTED_RIGHT_MASK) != 0) ? m_source : m_target); } /*! Get the right endpoint of the arc. */ - inline const Point_2& right () const - { - return (((_info & IS_DIRECTED_RIGHT_MASK) != 0) ? _target : _source); - } + inline const Point_2& right() const + { return (((m_info & IS_DIRECTED_RIGHT_MASK) != 0) ? m_target : m_source); } - /*! - * Check whether the given point is in the x-range of the arc. + /*! Check whether the given point is in the x-range of the arc. */ - bool is_in_x_range (const Point_2& p) const + bool is_in_x_range(const Point_2& p) const { - Comparison_result res = CGAL::compare (p.x(), left().x()); + Comparison_result res = CGAL::compare (p.x(), left().x()); - if (res == SMALLER) - return (false); - else if (res == EQUAL) - return (true); + if (res == SMALLER) return false; + else if (res == EQUAL) return true; return (CGAL::compare (p.x(), right().x()) != LARGER); } /*! Check if the arc is a vertical segment. */ - inline bool is_vertical () const - { - return ((_info & IS_VERTICAL_SEGMENT_MASK) != 0); - } + inline bool is_vertical() const + { return ((m_info & IS_VERTICAL_SEGMENT_MASK) != 0); } /*! Get the orientation of the arc. */ inline Orientation orientation() const { - unsigned int _or = (_info & ORIENTATION_MASK); + unsigned int or_ = (m_info & ORIENTATION_MASK); + if (or_ == COUNTERCLOCKWISE_CODE) return (CGAL::COUNTERCLOCKWISE); + else if (or_ == CLOCKWISE_CODE) return (CGAL::CLOCKWISE); - if (_or == COUNTERCLOCKWISE_CODE) - return (CGAL::COUNTERCLOCKWISE); - else if (_or == CLOCKWISE_CODE) - return (CGAL::CLOCKWISE); - - CGAL_assertion (_or == 0); + CGAL_assertion(or_ == 0); return (CGAL::COLLINEAR); } - /*! - * Check the position of a given point with respect to the arc. + /*! Check the position of a given point with respect to the arc. */ - Comparison_result point_position (const Point_2& p) const + Comparison_result point_position(const Point_2& p) const { - if (is_linear()) - return (_line_point_position (p)); - else - return (_circ_point_position (p)); + if (is_linear()) return (_line_point_position(p)); + else return (_circ_point_position (p)); } - - /*! - * Compare the two arcs to the right of their intersection point. + /*! Compare the two arcs to the right of their intersection point. */ - Comparison_result compare_to_right (const Self& cv, const Point_2& p) const + Comparison_result compare_to_right(const Self& cv, const Point_2& p) const { - if (is_linear()) - { - if (cv.is_linear()) - return (_lines_compare_to_right (cv, p)); - - Comparison_result res = cv._circ_line_compare_to_right (*this, p); - - if (res != EQUAL) - res = (res == SMALLER) ? LARGER : SMALLER; - + if (is_linear()) { + if (cv.is_linear()) return (_lines_compare_to_right (cv, p)); + Comparison_result res = cv._circ_line_compare_to_right (*this, p); + if (res != EQUAL) res = (res == SMALLER) ? LARGER : SMALLER; return (res); } - else - { - if (cv.is_linear()) - return (_circ_line_compare_to_right (cv, p)); - + else { + if (cv.is_linear()) return (_circ_line_compare_to_right (cv, p)); return (_circs_compare_to_right (cv, p)); } } - /*! - * Compare the two arcs to the left of their intersection point. + /*! Compare the two arcs to the left of their intersection point. */ - Comparison_result compare_to_left (const Self& cv, const Point_2& p) const + Comparison_result compare_to_left(const Self& cv, const Point_2& p) const { - if (is_linear()) - { - if (cv.is_linear()) - return (_lines_compare_to_left (cv, p)); - - Comparison_result res = cv._circ_line_compare_to_left (*this, p); - - if (res != EQUAL) - res = (res == SMALLER) ? LARGER : SMALLER; - + if (is_linear()) { + if (cv.is_linear()) return (_lines_compare_to_left (cv, p)); + Comparison_result res = cv._circ_line_compare_to_left(*this, p); + if (res != EQUAL) res = (res == SMALLER) ? LARGER : SMALLER; return (res); } - else - { - if (cv.is_linear()) - return (_circ_line_compare_to_left (cv, p)); - + else { + if (cv.is_linear()) return (_circ_line_compare_to_left(cv, p)); return (_circs_compare_to_left (cv, p)); } } - /*! - * Check whether the two arcs have the same supporting curve. + /*! Check whether the two arcs have the same supporting curve. */ - bool has_same_supporting_curve (const Self& cv) const + bool has_same_supporting_curve(const Self& cv) const { // Check if the curve indices are the same. - if (_index() != 0 && _index() == cv._index()) - return (true); + if (_index() != 0 && _index() == cv._index()) return true; // Make sure that the supporting curves are of the same type. - if (is_linear() && ! cv.is_linear()) - return (false); + if (is_linear() && ! cv.is_linear()) return false; - if (! is_linear() && cv.is_linear()) - return (false); + if (! is_linear() && cv.is_linear()) return false; // Compare the curve coefficients. - if (! is_linear()) - { + if (! is_linear()) { // The two circles must have the same center and the same radius. - return (CGAL::compare (x0(), cv.x0()) == EQUAL && - CGAL::compare (y0(), cv.y0()) == EQUAL && - CGAL::compare (sqr_r(), cv.sqr_r()) == EQUAL); + return (CGAL::compare(x0(), cv.x0()) == EQUAL && + CGAL::compare(y0(), cv.y0()) == EQUAL && + CGAL::compare(sqr_r(), cv.sqr_r()) == EQUAL); } // Compare the line equations: Note that these may be scaled. - NT fact1; - NT fact2; + NT fact1; + NT fact2; - if (is_vertical()) - { - if (! cv.is_vertical()) - return (false); + if (is_vertical()) { + if (! cv.is_vertical()) return false; fact1 = a(); fact2 = cv.a(); } - else - { + else { fact1 = b(); fact2 = cv.b(); } - return (CGAL::compare (fact2*a(), fact1*cv.a()) == EQUAL && - CGAL::compare (fact2*b(), fact1*cv.b()) == EQUAL && - CGAL::compare (fact2*c(), fact1*cv.c()) == EQUAL); + return (CGAL::compare(fact2*a(), fact1*cv.a()) == EQUAL && + CGAL::compare(fact2*b(), fact1*cv.b()) == EQUAL && + CGAL::compare(fact2*c(), fact1*cv.c()) == EQUAL); } - /*! - * Check if the two curves are equal. + /*! Check whether the two curves are equal. */ - bool equals (const Self& cv) const + bool equals(const Self& cv) const { - if (! this->has_same_supporting_curve (cv)) - return (false); + if (! this->has_same_supporting_curve(cv)) return false; - if (is_linear()) - { + if (is_linear()) { // In case of line segments we can swap the source and target: - return ((_source.equals (cv._source) && _target.equals (cv._target)) || - (_source.equals (cv._target) && _target.equals (cv._source))); + return ((m_source.equals(cv.m_source) && m_target.equals(cv.m_target)) || + (m_source.equals(cv.m_target) && m_target.equals(cv.m_source))); } // Once again, opposite circular arcs are considered to be equal: return ((orientation() == cv.orientation() && - _source.equals (cv._source) && _target.equals (cv._target)) || + m_source.equals(cv.m_source) && m_target.equals(cv.m_target)) || (orientation() != cv.orientation() && - _source.equals (cv._target) && _target.equals (cv._source))); + m_source.equals(cv.m_target) && m_target.equals(cv.m_source))); } - /*! - * Split the curve at a given point into two sub-arcs. + /*! Split the curve at a given point into two sub-arcs. */ - void split (const Point_2& p, Self& c1, Self& c2) const + void split(const Point_2& p, Self& c1, Self& c2) const { // Copy the properties of this arc to the sub-arcs. c1 = *this; c2 = *this; // Change the endpoint, such that c1 lies to the right of c2: - if (is_directed_right()) - { - c1._target = p; - c2._source = p; + if (is_directed_right()) { + c1.m_target = p; + c2.m_source = p; } - else - { - c1._source = p; - c2._target = p; + else { + c1.m_source = p; + c2.m_target = p; } - - return; } - /*! - * Compute the intersections between the two arcs or segments. + /*! Compute the intersections between the two arcs or segments. */ - template - OutputIterator intersect (const Self& cv, OutputIterator oi, - Intersection_map *inter_map = nullptr) const + template + OutputIterator intersect(const Self& cv, OutputIterator oi, + Intersection_map* inter_map = nullptr) const { - // First check whether the two arcs have the same supporting curve. - if (has_same_supporting_curve (cv)) - { - // Check for overlaps between the two arcs. - Self overlap; + typedef std::pair Intersection_point; + typedef boost::variant Intersection_result; - if (_compute_overlap (cv, overlap)) - { + // First check whether the two arcs have the same supporting curve. + if (has_same_supporting_curve(cv)) { + // Check for overlaps between the two arcs. + Self overlap; + + if (_compute_overlap(cv, overlap)) { // There can be just a single overlap between two x-monotone arcs: - *oi = CGAL::make_object (overlap); - ++oi; - return (oi); + *oi++ = Intersection_result(overlap); + return oi; } // In case there is not overlap and the supporting curves are the same, @@ -1199,155 +1014,121 @@ public: // a common end point. // Note that in this case we do not define the multiplicity of the // intersection points we report. - unsigned int mult = 0; - if (left().equals (cv.left()) || left().equals(cv.right())) - { - *oi = CGAL::make_object (std::make_pair (left(), mult)); - ++oi; + Multiplicity mult = 0; + if (left().equals(cv.left()) || left().equals(cv.right())) { + *oi++ = Intersection_result(std::make_pair(left(), mult)); } - if (right().equals (cv.right()) || right().equals(cv.left())) - { - *oi = CGAL::make_object (std::make_pair (right(), mult)); - ++oi; + if (right().equals(cv.right()) || right().equals(cv.left())) { + *oi++ = Intersection_result(std::make_pair(right(), mult)); } - return (oi); + return oi; } // Before computing the intersection points between the two supporting // curves, check if their intersection has already been computed and // cached. - Curve_id_pair id_pair; - Intersection_map_iterator map_iter; - Intersection_list inter_list; - bool invalid_ids = false; + Curve_id_pair id_pair; + Intersection_map_iterator map_iter; + Intersection_list inter_list; + bool invalid_ids = false; - if (inter_map != nullptr && _index() != 0 && cv._index() != 0) - { + if (inter_map != nullptr && _index() != 0 && cv._index() != 0) { if (_index() < cv._index()) id_pair = Curve_id_pair (_index(), cv._index()); - else - id_pair = Curve_id_pair (cv._index(), _index()); + else id_pair = Curve_id_pair (cv._index(), _index()); - map_iter = inter_map->find (id_pair); + map_iter = inter_map->find(id_pair); } - else - { + else { // In case one of the IDs is invalid, we do not look in the map neither // we cache the results. - if (inter_map != nullptr) - map_iter = inter_map->end(); + if (inter_map != nullptr) map_iter = inter_map->end(); invalid_ids = true; } - if (inter_map == nullptr || map_iter == inter_map->end()) - { + if ((inter_map == nullptr) || (map_iter == inter_map->end())) { // Compute the intersections points between the two supporting curves. - if (is_linear()) - { - if (cv.is_linear()) - _lines_intersect (cv, inter_list); - else - cv._circ_line_intersect (*this, inter_list); + if (is_linear()) { + if (cv.is_linear()) _lines_intersect(cv, inter_list); + else cv._circ_line_intersect(*this, inter_list); } - else - { - if (cv.is_linear()) - _circ_line_intersect (cv, inter_list); - else - _circs_intersect (cv, inter_list); + else { + if (cv.is_linear()) _circ_line_intersect(cv, inter_list); + else _circs_intersect(cv, inter_list); } // Cache the result. - if (! invalid_ids) - (*inter_map)[id_pair] = inter_list; + if (! invalid_ids) (*inter_map)[id_pair] = inter_list; } - else - { + else { // Obtain the precomputed intersection points from the map. inter_list = (*map_iter).second; } // Report only the intersection points that lie on both arcs. - typename Intersection_list::const_iterator iter; - - for (iter = inter_list.begin(); iter != inter_list.end(); ++iter) - { + for (auto iter = inter_list.begin(); iter != inter_list.end(); ++iter) { if (this->_is_between_endpoints (iter->first) && cv._is_between_endpoints (iter->first)) { - *oi = CGAL::make_object (*iter); - ++oi; + *oi++ = Intersection_result(*iter); } } - return (oi); + return oi; } - /*! - * Check whether it is possible to merge our arc with the given arc. + /*! Check whether it is possible to merge our arc with the given arc. */ - bool can_merge_with (const Self& cv) const + bool can_merge_with(const Self& cv) const { // In order to merge the two arcs, they should have the same supporting // curve. - if (! this->has_same_supporting_curve (cv)) - return (false); + if (! this->has_same_supporting_curve(cv)) return false; // Check if the left endpoint of one curve is the right endpoint of the // other. - return (right().equals (cv.left()) || - left().equals (cv.right())); + return (right().equals(cv.left()) || left().equals(cv.right())); } - /*! - * Merge our arc with the given arc. + /*! Merge our arc with the given arc. * \pre The two arcs are mergeable. */ - void merge (const Self& cv) + void merge(const Self& cv) { - CGAL_precondition (this->can_merge_with (cv)); + CGAL_precondition(this->can_merge_with (cv)); // Check if we should extend the arc to the left or to the right. - if (right().equals (cv.left())) - { + if (right().equals(cv.left())) { // Extend the arc to the right. - if (is_directed_right()) - this->_target = cv.right(); - else - this->_source = cv.right(); + if (is_directed_right()) this->m_target = cv.right(); + else this->m_source = cv.right(); } - else - { - CGAL_precondition (left().equals (cv.right())); + else { + CGAL_precondition(left().equals(cv.right())); // Extend the arc to the left. - if (is_directed_right()) - this->_source = cv.left(); - else - this->_target = cv.left(); + if (is_directed_right()) this->m_source = cv.left(); + else this->m_target = cv.left(); } - - return; } /*! construct an opposite arc. */ Self construct_opposite() const { Self opp_cv; - opp_cv._first = this->_first; - opp_cv._second = this-> _second; - opp_cv._third = this-> _third; - opp_cv._source = this->_target; - opp_cv._target = this->_source; + opp_cv.m_first = this->m_first; + opp_cv.m_second = this->m_second; + opp_cv.m_third = this->m_third; + opp_cv.m_source = this->m_target; + opp_cv.m_target = this->m_source; // Take care of the information bits: We flip the orientation bits and // the bits that marks the direction. - if (is_linear()) - opp_cv._info = (this->_info ^ IS_DIRECTED_RIGHT_MASK); + if (is_linear()) opp_cv.m_info = (this->m_info ^ IS_DIRECTED_RIGHT_MASK); else - opp_cv._info = (this->_info ^ IS_DIRECTED_RIGHT_MASK ^ ORIENTATION_MASK); + opp_cv.m_info = (this->m_info ^ IS_DIRECTED_RIGHT_MASK ^ ORIENTATION_MASK); return (opp_cv); } @@ -1358,65 +1139,47 @@ public: double x_max = to_double(right().x()); double y_min = to_double(left().y()); double y_max = to_double(right().y()); - if(y_min > y_max) - std::swap(y_min, y_max); - if(is_circular()) - { + if (y_min > y_max) std::swap(y_min, y_max); + if (is_circular()) { const Circle_2& circ = this->supporting_circle(); - if(_is_upper()) - { + if (_is_upper()) { y_max = to_double(circ.center().y())+ - std::sqrt(to_double(circ.squared_radius())); + std::sqrt(to_double(circ.squared_radius())); } - else - { + else { y_min = to_double(circ.center().y()) - - std::sqrt(to_double(circ.squared_radius())); + std::sqrt(to_double(circ.squared_radius())); } } - return Bbox_2(x_min, y_min, x_max, y_max); } protected: - /*! Get the curve index. */ - inline unsigned int _index () const - { - return (_info >> INDEX_SHIFT_BITS); - } + inline unsigned int _index() const { return (m_info >> INDEX_SHIFT_BITS); } /// \name Accessors for circular arcs. //@{ /*! Get the x-coordinate of the center of the supporting circle. */ - inline const NT& x0 () const - { - return (_first); - } + inline const NT& x0() const { return (m_first); } /*! Get the y-coordinate of the center of the supporting circle. */ - inline const NT& y0 () const - { - return (_second); - } + inline const NT& y0() const { return (m_second); } /*! Get the squared radius of the supporting circle. */ - inline const NT& sqr_r () const - { - return (_third); - } + inline const NT& sqr_r() const { return (m_third); } /*! * Check if the circular arc lies on the upper half of the supporting circle. */ - inline bool _is_upper () const + inline bool _is_upper() const { - Orientation orient = orientation(); - bool dir_right = ((_info & IS_DIRECTED_RIGHT_MASK) != 0); + Orientation orient = orientation(); + bool dir_right = ((m_info & IS_DIRECTED_RIGHT_MASK) != 0); - CGAL_precondition (orient != COLLINEAR); + CGAL_precondition(orient != COLLINEAR); return ((orient == COUNTERCLOCKWISE && !dir_right) || (orient == CLOCKWISE && dir_right)); @@ -1427,22 +1190,13 @@ protected: //@{ /*! Get the coefficient of x in the equation of the supporting line. */ - inline const NT& a () const - { - return (_first); - } + inline const NT& a() const { return (m_first); } /*! Get the coefficient of y in the equation of the supporting line. */ - inline const NT& b () const - { - return (_second); - } + inline const NT& b() const { return (m_second); } /*! Get the free coefficient in the equation of the supporting line. */ - inline const NT& c () const - { - return (_third); - } + inline const NT& c() const { return (m_third); } //@} /// \name Auxiliary functions for the point_position predicate. @@ -1451,27 +1205,24 @@ protected: /*! * Check the position of a given point with respect to a line segment. */ - Comparison_result _line_point_position (const Point_2& p) const + Comparison_result _line_point_position(const Point_2& p) const { // Check if we have a vertical segment. - CGAL_precondition (is_in_x_range(p)); + CGAL_precondition(is_in_x_range(p)); - Comparison_result res; + Comparison_result res; - if (is_vertical()) - { + if (is_vertical()) { // left() is the lower endpoint: - res = CGAL::compare (p.y(), left().y()); + res = CGAL::compare(p.y(), left().y()); - if (res != LARGER) - return (res); + if (res != LARGER) return (res); // left() is the upper endpoint: res = CGAL::compare (p.y(), right().y()); - if (res != SMALLER) - return (res); + if (res != SMALLER) return (res); // p lies in the interior of the vertical segment: return (EQUAL); @@ -1487,19 +1238,17 @@ protected: /*! * Check the position of a given point with respect to a circular arc. */ - Comparison_result _circ_point_position (const Point_2& p) const + Comparison_result _circ_point_position(const Point_2& p) const { - Comparison_result c_res = CGAL::compare (p.y(), y0()); + Comparison_result c_res = CGAL::compare (p.y(), y0()); - if (_is_upper()) - { + if (_is_upper()) { // Check if p lies below the "equator" (while the arc lies above it): if (c_res == SMALLER) return (SMALLER); } - else - { + else { // Check if p lies above the "equator" (while the arc lies below it): if (c_res == LARGER) return (LARGER); @@ -1507,21 +1256,18 @@ protected: // Check if p lies inside the supporting circle, namely we have to check // whether (p.x() - x0)^2 + (p.y() - y0)^2 < r^2: - Comparison_result res = - CGAL::compare (CGAL::square (p.x() - x0()), - sqr_r() - CGAL::square (p.y() - y0())); + Comparison_result res = + CGAL::compare(CGAL::square (p.x() - x0()), + sqr_r() - CGAL::square (p.y() - y0())); - if (res == EQUAL) - // p lies on the circle: - return (EQUAL); + // p lies on the circle: + if (res == EQUAL) return (EQUAL); - if (_is_upper()) - { + if (_is_upper()) { // If p is inside the circle, it lies below the upper arc: return (res); } - else - { + else { // If p is inside the circle, it lies above the lower arc: return (res == SMALLER ? LARGER : SMALLER); } @@ -1534,25 +1280,18 @@ protected: /*! * Compare two line segments to the right of their intersection point. */ - Comparison_result _lines_compare_to_right (const Self& cv, - const Point_2& /* p */) const + Comparison_result _lines_compare_to_right(const Self& cv, + const Point_2& /* p */) const { - if (_index() != 0 && _index() == cv._index()) - return (EQUAL); + if (_index() != 0 && _index() == cv._index()) return (EQUAL); // Special treatment for vertical segments: a vertical segment is larger // than any other non-vertical segment. - if (is_vertical()) - { - if (cv.is_vertical()) - return (EQUAL); - + if (is_vertical()) { + if (cv.is_vertical()) return (EQUAL); return (LARGER); } - else if (cv.is_vertical()) - { - return (SMALLER); - } + else if (cv.is_vertical()) return (SMALLER); // Compare the slopes: -A1/B1 and -A2/B2. We actually negate the slopes // and swap the result. @@ -1563,12 +1302,11 @@ protected: * Compare a circular arcs (this) and a line segment (cv) to the right of * their intersection point. */ - Comparison_result _circ_line_compare_to_right (const Self& cv, - const Point_2& p) const + Comparison_result _circ_line_compare_to_right(const Self& cv, + const Point_2& p) const { // A vertical segment lies above any other circle to the right of p: - if (cv.is_vertical()) - return (SMALLER); + if (cv.is_vertical()) return (SMALLER); // We have to compare the slopes of the supporting circles and the // supporting line at p: @@ -1580,8 +1318,7 @@ protected: const CGAL::Sign sign_denom1 = CGAL::sign (y0() - p.y()); // Check the case of a vertical tangent. - if (sign_denom1 == ZERO) - { + if (sign_denom1 == ZERO) { // The arc lies above any line segment if it is an upper arc, or below // any segment if it is a lower arc. return (_is_upper() ? LARGER : SMALLER); @@ -1589,16 +1326,13 @@ protected: // Compare (p.x() - x0(1)) and (A(2)/B(2)*(p.y() - y0(1)). // Note that if the denominator is negative, we have to swap the result. - const bool swap_res = (sign_denom1 == NEGATIVE); - Comparison_result slope_res = CGAL::compare (p.x() - x0(), - (p.y() - y0())*cv.a()/cv.b()); - - if (slope_res != EQUAL) - { - if (swap_res) - // Swap the comparison result, if necessary: - slope_res = (slope_res == SMALLER) ? LARGER : SMALLER; + const bool swap_res = (sign_denom1 == NEGATIVE); + Comparison_result slope_res = + CGAL::compare (p.x() - x0(), (p.y() - y0())*cv.a()/cv.b()); + if (slope_res != EQUAL) { + // Swap the comparison result, if necessary: + if (swap_res) slope_res = (slope_res == SMALLER) ? LARGER : SMALLER; return (slope_res); } @@ -1608,23 +1342,18 @@ protected: return (_is_upper() ? SMALLER : LARGER); } - /*! - * Compare two circular arcs to the right of their intersection point. + /*! Compare two circular arcs to the right of their intersection point. */ - Comparison_result _circs_compare_to_right (const Self& cv, - const Point_2& p) const + Comparison_result _circs_compare_to_right(const Self& cv, + const Point_2& p) const { - if (_index() != 0 && _index() == cv._index()) - { + if (_index() != 0 && _index() == cv._index()) { // Check the case of comparing two circular arcs that originate from the // same supporting circle. Their comparison result is not EQUAL only if // one is an upper arc and the other is a lower arc. - if (_is_upper() && ! cv._is_upper()) - return (LARGER); - else if (! _is_upper() && cv._is_upper()) - return (SMALLER); - else - return (EQUAL); + if (_is_upper() && ! cv._is_upper()) return (LARGER); + else if (! _is_upper() && cv._is_upper()) return (SMALLER); + else return (EQUAL); } // We have to compare the slopes of the two supporting circles at p: @@ -1633,39 +1362,31 @@ protected: // --------------- and --------------- // y0(1) - p.y() y0(2) - p.y() // - const CGAL::Sign sign_numer1 = CGAL::sign (p.x() - x0()); - const CGAL::Sign sign_denom1 = CGAL::sign (y0() - p.y()); - const CGAL::Sign sign_numer2 = CGAL::sign (p.x() - cv.x0()); - const CGAL::Sign sign_denom2 = CGAL::sign (cv.y0() - p.y()); + const CGAL::Sign sign_numer1 = CGAL::sign(p.x() - x0()); + const CGAL::Sign sign_denom1 = CGAL::sign(y0() - p.y()); + const CGAL::Sign sign_numer2 = CGAL::sign(p.x() - cv.x0()); + const CGAL::Sign sign_denom2 = CGAL::sign(cv.y0() - p.y()); // Check the case of vertical tangents. - if (sign_denom1 == ZERO) - { - if (sign_denom2 == ZERO) - { - if (_is_upper()) - { - if (cv._is_upper()) - { + if (sign_denom1 == ZERO) { + if (sign_denom2 == ZERO) { + if (_is_upper()) { + if (cv._is_upper()) { // The two circles have a vertical tangent: // The one with a larger radius is above the other. return (CGAL::compare (sqr_r(), cv.sqr_r())); } - else - { + else { // The other curve is directed downwards: return (LARGER); } } - else - { - if (cv._is_upper()) - { + else { + if (cv._is_upper()) { // The other curve is directed upwards: return (SMALLER); } - else - { + else { // The two circles have a vertical tangent: // The one with a smaller radius is above the other. return (CGAL::compare (cv.sqr_r(), sqr_r())); @@ -1676,28 +1397,21 @@ protected: // The other arc does not have a vertical tangent. return (_is_upper() ? LARGER : SMALLER); } - else if (sign_denom2 == ZERO) - { + else if (sign_denom2 == ZERO) { return (cv._is_upper() ? SMALLER : LARGER); } // Try to act according to the slope signs. - CGAL::Sign sign_slope1; - CGAL::Sign sign_slope2; + CGAL::Sign sign_slope1; + CGAL::Sign sign_slope2; - if (sign_numer1 == sign_denom1) - sign_slope1 = POSITIVE; - else if (sign_numer1 == ZERO) - sign_slope1 = ZERO; - else - sign_slope1 = NEGATIVE; + if (sign_numer1 == sign_denom1) sign_slope1 = POSITIVE; + else if (sign_numer1 == ZERO) sign_slope1 = ZERO; + else sign_slope1 = NEGATIVE; - if (sign_numer2 == sign_denom2) - sign_slope2 = POSITIVE; - else if (sign_numer2 == ZERO) - sign_slope2 = ZERO; - else - sign_slope2 = NEGATIVE; + if (sign_numer2 == sign_denom2) sign_slope2 = POSITIVE; + else if (sign_numer2 == ZERO) sign_slope2 = ZERO; + else sign_slope2 = NEGATIVE; if ((sign_slope1 == POSITIVE && sign_slope2 != POSITIVE) || (sign_slope1 == ZERO && sign_slope2 == NEGATIVE)) @@ -1718,46 +1432,38 @@ protected: else { // Actually compare the slopes. - const bool swap_res = (sign_denom1 != sign_denom2); + const bool swap_res = (sign_denom1 != sign_denom2); const CoordNT A = (cv.y0() - y0())*p.x() + (y0()*cv.x0() - cv.y0()*x0()); const CoordNT B = (cv.x0() - x0())*p.y(); slope_res = CGAL::compare (A, B); - if (slope_res != EQUAL && swap_res) - { + if (slope_res != EQUAL && swap_res) { // Swap the comparison result, if necessary: slope_res = (slope_res == SMALLER) ? LARGER : SMALLER; } } // In case the two circles have different tangent slopes at p: - if (slope_res != EQUAL) - return (slope_res); + if (slope_res != EQUAL) return (slope_res); // In this case we have a tangency point at p. - if (_is_upper()) - { - if (cv._is_upper()) - { + if (_is_upper()) { + if (cv._is_upper()) { // The circle with a larger radius is above the other. - return (CGAL::compare (sqr_r(), cv.sqr_r())); + return (CGAL::compare(sqr_r(), cv.sqr_r())); } - else - { + else { // The other curve is above our curve: return (SMALLER); } } - else - { - if (cv._is_upper()) - { + else { + if (cv._is_upper()) { // Out curve is above the other curve: return (LARGER); } - else - { + else { // The circle with a smaller radius is above the other. return (CGAL::compare (cv.sqr_r(), sqr_r())); } @@ -1771,23 +1477,18 @@ protected: /*! * Compare two line segments to the left of their intersection point. */ - Comparison_result _lines_compare_to_left (const Self& cv, - const Point_2& ) const + Comparison_result _lines_compare_to_left(const Self& cv, + const Point_2& ) const { - if (_index() != 0 && _index() == cv._index()) - return (EQUAL); + if (_index() != 0 && _index() == cv._index()) return (EQUAL); // Special treatment for vertical segments: a vertical segment is smaller // than any other non-vertical segment. - if (is_vertical()) - { - if (cv.is_vertical()) - return (EQUAL); - + if (is_vertical()) { + if (cv.is_vertical()) return (EQUAL); return (SMALLER); } - else if (cv.is_vertical()) - { + else if (cv.is_vertical()) { return (LARGER); } @@ -1796,16 +1497,14 @@ protected: return (CGAL::compare (a()/b(), cv.a()/cv.b())); } - /*! - * Compare a circular arcs (this) and a line segment (cv) to the left of + /*! Compare a circular arcs (this) and a line segment (cv) to the left of * their intersection point. */ - Comparison_result _circ_line_compare_to_left (const Self& cv, - const Point_2& p) const + Comparison_result _circ_line_compare_to_left(const Self& cv, + const Point_2& p) const { // A vertical segment lies below any other circle to the left of p: - if (cv.is_vertical()) - return (LARGER); + if (cv.is_vertical()) return (LARGER); // We have to compare the slopes of the supporting circles and the // supporting line at p, and return the swapped result: @@ -1817,8 +1516,7 @@ protected: const CGAL::Sign sign_denom1 = CGAL::sign (y0() - p.y()); // Check the case of a vertical tangent. - if (sign_denom1 == ZERO) - { + if (sign_denom1 == ZERO) { // The arc lies above any line segment if it is an upper arc, or below // any segment if it is a lower arc. return (_is_upper() ? LARGER : SMALLER); @@ -1826,12 +1524,11 @@ protected: // Compare (p.x() - x0(1)) and (A(2)/B(2)*(p.y() - y0(1)). // Note that if the denominator is negative, we have to swap the result. - const bool swap_res = (sign_denom1 == NEGATIVE); - Comparison_result slope_res = CGAL::compare (p.x() - x0(), - (p.y() - y0())*cv.a()/cv.b()); + const bool swap_res = (sign_denom1 == NEGATIVE); + Comparison_result slope_res = + CGAL::compare(p.x() - x0(), (p.y() - y0()) * cv.a() / cv.b()); - if (slope_res != EQUAL) - { + if (slope_res != EQUAL) { if (swap_res) // Swap the comparison result, if necessary: slope_res = (slope_res == SMALLER) ? LARGER : SMALLER; @@ -1849,20 +1546,16 @@ protected: /*! * Compare the two arcs to the left of their intersection point. */ - Comparison_result _circs_compare_to_left (const Self& cv, - const Point_2& p) const + Comparison_result _circs_compare_to_left(const Self& cv, + const Point_2& p) const { - if (_index() != 0 && _index() == cv._index()) - { + if (_index() != 0 && _index() == cv._index()) { // Check the case of comparing two circular arcs that originate from the // same supporting circle. Their comparison result is not EQUAL only if // one is an upper arc and the other is a lower arc. - if (_is_upper() && ! cv._is_upper()) - return (LARGER); - else if (! _is_upper() && cv._is_upper()) - return (SMALLER); - else - return (EQUAL); + if (_is_upper() && ! cv._is_upper()) return (LARGER); + else if (! _is_upper() && cv._is_upper()) return (SMALLER); + else return (EQUAL); } // We have to compare the slopes of the two supporting circles at p: @@ -1872,39 +1565,31 @@ protected: // y0(1) - p.y() y0(2) - p.y() // // Eventually, we should take the opposite result. - const CGAL::Sign sign_numer1 = CGAL::sign (p.x() - x0()); - const CGAL::Sign sign_denom1 = CGAL::sign (y0() - p.y()); - const CGAL::Sign sign_numer2 = CGAL::sign (p.x() - cv.x0()); - const CGAL::Sign sign_denom2 = CGAL::sign (cv.y0() - p.y()); + const CGAL::Sign sign_numer1 = CGAL::sign(p.x() - x0()); + const CGAL::Sign sign_denom1 = CGAL::sign(y0() - p.y()); + const CGAL::Sign sign_numer2 = CGAL::sign(p.x() - cv.x0()); + const CGAL::Sign sign_denom2 = CGAL::sign(cv.y0() - p.y()); // Check the case of vertical tangents. - if (sign_denom1 == ZERO) - { - if (sign_denom2 == ZERO) - { - if (_is_upper()) - { - if (cv._is_upper()) - { + if (sign_denom1 == ZERO) { + if (sign_denom2 == ZERO) { + if (_is_upper()) { + if (cv._is_upper()) { // The two circles have a vertical tangent: // The one with a larger radius is above the other. return (CGAL::compare (sqr_r(), cv.sqr_r())); } - else - { + else { // The other curve is directed downwards: return (LARGER); } } - else - { - if (cv._is_upper()) - { + else { + if (cv._is_upper()) { // The other curve is directed upwards: return (SMALLER); } - else - { + else { // The two circles have a vertical tangent: // The one with a smaller radius is above the other. return (CGAL::compare (cv.sqr_r(), sqr_r())); @@ -1915,28 +1600,21 @@ protected: // The other arc does not have a vertical tangent. return (_is_upper() ? LARGER : SMALLER); } - else if (sign_denom2 == ZERO) - { + else if (sign_denom2 == ZERO) { return (cv._is_upper() ? SMALLER : LARGER); } // Try to act according to the slope signs. - CGAL::Sign sign_slope1; - CGAL::Sign sign_slope2; + CGAL::Sign sign_slope1; + CGAL::Sign sign_slope2; - if (sign_numer1 == sign_denom1) - sign_slope1 = POSITIVE; - else if (sign_numer1 == ZERO) - sign_slope1 = ZERO; - else - sign_slope1 = NEGATIVE; + if (sign_numer1 == sign_denom1) sign_slope1 = POSITIVE; + else if (sign_numer1 == ZERO) sign_slope1 = ZERO; + else sign_slope1 = NEGATIVE; - if (sign_numer2 == sign_denom2) - sign_slope2 = POSITIVE; - else if (sign_numer2 == ZERO) - sign_slope2 = ZERO; - else - sign_slope2 = NEGATIVE; + if (sign_numer2 == sign_denom2) sign_slope2 = POSITIVE; + else if (sign_numer2 == ZERO) sign_slope2 = ZERO; + else sign_slope2 = NEGATIVE; if ((sign_slope1 == POSITIVE && sign_slope2 != POSITIVE) || (sign_slope1 == ZERO && sign_slope2 == NEGATIVE)) @@ -1954,17 +1632,15 @@ protected: // Special case were both circles have a horizontal tangent: slope_res = EQUAL; } - else - { + else { // Actually compare the slopes. - const bool swap_res = (sign_denom1 != sign_denom2); + const bool swap_res = (sign_denom1 != sign_denom2); const CoordNT A = (cv.y0() - y0())*p.x() + (y0()*cv.x0() - cv.y0()*x0()); const CoordNT B = (cv.x0() - x0())*p.y(); - slope_res = CGAL::compare (A, B); + slope_res = CGAL::compare(A, B); - if (slope_res != EQUAL && swap_res) - { + if (slope_res != EQUAL && swap_res) { // Swap the comparison result, if necessary: slope_res = (slope_res == SMALLER) ? LARGER : SMALLER; } @@ -1973,34 +1649,27 @@ protected: // In case the two circles have different tangent slopes at p, return // the opposite of the slope result (since the slope result is the // comparison result to the right of the intersection point): - if (slope_res != EQUAL) - return ((slope_res == SMALLER) ? LARGER : SMALLER); + if (slope_res != EQUAL) return ((slope_res == SMALLER) ? LARGER : SMALLER); // In this case we have a tangency point at p. - if (_is_upper()) - { - if (cv._is_upper()) - { + if (_is_upper()) { + if (cv._is_upper()) { // The circle with a larger radius is above the other. - return (CGAL::compare (sqr_r(), cv.sqr_r())); + return (CGAL::compare(sqr_r(), cv.sqr_r())); } - else - { + else { // The other curve is above our curve: return (SMALLER); } } - else - { - if (cv._is_upper()) - { + else { + if (cv._is_upper()) { // Out curve is above the other curve: return (LARGER); } - else - { + else { // The circle with a smaller radius is above the other. - return (CGAL::compare (cv.sqr_r(), sqr_r())); + return (CGAL::compare(cv.sqr_r(), sqr_r())); } } } @@ -2009,11 +1678,10 @@ protected: /// \name Auxiliary functions for computing intersections. //@{ - /*! - * Compute the intersections between two line segments. + /*! Compute the intersections between two line segments. */ - void _lines_intersect (const Self& cv, - Intersection_list& inter_list) const + void _lines_intersect(const Self& cv, + Intersection_list& inter_list) const { // The intersection of the lines: // a1*x + b1*y + c1 = 0 and a2*x + b2*y + c2 = 0 , @@ -2023,53 +1691,47 @@ protected: // ( --------------- , --------------- ) // a1*b2 - b1*a2 a1*b2 - b1*a2 // - unsigned int mult = 1; - const NT denom = a()*cv.b() - b()*cv.a(); + unsigned int mult = 1; + const NT denom = a()*cv.b() - b()*cv.a(); // Make sure the supporting lines are not parallel. - if (CGAL::sign(denom) == ZERO) - return; + if (CGAL::sign(denom) == ZERO) return; - const NT x = (b()*cv.c() - c()*cv.b()) / denom; - const NT y = (c()*cv.a() - a()*cv.c()) / denom; - Point_2 p (x, y); + const NT x = (b()*cv.c() - c()*cv.b()) / denom; + const NT y = (c()*cv.a() - a()*cv.c()) / denom; + Point_2 p (x, y); - inter_list.push_back (Intersection_point_2 (p, mult)); - return; + inter_list.push_back(Intersection_point(p, mult)); } - /*! - * Compute the intersections between the supporting circle of (*this) and + /*! Compute the intersections between the supporting circle of (*this) and * the supporting line of the segement cv. */ - void _circ_line_intersect (const Self& cv, - Intersection_list& inter_list) const + void _circ_line_intersect(const Self& cv, + Intersection_list& inter_list) const { - Point_2 p; - unsigned int mult; + Point_2 p; + unsigned int mult; // First check the special cases of vertical and horizontal lines. - if (cv.is_vertical()) - { + if (cv.is_vertical()) { // The equation of the vertical line is x = -c / a. // The y-coordinates of the intersection points are: // y = y0 +/- sqrt(r^2 - (x - x0)^2) // - const NT vx = -cv.c() / cv.a(); - const NT vdisc = sqr_r() - CGAL::square (vx - x0()); + const NT vx = -cv.c() / cv.a(); + const NT vdisc = sqr_r() - CGAL::square (vx - x0()); CGAL::Sign sign_vdisc = CGAL::sign (vdisc); - if (sign_vdisc == NEGATIVE) - { + if (sign_vdisc == NEGATIVE) { // The circle and the vertical line do not intersect. return; } - else if (sign_vdisc == ZERO) - { + else if (sign_vdisc == ZERO) { // A single tangency point, given by: mult = 2; p = Point_2 (vx, y0()); - inter_list.push_back (Intersection_point_2 (p, mult)); + inter_list.push_back(Intersection_point(p, mult)); return; } @@ -2077,37 +1739,30 @@ protected: // Compute the two intersection points: mult = 1; - p = Point_2 (CoordNT (vx), - CoordNT (y0(), NT(-1), vdisc)); - inter_list.push_back (Intersection_point_2 (p, mult)); + p = Point_2(CoordNT (vx), CoordNT (y0(), NT(-1), vdisc)); + inter_list.push_back (Intersection_point(p, mult)); - p = Point_2 (CoordNT (vx), - CoordNT (y0(), NT(1), vdisc)); - inter_list.push_back (Intersection_point_2 (p, mult)); + p = Point_2(CoordNT (vx), CoordNT (y0(), NT(1), vdisc)); + inter_list.push_back(Intersection_point(p, mult)); return; } - else if (CGAL::sign (cv.a()) == ZERO) - { + else if (CGAL::sign (cv.a()) == ZERO) { // The equation of the horizontal line is y = -c / b. // The y-coordinates of the intersection points are: // x = x0 +/- sqrt(r^2 - (y - y0)^2) // - const NT hy = -cv.c() / cv.b(); - const NT hdisc = sqr_r() - CGAL::square (hy - y0()); + const NT hy = -cv.c() / cv.b(); + const NT hdisc = sqr_r() - CGAL::square (hy - y0()); CGAL::Sign sign_hdisc = CGAL::sign (hdisc); - if (sign_hdisc == NEGATIVE) - { - // The circle and the vertical line do not intersect. - return; - } - else if (sign_hdisc == ZERO) - { + // The circle and the vertical line do not intersect. + if (sign_hdisc == NEGATIVE) return; + else if (sign_hdisc == ZERO) { // A single tangency point, given by: mult = 2; - p = Point_2 (x0(), hy); - inter_list.push_back (Intersection_point_2 (p, mult)); + p = Point_2(x0(), hy); + inter_list.push_back(Intersection_point (p, mult)); return; } @@ -2115,287 +1770,246 @@ protected: // Compute the two intersection points: mult = 1; - p = Point_2 (CoordNT (x0(), NT(-1), hdisc), - CoordNT (hy)); - inter_list.push_back (Intersection_point_2 (p, mult)); + p = Point_2(CoordNT(x0(), NT(-1), hdisc), CoordNT (hy)); + inter_list.push_back(Intersection_point (p, mult)); - p = Point_2 (CoordNT (x0(), NT(1), hdisc), - CoordNT (hy)); - inter_list.push_back (Intersection_point_2 (p, mult)); + p = Point_2(CoordNT(x0(), NT(1), hdisc), CoordNT(hy)); + inter_list.push_back(Intersection_point (p, mult)); return; } // Compute the squared distance between the line and the circle center, // inducing the discriminant of the quadratic equations we have to solve. - const NT line_factor = CGAL::square(cv.a()) + CGAL::square(cv.b()); - const NT disc = line_factor*sqr_r() - - CGAL::square(cv.a()*x0() + cv.b()*y0() + cv.c()); + const NT line_factor = CGAL::square(cv.a()) + CGAL::square(cv.b()); + const NT disc = + line_factor*sqr_r() - CGAL::square(cv.a()*x0() + cv.b()*y0() + cv.c()); CGAL::Sign sign_disc = CGAL::sign (disc); - if (sign_disc == NEGATIVE) - { - // The circle and the line do not intersect: - return; - } + // The circle and the line do not intersect: + if (sign_disc == NEGATIVE) return; // Compare the square-free part of the solution: - const NT aux = cv.b()*x0() - cv.a()*y0(); - const NT x_base = (aux*cv.b() - cv.a()*cv.c()) / line_factor; - const NT y_base = (-aux*cv.a() - cv.b()*cv.c()) / line_factor; + const NT aux = cv.b()*x0() - cv.a()*y0(); + const NT x_base = (aux*cv.b() - cv.a()*cv.c()) / line_factor; + const NT y_base = (-aux*cv.a() - cv.b()*cv.c()) / line_factor; - if (sign_disc == ZERO) - { + if (sign_disc == ZERO) { // A single tangency point, given by: mult = 2; - p = Point_2 (x_base, y_base); - inter_list.push_back (Intersection_point_2 (p, mult)); + p = Point_2(x_base, y_base); + inter_list.push_back(Intersection_point(p, mult)); return; } // We have two intersection points, whose coordinates are one-root numbers. - bool minus_root_first = (CGAL::sign(cv.b()) == POSITIVE); - const NT x_root_coeff = cv.b() / line_factor; - const NT y_root_coeff = cv.a() / line_factor; + bool minus_root_first = (CGAL::sign(cv.b()) == POSITIVE); + const NT x_root_coeff = cv.b() / line_factor; + const NT y_root_coeff = cv.a() / line_factor; mult = 1; - if (minus_root_first) - { - p = Point_2 (CoordNT (x_base, -x_root_coeff, disc), - CoordNT (y_base, y_root_coeff, disc)); - inter_list.push_back (Intersection_point_2 (p, mult)); + if (minus_root_first) { + p = Point_2(CoordNT(x_base, -x_root_coeff, disc), + CoordNT(y_base, y_root_coeff, disc)); + inter_list.push_back(Intersection_point (p, mult)); - p = Point_2 (CoordNT (x_base, x_root_coeff, disc), - CoordNT (y_base, -y_root_coeff, disc)); - inter_list.push_back (Intersection_point_2 (p, mult)); + p = Point_2(CoordNT(x_base, x_root_coeff, disc), + CoordNT(y_base, -y_root_coeff, disc)); + inter_list.push_back(Intersection_point(p, mult)); } - else - { - p = Point_2 (CoordNT (x_base, x_root_coeff, disc), - CoordNT (y_base, -y_root_coeff, disc)); - inter_list.push_back (Intersection_point_2 (p, mult)); + else { + p = Point_2(CoordNT(x_base, x_root_coeff, disc), + CoordNT(y_base, -y_root_coeff, disc)); + inter_list.push_back(Intersection_point(p, mult)); - p = Point_2 (CoordNT (x_base, -x_root_coeff, disc), - CoordNT (y_base, y_root_coeff, disc)); - inter_list.push_back (Intersection_point_2 (p, mult)); + p = Point_2(CoordNT(x_base, -x_root_coeff, disc), + CoordNT(y_base, y_root_coeff, disc)); + inter_list.push_back(Intersection_point(p, mult)); } - - return; } - /*! - * Compute the intersections between two circles. + /*! Compute the intersections between two circles. */ - void _circs_intersect (const Self& cv, - Intersection_list& inter_list) const + void _circs_intersect(const Self& cv, Intersection_list& inter_list) const { - Point_2 p; - unsigned int mult; + Point_2 p; + unsigned int mult; // Compute the squared distance between the circle centers, inducing the // discriminant of the quadratic equations we have to solve. - const NT diff_x = cv.x0() - x0(); - const NT diff_y = cv.y0() - y0(); - const NT sqr_dist = CGAL::square(diff_x) + CGAL::square(diff_y); - const NT diff_sqr_rad = sqr_r() - cv.sqr_r(); - const NT disc = 2*sqr_dist*(sqr_r() + cv.sqr_r()) - - (CGAL::square(diff_sqr_rad) + CGAL::square(sqr_dist)); + const NT diff_x = cv.x0() - x0(); + const NT diff_y = cv.y0() - y0(); + const NT sqr_dist = CGAL::square(diff_x) + CGAL::square(diff_y); + const NT diff_sqr_rad = sqr_r() - cv.sqr_r(); + const NT disc = 2 * sqr_dist * (sqr_r() + cv.sqr_r()) - + (CGAL::square(diff_sqr_rad) + CGAL::square(sqr_dist)); CGAL::Sign sign_disc = CGAL::sign (disc); - if (sign_disc == NEGATIVE) - { - // The two circles do not intersect. - return; - } + // The two circles do not intersect. + if (sign_disc == NEGATIVE) return; // Compare the square-free part of the solution: - const NT x_base = ((x0() + cv.x0()) + diff_x*diff_sqr_rad/sqr_dist) / 2; - const NT y_base = ((y0() + cv.y0()) + diff_y*diff_sqr_rad/sqr_dist) / 2; + const NT x_base = ((x0() + cv.x0()) + diff_x * diff_sqr_rad / sqr_dist) / 2; + const NT y_base = ((y0() + cv.y0()) + diff_y * diff_sqr_rad / sqr_dist) / 2; - if (sign_disc == ZERO) - { + if (sign_disc == ZERO) { // A single tangency point, given by: mult = 2; - p = Point_2 (x_base, y_base); - inter_list.push_back (Intersection_point_2 (p, mult)); - + p = Point_2(x_base, y_base); + inter_list.push_back(Intersection_point(p, mult)); return; } // We have two intersection points, whose coordinates are one-root numbers. CGAL::Sign sign_diff_y = CGAL::sign (diff_y); - bool minus_root_first; + bool minus_root_first; if (sign_diff_y == ZERO) minus_root_first = (CGAL::sign (diff_x) == NEGATIVE); else minus_root_first = (sign_diff_y == POSITIVE); - const NT x_root_coeff = diff_y / (2 * sqr_dist); - const NT y_root_coeff = diff_x / (2 * sqr_dist); + const NT x_root_coeff = diff_y / (2 * sqr_dist); + const NT y_root_coeff = diff_x / (2 * sqr_dist); mult = 1; - if (minus_root_first) - { - p = Point_2 (CoordNT (x_base, -x_root_coeff, disc), - CoordNT (y_base, y_root_coeff, disc)); - inter_list.push_back (Intersection_point_2 (p, mult)); + if (minus_root_first) { + p = Point_2(CoordNT(x_base, -x_root_coeff, disc), + CoordNT(y_base, y_root_coeff, disc)); + inter_list.push_back(Intersection_point (p, mult)); - p = Point_2 (CoordNT (x_base, x_root_coeff, disc), - CoordNT (y_base, -y_root_coeff, disc)); - inter_list.push_back (Intersection_point_2 (p, mult)); + p = Point_2(CoordNT(x_base, x_root_coeff, disc), + CoordNT(y_base, -y_root_coeff, disc)); + inter_list.push_back(Intersection_point (p, mult)); } - else - { - p = Point_2 (CoordNT (x_base, x_root_coeff, disc), - CoordNT (y_base, -y_root_coeff, disc)); - inter_list.push_back (Intersection_point_2 (p, mult)); + else { + p = Point_2(CoordNT(x_base, x_root_coeff, disc), + CoordNT(y_base, -y_root_coeff, disc)); + inter_list.push_back(Intersection_point (p, mult)); - p = Point_2 (CoordNT (x_base, -x_root_coeff, disc), - CoordNT (y_base, y_root_coeff, disc)); - inter_list.push_back (Intersection_point_2 (p, mult)); + p = Point_2(CoordNT(x_base, -x_root_coeff, disc), + CoordNT(y_base, y_root_coeff, disc)); + inter_list.push_back(Intersection_point(p, mult)); } - - return; } - /*! - * Check if the given point lies on the arc. + /*! Check if the given point lies on the arc. * \pre p lies on the supporting curve. */ - bool _is_between_endpoints (const Point_2& p) const + bool _is_between_endpoints(const Point_2& p) const { - if (is_linear()) - { - if (is_vertical()) - { + if (is_linear()) { + if (is_vertical()) { // Check if the point is in the y-range of the arc. // Note that left() is the lower endpoint and right() is the upper // endpoint of the segment in this case. - Comparison_result res = CGAL::compare (p.y(), left().y()); + Comparison_result res = CGAL::compare(p.y(), left().y()); - if (res == SMALLER) - return (false); - else if (res == EQUAL) - return (true); + if (res == SMALLER) return false; + else if (res == EQUAL) return true; - return (CGAL::compare (p.y(), right().y()) != LARGER); + return (CGAL::compare(p.y(), right().y()) != LARGER); } // For non-vertical segments, it is sufficient to check if the point // is in the x-range of the arc. - return (this->is_in_x_range (p)); + return (this->is_in_x_range(p)); } // The supporting curve is a circle: // Check whether p lies on the upper or on the lower part of the circle. - Comparison_result c_res = CGAL::compare (p.y(), y0()); + Comparison_result c_res = CGAL::compare(p.y(), y0()); - if ((_is_upper() && c_res == SMALLER) || - (! _is_upper() && c_res == LARGER)) + if ((_is_upper() && c_res == SMALLER) || (! _is_upper() && c_res == LARGER)) { // The point lies on the other half of the circle: - return (false); + return false; } // Check if the point is in the x-range of the arc. - return (this->is_in_x_range (p)); + return (this->is_in_x_range(p)); } - /*! - * Check if the given point lies in the interior of the arc. + /*! Check whether the given point lies in the interior of the arc. * \pre p lies on the supporting curve. */ - bool _is_strictly_between_endpoints (const Point_2& p) const + bool _is_strictly_between_endpoints(const Point_2& p) const { - if (p.equals (_source) || p.equals (_target)) - return (false); - - return (_is_between_endpoints (p)); + if (p.equals (m_source) || p.equals (m_target)) return false; + return (_is_between_endpoints(p)); } - /*! - * Compute the overlap with a given arc having the same supporting curve. + /*! Compute the overlap with a given arc having the same supporting curve. * \param cv The given arc. * \param overlap Output: The overlapping arc (if any). * \return Whether we found an overlap. */ - bool _compute_overlap (const Self& cv, Self& overlap) const + bool _compute_overlap(const Self& cv, Self& overlap) const { // Check if the two arcs are identical. - if (is_linear()) - { + if (is_linear()) { // In case of line segments we can swap the source and target: - if (((_source.equals (cv._source) && _target.equals (cv._target)) || - (_source.equals (cv._target) && _target.equals (cv._source)))) + if (((m_source.equals(cv.m_source) && m_target.equals(cv.m_target)) || + (m_source.equals(cv.m_target) && m_target.equals(cv.m_source)))) { overlap = cv; - return (true); + return true; } } - else - { + else { if ((orientation() == cv.orientation() && - _source.equals (cv._source) && _target.equals (cv._target)) || + m_source.equals(cv.m_source) && m_target.equals(cv.m_target)) || (orientation() != cv.orientation() && - _source.equals (cv._target) && _target.equals (cv._source))) + m_source.equals(cv.m_target) && m_target.equals(cv.m_source))) { overlap = cv; - return (true); + return true; } } // Check for other overlaps: - if (_is_strictly_between_endpoints (cv.left())) - { - if (_is_strictly_between_endpoints (cv.right())) - { + if (_is_strictly_between_endpoints(cv.left())) { + if (_is_strictly_between_endpoints(cv.right())) { // Case 1 - *this: +-----------> // cv: +=====> overlap = cv; - return (true); + return true; } - else - { + else { // Case 2 - *this: +-----------> // cv: +=====> overlap = *this; - if (overlap.is_directed_right()) - overlap._source = cv.left(); - else - overlap._target = cv.left(); + if (overlap.is_directed_right()) overlap.m_source = cv.left(); + else overlap.m_target = cv.left(); - return (true); + return true; } } - else if (_is_strictly_between_endpoints (cv.right())) - { + else if (_is_strictly_between_endpoints(cv.right())) { // Case 3 - *this: +-----------> // cv: +=====> overlap = *this; - if (overlap.is_directed_right()) - overlap._target = cv.right(); - else - overlap._source = cv.right(); + if (overlap.is_directed_right()) overlap.m_target = cv.right(); + else overlap.m_source = cv.right(); - return (true); + return true; } - else if (cv._is_between_endpoints (_source) && - cv._is_between_endpoints (_target) && - (cv._is_strictly_between_endpoints (_source) || - cv._is_strictly_between_endpoints (_target))) + else if (cv._is_between_endpoints(m_source) && + cv._is_between_endpoints(m_target) && + (cv._is_strictly_between_endpoints(m_source) || + cv._is_strictly_between_endpoints(m_target))) { // Case 4 - *this: +-----------> // cv: +================> overlap = *this; - return (true); + return true; } // If we reached here, there are no overlaps: - return (false); + return false; } public: @@ -2407,61 +2021,49 @@ protected: const double x_right = CGAL::to_double(this->target().x()); const double y_right = CGAL::to_double(this->target().y()); - if(this->is_linear()) - { - *oi = std::make_pair(x_left, y_left); - ++oi; - - *oi = std::make_pair(x_right, y_right); - ++oi; + if (this->is_linear()) { + *oi++ = std::make_pair(x_left, y_left); + *oi++ = std::make_pair(x_right, y_right); return; } // Otherwise, sample (n - 1) equally-spaced points in between. - const double app_xcenter = CGAL::to_double (this->_first); - const double app_ycenter = CGAL::to_double (this->_second); - const double app_sqr_rad = CGAL::to_double (this->_third); + const double app_xcenter = CGAL::to_double(this->m_first); + const double app_ycenter = CGAL::to_double(this->m_second); + const double app_sqr_rad = CGAL::to_double(this->m_third); - const double x_jump = (x_right - x_left) / n; - double x, y; - double disc; - unsigned int i; + const double x_jump = (x_right - x_left) / n; + double x, y; + double disc; + unsigned int i; const bool is_up = this->_is_upper(); - *oi = std::make_pair (x_left, y_left); // The left point. - ++oi; - for (i = 1; i < n; i++) - { + *oi++ = std::make_pair (x_left, y_left); // The left point. + for (i = 1; i < n; ++i) { x = x_left + x_jump*i; disc = app_sqr_rad - CGAL::square(x - app_xcenter); if (disc < 0) disc = 0; - if(is_up) - y = app_ycenter + std::sqrt(disc); - else - y = app_ycenter - std::sqrt(disc); + if(is_up) y = app_ycenter + std::sqrt(disc); + else y = app_ycenter - std::sqrt(disc); - *oi = std::make_pair(x, y); - ++oi; + *oi++ = std::make_pair(x, y); } - *oi = std::make_pair(x_right, y_right); // The right point. - ++oi; + *oi++ = std::make_pair(x_right, y_right); // The right point. } - /*! - * Trim the arc given its new endpoints. + /*! Trim the arc given its new endpoints. * \param ps The new source point. * \param pt The new target point. * \return The new trimmed arc. * \pre Both ps and pt lies on the arc and must conform with the current * direction of the arc. */ - Self trim (const Point_2& ps, - const Point_2& pt) const + Self trim(const Point_2& ps, const Point_2& pt) const { - Self arc = *this; + Self arc = *this; - arc._source = ps; - arc._target = pt; + arc.m_source = ps; + arc.m_target = pt; return arc; } @@ -2469,13 +2071,12 @@ protected: //@} }; -/*! - * Exporter for circular arcs (or line segments). +/*! Exporter for circular arcs (or line segments). */ template std::ostream& -operator<< (std::ostream& os, - const _X_monotone_circle_segment_2 & arc) +operator<<(std::ostream& os, + const _X_monotone_circle_segment_2 & arc) { if (! arc.is_linear()) os << "(" << arc.supporting_circle() << ") "; diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_geometry_traits/Conic_x_monotone_arc_2.h b/Arrangement_on_surface_2/include/CGAL/Arr_geometry_traits/Conic_x_monotone_arc_2.h index 6fc3ecce08c..b6587f4e1ab 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_geometry_traits/Conic_x_monotone_arc_2.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_geometry_traits/Conic_x_monotone_arc_2.h @@ -7,34 +7,32 @@ // $Id$ // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial // -// -// Author(s) : Ron Wein +// Author(s): Ron Wein #ifndef CGAL_CONIC_X_MONOTONE_ARC_2_H #define CGAL_CONIC_X_MONOTONE_ARC_2_H #include - /*! \file * Header file for the _Conic_x_monotone_arc_2 class. */ -#include - #include #include +#include + +#include + namespace CGAL { -/*! - * Representation of an x-monotone conic arc. +/*! Representation of an x-monotone conic arc. * The class is templated by a representation of a general bounded conic arc. */ -template -class _Conic_x_monotone_arc_2 : private Conic_arc_ -{ +template +class _Conic_x_monotone_arc_2 : private Conic_arc_ { public: typedef Conic_arc_ Conic_arc_2; @@ -49,8 +47,8 @@ public: // Type definition for the intersection points mapping. typedef typename Conic_point_2::Conic_id Conic_id; typedef std::pair Conic_pair; - typedef std::pair Intersection_point_2; - typedef std::list Intersection_list; + typedef std::pair Intersection_point; + typedef std::list Intersection_list; using Conic_arc_2::_sign_of_extra_data; using Conic_arc_2::_is_between_endpoints; @@ -59,13 +57,12 @@ public: /*! * \struct Less functor for Conic_pair. */ - struct Less_conic_pair - { - bool operator() (const Conic_pair& cp1, const Conic_pair& cp2) const + struct Less_conic_pair { + bool operator()(const Conic_pair& cp1, const Conic_pair& cp2) const { // Compare the pairs of IDs lexicographically. - return (cp1.first < cp2.first || - (cp1.first == cp2.first && cp1.second < cp2.second)); + return ((cp1.first < cp2.first) || + ((cp1.first == cp2.first) && (cp1.second < cp2.second))); } }; @@ -85,8 +82,7 @@ protected: // Bit masks for the _info field (the two least significant bits are already // used by the base class). - enum - { + enum { IS_VERTICAL_SEGMENT = 4, IS_DIRECTED_RIGHT = 8, DEGREE_1 = 16, @@ -99,14 +95,14 @@ protected: IS_SPECIAL_SEGMENT = 512 }; - Algebraic alg_r; // The coefficients of the supporting conic curve: - Algebraic alg_s; // - Algebraic alg_t; // r*x^2 + s*y^2 + t*xy + u*x + v*y +w = 0 , - Algebraic alg_u; // - Algebraic alg_v; // converted to algebraic numbers. - Algebraic alg_w; // + Algebraic alg_r; // The coefficients of the supporting conic curve: + Algebraic alg_s; // + Algebraic alg_t; // r*x^2 + s*y^2 + t*xy + u*x + v*y +w = 0 , + Algebraic alg_u; // + Algebraic alg_v; // converted to algebraic numbers. + Algebraic alg_w; // - Conic_id _id; // The ID number of the supporting conic curve. + Conic_id _id; // The ID number of the supporting conic curve. public: @@ -117,68 +113,62 @@ public: * Default constructor. */ _Conic_x_monotone_arc_2 () : - Base (), - _id () + Base(), + _id() {} /*! * Copy constructor. * \param arc The copied arc. */ - _Conic_x_monotone_arc_2 (const Self& arc) : - Base (arc), - alg_r (arc.alg_r), - alg_s (arc.alg_s), - alg_t (arc.alg_t), - alg_u (arc.alg_u), - alg_v (arc.alg_v), - alg_w (arc.alg_w), - _id (arc._id) + _Conic_x_monotone_arc_2(const Self& arc) : + Base(arc), + alg_r(arc.alg_r), + alg_s(arc.alg_s), + alg_t(arc.alg_t), + alg_u(arc.alg_u), + alg_v(arc.alg_v), + alg_w(arc.alg_w), + _id(arc._id) {} - /*! - * Construct an x-monotone arc from a conic arc. + /*! Construct an x-monotone arc from a conic arc. * \param arc The given (base) arc. * \pre The given arc is x-monotone. */ - _Conic_x_monotone_arc_2 (const Base& arc) : - Base (arc), - _id () + _Conic_x_monotone_arc_2(const Base& arc) : + Base(arc), + _id() { - CGAL_precondition (arc.is_valid() && arc.is_x_monotone()); - + CGAL_precondition(arc.is_valid() && arc.is_x_monotone()); _set (); } - /*! - * Construct an x-monotone arc from a conic arc. + /*! Construct an x-monotone arc from a conic arc. * \param arc The given (base) arc. * \param id The ID of the base arc. */ - _Conic_x_monotone_arc_2 (const Base& arc, - const Conic_id& id) : - Base (arc), - _id (id) + _Conic_x_monotone_arc_2(const Base& arc, const Conic_id& id) : + Base(arc), + _id(id) { - CGAL_precondition (arc.is_valid() && id.is_valid()); - + CGAL_precondition(arc.is_valid() && id.is_valid()); _set (); } - /*! - * Construct an x-monotone sub-arc from a conic arc. + /*! Construct an x-monotone sub-arc from a conic arc. * \param arc The given (base) arc. * \param source The source point. * \param target The target point. * \param id The ID of the base arc. */ - _Conic_x_monotone_arc_2 (const Base& arc, - const Point_2& source, const Point_2& target, - const Conic_id& id) : - Base (arc), - _id (id) + _Conic_x_monotone_arc_2(const Base& arc, + const Point_2& source, const Point_2& target, + const Conic_id& id) : + Base(arc), + _id(id) { - CGAL_precondition (arc.is_valid() && id.is_valid()); + CGAL_precondition(arc.is_valid() && id.is_valid()); // Set the two endpoints. this->_source = source; @@ -193,7 +183,7 @@ public: * \param source The source point. * \param target The target point. */ - _Conic_x_monotone_arc_2 (const Point_2& source, const Point_2& target) : + _Conic_x_monotone_arc_2(const Point_2& source, const Point_2& target) : Base() { // Set the basic properties and clear the _info bits. @@ -204,22 +194,21 @@ public: // Check if the arc is directed right (the target is lexicographically // greater than the source point), or to the left. - Alg_kernel ker; - Comparison_result dir_res = ker.compare_xy_2_object() (this->_source, - this->_target); + Alg_kernel ker; + Comparison_result dir_res = + ker.compare_xy_2_object()(this->_source, this->_target); CGAL_precondition (dir_res != EQUAL); - if (dir_res == EQUAL) - // Invalid arc: - return; + // Invalid arc: + if (dir_res == EQUAL) return; this->_info = (Conic_arc_2::IS_VALID | DEGREE_1); if (dir_res == SMALLER) this->_info = (this->_info | IS_DIRECTED_RIGHT); // Compose the equation of the underlying line. - const Algebraic x1 = source.x(), y1 = source.y(); - const Algebraic x2 = target.x(), y2 = target.y(); + const Algebraic x1 = source.x(), y1 = source.y(); + const Algebraic x2 = target.x(), y2 = target.y(); // The supporting line is A*x + B*y + C = 0, where: // @@ -249,18 +238,18 @@ public: * \param source The source point. * \param target The target point. */ - _Conic_x_monotone_arc_2 (const Algebraic& a, - const Algebraic& b, - const Algebraic& c, - const Point_2& source, const Point_2& target) : + _Conic_x_monotone_arc_2(const Algebraic& a, + const Algebraic& b, + const Algebraic& c, + const Point_2& source, const Point_2& target) : Base() { // Make sure the two endpoints lie on the supporting line. - CGAL_precondition (CGAL::sign (a * source.x() + - b * source.y() + c) == CGAL::ZERO); + CGAL_precondition(CGAL::sign(a * source.x() + + b * source.y() + c) == CGAL::ZERO); - CGAL_precondition (CGAL::sign (a * target.x() + - b * target.y() + c) == CGAL::ZERO); + CGAL_precondition(CGAL::sign(a * target.x() + + b * target.y() + c) == CGAL::ZERO); // Set the basic properties and clear the _info bits. this->_source = source; @@ -270,23 +259,20 @@ public: // Check if the arc is directed right (the target is lexicographically // greater than the source point), or to the left. - Alg_kernel ker; - Comparison_result res = ker.compare_x_2_object() (this->_source, - this->_target); + Alg_kernel ker; + Comparison_result res = + ker.compare_x_2_object()(this->_source, this->_target); this->_info = (Conic_arc_2::IS_VALID | DEGREE_1); - if (res == EQUAL) - { + if (res == EQUAL) { // Mark that the segment is vertical. this->_info = (this->_info | IS_VERTICAL_SEGMENT); // Compare the endpoints lexicographically. - res = ker.compare_y_2_object() (this->_source, - this->_target); + res = ker.compare_y_2_object()(this->_source, this->_target); CGAL_precondition (res != EQUAL); - if (res == EQUAL) - { + if (res == EQUAL) { // Invalid arc: this->_info = 0; return; @@ -313,12 +299,11 @@ public: * Assignment operator. * \param arc The copied arc. */ - const Self& operator= (const Self& arc) + const Self& operator=(const Self& arc) { CGAL_precondition (arc.is_valid()); - if (this == &arc) - return (*this); + if (this == &arc) return (*this); // Copy the base arc. Base::operator= (arc); @@ -343,49 +328,35 @@ public: /*! * Get the coefficients of the underlying conic. */ - const Integer& r () const {return (this->_r);} - const Integer& s () const {return (this->_s);} - const Integer& t () const {return (this->_t);} - const Integer& u () const {return (this->_u);} - const Integer& v () const {return (this->_v);} - const Integer& w () const {return (this->_w);} + const Integer& r() const { return (this->_r); } + const Integer& s() const { return (this->_s); } + const Integer& t() const { return (this->_t); } + const Integer& u() const { return (this->_u); } + const Integer& v() const { return (this->_v); } + const Integer& w() const { return (this->_w); } /*! * Get the arc's source. * \return The source point. */ - const Conic_point_2& source () const - { - return (this->_source); - } + const Conic_point_2& source() const { return (this->_source); } - /*! - * Get the arc's target. + /*! Get the arc's target. * \return The target point. */ - const Conic_point_2& target () const - { - return (this->_target); - } + const Conic_point_2& target() const { return (this->_target); } - /*! - * Get the orientation of the arc. + /*! Get the orientation of the arc. * \return The orientation. */ - Orientation orientation () const - { - return (this->_orient); - } + Orientation orientation() const { return (this->_orient); } - /*! - * Get the left endpoint of the arc. + /*! Get the left endpoint of the arc. */ const Conic_point_2& left () const { - if ((this->_info & IS_DIRECTED_RIGHT) != 0) - return (this->_source); - else - return (this->_target); + if ((this->_info & IS_DIRECTED_RIGHT) != 0) return (this->_source); + else return (this->_target); } /*! @@ -393,28 +364,21 @@ public: */ const Conic_point_2& right () const { - if ((this->_info & IS_DIRECTED_RIGHT) != 0) - return (this->_target); - else - return (this->_source); + if ((this->_info & IS_DIRECTED_RIGHT) != 0) return (this->_target); + else return (this->_source); } /*! * Return true iff the conic arc is directed right iexicographically. */ bool is_directed_right() const - { - return ((this->_info & IS_DIRECTED_RIGHT) != 0); - } + { return ((this->_info & IS_DIRECTED_RIGHT) != 0); } /*! * Get a bounding box for the conic arc. * \return The bounding box. */ - Bbox_2 bbox () const - { - return (Base::bbox()); - } + Bbox_2 bbox() const { return (Base::bbox()); } //@} /// \name Predicates. @@ -433,23 +397,20 @@ public: * \param p The qury point. * \param (true) if p lies on the arc; (false) otherwise. */ - bool contains_point (const Conic_point_2& p) const + bool contains_point(const Conic_point_2& p) const { // First check if p lies on the supporting conic. We first check whether // it is one of p's generating conic curves. bool p_on_conic = false; - if (p.is_generating_conic (_id)) - { + if (p.is_generating_conic(_id)) { p_on_conic = true; } - else - { + else { // Check whether p satisfies the supporting conic equation. - p_on_conic = _is_on_supporting_conic (p.x(), p.y()); + p_on_conic = _is_on_supporting_conic(p.x(), p.y()); - if (p_on_conic) - { + if (p_on_conic) { // As p lies on the supporting conic of our arc, add its ID to // the list of generating conics for p. Conic_point_2& p_non_const = const_cast (p); @@ -483,17 +444,16 @@ public: Alg_kernel ker; ); - CGAL_precondition (ker.compare_x_2_object() (p, left()) != SMALLER && - ker.compare_x_2_object() (p, right()) != LARGER); + CGAL_precondition(ker.compare_x_2_object() (p, left()) != SMALLER && + ker.compare_x_2_object() (p, right()) != LARGER); - if (_is_special_segment()) - { + if (_is_special_segment()) { // In case of a special segment, the equation of the supported line // (a*x + b*y + c) = 0 is stored with the extra data field, and we // simply have: - Algebraic _y = -(this->_extra_data_P->a*p.x() + - this->_extra_data_P->c) / - this->_extra_data_P->b; + Algebraic _y = -(this->_extra_data_P->a*p.x() + + this->_extra_data_P->c) / + this->_extra_data_P->b; // Return the computed point. return (Point_2 (p.x(), _y)); @@ -501,18 +461,16 @@ public: // Compute the y-coordinate according to the degree of the supporting // conic curve. - Nt_traits nt_traits; - Algebraic y; + Nt_traits nt_traits; + Algebraic y; - if ((this->_info & DEGREE_MASK) == DEGREE_1) - { + if ((this->_info & DEGREE_MASK) == DEGREE_1) { // In case of a linear curve, the y-coordinate is a simple linear // expression of x(p) (note that v is not 0 as the arc is not vertical): // y = -(u*x(p) + w) / v y = -(alg_u*p.x() + alg_w) / alg_v; } - else if (this->_orient == COLLINEAR) - { + else if (this->_orient == COLLINEAR) { CGAL_assertion (this->_extra_data_P != nullptr); // In this case the equation of the supporting line is given by the @@ -520,26 +478,23 @@ public: y = -(this->_extra_data_P->a * p.x() + this->_extra_data_P->c) / this->_extra_data_P->b; } - else - { - CGAL_assertion ((this->_info & DEGREE_MASK) == DEGREE_2); + else { + CGAL_assertion((this->_info & DEGREE_MASK) == DEGREE_2); // In this case the y-coordinate is one of solutions to the quadratic // equation: // s*y^2 + (t*x(p) + v)*y + (r*x(p)^2 + u*x(p) + w) = 0 - Algebraic A = alg_s; - Algebraic B = alg_t*p.x() + alg_v; - Algebraic C = (alg_r*p.x() + alg_u)*p.x() + alg_w; + Algebraic A = alg_s; + Algebraic B = alg_t*p.x() + alg_v; + Algebraic C = (alg_r*p.x() + alg_u)*p.x() + alg_w; - if (CGAL::sign(this->_s) == ZERO) - { + if (CGAL::sign(this->_s) == ZERO) { // In this case A is 0 and we have a linear equation. CGAL_assertion (CGAL::sign (B) != ZERO); y = -C / B; } - else - { + else { // Solve the quadratic equation. Algebraic disc = B*B - 4*A*C; @@ -547,13 +502,10 @@ public: // We take either the root involving -sqrt(disc) or +sqrt(disc) // based on the information flags. - if ((this->_info & PLUS_SQRT_DISC_ROOT) != 0) - { + if ((this->_info & PLUS_SQRT_DISC_ROOT) != 0) { y = (nt_traits.sqrt (disc) - B) / (2*A); } - else - - { + else { y = -(B + nt_traits.sqrt (disc)) / (2*A); } } @@ -579,169 +531,148 @@ public: { CGAL_precondition (n != 0); - const double x_left = CGAL::to_double (left().x()); - const double y_left = CGAL::to_double (left().y()); - const double x_right = CGAL::to_double (right().x()); - const double y_right = CGAL::to_double (right().y()); + const double x_left = CGAL::to_double (left().x()); + const double y_left = CGAL::to_double (left().y()); + const double x_right = CGAL::to_double (right().x()); + const double y_right = CGAL::to_double (right().y()); - if (this->_orient == COLLINEAR) - { + if (this->_orient == COLLINEAR) { // In case of a line segment, return the two endpoints. - *oi = std::pair (x_left, y_left); - ++oi; - *oi = std::pair (x_right, y_right); - ++oi; - return (oi); + *oi++ = std::pair (x_left, y_left); + *oi++ = std::pair (x_right, y_right); + return oi; } // Otherwise, sample (n - 1) equally-spaced points in between. - const double app_r = CGAL::to_double (this->_r); - const double app_s = CGAL::to_double (this->_s); - const double app_t = CGAL::to_double (this->_t); - const double app_u = CGAL::to_double (this->_u); - const double app_v = CGAL::to_double (this->_v); - const double app_w = CGAL::to_double (this->_w); - const double x_jump = (x_right - x_left) / n; - double x, y; - const bool A_is_zero = (CGAL::sign(this->_s) == ZERO); - double A = app_s, B, C; - double disc; - size_t i; + const double app_r = CGAL::to_double (this->_r); + const double app_s = CGAL::to_double (this->_s); + const double app_t = CGAL::to_double (this->_t); + const double app_u = CGAL::to_double (this->_u); + const double app_v = CGAL::to_double (this->_v); + const double app_w = CGAL::to_double (this->_w); + const double x_jump = (x_right - x_left) / n; + double x, y; + const bool A_is_zero = (CGAL::sign(this->_s) == ZERO); + double A = app_s, B, C; + double disc; + size_t i; - *oi = std::pair (x_left, y_left); // The left point. + *oi = std::pair(x_left, y_left); // The left point. ++oi; - for (i = 1; i < n; i++) - { + for (i = 1; i < n; i++) { x = x_left + x_jump*i; // Solve the quadratic equation: A*x^2 + B*x + C = 0: B = app_t*x + app_v; C = (app_r*x + app_u)*x + app_w; - if (A_is_zero) - { + if (A_is_zero) { y = -C / B; } - else - { + else { disc = B*B - 4*A*C; - if (disc < 0) - disc = 0; + if (disc < 0) disc = 0; // We take either the root involving -sqrt(disc) or +sqrt(disc) // based on the information flags. - if ((this->_info & PLUS_SQRT_DISC_ROOT) != 0) - { + if ((this->_info & PLUS_SQRT_DISC_ROOT) != 0) { y = (std::sqrt(disc) - B) / (2*A); } - else - { + else { y = -(B + std::sqrt (disc)) / (2*A); } } - *oi = std::pair (x, y); - ++oi; + *oi++ = std::pair (x, y); } - *oi = std::pair (x_right, y_right); // The right point. - ++oi; + *oi++ = std::pair (x_right, y_right); // The right point. - return (oi); + return oi; } - /*! - * Compare to arcs immediately to the right of their intersection point. + /*! Compare to arcs immediately to the right of their intersection point. * \param arc The compared arc. * \param p The reference intersection point. * \return The relative position of the arcs to the right of p. * \pre Both arcs we compare are not vertical segments. */ - Comparison_result compare_to_right (const Self& arc, - const Conic_point_2& p) const + Comparison_result compare_to_right(const Self& arc, + const Conic_point_2& p) const { - CGAL_precondition ((this->_info & IS_VERTICAL_SEGMENT) == 0 && - (arc._info & IS_VERTICAL_SEGMENT) == 0); + CGAL_precondition((this->_info & IS_VERTICAL_SEGMENT) == 0 && + (arc._info & IS_VERTICAL_SEGMENT) == 0); // In case one arc is facing upwards and another facing downwards, it is // clear that the one facing upward is above the one facing downwards. - if (_has_same_supporting_conic (arc)) - { + if (_has_same_supporting_conic (arc)) { if ((this->_info & FACING_UP) != 0 && (arc._info & FACING_DOWN) != 0) - return (LARGER); + return LARGER; else if ((this->_info & FACING_DOWN)!= 0 && (arc._info & FACING_UP) != 0) - return (SMALLER); + return SMALLER; // In this case the two arcs overlap. - CGAL_assertion ((this->_info & FACING_MASK) == - (arc._info & FACING_MASK)); + CGAL_assertion((this->_info & FACING_MASK) == (arc._info & FACING_MASK)); - return (EQUAL); + return EQUAL; } // Compare the slopes of the two arcs at p, using their first-order // partial derivatives. - Algebraic slope1_numer, slope1_denom; - Algebraic slope2_numer, slope2_denom; + Algebraic slope1_numer, slope1_denom; + Algebraic slope2_numer, slope2_denom; _derive_by_x_at (p, 1, slope1_numer, slope1_denom); arc._derive_by_x_at (p, 1, slope2_numer, slope2_denom); // Check if any of the slopes is vertical. - const bool is_vertical_slope1 = (CGAL::sign (slope1_denom) == ZERO); - const bool is_vertical_slope2 = (CGAL::sign (slope2_denom) == ZERO); + const bool is_vertical_slope1 = (CGAL::sign(slope1_denom) == ZERO); + const bool is_vertical_slope2 = (CGAL::sign(slope2_denom) == ZERO); - if (!is_vertical_slope1 && !is_vertical_slope2) - { + if (!is_vertical_slope1 && !is_vertical_slope2) { // The two derivatives at p are well-defined: use them to determine // which arc is above the other (the one with a larger slope is below). - Comparison_result slope_res = CGAL::compare (slope1_numer*slope2_denom, - slope2_numer*slope1_denom); + Comparison_result slope_res = + CGAL::compare(slope1_numer*slope2_denom, slope2_numer*slope1_denom); - if (slope_res != EQUAL) - return (slope_res); + if (slope_res != EQUAL) return (slope_res); // Use the second-order derivative. - _derive_by_x_at (p, 2, slope1_numer, slope1_denom); - arc._derive_by_x_at (p, 2, slope2_numer, slope2_denom); + _derive_by_x_at(p, 2, slope1_numer, slope1_denom); + arc._derive_by_x_at(p, 2, slope2_numer, slope2_denom); - slope_res = CGAL::compare (slope1_numer*slope2_denom, - slope2_numer*slope1_denom); + slope_res = + CGAL::compare(slope1_numer*slope2_denom, slope2_numer*slope1_denom); - if (slope_res != EQUAL) - return (slope_res); + if (slope_res != EQUAL) return (slope_res); // Use the third-order derivative. - _derive_by_x_at (p, 3, slope1_numer, slope1_denom); - arc._derive_by_x_at (p, 3, slope2_numer, slope2_denom); + _derive_by_x_at(p, 3, slope1_numer, slope1_denom); + arc._derive_by_x_at(p, 3, slope2_numer, slope2_denom); - slope_res = CGAL::compare (slope1_numer*slope2_denom, - slope2_numer*slope1_denom); + slope_res = + CGAL::compare(slope1_numer*slope2_denom, slope2_numer*slope1_denom); // \todo Handle higher-order derivatives: CGAL_assertion (slope_res != EQUAL); return (slope_res); } - else if (!is_vertical_slope2) - { + else if (!is_vertical_slope2) { // The first arc has a vertical slope at p: check whether it is // facing upwards or downwards and decide accordingly. CGAL_assertion ((this->_info & FACING_MASK) != 0); - if ((this->_info & FACING_UP) != 0) - return (LARGER); - return (SMALLER); + if ((this->_info & FACING_UP) != 0) return (LARGER); + return SMALLER; } - else if (!is_vertical_slope1) - { + else if (!is_vertical_slope1) { // The second arc has a vertical slope at p_int: check whether it is // facing upwards or downwards and decide accordingly. CGAL_assertion ((arc._info & FACING_MASK) != 0); - if ((arc._info & FACING_UP) != 0) - return (SMALLER); - return (LARGER); + if ((arc._info & FACING_UP) != 0) return (SMALLER); + return LARGER; } // The two arcs have vertical slopes at p_int: @@ -750,31 +681,29 @@ public: if ((this->_info & FACING_UP) != 0 && (arc._info & FACING_DOWN) != 0) return (LARGER); else if ((this->_info & FACING_DOWN)!= 0 && (arc._info & FACING_UP)!= 0) - return (SMALLER); + return SMALLER; // Compute the second-order derivative by y and act according to it. _derive_by_y_at (p, 2, slope1_numer, slope1_denom); arc._derive_by_y_at (p, 2, slope2_numer, slope2_denom); - Comparison_result slope_res = CGAL::compare (slope1_numer*slope2_denom, - slope2_numer*slope1_denom); + Comparison_result slope_res = + CGAL::compare(slope1_numer*slope2_denom, slope2_numer*slope1_denom); // If necessary, use the third-order derivative by y. - if (slope_res == EQUAL) - { + if (slope_res == EQUAL) { // \todo Check this! - _derive_by_y_at (p, 3, slope1_numer, slope1_denom); - arc._derive_by_y_at (p, 3, slope2_numer, slope2_denom); + _derive_by_y_at(p, 3, slope1_numer, slope1_denom); + arc._derive_by_y_at(p, 3, slope2_numer, slope2_denom); - slope_res = CGAL::compare (slope2_numer*slope1_denom, - slope1_numer*slope2_denom); + slope_res = + CGAL::compare(slope2_numer*slope1_denom, slope1_numer*slope2_denom); } // \todo Handle higher-order derivatives: CGAL_assertion(slope_res != EQUAL); - if ((this->_info & FACING_UP) != 0 && (arc._info & FACING_UP) != 0) - { + if ((this->_info & FACING_UP) != 0 && (arc._info & FACING_UP) != 0) { // Both are facing up. return ((slope_res == LARGER) ? SMALLER : LARGER); } @@ -789,50 +718,45 @@ public: * \return The relative position of the arcs to the left of p. * \pre Both arcs we compare are not vertical segments. */ - Comparison_result compare_to_left (const Self& arc, - const Conic_point_2& p) const + Comparison_result compare_to_left(const Self& arc, + const Conic_point_2& p) const { - CGAL_precondition ((this->_info & IS_VERTICAL_SEGMENT) == 0 && - (arc._info & IS_VERTICAL_SEGMENT) == 0); + CGAL_precondition((this->_info & IS_VERTICAL_SEGMENT) == 0 && + (arc._info & IS_VERTICAL_SEGMENT) == 0); // In case one arc is facing upwards and another facing downwards, it is // clear that the one facing upward is above the one facing downwards. - if (_has_same_supporting_conic (arc)) - { + if (_has_same_supporting_conic (arc)) { if ((this->_info & FACING_UP) != 0 && (arc._info & FACING_DOWN) != 0) - return (LARGER); + return LARGER; else if ((this->_info & FACING_DOWN)!= 0 && (arc._info & FACING_UP)!= 0) - return (SMALLER); + return SMALLER; // In this case the two arcs overlap. - CGAL_assertion ((this->_info & FACING_MASK) == - (arc._info & FACING_MASK)); + CGAL_assertion((this->_info & FACING_MASK) == (arc._info & FACING_MASK)); - return (EQUAL); + return EQUAL; } // Compare the slopes of the two arcs at p, using their first-order // partial derivatives. - Algebraic slope1_numer, slope1_denom; - Algebraic slope2_numer, slope2_denom; + Algebraic slope1_numer, slope1_denom; + Algebraic slope2_numer, slope2_denom; - _derive_by_x_at (p, 1, slope1_numer, slope1_denom); - arc._derive_by_x_at (p, 1, slope2_numer, slope2_denom); + _derive_by_x_at(p, 1, slope1_numer, slope1_denom); + arc._derive_by_x_at(p, 1, slope2_numer, slope2_denom); // Check if any of the slopes is vertical. - const bool is_vertical_slope1 = (CGAL::sign (slope1_denom) == ZERO); + const bool is_vertical_slope1 = (CGAL::sign (slope1_denom) == ZERO); + const bool is_vertical_slope2 = (CGAL::sign (slope2_denom) == ZERO); - const bool is_vertical_slope2 = (CGAL::sign (slope2_denom) == ZERO); - - if (!is_vertical_slope1 && !is_vertical_slope2) - { + if (!is_vertical_slope1 && !is_vertical_slope2) { // The two derivatives at p are well-defined: use them to determine // which arc is above the other (the one with a larger slope is below). Comparison_result slope_res = CGAL::compare(slope2_numer*slope1_denom, slope1_numer*slope2_denom); - if (slope_res != EQUAL) - return (slope_res); + if (slope_res != EQUAL) return (slope_res); // Use the second-order derivative. _derive_by_x_at (p, 2, slope1_numer, slope1_denom); @@ -841,73 +765,66 @@ public: slope_res = CGAL::compare (slope1_numer*slope2_denom, slope2_numer*slope1_denom); - if (slope_res != EQUAL) - return (slope_res); + if (slope_res != EQUAL) return (slope_res); // Use the third-order derivative. - _derive_by_x_at (p, 3, slope1_numer, slope1_denom); - arc._derive_by_x_at (p, 3, slope2_numer, slope2_denom); + _derive_by_x_at(p, 3, slope1_numer, slope1_denom); + arc._derive_by_x_at(p, 3, slope2_numer, slope2_denom); - slope_res = CGAL::compare (slope2_numer*slope1_denom, - slope1_numer*slope2_denom); + slope_res = CGAL::compare(slope2_numer*slope1_denom, + slope1_numer*slope2_denom); // \todo Handle higher-order derivatives: CGAL_assertion (slope_res != EQUAL); return (slope_res); } - else if (!is_vertical_slope2) - { + else if (!is_vertical_slope2) { // The first arc has a vertical slope at p: check whether it is // facing upwards or downwards and decide accordingly. CGAL_assertion ((this->_info & FACING_MASK) != 0); - if ((this->_info & FACING_UP) != 0) - return (LARGER); - return (SMALLER); + if ((this->_info & FACING_UP) != 0) return (LARGER); + return SMALLER; } - else if (!is_vertical_slope1) - { + else if (!is_vertical_slope1) { // The second arc has a vertical slope at p_int: check whether it is // facing upwards or downwards and decide accordingly. CGAL_assertion ((arc._info & FACING_MASK) != 0); - if ((arc._info & FACING_UP) != 0) - return (SMALLER); - return (LARGER); + if ((arc._info & FACING_UP) != 0) return (SMALLER); + return LARGER; } // The two arcs have vertical slopes at p_int: // First check whether one is facing up and one down. In this case the // comparison result is trivial. if ((this->_info & FACING_UP) != 0 && (arc._info & FACING_DOWN) != 0) - return (LARGER); + return LARGER; else if ((this->_info & FACING_DOWN)!= 0 && (arc._info & FACING_UP)!= 0) - return (SMALLER); + return SMALLER; // Compute the second-order derivative by y and act according to it. - _derive_by_y_at (p, 2, slope1_numer, slope1_denom); - arc._derive_by_y_at (p, 2, slope2_numer, slope2_denom); + _derive_by_y_at(p, 2, slope1_numer, slope1_denom); + arc._derive_by_y_at(p, 2, slope2_numer, slope2_denom); - Comparison_result slope_res = CGAL::compare(slope2_numer*slope1_denom, - slope1_numer*slope2_denom); + Comparison_result slope_res = + CGAL::compare(slope2_numer*slope1_denom, slope1_numer*slope2_denom); // If necessary, use the third-order derivative by y. - if (slope_res == EQUAL) - { + if (slope_res == EQUAL) { // \todo Check this! - _derive_by_y_at (p, 3, slope1_numer, slope1_denom); - arc._derive_by_y_at (p, 3, slope2_numer, slope2_denom); + _derive_by_y_at(p, 3, slope1_numer, slope1_denom); + arc._derive_by_y_at(p, 3, slope2_numer, slope2_denom); - slope_res = CGAL::compare (slope2_numer*slope1_denom, - slope1_numer*slope2_denom); + slope_res = + CGAL::compare(slope2_numer*slope1_denom, slope1_numer*slope2_denom); } // \todo Handle higher-order derivatives: CGAL_assertion(slope_res != EQUAL); - if ((this->_info & FACING_UP) != 0 && (arc._info & FACING_UP) != 0) - { + if ((this->_info & FACING_UP) != 0 && (arc._info & FACING_UP) != 0) { // Both are facing up. return ((slope_res == LARGER) ? SMALLER : LARGER); } @@ -922,22 +839,21 @@ public: * \param oi The output iterator. * \return The past-the-end iterator. */ - template - OutputIterator intersect (const Self& arc, - Intersection_map& inter_map, - OutputIterator oi) const + template + OutputIterator intersect(const Self& arc, + Intersection_map& inter_map, + OutputIterator oi) const { - if (_has_same_supporting_conic (arc)) - { - // Check for overlaps between the two arcs. - Self overlap; + typedef boost::variant Intersection_result; - if (_compute_overlap (arc, overlap)) - { + if (_has_same_supporting_conic(arc)) { + // Check for overlaps between the two arcs. + Self overlap; + + if (_compute_overlap(arc, overlap)) { // There can be just a single overlap between two x-monotone arcs: - *oi = make_object (overlap); - oi++; - return (oi); + *oi++ = Intersection_result(overlap); + return oi; } // In case there is not overlap and the supporting conics are the same, @@ -947,80 +863,62 @@ public: // intersection points we report. Alg_kernel ker; - if (ker.equal_2_object() (left(), arc.left())) - { - Intersection_point_2 ip (left(), 0); - - *oi = make_object (ip); - oi++; + if (ker.equal_2_object()(left(), arc.left())) { + Intersection_point ip(left(), 0); + *oi++ = Intersection_result(ip); } - if (ker.equal_2_object() (right(), arc.right())) - { - Intersection_point_2 ip (right(), 0); - - *oi = make_object (ip); - oi++; + if (ker.equal_2_object()(right(), arc.right())) { + Intersection_point ip(right(), 0); + *oi++ = Intersection_result(ip); } - return (oi); + return oi; } // Search for the pair of supporting conics in the map (the first conic // ID in the pair should be smaller than the second one, to guarantee // uniqueness). - Conic_pair conic_pair; - Intersection_map_iterator map_iter; - Intersection_list inter_list; - bool invalid_ids = false; - - if (_id.is_valid() && arc._id.is_valid()) - { - if (_id < arc._id) - conic_pair = Conic_pair (_id, arc._id); - else - conic_pair = Conic_pair (arc._id, _id); + Conic_pair conic_pair; + Intersection_map_iterator map_iter; + Intersection_list inter_list; + bool invalid_ids = false; + if (_id.is_valid() && arc._id.is_valid()) { + if (_id < arc._id) conic_pair = Conic_pair (_id, arc._id); + else conic_pair = Conic_pair (arc._id, _id); map_iter = inter_map.find (conic_pair); } - else - { + else { // In case one of the IDs is invalid, we do not look in the map neither // we cache the results. map_iter = inter_map.end(); invalid_ids = true; } - if (map_iter == inter_map.end()) - { + if (map_iter == inter_map.end()) { // In case the intersection points between the supporting conics have // not been computed before, compute them now and store them in the map. - _intersect_supporting_conics (arc, inter_list); + _intersect_supporting_conics(arc, inter_list); - if (! invalid_ids) - inter_map[conic_pair] = inter_list; + if (! invalid_ids) inter_map[conic_pair] = inter_list; } - else - { + else { // Obtain the precomputed intersection points from the map. inter_list = (*map_iter).second; } // Go over the list of intersection points and report those that lie on // both x-monotone arcs. - typename Intersection_list::const_iterator iter; - - for (iter = inter_list.begin(); iter != inter_list.end(); ++iter) - { - if (_is_between_endpoints ((*iter).first) && - arc._is_between_endpoints ((*iter).first)) + for (auto iter = inter_list.begin(); iter != inter_list.end(); ++iter) { + if (_is_between_endpoints((*iter).first) && + arc._is_between_endpoints((*iter).first)) { - *oi = make_object (*iter); - ++oi; + *oi++ = Intersection_result(*iter); } } - return (oi); + return oi; } //@} @@ -1034,13 +932,10 @@ public: * \param c2 Output: The first resulting arc, lying to the right of p. * \pre p lies in the interior of the arc (not one of its endpoints). */ - void split (const Conic_point_2& p, - Self& c1, Self& c2) const + void split(const Conic_point_2& p, Self& c1, Self& c2) const { // Make sure that p lies on the interior of the arc. - CGAL_precondition_code ( - Alg_kernel ker; - ); + CGAL_precondition_code(Alg_kernel ker); CGAL_precondition (this->contains_point (p) && ! ker.equal_2_object() (p, this->_source) && @@ -1058,8 +953,7 @@ public: c1._target = p; c2._source = p; - if (! p.is_generating_conic (_id)) - { + if (! p.is_generating_conic (_id)) { c1._target.set_generating_conic (_id); c2._source.set_generating_conic (_id); } @@ -1071,8 +965,7 @@ public: c1._source = p; c2._target = p; - if (! p.is_generating_conic (_id)) - { + if (! p.is_generating_conic (_id)) { c1._source.set_generating_conic (_id); c2._target.set_generating_conic (_id); } @@ -1085,16 +978,14 @@ public: * Flip the arc. * \return An arc with swapped source and target and a reverse orienation. */ - Self flip () const + Self flip() const { // Make a copy of the current arc. - Self arc = *this; + Self arc = *this; // Reverse the orientation. - if (this->_orient == CLOCKWISE) - arc._orient = COUNTERCLOCKWISE; - else if (this->_orient == COUNTERCLOCKWISE) - arc._orient = CLOCKWISE; + if (this->_orient == CLOCKWISE) arc._orient = COUNTERCLOCKWISE; + else if (this->_orient == COUNTERCLOCKWISE) arc._orient = CLOCKWISE; // Swap the source and the target. arc._source = this->_target; @@ -1103,7 +994,7 @@ public: // Change the direction bit among the information flags. arc._info = (this->_info ^ IS_DIRECTED_RIGHT); - return (arc); + return arc; } /*! @@ -1114,12 +1005,11 @@ public: * \pre Both ps and pt lies on the arc and must conform with the current * direction of the arc. */ - Self trim (const Conic_point_2& ps, - const Conic_point_2& pt) const + Self trim(const Conic_point_2& ps, const Conic_point_2& pt) const { // Make sure that both ps and pt lie on the arc. - CGAL_precondition (this->contains_point (ps) && - this->contains_point (pt)); + CGAL_precondition(this->contains_point (ps) && + this->contains_point (pt)); // Make sure that the endpoints conform with the direction of the arc. Self arc = *this; @@ -1136,8 +1026,7 @@ public: } // Make a copy of the current arc and assign its endpoints. - if (! ker.equal_2_object() (ps, this->_source)) - { + if (! ker.equal_2_object() (ps, this->_source)) { arc._source = ps; if (! ps.is_generating_conic (_id)) @@ -1164,46 +1053,41 @@ public: { // The two arc must have the same supporting conic curves. if (! _has_same_supporting_conic (arc)) - return (false); + return false; // Check that the arc endpoints are the same. - Alg_kernel ker; + Alg_kernel ker; - if(this->_orient == COLLINEAR) - { + if (this->_orient == COLLINEAR) { CGAL_assertion(arc._orient == COLLINEAR); - return((ker.equal_2_object() (this->_source, arc._source) && - ker.equal_2_object() (this->_target, arc._target)) || - (ker.equal_2_object() (this->_source, arc._target) && - ker.equal_2_object() (this->_target, arc._source))); + return((ker.equal_2_object()(this->_source, arc._source) && + ker.equal_2_object()(this->_target, arc._target)) || + (ker.equal_2_object()(this->_source, arc._target) && + ker.equal_2_object()(this->_target, arc._source))); } - if (this->_orient == arc._orient) - { + if (this->_orient == arc._orient) { // Same orientation - the source and target points must be the same. - return (ker.equal_2_object() (this->_source, arc._source) && - ker.equal_2_object() (this->_target, arc._target)); + return (ker.equal_2_object()(this->_source, arc._source) && + ker.equal_2_object()(this->_target, arc._target)); } - else - { + else { // Reverse orientation - the source and target points must be swapped. - return (ker.equal_2_object() (this->_source, arc._target) && - ker.equal_2_object() (this->_target, arc._source)); + return (ker.equal_2_object()(this->_source, arc._target) && + ker.equal_2_object()(this->_target, arc._source)); } } - /*! - * Check whether it is possible to merge the arc with the given arc. + /*! Check whether it is possible to merge the arc with the given arc. * \param arc The query arc. * \return (true) if it is possible to merge the two arcs; * (false) otherwise. */ - bool can_merge_with (const Self& arc) const + bool can_merge_with(const Self& arc) const { // In order to merge the two arcs, they should have the same supporting // conic. - if (! _has_same_supporting_conic (arc)) - return (false); + if (! _has_same_supporting_conic(arc)) return false; // Check if the left endpoint of one curve is the right endpoint of the // other. @@ -1213,28 +1097,23 @@ public: ker.equal_2_object() (left(), arc.right())); } - /*! - * Merge the current arc with the given arc. + /*! Merge the current arc with the given arc. * \param arc The arc to merge with. * \pre The two arcs are mergeable. */ - void merge (const Self& arc) + void merge(const Self& arc) { CGAL_precondition (this->can_merge_with (arc)); // Check if we should extend the arc to the left or to the right. Alg_kernel ker; - if (ker.equal_2_object() (right(), arc.left())) - { + if (ker.equal_2_object() (right(), arc.left())) { // Extend the arc to the right. - if ((this->_info & IS_DIRECTED_RIGHT) != 0) - this->_target = arc.right(); - else - this->_source = arc.right(); + if ((this->_info & IS_DIRECTED_RIGHT) != 0) this->_target = arc.right(); + else this->_source = arc.right(); } - else - { + else { CGAL_precondition (ker.equal_2_object() (left(), arc.right())); // Extend the arc to the left. @@ -1835,36 +1714,32 @@ private: * \param arc The arc to intersect with. * \param inter_list The list of intersection points. */ - void _intersect_supporting_conics (const Self& arc, - Intersection_list& inter_list) const + void _intersect_supporting_conics(const Self& arc, + Intersection_list& inter_list) const { - if (_is_special_segment() && ! arc._is_special_segment()) - { + if (_is_special_segment() && ! arc._is_special_segment()) { // If one of the arcs is a special segment, make sure it is (arc). - arc._intersect_supporting_conics (*this, inter_list); + arc._intersect_supporting_conics(*this, inter_list); return; } - const int deg1 = ((this->_info & DEGREE_MASK) == DEGREE_1) ? 1 : 2; - const int deg2 = ((arc._info & DEGREE_MASK) == DEGREE_1) ? 1 : 2; - Nt_traits nt_traits; - Algebraic xs[4]; - int n_xs = 0; - Algebraic ys[4]; - int n_ys = 0; + const int deg1 = ((this->_info & DEGREE_MASK) == DEGREE_1) ? 1 : 2; + const int deg2 = ((arc._info & DEGREE_MASK) == DEGREE_1) ? 1 : 2; + Nt_traits nt_traits; + Algebraic xs[4]; + int n_xs = 0; + Algebraic ys[4]; + int n_ys = 0; - if (arc._is_special_segment()) - { + if (arc._is_special_segment()) { // The second arc is a special segment (a*x + b*y + c = 0). - if (_is_special_segment()) - { + if (_is_special_segment()) { // Both arc are sepcial segment, so they have at most one intersection // point. - Algebraic denom = this->_extra_data_P->a * arc._extra_data_P->b - - this->_extra_data_P->b * arc._extra_data_P->a; + Algebraic denom = this->_extra_data_P->a * arc._extra_data_P->b - + this->_extra_data_P->b * arc._extra_data_P->a; - if (CGAL::sign (denom) != CGAL::ZERO) - { + if (CGAL::sign (denom) != CGAL::ZERO) { xs[0] = (this->_extra_data_P->b * arc._extra_data_P->c - this->_extra_data_P->c * arc._extra_data_P->b) / denom; n_xs = 1; @@ -1874,8 +1749,7 @@ private: n_ys = 1; } } - else - { + else { // Compute the x-coordinates of the intersection points. n_xs = _compute_resultant_roots (nt_traits, alg_r, alg_s, alg_t, @@ -1899,8 +1773,7 @@ private: CGAL_assertion (n_ys <= 2); } } - else - { + else { // Compute the x-coordinates of the intersection points. n_xs = _compute_resultant_roots (nt_traits, this->_r, this->_s, this->_t, @@ -1921,7 +1794,7 @@ private: arc._v, arc._u, arc._w, deg2, ys); - CGAL_assertion (n_ys <= 4); + CGAL_assertion(n_ys <= 4); } // Pair the coordinates of the intersection points. As the vectors of @@ -1938,14 +1811,14 @@ private: if (n_xs == 1 && n_ys == 1) { // Single intersection. - Conic_point_2 ip (xs[0], ys[0]); + Conic_point_2 ip (xs[0], ys[0]); ip.set_generating_conic (_id); ip.set_generating_conic (arc._id); // In case the other curve is of degree 2, this is a tangency point. mult = (deg1 == 1 || _is_special_segment()) ? 1 : 2; - inter_list.push_back (Intersection_point_2 (ip, mult)); + inter_list.push_back(Intersection_point (ip, mult)); } else if (n_xs == 1 && n_ys == 2) { @@ -1954,14 +1827,14 @@ private: ip1.set_generating_conic (_id); ip1.set_generating_conic (arc._id); - inter_list.push_back (Intersection_point_2 (ip1, 1)); + inter_list.push_back(Intersection_point (ip1, 1)); Conic_point_2 ip2 (xs[0], ys[1]); ip2.set_generating_conic (_id); ip2.set_generating_conic (arc._id); - inter_list.push_back (Intersection_point_2 (ip2, 1)); + inter_list.push_back(Intersection_point (ip2, 1)); } else if (n_xs == 2 && n_ys == 1) { @@ -1970,24 +1843,23 @@ private: ip1.set_generating_conic (_id); ip1.set_generating_conic (arc._id); - inter_list.push_back (Intersection_point_2 (ip1, 1)); + inter_list.push_back(Intersection_point (ip1, 1)); Conic_point_2 ip2 (xs[1], ys[0]); ip2.set_generating_conic (_id); ip2.set_generating_conic (arc._id); - inter_list.push_back (Intersection_point_2 (ip2, 1)); + inter_list.push_back(Intersection_point (ip2, 1)); } - else - { + else { CGAL_assertion (n_xs == 2 && n_ys == 2); // The x-coordinates and the y-coordinates are given in ascending // order. If the slope of the segment is positive, we pair the // coordinates as is - otherwise, we swap the pairs. - int ind_first_y = 0, ind_second_y = 1; + int ind_first_y = 0, ind_second_y = 1; if (CGAL::sign (arc._extra_data_P->b) == CGAL::sign(arc._extra_data_P->a)) @@ -1996,45 +1868,41 @@ private: ind_second_y = 0; } - Conic_point_2 ip1 (xs[0], ys[ind_first_y]); + Conic_point_2 ip1(xs[0], ys[ind_first_y]); - ip1.set_generating_conic (_id); - ip1.set_generating_conic (arc._id); + ip1.set_generating_conic(_id); + ip1.set_generating_conic(arc._id); - inter_list.push_back (Intersection_point_2 (ip1, 1)); + inter_list.push_back(Intersection_point (ip1, 1)); - Conic_point_2 ip2 (xs[1], ys[ind_second_y]); + Conic_point_2 ip2(xs[1], ys[ind_second_y]); ip2.set_generating_conic (_id); ip2.set_generating_conic (arc._id); - inter_list.push_back (Intersection_point_2 (ip2, 1)); + inter_list.push_back(Intersection_point(ip2, 1)); } return; } - for (i = 0; i < n_xs; i++) - { - for (j = 0; j < n_ys; j++) - { + for (i = 0; i < n_xs; i++) { + for (j = 0; j < n_ys; j++) { if (_is_on_supporting_conic (xs[i], ys[j]) && arc._is_on_supporting_conic (xs[i], ys[j])) { // Create the intersection point and set its generating conics. - Conic_point_2 ip (xs[i], ys[j]); + Conic_point_2 ip(xs[i], ys[j]); ip.set_generating_conic (_id); ip.set_generating_conic (arc._id); // Compute the multiplicity of the intersection point. - if (deg1 == 1 && deg2 == 1) - mult = 1; - else - mult = _multiplicity_of_intersection_point (arc, ip); + if (deg1 == 1 && deg2 == 1) mult = 1; + else mult = _multiplicity_of_intersection_point(arc, ip); // Insert the intersection point to the output list. - inter_list.push_back (Intersection_point_2 (ip, mult)); + inter_list.push_back(Intersection_point(ip, mult)); } } } diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_geometry_traits/Rational_arc_2.h b/Arrangement_on_surface_2/include/CGAL/Arr_geometry_traits/Rational_arc_2.h index f5db0ebbad7..b6c246eb583 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_geometry_traits/Rational_arc_2.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_geometry_traits/Rational_arc_2.h @@ -1830,7 +1830,7 @@ public: typedef typename Base::Rat_vector Rat_vector; typedef typename Base::Polynomial Polynomial; - typedef std::pair Intersection_point_2; + typedef std::pair Intersection_point; /// \name Constrcution methods. @@ -1967,138 +1967,118 @@ public: CGAL_precondition (this->is_valid() && this->is_continuous()); CGAL_precondition (arc.is_valid() && arc.is_continuous()); - if (this->_has_same_base (arc)) - { - Alg_kernel ker; + if (this->_has_same_base (arc)) { + Alg_kernel ker; // Get the left and right endpoints of (*this) and their information // bits. - const Point_2& left1 = (this->is_directed_right() ? - this->_ps : this->_pt); - const Point_2& right1 = (this->is_directed_right() ? - this->_pt : this->_ps); - int info_left1, info_right1; + const Point_2& left1 = + (this->is_directed_right() ? this->_ps : this->_pt); + const Point_2& right1 = + (this->is_directed_right() ? this->_pt : this->_ps); + int info_left1, info_right1; - if (this->is_directed_right()) - { + if (this->is_directed_right()) { info_left1 = (this->_info & this->SRC_INFO_BITS); info_right1 = ((this->_info & this->TRG_INFO_BITS) >> 4); } - else - { + else { info_right1 = (this->_info & this->SRC_INFO_BITS); info_left1 = ((this->_info & this->TRG_INFO_BITS) >> 4); } // Get the left and right endpoints of the other arc and their // information bits. - const Point_2& left2 = (arc.is_directed_right() ? arc._ps : arc._pt); - const Point_2& right2 = (arc.is_directed_right() ? arc._pt : arc._ps); - int info_left2, info_right2; + const Point_2& left2 = (arc.is_directed_right() ? arc._ps : arc._pt); + const Point_2& right2 = (arc.is_directed_right() ? arc._pt : arc._ps); + int info_left2, info_right2; - if (arc.is_directed_right()) - { + if (arc.is_directed_right()) { info_left2 = (arc._info & this->SRC_INFO_BITS); info_right2 = ((arc._info & this->TRG_INFO_BITS) >> 4); } - else - { + else { info_right2 = (arc._info & this->SRC_INFO_BITS); info_left2 = ((arc._info & this->TRG_INFO_BITS) >> 4); } // Locate the left curve-end with larger x-coordinate. - bool at_minus_infinity = false; - Arr_parameter_space inf_l1 = this->left_infinite_in_x(); - Arr_parameter_space inf_l2 = arc.left_infinite_in_x(); - Point_2 p_left; - int info_left; + bool at_minus_infinity = false; + Arr_parameter_space inf_l1 = this->left_infinite_in_x(); + Arr_parameter_space inf_l2 = arc.left_infinite_in_x(); + Point_2 p_left; + int info_left; - if (inf_l1 == ARR_INTERIOR && inf_l2 == ARR_INTERIOR) - { + if (inf_l1 == ARR_INTERIOR && inf_l2 == ARR_INTERIOR) { // Let p_left be the rightmost of the two left endpoints. - if (ker.compare_x_2_object() (left1, left2) == LARGER) - { + if (ker.compare_x_2_object() (left1, left2) == LARGER) { p_left = left1; info_left = info_left1; } - else - { + else { p_left = left2; info_left = info_left2; } } - else if (inf_l1 == ARR_INTERIOR) - { + else if (inf_l1 == ARR_INTERIOR) { // Let p_left be the left endpoint of (*this). p_left = left1; info_left = info_left1; } - else if (inf_l2 == ARR_INTERIOR) - { + else if (inf_l2 == ARR_INTERIOR) { // Let p_left be the left endpoint of the other arc. p_left = left2; info_left = info_left2; } - else - { + else { // Both arcs are defined at x = -oo. at_minus_infinity = true; info_left = info_left1; } // Locate the right curve-end with smaller x-coordinate. - bool at_plus_infinity = false; - Arr_parameter_space inf_r1 = this->right_infinite_in_x(); - Arr_parameter_space inf_r2 = arc.right_infinite_in_x(); - Point_2 p_right; - int info_right; + bool at_plus_infinity = false; + Arr_parameter_space inf_r1 = this->right_infinite_in_x(); + Arr_parameter_space inf_r2 = arc.right_infinite_in_x(); + Point_2 p_right; + int info_right; - if (inf_r1 == ARR_INTERIOR && inf_r2 == ARR_INTERIOR) - { + if (inf_r1 == ARR_INTERIOR && inf_r2 == ARR_INTERIOR) { // Let p_right be the rightmost of the two right endpoints. - if (ker.compare_x_2_object() (right1, right2) == SMALLER) - { + if (ker.compare_x_2_object() (right1, right2) == SMALLER) { p_right = right1; info_right = info_right1; } - else - { + else { p_right = right2; info_right = info_right2; } } - else if (inf_r1 == ARR_INTERIOR) - { + else if (inf_r1 == ARR_INTERIOR) { // Let p_right be the right endpoint of (*this). p_right = right1; info_right = info_right1; } - else if (inf_r2 == ARR_INTERIOR) - { + else if (inf_r2 == ARR_INTERIOR) { // Let p_right be the right endpoint of the other arc. p_right = right2; info_right = info_right2; } - else - { + else { // Both arcs are defined at x = +oo. at_plus_infinity = true; info_right = info_right2; } // Check the case of two bounded (in x) ends. - if (! at_minus_infinity && ! at_plus_infinity) - { + if (! at_minus_infinity && ! at_plus_infinity) { Comparison_result res = ker.compare_x_2_object() (p_left, p_right); - if (res == LARGER) - { + if (res == LARGER) { // The x-range of the overlap is empty, so there is no overlap. - return (oi); + return oi; } - else if (res == EQUAL) - { + if (res == EQUAL) { // We have a single overlapping point. Just make sure this point // is not at y = -/+ oo. if (info_left && @@ -2106,20 +2086,19 @@ public: info_right && (this->SRC_AT_Y_MINUS_INFTY | this->SRC_AT_Y_PLUS_INFTY) == 0) { - Intersection_point_2 ip (p_left, 0); + Intersection_point ip (p_left, 0); - *oi = make_object (ip); - ++oi; + *oi++ = make_object (ip); } - return (oi); + return oi; } } // Create the overlapping portion of the rational arc by properly setting // the source (left) and target (right) endpoints and their information // bits. - Self overlap_arc (*this); + Self overlap_arc(*this); overlap_arc._ps = p_left; overlap_arc._pt = p_right; @@ -2128,10 +2107,9 @@ public: this->IS_DIRECTED_RIGHT | this->IS_CONTINUOUS | this->IS_VALID); - *oi = make_object (overlap_arc); - ++oi; + *oi++ = make_object(overlap_arc); - return (oi); + return oi; } // We wish to find the intersection points between: @@ -2140,39 +2118,34 @@ public: // // It is clear that the x-coordinates of the intersection points are // the roots of the polynomial: ip(x) = p1(x)*q2(x) - p2(x)*q1(x). - Nt_traits nt_traits; - Polynomial ipoly = this->_numer * arc._denom - - arc._numer * this->_denom; - std::list xs; + Nt_traits nt_traits; + Polynomial ipoly = this->_numer * arc._denom - arc._numer* this->_denom; + std::list xs; typename std::list::const_iterator x_iter; - nt_traits.compute_polynomial_roots (ipoly, - std::back_inserter(xs)); + nt_traits.compute_polynomial_roots(ipoly, std::back_inserter(xs)); // Go over the x-values we obtained. For each value produce an // intersection point if it is contained in the x-range of both curves. - unsigned int mult; + unsigned int mult; - for (x_iter = xs.begin(); x_iter != xs.end(); ++x_iter) - { + for (x_iter = xs.begin(); x_iter != xs.end(); ++x_iter) { if (this->_is_in_true_x_range (*x_iter) && arc._is_in_true_x_range (*x_iter)) { // Compute the intersection point and obtain its multiplicity. - Point_2 p (*x_iter, nt_traits.evaluate_at (this->_numer, *x_iter) / - nt_traits.evaluate_at (this->_denom, *x_iter)); + Point_2 p(*x_iter, nt_traits.evaluate_at (this->_numer, *x_iter) / + nt_traits.evaluate_at (this->_denom, *x_iter)); - this->compare_slopes (arc, p, mult); + this->compare_slopes(arc, p, mult); // Output the intersection point: - Intersection_point_2 ip (p, mult); - - *oi = make_object (ip); - ++oi; + Intersection_point ip(p, mult); + *oi++ = make_object(ip); } } - return (oi); + return oi; } /*! 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 2038cf0ad79..0e1262db0ec 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 @@ -8,8 +8,9 @@ // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial // // -// Author(s) : Ron Wein -// : Waqar Khan +// Author(s): Ron Wein +// Waqar Khan +// Efi fogel #ifndef CGAL_ARR_LINEAR_TRAITS_2_H #define CGAL_ARR_LINEAR_TRAITS_2_H @@ -23,27 +24,29 @@ * in the arrangement package. */ +#include + +#include + #include #include #include #include #include -#include namespace CGAL { -template class Arr_linear_object_2; +template class Arr_linear_object_2; /*! \class * A traits class for maintaining an arrangement of linear objects (lines, * rays and segments), aoviding cascading of computations as much as possible. */ -template +template class Arr_linear_traits_2 : public Kernel_ { friend class Arr_linear_object_2; public: - typedef Kernel_ Kernel; typedef typename Kernel::FT FT; @@ -70,17 +73,14 @@ public: /*! * \class Representation of a linear with cached data. */ - class _Linear_object_cached_2 - { + class _Linear_object_cached_2 { public: - typedef typename Kernel::Line_2 Line_2; typedef typename Kernel::Ray_2 Ray_2; typedef typename Kernel::Segment_2 Segment_2; typedef typename Kernel::Point_2 Point_2; protected: - Line_2 l; // The supporting line. Point_2 ps; // The source point (if exists). Point_2 pt; // The target point (if exists). @@ -99,39 +99,36 @@ public: bool is_degen; // Is the object degenerate (a single point). public: - - /*! - * Default constructor. + /*! Default constructor. */ - _Linear_object_cached_2 () : - has_source (true), - has_target (true), - is_vert (false), - is_horiz (false), - has_pos_slope (false), - is_degen (true) + _Linear_object_cached_2() : + has_source(true), + has_target(true), + is_vert(false), + is_horiz(false), + has_pos_slope(false), + is_degen(true) {} - /*! - * Constructor for segment from two points. + /*! Constructor for segment from two points. * \param p1 source point. * \param p2 target point. * \pre The two points must not be equal. */ _Linear_object_cached_2(const Point_2& source, const Point_2& target) : - ps (source), - pt (target), - has_source (true), - has_target (true) + ps(source), + pt(target), + has_source(true), + has_target(true) { - Kernel kernel; + Kernel kernel; - Comparison_result res = kernel.compare_xy_2_object()(source, target); + Comparison_result res = kernel.compare_xy_2_object()(source, target); is_degen = (res == EQUAL); is_right = (res == SMALLER); - CGAL_precondition_msg (! is_degen, - "Cannot construct a degenerate segment."); + CGAL_precondition_msg(! is_degen, + "Cannot construct a degenerate segment."); l = kernel.construct_line_2_object()(source, target); is_vert = kernel.is_vertical_2_object()(l); @@ -139,29 +136,25 @@ public: has_pos_slope = _has_positive_slope(); } - /*! - * Constructor from a segment. + /*! Constructor from a segment. * \param seg The segment. * \pre The segment is not degenerate. */ - _Linear_object_cached_2 (const Segment_2& seg) + _Linear_object_cached_2(const Segment_2& seg) : + has_source(true), + has_target(true) { - Kernel kernel; + Kernel kernel; - CGAL_assertion_msg (! kernel.is_degenerate_2_object() (seg), - "Cannot construct a degenerate segment."); - - typename Kernel_::Construct_vertex_2 - construct_vertex = kernel.construct_vertex_2_object(); + CGAL_assertion_msg(! kernel.is_degenerate_2_object()(seg), + "Cannot construct a degenerate segment."); + auto construct_vertex = kernel.construct_vertex_2_object(); ps = construct_vertex(seg, 0); - has_source = true; pt = construct_vertex(seg, 1); - has_target = true; - Comparison_result res = kernel.compare_xy_2_object()(ps, pt); - - CGAL_assertion (res != EQUAL); + Comparison_result res = kernel.compare_xy_2_object()(ps, pt); + CGAL_assertion(res != EQUAL); is_degen = false; is_right = (res == SMALLER); @@ -171,28 +164,25 @@ public: has_pos_slope = _has_positive_slope(); } - /*! - * Constructor from a ray. + /*! Constructor from a ray. * \param ray The ray. * \pre The ray is not degenerate. */ - _Linear_object_cached_2 (const Ray_2& ray) + _Linear_object_cached_2(const Ray_2& ray) : + has_source(true), + has_target(false) { - Kernel kernel; + Kernel kernel; - CGAL_assertion_msg (! kernel.is_degenerate_2_object() (ray), - "Cannot construct a degenerate ray."); - - typename Kernel_::Construct_point_on_2 - construct_vertex = kernel.construct_point_on_2_object(); + CGAL_assertion_msg(! kernel.is_degenerate_2_object()(ray), + "Cannot construct a degenerate ray."); + auto construct_vertex = kernel.construct_point_on_2_object(); ps = construct_vertex(ray, 0); // The source point. - has_source = true; pt = construct_vertex(ray, 1); // Some point on the ray. - has_target = false; Comparison_result res = kernel.compare_xy_2_object()(ps, pt); - CGAL_assertion (res != EQUAL); + CGAL_assertion(res != EQUAL); is_degen = false; is_right = (res == SMALLER); @@ -202,31 +192,26 @@ public: has_pos_slope = _has_positive_slope(); } - /*! - * Constructor from a line. + /*! Constructor from a line. * \param ln The line. * \pre The line is not degenerate. */ - _Linear_object_cached_2 (const Line_2& ln) : - l (ln), - has_source (false), - has_target (false) + _Linear_object_cached_2(const Line_2& ln) : + l(ln), + has_source(false), + has_target(false) { - Kernel kernel; + Kernel kernel; - CGAL_assertion_msg (! kernel.is_degenerate_2_object() (ln), - "Cannot construct a degenerate line."); - - typename Kernel_::Construct_point_on_2 - construct_vertex = kernel.construct_point_on_2_object(); + CGAL_assertion_msg(! kernel.is_degenerate_2_object()(ln), + "Cannot construct a degenerate line."); + auto construct_vertex = kernel.construct_point_on_2_object(); ps = construct_vertex(ln, 0); // Some point on the line. - has_source = false; pt = construct_vertex(ln, 1); // Some point further on the line. - has_target = false; - Comparison_result res = kernel.compare_xy_2_object()(ps, pt); - CGAL_assertion (res != EQUAL); + Comparison_result res = kernel.compare_xy_2_object()(ps, pt); + CGAL_assertion(res != EQUAL); is_degen = false; is_right = (res == SMALLER); @@ -235,31 +220,27 @@ public: has_pos_slope = _has_positive_slope(); } - /*! - * Check whether the x-coordinate of the left point is infinite. + /*! Check whether the x-coordinate of the left point is infinite. * \return ARR_LEFT_BOUNDARY if the left point is near the boundary; * ARR_INTERIOR if the x-coordinate is finite. */ - Arr_parameter_space left_infinite_in_x () const + Arr_parameter_space left_infinite_in_x() const { - if (is_vert || is_degen) - return (ARR_INTERIOR); + if (is_vert || is_degen) return (ARR_INTERIOR); return (is_right) ? (has_source ? ARR_INTERIOR : ARR_LEFT_BOUNDARY) : (has_target ? ARR_INTERIOR : ARR_LEFT_BOUNDARY); } - /*! - * Check whether the y-coordinate of the left point is infinite. + /*! Check whether the y-coordinate of the left point is infinite. * \return ARR_BOTTOM_BOUNDARY if the left point is at y = -oo; * ARR_INTERIOR if the y-coordinate is finite. * ARR_TOP_BOUNDARY if the left point is at y = +oo; */ - Arr_parameter_space left_infinite_in_y () const + Arr_parameter_space left_infinite_in_y() const { - if (is_horiz || is_degen) - return ARR_INTERIOR; + if (is_horiz || is_degen) return ARR_INTERIOR; if (is_vert) { return (is_right) ? @@ -268,100 +249,80 @@ public: } if ((is_right && has_source) || (! is_right && has_target)) - return ARR_INTERIOR; + return ARR_INTERIOR; return (has_pos_slope ? ARR_BOTTOM_BOUNDARY : ARR_TOP_BOUNDARY); } - /*! - * Check whether the left point is finite. + /*! Check whether the left point is finite. */ - bool has_left () const - { - if (is_right) - return (has_source); - else - return (has_target); - } + bool has_left() const { return (is_right ? has_source : has_target); } - /*! - * Obtain the (lexicographically) left endpoint. + /*! Obtain the (lexicographically) left endpoint. * \pre The left point is finite. */ - const Point_2& left () const + const Point_2& left() const { - CGAL_precondition (has_left()); + CGAL_precondition(has_left()); return (is_right ? ps : pt); } - /*! - * Set the (lexicographically) left endpoint. + /*! Set the (lexicographically) left endpoint. * \param p The point to set. * \pre p lies on the supporting line to the left of the right endpoint. */ - void set_left (const Point_2& p, bool CGAL_assertion_code(check_validity) = true) + void set_left(const Point_2& p, + bool CGAL_assertion_code(check_validity) = true) { - CGAL_precondition (! is_degen); + CGAL_precondition(! is_degen); - CGAL_precondition_code ( - Kernel kernel; - ); + CGAL_precondition_code(Kernel kernel); CGAL_precondition - (Segment_assertions::_assert_is_point_on (p, l, - Has_exact_division()) && + (Segment_assertions::_assert_is_point_on(p, l, Has_exact_division()) && (! check_validity || ! has_right() || - kernel.compare_xy_2_object() (p, right()) == SMALLER)); + kernel.compare_xy_2_object()(p, right()) == SMALLER)); - if (is_right) - { + if (is_right) { ps = p; has_source = true; } - else - { + else { pt = p; has_target = true; } } - /*! - * Set the (lexicographically) left endpoint as infinite. + /*! Set the (lexicographically) left endpoint as infinite. */ - void set_left () + void set_left() { - CGAL_precondition (! is_degen); + CGAL_precondition(! is_degen); - if (is_right) - has_source = false; - else - has_target = false; + if (is_right) has_source = false; + else has_target = false; } - /*! - * Check whether the x-coordinate of the right point is infinite. + /*! Check whether the x-coordinate of the right point is infinite. * \return ARR_RIGHT_BOUNDARY if the right point is near the boundary; * ARR_INTERIOR if the x-coordinate is finite. */ - Arr_parameter_space right_infinite_in_x () const + Arr_parameter_space right_infinite_in_x() const { - if (is_vert || is_degen) - return ARR_INTERIOR; + if (is_vert || is_degen) return ARR_INTERIOR; return (is_right) ? (has_target ? ARR_INTERIOR : ARR_RIGHT_BOUNDARY) : (has_source ? ARR_INTERIOR : ARR_RIGHT_BOUNDARY); } - /*! - * Check whether the y-coordinate of the right point is infinite. + /*! Check whether the y-coordinate of the right point is infinite. * \return ARR_BOTTOM_BOUNDARY if the right point is at y = -oo; * ARR_INTERIOR if the y-coordinate is finite. * ARR_TOP_BOUNDARY if the right point is at y = +oo; */ - Arr_parameter_space right_infinite_in_y () const + Arr_parameter_space right_infinite_in_y() const { - if (is_horiz || is_degen) - return ARR_INTERIOR; + if (is_horiz || is_degen) return ARR_INTERIOR; if (is_vert) { return (is_right) ? @@ -375,145 +336,108 @@ public: return (has_pos_slope ? ARR_TOP_BOUNDARY : ARR_BOTTOM_BOUNDARY); } - /*! - * Check whether the right point is finite. + /*! Check whether the right point is finite. */ - bool has_right () const - { - if (is_right) - return (has_target); - else - return (has_source); - } + bool has_right() const { return (is_right ? has_target : has_source); } - /*! - * Obtain the (lexicographically) right endpoint. + /*! Obtain the (lexicographically) right endpoint. * \pre The right endpoint is finite. */ - const Point_2& right () const + const Point_2& right() const { - CGAL_precondition (has_right()); + CGAL_precondition(has_right()); return (is_right ? pt : ps); } - /*! - * Set the (lexicographically) right endpoint. + /*! Set the (lexicographically) right endpoint. * \param p The point to set. * \pre p lies on the supporting line to the right of the left endpoint. */ - void set_right (const Point_2& p, bool CGAL_assertion_code(check_validity) = true) + void set_right(const Point_2& p, + bool CGAL_assertion_code(check_validity) = true) { - CGAL_precondition (! is_degen); - CGAL_precondition_code ( - Kernel kernel; - ); + CGAL_precondition(! is_degen); + CGAL_precondition_code(Kernel kernel); CGAL_precondition - (Segment_assertions::_assert_is_point_on (p, l, - Has_exact_division()) && + (Segment_assertions::_assert_is_point_on(p, l, Has_exact_division()) && (! check_validity || ! has_left() || - kernel.compare_xy_2_object() (p, left()) == LARGER)); + kernel.compare_xy_2_object()(p, left()) == LARGER)); - if (is_right) - { + if (is_right) { pt = p; has_target = true; } - else - { + else { ps = p; has_source = true; } } - /*! - * Set the (lexicographically) right endpoint as infinite. + /*! Set the (lexicographically) right endpoint as infinite. */ - void set_right () + void set_right() { CGAL_precondition (! is_degen); - if (is_right) - has_target = false; - else - has_source = false; + if (is_right) has_target = false; + else has_source = false; } - /*! - * Obtain the supporting line. + /*! Obtain the supporting line. */ - const Line_2& supp_line () const + const Line_2& supp_line() const { - CGAL_precondition (! is_degen); + CGAL_precondition(! is_degen); return (l); } - /*! - * Check whether the curve is vertical. + /*! Check whether the curve is vertical. */ - bool is_vertical () const + bool is_vertical() const { - CGAL_precondition (! is_degen); + CGAL_precondition(! is_degen); return (is_vert); } - /*! - * Check whether the curve is degenerate. + /*! Check whether the curve is degenerate. */ - bool is_degenerate () const - { - return (is_degen); - } + bool is_degenerate() const { return (is_degen); } - /*! - * Check whether the curve is directed lexicographic from left to right + /*! Check whether the curve is directed lexicographic from left to right */ - bool is_directed_right () const - { - return (is_right); - } + bool is_directed_right() const { return (is_right); } - /*! - * Check whether the given point is in the x-range of the object. + /*! Check whether the given point is in the x-range of the object. * \param p The query point. * \return (true) is in the x-range of the segment; (false) if it is not. */ - bool is_in_x_range (const Point_2& p) const + bool is_in_x_range(const Point_2& p) const { - Kernel kernel; - typename Kernel_::Compare_x_2 compare_x = kernel.compare_x_2_object(); - Comparison_result res1; + Kernel kernel; + typename Kernel_::Compare_x_2 compare_x = kernel.compare_x_2_object(); + Comparison_result res1; - if (left_infinite_in_x() == ARR_INTERIOR) - { - if (left_infinite_in_y() != ARR_INTERIOR) - // Compare with some point on the curve. - res1 = compare_x (p, ps); - else - res1 = compare_x (p, left()); + if (left_infinite_in_x() == ARR_INTERIOR) { + // Compare with some point on the curve. + if (left_infinite_in_y() != ARR_INTERIOR) res1 = compare_x(p, ps); + else res1 = compare_x(p, left()); } - else - { + else { // p is obviously to the right. res1 = LARGER; } - if (res1 == SMALLER) - return (false); - else if (res1 == EQUAL) - return (true); + if (res1 == SMALLER) return false; + else if (res1 == EQUAL) return true; - Comparison_result res2; + Comparison_result res2; - if (right_infinite_in_x() == ARR_INTERIOR) - { - if (right_infinite_in_y() != ARR_INTERIOR) - // Compare with some point on the curve. - res2 = compare_x (p, ps); - else - res2 = compare_x (p, right()); + if (right_infinite_in_x() == ARR_INTERIOR) { + // Compare with some point on the curve. + if (right_infinite_in_y() != ARR_INTERIOR) res2 = compare_x(p, ps); + else res2 = compare_x(p, right()); } - else - { + else { // p is obviously to the right. res2 = SMALLER; } @@ -521,68 +445,54 @@ public: return (res2 != LARGER); } - /*! - * Check whether the given point is in the y-range of the object. + /*! Check whether the given point is in the y-range of the object. * \param p The query point. * \pre The object is vertical. * \return (true) is in the y-range of the segment; (false) if it is not. */ - bool is_in_y_range (const Point_2& p) const + bool is_in_y_range(const Point_2& p) const { - CGAL_precondition (is_vertical()); + CGAL_precondition(is_vertical()); - Kernel kernel; - typename Kernel_::Compare_y_2 compare_y = kernel.compare_y_2_object(); - Arr_parameter_space inf = left_infinite_in_y(); - Comparison_result res1; + Kernel kernel; + typename Kernel_::Compare_y_2 compare_y = kernel.compare_y_2_object(); + Arr_parameter_space inf = left_infinite_in_y(); + Comparison_result res1; - CGAL_assertion (inf != ARR_TOP_BOUNDARY); - if (inf == ARR_INTERIOR) - res1 = compare_y (p, left()); - else - res1 = LARGER; // p is obviously above. + CGAL_assertion(inf != ARR_TOP_BOUNDARY); + if (inf == ARR_INTERIOR) res1 = compare_y (p, left()); + else res1 = LARGER; // p is obviously above. - if (res1 == SMALLER) - return (false); - else if (res1 == EQUAL) - return (true); + if (res1 == SMALLER) return false; + else if (res1 == EQUAL) return true; - Comparison_result res2; + Comparison_result res2; inf = right_infinite_in_y(); - CGAL_assertion (inf != ARR_BOTTOM_BOUNDARY); - if (inf == ARR_INTERIOR) - res2 = compare_y (p, right()); - else - res2 = SMALLER; // p is obviously below. + CGAL_assertion(inf != ARR_BOTTOM_BOUNDARY); + if (inf == ARR_INTERIOR) res2 = compare_y(p, right()); + else res2 = SMALLER; // p is obviously below. return (res2 != LARGER); } private: - - /*! - * Determine if the supporting line has a positive slope. + /*! Determine if the supporting line has a positive slope. */ - bool _has_positive_slope () const + bool _has_positive_slope() const { - if (is_vert) - return (true); - - if (is_horiz) - return (false); + if (is_vert) return true; + if (is_horiz) return false; // Construct a horizontal line and compare its slope the that of l. - Kernel kernel; - Line_2 l_horiz = kernel.construct_line_2_object() (Point_2 (0, 0), - Point_2 (1, 0)); - - return (kernel.compare_slope_2_object() (l, l_horiz) == LARGER); + Kernel kernel; + Line_2 l_horiz = + kernel.construct_line_2_object()(Point_2(0, 0), Point_2(1, 0)); + return (kernel.compare_slope_2_object()(l, l_horiz) == LARGER); } }; public: - // Traits objects typedef typename Kernel::Point_2 Point_2; typedef Arr_linear_object_2 X_monotone_curve_2; @@ -590,12 +500,9 @@ public: typedef unsigned int Multiplicity; public: - - /*! - * Default constructor. + /*! Default constructor. */ - Arr_linear_traits_2 () - {} + Arr_linear_traits_2() {} /// \name Basic functor definitions. //@{ @@ -606,7 +513,7 @@ public: typedef Arr_linear_traits_2 Traits; /*! The traits (in case it has state) */ - const Traits * m_traits; + const Traits& m_traits; /*! Constructor * \param traits the traits (in case it has state) @@ -614,32 +521,28 @@ public: * obtaining function, which is a member of the nesting class, * constructing it. */ - Compare_x_2(const Traits * traits) : m_traits(traits) {} + Compare_x_2(const Traits& traits) : m_traits(traits) {} //! Allow its functor obtaining function calling the private constructor. friend class Arr_linear_traits_2; public: - /*! - * Compare the x-coordinates of two points. + /*! Compare the x-coordinates of two points. * \param p1 The first point. * \param p2 The second point. * \return LARGER if x(p1) > x(p2); * SMALLER if x(p1) < x(p2); * EQUAL if x(p1) = x(p2). */ - Comparison_result operator() (const Point_2& p1, const Point_2& p2) const + Comparison_result operator()(const Point_2& p1, const Point_2& p2) const { - const Kernel * kernel = m_traits; - return (kernel->compare_x_2_object()(p1, p2)); + const Kernel& kernel = m_traits; + return (kernel.compare_x_2_object()(p1, p2)); } }; /*! Obtain a Compare_x_2 functor. */ - Compare_x_2 compare_x_2_object () const - { - return Compare_x_2(this); - } + Compare_x_2 compare_x_2_object() const { return Compare_x_2(*this); } /*! A functor that compares the he endpoints of an $x$-monotone curve. */ class Compare_endpoints_xy_2{ @@ -650,21 +553,19 @@ public: * \return SMALLER if the curve is directed right; * LARGER if the curve is directed left. */ - Comparison_result operator() (const X_monotone_curve_2& xcv) const + Comparison_result operator()(const X_monotone_curve_2& xcv) const { return (xcv.is_directed_right()) ? (SMALLER) : (LARGER); } }; Compare_endpoints_xy_2 compare_endpoints_xy_2_object() const - { - return Compare_endpoints_xy_2(); - } + { return Compare_endpoints_xy_2(); } - class Trim_2{ + class Trim_2 { protected: typedef Arr_linear_traits_2 Traits; /*! The traits (in case it has state) */ - const Traits* m_traits; + const Traits& m_traits; /*! Constructor * \param traits the traits (in case it has state) @@ -672,25 +573,25 @@ public: * obtaining function, which is a member of the nesting class, * constructing it. */ - Trim_2(const Traits * traits) : m_traits(traits) {} + Trim_2(const Traits& traits) : m_traits(traits) {} //! Allow its functor obtaining function calling the private constructor. friend class Arr_linear_traits_2; public: - X_monotone_curve_2 operator()( const X_monotone_curve_2 xcv, - const Point_2 src, - const Point_2 tgt ) + X_monotone_curve_2 operator()(const X_monotone_curve_2 xcv, + const Point_2 src, + const Point_2 tgt) { /* * "Line_segment, line, and ray" will become line segments * when trimmed. - */ + */ Equal_2 equal = Equal_2(); - Compare_y_at_x_2 compare_y_at_x = m_traits->compare_y_at_x_2_object(); + Compare_y_at_x_2 compare_y_at_x = m_traits.compare_y_at_x_2_object(); //preconditions - //check if source and taget are two distinct points and they lie on the line. + //check if source and taget are distinct points and they lie on the line. CGAL_precondition(!equal(src, tgt)); CGAL_precondition(compare_y_at_x(src, xcv) == EQUAL); CGAL_precondition(compare_y_at_x(tgt, xcv) == EQUAL); @@ -698,33 +599,24 @@ public: //create trimmed line_segment X_monotone_curve_2 trimmed_segment; - if( xcv.is_directed_right() && tgt.x() < src.x() ) + if (xcv.is_directed_right() && (tgt.x() < src.x())) trimmed_segment = Segment_2(tgt, src); - - - else if( !xcv.is_directed_right() && tgt.x() > src.x()) + else if (! xcv.is_directed_right() && (tgt.x() > src.x())) trimmed_segment = Segment_2(tgt, src); - - else - trimmed_segment = Segment_2(src, tgt); + else trimmed_segment = Segment_2(src, tgt); return trimmed_segment; } - }; - Trim_2 trim_2_object() const - { - return Trim_2(this); - } - + Trim_2 trim_2_object() const { return Trim_2(*this); } class Construct_opposite_2{ protected: typedef Arr_linear_traits_2 Traits; /*! The traits (in case it has state) */ - const Traits* m_traits; + const Traits& m_traits; /*! Constructor * \param traits the traits (in case it has state) @@ -732,142 +624,111 @@ public: * obtaining function, which is a member of the nesting class, * constructing it. */ - Construct_opposite_2(const Traits * traits) : m_traits(traits) {} + Construct_opposite_2(const Traits& traits) : m_traits(traits) {} //! Allow its functor obtaining function calling the private constructor. friend class Arr_linear_traits_2; public: - - X_monotone_curve_2 operator()(const X_monotone_curve_2& xcv)const + X_monotone_curve_2 operator()(const X_monotone_curve_2& xcv) const { - CGAL_precondition (! xcv.is_degenerate()); + CGAL_precondition(! xcv.is_degenerate()); X_monotone_curve_2 opp_xcv; - if( xcv.is_segment() ) - { - opp_xcv = Segment_2(xcv.target(), xcv.source()); - } - - if( xcv.is_line() ) - { - opp_xcv = Line_2(xcv.get_pt(), xcv.get_ps()); - } - - if( xcv.is_ray() ) - { + if (xcv.is_segment()) opp_xcv = Segment_2(xcv.target(), xcv.source()); + if (xcv.is_line()) opp_xcv = Line_2(xcv.get_pt(), xcv.get_ps()); + if (xcv.is_ray()) { Point_2 opp_tgt = Point_2( -(xcv.get_pt().x()), -(xcv.get_pt().y())); opp_xcv = Ray_2( xcv.source(), opp_tgt); } return opp_xcv; - } - }; /*! Get a Construct_opposite_2 functor object. */ Construct_opposite_2 construct_opposite_2_object() const - { - return Construct_opposite_2(this); - } + { return Construct_opposite_2(*this); } /*! A functor that compares the x-coordinates of two points */ class Compare_xy_2 { public: - /*! - * Compare two points lexigoraphically: by x, then by y. + /*! Compare two points lexigoraphically: by x, then by y. * \param p1 The first point. * \param p2 The second point. * \return LARGER if x(p1) > x(p2), or if x(p1) = x(p2) and y(p1) > y(p2); * SMALLER if x(p1) < x(p2), or if x(p1) = x(p2) and y(p1) < y(p2); * EQUAL if the two points are equal. */ - Comparison_result operator() (const Point_2& p1, const Point_2& p2) const + Comparison_result operator()(const Point_2& p1, const Point_2& p2) const { - Kernel kernel; + Kernel kernel; return (kernel.compare_xy_2_object()(p1, p2)); } }; /*! Obtain a Compare_xy_2 functor object. */ - Compare_xy_2 compare_xy_2_object () const - { - return Compare_xy_2(); - } + Compare_xy_2 compare_xy_2_object() const { return Compare_xy_2(); } /*! A functor that obtains the left endpoint of a segment or a ray. */ - class Construct_min_vertex_2 - { + class Construct_min_vertex_2 { public: - /*! - * Get the left endpoint of the x-monotone curve (segment). + /*! Obtain the left endpoint of the x-monotone curve (segment). * \param cv The curve. * \pre The left end of cv is a valid (bounded) point. * \return The left endpoint. */ - const Point_2& operator() (const X_monotone_curve_2& cv) const + const Point_2& operator()(const X_monotone_curve_2& cv) const { - CGAL_precondition (! cv.is_degenerate()); - CGAL_precondition (cv.has_left()); + CGAL_precondition(! cv.is_degenerate()); + CGAL_precondition(cv.has_left()); return (cv.left()); } }; /*! Obtain a Construct_min_vertex_2 functor object. */ - Construct_min_vertex_2 construct_min_vertex_2_object () const - { - return Construct_min_vertex_2(); - } + Construct_min_vertex_2 construct_min_vertex_2_object() const + { return Construct_min_vertex_2(); } /*! A functor that obtains the right endpoint of a segment or a ray. */ - class Construct_max_vertex_2 - { + class Construct_max_vertex_2 { public: - /*! - * Get the right endpoint of the x-monotone curve (segment). + /*! Obtain the right endpoint of the x-monotone curve (segment). * \param cv The curve. * \pre The right end of cv is a valid (bounded) point. * \return The right endpoint. */ - const Point_2& operator() (const X_monotone_curve_2& cv) const + const Point_2& operator()(const X_monotone_curve_2& cv) const { - CGAL_precondition (! cv.is_degenerate()); - CGAL_precondition (cv.has_right()); + CGAL_precondition(! cv.is_degenerate()); + CGAL_precondition(cv.has_right()); return (cv.right()); } }; /*! Obtain a Construct_max_vertex_2 functor object. */ - Construct_max_vertex_2 construct_max_vertex_2_object () const - { - return Construct_max_vertex_2(); - } + Construct_max_vertex_2 construct_max_vertex_2_object() const + { return Construct_max_vertex_2(); } /*! A functor that checks whether a given linear curve is vertical. */ - class Is_vertical_2 - { + class Is_vertical_2 { public: - /*! - * Check whether the given x-monotone curve is a vertical segment. + /*! Check whether the given x-monotone curve is a vertical segment. * \param cv The curve. * \return (true) if the curve is a vertical segment; (false) otherwise. */ - bool operator() (const X_monotone_curve_2& cv) const + bool operator()(const X_monotone_curve_2& cv) const { - CGAL_precondition (! cv.is_degenerate()); + CGAL_precondition(! cv.is_degenerate()); return (cv.is_vertical()); } }; /*! Obtain an Is_vertical_2 functor object. */ - Is_vertical_2 is_vertical_2_object () const - { - return Is_vertical_2(); - } + Is_vertical_2 is_vertical_2_object() const { return Is_vertical_2(); } /*! A functor that compares the y-coordinates of a point and a line at * the point x-coordinate @@ -877,7 +738,7 @@ public: typedef Arr_linear_traits_2 Traits; /*! The traits (in case it has state) */ - const Traits* m_traits; + const Traits& m_traits; /*! Constructor * \param traits the traits (in case it has state) @@ -885,14 +746,13 @@ public: * obtaining function, which is a member of the nesting class, * constructing it. */ - Compare_y_at_x_2(const Traits * traits) : m_traits(traits) {} + Compare_y_at_x_2(const Traits& traits) : m_traits(traits) {} //! Allow its functor obtaining function calling the private constructor. friend class Arr_linear_traits_2; public: - /*! - * Return the location of the given point with respect to the input curve. + /*! Obtain the location of the given point with respect to the input curve. * \param cv The curve. * \param p The point. * \pre p is in the x-range of cv. @@ -900,42 +760,38 @@ public: * LARGER if y(p) > cv(x(p)), i.e. the point is above the curve; * EQUAL if p lies on the curve. */ - Comparison_result operator() (const Point_2& p, - const X_monotone_curve_2& cv) const + Comparison_result operator()(const Point_2& p, + const X_monotone_curve_2& cv) const { - CGAL_precondition (! cv.is_degenerate()); - CGAL_precondition (cv.is_in_x_range (p)); + CGAL_precondition(! cv.is_degenerate()); + CGAL_precondition(cv.is_in_x_range(p)); - const Kernel * kernel = m_traits; + const Kernel& kernel = m_traits; if (! cv.is_vertical()) // Compare p with the segment's supporting line. - return (kernel->compare_y_at_x_2_object()(p, cv.supp_line())); + return (kernel.compare_y_at_x_2_object()(p, cv.supp_line())); // Compare with the vertical segment's end-points. - typename Kernel::Compare_y_2 compare_y = kernel->compare_y_2_object(); + typename Kernel::Compare_y_2 compare_y = kernel.compare_y_2_object(); const Comparison_result res1 = - cv.has_left() ? compare_y (p, cv.left()) : LARGER; + cv.has_left() ? compare_y(p, cv.left()) : LARGER; const Comparison_result res2 = - cv.has_right() ? compare_y (p, cv.right()) : SMALLER; + cv.has_right() ? compare_y(p, cv.right()) : SMALLER; return (res1 == res2) ? res1 : EQUAL; } }; /*! Obtain a Compare_y_at_x_2 functor object. */ - Compare_y_at_x_2 compare_y_at_x_2_object () const - { - return Compare_y_at_x_2(this); - } + Compare_y_at_x_2 compare_y_at_x_2_object() const + { return Compare_y_at_x_2(*this); } /*! A functor that compares compares the y-coordinates of two linear * curves immediately to the left of their intersection point. */ - class Compare_y_at_x_left_2 - { + class Compare_y_at_x_left_2 { public: - /*! - * Compare the y value of two x-monotone curves immediately to the left + /*! Compare the y value of two x-monotone curves immediately to the left * of their intersection point. * \param cv1 The first curve. * \param cv2 The second curve. @@ -945,31 +801,28 @@ public: * \return The relative position of cv1 with respect to cv2 immdiately to * the left of p: SMALLER, LARGER or EQUAL. */ - Comparison_result operator() (const X_monotone_curve_2& cv1, - const X_monotone_curve_2& cv2, - const Point_2& CGAL_precondition_code(p)) const + Comparison_result operator()(const X_monotone_curve_2& cv1, + const X_monotone_curve_2& cv2, + const Point_2& CGAL_precondition_code(p)) const { - CGAL_precondition (! cv1.is_degenerate()); - CGAL_precondition (! cv2.is_degenerate()); + CGAL_precondition(! cv1.is_degenerate()); + CGAL_precondition(! cv2.is_degenerate()); Kernel kernel; // Make sure that p lies on both curves, and that both are defined to its // left (so their left endpoint is lexicographically smaller than p). - CGAL_precondition_code ( - typename Kernel::Compare_xy_2 compare_xy = kernel.compare_xy_2_object(); - ); + CGAL_precondition_code(auto compare_xy = kernel.compare_xy_2_object()); CGAL_precondition - (Segment_assertions::_assert_is_point_on (p, cv1, - Has_exact_division()) && - Segment_assertions::_assert_is_point_on (p, cv2, - Has_exact_division())); + (Segment_assertions::_assert_is_point_on(p, cv1, + Has_exact_division()) && + Segment_assertions::_assert_is_point_on(p, cv2, Has_exact_division())); - CGAL_precondition ((! cv1.has_left() || - compare_xy(cv1.left(), p) == SMALLER) && - (! cv2.has_left() || - compare_xy(cv2.left(), p) == SMALLER)); + CGAL_precondition((! cv1.has_left() || + compare_xy(cv1.left(), p) == SMALLER) && + (! cv2.has_left() || + compare_xy(cv2.left(), p) == SMALLER)); // Compare the slopes of the two segments to determine thir relative // position immediately to the left of q. @@ -981,19 +834,15 @@ public: }; /*! Obtain a Compare_y_at_x_left_2 functor object. */ - Compare_y_at_x_left_2 compare_y_at_x_left_2_object () const - { - return Compare_y_at_x_left_2(); - } + Compare_y_at_x_left_2 compare_y_at_x_left_2_object() const + { return Compare_y_at_x_left_2(); } /*! A functor that compares compares the y-coordinates of two linear * curves immediately to the right of their intersection point. */ - class Compare_y_at_x_right_2 - { + class Compare_y_at_x_right_2 { public: - /*! - * Compare the y value of two x-monotone curves immediately to the right + /*! Compare the y value of two x-monotone curves immediately to the right * of their intersection point. * \param cv1 The first curve. * \param cv2 The second curve. @@ -1003,31 +852,28 @@ public: * \return The relative position of cv1 with respect to cv2 immdiately to * the right of p: SMALLER, LARGER or EQUAL. */ - Comparison_result operator() (const X_monotone_curve_2& cv1, - const X_monotone_curve_2& cv2, - const Point_2& CGAL_precondition_code(p)) const + Comparison_result operator()(const X_monotone_curve_2& cv1, + const X_monotone_curve_2& cv2, + const Point_2& CGAL_precondition_code(p)) const { - CGAL_precondition (! cv1.is_degenerate()); - CGAL_precondition (! cv2.is_degenerate()); + CGAL_precondition(! cv1.is_degenerate()); + CGAL_precondition(! cv2.is_degenerate()); - Kernel kernel; + Kernel kernel; // Make sure that p lies on both curves, and that both are defined to its // right (so their right endpoint is lexicographically larger than p). - CGAL_precondition_code ( - typename Kernel::Compare_xy_2 compare_xy = kernel.compare_xy_2_object(); - ); + CGAL_precondition_code(auto compare_xy = kernel.compare_xy_2_object()); CGAL_precondition - (Segment_assertions::_assert_is_point_on (p, cv1, - Has_exact_division()) && - Segment_assertions::_assert_is_point_on (p, cv2, - Has_exact_division())); + (Segment_assertions::_assert_is_point_on(p, cv1, + Has_exact_division()) && + Segment_assertions::_assert_is_point_on(p, cv2, Has_exact_division())); - CGAL_precondition ((! cv1.has_right() || - compare_xy(cv1.right(), p) == LARGER) && - (! cv2.has_right() || - compare_xy(cv2.right(), p) == LARGER)); + CGAL_precondition((! cv1.has_right() || + compare_xy(cv1.right(), p) == LARGER) && + (! cv2.has_right() || + compare_xy(cv2.right(), p) == LARGER)); // Compare the slopes of the two segments to determine thir relative // position immediately to the left of q. @@ -1038,47 +884,43 @@ public: }; /*! Obtain a Compare_y_at_x_right_2 functor object. */ - Compare_y_at_x_right_2 compare_y_at_x_right_2_object () const - { - return Compare_y_at_x_right_2(); - } + Compare_y_at_x_right_2 compare_y_at_x_right_2_object() const + { return Compare_y_at_x_right_2(); } /*! A functor that checks whether two points and two linear curves are * identical. */ - class Equal_2 - { + class Equal_2 { public: - /*! - * Check whether the two x-monotone curves are the same (have the same + /*! Check whether the two x-monotone curves are the same (have the same * graph). * \param cv1 The first curve. * \param cv2 The second curve. * \return (true) if the two curves are the same; (false) otherwise. */ - bool operator() (const X_monotone_curve_2& cv1, - const X_monotone_curve_2& cv2) const + bool operator()(const X_monotone_curve_2& cv1, + const X_monotone_curve_2& cv2) const { - CGAL_precondition (! cv1.is_degenerate()); - CGAL_precondition (! cv2.is_degenerate()); + CGAL_precondition(! cv1.is_degenerate()); + CGAL_precondition(! cv2.is_degenerate()); - Kernel kernel; - typename Kernel::Equal_2 equal = kernel.equal_2_object(); + Kernel kernel; + typename Kernel::Equal_2 equal = kernel.equal_2_object(); // Check that the two supporting lines are the same. - if (! equal (cv1.supp_line(), cv2.supp_line()) && - ! equal (cv1.supp_line(), - kernel.construct_opposite_line_2_object()(cv2.supp_line()))) + if (! equal(cv1.supp_line(), cv2.supp_line()) && + ! equal(cv1.supp_line(), + kernel.construct_opposite_line_2_object()(cv2.supp_line()))) { - return (false); + return false; } // Check that either the two left endpoints are at infinity, or they // are bounded and equal. if ((cv1.has_left() != cv2.has_left()) || - (cv1.has_left() && ! equal (cv1.left(), cv2.left()))) + (cv1.has_left() && ! equal(cv1.left(), cv2.left()))) { - return (false); + return false; } // Check that either the two right endpoints are at infinity, or they @@ -1087,24 +929,20 @@ public: (! cv1.has_right() || equal (cv1.right(), cv2.right()))); } - /*! - * Check whether the two points are the same. + /*! Check whether the two points are the same. * \param p1 The first point. * \param p2 The second point. * \return (true) if the two point are the same; (false) otherwise. */ - bool operator() (const Point_2& p1, const Point_2& p2) const + bool operator()(const Point_2& p1, const Point_2& p2) const { - Kernel kernel; + Kernel kernel; return (kernel.equal_2_object()(p1, p2)); } }; /*! Obtain an Equal_2 functor object. */ - Equal_2 equal_2_object () const - { - return Equal_2(); - } + Equal_2 equal_2_object() const { return Equal_2(); } //@} /// \name Functor definitions to handle boundaries @@ -1130,7 +968,7 @@ public: Arr_parameter_space operator()(const X_monotone_curve_2 & xcv, Arr_curve_end ce) const { - CGAL_precondition (! xcv.is_degenerate()); + CGAL_precondition(! xcv.is_degenerate()); return (ce == ARR_MIN_END) ? xcv.left_infinite_in_x() : xcv.right_infinite_in_x(); } @@ -1140,9 +978,7 @@ public: * \return the parameter space at p. */ Arr_parameter_space operator()(const Point_2 ) const - { - return ARR_INTERIOR; - } + { return ARR_INTERIOR; } }; /*! Obtain a Parameter_space_in_x_2 function object */ @@ -1185,9 +1021,7 @@ public: * \return the parameter space at p. */ Arr_parameter_space operator()(const Point_2 ) const - { - return ARR_INTERIOR; - } + { return ARR_INTERIOR; } }; /*! Obtain a Parameter_space_in_y_2 function object */ @@ -1202,7 +1036,7 @@ public: typedef Arr_linear_traits_2 Traits; /*! The traits (in case it has state) */ - const Traits* m_traits; + const Traits& m_traits; /*! Constructor * \param traits the traits (in case it has state) @@ -1210,7 +1044,7 @@ public: * obtaining function, which is a member of the nesting class, * constructing it. */ - Compare_x_at_limit_2(const Traits* traits) : m_traits(traits) {} + Compare_x_at_limit_2(const Traits& traits) : m_traits(traits) {} //! Allow its functor obtaining function calling the private constructor. friend class Arr_linear_traits_2; @@ -1238,8 +1072,8 @@ public: CGAL_precondition(! xcv.is_degenerate()); CGAL_precondition(xcv.is_vertical()); - const Kernel* kernel = m_traits; - return (kernel->compare_x_at_y_2_object()(p, xcv.supp_line())); + const Kernel& kernel = m_traits; + return (kernel.compare_x_at_y_2_object()(p, xcv.supp_line())); } /*! Compare the x-limits of 2 arcs ends on the boundary of the @@ -1271,23 +1105,22 @@ public: CGAL_precondition(xcv1.is_vertical()); CGAL_precondition(xcv2.is_vertical()); - const Kernel* kernel = m_traits; - const Point_2 p = kernel->construct_point_2_object()(ORIGIN); - return (kernel->compare_x_at_y_2_object()(p, xcv1.supp_line(), - xcv2.supp_line())); + const Kernel& kernel = m_traits; + const Point_2 p = kernel.construct_point_2_object()(ORIGIN); + return (kernel.compare_x_at_y_2_object()(p, xcv1.supp_line(), + xcv2.supp_line())); } }; /*! Obtain a Compare_x_at_limit_2 function object */ Compare_x_at_limit_2 compare_x_at_limit_2_object() const - { return Compare_x_at_limit_2(this); } + { return Compare_x_at_limit_2(*this); } /*! A function object that compares the x-coordinates of arc ends near the * boundary of the parameter space */ class Compare_x_near_limit_2 { public: - /*! Compare the x-coordinates of 2 arcs ends near the boundary of the * parameter space at y = +/- oo. * \param xcv1 the first arc. @@ -1335,7 +1168,7 @@ public: typedef Arr_linear_traits_2 Traits; /*! The traits (in case it has state) */ - const Traits* m_traits; + const Traits& m_traits; /*! Constructor * \param traits the traits (in case it has state) @@ -1343,7 +1176,7 @@ public: * obtaining function, which is a member of the nesting class, * constructing it. */ - Compare_y_near_boundary_2(const Traits* traits) : m_traits(traits) {} + Compare_y_near_boundary_2(const Traits& traits) : m_traits(traits) {} //! Allow its functor obtaining function calling the private constructor. friend class Arr_linear_traits_2; @@ -1373,17 +1206,17 @@ public: xcv2.right_infinite_in_x() == ARR_RIGHT_BOUNDARY)); // Compare the slopes of the two supporting lines. - const Kernel* kernel = m_traits; + const Kernel& kernel = m_traits; const Comparison_result res_slopes = - kernel->compare_slope_2_object()(xcv1.supp_line(), xcv2.supp_line()); + kernel.compare_slope_2_object()(xcv1.supp_line(), xcv2.supp_line()); if (res_slopes == EQUAL) { // In case the two supporting line are parallel, compare their // relative position at x = 0, which is the same as their position // at infinity. - const Point_2 p = kernel->construct_point_2_object()(ORIGIN); - return (kernel->compare_y_at_x_2_object()(p, xcv1.supp_line(), - xcv2.supp_line())); + const Point_2 p = kernel.construct_point_2_object()(ORIGIN); + return (kernel.compare_y_at_x_2_object()(p, xcv1.supp_line(), + xcv2.supp_line())); } // Flip the slope result if we compare at x = -oo: @@ -1391,21 +1224,18 @@ public: } }; - /*! Obtain a Compare_y_limit_on_boundary_2 function object */ Compare_y_near_boundary_2 compare_y_near_boundary_2_object() const - { return Compare_y_near_boundary_2(this); } + { return Compare_y_near_boundary_2(*this); } //@} /// \name Functor definitions for supporting intersections. //@{ - class Make_x_monotone_2 - { + class Make_x_monotone_2 { public: - /*! - * Cut the given curve into x-monotone subcurves and insert them into the + /*! Cut the given curve into x-monotone subcurves and insert them into the * given output iterator. As segments are always x_monotone, only one * object will be contained in the iterator. * \param cv The curve. @@ -1414,73 +1244,72 @@ public: * essentially the same as the input curve. * \return The past-the-end iterator. */ - template - OutputIterator operator() (const Curve_2& cv, OutputIterator oi) const + template + OutputIterator operator()(const Curve_2& cv, OutputIterator oi) const { // Wrap the curve with an object. - *oi = make_object (cv); - ++oi; - - return (oi); + *oi++ = make_object(cv); + return oi; } }; /*! Obtain a Make_x_monotone_2 functor object. */ - Make_x_monotone_2 make_x_monotone_2_object () const - { - return Make_x_monotone_2(); - } + Make_x_monotone_2 make_x_monotone_2_object() const + { return Make_x_monotone_2(); } - class Split_2 - { + class Split_2 { public: - /*! - * Split a given x-monotone curve at a given point into two sub-curves. + /*! Split a given x-monotone curve at a given point into two sub-curves. * \param cv The curve to split * \param p The split point. * \param c1 Output: The left resulting subcurve (p is its right endpoint). * \param c2 Output: The right resulting subcurve (p is its left endpoint). * \pre p lies on cv but is not one of its end-points. */ - void operator() (const X_monotone_curve_2& cv, const Point_2& p, - X_monotone_curve_2& c1, X_monotone_curve_2& c2) const + void operator()(const X_monotone_curve_2& cv, const Point_2& p, + X_monotone_curve_2& c1, X_monotone_curve_2& c2) const { CGAL_precondition (! cv.is_degenerate()); // Make sure that p lies on the interior of the curve. CGAL_precondition_code ( - Kernel kernel; + Kernel kernel; typename Kernel::Compare_xy_2 compare_xy = kernel.compare_xy_2_object(); ); CGAL_precondition - (Segment_assertions::_assert_is_point_on (p, cv, - Has_exact_division()) && + (Segment_assertions::_assert_is_point_on(p, cv, Has_exact_division()) && (! cv.has_left() || compare_xy(cv.left(), p) == SMALLER) && (! cv.has_right() || compare_xy(cv.right(), p) == LARGER)); // Perform the split. c1 = cv; - c1.set_right (p); + c1.set_right(p); c2 = cv; - c2.set_left (p); - - return; + c2.set_left(p); } }; /*! Obtain a Split_2 functor object. */ - Split_2 split_2_object () const - { - return Split_2(); - } + Split_2 split_2_object() const { return Split_2(); } + + class Intersect_2 { + protected: + typedef Arr_linear_traits_2 Traits; + + /*! The traits (in case it has state) */ + const Traits& m_traits; + + /*! Constructor + * \param traits the traits (in case it has state) + */ + Intersect_2(const Traits& traits) : m_traits(traits) {} + + friend class Arr_linear_traits_2; - class Intersect_2 - { public: - /*! - * Find the intersections of the two given curves and insert them into the + /*! Find the intersections of the two given curves and insert them into the * given output iterator. As two segments may itersect only once, only a * single intersection will be contained in the iterator. * \param cv1 The first curve. @@ -1488,195 +1317,170 @@ public: * \param oi The output iterator. * \return The past-the-end iterator. */ - template - OutputIterator operator() (const X_monotone_curve_2& cv1, - const X_monotone_curve_2& cv2, - OutputIterator oi) const + template + OutputIterator operator()(const X_monotone_curve_2& cv1, + const X_monotone_curve_2& cv2, + OutputIterator oi) const { - CGAL_precondition (! cv1.is_degenerate()); - CGAL_precondition (! cv2.is_degenerate()); + typedef std::pair Intersection_point; + typedef boost::variant + Intersection_result; + + CGAL_precondition(! cv1.is_degenerate()); + CGAL_precondition(! cv2.is_degenerate()); // Intersect the two supporting lines. - Kernel kernel; - CGAL::Object obj = kernel.intersect_2_object()(cv1.supp_line(), - cv2.supp_line()); + const Kernel& kernel = m_traits; + auto res = kernel.intersect_2_object()(cv1.supp_line(), cv2.supp_line()); - if (obj.is_empty()) - { - // The supporting line are parallel lines and do not intersect: - return (oi); - } + // The supporting line are parallel lines and do not intersect: + if (! res) return oi; // Check whether we have a single intersection point. - const Point_2 *ip = object_cast (&obj); - - if (ip != nullptr) - { + const Point_2* ip = boost::get(&*res); + if (ip != nullptr) { // Check whether the intersection point ip lies on both segments. - const bool ip_on_cv1 = cv1.is_vertical() ? cv1.is_in_y_range(*ip) : - cv1.is_in_x_range(*ip); + const bool ip_on_cv1 = cv1.is_vertical() ? + cv1.is_in_y_range(*ip) : cv1.is_in_x_range(*ip); - if (ip_on_cv1) - { - const bool ip_on_cv2 = cv2.is_vertical() ? cv2.is_in_y_range(*ip) : - cv2.is_in_x_range(*ip); + if (ip_on_cv1) { + const bool ip_on_cv2 = cv2.is_vertical() ? + cv2.is_in_y_range(*ip) : cv2.is_in_x_range(*ip); - if (ip_on_cv2) - { + if (ip_on_cv2) { // Create a pair representing the point with its multiplicity, // which is always 1 for line segments. - std::pair ip_mult (*ip, 1); - *oi = make_object (ip_mult); - oi++; + Intersection_point ip_mult(*ip, 1); + *oi++ = Intersection_result(ip_mult); } } - return (oi); + return oi; } // In this case, the two supporting lines overlap. // We start with the entire cv1 curve as the overlapping subcurve, // then clip it to form the true overlapping curve. - typename Kernel::Compare_xy_2 compare_xy = kernel.compare_xy_2_object(); - X_monotone_curve_2 ovlp = cv1; + auto compare_xy = kernel.compare_xy_2_object(); + X_monotone_curve_2 ovlp = cv1; - if (cv2.has_left()) - { + if (cv2.has_left()) { // If the left endpoint of cv2 is to the right of cv1's left endpoint, // clip the overlapping subcurve. - if (! cv1.has_left()) - { + if (! cv1.has_left()) { ovlp.set_left (cv2.left(), false); } - else - { - if (compare_xy (cv1.left(), cv2.left()) == SMALLER) - ovlp.set_left (cv2.left(), false); + else { + if (compare_xy(cv1.left(), cv2.left()) == SMALLER) + ovlp.set_left(cv2.left(), false); } } - if (cv2.has_right()) - { + if (cv2.has_right()) { // If the right endpoint of cv2 is to the left of cv1's right endpoint, // clip the overlapping subcurve. - if (! cv1.has_right()) - { - ovlp.set_right (cv2.right(), false); + if (! cv1.has_right()) { + ovlp.set_right(cv2.right(), false); } - else - { - if (compare_xy (cv1.right(), cv2.right()) == LARGER) - ovlp.set_right (cv2.right(), false); + else { + if (compare_xy(cv1.right(), cv2.right()) == LARGER) + ovlp.set_right(cv2.right(), false); } } // Examine the resulting subcurve. - Comparison_result res = SMALLER; + Comparison_result cmp_res = SMALLER; if (ovlp.has_left() && ovlp.has_right()) - res = compare_xy (ovlp.left(), ovlp.right()); + cmp_res = compare_xy(ovlp.left(), ovlp.right()); - if (res == SMALLER) - { + if (cmp_res == SMALLER) { // We have discovered a true overlapping subcurve: - *oi = make_object (ovlp); - oi++; + *oi++ = Intersection_result(ovlp); } - else if (res == EQUAL) - { + else if (cmp_res == EQUAL) { // The two objects have the same supporting line, but they just share // a common endpoint. Thus we have an intersection point, but we leave // the multiplicity of this point undefined. - std::pair ip_mult (ovlp.left(), 0); - *oi = make_object (ip_mult); - oi++; + Intersection_point ip_mult(ovlp.left(), 0); + *oi++ = Intersection_result(ip_mult); } - return (oi); + return oi; } }; /*! Obtain an Intersect_2 functor object. */ - Intersect_2 intersect_2_object () const - { - return Intersect_2(); - } + Intersect_2 intersect_2_object () const { return Intersect_2(*this); } - class Are_mergeable_2 - { + class Are_mergeable_2 { public: - /*! - * Check whether it is possible to merge two given x-monotone curves. + /*! Check whether it is possible to merge two given x-monotone curves. * \param cv1 The first curve. * \param cv2 The second curve. * \return (true) if the two curves are mergeable - if they are supported * by the same line and share a common endpoint; (false) otherwise. */ - bool operator() (const X_monotone_curve_2& cv1, + bool operator()(const X_monotone_curve_2& cv1, const X_monotone_curve_2& cv2) const { - CGAL_precondition (! cv1.is_degenerate()); - CGAL_precondition (! cv2.is_degenerate()); + CGAL_precondition(! cv1.is_degenerate()); + CGAL_precondition(! cv2.is_degenerate()); - Kernel kernel; - typename Kernel::Equal_2 equal = kernel.equal_2_object(); + Kernel kernel; + typename Kernel::Equal_2 equal = kernel.equal_2_object(); // Check whether the two curves have the same supporting line. - if (! equal (cv1.supp_line(), cv2.supp_line()) && - ! equal (cv1.supp_line(), - kernel.construct_opposite_line_2_object()(cv2.supp_line()))) - return (false); + if (! equal(cv1.supp_line(), cv2.supp_line()) && + ! equal(cv1.supp_line(), + kernel.construct_opposite_line_2_object()(cv2.supp_line()))) + return false; // Check whether the left endpoint of one curve is the right endpoint of the // other. return ((cv1.has_right() && cv2.has_left() && - equal (cv1.right(), cv2.left())) || + equal(cv1.right(), cv2.left())) || (cv2.has_right() && cv1.has_left() && - equal (cv2.right(), cv1.left()))); + equal(cv2.right(), cv1.left()))); } }; /*! Obtain an Are_mergeable_2 functor object. */ - Are_mergeable_2 are_mergeable_2_object () const - { - return Are_mergeable_2(); - } + Are_mergeable_2 are_mergeable_2_object () const { return Are_mergeable_2(); } /*! \class Merge_2 * A functor that merges two x-monotone arcs into one. */ - class Merge_2 - { + class Merge_2 { protected: typedef Arr_linear_traits_2 Traits; /*! The traits (in case it has state) */ - const Traits* m_traits; + const Traits& m_traits; /*! Constructor * \param traits the traits (in case it has state) */ - Merge_2(const Traits* traits) : m_traits(traits) {} + Merge_2(const Traits& traits) : m_traits(traits) {} friend class Arr_linear_traits_2; public: - /*! - * Merge two given x-monotone curves into a single curve (segment). + /*! Merge two given x-monotone curves into a single curve (segment). * \param cv1 The first curve. * \param cv2 The second curve. * \param c Output: The merged curve. * \pre The two curves are mergeable. */ - void operator() (const X_monotone_curve_2& cv1, - const X_monotone_curve_2& cv2, - X_monotone_curve_2& c) const + void operator()(const X_monotone_curve_2& cv1, + const X_monotone_curve_2& cv2, + X_monotone_curve_2& c) const { - CGAL_precondition(m_traits->are_mergeable_2_object()(cv2, cv1)); + CGAL_precondition(m_traits.are_mergeable_2_object()(cv2, cv1)); CGAL_precondition(!cv1.is_degenerate()); CGAL_precondition(!cv2.is_degenerate()); - Equal_2 equal = m_traits->equal_2_object(); + Equal_2 equal = m_traits.equal_2_object(); // Check which curve extends to the right of the other. if (cv1.has_right() && cv2.has_left() && @@ -1685,10 +1489,8 @@ public: // cv2 extends cv1 to the right. c = cv1; - if (cv2.has_right()) - c.set_right(cv2.right()); - else - c.set_right(); // Unbounded endpoint. + if (cv2.has_right()) c.set_right(cv2.right()); + else c.set_right(); // Unbounded endpoint. } else { CGAL_precondition(cv2.has_right() && cv1.has_left() && @@ -1697,87 +1499,67 @@ public: // cv1 extends cv2 to the right. c = cv2; - if (cv1.has_right()) - c.set_right(cv1.right()); - else - c.set_right(); // Unbounded endpoint. + if (cv1.has_right()) c.set_right(cv1.right()); + else c.set_right(); // Unbounded endpoint. } } }; /*! Obtain a Merge_2 functor object. */ - Merge_2 merge_2_object () const { return Merge_2(this); } + Merge_2 merge_2_object() const { return Merge_2(*this); } //@} /// \name Functor definitions for the landmarks point-location strategy. //@{ typedef double Approximate_number_type; - class Approximate_2 - { + class Approximate_2 { public: - - /*! - * Return an approximation of a point coordinate. + /*! Obtain an approximation of a point coordinate. * \param p The exact point. * \param i The coordinate index (either 0 or 1). * \pre i is either 0 or 1. * \return An approximation of p's x-coordinate (if i == 0), or an * approximation of p's y-coordinate (if i == 1). */ - Approximate_number_type operator() (const Point_2& p, - int i) const + Approximate_number_type operator()(const Point_2& p, int i) const { - CGAL_precondition (i == 0 || i == 1); - - if (i == 0) - return (CGAL::to_double(p.x())); - else - return (CGAL::to_double(p.y())); + CGAL_precondition((i == 0) || (i == 1)); + return (i == 0) ? CGAL::to_double(p.x()) : CGAL::to_double(p.y()); } }; /*! Obtain an Approximate_2 functor object. */ - Approximate_2 approximate_2_object () const - { - return Approximate_2(); - } + Approximate_2 approximate_2_object() const { return Approximate_2(); } - class Construct_x_monotone_curve_2 - { + class Construct_x_monotone_curve_2 { public: - - /*! - * Return an x-monotone curve connecting the two given endpoints. + /*! Obtain an x-monotone curve connecting the two given endpoints. * \param p The first point. * \param q The second point. * \pre p and q must not be the same. * \return A segment connecting p and q. */ - X_monotone_curve_2 operator() (const Point_2& p, - const Point_2& q) const + X_monotone_curve_2 operator()(const Point_2& p, const Point_2& q) const { - Kernel kernel; - Segment_2 seg = kernel.construct_segment_2_object() (p, q); + Kernel kernel; + Segment_2 seg = kernel.construct_segment_2_object()(p, q); - return (X_monotone_curve_2 (seg)); + return (X_monotone_curve_2(seg)); } }; /*! Obtain a Construct_x_monotone_curve_2 functor object. */ - Construct_x_monotone_curve_2 construct_x_monotone_curve_2_object () const - { - return Construct_x_monotone_curve_2(); - } + Construct_x_monotone_curve_2 construct_x_monotone_curve_2_object() const + { return Construct_x_monotone_curve_2(); } //@} - }; /*! * \class A representation of a segment, as used by the Arr_segment_traits_2 * traits-class. */ -template +template class Arr_linear_object_2 : public Arr_linear_traits_2::_Linear_object_cached_2 { @@ -1785,7 +1567,6 @@ class Arr_linear_object_2 : Base; public: - typedef Kernel_ Kernel; typedef typename Kernel::Point_2 Point_2; @@ -1794,121 +1575,92 @@ public: typedef typename Kernel::Line_2 Line_2; public: - - /*! - * Default constructor. + /*! Default constructor. */ - Arr_linear_object_2 () : - Base() - {} + Arr_linear_object_2() : Base() {} - /*! - * Constructor from two points. + /*! Constructor from two points. * \param s The source point. * \param t The target point. * \pre The two points must not be the same. */ - Arr_linear_object_2(const Point_2& s, const Point_2& t): - Base(s, t) - {} + Arr_linear_object_2(const Point_2& s, const Point_2& t) : Base(s, t) {} - /*! - * Constructor from a segment. + /*! Constructor from a segment. * \param seg The segment. * \pre The segment is not degenerate. */ - Arr_linear_object_2 (const Segment_2& seg) : - Base (seg) - {} + Arr_linear_object_2(const Segment_2& seg) : Base(seg) {} - /*! - * Constructor from a ray. + /*! Constructor from a ray. * \param ray The segment. * \pre The ray is not degenerate. */ - Arr_linear_object_2 (const Ray_2& ray) : - Base (ray) - {} + Arr_linear_object_2(const Ray_2& ray) : Base(ray) {} - /*! - * Constructor from a line. + /*! Constructor from a line. * \param line The line. * \pre The line is not degenerate. */ - Arr_linear_object_2 (const Line_2& line) : - Base (line) - {} + Arr_linear_object_2(const Line_2& line) : Base(line) {} - /*! - * Check whether the object is actually a segment. + /*! Check whether the object is actually a segment. */ - bool is_segment () const - { - return (! this->is_degen && this->has_source && this->has_target); - } + bool is_segment() const + { return (! this->is_degen && this->has_source && this->has_target); } - /*! - * Cast to a segment. + /*! Cast to a segment. * \pre The linear object is really a segment. */ - Segment_2 segment () const + Segment_2 segment() const { - CGAL_precondition (is_segment()); + CGAL_precondition(is_segment()); - Kernel kernel; - Segment_2 seg = kernel.construct_segment_2_object() (this->ps, this->pt); + Kernel kernel; + Segment_2 seg = kernel.construct_segment_2_object()(this->ps, this->pt); return seg; } - /*! - * Check whether the object is actually a ray. + /*! Check whether the object is actually a ray. */ - bool is_ray () const - { - return (! this->is_degen && (this->has_source != this->has_target)); - } + bool is_ray() const + { return (! this->is_degen && (this->has_source != this->has_target)); } - /*! - * Cast to a ray. + /*! Cast to a ray. * \pre The linear object is really a ray. */ - Ray_2 ray () const + Ray_2 ray() const { - CGAL_precondition (is_ray()); + CGAL_precondition(is_ray()); - Kernel kernel; - Ray_2 ray = (this->has_source) ? - kernel.construct_ray_2_object() (this->ps, this->l) : + Kernel kernel; + Ray_2 ray = (this->has_source) ? + kernel.construct_ray_2_object()(this->ps, this->l) : kernel.construct_ray_2_object() (this->pt, kernel.construct_opposite_line_2_object()(this->l)); return ray; } - /*! - * Check whether the object is actually a line. + /*! Check whether the object is actually a line. */ - bool is_line () const - { - return (! this->is_degen && ! this->has_source && ! this->has_target); - } + bool is_line() const + { return (! this->is_degen && ! this->has_source && ! this->has_target); } - /*! - * Cast to a line. + /*! Cast to a line. * \pre The linear object is really a line. */ - Line_2 line () const + Line_2 line() const { - CGAL_precondition (is_line()); + CGAL_precondition(is_line()); return (this->l); } - /*! - * Get the supporting line. + /*! Get the supporting line. * \pre The object is not a point. */ - const Line_2& supporting_line () const + const Line_2& supporting_line() const { - CGAL_precondition (! this->is_degen); + CGAL_precondition(! this->is_degen); return (this->l); } @@ -1918,37 +1670,30 @@ public: */ const Point_2& source() const { - CGAL_precondition (! is_line()); + CGAL_precondition(! is_line()); - if (this->is_degen) - return (this->ps); // For a point. - - if (this->has_source) - return (this->ps); // For a segment or a ray. - else - return (this->pt); // For a "flipped" ray. + if (this->is_degen) return (this->ps); // For a point. + if (this->has_source) return (this->ps); // For a segment or a ray. + else return (this->pt); // For a "flipped" ray. } - /*! - * Get the target point. + /*! Get the target point. * \pre The object is a point or a segment. */ const Point_2& target() const { - CGAL_precondition (! is_line() && ! is_ray()); - + CGAL_precondition(! is_line() && ! is_ray()); return (this->pt); } - /*! - * Create a bounding box for the linear object. + /*! Create a bounding box for the linear object. */ Bbox_2 bbox() const { CGAL_precondition(this->is_segment()); - Kernel kernel; - Segment_2 seg = kernel.construct_segment_2_object() (this->ps, this->pt); - return (kernel.construct_bbox_2_object() (seg)); + Kernel kernel; + Segment_2 seg = kernel.construct_segment_2_object()(this->ps, this->pt); + return (kernel.construct_bbox_2_object()(seg)); } // Introducing casting operators instead from a curve to @@ -1962,58 +1707,49 @@ public: /*! * Exporter for the segment class used by the traits-class. */ -template -OutputStream& operator<< (OutputStream& os, - const Arr_linear_object_2& lobj) +template +OutputStream& operator<<(OutputStream& os, + const Arr_linear_object_2& lobj) { // Print a letter identifying the object type, then the object itself. - if (lobj.is_segment()) - os << " S " << lobj.segment(); - else if (lobj.is_ray()) - os << " R " << lobj.ray(); - else - os << " L " << lobj.line(); - - return (os); + if (lobj.is_segment()) os << " S " << lobj.segment(); + else if (lobj.is_ray()) os << " R " << lobj.ray(); + else os << " L " << lobj.line(); + return os; } -/*! - * Importer for the segment class used by the traits-class. +/*! Importer for the segment class used by the traits-class. */ -template -InputStream& operator>> (InputStream& is, Arr_linear_object_2& lobj) +template +InputStream& operator>>(InputStream& is, Arr_linear_object_2& lobj) { // Read the object type. - char c; + char c; - do - { + do { is >> c; } while ((c != 'S' && c != 's') && (c != 'R' && c != 'r') && (c != 'L' && c != 'l')); // Read the object accordingly. - if (c == 'S' || c == 's') - { + if (c == 'S' || c == 's') { typename Kernel::Segment_2 seg; is >> seg; lobj = seg; } - else if (c == 'R' || c == 'r') - { - typename Kernel::Ray_2 ray; + else if (c == 'R' || c == 'r') { + typename Kernel::Ray_2 ray; is >> ray; lobj = ray; } - else - { - typename Kernel::Line_2 line; + else { + typename Kernel::Line_2 line; is >> line; lobj = line; } - return (is); + return is; } } //namespace CGAL 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 2e567fc241a..3df642ba1e7 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 @@ -7,9 +7,9 @@ // $Id$ // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial // -// Author(s) : Efi Fogel -// Ron Wein -// (base on old version by: Iddo Hanniel) +// Author(s): Efi Fogel +// Ron Wein +// (base on old version by: Iddo Hanniel) #ifndef CGAL_ARR_NON_CACHING_SEGMENT_TRAITS_H #define CGAL_ARR_NON_CACHING_SEGMENT_TRAITS_H @@ -27,6 +27,8 @@ * functors required by the concept it models. */ +#include + #include #include #include @@ -39,7 +41,7 @@ namespace CGAL { * A model of the ArrangementTraits_2 concept that handles general * line segments. */ -template +template class Arr_non_caching_segment_traits_2 : public Arr_non_caching_segment_basic_traits_2 { @@ -114,12 +116,10 @@ public: /*! \class * A functor for splitting curves into x-monotone pieces. */ - class Make_x_monotone_2 - { + class Make_x_monotone_2 { public: - /*! - * Cut the given segment into x-monotone subcurves and insert them into + /*! 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. @@ -127,54 +127,47 @@ public: * object is a wrapper of an X_monotone_curve_2 object. * \return The past-the-end iterator. */ - template - OutputIterator operator()(const Curve_2 & cv, OutputIterator oi) const + template + OutputIterator operator()(const Curve_2& cv, OutputIterator oi) const { - *oi = make_object (cv); - ++oi; - return (oi); + *oi++ = make_object(cv); + return oi; } }; - /*! Get a Make_x_monotone_2 functor object. */ + /*! Obtain a Make_x_monotone_2 functor object. */ Make_x_monotone_2 make_x_monotone_2_object() const - { - return Make_x_monotone_2(); - } + { return Make_x_monotone_2(); } /*! \class * A functor for splitting a segment into two segements. */ - class Split_2 - { + class Split_2 { typedef Arr_non_caching_segment_traits_2 Self; - public: - /*! - * Split a given x-monotone curve at a given point into two sub-curves. + public: + /*! Split a given x-monotone curve at a given point into two sub-curves. * \param cv The curve to split * \param p The split point. * \param c1 Output: The left resulting subcurve (p is its right endpoint). * \param c2 Output: The right resulting subcurve (p is its left endpoint). * \pre p lies on cv but is not one of its end-points. */ - void operator()(const X_monotone_curve_2 & cv, const Point_2 & p, - X_monotone_curve_2 & c1, X_monotone_curve_2 & c2) const + void operator()(const X_monotone_curve_2& cv, const Point_2& p, + X_monotone_curve_2& c1, X_monotone_curve_2& c2) const { Base base; // Make sure that p lies on the interior of the curve. - CGAL_precondition_code ( - Compare_xy_2 compare_xy = base.compare_xy_2_object(); - ); + CGAL_precondition_code(auto compare_xy = base.compare_xy_2_object()); Construct_min_vertex_2 min_vertex = base.construct_min_vertex_2_object(); Construct_max_vertex_2 max_vertex = base.construct_max_vertex_2_object(); - const Point_2 & left = min_vertex(cv); - const Point_2 & right = max_vertex(cv); + const Point_2& left = min_vertex(cv); + const Point_2& right = max_vertex(cv); CGAL_precondition - (Segment_assertions::_assert_is_point_on(p, cv, Has_exact_division())&& + (Segment_assertions::_assert_is_point_on(p, cv, Has_exact_division()) && compare_xy(left, p) == SMALLER && compare_xy(right, p) == LARGER); @@ -182,31 +175,36 @@ public: base.construct_segment_2_object(); Self self; - if(self.compare_endpoints_xy_2_object()(cv) == SMALLER) - { + if (self.compare_endpoints_xy_2_object()(cv) == SMALLER) { c1 = construct_segment(left, p); c2 = construct_segment(p, right); } - else - { + else { c1 = construct_segment(p, left); c2 = construct_segment(right, p); } } }; - /*! Get a Split_2 functor object. */ - Split_2 split_2_object() const - { - return Split_2(); - } + /*! Obtain a Split_2 functor object. */ + Split_2 split_2_object() const { return Split_2(); } /*! \class * A functor for computing intersections. */ - class Intersect_2 - { - typedef Arr_non_caching_segment_traits_2 Self; + class Intersect_2 { + protected: + typedef Arr_non_caching_segment_traits_2 Traits; + + /*! The traits (in case it has state) */ + const Traits& m_traits; + + /*! Constructor + * \param traits the traits (in case it has state) + */ + Intersect_2(const Traits& traits) : m_traits(traits) {} + + friend class Arr_non_caching_segment_traits_2; public: /*! Find the intersections of the two given segments and insert them into @@ -217,67 +215,56 @@ public: * \param oi The output iterator. * \return The past-the-end iterator. */ - template - OutputIterator operator()(const X_monotone_curve_2 & cv1, - const X_monotone_curve_2 & cv2, + template + OutputIterator operator()(const X_monotone_curve_2& cv1, + const X_monotone_curve_2& cv2, OutputIterator oi) const { - Base base; - Object res = base.intersect_2_object()(cv1, cv2); + typedef std::pair Intersection_point; + typedef boost::variant + Intersection_result; + + const Kernel& kernel = m_traits; + auto res = kernel.intersect_2_object()(cv1, cv2); // There is no intersection: - if (res.is_empty()) - return (oi); + if (! res) return oi; // Chack if the intersection is a point: - const Point_2 *ip; - - if ((ip = object_cast (&res)) != nullptr) - { + const Point_2* p_p = boost::get(&*res); + if (p_p != nullptr) { // Create a pair representing the point with its multiplicity, // which is always 1 for line segments for all practical purposes. // If the two segments intersect at their endpoints, then the // multiplicity is undefined, but we deliberately ignore it for // efficieny reasons. - std::pair ip_mult(*ip, 1); - *oi = make_object (ip_mult); - ++oi; + *oi++ = Intersection_result(Intersection_point(*p_p, 1)); + return oi; } - else - { - // The intersection is a segment. - const X_monotone_curve_2 *ov = object_cast(&res); - CGAL_assertion (ov != nullptr); + // The intersection is a segment. + const X_monotone_curve_2* cv_p = boost::get(&*res); + CGAL_assertion(cv_p != nullptr); - Self self; - Comparison_result cmp1 = self.compare_endpoints_xy_2_object()(cv1); - Comparison_result cmp2 = self.compare_endpoints_xy_2_object()(cv2); + Comparison_result cmp1 = m_traits.compare_endpoints_xy_2_object()(cv1); + Comparison_result cmp2 = m_traits.compare_endpoints_xy_2_object()(cv2); - if(cmp1 == cmp2) - { - // cv1 and cv2 have the same directions, maintain this direction - // in the overlap segment - if(self.compare_endpoints_xy_2_object()(*ov) != cmp1) - { - Kernel k; - res = make_object(k.construct_opposite_segment_2_object()(*ov)); - } + if (cmp1 == cmp2) { + // cv1 and cv2 have the same directions, maintain this direction + // in the overlap segment + if (m_traits.compare_endpoints_xy_2_object()(*cv_p) != cmp1) { + auto ctr_opposite = kernel.construct_opposite_segment_2_object(); + *oi++ = Intersection_result(ctr_opposite(*cv_p)); + return oi; } - - *oi = res; - ++oi; } - - return (oi); + *oi++ = Intersection_result(*cv_p); + return oi; } }; - /*! Get an Intersect_2 functor object. */ - Intersect_2 intersect_2_object() const - { - return Intersect_2(); - } + /*! Obtain an Intersect_2 functor object. */ + Intersect_2 intersect_2_object() const { return Intersect_2(*this); } /*! \class * A functor for testing whether two segments are mergeable. @@ -297,24 +284,22 @@ public: friend class Arr_non_caching_segment_traits_2; public: - - /*! - * Check whether it is possible to merge two given x-monotone curves. + /*! Check whether it is possible to merge two given x-monotone curves. * \param cv1 The first curve. * \param cv2 The second curve. * \return (true) if the two curves are mergeable, that is, if they are * supported by the same line; (false) otherwise. * \pre cv1 and cv2 share a common endpoint. */ - bool operator()(const X_monotone_curve_2 & cv1, - const X_monotone_curve_2 & cv2) const + bool operator()(const X_monotone_curve_2& cv1, + const X_monotone_curve_2& cv2) const { const Base* base = m_traits; Equal_2 equal = base->equal_2_object(); Construct_min_vertex_2 min_vertex = base->construct_min_vertex_2_object(); Construct_max_vertex_2 max_vertex = base->construct_max_vertex_2_object(); - if (!equal(max_vertex(cv1), min_vertex(cv2)) && - !equal(max_vertex(cv2), min_vertex(cv1))) + if (! equal(max_vertex(cv1), min_vertex(cv2)) && + ! equal(max_vertex(cv2), min_vertex(cv1))) return false; // Check if the two curves have the same supporting line. @@ -344,16 +329,15 @@ public: friend class Arr_non_caching_segment_traits_2; public: - /*! - * Merge two given segments into a single segment. + /*! Merge two given segments into a single segment. * \param cv1 The first curve. * \param cv2 The second curve. * \param c Output: The merged curve. * \pre The two curves are mergeable. */ - void operator()(const X_monotone_curve_2 & cv1, - const X_monotone_curve_2 & cv2, - X_monotone_curve_2 & c) const + void operator()(const X_monotone_curve_2& cv1, + const X_monotone_curve_2& cv2, + X_monotone_curve_2& c) const { CGAL_precondition(m_traits->are_mergeable_2_object()(cv2, cv1)); @@ -390,12 +374,9 @@ public: /*! Obtain a Construct_opposite_2 functor object */ Construct_opposite_2 construct_opposite_2_object() const - { - return Construct_opposite_2(); - } + { return Construct_opposite_2(); } - class Compare_endpoints_xy_2 - { + class Compare_endpoints_xy_2 { public: /*! * Compare the two endpoints of a given curve lexigoraphically. @@ -417,9 +398,7 @@ public: /*! Obtain a Compare_endpoints_xy_2 functor object */ Compare_endpoints_xy_2 compare_endpoints_xy_2_object() const - { - return Compare_endpoints_xy_2(); - } + { return Compare_endpoints_xy_2(); } //@} }; diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_X_trapezoid.h b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_X_trapezoid.h index a52f91db9d2..e7202ffe935 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_X_trapezoid.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_X_trapezoid.h @@ -142,7 +142,7 @@ public: private: - Trpz_parameter_space* ptr() const { return (Trpz_parameter_space*)(PTR.p); } + Trpz_parameter_space* ptr() const { return (Trpz_parameter_space*)(PTR); } #ifndef CGAL_TD_DEBUG @@ -323,7 +323,7 @@ public: { //define the initial trapezoid: left, right, btm, top are at infinity. // its type is TD_TRAPEZOID ,it is on all boundaries, and has no neighbours - PTR.p = new Trpz_parameter_space + PTR = new Trpz_parameter_space (Traits::vtx_at_left_infinity(), Traits::vtx_at_right_infinity(), Traits::he_at_bottom_infinity(), @@ -353,7 +353,7 @@ public: else //tp == TD_VERTEX type_flag |= CGAL_TD_VERTEX; - PTR.p = new Trpz_parameter_space + PTR = new Trpz_parameter_space (l, r, b, t, type_flag | boundness_flag, lb, lt, rb, rt); m_dag_node = node; } @@ -370,7 +370,7 @@ public: Self* rb = 0, Self* rt = 0, Dag_node* node = 0) { - PTR.p = new Trpz_parameter_space + PTR = new Trpz_parameter_space (l ? *l : Traits::vtx_at_left_infinity(), r ? *r : Traits::vtx_at_right_infinity(), b ? *b : Traits::he_at_bottom_infinity(), @@ -436,7 +436,7 @@ public: /*! Access the trapezoid id (PTR). */ CGAL_TD_INLINE unsigned long id() const { - return (unsigned long) PTR.p; + return (unsigned long) PTR; } /*! Access trapezoid left. */ diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_active_edge.h b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_active_edge.h index 2cdeee6bca5..61259f33547 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_active_edge.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_active_edge.h @@ -135,7 +135,7 @@ public: private: - Data* ptr() const { return (Data*)(PTR.p); } + Data* ptr() const { return (Data*)(PTR); } #ifndef CGAL_TD_DEBUG @@ -194,7 +194,7 @@ public: Td_active_edge () { - PTR.p = new Data + PTR = new Data (Traits::empty_he_handle(), Td_map_item(0), nullptr); //m_dag_node = nullptr; } @@ -204,7 +204,7 @@ public: boost::optional next = boost::none) { - PTR.p = new Data(he, (next) ? *next : Td_map_item(0), node); + PTR = new Data(he, (next) ? *next : Td_map_item(0), node); //m_dag_node = node; } @@ -261,7 +261,7 @@ public: /*! Access the trapezoid id (PTR). */ CGAL_TD_INLINE unsigned long id() const { - return (unsigned long) PTR.p; + return (unsigned long) PTR; } diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_active_fictitious_vertex.h b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_active_fictitious_vertex.h index 6bfb3d5e6f2..b75de1b9d97 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_active_fictitious_vertex.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_active_fictitious_vertex.h @@ -129,7 +129,7 @@ public: }; private: - Data* ptr() const { return (Data*)(PTR.p); } + Data* ptr() const { return (Data*)(PTR); } Curve_end vtx_to_ce(Vertex_const_handle v) const { @@ -180,14 +180,14 @@ public: Td_active_fictitious_vertex() { - PTR.p = new Data(Traits::empty_vtx_handle(), Traits::empty_he_handle(), nullptr); + PTR = new Data(Traits::empty_vtx_handle(), Traits::empty_he_handle(), nullptr); } /*! Constructor given Vertex & Halfedge handles. */ Td_active_fictitious_vertex(Vertex_const_handle v, Halfedge_const_handle cw_he, Dag_node* node = 0) - { PTR.p = new Data(v, cw_he, node); } + { PTR = new Data(v, cw_he, node); } /*! Copy constructor. */ @@ -224,7 +224,7 @@ public: inline const Self& self() const { return *this; } /*! Access the trapezoid id (PTR). */ - inline unsigned long id() const { return (unsigned long) PTR.p; } + inline unsigned long id() const { return (unsigned long) PTR; } /*! Access trapezoid left. * filters out the infinite case which returns predefined dummy values diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_active_trapezoid.h b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_active_trapezoid.h index 2b565adba74..8b92b739626 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_active_trapezoid.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_active_trapezoid.h @@ -144,7 +144,7 @@ public: private: - Data* ptr() const { return (Data*)(PTR.p); } + Data* ptr() const { return (Data*)(PTR); } public: @@ -255,7 +255,7 @@ private: { //define the initial trapezoid: left, right, btm, top are at infinity. // has no neighbours - PTR.p = new Data + PTR = new Data (Traits::empty_vtx_handle(), Traits::empty_vtx_handle(), Traits::empty_he_handle(), @@ -274,7 +274,7 @@ private: boost::optional rt = boost::none, Dag_node* node = 0) { - PTR.p = new Data (l, r, b, t, (lb) ? *lb : Td_map_item(0), (lt) ? *lt : Td_map_item(0), + PTR = new Data (l, r, b, t, (lb) ? *lb : Td_map_item(0), (lt) ? *lt : Td_map_item(0), (rb) ? *rb : Td_map_item(0), (rt) ? *rt : Td_map_item(0), node); //m_dag_node = node; } @@ -332,7 +332,7 @@ private: /*! Access the trapezoid id (PTR). */ inline unsigned long id() const { - return (unsigned long) PTR.p; + return (unsigned long) PTR; } /*! Access trapezoid left. diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_active_vertex.h b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_active_vertex.h index de4000ebfd9..3b3e86aa0c6 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_active_vertex.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_active_vertex.h @@ -134,7 +134,7 @@ public: }; private: - Data* ptr() const { return (Data*)(PTR.p); } + Data* ptr() const { return (Data*)(PTR); } Curve_end vtx_to_ce(Vertex_const_handle v) const { @@ -184,14 +184,14 @@ public: Td_active_vertex() { - PTR.p = new Data(Traits::empty_vtx_handle(), Traits::empty_he_handle(), nullptr); + PTR = new Data(Traits::empty_vtx_handle(), Traits::empty_he_handle(), nullptr); } /*! Constructor given Vertex & Halfedge handles. */ Td_active_vertex(Vertex_const_handle v, Halfedge_const_handle cw_he, Dag_node* node = 0) - { PTR.p = new Data(v, cw_he, node); } + { PTR = new Data(v, cw_he, node); } /*! Copy constructor. */ @@ -228,7 +228,7 @@ public: inline const Self& self() const { return *this; } /*! Access the trapezoid id (PTR). */ - inline unsigned long id() const { return (unsigned long) PTR.p; } + inline unsigned long id() const { return (unsigned long) PTR; } inline Vertex_const_handle vertex() const { return ptr()->v; } diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_dag.h b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_dag.h index e5eee91e724..f8a47536c85 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_dag.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_dag.h @@ -41,14 +41,14 @@ public: //iddo (for CC-7.2) maybe protected? typedef const T & const_reference; protected: - void init() { PTR.p = 0; } + void init() { PTR = 0; } public: Td_dag_base() {init();} Td_dag_base(const Td_dag_base & x) : Handle(x) {} Td_dag_base & operator=(const Td_dag_base & x) {Handle::operator=(x); return *this; } - bool operator!() const { return PTR.p == 0; } + bool operator!() const { return PTR == 0; } }; template @@ -96,9 +96,9 @@ public: Td_dag(){} Td_dag(const Td_dag_handle& dag):Td_dag_handle(dag){} Td_dag(const Self& dag):Td_dag_handle(dag){} - Td_dag(const T& rootValue){PTR.p = new node(rootValue);} + Td_dag(const T& rootValue){PTR = new node(rootValue);} Td_dag(const T& rootValue, const Self& left, const Self& right) - {PTR.p = new node(rootValue, left, right); rebalance_depth();} + {PTR = new node(rootValue, left, right); rebalance_depth();} ~Td_dag(){} /* --------information retrieval -------*/ @@ -145,7 +145,7 @@ public: } bool operator==(const Self& b) const { - return PTR.p==b.PTR.p; + return PTR==b.PTR; } bool operator!=(const Self& b) const { @@ -189,7 +189,7 @@ public: // detach left son,redirect to dummy set_left(dummy); // set left son pointer to 0 - ptr()->leftPtr.PTR.p=0; + ptr()->leftPtr.PTR=0; // delete dummy Td_dag delete dummy.ptr(); } @@ -204,7 +204,7 @@ public: // detach right son,redirect to dummy set_right(dummy); // set right son pointer to 0 - ptr()->rightPtr.PTR.p=0; + ptr()->rightPtr.PTR=0; // delete dummy Td_dag delete dummy.ptr(); } @@ -371,7 +371,7 @@ protected: } #endif private: - node* ptr() const {return (node*)PTR.p;} + node* ptr() const {return (node*)PTR;} }; template @@ -441,7 +441,7 @@ template std::ostream& operator<<(std::ostream& out, tech notes: The code is Handle designed. left(),right() are designed to cope with Handle(Handle& x) - precondition x.PTR.p!=0 + precondition x.PTR!=0 operator=() performs shallow copy operator*() returns data type output is done as a binary tree. diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_dag_node.h b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_dag_node.h index bbf45831519..ec4a961d8f1 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_dag_node.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_dag_node.h @@ -39,7 +39,7 @@ template class Td_dag_node_base : public Handle { protected: - void init() { PTR.p = 0; } //MICHAL: I think it is not used - so need to be removed + void init() { PTR = 0; } //MICHAL: I think it is not used - so need to be removed public: //c'tors @@ -57,12 +57,12 @@ public: return *this; } - //bool operator!() const { return PTR.p == 0; } //MICHAL: maybe use ptr(), and also can change to is_null or something similar - bool is_null() const { return PTR.p == 0; } - Rep * ptr() const { return (Rep*) PTR.p; } + //bool operator!() const { return PTR == 0; } //MICHAL: maybe use ptr(), and also can change to is_null or something similar + bool is_null() const { return PTR == 0; } + Rep * ptr() const { return (Rep*) PTR; } protected: - //Rep *& ptr() { return (Rep*) PTR.p; } - void set_ptr(Rep* rep) { PTR.p = rep; } + //Rep *& ptr() { return (Rep*) PTR; } + void set_ptr(Rep* rep) { PTR = rep; } }; @@ -94,7 +94,7 @@ public: #ifndef CGAL_CFG_USING_BASE_MEMBER_BUG_2 public: - //using Td_dag_node_handle::PTR.p; + //using Td_dag_node_handle::PTR; //using Td_dag_node_handle::operator!; #endif //CGAL_CFG_USING_BASE_MEMBER_BUG_2 @@ -549,7 +549,7 @@ protected: private: - Node* node() const { return (Node*)Base::PTR.p; } + Node* node() const { return (Node*)Base::PTR; } }; @@ -629,7 +629,7 @@ std::ostream& operator<< (std::ostream& out, tech notes: The code is Handle designed. left_child(),right_child() are designed to cope with Handle(Handle& x) - precondition x.PTR.p!=0 + precondition x.PTR!=0 operator=() performs shallow copy operator*() returns data type output is done as a binary tree. diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_inactive_edge.h b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_inactive_edge.h index 0d85f93f148..bb57f7c6d1c 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_inactive_edge.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_inactive_edge.h @@ -128,7 +128,7 @@ public: private: - Data* ptr() const { return (Data*)(PTR.p); } + Data* ptr() const { return (Data*)(PTR); } #ifndef CGAL_TD_DEBUG @@ -161,7 +161,7 @@ public: /*! Constructor given Vertex & Halfedge handles. */ Td_inactive_edge (boost::shared_ptr& cv, Dag_node* node = nullptr) { - PTR.p = new Data(cv,node); + PTR = new Data(cv,node); } /*! Copy constructor. */ @@ -215,7 +215,7 @@ public: /*! Access the trapezoid id (PTR). */ inline unsigned long id() const { - return (unsigned long) PTR.p; + return (unsigned long) PTR; } inline X_monotone_curve_2& curve() const diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_inactive_fictitious_vertex.h b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_inactive_fictitious_vertex.h index cf2d75d79ec..03ca8d563c7 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_inactive_fictitious_vertex.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_inactive_fictitious_vertex.h @@ -133,7 +133,7 @@ public: private: - Data* ptr() const { return (Data*)(PTR.p); } + Data* ptr() const { return (Data*)(PTR); } Curve_end vtx_to_ce(Vertex_const_handle v) const { @@ -185,7 +185,7 @@ public: { Curve_end v_ce(vtx_to_ce(v_before_rem)); - PTR.p = new Data( v_ce.cv(), v_ce.ce(), node); + PTR = new Data( v_ce.cv(), v_ce.ce(), node); } @@ -241,7 +241,7 @@ public: /*! Access the trapezoid id (PTR). */ inline unsigned long id() const { - return (unsigned long) PTR.p; + return (unsigned long) PTR; } diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_inactive_vertex.h b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_inactive_vertex.h index 0c42b1e7669..409a6f576ee 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_inactive_vertex.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Td_inactive_vertex.h @@ -127,7 +127,7 @@ public: private: - Data* ptr() const { return (Data*)(PTR.p); } + Data* ptr() const { return (Data*)(PTR); } #ifndef CGAL_TD_DEBUG @@ -162,7 +162,7 @@ public: /*! Constructor given Vertex & Halfedge handles. */ Td_inactive_vertex (Vertex_const_handle v_before_rem, Dag_node* node = nullptr) { - PTR.p = new Data(v_before_rem->point(), node); + PTR = new Data(v_before_rem->point(), node); } @@ -217,7 +217,7 @@ public: /*! Access the trapezoid id (PTR). */ inline unsigned long id() const { - return (unsigned long) PTR.p; + return (unsigned long) PTR; } inline Point& point() const 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 e99c306a1e0..6d61db9e61e 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 @@ -25,6 +25,8 @@ */ #include + +#include #include #include @@ -193,13 +195,12 @@ public: // If the polycurve is empty, return. if (cv.number_of_subcurves() == 0) return oi; - Construct_x_monotone_curve_2 ctr_x_curve = - m_poly_traits.construct_x_monotone_curve_2_object(); + auto ctr_x_curve = m_poly_traits.construct_x_monotone_curve_2_object(); - typename Subcurve_traits_2::Make_x_monotone_2 make_seg_x_monotone = + auto make_seg_x_monotone = m_poly_traits.subcurve_traits_2()->make_x_monotone_2_object(); - typename Subcurve_traits_2::Compare_endpoints_xy_2 cmp_seg_endpts = + auto cmp_seg_endpts = m_poly_traits.subcurve_traits_2()->compare_endpoints_xy_2_object(); #ifdef CGAL_ALWAYS_LEFT_TO_RIGHT @@ -238,12 +239,11 @@ public: ( // To be used in order to verify continuity and well-orientedness // of the input curve cv. - typename Subcurve_traits_2::Construct_min_vertex_2 min_seg_v = + auto min_seg_v = m_poly_traits.subcurve_traits_2()->construct_min_vertex_2_object(); - typename Subcurve_traits_2::Construct_max_vertex_2 max_seg_v = + auto max_seg_v = m_poly_traits.subcurve_traits_2()->construct_max_vertex_2_object(); - typename Subcurve_traits_2::Equal_2 equal = - m_poly_traits.subcurve_traits_2()->equal_2_object(); + auto equal = m_poly_traits.subcurve_traits_2()->equal_2_object(); Point_2 last_target = (cmp_seg_endpts(x_seg) == SMALLER) ? max_seg_v(x_seg) : min_seg_v(x_seg); Point_2 next_src; @@ -329,19 +329,18 @@ public: // If the polycurve is empty, return. if (cv.number_of_subcurves() == 0) return oi; - Construct_x_monotone_curve_2 ctr_x_curve = - m_poly_traits.construct_x_monotone_curve_2_object(); + auto ctr_x_curve = m_poly_traits.construct_x_monotone_curve_2_object(); - typename Subcurve_traits_2::Make_x_monotone_2 make_seg_x_monotone = + auto make_seg_x_monotone = m_poly_traits.subcurve_traits_2()->make_x_monotone_2_object(); - typename Subcurve_traits_2::Compare_endpoints_xy_2 cmp_seg_endpts = + auto cmp_seg_endpts = m_poly_traits.subcurve_traits_2()->compare_endpoints_xy_2_object(); - typename Subcurve_traits_2::Parameter_space_in_x_2 ps_x = - m_poly_traits.subcurve_traits_2()->parameter_space_in_x_2_object(); - typename Subcurve_traits_2::Parameter_space_in_y_2 ps_y = - m_poly_traits.subcurve_traits_2()->parameter_space_in_y_2_object(); + auto ps_x = + m_poly_traits.subcurve_traits_2()->parameter_space_in_x_2_object(); + auto ps_y = + m_poly_traits.subcurve_traits_2()->parameter_space_in_y_2_object(); #ifdef CGAL_ALWAYS_LEFT_TO_RIGHT typename Subcurve_traits_2::Construct_opposite_2 ctr_seg_opposite = @@ -379,12 +378,11 @@ public: ( // To be used in order to verify continuity and well-orientedness // of the input curve cv. - typename Subcurve_traits_2::Construct_min_vertex_2 min_seg_v = + auto min_seg_v = m_poly_traits.subcurve_traits_2()->construct_min_vertex_2_object(); - typename Subcurve_traits_2::Construct_max_vertex_2 max_seg_v = + auto max_seg_v = m_poly_traits.subcurve_traits_2()->construct_max_vertex_2_object(); - typename Subcurve_traits_2::Equal_2 equal = - m_poly_traits.subcurve_traits_2()->equal_2_object(); + auto equal = m_poly_traits.subcurve_traits_2()->equal_2_object(); Point_2 last_target = (cmp_seg_endpts(x_seg) == SMALLER) ? max_seg_v(x_seg) : min_seg_v(x_seg); Point_2 next_src; @@ -498,9 +496,7 @@ public: public: /*! Constructor. */ - Push_back_2(const Polycurve_traits_2& traits) : - Base::Push_back_2(traits) - {} + Push_back_2(const Polycurve_traits_2& traits) : Base::Push_back_2(traits) {} // Normally, the moment the compiler finds a name, it stops looking. In // other words, the compiler first finds the operator() in the current @@ -584,20 +580,16 @@ public: X_monotone_curve_2& xcv1, X_monotone_curve_2& xcv2) const { const Subcurve_traits_2* geom_traits = m_poly_traits.subcurve_traits_2(); - typename Subcurve_traits_2::Construct_min_vertex_2 min_vertex = - geom_traits->construct_min_vertex_2_object(); - typename Subcurve_traits_2::Construct_max_vertex_2 max_vertex = - geom_traits->construct_max_vertex_2_object(); - typename Subcurve_traits_2::Equal_2 equal = - geom_traits->equal_2_object(); - typename Subcurve_traits_2::Compare_endpoints_xy_2 cmp_seg_endpts = - geom_traits->compare_endpoints_xy_2_object(); + auto min_vertex = geom_traits->construct_min_vertex_2_object(); + auto max_vertex = geom_traits->construct_max_vertex_2_object(); + auto equal = geom_traits->equal_2_object(); + auto cmp_seg_endpts = geom_traits->compare_endpoints_xy_2_object(); // Make sure the split point is not one of the curve endpoints. - CGAL_precondition((!equal(m_poly_traits. - construct_min_vertex_2_object()(xcv), p))); - CGAL_precondition((!equal(m_poly_traits. - construct_max_vertex_2_object()(xcv), p))); + CGAL_precondition((! equal(m_poly_traits. + construct_min_vertex_2_object()(xcv), p))); + CGAL_precondition((! equal(m_poly_traits. + construct_max_vertex_2_object()(xcv), p))); CGAL_precondition_msg(xcv.number_of_subcurves() > 0, "Cannot split a polycurve of length zero."); @@ -709,22 +701,20 @@ public: const X_monotone_curve_2& cv2, OutputIterator oi) const { - const Subcurve_traits_2* geom_traits = m_poly_traits.subcurve_traits_2(); - Compare_y_at_x_2 cmp_y_at_x = m_poly_traits.compare_y_at_x_2_object(); - typename Subcurve_traits_2::Equal_2 equal = - geom_traits->equal_2_object(); - typename Subcurve_traits_2::Construct_min_vertex_2 min_vertex = - geom_traits->construct_min_vertex_2_object(); - typename Subcurve_traits_2::Construct_max_vertex_2 max_vertex = - geom_traits->construct_max_vertex_2_object(); - typename Subcurve_traits_2::Intersect_2 intersect = - geom_traits->intersect_2_object(); - typename Subcurve_traits_2::Compare_endpoints_xy_2 cmp_seg_endpts = - geom_traits->compare_endpoints_xy_2_object(); - typename Subcurve_traits_2::Construct_opposite_2 construct_opposite = - geom_traits->construct_opposite_2_object(); + typedef std::pair Intersection_point; + typedef boost::variant + Intersection_base_result; + typedef boost::variant + Intersection_result; - typedef std::pair Point_2_pair; + const Subcurve_traits_2* geom_traits = m_poly_traits.subcurve_traits_2(); + auto cmp_y_at_x = m_poly_traits.compare_y_at_x_2_object(); + auto equal = geom_traits->equal_2_object(); + auto min_vertex = geom_traits->construct_min_vertex_2_object(); + auto max_vertex = geom_traits->construct_max_vertex_2_object(); + auto intersect = geom_traits->intersect_2_object(); + auto cmp_seg_endpts = geom_traits->compare_endpoints_xy_2_object(); + auto construct_opposite = geom_traits->construct_opposite_2_object(); Comparison_result dir1 = cmp_seg_endpts(cv1[0]); Comparison_result dir2 = cmp_seg_endpts(cv2[0]); @@ -737,7 +727,7 @@ public: X_monotone_curve_2 ocv; // Used to represent overlaps. - Compare_xy_2 compare_xy = m_poly_traits.compare_xy_2_object(); + auto compare_xy = m_poly_traits.compare_xy_2_object(); Comparison_result left_res = compare_xy(cv1[i1], ARR_MIN_END, cv2[i2], ARR_MIN_END); @@ -754,12 +744,13 @@ public: ((dir1 == LARGER) && (i1 == 0))){ // cv1's right endpoint equals cv2's left endpoint // Thus we can return this single(!) intersection point - std::pair p(max_vertex(cv1[i1]), 0); - *oi++ = make_object(p); + Intersection_point p(max_vertex(cv1[i1]), 0); + *oi++ = Intersection_result(p); return oi; } dir1 == SMALLER ? - ++i1 : (i1 != 0) ? --i1 : (std::size_t) Polycurve_traits_2::INVALID_INDEX; + ++i1 : + (i1 != 0) ? --i1 : (std::size_t) Polycurve_traits_2::INVALID_INDEX; left_res = EQUAL; } } @@ -776,13 +767,14 @@ public: ((dir2 == LARGER) && (i2 == 0))){ // cv2's right endpoint equals cv1's left endpoint // Thus we can return this single(!) intersection point - std::pair p(max_vertex(cv2[i2]), 0); - *oi++ = make_object(p); + Intersection_point p(max_vertex(cv2[i2]), 0); + *oi++ = Intersection_result(p); return oi; } dir2 == SMALLER ? - ++i2 : (i2 != 0) ? --i2 : (std::size_t) Polycurve_traits_2::INVALID_INDEX; + ++i2 : + (i2 != 0) ? --i2 : (std::size_t) Polycurve_traits_2::INVALID_INDEX; left_res = EQUAL; } } @@ -823,48 +815,64 @@ public: right_overlap = false; - if (!right_coincides && !left_coincides) { + //! EF: the following code is abit suspicious. It may erroneously + // assume that the subcurves cannot overlap more than once. + if (! right_coincides && ! left_coincides) { // Non of the endpoints of the current subcurve of one polycurve // coincides with the curent subcurve of the other polycurve: // Output the intersection if exists. - oi = intersect(cv1[i1], cv2[i2], oi); + std::vector xections; + intersect(cv1[i1], cv2[i2], std::back_inserter(xections)); + for (const auto& xection : xections) { + const X_monotone_subcurve_2* subcv_p = + boost::get(&xection); + if (subcv_p != nullptr) { + ocv.push_back(*subcv_p); + *oi++ = Intersection_result(ocv); + ocv.clear(); + continue; + } + + const Intersection_point* p_p = + boost::get(&xection); + if (p_p != nullptr) *oi++ = Intersection_result(*p_p); + } } else if (right_coincides && left_coincides) { // An overlap exists between the current subcurves of the // polycurves: Output the overlapping subcurve. right_overlap = true; - std::vector int_seg; - intersect(cv1[i1], cv2[i2], std::back_inserter(int_seg)); + std::vector sub_xections; + intersect(cv1[i1], cv2[i2], std::back_inserter(sub_xections)); - for (size_t i = 0; i < int_seg.size(); ++i) { + for (const auto& item : sub_xections) { const X_monotone_subcurve_2* x_seg = - CGAL::object_cast (&(int_seg[i])); + boost::get(&item); if (x_seg != nullptr) { X_monotone_subcurve_2 seg = *x_seg; // If for some reason the subcurve intersection // results in left oriented curve. - if ( cmp_seg_endpts(seg) == LARGER) - seg = construct_opposite(seg); + if (cmp_seg_endpts(seg) == LARGER) seg = construct_opposite(seg); ocv.push_back(seg); } - const Point_2_pair* p_ptr = - CGAL::object_cast(&(int_seg[i])); + const Intersection_point* p_ptr = + boost::get(&item); if (p_ptr != nullptr) { // Any point that is not equal to the max_vertex of the // subcurve should be inserted into oi. // The max_vertex of the current subcurve (if intersecting) // will be taken care of as the min_vertex of in the next // iteration. - if (!equal(p_ptr->first, max_vertex(cv1[i1]))) - *oi++ = make_object(*p_ptr); + if (! equal(p_ptr->first, max_vertex(cv1[i1]))) + *oi++ = Intersection_result(*p_ptr); } } } - else if (left_coincides && !right_coincides) { + else if (left_coincides && ! right_coincides) { // std::cout << "Left is coinciding but right is not." << std::endl; // The left point of the current subcurve of one polycurve // coincides with the current subcurve of the other polycurve. @@ -872,7 +880,7 @@ public: // An overlap occurred at the previous iteration: // Output the overlapping polycurve. CGAL_assertion(ocv.number_of_subcurves() > 0); - *oi++ = make_object(ocv); + *oi++ = Intersection_result(ocv); ocv.clear(); } else { @@ -884,12 +892,12 @@ public: // polycurves is not defined at this point, so we give // it multiplicity 0. if (left_res == SMALLER) { - std::pair p(min_vertex(cv2[i2]), 0); - *oi++ = make_object(p); + Intersection_point p(min_vertex(cv2[i2]), 0); + *oi++ = Intersection_result(p); } else { - std::pair p(min_vertex(cv1[i1]), 0); - *oi++ = make_object(p); + Intersection_point p(min_vertex(cv1[i1]), 0); + *oi++ = Intersection_result(p); } } } @@ -919,7 +927,7 @@ public: // Output the remaining overlapping polycurve, if necessary. if (ocv.number_of_subcurves() > 0) { - *oi++ = make_object(ocv); + *oi++ = Intersection_result(ocv); } else if (right_coincides) { typedef std::pair return_point; @@ -930,7 +938,7 @@ public: (i1 != Polycurve_traits_2::INVALID_INDEX) ? return_point(max_vertex(cv1[i1+1]), 0) : return_point(max_vertex(cv1[0]), 0); - *oi++ = make_object(ip); + *oi++ = Intersection_result(ip); } else if (right_res == LARGER) { ip = (dir2 == SMALLER) ? @@ -938,7 +946,7 @@ public: (i2 != Polycurve_traits_2::INVALID_INDEX) ? return_point(max_vertex(cv2[i2+1]), 0) : return_point(max_vertex(cv2[0]), 0); - *oi++ = make_object(ip); + *oi++ = Intersection_result(ip); } else if (((i1 > 0) && (dir1 == SMALLER)) || ((i1 < n1) && (dir1 != SMALLER)) || @@ -950,7 +958,7 @@ public: (i1 != Polycurve_traits_2::INVALID_INDEX) ? return_point(max_vertex(cv1[i1+1]), 0) : return_point(max_vertex(cv1[0]), 0); - *oi++ = make_object(ip); + *oi++ = Intersection_result(ip); } else { CGAL_assertion_msg((dir2 == SMALLER && i2 > 0) || @@ -965,7 +973,7 @@ public: (i2 != Polycurve_traits_2::INVALID_INDEX) ? return_point(max_vertex(cv2[i2+1]), 0) : return_point(max_vertex(cv2[0]), 0); - *oi++ = make_object(ip); + *oi++ = Intersection_result(ip); } } diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_rat_arc/Rational_arc_d_1.h b/Arrangement_on_surface_2/include/CGAL/Arr_rat_arc/Rational_arc_d_1.h index e2010a578ec..7d253018be3 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_rat_arc/Rational_arc_d_1.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_rat_arc/Rational_arc_d_1.h @@ -1848,8 +1848,8 @@ public: typedef typename Base::Cache Cache; - typedef std::pair Intersection_point_2; - //typedef std::pair Intersection_point_2; + typedef std::pair Intersection_point; + //typedef std::pair Intersection_point; /// \name Constrcution methods. @@ -2029,8 +2029,7 @@ public: /// \name Constructions of points and curves. //@{ - /*! - * Compute the intersections with the given arc. + /*! Compute the intersections with the given arc. * \param arc The given intersecting arc. * \param oi The output iterator. * \return The past-the-end iterator. @@ -2039,33 +2038,31 @@ public: OutputIterator intersect(const Self& arc, OutputIterator oi, const Cache& cache) const { + typedef boost::variant Intersection_result; + CGAL_precondition(this->is_valid() && this->is_continuous()); CGAL_precondition(arc.is_valid() && arc.is_continuous()); - if (this->equals(arc)) - { - Self overlap_arc(*this); - *oi++ = make_object(overlap_arc); - return (oi); + if (this->equals(arc)) { + Self overlap_arc(*this); + *oi++ = Intersection_result(overlap_arc); + return oi; } - if (this->_has_same_base(arc)) - { + if (this->_has_same_base(arc)) { // Get the left and right endpoints of (*this) and their information // bits. - const Algebraic_point_2& left1 = (this->is_directed_right() ? - this->_ps : this->_pt); - const Algebraic_point_2& right1 = (this->is_directed_right() ? - this->_pt : this->_ps); - int info_left1, info_right1; + const Algebraic_point_2& left1 = + (this->is_directed_right() ? this->_ps : this->_pt); + const Algebraic_point_2& right1 = + (this->is_directed_right() ? this->_pt : this->_ps); + int info_left1, info_right1; - if (this->is_directed_right()) - { + if (this->is_directed_right()) { info_left1 = (this->_info & this->SRC_INFO_BITS); info_right1 = ((this->_info & this->TRG_INFO_BITS) >> 4); } - else - { + else { info_right1 = (this->_info & this->SRC_INFO_BITS); info_left1 = ((this->_info & this->TRG_INFO_BITS) >> 4); } @@ -2076,110 +2073,93 @@ public: (arc.is_directed_right() ? arc._ps : arc._pt); const Algebraic_point_2& right2 = (arc.is_directed_right() ? arc._pt : arc._ps); - int info_left2, info_right2; + int info_left2, info_right2; - if (arc.is_directed_right()) - { + if (arc.is_directed_right()) { info_left2 = (arc._info & this->SRC_INFO_BITS); info_right2 = ((arc._info & this->TRG_INFO_BITS) >> 4); } - else - { + else { info_right2 = (arc._info & this->SRC_INFO_BITS); info_left2 = ((arc._info & this->TRG_INFO_BITS) >> 4); } // Locate the left curve-end with larger x-coordinate. - bool at_minus_infinity = false; - Arr_parameter_space inf_l1 = this->left_parameter_space_in_x(); - Arr_parameter_space inf_l2 = arc.left_parameter_space_in_x(); - Algebraic_point_2 p_left; - int info_left; + bool at_minus_infinity = false; + Arr_parameter_space inf_l1 = this->left_parameter_space_in_x(); + Arr_parameter_space inf_l2 = arc.left_parameter_space_in_x(); + Algebraic_point_2 p_left; + int info_left; - if (inf_l1 == ARR_INTERIOR && inf_l2 == ARR_INTERIOR) - { + if (inf_l1 == ARR_INTERIOR && inf_l2 == ARR_INTERIOR) { // Let p_left be the rightmost of the two left endpoints. - if (left1.x() > left2.x()) - { + if (left1.x() > left2.x()) { p_left = left1; info_left = info_left1; } - else - { + else { p_left = left2; info_left = info_left2; } } - else if (inf_l1 == ARR_INTERIOR) - { + else if (inf_l1 == ARR_INTERIOR) { // Let p_left be the left endpoint of (*this). p_left = left1; info_left = info_left1; } - else if (inf_l2 == ARR_INTERIOR) - { + else if (inf_l2 == ARR_INTERIOR) { // Let p_left be the left endpoint of the other arc. p_left = left2; info_left = info_left2; } - else - { + else { // Both arcs are defined at x = -oo. at_minus_infinity = true; info_left = info_left1; } // Locate the right curve-end with smaller x-coordinate. - bool at_plus_infinity = false; - Arr_parameter_space inf_r1 = this->right_parameter_space_in_x(); - Arr_parameter_space inf_r2 = arc.right_parameter_space_in_x(); - Algebraic_point_2 p_right; - int info_right; + bool at_plus_infinity = false; + Arr_parameter_space inf_r1 = this->right_parameter_space_in_x(); + Arr_parameter_space inf_r2 = arc.right_parameter_space_in_x(); + Algebraic_point_2 p_right; + int info_right; - if (inf_r1 == ARR_INTERIOR && inf_r2 == ARR_INTERIOR) - { + if (inf_r1 == ARR_INTERIOR && inf_r2 == ARR_INTERIOR) { // Let p_right be the rightmost of the two right endpoints. - if (right1.x() < right2.x()) - { + if (right1.x() < right2.x()) { p_right = right1; info_right = info_right1; } - else - { + else { p_right = right2; info_right = info_right2; } } - else if (inf_r1 == ARR_INTERIOR) - { + else if (inf_r1 == ARR_INTERIOR) { // Let p_right be the right endpoint of (*this). p_right = right1; info_right = info_right1; } - else if (inf_r2 == ARR_INTERIOR) - { + else if (inf_r2 == ARR_INTERIOR) { // Let p_right be the right endpoint of the other arc. p_right = right2; info_right = info_right2; } - else - { + else { // Both arcs are defined at x = +oo. at_plus_infinity = true; info_right = info_right2; } // Check the case of two bounded (in x) ends. - if (! at_minus_infinity && ! at_plus_infinity) - { + if (! at_minus_infinity && ! at_plus_infinity) { Comparison_result res = CGAL::compare(p_left.x(), p_right.x()); - if (res == LARGER) - { - // The x-range of the overlap is empty, so there is no overlap. - return (oi); - } - else if (res == EQUAL) - { + + // The x-range of the overlap is empty, so there is no overlap. + if (res == LARGER) return oi; + + if (res == EQUAL) { // We have a single overlapping point. Just make sure this point // is not at y = -/+ oo. if (info_left && @@ -2187,19 +2167,18 @@ public: info_right && (this->SRC_AT_Y_MINUS_INFTY | this->SRC_AT_Y_PLUS_INFTY) == 0) { - Intersection_point_2 ip(p_left, 0); - - *oi++ = make_object(ip); + Intersection_point ip(p_left, 0); + *oi++ = Intersection_result(ip); } - return (oi); + return oi; } } // Create the overlapping portion of the rational arc by properly setting // the source (left) and target (right) endpoints and their information // bits. - Self overlap_arc(*this); + Self overlap_arc(*this); overlap_arc._ps = p_left; overlap_arc._pt = p_right; @@ -2208,8 +2187,8 @@ public: this->IS_DIRECTED_RIGHT | this->IS_CONTINUOUS | this->IS_VALID); - *oi++ = make_object(overlap_arc); - return (oi); + *oi++ = Intersection_result(overlap_arc); + return oi; } // We wish to find the intersection points between: @@ -2237,15 +2216,14 @@ public: if (this->_is_in_true_x_range(*x_iter) && arc._is_in_true_x_range(*x_iter)) { // Compute the intersection point and obtain its multiplicity. - Algebraic_point_2 p(this->_f, *x_iter); + Algebraic_point_2 p(this->_f, *x_iter); // Output the intersection point: - Intersection_point_2 ip(p, *m_iter); - - *oi++ = make_object(ip); + Intersection_point ip(p, *m_iter); + *oi++ = Intersection_result(ip); } } - return (oi); + return oi; } /*! @@ -2255,7 +2233,8 @@ public: * \param c2 Output: The first resulting arc, lying to the right of p. * \pre p lies in the interior of the arc (not one of its endpoints). */ - void split(const Algebraic_point_2& p, Self& c1, Self& c2, const Cache& CGAL_assertion_code(cache)) const + void split(const Algebraic_point_2& p, Self& c1, Self& c2, + const Cache& CGAL_assertion_code(cache)) const { CGAL_precondition(this->is_valid() && this->is_continuous()); @@ -2598,4 +2577,3 @@ public: } //namespace CGAL { #endif //CGAL_RATIONAL_ARC_D_1_H - 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 a9f3506ea29..a671a741f80 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 @@ -7,9 +7,9 @@ // $Id$ // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial // -// Author(s) : Ron Wein -// Efi Fogel -// Waqar Khan +// Author(s): Ron Wein +// Efi Fogel +// Waqar Khan #ifndef CGAL_ARR_SEGMENT_TRAITS_2_H #define CGAL_ARR_SEGMENT_TRAITS_2_H @@ -22,21 +22,23 @@ * The segment traits-class for the arrangement package. */ +#include + +#include + #include #include #include #include #include #include -#include namespace CGAL { -template +template class Arr_segment_2; -/*! - * \class A traits class for maintaining an arrangement of segments, avoiding +/*! \class A traits class for maintaining an arrangement of segments, avoiding * cascading of computations as much as possible. * * The class is derived from the parameterized kernel to extend the traits @@ -79,17 +81,17 @@ public: typedef typename Kernel::Point_2 Point_2; protected: - Line_2 l; // The line that supports the segment. - Point_2 ps; // The source point of the segment. - Point_2 pt; // The target point of the segment. - bool is_pt_max; // Is the target (lexicographically) larger - // than the source. - bool is_vert; // Is this a vertical segment. - bool is_degen; // Is the segment degenerate (a single point). + Line_2 m_l; // The line that supports the segment. + Point_2 m_ps; // The source point of the segment. + Point_2 m_pt; // The target point of the segment. + bool m_is_pt_max; // Is the target (lexicographically) larger + // than the source. + bool m_is_vert; // Is this a vertical segment. + bool m_is_degen; // Is the segment degenerate (a single point). public: /*! Default constructor. */ - _Segment_cached_2() : is_vert(false), is_degen(true) {} + _Segment_cached_2() : m_is_vert(false), m_is_degen(true) {} /*! Constructor from a segment. * \param seg The segment. @@ -97,50 +99,46 @@ public: */ _Segment_cached_2(const Segment_2& seg) { - Kernel kernel; + Kernel kernel; + auto construct_vertex = kernel.construct_vertex_2_object(); - typename Kernel_::Construct_vertex_2 - construct_vertex = kernel.construct_vertex_2_object(); + m_ps = construct_vertex(seg, 0); + m_pt = construct_vertex(seg, 1); - ps = construct_vertex(seg, 0); - pt = construct_vertex(seg, 1); + Comparison_result res = kernel.compare_xy_2_object()(m_ps, m_pt); + m_is_degen = (res == EQUAL); + m_is_pt_max = (res == SMALLER); - Comparison_result res = kernel.compare_xy_2_object()(ps, pt); - is_degen = (res == EQUAL); - is_pt_max = (res == SMALLER); - - CGAL_precondition_msg (! is_degen, + CGAL_precondition_msg (! m_is_degen, "Cannot construct a degenerate segment."); - l = kernel.construct_line_2_object()(seg); - is_vert = kernel.is_vertical_2_object()(seg); + m_l = kernel.construct_line_2_object()(seg); + m_is_vert = kernel.is_vertical_2_object()(seg); } - /*! - * Construct a segment from two end-points. + /*! Construct a segment from two end-points. * \param source The source point. * \param target The target point. * \param The two points must not be equal. */ _Segment_cached_2(const Point_2& source, const Point_2& target) : - ps(source), - pt(target) + m_ps(source), + m_pt(target) { - Kernel kernel; + Kernel kernel; - Comparison_result res = kernel.compare_xy_2_object()(ps, pt); - is_degen = (res == EQUAL); - is_pt_max = (res == SMALLER); + Comparison_result res = kernel.compare_xy_2_object()(m_ps, m_pt); + m_is_degen = (res == EQUAL); + m_is_pt_max = (res == SMALLER); - CGAL_precondition_msg(! is_degen, + CGAL_precondition_msg(! m_is_degen, "Cannot construct a degenerate segment."); - l = kernel.construct_line_2_object()(source, target); - is_vert = kernel.is_vertical_2_object()(l); + m_l = kernel.construct_line_2_object()(source, target); + m_is_vert = kernel.is_vertical_2_object()(m_l); } - /*! - * Construct a segment from two end-points on a supporting line. + /*! Construct a segment from two end-points on a supporting line. * \param supp_line The supporting line. * \param source The source point. * \param target The target point. @@ -148,60 +146,56 @@ public: */ _Segment_cached_2(const Line_2& supp_line, const Point_2& source, const Point_2& target) : - l(supp_line), - ps(source), - pt(target) + m_l(supp_line), + m_ps(source), + m_pt(target) { - Kernel kernel; + Kernel kernel; - CGAL_precondition( - Segment_assertions::_assert_is_point_on(source, l, - Has_exact_division()) && - Segment_assertions::_assert_is_point_on(target,l, - Has_exact_division()) - ); + CGAL_precondition + (Segment_assertions::_assert_is_point_on(source, m_l, + Has_exact_division()) && + Segment_assertions::_assert_is_point_on(target, m_l, + Has_exact_division())); - is_vert = kernel.is_vertical_2_object()(l); + m_is_vert = kernel.is_vertical_2_object()(m_l); - Comparison_result res = kernel.compare_xy_2_object()(ps, pt); - is_degen = (res == EQUAL); - is_pt_max = (res == SMALLER); + Comparison_result res = kernel.compare_xy_2_object()(m_ps, m_pt); + m_is_degen = (res == EQUAL); + m_is_pt_max = (res == SMALLER); - CGAL_precondition_msg(! is_degen, + CGAL_precondition_msg(! m_is_degen, "Cannot construct a degenerate segment."); } - /*! - * Assignment operator. + /*! Assignment operator. * \param seg the source segment to copy from * \pre The segment is not degenerate. */ - const _Segment_cached_2& operator= (const Segment_2& seg) + const _Segment_cached_2& operator=(const Segment_2& seg) { - Kernel kernel; + Kernel kernel; + auto construct_vertex = kernel.construct_vertex_2_object(); - typename Kernel_::Construct_vertex_2 - construct_vertex = kernel.construct_vertex_2_object(); + m_ps = construct_vertex(seg, 0); + m_pt = construct_vertex(seg, 1); - ps = construct_vertex(seg, 0); - pt = construct_vertex(seg, 1); + Comparison_result res = kernel.compare_xy_2_object()(m_ps, m_pt); + m_is_degen = (res == EQUAL); + m_is_pt_max = (res == SMALLER); - Comparison_result res = kernel.compare_xy_2_object()(ps, pt); - is_degen = (res == EQUAL); - is_pt_max = (res == SMALLER); - - CGAL_precondition_msg(! is_degen, + CGAL_precondition_msg(! m_is_degen, "Cannot construct a degenerate segment."); - l = kernel.construct_line_2_object()(seg); - is_vert = kernel.is_vertical_2_object()(seg); + m_l = kernel.construct_line_2_object()(seg); + m_is_vert = kernel.is_vertical_2_object()(seg); return (*this); } /*! Obtain the (lexicographically) left endpoint. */ - const Point_2& left() const { return (is_pt_max ? ps : pt); } + const Point_2& left() const { return (m_is_pt_max ? m_ps : m_pt); } /*! Set the (lexicographically) left endpoint. * \param p The point to set. @@ -209,22 +203,19 @@ public: */ void set_left(const Point_2& p) { - CGAL_precondition (! is_degen); - CGAL_precondition_code ( - Kernel kernel; - ); + CGAL_precondition(! m_is_degen); + CGAL_precondition_code(Kernel kernel); CGAL_precondition - (Segment_assertions::_assert_is_point_on (p, l, - Has_exact_division()) && - kernel.compare_xy_2_object() (p, right()) == SMALLER); + (Segment_assertions::_assert_is_point_on(p, m_l, Has_exact_division()) && + (kernel.compare_xy_2_object()(p, right()) == SMALLER)); - if (is_pt_max) ps = p; - else pt = p; + if (m_is_pt_max) m_ps = p; + else m_pt = p; } /*! Obtain the (lexicographically) right endpoint. */ - const Point_2& right() const { return (is_pt_max ? pt : ps); } + const Point_2& right() const { return (m_is_pt_max ? m_pt : m_ps); } /*! Set the (lexicographically) right endpoint. * \param p The point to set. @@ -232,38 +223,35 @@ public: */ void set_right(const Point_2& p) { - CGAL_precondition(! is_degen); - CGAL_precondition_code( - Kernel kernel; - ); + CGAL_precondition(! m_is_degen); + CGAL_precondition_code(Kernel kernel); CGAL_precondition - (Segment_assertions::_assert_is_point_on (p, l, - Has_exact_division()) && - kernel.compare_xy_2_object() (p, left()) == LARGER); + (Segment_assertions::_assert_is_point_on(p, m_l, Has_exact_division()) && + (kernel.compare_xy_2_object()(p, left()) == LARGER)); - if (is_pt_max) pt = p; - else ps = p; + if (m_is_pt_max) m_pt = p; + else m_ps = p; } /*! Obtain the supporting line. */ const Line_2& line() const { - CGAL_precondition(! is_degen); - return (l); + CGAL_precondition(! m_is_degen); + return m_l; } /*! Determine whether the curve is vertical. */ bool is_vertical() const { - CGAL_precondition(! is_degen); - return (is_vert); + CGAL_precondition(! m_is_degen); + return m_is_vert; } /*! Determine whether the curve is directed lexicographic from left to right */ - bool is_directed_right() const { return (is_pt_max); } + bool is_directed_right() const { return (m_is_pt_max); } /*! Determine whether the given point is in the x-range of the segment. * \param p The query point. @@ -271,12 +259,12 @@ public: */ bool is_in_x_range(const Point_2& p) const { - Kernel kernel; - typename Kernel_::Compare_x_2 compare_x = kernel.compare_x_2_object(); - const Comparison_result res1 = compare_x(p, left()); + Kernel kernel; + typename Kernel_::Compare_x_2 compare_x = kernel.compare_x_2_object(); + const Comparison_result res1 = compare_x(p, left()); - if (res1 == SMALLER) return (false); - else if (res1 == EQUAL) return (true); + if (res1 == SMALLER) return false; + else if (res1 == EQUAL) return true; const Comparison_result res2 = compare_x(p, right()); return (res2 != LARGER); @@ -288,14 +276,14 @@ public: */ bool is_in_y_range(const Point_2& p) const { - Kernel kernel; - typename Kernel_::Compare_y_2 compare_y = kernel.compare_y_2_object(); - const Comparison_result res1 = compare_y (p, left()); + Kernel kernel; + typename Kernel_::Compare_y_2 compare_y = kernel.compare_y_2_object(); + const Comparison_result res1 = compare_y(p, left()); - if (res1 == SMALLER) return (false); - else if (res1 == EQUAL) return (true); + if (res1 == SMALLER) return false; + else if (res1 == EQUAL) return true; - const Comparison_result res2 = compare_y (p, right()); + const Comparison_result res2 = compare_y(p, right()); return (res2 != LARGER); } }; @@ -329,23 +317,21 @@ public: friend class Arr_segment_traits_2; public: - /*! - * Compare the x-coordinates of two points. + /*! Compare the x-coordinates of two points. * \param p1 The first point. * \param p2 The second point. * \return LARGER if x(p1) > x(p2); * SMALLER if x(p1) < x(p2); * EQUAL if x(p1) = x(p2). */ - Comparison_result operator() (const Point_2& p1, const Point_2& p2) const + Comparison_result operator()(const Point_2& p1, const Point_2& p2) const { const Kernel& kernel = m_traits; - return (kernel.compare_x_2_object()(p1, p2)); } }; - /*! Get a Compare_x_2 functor object. */ + /*! Obtain a Compare_x_2 functor object. */ Compare_x_2 compare_x_2_object() const { return Compare_x_2(*this); } class Compare_xy_2 { @@ -363,8 +349,7 @@ public: friend class Arr_segment_traits_2; public: - /*! - * Compare two points lexicographically: by x, then by y. + /*! Compare two points lexicographically: by x, then by y. * \param p1 The first point. * \param p2 The second point. * \return LARGER if x(p1) > x(p2), or if x(p1) = x(p2) and y(p1) > y(p2); @@ -378,13 +363,12 @@ public: } }; - /*! Get a Compare_xy_2 functor object. */ + /*! Obtain a Compare_xy_2 functor object. */ Compare_xy_2 compare_xy_2_object() const { return Compare_xy_2(*this); } class Construct_min_vertex_2 { public: - /*! - * Get the left endpoint of the x-monotone curve (segment). + /*! Obtain the left endpoint of the x-monotone curve (segment). * \param cv The curve. * \return The left endpoint. */ @@ -392,29 +376,27 @@ public: { return (cv.left()); } }; - /*! Get a Construct_min_vertex_2 functor object. */ + /*! Obtain a Construct_min_vertex_2 functor object. */ Construct_min_vertex_2 construct_min_vertex_2_object() const { return Construct_min_vertex_2(); } class Construct_max_vertex_2 { public: - /*! - * Get the right endpoint of the x-monotone curve (segment). + /*! Obtain the right endpoint of the x-monotone curve (segment). * \param cv The curve. * \return The right endpoint. */ - const Point_2& operator() (const X_monotone_curve_2& cv) const + const Point_2& operator()(const X_monotone_curve_2& cv) const { return (cv.right()); } }; - /*! Get a Construct_max_vertex_2 functor object. */ + /*! Obtain a Construct_max_vertex_2 functor object. */ Construct_max_vertex_2 construct_max_vertex_2_object() const { return Construct_max_vertex_2(); } class Is_vertical_2 { public: - /*! - * Check whether the given x-monotone curve is a vertical segment. + /*! Check whether the given x-monotone curve is a vertical segment. * \param cv The curve. * \return (true) if the curve is a vertical segment; (false) otherwise. */ @@ -422,9 +404,8 @@ public: { return (cv.is_vertical()); } }; - /*! Get an Is_vertical_2 functor object. */ - Is_vertical_2 is_vertical_2_object () const - { return Is_vertical_2(); } + /*! Obtain an Is_vertical_2 functor object. */ + Is_vertical_2 is_vertical_2_object () const { return Is_vertical_2(); } class Compare_y_at_x_2 { protected: @@ -441,8 +422,7 @@ public: friend class Arr_segment_traits_2; public: - /*! - * Return the location of the given point with respect to the input curve. + /*! Return the location of the given point with respect to the input curve. * \param cv The curve. * \param p The point. * \pre p is in the x-range of cv. @@ -453,27 +433,26 @@ public: Comparison_result operator()(const Point_2& p, const X_monotone_curve_2& cv) const { - CGAL_precondition (cv.is_in_x_range(p)); + CGAL_precondition(cv.is_in_x_range(p)); const Kernel& kernel = m_traits; if (! cv.is_vertical()) { // Compare p with the segment's supporting line. - CGAL_assertion( kernel.compare_x_2_object()(cv.left(), cv.right()) == SMALLER ); + CGAL_assertion_code(auto cmp_x = kernel.compare_x_2_object()); + CGAL_assertion(cmp_x(cv.left(), cv.right()) == SMALLER); return kernel.orientation_2_object()(cv.left(), cv.right(), p); } - else { - // Compare with the vertical segment's end-points. - typename Kernel::Compare_y_2 compare_y = kernel.compare_y_2_object(); - Comparison_result res1 = compare_y(p, cv.left()); - Comparison_result res2 = compare_y(p, cv.right()); - return (res1 == res2) ? res1 : EQUAL; - } + // Compare with the vertical segment's end-points. + typename Kernel::Compare_y_2 compare_y = kernel.compare_y_2_object(); + Comparison_result res1 = compare_y(p, cv.left()); + Comparison_result res2 = compare_y(p, cv.right()); + return (res1 == res2) ? res1 : EQUAL; } }; - /*! Get a Compare_y_at_x_2 functor object. */ + /*! Obtain a Compare_y_at_x_2 functor object. */ Compare_y_at_x_2 compare_y_at_x_2_object() const { return Compare_y_at_x_2(*this); } @@ -492,8 +471,7 @@ public: friend class Arr_segment_traits_2; public: - /*! - * Compare the y value of two x-monotone curves immediately to the left + /*! Compare the y value of two x-monotone curves immediately to the left * of their intersection point. * \param cv1 The first curve. * \param cv2 The second curve. @@ -511,14 +489,10 @@ public: // Make sure that p lies on both curves, and that both are defined to its // left (so their left endpoint is lexicographically smaller than p). - CGAL_precondition_code( - typename Kernel::Compare_xy_2 compare_xy = - kernel.compare_xy_2_object(); - ); + CGAL_precondition_code(auto compare_xy = kernel.compare_xy_2_object()); - CGAL_precondition( - (m_traits.compare_y_at_x_2_object()(p, cv1) == EQUAL) && - (m_traits.compare_y_at_x_2_object()(p, cv2) == EQUAL)); + CGAL_precondition((m_traits.compare_y_at_x_2_object()(p, cv1) == EQUAL) && + (m_traits.compare_y_at_x_2_object()(p, cv2) == EQUAL)); CGAL_precondition(compare_xy(cv1.left(), p) == SMALLER && compare_xy(cv2.left(), p) == SMALLER); @@ -532,8 +506,8 @@ public: } }; - /*! Get a Compare_y_at_x_left_2 functor object. */ - Compare_y_at_x_left_2 compare_y_at_x_left_2_object () const + /*! Obtain a Compare_y_at_x_left_2 functor object. */ + Compare_y_at_x_left_2 compare_y_at_x_left_2_object() const { return Compare_y_at_x_left_2(*this); } class Compare_y_at_x_right_2 { @@ -551,8 +525,7 @@ public: friend class Arr_segment_traits_2; public: - /*! - * Compare the y value of two x-monotone curves immediately to the right + /*! Compare the y value of two x-monotone curves immediately to the right * of their intersection point. * \param cv1 The first curve. * \param cv2 The second curve. @@ -570,14 +543,10 @@ public: // Make sure that p lies on both curves, and that both are defined to its // right (so their right endpoint is lexicographically larger than p). - CGAL_precondition_code ( - typename Kernel::Compare_xy_2 compare_xy = - kernel.compare_xy_2_object(); - ); + CGAL_precondition_code(auto compare_xy = kernel.compare_xy_2_object()); - CGAL_precondition( - (m_traits.compare_y_at_x_2_object()(p, cv1) == EQUAL) && - (m_traits.compare_y_at_x_2_object()(p, cv2) == EQUAL)); + CGAL_precondition((m_traits.compare_y_at_x_2_object()(p, cv1) == EQUAL) && + (m_traits.compare_y_at_x_2_object()(p, cv2) == EQUAL)); CGAL_precondition(compare_xy(cv1.right(), p) == LARGER && compare_xy(cv2.right(), p) == LARGER); @@ -589,7 +558,7 @@ public: } }; - /*! Get a Compare_y_at_x_right_2 functor object. */ + /*! Obtain a Compare_y_at_x_right_2 functor object. */ Compare_y_at_x_right_2 compare_y_at_x_right_2_object() const { return Compare_y_at_x_right_2(*this); } @@ -608,8 +577,8 @@ public: friend class Arr_segment_traits_2; public: - /*! - * Check if the two x-monotone curves are the same (have the same graph). + /*! Check whether the two x-monotone curves are the same (have the same + * graph). * \param cv1 The first curve. * \param cv2 The second curve. * \return (true) if the two curves are the same; (false) otherwise. @@ -629,14 +598,14 @@ public: * \param p2 The second point. * \return (true) if the two point are the same; (false) otherwise. */ - bool operator() (const Point_2& p1, const Point_2& p2) const + bool operator()(const Point_2& p1, const Point_2& p2) const { const Kernel& kernel = m_traits; return (kernel.equal_2_object()(p1, p2)); } }; - /*! Get an Equal_2 functor object. */ + /*! Obtain an Equal_2 functor object. */ Equal_2 equal_2_object() const { return Equal_2(*this); } //@} @@ -645,25 +614,23 @@ public: class Make_x_monotone_2 { public: - /*! - * Cut the given curve into x-monotone subcurves and insert them into the + /*! Cut the given curve into x-monotone subcurves and insert them into the * 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. + * \param oi The output iterator, whose value-type is variant<.... * \return The past-the-end iterator. */ - template + template OutputIterator operator()(const Curve_2& cv, OutputIterator oi) const { // Wrap the segment with an object. - *oi = make_object (cv); - ++oi; - return (oi); + *oi++ = make_object(cv); + return oi; } }; - /*! Get a Make_x_monotone_2 functor object. */ + /*! Obtain a Make_x_monotone_2 functor object. */ Make_x_monotone_2 make_x_monotone_2_object() const { return Make_x_monotone_2(); } @@ -682,8 +649,7 @@ public: friend class Arr_segment_traits_2; public: - /*! - * Split a given x-monotone curve at a given point into two sub-curves. + /*! Split a given x-monotone curve at a given point into two sub-curves. * \param cv The curve to split * \param p The split point. * \param c1 Output: The left resulting subcurve (p is its right endpoint). @@ -694,28 +660,24 @@ public: X_monotone_curve_2& c1, X_monotone_curve_2& c2) const { // Make sure that p lies on the interior of the curve. - CGAL_precondition_code ( - const Kernel& kernel = m_traits; - typename Kernel::Compare_xy_2 compare_xy = - kernel.compare_xy_2_object(); - ); + CGAL_precondition_code(const Kernel& kernel = m_traits; + auto compare_xy = kernel.compare_xy_2_object()); - CGAL_precondition( - (m_traits.compare_y_at_x_2_object()(p, cv) == EQUAL) && - compare_xy(cv.left(), p) == SMALLER && - compare_xy(cv.right(), p) == LARGER); + CGAL_precondition((m_traits.compare_y_at_x_2_object()(p, cv) == EQUAL) && + compare_xy(cv.left(), p) == SMALLER && + compare_xy(cv.right(), p) == LARGER); // Perform the split. c1 = cv; - c1.set_right (p); + c1.set_right(p); c2 = cv; - c2.set_left (p); + c2.set_left(p); } }; - /*! Get a Split_2 functor object. */ - Split_2 split_2_object () const { return Split_2(*this); } + /*! Obtain a Split_2 functor object. */ + Split_2 split_2_object() const { return Split_2(*this); } class Intersect_2 { protected: @@ -732,8 +694,7 @@ public: friend class Arr_segment_traits_2; public: - /*! - * Find the intersections of the two given curves and insert them into the + /*! Find the intersections of the two given curves and insert them into the * given output iterator. As two segments may intersect only once, only a * single intersection will be contained in the iterator. * \param cv1 The first curve. @@ -741,93 +702,90 @@ public: * \param oi The output iterator. * \return The past-the-end iterator. */ - template - OutputIterator operator() (const X_monotone_curve_2& cv1, - const X_monotone_curve_2& cv2, - OutputIterator oi) const + template + OutputIterator operator()(const X_monotone_curve_2& cv1, + const X_monotone_curve_2& cv2, + OutputIterator oi) const { + typedef std::pair Intersection_point; + typedef boost::variant + Intersection_result; + // Intersect the two supporting lines. const Kernel& kernel = m_traits; - CGAL::Object obj = kernel.intersect_2_object()(cv1.line(), cv2.line()); + auto res = kernel.intersect_2_object()(cv1.line(), cv2.line()); - if (obj.is_empty()) { - // The supporting line are parallel lines and do not intersect: - return (oi); - } + // The supporting line are parallel lines and do not intersect: + if (! res) return oi; // Check if we have a single intersection point. - const Point_2 *ip = object_cast (&obj); - + const Point_2* ip = boost::get(&*res); if (ip != nullptr) { // Check if the intersection point ip lies on both segments. - const bool ip_on_cv1 = cv1.is_vertical() ? cv1.is_in_y_range(*ip) : - cv1.is_in_x_range(*ip); + const bool ip_on_cv1 = cv1.is_vertical() ? + cv1.is_in_y_range(*ip) : cv1.is_in_x_range(*ip); if (ip_on_cv1) { - const bool ip_on_cv2 = cv2.is_vertical() ? cv2.is_in_y_range(*ip) : - cv2.is_in_x_range(*ip); + const bool ip_on_cv2 = cv2.is_vertical() ? + cv2.is_in_y_range(*ip) : cv2.is_in_x_range(*ip); if (ip_on_cv2) { // Create a pair representing the point with its multiplicity, // which is always 1 for line segments. - std::pair ip_mult (*ip, 1); - *oi = make_object (ip_mult); - oi++; + Intersection_point ip_mult(*ip, 1); + *oi++ = Intersection_result(ip_mult); } } - return (oi); + return oi; } // In this case, the two supporting lines overlap. // The overlapping segment is therefore [p_l,p_r], where p_l is the // rightmost of the two left endpoints and p_r is the leftmost of the // two right endpoints. - typename Kernel::Compare_xy_2 compare_xy = kernel.compare_xy_2_object(); - Point_2 p_l, p_r; - - if (compare_xy (cv1.left(), cv2.left()) == SMALLER) p_l = cv2.left(); - else p_l = cv1.left(); - - if (compare_xy (cv1.right(), cv2.right()) == SMALLER) p_r = cv1.right(); - else p_r = cv2.right(); + auto compare_xy = kernel.compare_xy_2_object(); + Point_2 p_l = (compare_xy(cv1.left(), cv2.left()) == SMALLER) ? + cv2.left() : cv1.left(); + Point_2 p_r = (compare_xy(cv1.right(), cv2.right()) == SMALLER) ? + cv1.right() : cv2.right(); // Examine the resulting segment. - const Comparison_result res = compare_xy (p_l, p_r); + const Comparison_result cmp_res = compare_xy(p_l, p_r); - if (res == SMALLER) { + if (cmp_res == SMALLER) { // We have discovered an overlapping segment: if (cv1.is_directed_right() == cv2.is_directed_right()) { // cv1 and cv2 have the same directions, maintain this direction // in the overlap segment if (cv1.is_directed_right()) { - X_monotone_curve_2 overlap_seg(cv1.line(), p_l, p_r); - *oi++ = make_object(overlap_seg); - } - else { - X_monotone_curve_2 overlap_seg(cv1.line(), p_r, p_l); - *oi++ = make_object(overlap_seg); + X_monotone_curve_2 overlap_seg(cv1.line(), p_l, p_r); + *oi++ = Intersection_result(overlap_seg); + return oi; } + X_monotone_curve_2 overlap_seg(cv1.line(), p_r, p_l); + *oi++ = Intersection_result(overlap_seg); + return oi; } - else { - // cv1 and cv2 have opposite directions, the overlap segment - // will be directed from left to right - X_monotone_curve_2 overlap_seg(cv1.line(), p_l, p_r); - *oi++ = make_object(overlap_seg); - } + // cv1 and cv2 have opposite directions, the overlap segment + // will be directed from left to right + X_monotone_curve_2 overlap_seg(cv1.line(), p_l, p_r); + *oi++ = Intersection_result(overlap_seg); + return oi; } - else if (res == EQUAL) { + if (cmp_res == EQUAL) { // The two segment have the same supporting line, but they just share // a common endpoint. Thus we have an intersection point, but we leave // the multiplicity of this point undefined. - std::pair ip_mult(p_r, 0); - *oi++ = make_object(ip_mult); + Intersection_point ip_mult(p_r, 0); + *oi++ = Intersection_result(ip_mult); + return oi; } - return (oi); + return oi; } }; - /*! Get an Intersect_2 functor object. */ + /*! Obtain an Intersect_2 functor object. */ Intersect_2 intersect_2_object() const { return Intersect_2(*this); } class Are_mergeable_2 { @@ -845,8 +803,7 @@ public: friend class Arr_segment_traits_2; public: - /*! - * Check whether it is possible to merge two given x-monotone curves. + /*! Check whether it is possible to merge two given x-monotone curves. * \param cv1 The first curve. * \param cv2 The second curve. * \return (true) if the two curves are mergeable, that is, if they are @@ -856,20 +813,20 @@ public: bool operator()(const X_monotone_curve_2& cv1, const X_monotone_curve_2& cv2) const { - if (!m_traits.equal_2_object()(cv1.right(), cv2.left()) && - !m_traits.equal_2_object()(cv2.right(), cv1.left())) + const Kernel& kernel = m_traits; + typename Kernel::Equal_2 equal = kernel.equal_2_object(); + if (! equal(cv1.right(), cv2.left()) && + ! equal(cv2.right(), cv1.left())) return false; // Check whether the two curves have the same supporting line. - const Kernel& kernel = m_traits; - typename Kernel::Equal_2 equal = kernel.equal_2_object(); return (equal(cv1.line(), cv2.line()) || equal(cv1.line(), kernel.construct_opposite_line_2_object()(cv2.line()))); } }; - /*! Get an Are_mergeable_2 functor object. */ + /*! Obtain an Are_mergeable_2 functor object. */ Are_mergeable_2 are_mergeable_2_object() const { return Are_mergeable_2(*this); } @@ -891,8 +848,7 @@ public: friend class Arr_segment_traits_2; public: - /*! - * Merge two given x-monotone curves into a single curve (segment). + /*! Merge two given x-monotone curves into a single curve (segment). * \param cv1 The first curve. * \param cv2 The second curve. * \param c Output: The merged curve. @@ -904,25 +860,26 @@ public: { CGAL_precondition(m_traits.are_mergeable_2_object()(cv1, cv2)); - Equal_2 equal = m_traits.equal_2_object(); + const Kernel& kernel = m_traits; + auto equal = kernel.equal_2_object(); // Check which curve extends to the right of the other. if (equal(cv1.right(), cv2.left())) { // cv2 extends cv1 to the right. c = cv1; c.set_right(cv2.right()); + return; } - else { - CGAL_precondition(equal(cv2.right(), cv1.left())); - // cv1 extends cv2 to the right. - c = cv2; - c.set_right(cv1.right()); - } + CGAL_precondition(equal(cv2.right(), cv1.left())); + + // cv1 extends cv2 to the right. + c = cv2; + c.set_right(cv1.right()); } }; - /*! Get a Merge_2 functor object. */ + /*! Obtain a Merge_2 functor object. */ Merge_2 merge_2_object() const { return Merge_2(*this); } //@} @@ -932,8 +889,7 @@ public: class Approximate_2 { public: - /*! - * Return an approximation of a point coordinate. + /*! Obtain an approximation of a point coordinate. * \param p The exact point. * \param i The coordinate index (either 0 or 1). * \pre i is either 0 or 1. @@ -947,13 +903,12 @@ public: } }; - /*! Get an Approximate_2 functor object. */ + /*! Obtain an Approximate_2 functor object. */ Approximate_2 approximate_2_object() const { return Approximate_2(); } class Construct_x_monotone_curve_2 { public: - /*! - * Return an x-monotone curve connecting the two given endpoints. + /*! Obtain an x-monotone curve connecting the two given endpoints. * \param p The first point. * \param q The second point. * \pre p and q must not be the same. @@ -963,7 +918,7 @@ public: { return (X_monotone_curve_2(p, q)); } }; - /*! Get a Construct_x_monotone_curve_2 functor object. */ + /*! Obtain a Construct_x_monotone_curve_2 functor object. */ Construct_x_monotone_curve_2 construct_x_monotone_curve_2_object() const { return Construct_x_monotone_curve_2(); } //@} @@ -1011,41 +966,37 @@ public: // exchange src and tgt IF they do not conform with the direction X_monotone_curve_2 trimmed_segment; - if (xcv.is_directed_right() && compare_x_2(src, tgt) == LARGER) trimmed_segment = X_monotone_curve_2(tgt, src); - else if (!xcv.is_directed_right() && compare_x_2(src, tgt) == SMALLER ) + else if (! xcv.is_directed_right() && (compare_x_2(src, tgt) == SMALLER)) trimmed_segment = X_monotone_curve_2(tgt, src); else trimmed_segment = X_monotone_curve_2(src, tgt); - return (trimmed_segment); + return trimmed_segment; } }; - //get a Trim_2 functor object + /*! Obtain a Trim_2 functor object */ Trim_2 trim_2_object() const { return Trim_2(*this); } - class Compare_endpoints_xy_2 - { + class Compare_endpoints_xy_2 { public: - /*! - * Compare the endpoints of an $x$-monotone curve lexicographically. + /*! Compare the endpoints of an $x$-monotone curve lexicographically. * (assuming the curve has a designated source and target points). * \param cv The curve. * \return SMALLER if the curve is directed right; * LARGER if the curve is directed left. */ - Comparison_result operator() (const X_monotone_curve_2& cv) const + Comparison_result operator()(const X_monotone_curve_2& cv) const { return (cv.is_directed_right()) ? (SMALLER) : (LARGER); } }; - /*! Get a Compare_endpoints_xy_2 functor object. */ + /*! Obtain a Compare_endpoints_xy_2 functor object. */ Compare_endpoints_xy_2 compare_endpoints_xy_2_object() const { return Compare_endpoints_xy_2(); } class Construct_opposite_2 { public: - /*! - * Construct an opposite x-monotone (with swapped source and target). + /*! Construct an opposite x-monotone (with swapped source and target). * \param cv The curve. * \return The opposite curve. */ @@ -1053,17 +1004,16 @@ public: { return (cv.flip()); } }; - /*! Get a Construct_opposite_2 functor object. */ + /*! Obtain a Construct_opposite_2 functor object. */ Construct_opposite_2 construct_opposite_2_object() const { return Construct_opposite_2(); } //@} }; -/*! - * \class A representation of a segment, as used by the Arr_segment_traits_2 +/*! \class A representation of a segment, as used by the Arr_segment_traits_2 * traits-class. */ -template +template class Arr_segment_2 : public Arr_segment_traits_2::_Segment_cached_2 { @@ -1089,7 +1039,7 @@ public: * \pre The two points are not the same. */ Arr_segment_2(const Point_2& source, const Point_2& target) : - Base(source,target) + Base(source, target) {} /*! Construct a segment from a line and two end-points. @@ -1101,7 +1051,7 @@ public: */ Arr_segment_2(const Line_2& line, const Point_2& source, const Point_2& target) : - Base(line,source,target) + Base(line,source, target) {} /*! Cast to a segment. @@ -1109,8 +1059,8 @@ public: operator Segment_2() const { Kernel kernel; - Segment_2 seg = kernel.construct_segment_2_object()(this->ps, this->pt); - return (seg); + Segment_2 seg = kernel.construct_segment_2_object()(this->m_ps, this->m_pt); + return seg; } /*! Create a bounding box for the segment. @@ -1118,37 +1068,37 @@ public: Bbox_2 bbox() const { Kernel kernel; - Segment_2 seg = kernel.construct_segment_2_object()(this->ps, this->pt); - return (kernel.construct_bbox_2_object() (seg)); + Segment_2 seg = kernel.construct_segment_2_object()(this->m_ps, this->m_pt); + return (kernel.construct_bbox_2_object()(seg)); } /*! Obtain the segment source. */ - const Point_2& source() const { return (this->ps); } + const Point_2& source() const { return (this->m_ps); } /*! Obtain the segment target. */ - const Point_2& target() const { return (this->pt); } + const Point_2& target() const { return (this->m_pt); } /*! Flip the segment (swap its source and target). */ Arr_segment_2 flip() const { - Arr_segment_2 opp; - opp.l = this->l; - opp.ps = this->pt; - opp.pt = this->ps; - opp.is_pt_max = !(this->is_pt_max); - opp.is_vert = this->is_vert; - opp.is_degen = this->is_degen; + Arr_segment_2 opp; + opp.m_l = this->m_l; + opp.m_ps = this->m_pt; + opp.m_pt = this->m_ps; + opp.m_is_pt_max = !(this->m_is_pt_max); + opp.m_is_vert = this->m_is_vert; + opp.m_is_degen = this->m_is_degen; - return (opp); + return opp; } }; /*! Exporter for the segment class used by the traits-class. */ -template +template OutputStream& operator<<(OutputStream& os, const Arr_segment_2& seg) { os << static_cast(seg); @@ -1157,13 +1107,13 @@ OutputStream& operator<<(OutputStream& os, const Arr_segment_2& seg) /*! Importer for the segment class used by the traits-class. */ -template +template InputStream& operator>>(InputStream& is, Arr_segment_2& seg) { typename Kernel::Segment_2 kernel_seg; is >> kernel_seg; seg = kernel_seg; - return (is); + return is; } } //namespace CGAL 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 532b2bf4dbd..5847dd43e02 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 @@ -7,7 +7,7 @@ // $Id$ // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial // -// Author(s) : Efi Fogel +// Author(s): Efi Fogel #ifndef CGAL_ARR_TRACING_TRAITS_H #define CGAL_ARR_TRACING_TRAITS_H @@ -26,6 +26,8 @@ #include #include +#include + #include #include #include @@ -592,7 +594,7 @@ public: public: /*! Construct */ - Intersect_2(const Base * base, bool enabled = true) : + Intersect_2(const Base* base, bool enabled = true) : m_object(base->intersect_2_object()), m_enabled(enabled) {} /*! Operate @@ -604,37 +606,41 @@ public: * multiplicity * \return the output iterator */ - template + template OutputIterator operator()(const X_monotone_curve_2 & xcv1, const X_monotone_curve_2 & xcv2, OutputIterator oi) const { - if (!m_enabled) return m_object(xcv1, xcv2, oi); + typedef std::pair Intersection_point; + typedef boost::variant + Intersection_result; + + if (! m_enabled) return m_object(xcv1, xcv2, oi); + std::cout << "intersect" << std::endl << " xcv1: " << xcv1 << std::endl << " xcv2: " << xcv2 << std::endl; - std::list container; + std::list container; m_object(xcv1, xcv2, std::back_inserter(container)); if (container.empty()) return oi; - std::list::iterator it; unsigned int i = 0; - for (it = container.begin(); it != container.end(); ++it) { - X_monotone_curve_2 xcv; - if (assign (xcv, *it)) { - std::cout << " result[" << i++ << "]: xcv: " << xcv << std::endl; + for (const auto& item : container) { + const X_monotone_curve_2* xcv = boost::get(&item); + if (xcv != nullptr) { + std::cout << " result[" << i++ << "]: xcv: " << *xcv << std::endl; continue; } - std::pair point_pair; - if (assign (point_pair, *it)) { - std::cout << " result[" << i++ << "]: p: " << point_pair.first - << ", multiplicity: " << point_pair.second << std::endl; + const Intersection_point* ip = boost::get(&item); + if (ip != nullptr) { + std::cout << " result[" << i++ << "]: p: " << ip->first + << ", multiplicity: " << ip->second << std::endl; continue; } } - for (it = container.begin(); it != container.end(); ++it) *oi++ = *it; + for (auto it = container.begin(); it != container.end(); ++it) *oi++ = *it; container.clear(); return oi; } diff --git a/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_zone_2_impl.h b/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_zone_2_impl.h index aa0532cde12..b3d8c63f5b2 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_zone_2_impl.h +++ b/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_zone_2_impl.h @@ -132,8 +132,8 @@ void Arrangement_zone_2::compute_zone() // In this case m_cv overlaps the curve associated with m_intersect_he. // Compute the overlapping subcurve. bool dummy; - m_obj = _compute_next_intersection(m_intersect_he, false, dummy); - m_overlap_cv = object_cast(m_obj); + auto obj = _compute_next_intersection(m_intersect_he, false, dummy); + m_overlap_cv = boost::get(*obj); // Remove the overlap from the map. _remove_next_intersection(m_intersect_he); @@ -148,8 +148,8 @@ void Arrangement_zone_2::compute_zone() m_intersect_he = m_arr.non_const_handle(*hh); bool dummy; - m_obj = _compute_next_intersection(m_intersect_he, false, dummy); - m_overlap_cv = object_cast(m_obj); + auto obj = _compute_next_intersection(m_intersect_he, false, dummy); + m_overlap_cv = boost::get(*obj); // Remove the overlap from the map. _remove_next_intersection(m_intersect_he); @@ -207,8 +207,8 @@ void Arrangement_zone_2::compute_zone() // In this case m_cv overlaps the curve associated with m_intersect_he. // Compute the overlapping subcurve to the right of curr_v. bool dummy; - m_obj = _compute_next_intersection(m_intersect_he, false, dummy); - m_overlap_cv = object_cast(m_obj); + auto obj = _compute_next_intersection(m_intersect_he, false, dummy); + m_overlap_cv = boost::get(*obj); // Remove the overlap from the map. _remove_next_intersection(m_intersect_he); @@ -800,7 +800,7 @@ _direct_intersecting_edge_to_left(const X_monotone_curve_2& cv_ins, // Get the next intersection of cv with the given halfedge. // template -CGAL::Object +typename Arrangement_zone_2::Optional_intersection Arrangement_zone_2:: _compute_next_intersection(Halfedge_handle he, bool skip_first_point, @@ -811,7 +811,7 @@ _compute_next_intersection(Halfedge_handle he, // Try to locate the intersections with this curve in the intersections map. Intersect_map_iterator iter = m_inter_map.find(p_curve); - const Intersect_point_2* ip; + const Intersection_point* ip; const X_monotone_curve_2* icv; bool valid_intersection; @@ -821,13 +821,13 @@ _compute_next_intersection(Halfedge_handle he, // Retrieve the intersections list from the map. Intersect_list& inter_list = iter->second; - if (inter_list.empty()) return CGAL::Object(); + if (inter_list.empty()) return Optional_intersection(); // Locate the first intersection that lies to the right of m_left_pt // (if the left point exists). while (! inter_list.empty()) { // Compare that current object with m_left_pt (if exists). - ip = object_cast(&(inter_list.front())); + ip = boost::get(&(inter_list.front())); if (m_left_on_boundary) { // The left end lie on the left boundary, so all intersections are @@ -851,7 +851,7 @@ _compute_next_intersection(Halfedge_handle he, } else { // We have an overlapping subcurve. - icv = object_cast(&(inter_list.front())); + icv = boost::get(&(inter_list.front())); CGAL_assertion(icv != nullptr); if (m_geom_traits->is_closed_2_object()(*icv, ARR_MIN_END)) { @@ -869,14 +869,14 @@ _compute_next_intersection(Halfedge_handle he, } // Found an intersection to m_left_pt's right. - if (valid_intersection) return (inter_list.front()); + if (valid_intersection) return Optional_intersection(inter_list.front()); // Discard the current intersection, which lies to m_left_pt's left. inter_list.pop_front(); } // If we reached here, the list of intersections is empty: - return CGAL::Object(); + return Optional_intersection(); } // The intersections with the curve have not been computed yet, so we @@ -894,7 +894,7 @@ _compute_next_intersection(Halfedge_handle he, // Discard all intersection lying to the left of m_left_pt (if exists). while (! inter_list.empty()) { // Compare that current object with m_left_pt (if exists). - ip = object_cast(&(inter_list.front())); + ip = boost::get(&(inter_list.front())); if (ip != nullptr) { // We have a simple intersection point - if we don't have to skip it, @@ -920,7 +920,7 @@ _compute_next_intersection(Halfedge_handle he, } else { // We have an overlapping subcurve. - icv = object_cast(&(inter_list.front())); + icv = boost::get(&(inter_list.front())); CGAL_assertion(icv != nullptr); if (m_geom_traits->is_closed_2_object()(*icv, ARR_MIN_END)) { @@ -947,8 +947,8 @@ _compute_next_intersection(Halfedge_handle he, m_inter_map[p_curve] = inter_list; // Return the first intersection object computed (may be empty). - if (inter_list.empty()) return CGAL::Object(); - else return (inter_list.front()); + if (inter_list.empty()) return Optional_intersection(); + else return Optional_intersection(inter_list.front()); } //----------------------------------------------------------------------------- @@ -1105,14 +1105,14 @@ _leftmost_intersection(Ccb_halfedge_circulator he_curr, bool on_boundary, // Compute the next intersection of m_cv and the current halfedge. bool intersection_on_right_boundary; - CGAL::Object iobj = + Optional_intersection iobj = _compute_next_intersection(he_curr, left_equals_curr_endpoint, intersection_on_right_boundary); - if (! iobj.is_empty()) { + if (iobj) { // We have found an intersection (either a simple point or an // overlapping x-monotone curve). - const Intersect_point_2* int_p = object_cast(&iobj); + const Intersection_point* int_p = boost::get(&*iobj); if (int_p != nullptr) { Point_2 ip = int_p->first; @@ -1134,7 +1134,7 @@ _leftmost_intersection(Ccb_halfedge_circulator he_curr, bool on_boundary, else { // We have located an overlapping curve. Assign ip as its left // endpoint. - const X_monotone_curve_2* icv = object_cast(&iobj); + const X_monotone_curve_2* icv = boost::get(&*iobj); CGAL_assertion(icv != nullptr); Point_2 ip = min_vertex(*icv); diff --git a/Arrangement_on_surface_2/include/CGAL/Arrangement_zone_2.h b/Arrangement_on_surface_2/include/CGAL/Arrangement_zone_2.h index b3d39acaf46..55616307cd0 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arrangement_zone_2.h +++ b/Arrangement_on_surface_2/include/CGAL/Arrangement_zone_2.h @@ -93,22 +93,25 @@ protected: Right_side_category>::result Are_all_sides_oblivious_category; - typedef typename Arrangement_2::Vertex_const_handle Vertex_const_handle; - typedef typename Arrangement_2::Halfedge_const_handle Halfedge_const_handle; - typedef typename Arrangement_2::Face_const_handle Face_const_handle; + typedef typename Arrangement_2::Vertex_const_handle Vertex_const_handle; + typedef typename Arrangement_2::Halfedge_const_handle Halfedge_const_handle; + typedef typename Arrangement_2::Face_const_handle Face_const_handle; typedef typename Arrangement_2::Ccb_halfedge_circulator Ccb_halfedge_circulator; // Types used for caching intersection points: - typedef std::pair Intersect_point_2; - typedef std::list Intersect_list; + typedef std::pair Intersection_point; + typedef boost::variant + Intersection_result; + typedef boost::optional Optional_intersection; + typedef std::list Intersect_list; typedef std::map - Intersect_map; - typedef typename Intersect_map::iterator Intersect_map_iterator; + Intersect_map; + typedef typename Intersect_map::iterator Intersect_map_iterator; - typedef std::set Curves_set; - typedef typename Curves_set::iterator Curves_set_iterator; + typedef std::set Curves_set; + typedef typename Curves_set::iterator Curves_set_iterator; // Data members: Arrangement_2& m_arr; // The associated arrangement. @@ -378,14 +381,15 @@ private: * point coincides with the right * curve-end, which lies on the * surface boundary. - * \return An object representing the next intersection: Intersect_point_2 + * \return An object representing the next intersection: Intersection_point * in case of a simple intersection point, X_monotone_curve_2 in * case of an overlap, and an empty object if there is no * intersection. */ - CGAL::Object _compute_next_intersection(Halfedge_handle he, - bool skip_first_point, - bool& intersect_on_right_boundary); + Optional_intersection + _compute_next_intersection(Halfedge_handle he, + bool skip_first_point, + bool& intersect_on_right_boundary); /*! Remove the next intersection of m_cv with the given halfedge from the map. * \param he A handle to the halfedge. diff --git a/Arrangement_on_surface_2/include/CGAL/Curved_kernel_via_analysis_2/Curved_kernel_via_analysis_2_functors.h b/Arrangement_on_surface_2/include/CGAL/Curved_kernel_via_analysis_2/Curved_kernel_via_analysis_2_functors.h index adb833f663a..de6f2e14529 100644 --- a/Arrangement_on_surface_2/include/CGAL/Curved_kernel_via_analysis_2/Curved_kernel_via_analysis_2_functors.h +++ b/Arrangement_on_surface_2/include/CGAL/Curved_kernel_via_analysis_2/Curved_kernel_via_analysis_2_functors.h @@ -1459,29 +1459,24 @@ public: OutputIterator operator()(const Arc_2& cv1, const Arc_2& cv2, OutputIterator oi) const { + typedef unsigned int Multiplicity; + typedef std::pair Intersection_point; + typedef boost::variant Intersection_result; + CERR("\nintersect; cv1: " << cv1 << ";\n cv2:" << cv2 << ""); // if arcs overlap, just store their common part, otherwise compute // point-wise intersections - std::vector< Arc_2 > common_arcs; - if (cv1._trim_if_overlapped(cv2, std::back_inserter(common_arcs))) { - typename std::vector< Arc_2 >::const_iterator it; - for(it = common_arcs.begin(); it < common_arcs.end(); it++) { - *oi++ = CGAL::make_object(*it); - } + std::vector arcs; + if (cv1._trim_if_overlapped(cv2, std::back_inserter(arcs))) { + for (const auto& item : arcs) *oi++ = Intersection_result(item); return oi; } // process non-ov erlapping case - typedef std::pair< Point_2, unsigned int > Point_and_mult; - typedef std::vector< Point_and_mult > Point_vector; - Point_vector vec; - typename Point_vector::const_iterator it; + std::vector vec; Arc_2::_intersection_points(cv1, cv2, std::back_inserter(vec)); - - for (it = vec.begin(); it != vec.end(); it++) { - *oi++ = CGAL::make_object(*it); - } + for (const auto& item : vec) *oi++ = Intersection_result(item); return oi; } diff --git a/Arrangement_on_surface_2/include/CGAL/Surface_sweep_2/Arr_insertion_traits_2.h b/Arrangement_on_surface_2/include/CGAL/Surface_sweep_2/Arr_insertion_traits_2.h index ba2e709c6cf..73d7f3b0326 100644 --- a/Arrangement_on_surface_2/include/CGAL/Surface_sweep_2/Arr_insertion_traits_2.h +++ b/Arrangement_on_surface_2/include/CGAL/Surface_sweep_2/Arr_insertion_traits_2.h @@ -80,17 +80,13 @@ public: protected: //! The base operators. Base_intersect_2 m_base_intersect; - Halfedge_handle invalid_he; /*! Constructor. * The constructor is declared private to allow only the functor * obtaining function, which is a member of the nesting class, * constructing it. */ - Intersect_2(const Base_intersect_2& base) : - m_base_intersect (base), - invalid_he() - {} + Intersect_2(const Base_intersect_2& base) : m_base_intersect (base) {} //! Allow its functor obtaining function calling the private constructor. friend class Arr_insertion_traits_2; @@ -101,6 +97,14 @@ public: const X_monotone_curve_2& cv2, OutputIterator oi) { + typedef std::pair Intersection_point; + typedef boost::variant + Intersection_result; + typedef boost::variant + Intersection_base_result; + + Halfedge_handle invalid_he; + if ((cv1.halfedge_handle() != invalid_he) && (cv2.halfedge_handle() != invalid_he) && (cv1.halfedge_handle() != cv2.halfedge_handle())) @@ -110,40 +114,32 @@ public: return oi; } - OutputIterator oi_end = m_base_intersect(cv1.base(), cv2.base(), oi); - const Base_x_monotone_curve_2* base_overlap_cv; - const std::pair* intersect_p; - + std::vector xections; + m_base_intersect(cv1.base(), cv2.base(), std::back_inserter(xections)); // convert objects that are associated with Base_x_monotone_curve_2 to // X_monotone_curve_2 - for(; oi != oi_end; ++oi) { - base_overlap_cv = object_cast(&(*oi)); - if (base_overlap_cv != nullptr) { - // Add halfedge handles to the resulting curve. - Halfedge_handle he; - - if (cv1.halfedge_handle() != invalid_he) he = cv1.halfedge_handle(); - else if (cv2.halfedge_handle() != invalid_he) - he = cv2.halfedge_handle(); - - X_monotone_curve_2 overlap_cv (*base_overlap_cv, he); - - overlap_cv.set_overlapping(); - *oi = make_object (overlap_cv); + for (const auto& xection : xections) { + const Intersection_point* + p_p = boost::get(&xection); + if (p_p != nullptr) { + *oi++ = Intersection_result(xection); + continue; } - else { - intersect_p = - object_cast >(&(*oi)); + const Base_x_monotone_curve_2* base_cv_p = + boost::get(&xection); + CGAL_assertion(base_cv_p); - CGAL_assertion (intersect_p != nullptr); - - *oi = make_object(std::make_pair(Point_2(intersect_p->first), - intersect_p->second)); - } + // Add halfedge handles to the resulting curve. + Halfedge_handle he; + if (cv1.halfedge_handle() != invalid_he) he = cv1.halfedge_handle(); + else if (cv2.halfedge_handle() != invalid_he) + he = cv2.halfedge_handle(); + X_monotone_curve_2 cv(*base_cv_p, he); + cv.set_overlapping(); + *oi++ = Intersection_result(cv); } - - // Return a past-the-end iterator. - return oi_end; + xections.clear(); + return oi; } }; diff --git a/Arrangement_on_surface_2/include/CGAL/Surface_sweep_2/Arr_overlay_traits_2.h b/Arrangement_on_surface_2/include/CGAL/Surface_sweep_2/Arr_overlay_traits_2.h index 8f6275e441d..c94ecf40913 100644 --- a/Arrangement_on_surface_2/include/CGAL/Surface_sweep_2/Arr_overlay_traits_2.h +++ b/Arrangement_on_surface_2/include/CGAL/Surface_sweep_2/Arr_overlay_traits_2.h @@ -345,24 +345,31 @@ public: class Intersect_2 { protected: //! The base traits. - const Arr_overlay_traits_2* m_traits; + const Arr_overlay_traits_2& m_traits; /*! Constructor. * The constructor is declared protected to allow only the functor * obtaining function, which is a member of the nesting class, * constructing it. */ - Intersect_2(const Arr_overlay_traits_2* traits) : m_traits(traits) {} + Intersect_2(const Arr_overlay_traits_2& traits) : m_traits(traits) {} //! Allow its functor obtaining function calling the protected constructor. friend class Arr_overlay_traits_2; public: - template + template OutputIterator operator()(const X_monotone_curve_2& xcv1, const X_monotone_curve_2& xcv2, OutputIterator oi) { + typedef std::pair Intersection_point; + typedef boost::variant + Intersection_result; + typedef std::pair Intersection_base_point; + typedef boost::variant + Intersection_base_result; + // In case the curves originate from the same arrangement, they are // obviously interior-disjoint. if (xcv1.color() == xcv2.color()) return oi; @@ -396,19 +403,16 @@ public: // Note that we do not bother with curves whose left ends are open, // since such curved did not intersect before. - const std::pair* base_ipt; - const Base_x_monotone_curve_2* overlap_xcv; bool send_xcv1_first = true; - OutputIterator oi_end; - Parameter_space_in_x_2 ps_x_op = m_traits->parameter_space_in_x_2_object(); - Parameter_space_in_y_2 ps_y_op = m_traits->parameter_space_in_y_2_object(); - const Arr_parameter_space bx1 = ps_x_op(xcv1, ARR_MIN_END); - const Arr_parameter_space by1 = ps_y_op(xcv1, ARR_MIN_END); - const Arr_parameter_space bx2 = ps_x_op(xcv2, ARR_MIN_END); - const Arr_parameter_space by2 = ps_y_op(xcv2, ARR_MIN_END); + auto ps_x_op = m_traits.parameter_space_in_x_2_object(); + auto ps_y_op = m_traits.parameter_space_in_y_2_object(); + Arr_parameter_space bx1 = ps_x_op(xcv1, ARR_MIN_END); + Arr_parameter_space by1 = ps_y_op(xcv1, ARR_MIN_END); + Arr_parameter_space bx2 = ps_x_op(xcv2, ARR_MIN_END); + Arr_parameter_space by2 = ps_y_op(xcv2, ARR_MIN_END); - const Gt2* m_base_tr = m_traits->base_traits(); + const Gt2* m_base_tr = m_traits.base_traits(); if ((bx1 == ARR_INTERIOR) && (by1 == ARR_INTERIOR) && (bx2 == ARR_INTERIOR) && (by2 == ARR_INTERIOR)) @@ -419,15 +423,17 @@ public: m_base_tr->construct_min_vertex_2_object()(xcv2.base())) == LARGER); } - oi_end = (send_xcv1_first) ? - m_base_tr->intersect_2_object()(xcv1.base(), xcv2.base(), oi) : - m_base_tr->intersect_2_object()(xcv2.base(), xcv1.base(), oi); + auto intersector = m_base_tr->intersect_2_object(); + std::vector xections; + (send_xcv1_first) ? + intersector(xcv1.base(), xcv2.base(), std::back_inserter(xections)) : + intersector(xcv2.base(), xcv1.base(), std::back_inserter(xections)); // Convert objects that are associated with Base_x_monotone_curve_2 to // the exteneded X_monotone_curve_2. - while (oi != oi_end) { - base_ipt = object_cast >(&(*oi)); - + for (const auto& xection : xections) { + const Intersection_base_point* base_ipt = + boost::get(&xection); if (base_ipt != nullptr) { // We have a red-blue intersection point, so we attach the // intersecting red and blue halfedges to it. @@ -451,42 +457,44 @@ public: // Create the extended point and add the multiplicity. Point_2 ex_point(base_ipt->first, red_cell, blue_cell); - *oi++ = CGAL::make_object(std::make_pair(ex_point, base_ipt->second)); + *oi++ = + Intersection_result(std::make_pair(ex_point, base_ipt->second)); + continue; + } + + const Base_x_monotone_curve_2* overlap_xcv = + boost::get(&xection); + CGAL_assertion(overlap_xcv != nullptr); + + // We have a red-blue overlap, so we mark the curve accordingly. + Halfedge_handle_red red_he; + Halfedge_handle_blue blue_he; + + if (xcv1.color() == RED) { + red_he = xcv1.red_halfedge_handle(); + + // Overlap can occur only between curves from a different color. + CGAL_assertion(xcv2.color() == BLUE); + blue_he = xcv2.blue_halfedge_handle(); } else { - overlap_xcv = object_cast(&(*oi)); - CGAL_assertion(overlap_xcv != nullptr); + CGAL_assertion((xcv1.color() == BLUE) && (xcv2.color() == RED)); - // We have a red-blue overlap, so we mark the curve accordingly. - Halfedge_handle_red red_he; - Halfedge_handle_blue blue_he; - - if (xcv1.color() == RED) { - red_he = xcv1.red_halfedge_handle(); - - // Overlap can occur only between curves from a different color. - CGAL_assertion(xcv2.color() == BLUE); - blue_he = xcv2.blue_halfedge_handle(); - } - else { - CGAL_assertion((xcv1.color() == BLUE) && (xcv2.color() == RED)); - - red_he = xcv2.red_halfedge_handle(); - blue_he = xcv1.blue_halfedge_handle(); - } - - *oi++ = CGAL::make_object(X_monotone_curve_2(*overlap_xcv, - red_he, blue_he)); + red_he = xcv2.red_halfedge_handle(); + blue_he = xcv1.blue_halfedge_handle(); } + + X_monotone_curve_2 cv(*overlap_xcv, red_he, blue_he); + *oi++ = Intersection_result(cv); } // Return the past-the-end iterator. - return oi_end; + return oi; } }; /*! Obtain an Intersect_2 functor object. */ - Intersect_2 intersect_2_object() const { return Intersect_2(this); } + Intersect_2 intersect_2_object() const { return Intersect_2(*this); } /*! A functor that splits an arc at a point. */ class Split_2 { diff --git a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Traits_test.h b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Traits_test.h index b69443c205d..a519c90b1e1 100644 --- a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Traits_test.h +++ b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Traits_test.h @@ -17,6 +17,7 @@ #include #include #include + #include "Traits_base_test.h" /*! Traits test */ @@ -989,18 +990,22 @@ intersect_wrapper(std::istringstream& str_stream) typedef typename Traits::X_monotone_curve_2 X_monotone_curve_2; typedef typename Traits::Multiplicity Multiplicity; + typedef std::pair Intersection_point; + typedef boost::variant + Intersection_result; + unsigned int id1, id2; str_stream >> id1 >> id2; - std::vector object_vec; + std::vector xections; this->m_geom_traits.intersect_2_object()(this->m_xcurves[id1], this->m_xcurves[id2], - std::back_inserter(object_vec)); + std::back_inserter(xections)); std::cout << "Test: intersect( " << this->m_xcurves[id1] << "," << this->m_xcurves[id2] << " ) ? "; size_t num; str_stream >> num; - if (!this->compare(num, object_vec.size(), "size")) return false; + if (! this->compare(num, xections.size(), "size")) return false; for (size_t i = 0; i < num; ++i) { unsigned int type; // 0 - point, 1 - x-monotone curve @@ -1011,30 +1016,25 @@ intersect_wrapper(std::istringstream& str_stream) if (type == 0) str_stream >> multiplicity; unsigned int exp_type = 1; - const X_monotone_curve_2 * xcv_ptr = - CGAL::object_cast (&(object_vec[i])); + const X_monotone_curve_2* cv_p = + boost::get(&(xections[i])); - if (xcv_ptr != NULL) { - if (!this->compare(type, exp_type, "type")) return false; - - if (!this->compare_curves(this->m_xcurves[id], *xcv_ptr)) return false; + if (cv_p != nullptr) { + if (! this->compare(type, exp_type, "type")) return false; + if (! this->compare_curves(this->m_xcurves[id], *cv_p)) return false; continue; } exp_type = 0; - typedef std::pair Point_2_pair; - const Point_2_pair * pt_pair_ptr = - CGAL::object_cast (&(object_vec[i])); - assert(pt_pair_ptr != NULL); - if (!this->compare(type, exp_type, "type")) return false; - if (!this->compare_points(this->m_points[id], (*pt_pair_ptr).first)) - return false; - if (!this->compare(multiplicity, (*pt_pair_ptr).second, "multiplicity")) - return false; - } //forloop - - object_vec.clear(); + const Intersection_point* p_p = + boost::get(&(xections[i])); + assert(p_p != nullptr); + if (! this->compare(type, exp_type, "type")) return false; + if (! this->compare_points(this->m_points[id], p_p->first)) return false; + if (! this->compare(multiplicity, p_p->second, "multiplicity")) return false; + } + xections.clear(); return true; } diff --git a/BGL/include/CGAL/boost/graph/copy_face_graph.h b/BGL/include/CGAL/boost/graph/copy_face_graph.h index dcd8c5cedbf..d63d7f61b5a 100644 --- a/BGL/include/CGAL/boost/graph/copy_face_graph.h +++ b/BGL/include/CGAL/boost/graph/copy_face_graph.h @@ -40,7 +40,6 @@ void copy_face_graph_impl(const SourceMesh& sm, TargetMesh& tm, { typedef typename boost::graph_traits::vertex_descriptor sm_vertex_descriptor; typedef typename boost::graph_traits::vertex_descriptor tm_vertex_descriptor; - typedef typename boost::graph_traits::halfedge_iterator tm_halfedge_iterator; typedef typename boost::graph_traits::face_descriptor sm_face_descriptor; typedef typename boost::graph_traits::face_descriptor tm_face_descriptor; @@ -64,14 +63,17 @@ void copy_face_graph_impl(const SourceMesh& sm, TargetMesh& tm, const tm_face_descriptor tm_null_face = boost::graph_traits::null_face(); const tm_vertex_descriptor tm_null_vertex = boost::graph_traits::null_vertex(); - reserve(tm, static_cast::vertices_size_type>(vertices(sm).size()), - static_cast::edges_size_type>(edges(sm).size()), - static_cast::faces_size_type>(faces(sm).size()) ); + reserve(tm, static_cast::vertices_size_type>(vertices(tm).size()+vertices(sm).size()), + static_cast::edges_size_type>(edges(tm).size()+edges(sm).size()), + static_cast::faces_size_type>(faces(tm).size()+faces(sm).size()) ); //insert halfedges and create each vertex when encountering its halfedge + std::vector new_edges; + new_edges.reserve(edges(sm).size()); for(sm_edge_descriptor sm_e : edges(sm)) { tm_edge_descriptor tm_e = add_edge(tm); + new_edges.push_back(tm_e); sm_halfedge_descriptor sm_h = halfedge(sm_e, sm), sm_h_opp = opposite(sm_h, sm); tm_halfedge_descriptor tm_h = halfedge(tm_e, tm), tm_h_opp = opposite(tm_h, tm); @@ -173,9 +175,10 @@ void copy_face_graph_impl(const SourceMesh& sm, TargetMesh& tm, } // detect if there are some non-manifold umbrellas and fix missing halfedge target pointers - for (tm_halfedge_iterator it=halfedges(tm).first; it!=halfedges(tm).second; ++it) + typedef typename std::vector::iterator edge_iterator; + for (edge_iterator it=new_edges.begin(); it!=new_edges.end(); ++it) { - if (target(*it, tm) == tm_null_vertex) + if (target(*it, tm) == tm_null_vertex || source(*it, tm) == tm_null_vertex) { // create and fill a map from target halfedge to source halfedge typedef CGAL::dynamic_halfedge_property_t Dyn_th_tag; @@ -183,17 +186,22 @@ void copy_face_graph_impl(const SourceMesh& sm, TargetMesh& tm, for (sm_halfedge_descriptor hs : halfedges(sm)) put(ht_to_hs, get(hs_to_ht, hs), hs); - for(; it!=halfedges(tm).second; ++it) + for(; it!=new_edges.end(); ++it) { - if (target(*it, tm) == tm_null_vertex) + tm_halfedge_descriptor nh_t = halfedge(*it, tm); + for (int i=0; i<2; ++i) { - // we recover tm_v using the halfedge associated to the target vertex of - // the halfedge in sm corresponding to *it. This is working because we - // set the vertex halfedge pointer to the "same" halfedges. - tm_vertex_descriptor tm_v = - target( get(hs_to_ht, halfedge(target(get(ht_to_hs, *it), sm), sm)), tm); - for(tm_halfedge_descriptor ht : halfedges_around_target(*it, tm)) - set_target(ht, tm_v, tm); + if (target(nh_t, tm) == tm_null_vertex) + { + // we recover tm_v using the halfedge associated to the target vertex of + // the halfedge in sm corresponding to nh_t. This is working because we + // set the vertex halfedge pointer to the "same" halfedges. + tm_vertex_descriptor tm_v = + target( get(hs_to_ht, halfedge(target(get(ht_to_hs, nh_t), sm), sm)), tm); + for(tm_halfedge_descriptor ht : halfedges_around_target(nh_t, tm)) + set_target(ht, tm_v, tm); + } + nh_t = opposite(nh_t, tm); } } break; diff --git a/BGL/include/CGAL/boost/graph/named_params_helper.h b/BGL/include/CGAL/boost/graph/named_params_helper.h index db7473882b9..d3cd5b68461 100644 --- a/BGL/include/CGAL/boost/graph/named_params_helper.h +++ b/BGL/include/CGAL/boost/graph/named_params_helper.h @@ -25,6 +25,8 @@ #include #include #include +#include + #include #include @@ -500,6 +502,18 @@ CGAL_DEF_GET_INITIALIZED_INDEX_MAP(face, typename boost::graph_traits::fa > ::type type; }; + template + class GetAdjacencies + { + public: + typedef Emptyset_iterator Empty; + typedef typename internal_np::Lookup_named_param_def < + internal_np::adjacencies_t, + NamedParameters, + Empty//default + > ::type type; + }; + } // namespace Point_set_processing_3 template diff --git a/BGL/include/CGAL/boost/graph/parameters_interface.h b/BGL/include/CGAL/boost/graph/parameters_interface.h index f857f3966ac..0ca726f6e31 100644 --- a/BGL/include/CGAL/boost/graph/parameters_interface.h +++ b/BGL/include/CGAL/boost/graph/parameters_interface.h @@ -148,6 +148,7 @@ CGAL_add_named_parameter(transformation_checkers_t, transformation_checkers, tra CGAL_add_named_parameter(inspector_t, inspector, inspector) CGAL_add_named_parameter(logger_t, logger, logger) CGAL_add_named_parameter(pointmatcher_config_t, pointmatcher_config, pointmatcher_config) +CGAL_add_named_parameter(adjacencies_t, adjacencies, adjacencies) // List of named parameters used in Surface_mesh_approximation package CGAL_add_named_parameter(verbose_level_t, verbose_level, verbose_level) @@ -166,6 +167,12 @@ CGAL_add_named_parameter(with_dihedral_angle_t, with_dihedral_angle, with_dihedr CGAL_add_named_parameter(optimize_anchor_location_t, optimize_anchor_location, optimize_anchor_location) CGAL_add_named_parameter(pca_plane_t, pca_plane, pca_plane) +// tetrahedral remeshing parameters +CGAL_add_named_parameter(remesh_boundaries_t, remesh_boundaries, remesh_boundaries) +CGAL_add_named_parameter(cell_selector_t, cell_selector, cell_selector) +CGAL_add_named_parameter(facet_is_constrained_t, facet_is_constrained, facet_is_constrained_map) +CGAL_add_named_parameter(remeshing_visitor_t, remeshing_visitor, remeshing_visitor) + // output parameters CGAL_add_named_parameter(face_proxy_map_t, face_proxy_map, face_proxy_map) CGAL_add_named_parameter(proxies_t, proxies, proxies) @@ -177,4 +184,3 @@ CGAL_add_named_parameter(accuracy_t, accuracy, accuracy) CGAL_add_named_parameter(maximum_running_time_t, maximum_running_time, maximum_running_time) CGAL_add_named_parameter(overlap_t, overlap, overlap) CGAL_add_named_parameter(maximum_normal_deviation_t, maximum_normal_deviation, maximum_normal_deviation) - diff --git a/Boolean_set_operations_2/doc/Boolean_set_operations_2/Concepts/ArrDirectionalTraits--Intersect_2.h b/Boolean_set_operations_2/doc/Boolean_set_operations_2/Concepts/ArrDirectionalTraits--Intersect_2.h index 4d09d1f41e3..76efa0e5073 100644 --- a/Boolean_set_operations_2/doc/Boolean_set_operations_2/Concepts/ArrDirectionalTraits--Intersect_2.h +++ b/Boolean_set_operations_2/doc/Boolean_set_operations_2/Concepts/ArrDirectionalTraits--Intersect_2.h @@ -16,24 +16,23 @@ public: /// A model of this concept must provide: /// @{ -/*! -computes the intersections of `xc1` and `xc2` and -inserts them in an ascending lexicographic \f$ xy\f$-order into the -output iterator `oi`. The value-type of `Output_iterator` is -`CGAL::Object`, where each `Object` wraps either a -`pair` object, which -represents an intersection point with its multiplicity (in case the -multiplicity is undefined or unknown, it is set to \f$ 0\f$) or an -`ArrDirectionalTraits::X_monotone_curve_2` object, representing an -overlapping subcurve of `xc1` and `xc2`. In the latter case, -the overlapping subcurves are given the direction of `xc1` and -`xc2` if their directions are identical. Otherwise, the overlapping -subcurves are given an arbitrary direction. The operator returns a -past-the-end iterator for the output sequence. -*/ -Output_iterator operator()(ArrDirectionalTraits::X_monotone_curve_2 xc1, -ArrDirectionalTraits::X_monotone_curve_2 xc2, -Output_iterator& oi); +/*! computes the intersections of `xc1` and `xc2` and inserts them in an + * ascending lexicographic \f$ xy\f$-order into a range begining at + * `oi`. The type `OutputIterator` dereferences a `boost::variant` of either the + * type `pair` or the type + * `ArrDirectionalTraits::X_monotone_curve_2`. An object of the former type + * represents an intersection point with its multiplicity (in case the + * multiplicity is undefined or unknown, it is set to \f$ 0\f$). An object of + * the latter type representing an overlapping subcurve of `xc1` and `xc2`. The + * overlapping subcurves are given the direction of `xc1` and `xc2` if their + * directions are identical. Otherwise, the overlapping subcurves are given an + * arbitrary direction. The operator returns a past-the-end iterator of the + * destination range. + */ +OutputIterator operator()(ArrDirectionalTraits::X_monotone_curve_2 xc1, + ArrDirectionalTraits::X_monotone_curve_2 xc2, + Output_iterator& oi); /// @} diff --git a/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Gps_agg_meta_traits.h b/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Gps_agg_meta_traits.h index 854f90f70c3..5d062639df6 100644 --- a/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Gps_agg_meta_traits.h +++ b/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Gps_agg_meta_traits.h @@ -8,7 +8,8 @@ // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial // // -// Author(s) : Baruch Zukerman +// Author(s): Baruch Zukerman +// Efi Fogel #ifndef CGAL_BSO_2_GPS_AGG_META_TRAITS_H #define CGAL_BSO_2_GPS_AGG_META_TRAITS_H @@ -81,8 +82,8 @@ class Gps_agg_meta_traits : typedef typename Arr::Traits_adaptor_2 Traits; typedef Traits Gt2; - typedef typename Gt2::X_monotone_curve_2 Base_X_monotone_curve_2; - typedef typename Gt2::Point_2 Base_Point_2; + typedef typename Gt2::X_monotone_curve_2 Base_x_monotone_curve_2; + typedef typename Gt2::Point_2 Base_point_2; typedef typename Gt2::Construct_min_vertex_2 Base_Construct_min_vertex_2; typedef typename Gt2::Construct_max_vertex_2 Base_Construct_max_vertex_2; typedef typename Gt2::Compare_endpoints_xy_2 Base_Compare_endpoints_xy_2; @@ -106,8 +107,8 @@ public: typedef Point_with_vertex Point_data; private: - typedef Gps_traits_decorator - Base; + typedef Gps_agg_meta_traits Self; + typedef Gps_traits_decorator Base; public: typedef typename Base::X_monotone_curve_2 X_monotone_curve_2; @@ -145,93 +146,88 @@ public: class Intersect_2 { private: - Base_Intersect_2 m_base; - Base_Compare_endpoints_xy_2 m_base_cmp_endpoints; - Base_Compare_xy_2 m_base_cmp_xy; - Base_Construct_min_vertex_2 m_base_ctr_min_v; + const Self& m_traits; + + /*! Constructor. */ + Intersect_2(const Self& traits) : m_traits(traits) {} + + friend Self; public: - /*! Construct. */ - Intersect_2(const Base_Intersect_2& base, - const Base_Compare_endpoints_xy_2& base_cmp_endpoints, - const Base_Compare_xy_2& base_cmp_xy, - const Base_Construct_min_vertex_2& base_ctr_min_v) : - m_base(base), - m_base_cmp_endpoints(base_cmp_endpoints), - m_base_cmp_xy(base_cmp_xy), - m_base_ctr_min_v(base_ctr_min_v) - {} - template OutputIterator operator()(const X_monotone_curve_2& cv1, const X_monotone_curve_2& cv2, OutputIterator oi) const { - if (cv1.data().arr() == cv2.data().arr()) { - return oi; // the curves are disjoint-interior because they - // are already at the same arrangement. - } + // Check whether the curves are already in the same arrangement, and thus + // must be interior-disjoint + if (cv1.data().arr() == cv2.data().arr()) return oi; - const std::pair* base_pt; - const Base_X_monotone_curve_2* overlap_cv; - OutputIterator oi_end; - if(m_base_cmp_xy(m_base_ctr_min_v(cv1.base()), - m_base_ctr_min_v(cv2.base())) == LARGER) - oi_end = m_base(cv1.base(), cv2.base(), oi); + typedef const std::pair + Intersection_base_point; + typedef boost::variant + Intersection_base_result; + typedef const std::pair Intersection_point; + typedef boost::variant + Intersection_result; + + const auto* base_traits = m_traits.m_base_traits; + auto base_cmp_xy = base_traits->compare_xy_2_object(); + auto base_cmp_endpoints = base_traits->compare_endpoints_xy_2_object(); + auto base_ctr_min_vertex = base_traits->construct_min_vertex_2_object(); + auto base_intersect = base_traits->intersect_2_object(); + + std::vector xections; + if (base_cmp_xy(base_ctr_min_vertex(cv1.base()), + base_ctr_min_vertex(cv2.base())) == LARGER) + base_intersect(cv1.base(), cv2.base(), back_inserter(xections)); else - oi_end = m_base(cv2.base(), cv1.base(), oi); + base_intersect(cv2.base(), cv1.base(), back_inserter(xections)); - // convert objects that are associated with Base_X_monotone_curve_2 to + // convert objects that are associated with Base_x_monotone_curve_2 to // the extenede X_monotone_curve_2 - for (; oi != oi_end; ++oi) { - base_pt = object_cast >(&(*oi)); - + for (const auto& xection : xections) { + const Intersection_base_point* base_pt = + boost::get(&xection); if (base_pt != nullptr) { Point_2 point_plus(base_pt->first); // the extended point - *oi = CGAL::make_object(std::make_pair(point_plus, - base_pt->second)); + *oi++ = + Intersection_result(std::make_pair(point_plus, base_pt->second)); + continue; + } + + const Base_x_monotone_curve_2* overlap_cv = + boost::get(&xection); + CGAL_assertion(overlap_cv != nullptr); + unsigned int ov_bc; + unsigned int ov_twin_bc; + if (base_cmp_endpoints(cv1) == base_cmp_endpoints(cv2)) { + // cv1 and cv2 have the same directions + ov_bc = cv1.data().bc() + cv2.data().bc(); + ov_twin_bc = cv1.data().twin_bc() + cv2.data().twin_bc(); } else { - overlap_cv = object_cast(&(*oi)); - - if (overlap_cv != nullptr) { - unsigned int ov_bc; - unsigned int ov_twin_bc; - if (m_base_cmp_endpoints(cv1) == m_base_cmp_endpoints(cv2)) { - // cv1 and cv2 have the same directions - ov_bc = cv1.data().bc() + cv2.data().bc(); - ov_twin_bc = cv1.data().twin_bc() + cv2.data().twin_bc(); - } - else { - // cv1 and cv2 have opposite directions - ov_bc = cv1.data().bc() + cv2.data().twin_bc(); - ov_twin_bc = cv1.data().twin_bc() + cv2.data().bc(); - } - - if(m_base_cmp_endpoints(*overlap_cv) != m_base_cmp_endpoints(cv1)) { - // overlap_cv, cv1 have opposite directions - std::swap(ov_bc, ov_twin_bc); - } - - Curve_data cv_data(cv1.data().arr(), Halfedge_handle(), - ov_bc, ov_twin_bc); - *oi = CGAL::make_object(X_monotone_curve_2(*overlap_cv, cv_data)); - } + // cv1 and cv2 have opposite directions + ov_bc = cv1.data().bc() + cv2.data().twin_bc(); + ov_twin_bc = cv1.data().twin_bc() + cv2.data().bc(); } + + if (base_cmp_endpoints(*overlap_cv) != base_cmp_endpoints(cv1)) { + // overlap_cv, cv1 have opposite directions + std::swap(ov_bc, ov_twin_bc); + } + + Curve_data cv_data(cv1.data().arr(), Halfedge_handle(), + ov_bc, ov_twin_bc); + *oi++ = Intersection_result(X_monotone_curve_2(*overlap_cv, cv_data)); } - //return past-end iterator - return oi_end; + + return oi; } }; /*! Obtain an Intersect_2 functor object. */ - Intersect_2 intersect_2_object() const - { - return Intersect_2(this->m_base_tr->intersect_2_object(), - this->m_base_tr->compare_endpoints_xy_2_object(), - this->m_base_tr->compare_xy_2_object(), - this->m_base_tr->construct_min_vertex_2_object()); - } + Intersect_2 intersect_2_object() const { return Intersect_2(*this); } class Split_2 { private: @@ -256,7 +252,7 @@ public: /*! Obtain a Split_2 functor object. */ Split_2 split_2_object() const - { return Split_2(this->m_base_tr->split_2_object()); } + { return Split_2(this->m_base_traits->split_2_object()); } class Construct_min_vertex_2 { private: @@ -286,7 +282,7 @@ public: /*! Get a Construct_min_vertex_2 functor object. */ Construct_min_vertex_2 construct_min_vertex_2_object() const { - return Construct_min_vertex_2(this->m_base_tr-> + return Construct_min_vertex_2(this->m_base_traits-> construct_min_vertex_2_object()); } @@ -318,7 +314,7 @@ public: /*! Get a Construct_min_vertex_2 functor object. */ Construct_max_vertex_2 construct_max_vertex_2_object() const { - return Construct_max_vertex_2(this->m_base_tr-> + return Construct_max_vertex_2(this->m_base_traits-> construct_max_vertex_2_object()); } @@ -348,7 +344,7 @@ public: /*! Obtain a Construct_min_vertex_2 functor object. */ Compare_xy_2 compare_xy_2_object() const - { return Compare_xy_2(this->m_base_tr->compare_xy_2_object()); } + { return Compare_xy_2(this->m_base_traits->compare_xy_2_object()); } // left-right class Parameter_space_in_x_2 { @@ -380,7 +376,7 @@ public: /*! Obtain a Construct_min_vertex_2 functor object. */ Parameter_space_in_x_2 parameter_space_in_x_2_object() const { - return Parameter_space_in_x_2(this->m_base_tr-> + return Parameter_space_in_x_2(this->m_base_traits-> parameter_space_in_x_2_object()); } @@ -404,7 +400,7 @@ public: /*! Obtain a Construct_min_vertex_2 functor object. */ Compare_y_near_boundary_2 compare_y_near_boundary_2_object() const { - return Compare_y_near_boundary_2(this->m_base_tr-> + return Compare_y_near_boundary_2(this->m_base_traits-> compare_y_near_boundary_2_object() ); } @@ -443,7 +439,7 @@ public: /*! Obtain a Construct_min_vertex_2 functor object. */ Parameter_space_in_y_2 parameter_space_in_y_2_object() const { - return Parameter_space_in_y_2(this->m_base_tr-> + return Parameter_space_in_y_2(this->m_base_traits-> parameter_space_in_y_2_object()); } @@ -476,7 +472,7 @@ public: /*! Obtain a Construct_min_vertex_2 functor object. */ Compare_x_near_boundary_2 compare_x_near_boundary_2_object() const { - return Compare_x_near_boundary_2(this->m_base_tr-> + return Compare_x_near_boundary_2(this->m_base_traits-> compare_x_near_boundary_2_object()); } diff --git a/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Gps_insertion_meta_traits.h b/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Gps_insertion_meta_traits.h index 2c1557a2619..bbf2835fb68 100644 --- a/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Gps_insertion_meta_traits.h +++ b/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Gps_insertion_meta_traits.h @@ -75,7 +75,7 @@ public: Construct_min_vertex_2 construct_min_vertex_2_object () const { return Construct_min_vertex_2 - (this->m_base_tr->construct_min_vertex_2_object()); + (this->m_base_traits->construct_min_vertex_2_object()); } @@ -100,7 +100,7 @@ public: Construct_max_vertex_2 construct_max_vertex_2_object () const { return Construct_max_vertex_2 - (this->m_base_tr->construct_max_vertex_2_object()); + (this->m_base_traits->construct_max_vertex_2_object()); } class Compare_xy_2 @@ -123,7 +123,7 @@ public: /*! Get a Compare_xy_2 functor object. */ Compare_xy_2 compare_xy_2_object () const { - return Compare_xy_2(m_base_tr->compare_xy_2_object()); + return Compare_xy_2(m_base_traits->compare_xy_2_object()); } }; diff --git a/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Gps_simplifier_traits.h b/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Gps_simplifier_traits.h index 48b969adea8..fdc111751de 100644 --- a/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Gps_simplifier_traits.h +++ b/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Gps_simplifier_traits.h @@ -8,7 +8,8 @@ // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial // // -// Author(s) : Baruch Zukerman +// Author(s): Baruch Zukerman +// Efi Fogel #ifndef CGAL_GPS_SIMPLIFIER_TRAITS_H #define CGAL_GPS_SIMPLIFIER_TRAITS_H @@ -20,103 +21,67 @@ namespace CGAL { -class Gps_simplifier_curve_data -{ +class Gps_simplifier_curve_data { protected: unsigned int m_bc; unsigned int m_twin_bc; unsigned int m_index; public: - Gps_simplifier_curve_data() - {} + Gps_simplifier_curve_data() {} - Gps_simplifier_curve_data(unsigned int bc, - unsigned int twin_bc, + Gps_simplifier_curve_data(unsigned int bc, unsigned int twin_bc, unsigned int index): m_bc(bc), m_twin_bc(twin_bc), m_index(index) {} - unsigned int bc() const - { - return m_bc; - } + unsigned int bc() const { return m_bc; } - unsigned int twin_bc() const - { - return m_twin_bc; - } + unsigned int twin_bc() const { return m_twin_bc; } - unsigned int index() const - { - return m_index; - } + unsigned int index() const { return m_index; } - unsigned int& index() - { - return m_index; - } + unsigned int& index() { return m_index; } - unsigned int& twin_bc() - { - return m_twin_bc; - } + unsigned int& twin_bc() { return m_twin_bc; } - void set_bc(unsigned int bc) - { - m_bc = bc; - } + void set_bc(unsigned int bc) { m_bc = bc; } - void set_twin_bc(unsigned int twin_bc) - { - m_twin_bc = twin_bc; - } + void set_twin_bc(unsigned int twin_bc) { m_twin_bc = twin_bc; } - void set_index(unsigned int index) - { - m_index = index; - } + void set_index(unsigned int index) { m_index = index; } }; -struct Gps_simplifier_point_data -{ +struct Gps_simplifier_point_data { protected: unsigned int m_index; public: - Gps_simplifier_point_data() - {} + Gps_simplifier_point_data() {} - Gps_simplifier_point_data(unsigned int index) : m_index(index) - {} + Gps_simplifier_point_data(unsigned int index) : m_index(index) {} - unsigned int index() const - { - return m_index; - } + unsigned int index() const { return m_index; } - void set_index(unsigned int index) - { - m_index = index; - } + void set_index(unsigned int index) { m_index = index; } }; -template +template class Gps_simplifier_traits : public Gps_traits_decorator { public: - typedef Traits_ Traits; + typedef Traits_ Traits; typedef Gps_traits_decorator Base; - typedef Gps_simplifier_traits Self; - typedef typename Traits::X_monotone_curve_2 Base_X_monotone_curve_2; - typedef typename Traits::Point_2 Base_Point_2; + Gps_simplifier_point_data> Base; + typedef Gps_simplifier_traits Self; + typedef typename Traits::X_monotone_curve_2 Base_x_monotone_curve_2; + typedef typename Traits::Point_2 Base_point_2; typedef typename Traits::Construct_min_vertex_2 Base_Construct_min_vertex_2; typedef typename Traits::Construct_max_vertex_2 Base_Construct_max_vertex_2; typedef typename Traits::Compare_endpoints_xy_2 Base_Compare_endpoints_xy_2; @@ -129,9 +94,7 @@ public: protected: mutable unsigned int m_pgn_size; - public: - typedef typename Base::X_monotone_curve_2 X_monotone_curve_2; typedef typename Base::Point_2 Point_2; typedef typename Base::Multiplicity Multiplicity; @@ -139,333 +102,256 @@ public: typedef typename Base::Curve_data Curve_data; typedef typename Base::Point_data Point_data; - Gps_simplifier_traits() - {} + Gps_simplifier_traits() {} - Gps_simplifier_traits(const Traits & tr) : Base(tr) - {} + Gps_simplifier_traits(const Traits& tr) : Base(tr) {} - unsigned int polygon_size() const - { - return m_pgn_size; - } + unsigned int polygon_size() const { return m_pgn_size; } - void set_polygon_size(unsigned int pgn_size) const - { - m_pgn_size = pgn_size; - } + void set_polygon_size(unsigned int pgn_size) const { m_pgn_size = pgn_size; } bool is_valid_index(unsigned int index) const - { - return (index < m_pgn_size); - } + { return (index < m_pgn_size); } - unsigned int invalid_index() const - { - return (m_pgn_size); - } + unsigned int invalid_index() const { return (m_pgn_size); } - - class Intersect_2 - { + class Intersect_2 { private: - - Base_Intersect_2 m_base; - Base_Compare_endpoints_xy_2 m_base_cmp_endpoints; - Base_Compare_xy_2 m_base_cmp_xy; - Base_Construct_min_vertex_2 m_ctr_min_v; - const Self * m_self_tr; - - public: + /*! The traits (in case it has state) */ + const Self& m_traits; /*! Constructor. */ - Intersect_2 (const Base_Intersect_2& base, - const Base_Compare_endpoints_xy_2& base_cmp_endpoints, - const Base_Compare_xy_2& base_cmp_xy, - const Base_Construct_min_vertex_2& , - const Self* tr) : - m_base(base), - m_base_cmp_endpoints(base_cmp_endpoints), - m_base_cmp_xy(base_cmp_xy), - m_self_tr(tr) - {} + Intersect_2(const Self& tr) : m_traits(tr) {} - template - OutputIterator operator() (const X_monotone_curve_2& cv1, - const X_monotone_curve_2& cv2, - OutputIterator oi) const + friend Self; + + public: + template + OutputIterator operator()(const X_monotone_curve_2& cv1, + const X_monotone_curve_2& cv2, + OutputIterator oi) const { + typedef const std::pair + Intersection_base_point; + typedef boost::variant + Intersection_base_result; + typedef const std::pair Intersection_point; + typedef boost::variant + Intersection_result; + + const auto* base_traits = m_traits.m_base_traits; + auto base_cmp_xy = base_traits->compare_xy_2_object(); + auto base_cmp_endpoints = base_traits->compare_endpoints_xy_2_object(); + auto base_ctr_min_vertex = base_traits->construct_min_vertex_2_object(); + auto base_intersect = base_traits->intersect_2_object(); + //// if the two curves are incident, do not intersect them - //if(m_self_tr->is_valid_index(cv1.data().index()) && - // m_self_tr->is_valid_index(cv2.data().index())) + //if (m_traits.is_valid_index(cv1.data().index()) && + // m_traits.is_valid_index(cv2.data().index())) //{ // unsigned int index_diff = // (cv1.data().index() > cv2.data().index()) ? // (cv1.data().index() - cv2.data().index()): // (cv2.data().index() - cv1.data().index()); - // if(index_diff == 1 ||index_diff == m_self_tr->polygon_size() -1) + // if(index_diff == 1 ||index_diff == m_traits.polygon_size() -1) // { // return (oi); // } //} - const std::pair *base_pt; - const Base_X_monotone_curve_2 *overlap_cv; - OutputIterator oi_end; - if(m_base_cmp_xy(m_ctr_min_v(cv1.base()), - m_ctr_min_v(cv2.base())) == LARGER) - oi_end = m_base(cv1.base(), cv2.base(), oi); + std::vector xections; + if (base_cmp_xy(base_ctr_min_vertex(cv1.base()), + base_ctr_min_vertex(cv2.base())) == LARGER) + base_intersect(cv1.base(), cv2.base(), back_inserter(xections)); else - oi_end = m_base(cv2.base(), cv1.base(), oi); + base_intersect(cv2.base(), cv1.base(), back_inserter(xections)); - // convert objects that are associated with Base_X_monotone_curve_2 to + // convert objects that are associated with Base_x_monotone_curve_2 to // the extenede X_monotone_curve_2 - for(; oi != oi_end; ++oi) - { - base_pt = object_cast >(&(*oi)); - - if (base_pt != nullptr) - { - Point_data pt_data(m_self_tr->invalid_index()); - Point_2 point_plus (base_pt->first, pt_data); // the extended point - *oi = CGAL::make_object(std::make_pair(point_plus, - base_pt->second)); + for (const auto& xection : xections) { + const Intersection_base_point* base_pt = + boost::get(&xection); + if (base_pt != nullptr) { + Point_data pt_data(m_traits.invalid_index()); + Point_2 point_plus(base_pt->first, pt_data); // the extended point + *oi++ = + Intersection_result(std::make_pair(point_plus, base_pt->second)); + continue; } - else - { - overlap_cv = object_cast (&(*oi)); - if (overlap_cv != nullptr) - { - unsigned int ov_bc; - unsigned int ov_twin_bc; - if(m_base_cmp_endpoints(cv1) == m_base_cmp_endpoints(cv2)) - { - // cv1 and cv2 have the same directions - ov_bc = cv1.data().bc() + cv2.data().bc(); - ov_twin_bc = cv1.data().twin_bc() + cv2.data().twin_bc(); - } - else - { - // cv1 and cv2 have opposite directions - ov_bc = cv1.data().bc() + cv2.data().twin_bc(); - ov_twin_bc = cv1.data().twin_bc() + cv2.data().bc(); - } + const Base_x_monotone_curve_2* overlap_cv = + boost::get(&xection); - if(m_base_cmp_endpoints(*overlap_cv) != m_base_cmp_endpoints(cv1)) - { - // overlap_cv, cv1 have opposite directions - std::swap(ov_bc, ov_twin_bc); - } - - Curve_data cv_data(ov_bc, ov_twin_bc, m_self_tr->invalid_index()); - *oi = CGAL::make_object (X_monotone_curve_2 (*overlap_cv, cv_data)); - } + CGAL_assertion(overlap_cv != nullptr); + unsigned int ov_bc; + unsigned int ov_twin_bc; + if (base_cmp_endpoints(cv1) == base_cmp_endpoints(cv2)) { + // cv1 and cv2 have the same directions + ov_bc = cv1.data().bc() + cv2.data().bc(); + ov_twin_bc = cv1.data().twin_bc() + cv2.data().twin_bc(); } + else { + // cv1 and cv2 have opposite directions + ov_bc = cv1.data().bc() + cv2.data().twin_bc(); + ov_twin_bc = cv1.data().twin_bc() + cv2.data().bc(); + } + + if (base_cmp_endpoints(*overlap_cv) != base_cmp_endpoints(cv1)) { + // overlap_cv, cv1 have opposite directions + std::swap(ov_bc, ov_twin_bc); + } + + Curve_data cv_data(ov_bc, ov_twin_bc, m_traits.invalid_index()); + *oi++ = Intersection_result(X_monotone_curve_2(*overlap_cv, cv_data)); } - //return past-end iterator - return oi_end; + + return oi; } }; - /*! Get an Intersect_2 functor object. */ - Intersect_2 intersect_2_object () const - { - return Intersect_2(this->m_base_tr->intersect_2_object(), - this->m_base_tr->compare_endpoints_xy_2_object(), - this->m_base_tr->compare_xy_2_object(), - this->m_base_tr->construct_min_vertex_2_object(), - this); - } + /*! Obtain an Intersect_2 functor object. */ + Intersect_2 intersect_2_object () const { return Intersect_2(*this); } - class Split_2 - { + class Split_2 { private: - Base_Split_2 m_base_split; - const Self * m_self_tr; - - public: + const Self& m_traits; /*! Constructor. */ - Split_2 (const Base_Split_2& base, const Self* tr) : - m_base_split(base), - m_self_tr(tr) - {} + Split_2(const Self& tr) : m_traits(tr) {} - void operator() (const X_monotone_curve_2& cv, const Point_2 & p, - X_monotone_curve_2& c1, X_monotone_curve_2& c2) const + friend Self; + + public: + void operator()(const X_monotone_curve_2& cv, const Point_2 & p, + X_monotone_curve_2& c1, X_monotone_curve_2& c2) const { - m_base_split(cv.base(), - p.base(), - c1.base(), - c2.base()); + const auto* base_traits = m_traits.m_base_traits; + auto base_split = base_traits->split_2_object(); + base_split(cv.base(), p.base(), c1.base(), c2.base()); const Curve_data& cv_data = cv.data(); - c1.set_data(Curve_data(cv_data.bc(), - cv_data.twin_bc(), - m_self_tr->invalid_index())); + c1.set_data(Curve_data(cv_data.bc(), cv_data.twin_bc(), + m_traits.invalid_index())); - c2.set_data(Curve_data(cv_data.bc(), - cv_data.twin_bc(), - m_self_tr->invalid_index())); + c2.set_data(Curve_data(cv_data.bc(), cv_data.twin_bc(), + m_traits.invalid_index())); } }; /*! Get a Split_2 functor object. */ - Split_2 split_2_object () const - { - return Split_2(this->m_base_tr->split_2_object(), this); - } + Split_2 split_2_object () const { return Split_2(*this); } - class Construct_min_vertex_2 - { + class Construct_min_vertex_2 { private: - Base_Construct_min_vertex_2 m_base; - Base_Compare_endpoints_xy_2 m_base_cmp_endpoints; - const Self * m_self_tr; + const Self& m_traits; + + Construct_min_vertex_2(const Self& tr) : m_traits(tr) {} + + friend Self; public: - - Construct_min_vertex_2(const Base_Construct_min_vertex_2& base, - const Base_Compare_endpoints_xy_2& base_cmp_endpoints, - const Self * tr): - m_base(base), - m_base_cmp_endpoints(base_cmp_endpoints), - m_self_tr(tr) - {} - - /*! - * Get the left endpoint of the x-monotone curve (segment). + /*! Obtain the left endpoint of the x-monotone curve (segment). * \param cv The curve. * \return The left endpoint. */ - Point_2 operator() (const X_monotone_curve_2 & cv) const + Point_2 operator()(const X_monotone_curve_2 & cv) const { - if(!m_self_tr->is_valid_index(cv.data().index())) - { - return Point_2 (m_base(cv.base()), m_self_tr->invalid_index()); - } + const auto* base_traits = m_traits.m_base_traits; + auto base_ctr_min_vertex = base_traits->construct_min_vertex_2_object(); - Comparison_result res = m_base_cmp_endpoints(cv); + if (! m_traits.is_valid_index(cv.data().index())) + return Point_2(base_ctr_min_vertex(cv.base()), m_traits.invalid_index()); + + auto base_cmp_endpoints = base_traits->compare_endpoints_xy_2_object(); + Comparison_result res = base_cmp_endpoints(cv); Point_data pt_data; - if(res == SMALLER) - { + if (res == SMALLER) { // min vertex is the source pt_data.set_index(cv.data().index()); } - else - { + else { // min vertex is the target - pt_data.set_index((cv.data().index() + 1) % m_self_tr->polygon_size()); + pt_data.set_index((cv.data().index() + 1) % m_traits.polygon_size()); } - return Point_2 (m_base(cv.base()), pt_data); + return Point_2(base_ctr_min_vertex(cv.base()), pt_data); } }; /*! Get a Construct_min_vertex_2 functor object. */ Construct_min_vertex_2 construct_min_vertex_2_object () const - { - return Construct_min_vertex_2 - (this->m_base_tr->construct_min_vertex_2_object(), - this->m_base_tr->compare_endpoints_xy_2_object(), - this); - } + { return Construct_min_vertex_2(*this); } - - class Construct_max_vertex_2 - { + class Construct_max_vertex_2 { private: - Base_Construct_max_vertex_2 m_base; - Base_Compare_endpoints_xy_2 m_base_cmp_endpoints; - const Self * m_self_tr; + const Self& m_traits; + + Construct_max_vertex_2(const Self& tr) : m_traits(tr) {} + + friend Self; public: - - Construct_max_vertex_2(const Base_Construct_max_vertex_2& base, - const Base_Compare_endpoints_xy_2& base_cmp_endpoints, - const Self * tr): - m_base(base), - m_base_cmp_endpoints(base_cmp_endpoints), - m_self_tr(tr) - {} - - /*! - * Get the right endpoint of the x-monotone curve (segment). + /*! Obtain the right endpoint of the x-monotone curve (segment). * \param cv The curve. * \return The left endpoint. */ Point_2 operator() (const X_monotone_curve_2 & cv) const { - if(!m_self_tr->is_valid_index(cv.data().index())) - { - return Point_2 (m_base(cv.base()), m_self_tr->invalid_index()); - } - Comparison_result res = m_base_cmp_endpoints(cv); + const auto* base_traits = m_traits.m_base_traits; + auto base_ctr_max_vertex = base_traits->construct_max_vertex_2_object(); + if (! m_traits.is_valid_index(cv.data().index())) + return Point_2(base_ctr_max_vertex(cv.base()), m_traits.invalid_index()); + + auto base_cmp_endpoints = base_traits->compare_endpoints_xy_2_object(); + Comparison_result res = base_cmp_endpoints(cv); Point_data pt_data; - if(res == SMALLER) - { + if (res == SMALLER) { // min vertex is the target - pt_data.set_index((cv.data().index() + 1) % m_self_tr->polygon_size()); + pt_data.set_index((cv.data().index() + 1) % m_traits.polygon_size()); } - else - { + else { // min vertex is the source pt_data.set_index(cv.data().index()); } - return Point_2 (m_base(cv.base()), pt_data); + return Point_2(base_ctr_max_vertex(cv.base()), pt_data); } }; /*! Get a Construct_min_vertex_2 functor object. */ Construct_max_vertex_2 construct_max_vertex_2_object () const - { - return Construct_max_vertex_2 - (this->m_base_tr->construct_max_vertex_2_object(), - this->m_base_tr->compare_endpoints_xy_2_object(), - this); - } + { return Construct_max_vertex_2(*this); } - class Compare_xy_2 - { + class Compare_xy_2 { private: - Base_Compare_xy_2 m_base; - const Self * m_self_tr; + const Self& m_traits; + + Compare_xy_2(const Self& tr) : m_traits(tr) {} + + friend Self; public: - Compare_xy_2(const Base_Compare_xy_2& base, - const Self * tr): - m_base(base), - m_self_tr(tr) - {} - - - /*! - * Get the left endpoint of the x-monotone curve (segment). + /*! Obtain the left endpoint of the x-monotone curve (segment). * \param cv The curve. * \return The left endpoint. */ - Comparison_result operator() (const Point_2& p1, const Point_2& p2) const + Comparison_result operator()(const Point_2& p1, const Point_2& p2) const { + const auto* base_traits = m_traits.m_base_traits; + auto base_cmp_xy = base_traits->compare_xy_2_object(); + //if one of the indexes is invalid, compare p1 and p2 - if(! m_self_tr->is_valid_index(p1.data().index()) || - ! m_self_tr->is_valid_index(p2.data().index())) - return (m_base(p1.base(), p2.base())); + if (! m_traits.is_valid_index(p1.data().index()) || + ! m_traits.is_valid_index(p2.data().index())) + return (base_cmp_xy(p1.base(), p2.base())); // if the two point has the same index, return EQUAL - if(p1.data().index() == p2.data().index()) - { - return EQUAL; - } + if (p1.data().index() == p2.data().index()) return EQUAL; - return (m_base(p1.base(), p2.base())); + return (base_cmp_xy(p1.base(), p2.base())); } }; /*! Get a Construct_min_vertex_2 functor object. */ - Compare_xy_2 compare_xy_2_object () const - { - return Compare_xy_2(this->m_base_tr->compare_xy_2_object(), this); - } + Compare_xy_2 compare_xy_2_object () const { return Compare_xy_2(*this); } }; } //namespace CGAL diff --git a/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Gps_traits_decorator.h b/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Gps_traits_decorator.h index 74b62b9d5f5..74664d72795 100644 --- a/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Gps_traits_decorator.h +++ b/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Gps_traits_decorator.h @@ -202,25 +202,27 @@ public: protected: //Data members - const Base * m_base_tr; + const Base* m_base_traits; bool m_traits_owner; public: Gps_traits_decorator() : - m_base_tr(new Base()), + m_base_traits(new Base()), m_traits_owner(true) {} - Gps_traits_decorator(const Base & base_traits) : - m_base_tr(&base_traits), + Gps_traits_decorator(const Base& base_traits) : + m_base_traits(&base_traits), m_traits_owner(false) {} ~Gps_traits_decorator() { - if (m_traits_owner) - delete m_base_tr; + if (m_traits_owner) { + delete m_base_traits; + m_base_traits = nullptr; + } } class Compare_x_2 @@ -242,7 +244,7 @@ public: /*! Get a Compare_x_2 functor object. */ Compare_x_2 compare_x_2_object () const { - return Compare_x_2(m_base_tr->compare_x_2_object()); + return Compare_x_2(m_base_traits->compare_x_2_object()); } @@ -265,7 +267,7 @@ public: /*! Get a Compare_xy_2 functor object. */ Compare_xy_2 compare_xy_2_object () const { - return Compare_xy_2(m_base_tr->compare_xy_2_object()); + return Compare_xy_2(m_base_traits->compare_xy_2_object()); } class Construct_min_vertex_2 @@ -288,7 +290,7 @@ public: /*! Get a Construct_min_vertex_2 functor object. */ Construct_min_vertex_2 construct_min_vertex_2_object () const { - return Construct_min_vertex_2(m_base_tr->construct_min_vertex_2_object()); + return Construct_min_vertex_2(m_base_traits->construct_min_vertex_2_object()); } class Construct_max_vertex_2 @@ -311,7 +313,7 @@ public: /*! Get a Construct_max_vertex_2 functor object. */ Construct_max_vertex_2 construct_max_vertex_2_object () const { - return Construct_max_vertex_2(m_base_tr->construct_max_vertex_2_object()); + return Construct_max_vertex_2(m_base_traits->construct_max_vertex_2_object()); } @@ -334,7 +336,7 @@ public: /*! Get a Is_vertical_2 functor object. */ Is_vertical_2 is_vertical_2_object() const { - return Is_vertical_2(m_base_tr->is_vertical_2_object()); + return Is_vertical_2(m_base_traits->is_vertical_2_object()); } @@ -358,7 +360,7 @@ public: /*! Get a compare_y_at_x_2_object functor object. */ Compare_y_at_x_2 compare_y_at_x_2_object() const { - return Compare_y_at_x_2(m_base_tr->compare_y_at_x_2_object()); + return Compare_y_at_x_2(m_base_traits->compare_y_at_x_2_object()); } @@ -384,7 +386,7 @@ public: /*! Get a Compare_y_at_x_right_2 functor object. */ Compare_y_at_x_right_2 compare_y_at_x_right_2_object() const { - return Compare_y_at_x_right_2(m_base_tr->compare_y_at_x_right_2_object()); + return Compare_y_at_x_right_2(m_base_traits->compare_y_at_x_right_2_object()); } @@ -407,7 +409,7 @@ public: /*! Get a Equal_2 functor object. */ Equal_2 equal_2_object() const { - return Equal_2(m_base_tr->equal_2_object()); + return Equal_2(m_base_traits->equal_2_object()); } @@ -432,7 +434,7 @@ public: /*! Get a Split_2 functor object. */ Split_2 split_2_object() const { - return Split_2(m_base_tr->split_2_object()); + return Split_2(m_base_traits->split_2_object()); } @@ -495,9 +497,9 @@ public: /*! Get a Intersect_2 functor object. */ Intersect_2 intersect_2_object() const { - return Intersect_2(m_base_tr->intersect_2_object(), - m_base_tr->compare_xy_2_object(), - m_base_tr->construct_min_vertex_2_object()); + return Intersect_2(m_base_traits->intersect_2_object(), + m_base_traits->compare_xy_2_object(), + m_base_traits->construct_min_vertex_2_object()); } @@ -522,7 +524,7 @@ public: /*! Get a Compare_endpoints_xy_2 functor object. */ Compare_endpoints_xy_2 compare_endpoints_xy_2_object() const { - return Compare_endpoints_xy_2(m_base_tr->compare_endpoints_xy_2_object()); + return Compare_endpoints_xy_2(m_base_traits->compare_endpoints_xy_2_object()); } @@ -545,7 +547,7 @@ public: /*! Get a Construct_opposite_2 functor object. */ Construct_opposite_2 construct_opposite_2_object() const { - return Construct_opposite_2(m_base_tr->construct_opposite_2_object()); + return Construct_opposite_2(m_base_traits->construct_opposite_2_object()); } }; diff --git a/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Polygon_2_curve_iterator.h b/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Polygon_2_curve_iterator.h index 39a5e7dd34a..833f9afd571 100644 --- a/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Polygon_2_curve_iterator.h +++ b/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Polygon_2_curve_iterator.h @@ -60,9 +60,9 @@ public: Edge_const_iterator m_curr_edge; // points to the current edge iterator public: - Polygon_2_curve_iterator< X_monotone_curve_2_, Polygon_ >(){} + Polygon_2_curve_iterator(){} - Polygon_2_curve_iterator< X_monotone_curve_2_, Polygon_ > + Polygon_2_curve_iterator (const Polygon* pgn, Edge_const_iterator ci) : m_pgn(pgn), m_curr_edge(ci) {} diff --git a/Boolean_set_operations_2/include/CGAL/Gps_circle_segment_traits_2.h b/Boolean_set_operations_2/include/CGAL/Gps_circle_segment_traits_2.h index 1d29214e267..4b88536cf14 100644 --- a/Boolean_set_operations_2/include/CGAL/Gps_circle_segment_traits_2.h +++ b/Boolean_set_operations_2/include/CGAL/Gps_circle_segment_traits_2.h @@ -27,7 +27,7 @@ class Gps_circle_segment_traits_2 : public Gps_traits_2 > { public: - Gps_circle_segment_traits_2(bool use_cache = false) : + Gps_circle_segment_traits_2(bool use_cache = false) : Gps_traits_2 >() { this->m_use_cache = use_cache; diff --git a/Boolean_set_operations_2/include/CGAL/Gps_traits_2.h b/Boolean_set_operations_2/include/CGAL/Gps_traits_2.h index 068e95c2169..3f916b7e71d 100644 --- a/Boolean_set_operations_2/include/CGAL/Gps_traits_2.h +++ b/Boolean_set_operations_2/include/CGAL/Gps_traits_2.h @@ -35,6 +35,8 @@ public: typedef typename Base::Point_2 Point_2; typedef typename Base::X_monotone_curve_2 X_monotone_curve_2; + typedef typename Base::Multiplicity Multiplicity; + //Polygon_2 type is required by GeneralPolygonSetTraits Concept typedef General_polygon_t Polygon_2; //Polygon_2 is a model of the GeneralPolygon2 concept diff --git a/Bounding_volumes/examples/Approximate_min_ellipsoid_d/CMakeLists.txt b/Bounding_volumes/examples/Approximate_min_ellipsoid_d/CMakeLists.txt index 5ea12f55be3..9c066bd6cf4 100644 --- a/Bounding_volumes/examples/Approximate_min_ellipsoid_d/CMakeLists.txt +++ b/Bounding_volumes/examples/Approximate_min_ellipsoid_d/CMakeLists.txt @@ -8,15 +8,18 @@ if ( CGAL_FOUND ) # Use Eigen find_package(Eigen3 3.1.0 QUIET) #(3.1.0 or greater) + include(CGAL_Eigen_support) # create a target per cppfile file(GLOB cppfiles RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) foreach(cppfile ${cppfiles}) - if(NOT (${cppfile} STREQUAL "ellipsoid.cpp") OR EIGEN3_FOUND) - create_single_source_cgal_program( "${cppfile}" ) - if (EIGEN3_FOUND) - get_filename_component(target ${cppfile} NAME_WE) - CGAL_target_use_Eigen(${target}) + if(NOT (${cppfile} STREQUAL "ellipsoid.cpp") OR TARGET CGAL::Eigen_support) + get_filename_component(target ${cppfile} NAME_WE) + add_executable(${target} ${cppfile}) + if (TARGET CGAL::Eigen_support) + target_link_libraries(${target} CGAL::CGAL CGAL::Eigen_support) + else() + target_link_libraries(${target} CGAL::CGAL) endif() endif() endforeach() @@ -26,4 +29,3 @@ else() message(STATUS "This program requires the CGAL library, and will not be compiled.") endif() - diff --git a/Bounding_volumes/test/Bounding_volumes/CMakeLists.txt b/Bounding_volumes/test/Bounding_volumes/CMakeLists.txt index 804517aea26..5a29e19f887 100644 --- a/Bounding_volumes/test/Bounding_volumes/CMakeLists.txt +++ b/Bounding_volumes/test/Bounding_volumes/CMakeLists.txt @@ -14,15 +14,18 @@ if ( CGAL_FOUND ) # Use Eigen find_package(Eigen3 3.1.0 QUIET) #(3.1.0 or greater) + include(CGAL_Eigen_support) # create a target per cppfile file(GLOB cppfiles RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) foreach(cppfile ${cppfiles}) - if(NOT (${cppfile} STREQUAL "Approximate_min_ellipsoid_d.cpp") OR EIGEN3_FOUND) - create_single_source_cgal_program( "${cppfile}" ) - if (EIGEN3_FOUND) - get_filename_component(target ${cppfile} NAME_WE) - CGAL_target_use_Eigen(${target}) + if(NOT (${cppfile} STREQUAL "Approximate_min_ellipsoid_d.cpp") OR TARGET CGAL::Eigen_support) + get_filename_component(target ${cppfile} NAME_WE) + add_executable(${target} ${cppfile}) + if (TARGET CGAL::Eigen_support) + target_link_libraries(${target} CGAL::CGAL CGAL::Eigen_support) + else() + target_link_libraries(${target} CGAL::CGAL) endif() endif() endforeach() @@ -32,4 +35,3 @@ else() message(STATUS "This program requires the CGAL library, and will not be compiled.") endif() - diff --git a/Box_intersection_d/test/Box_intersection_d/CMakeLists.txt b/Box_intersection_d/test/Box_intersection_d/CMakeLists.txt index 6f4ec1704ce..de7955c4208 100644 --- a/Box_intersection_d/test/Box_intersection_d/CMakeLists.txt +++ b/Box_intersection_d/test/Box_intersection_d/CMakeLists.txt @@ -8,6 +8,7 @@ project( Box_intersection_d_Tests ) find_package( CGAL QUIET ) find_package( TBB ) +include(CGAL_TBB_support) if ( CGAL_FOUND ) @@ -16,12 +17,11 @@ if ( CGAL_FOUND ) create_single_source_cgal_program( "random_set_test.cpp" ) create_single_source_cgal_program( "test_box_grid.cpp" ) - if( TBB_FOUND ) - CGAL_target_use_TBB( test_box_grid ) + if(TARGET CGAL::TBB_support) + target_link_libraries(test_box_grid PUBLIC CGAL::TBB_support) else() message( STATUS "NOTICE: Intel TBB was not found. Sequential code will be used." ) endif() else() message(STATUS "This program requires the CGAL library, and will not be compiled.") endif() - diff --git a/CGALConfigVersion.cmake b/CGALConfigVersion.cmake new file mode 100644 index 00000000000..f1363d9a8f6 --- /dev/null +++ b/CGALConfigVersion.cmake @@ -0,0 +1 @@ +include(${CMAKE_CURRENT_LIST_DIR}/Installation/lib/cmake/CGAL/CGALConfigVersion.cmake) diff --git a/CGAL_ipelets/demo/CGAL_ipelets/CMakeLists.txt b/CGAL_ipelets/demo/CGAL_ipelets/CMakeLists.txt index 18e2f342352..6e6749d8619 100644 --- a/CGAL_ipelets/demo/CGAL_ipelets/CMakeLists.txt +++ b/CGAL_ipelets/demo/CGAL_ipelets/CMakeLists.txt @@ -27,7 +27,8 @@ if ( CGAL_FOUND ) include(${CGAL_USE_FILE}) find_package(Eigen3 3.1.0) #(requires 3.1.0 or greater) - if (NOT EIGEN3_FOUND) + include(CGAL_Eigen_support) + if (NOT TARGET CGAL::Eigen_support) message(STATUS "NOTICE: This project requires the Eigen library, and will not be compiled.") return() endif() @@ -140,8 +141,7 @@ if ( CGAL_FOUND ) foreach(IPELET ${CGAL_IPELETS}) add_library(CGAL_${IPELET} MODULE ${IPELET}.cpp) add_to_cached_list(CGAL_EXECUTABLE_TARGETS CGAL_${IPELET}) - target_link_libraries(CGAL_${IPELET} PRIVATE CGAL::CGAL ${IPE_LIBRARIES}) - CGAL_target_use_Eigen(CGAL_${IPELET}) + target_link_libraries(CGAL_${IPELET} PRIVATE CGAL::CGAL CGAL::Eigen_support ${IPE_LIBRARIES}) if ( IPELET_INSTALL_DIR ) install(TARGETS CGAL_${IPELET} DESTINATION ${IPELET_INSTALL_DIR}) if (WITH_IPE_7) @@ -151,14 +151,12 @@ if ( CGAL_FOUND ) cgal_add_compilation_test(CGAL_${IPELET}) endforeach(IPELET) if(CGAL_Core_FOUND) - target_link_libraries(CGAL_cone_spanners PRIVATE CGAL::CGAL_Core) - CGAL_target_use_Eigen(CGAL_cone_spanners) + target_link_libraries(CGAL_cone_spanners PRIVATE CGAL::CGAL_Core CGAL::Eigen_support) endif() #example in doc not installed add_library(simple_triangulation MODULE simple_triangulation.cpp) add_to_cached_list(CGAL_EXECUTABLE_TARGETS simple_triangulation) - target_link_libraries(simple_triangulation ${IPE_LIBRARIES}) - CGAL_target_use_Eigen(simple_triangulation) + target_link_libraries(simple_triangulation CGAL::Eigen_support ${IPE_LIBRARIES}) cgal_add_compilation_test(simple_triangulation) else() diff --git a/CMakeLists.txt b/CMakeLists.txt index acdc5817a06..9696ca95b3d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ export(PACKAGE CGAL) set( CGAL_BRANCH_BUILD ON CACHE INTERNAL "Create CGAL from a Git branch" FORCE) +include(${CMAKE_SOURCE_DIR}/CGALConfigVersion.cmake) include(${CMAKE_SOURCE_DIR}/Installation/cmake/modules/CGAL_SCM.cmake) CGAL_detect_git(${CMAKE_SOURCE_DIR}) diff --git a/Cartesian_kernel/include/CGAL/Cartesian/Aff_transformation_3.h b/Cartesian_kernel/include/CGAL/Cartesian/Aff_transformation_3.h index ec41f708100..7a04f837092 100644 --- a/Cartesian_kernel/include/CGAL/Cartesian/Aff_transformation_3.h +++ b/Cartesian_kernel/include/CGAL/Cartesian/Aff_transformation_3.h @@ -169,6 +169,9 @@ public: Aff_transformation_3 operator*(const Aff_transformationC3 &t) const { return (*this->Ptr()) * (*t.Ptr()); } + std::ostream & + print(std::ostream &os) const; + bool operator==(const Aff_transformationC3 &t)const { for(int i=0; i<3; ++i) @@ -188,13 +191,21 @@ protected: }; +template < class R > +std::ostream& +Aff_transformationC3::print(std::ostream &os) const +{ + this->Ptr()->print(os); + return os; +} + #ifndef CGAL_NO_OSTREAM_INSERT_AFF_TRANSFORMATIONC3 template < class R > -std::ostream &operator<<(std::ostream &os, - const Aff_transformationC3 &t) +std::ostream& +operator<<(std::ostream &os, const Aff_transformationC3 &t) { - t.print(os); - return os; + t.print(os); + return os; } #endif // CGAL_NO_OSTREAM_INSERT_AFF_TRANSFORMATIONC3 diff --git a/Cartesian_kernel/include/CGAL/Cartesian/Aff_transformation_rep_3.h b/Cartesian_kernel/include/CGAL/Cartesian/Aff_transformation_rep_3.h index d1335a1096b..406cb7accca 100644 --- a/Cartesian_kernel/include/CGAL/Cartesian/Aff_transformation_rep_3.h +++ b/Cartesian_kernel/include/CGAL/Cartesian/Aff_transformation_rep_3.h @@ -183,8 +183,8 @@ public: virtual std::ostream &print(std::ostream &os) const { os <<"Aff_transformationC3("< #include #include +#include #include #include #include @@ -439,7 +440,7 @@ namespace CGAL { bool copy_perforated_darts=false, size_type mark_perforated=INVALID_MARK) { - CGAL::cpp11::tuple<> converters; + std::tuple<> converters; copy(amap, origin_to_copy, copy_to_origin, converters, copy_perforated_darts, mark_perforated); } @@ -454,7 +455,7 @@ namespace CGAL { bool copy_perforated_darts=false, size_type mark_perforated=INVALID_MARK) { - CGAL::cpp11::tuple<> converters; + std::tuple<> converters; copy_from_const(amap, origin_to_copy, copy_to_origin, converters, copy_perforated_darts, mark_perforated); } diff --git a/Combinatorial_map/include/CGAL/Dart.h b/Combinatorial_map/include/CGAL/Dart.h index eab9f898131..bfc21e7b25a 100644 --- a/Combinatorial_map/include/CGAL/Dart.h +++ b/Combinatorial_map/include/CGAL/Dart.h @@ -105,8 +105,8 @@ namespace CGAL { void * for_compact_container() const { return mf[0].for_compact_container(); } - void * & for_compact_container() - { return mf[0].for_compact_container(); } + void for_compact_container(void *p) + { mf[0].for_compact_container(p); } Dart_handle get_f(unsigned int i) const { diff --git a/Convex_hull_2/include/CGAL/IO/Tee_for_output_iterator.h b/Convex_hull_2/include/CGAL/IO/Tee_for_output_iterator.h index 3a298f6b6c0..26aee3bba75 100644 --- a/Convex_hull_2/include/CGAL/IO/Tee_for_output_iterator.h +++ b/Convex_hull_2/include/CGAL/IO/Tee_for_output_iterator.h @@ -39,7 +39,7 @@ class Tee_for_output_iterator public: Tee_for_output_iterator(const OutputIterator& o) : o_it(o) - { PTR.p = (Rep*) new _Tee_for_output_iterator_rep(); } + { PTR = (Rep*) new _Tee_for_output_iterator_rep(); } Tee_for_output_iterator& operator=(const T& value) @@ -82,7 +82,7 @@ public: _Tee_for_output_iterator_rep* ptr() - { return (_Tee_for_output_iterator_rep*)(PTR.p); } + { return (_Tee_for_output_iterator_rep*)PTR; } protected: OutputIterator o_it; diff --git a/Convex_hull_d/include/CGAL/Regular_complex_d.h b/Convex_hull_d/include/CGAL/Regular_complex_d.h index 753637ec1e5..4a5a32b1213 100644 --- a/Convex_hull_d/include/CGAL/Regular_complex_d.h +++ b/Convex_hull_d/include/CGAL/Regular_complex_d.h @@ -87,7 +87,7 @@ public: void* pp; void* for_compact_container() const { return pp; } - void* & for_compact_container() { return pp; } + void for_compact_container(void *p) { pp = p; } #ifdef CGAL_USE_LEDA LEDA_MEMORY(RC_vertex_d) @@ -153,7 +153,7 @@ public: void* pp; void* for_compact_container() const { return pp; } - void* & for_compact_container() { return pp; } + void for_compact_container(void *p) { pp = p; } #if 0 struct Point_const_iterator { diff --git a/Distance_3/include/CGAL/squared_distance_3_1.h b/Distance_3/include/CGAL/squared_distance_3_1.h index 2978c1d8fe3..e0e63a6fb23 100644 --- a/Distance_3/include/CGAL/squared_distance_3_1.h +++ b/Distance_3/include/CGAL/squared_distance_3_1.h @@ -217,7 +217,7 @@ compare_distance_pssC3( } } } - return compare(d1*e2, d2*e1); + return CGAL::compare(d1*e2, d2*e1); } template @@ -253,7 +253,7 @@ compare_distance_ppsC3( } } } - return compare(d1*e2, d2); + return CGAL::compare(d1*e2, d2); } diff --git a/Documentation/doc/CMakeLists.txt b/Documentation/doc/CMakeLists.txt index 744b16f32e8..9c1695ca28e 100644 --- a/Documentation/doc/CMakeLists.txt +++ b/Documentation/doc/CMakeLists.txt @@ -252,9 +252,7 @@ endif() if (NOT CGAL_CREATED_VERSION_NUM) if (CGAL_BRANCH_BUILD) - file(STRINGS "${CGAL_ROOT}/Maintenance/release_building/MAJOR_NUMBER" CGAL_MAJOR_VERSION REGEX "[0-9]*") - file(STRINGS "${CGAL_ROOT}/Maintenance/release_building/MINOR_NUMBER" CGAL_MINOR_VERSION REGEX "[0-9]*") - file(STRINGS "${CGAL_ROOT}/Maintenance/release_building/BUGFIX_NUMBER" CGAL_BUGFIX_VERSION REGEX "[0-9]*") + include(${CGAL_ROOT}/CGALConfigVersion.cmake) if (CGAL_BUGFIX_VERSION AND CGAL_BUGFIX_VERSION GREATER 0) set(CGAL_CREATED_VERSION_NUM "${CGAL_MAJOR_VERSION}.${CGAL_MINOR_VERSION}.${CGAL_BUGFIX_VERSION}") diff --git a/Documentation/doc/Documentation/Developer_manual/create_and_use_a_cmakelist.txt b/Documentation/doc/Documentation/Developer_manual/create_and_use_a_cmakelist.txt index afc413a7dd7..0fffe791b9b 100644 --- a/Documentation/doc/Documentation/Developer_manual/create_and_use_a_cmakelist.txt +++ b/Documentation/doc/Documentation/Developer_manual/create_and_use_a_cmakelist.txt @@ -18,7 +18,7 @@ find_package(CGAL REQUIRED COMPONENTS Core) target_link_libraries(my_executable CGAL::CGAL CGAL::CGAL_Core) \endcode -There are also some cmake macros to link with \cgal dependencies that can be found in +There are also imported targets to link with \cgal dependencies that can be found in the section \subpage thirdparty. \note The \cgal targets define the following compiler flags: diff --git a/Documentation/doc/Documentation/Third_party.txt b/Documentation/doc/Documentation/Third_party.txt index 71e3c43d291..ea4987e97e5 100644 --- a/Documentation/doc/Documentation/Third_party.txt +++ b/Documentation/doc/Documentation/Third_party.txt @@ -132,8 +132,8 @@ sparse linear solvers and singular value decompositions. A package dependency over \sc{Eigen} is marked on the Package Overview page. In order to use Eigen in \cgal programs, the -provided CMake function `CGAL_target_use_Eigen()` should be -used. +executables should be linked with the CMake imported target +`CGAL::Eigen_support` provided in `CGAL_Eigen_support.cmake`. The \sc{Eigen} web site is `http://eigen.tuxfamily.org`. @@ -142,8 +142,7 @@ The \sc{Eigen} web site is `https://github.com/STORM-IRIT/OpenGR`. @@ -152,8 +151,10 @@ The \sc{OpenGR} web site is `http \sc{libpointmatcher} is a modular library implementing the Iterative Closest Point (ICP) algorithm for aligning point clouds, released under a permissive BSD license. \cgal provides wrappers for the ICP algorithm of \sc{libpointmatcher} in the \ref PkgPointSetProcessing3Ref -packages. In order to use \sc{libpointmatcher} in \cgal programs, the provided CMake function -`CGAL_target_use_pointmatcher()` should be used. +packages. In order to use \sc{libpointmatcher} in \cgal programs, the +executables should be linked with the CMake imported target +`CGAL::pointmatcher_support` provided in +`CGAL_pointmatcher_support.cmake`. The \sc{libpointmatcher} web site is `https://github.com/ethz-asl/libpointmatcher`. @@ -220,8 +221,9 @@ It can be downloaded from `http://esbtl. programs that take advantage of multi-core processors. In \cgal, \sc{Tbb} is used by the packages that offer parallel -code. In order to use \sc{Tbb} in \cgal programs, the provided CMake -function `CGAL_target_use_TBB()` should be used. +code. In order to use \sc{Tbb} in \cgal programs, the executables +should be linked with the CMake imported target `CGAL::TBB_support` +provided in `CGAL_TBB_support.cmake`. The \sc{Tbb} web site is `https://www.threadingbuildingblocks.org`. @@ -231,9 +233,10 @@ The \sc{Tbb} web site is `http the LAS format (or the compressed LAZ format). In \cgal, \sc{LASlib} is used to provide input and output functions in -the \ref PkgPointSetProcessing3 package. In order to use \sc{LASlib} in -\cgal programs, the provided CMake function -`CGAL_target_use_LASLIB()` should be used. +the \ref PkgPointSetProcessing3 package. In order to use \sc{LASlib} +in \cgal programs, the executables should be linked with the CMake +imported target `CGAL::LASLIB_support` provided in +`CGAL_LASLIB_support.cmake`. The \sc{LASlib} web site is `https://rapidlasso.com/lastools/`. \sc{LASlib} @@ -247,8 +250,9 @@ CMake based install procedure. vision, computer graphics and machine learning. In \cgal, \sc{OpenCV} is used by the \ref PkgClassification -package. In order to use \sc{OpenCV} in \cgal programs, the provided -CMake function `CGAL_target_use_OpenCV()` should be used. +package. In order to use \sc{OpenCV} in \cgal programs, the +executables should be linked with the CMake imported target +`CGAL::OpenCV_support` provided in `CGAL_OpenCV_support.cmake`. The \sc{OpenCV} web site is `https://opencv.org/`. @@ -266,8 +270,10 @@ enable and compile the following targets: - `tensorflow_BUILD_PYTHON_BINDINGS` - `tensorflow_BUILD_SHARED_LIB`. -In order to use \sc{TensorFlow} in \cgal programs, the provided CMake -function `CGAL_target_use_TensorFlow()` should be used. +In order to use \sc{TensorFlow} in \cgal programs, the executables +should be linked with the CMake imported target +`CGAL::TensorFlow_support` provided in +`CGAL_TensorFlow_support.cmake`. The \sc{TensorFlow} web site is `https://www.tensorflow.org/`. @@ -310,8 +316,9 @@ for more information. In \cgal, \sc{GLPK} provides an optional linear integer program solver in the \ref PkgPolygonalSurfaceReconstruction package. In order to use -\sc{GLPK} in \cgal programs, the provided CMake function -`CGAL_target_use_GLPK()` should be used. +\sc{GLPK} in \cgal programs, the executables should be linked with the +CMake imported target `CGAL::GLPK_support` provided in +`CGAL_GLPK_support.cmake`. The \sc{GLPK} web site is `https://www.gnu.org/software/glpk/`. @@ -321,8 +328,9 @@ The \sc{GLPK} web site is `https:// In \cgal, \sc{SCIP} provides an optional linear integer program solver in the \ref PkgPolygonalSurfaceReconstruction package. In order to use -\sc{SCIP} in \cgal programs, the provided CMake function -`CGAL_target_use_SCIP()` should be used. +\sc{SCIP} in \cgal programs, the executables should be linked with the +CMake imported target `CGAL::SCIP_support` provided in +`CGAL_SCIP_support.cmake`. The \sc{SCIP} web site is `http://scip.zib.de/`. diff --git a/Documentation/doc/Documentation/Usage.txt b/Documentation/doc/Documentation/Usage.txt index 38d2b257697..247348cab68 100644 --- a/Documentation/doc/Documentation/Usage.txt +++ b/Documentation/doc/Documentation/Usage.txt @@ -60,12 +60,6 @@ On most operating systems, package managers offer \cgal and its essential third On macOS, we recommend using of Homebrew in the following way: brew install cgal - brew install cgal-qt5 #(only for GUI) - -You should check that cgal and cgal-qt5 are correctly "linked", especially when upgrading from an old version. If not, run the following command: - - brew link cgal - brew link cgal-qt5 #(if you installed it) On Linux distributions such as `Debian`/`Ubuntu`/`Mint`, use `apt-get` in the following way: diff --git a/Documentation/doc/Documentation/packages.txt b/Documentation/doc/Documentation/packages.txt index 5fb6e1a5446..a18528a063d 100644 --- a/Documentation/doc/Documentation/packages.txt +++ b/Documentation/doc/Documentation/packages.txt @@ -90,6 +90,7 @@ \package_listing{Surface_mesher} \package_listing{Skin_surface_3} \package_listing{Mesh_3} +\package_listing{Tetrahedral_remeshing} \package_listing{Periodic_3_mesh_3} \cgalPackageSection{PartReconstruction,Shape Reconstruction} diff --git a/Documentation/doc/biblio/cgal_manual.bib b/Documentation/doc/biblio/cgal_manual.bib index e2a2fd57555..6dcd0e958c7 100644 --- a/Documentation/doc/biblio/cgal_manual.bib +++ b/Documentation/doc/biblio/cgal_manual.bib @@ -3127,6 +3127,14 @@ pages = "207--221" year={2012}, organization={Wiley Online Library} } + +@article{faraj2016mvr, + author = {Noura Faraj and Jean-Marc Thiery and Tamy Boubekeur}, + title = {Multi-Material Adaptive Volume Remesher}, + journal = {Compurer and Graphics Journal (proc. Shape Modeling International 2016)}, + year = {2016}, +} + % ---------------------------------------------------------------------------- % END OF BIBFILE % ---------------------------------------------------------------------------- diff --git a/Documentation/doc/resources/1.8.13/menu_version.js b/Documentation/doc/resources/1.8.13/menu_version.js index 36b298ee045..780aefa1246 100644 --- a/Documentation/doc/resources/1.8.13/menu_version.js +++ b/Documentation/doc/resources/1.8.13/menu_version.js @@ -3,10 +3,11 @@ var url_re = /(cgal\.geometryfactory\.com\/CGAL\/doc\/|doc\.cgal\.org\/)(master|latest|(\d\.\d+|\d\.\d+\.\d+))\//; var url_local = /.*\/doc_output\//; - var current_version_local = '5.1-dev' + var current_version_local = '5.1-beta1' var all_versions = [ 'master', 'latest', + '5.1-beta1', '5.0.2', '4.14.3', '4.13.2', @@ -23,6 +24,15 @@ ]; function build_select(current_version) { + if( current_version == 'master') { + let top_elt = document.getElementById("top"); + + let first_element = top_elt.childNodes[0]; + let new_div = document.createElement("p"); + new_div.innerHTML = '⚠️ This documentation corresponds to the master development branch of CGAL. It might diverge from the official releases.'; + new_div.style.cssText = "background-color: #ff9800; margin: 1ex auto 1ex 1em; padding: 1ex; border-radius: 1ex; display: inline-block;" + let OK = top_elt.insertBefore(new_div, first_element); + } var buf = ['']; $.each(all_versions, function(id) { var version = all_versions[id]; @@ -44,7 +54,7 @@ } function patch_url(url, new_version) { - if(url.includes("doc.cgal.org")||url.includes("cgal.geometryfactory.com")){ + if(url.includes("doc.cgal.org")||url.includes("cgal.geometryfactory.com")){ return url.replace(url_re, 'doc.cgal.org/' + new_version + '/'); } else{ @@ -65,7 +75,7 @@ var motherNode=$("#back-nav ul")[0]; var node = document.createElement("LI"); var spanNode = document.createElement("SPAN"); - var titleNode =document.createTextNode("CGAL Version: "); + var titleNode =document.createTextNode("CGAL Version: "); var textNode = document.createTextNode("x.y"); spanNode.setAttribute("class", "version_menu"); spanNode.appendChild(textNode); @@ -90,4 +100,4 @@ } } }); -})(); +})(); diff --git a/Documentation/doc/resources/1.8.4/menu_version.js b/Documentation/doc/resources/1.8.4/menu_version.js index 36b298ee045..780aefa1246 100644 --- a/Documentation/doc/resources/1.8.4/menu_version.js +++ b/Documentation/doc/resources/1.8.4/menu_version.js @@ -3,10 +3,11 @@ var url_re = /(cgal\.geometryfactory\.com\/CGAL\/doc\/|doc\.cgal\.org\/)(master|latest|(\d\.\d+|\d\.\d+\.\d+))\//; var url_local = /.*\/doc_output\//; - var current_version_local = '5.1-dev' + var current_version_local = '5.1-beta1' var all_versions = [ 'master', 'latest', + '5.1-beta1', '5.0.2', '4.14.3', '4.13.2', @@ -23,6 +24,15 @@ ]; function build_select(current_version) { + if( current_version == 'master') { + let top_elt = document.getElementById("top"); + + let first_element = top_elt.childNodes[0]; + let new_div = document.createElement("p"); + new_div.innerHTML = '⚠️ This documentation corresponds to the master development branch of CGAL. It might diverge from the official releases.'; + new_div.style.cssText = "background-color: #ff9800; margin: 1ex auto 1ex 1em; padding: 1ex; border-radius: 1ex; display: inline-block;" + let OK = top_elt.insertBefore(new_div, first_element); + } var buf = ['