Fixed do_intersect() and cleaned up

This commit is contained in:
Efi Fogel 2025-09-06 20:41:49 +03:00
parent b871b81d57
commit 5b6df813f5
9 changed files with 250 additions and 215 deletions

View File

@ -40,7 +40,6 @@ class Arr_do_intersect_overlay_ss_visitor :
OverlayHelper, OverlayTraits, OverlayHelper, OverlayTraits,
typename Default::Get<Visitor_, typename Default::Get<Visitor_,
Arr_do_intersect_overlay_ss_visitor<OverlayHelper, OverlayTraits, Visitor_> >::type> { Arr_do_intersect_overlay_ss_visitor<OverlayHelper, OverlayTraits, Visitor_> >::type> {
private: private:
using Overlay_helper = OverlayHelper; using Overlay_helper = OverlayHelper;
using Overlay_traits = OverlayTraits; using Overlay_traits = OverlayTraits;
@ -61,6 +60,7 @@ public:
using Status_line_iterator = typename Base::Status_line_iterator; using Status_line_iterator = typename Base::Status_line_iterator;
using X_monotone_curve_2 = typename Base::X_monotone_curve_2; using X_monotone_curve_2 = typename Base::X_monotone_curve_2;
using Point_2 = typename Base::Point_2; using Point_2 = typename Base::Point_2;
using Multiplicity = typename Base::Multiplicity;
/*! Constructor */ /*! Constructor */
Arr_do_intersect_overlay_ss_visitor(const Arrangement_red_2* red_arr, Arr_do_intersect_overlay_ss_visitor(const Arrangement_red_2* red_arr,
@ -90,11 +90,15 @@ public:
void update_event(Event* e, Subcurve* sc) { return Base::update_event(e, sc); } void update_event(Event* e, Subcurve* sc) { return Base::update_event(e, sc); }
/*! Update an event that corresponds to an intersection between curves */ /*! Update an event that corresponds to an intersection between curves */
void update_event(Event*, Subcurve*, Subcurve*, bool is_new) { m_found_x = true; } void update_event(Event* e, Subcurve* sc1, Subcurve* sc2, bool is_new, Multiplicity multiplicity) {
if ((multiplicity % 2) == 1) m_found_x = true;
Base::update_event(e, sc1, sc2, is_new, multiplicity);
}
bool after_handle_event(Event* e, Status_line_iterator iter, bool flag) { bool after_handle_event(Event* e, Status_line_iterator iter, bool flag) {
auto res = Base::after_handle_event(e, iter, flag);
if (m_found_x) this->surface_sweep()->stop_sweep(); if (m_found_x) this->surface_sweep()->stop_sweep();
return Base::after_handle_event(e, iter, flag); return res;
} }
/*! Getter */ /*! Getter */

View File

@ -8,7 +8,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
// //
// //
// Author(s): Baruch Zukerman <baruchzu@post.tau.ac.il> // Author(s) : Baruch Zukerman <baruchzu@post.tau.ac.il>
// Ron Wein <wein@post.tau.ac.il> // Ron Wein <wein@post.tau.ac.il>
// Efi Fogel <efif@post.tau.ac.il> // Efi Fogel <efif@post.tau.ac.il>
@ -42,35 +42,33 @@ class Arr_no_intersection_insertion_ss_visitor :
public Arr_construction_ss_visitor< public Arr_construction_ss_visitor<
Helper_, Helper_,
typename Default::Get<Visitor_, Arr_no_intersection_insertion_ss_visitor< typename Default::Get<Visitor_, Arr_no_intersection_insertion_ss_visitor<
Helper_, Visitor_> >::type> Helper_, Visitor_> >::type> {
{
public: public:
typedef Helper_ Helper; using Helper = Helper_;
typedef typename Helper::Geometry_traits_2 Geometry_traits_2; using Geometry_traits_2 = typename Helper::Geometry_traits_2;
typedef typename Helper::Event Event; using Event = typename Helper::Event;
typedef typename Helper::Subcurve Subcurve; using Subcurve = typename Helper::Subcurve;
private: private:
typedef Geometry_traits_2 Gt2; using Gt2 = Geometry_traits_2;
typedef Arr_no_intersection_insertion_ss_visitor<Helper, Visitor_> using Self = Arr_no_intersection_insertion_ss_visitor<Helper, Visitor_>;
Self; using Visitor = typename Default::Get<Visitor_, Self>::type;
typedef typename Default::Get<Visitor_, Self>::type Visitor; using Base = Arr_construction_ss_visitor<Helper, Visitor>;
typedef Arr_construction_ss_visitor<Helper, Visitor> Base;
public: public:
typedef typename Gt2::X_monotone_curve_2 X_monotone_curve_2; using X_monotone_curve_2 = typename Gt2::X_monotone_curve_2;
typedef typename Gt2::Point_2 Point_2; using Point_2 = typename Gt2::Point_2;
using Multiplicity = typename Gt2::Multiplicity;
protected: protected:
typedef typename Subcurve::Status_line_iterator Status_line_iterator; using Status_line_iterator = typename Subcurve::Status_line_iterator;
typedef typename Base::Event_subcurve_reverse_iterator using Event_subcurve_reverse_iterator = typename Base::Event_subcurve_reverse_iterator;
Event_subcurve_reverse_iterator;
typedef typename Helper::Arrangement_2 Arrangement_2; using Arrangement_2 = typename Helper::Arrangement_2;
typedef typename Arrangement_2::Vertex_handle Vertex_handle; using Vertex_handle = typename Arrangement_2::Vertex_handle;
typedef typename Arrangement_2::Halfedge_handle Halfedge_handle; using Halfedge_handle = typename Arrangement_2::Halfedge_handle;
typedef typename Arrangement_2::Face_handle Face_handle; using Face_handle = typename Arrangement_2::Face_handle;
public: public:
/*! Constructor. */ /*! Constructor. */
@ -103,13 +101,12 @@ public:
{} {}
void update_event(Event* /* e */, Subcurve* /* sc1 */, Subcurve* /* sc2 */, void update_event(Event* /* e */, Subcurve* /* sc1 */, Subcurve* /* sc2 */,
bool /* is_new */) bool /* is_new */, Multiplicity /* multiplicity */)
{} {}
void update_event(Event* /* e */, Subcurve* /* sc1 */) {} void update_event(Event* /* e */, Subcurve* /* sc1 */) {}
void update_event(Event* e, const Point_2& pt, bool /* is_new */) void update_event(Event* e, const Point_2& pt, bool /* is_new */) {
{
Vertex_handle invalid_v; Vertex_handle invalid_v;
if (e->point().vertex_handle() == invalid_v) if (e->point().vertex_handle() == invalid_v)
e->point().set_vertex_handle(pt.vertex_handle()); e->point().set_vertex_handle(pt.vertex_handle());
@ -241,8 +238,7 @@ void Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>::before_sweep()
// //
template <typename Hlpr, typename Vis> template <typename Hlpr, typename Vis>
void Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>:: void Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>::
before_handle_event(Event* event) before_handle_event(Event* event) {
{
// First we notify the helper class on the event. // First we notify the helper class on the event.
this->m_helper.before_handle_event(event); this->m_helper.before_handle_event(event);
@ -330,8 +326,7 @@ before_handle_event(Event* event)
// //
template <typename Hlpr, typename Vis> template <typename Hlpr, typename Vis>
bool Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>:: bool Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>::
add_subcurve_(const X_monotone_curve_2& cv, Subcurve* sc) add_subcurve_(const X_monotone_curve_2& cv, Subcurve* sc) {
{
const Halfedge_handle invalid_he; const Halfedge_handle invalid_he;
if (cv.halfedge_handle() != invalid_he) return false; if (cv.halfedge_handle() != invalid_he) return false;
// Insert the curve into the arrangement // Insert the curve into the arrangement
@ -344,8 +339,7 @@ add_subcurve_(const X_monotone_curve_2& cv, Subcurve* sc)
// //
template <typename Hlpr, typename Vis> template <typename Hlpr, typename Vis>
void Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>:: void Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>::
add_subcurve(const X_monotone_curve_2& cv, Subcurve* sc) add_subcurve(const X_monotone_curve_2& cv, Subcurve* sc) {
{
if (add_subcurve_(cv, sc)) return; if (add_subcurve_(cv, sc)) return;
Halfedge_handle next_ccw_he = Halfedge_handle next_ccw_he =
@ -359,8 +353,7 @@ add_subcurve(const X_monotone_curve_2& cv, Subcurve* sc)
template <typename Hlpr, typename Vis> template <typename Hlpr, typename Vis>
typename Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>::Halfedge_handle typename Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>::Halfedge_handle
Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>:: Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>::
insert_in_face_interior(const X_monotone_curve_2& cv, Subcurve* sc) insert_in_face_interior(const X_monotone_curve_2& cv, Subcurve* sc) {
{
Event* last_event = this->last_event_on_subcurve(sc); Event* last_event = this->last_event_on_subcurve(sc);
Vertex_handle last_v = last_event->point().vertex_handle(); Vertex_handle last_v = last_event->point().vertex_handle();
Vertex_handle curr_v = this->current_event()->point().vertex_handle(); Vertex_handle curr_v = this->current_event()->point().vertex_handle();
@ -385,8 +378,7 @@ template <typename Hlpr, typename Vis>
typename Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>::Halfedge_handle typename Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>::Halfedge_handle
Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>:: Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>::
insert_from_left_vertex(const X_monotone_curve_2& cv, Halfedge_handle he, insert_from_left_vertex(const X_monotone_curve_2& cv, Halfedge_handle he,
Subcurve* sc) Subcurve* sc) {
{
Vertex_handle curr_v = this->current_event()->point().vertex_handle(); Vertex_handle curr_v = this->current_event()->point().vertex_handle();
if (curr_v != Vertex_handle()) if (curr_v != Vertex_handle())
return (this->m_arr->insert_at_vertices(cv.base(), he, curr_v)); return (this->m_arr->insert_at_vertices(cv.base(), he, curr_v));
@ -400,8 +392,7 @@ template <typename Hlpr, typename Vis>
typename Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>::Halfedge_handle typename Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>::Halfedge_handle
Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>:: Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>::
insert_from_right_vertex(const X_monotone_curve_2& cv, Halfedge_handle he, insert_from_right_vertex(const X_monotone_curve_2& cv, Halfedge_handle he,
Subcurve* sc) Subcurve* sc) {
{
Event* last_event = this->last_event_on_subcurve(sc); Event* last_event = this->last_event_on_subcurve(sc);
Vertex_handle last_v = last_event->point().vertex_handle(); Vertex_handle last_v = last_event->point().vertex_handle();
if (last_v != Vertex_handle()) if (last_v != Vertex_handle())
@ -426,8 +417,7 @@ insert_at_vertices(const X_monotone_curve_2& cv,
template <typename Hlpr, typename Vis> template <typename Hlpr, typename Vis>
typename Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>::Vertex_handle typename Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>::Vertex_handle
Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>:: Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>::
insert_isolated_vertex(const Point_2& pt, Status_line_iterator iter) insert_isolated_vertex(const Point_2& pt, Status_line_iterator iter) {
{
// If the isolated vertex is already at the arrangement, return: // If the isolated vertex is already at the arrangement, return:
if (pt.vertex_handle() != Vertex_handle()) return Vertex_handle(); if (pt.vertex_handle() != Vertex_handle()) return Vertex_handle();
@ -443,8 +433,7 @@ insert_isolated_vertex(const Point_2& pt, Status_line_iterator iter)
template <typename Hlpr, typename Vis> template <typename Hlpr, typename Vis>
typename Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>::Halfedge_handle typename Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>::Halfedge_handle
Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>:: Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>::
_insert_in_face_interior(const X_monotone_curve_2& cv, Subcurve* sc) _insert_in_face_interior(const X_monotone_curve_2& cv, Subcurve* sc) {
{
// Check if the vertex to be associated with the left end of the curve has // Check if the vertex to be associated with the left end of the curve has
// already been created. // already been created.
Event* last_event = this->last_event_on_subcurve(sc); Event* last_event = this->last_event_on_subcurve(sc);
@ -514,8 +503,7 @@ template <typename Hlpr, typename Vis>
typename Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>::Halfedge_handle typename Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>::Halfedge_handle
Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>:: Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>::
_insert_from_left_vertex(const X_monotone_curve_2& cv, _insert_from_left_vertex(const X_monotone_curve_2& cv,
Halfedge_handle prev, Subcurve* sc) Halfedge_handle prev, Subcurve* sc) {
{
// Check if the vertex to be associated with the right end of the curve has // Check if the vertex to be associated with the right end of the curve has
// already been created. // already been created.
Event* curr_event = this->current_event(); Event* curr_event = this->current_event();
@ -551,8 +539,7 @@ template <typename Hlpr, typename Vis>
typename Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>::Halfedge_handle typename Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>::Halfedge_handle
Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>:: Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>::
_insert_from_right_vertex(const X_monotone_curve_2& cv, Halfedge_handle prev, _insert_from_right_vertex(const X_monotone_curve_2& cv, Halfedge_handle prev,
Subcurve* sc) Subcurve* sc) {
{
// Check if the vertex to be associated with the left end of the curve has // Check if the vertex to be associated with the left end of the curve has
// already been created. // already been created.
Event* last_event = this->last_event_on_subcurve(sc); Event* last_event = this->last_event_on_subcurve(sc);
@ -589,8 +576,7 @@ typename Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>::Halfedge_handle
Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>:: Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>::
_insert_at_vertices(const X_monotone_curve_2& cv, _insert_at_vertices(const X_monotone_curve_2& cv,
Halfedge_handle prev1, Halfedge_handle prev2, Halfedge_handle prev1, Halfedge_handle prev2,
Subcurve* sc, bool& new_face_created) Subcurve* sc, bool& new_face_created) {
{
// Perform the insertion. // Perform the insertion.
new_face_created = false; new_face_created = false;
bool swapped_predecessors = false; bool swapped_predecessors = false;
@ -632,8 +618,7 @@ _insert_at_vertices(const X_monotone_curve_2& cv,
template <typename Hlpr, typename Vis> template <typename Hlpr, typename Vis>
typename Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>::Face_handle typename Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>::Face_handle
Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>:: Arr_no_intersection_insertion_ss_visitor<Hlpr, Vis>::
_ray_shoot_up(Status_line_iterator iter) _ray_shoot_up(Status_line_iterator iter) {
{
// Go up the status line and try to locate a curve which is associated // Go up the status line and try to locate a curve which is associated
// with a valid arrangement halfedge. // with a valid arrangement halfedge.
const Halfedge_handle invalid_he; const Halfedge_handle invalid_he;

View File

@ -71,6 +71,7 @@ private:
public: public:
using X_monotone_curve_2 = typename Gt2::X_monotone_curve_2; using X_monotone_curve_2 = typename Gt2::X_monotone_curve_2;
using Point_2 = typename Gt2::Point_2; using Point_2 = typename Gt2::Point_2;
using Multiplicity = typename Gt2::Multiplicity;
// The input arrangements (the "red" and the "blue" one): // The input arrangements (the "red" and the "blue" one):
using Halfedge_handle_red = typename Ar2::Halfedge_const_handle; using Halfedge_handle_red = typename Ar2::Halfedge_const_handle;
@ -182,7 +183,8 @@ public:
void update_event(Event* /* e */, void update_event(Event* /* e */,
Subcurve* /* c1 */, Subcurve* /* c1 */,
Subcurve* /* c2 */, Subcurve* /* c2 */,
bool CGAL_assertion_code(is_new)) bool CGAL_assertion_code(is_new),
Multiplicity /* multiplicity */)
{ CGAL_assertion(is_new == true); } { CGAL_assertion(is_new == true); }
/*! Update an event. */ /*! Update an event. */

View File

@ -48,6 +48,7 @@ public:
using Status_line_iterator = typename Base::Status_line_iterator; using Status_line_iterator = typename Base::Status_line_iterator;
using X_monotone_curve_2 = typename Base::X_monotone_curve_2; using X_monotone_curve_2 = typename Base::X_monotone_curve_2;
using Point_2 = typename Base::Point_2; using Point_2 = typename Base::Point_2;
using Multiplicity = typename Base::Multiplicity;
Gps_do_intersect_agg_op_visitor(Arr* arr, Edges_hash* hash, Gps_do_intersect_agg_op_visitor(Arr* arr, Edges_hash* hash,
std::vector<Vertex_handle>* vertices_vec) : std::vector<Vertex_handle>* vertices_vec) :
@ -57,22 +58,26 @@ public:
/*! Update an event that corresponds to a curve endpoint. */ /*! Update an event that corresponds to a curve endpoint. */
void update_event(Event* e, const Point_2& end_point, const X_monotone_curve_2& cv, Arr_curve_end cv_end, bool is_new) void update_event(Event* e, const Point_2& end_point, const X_monotone_curve_2& cv, Arr_curve_end cv_end, bool is_new)
{ return Base::update_event(e, end_point, cv, cv_end, is_new); } { Base::update_event(e, end_point, cv, cv_end, is_new); }
/*! Update an event that corresponds to a curve endpoint */ /*! Update an event that corresponds to a curve endpoint */
void update_event(Event* e, const X_monotone_curve_2& cv, Arr_curve_end cv_end, bool is_new ) void update_event(Event* e, const X_monotone_curve_2& cv, Arr_curve_end cv_end, bool is_new )
{ return Base::update_event(e, cv, cv_end, is_new); } { Base::update_event(e, cv, cv_end, is_new); }
/*! Update an event that corresponds to a curve endpoint */ /*! Update an event that corresponds to a curve endpoint */
void update_event(Event* e, const Point_2& p, bool is_new) void update_event(Event* e, const Point_2& p, bool is_new)
{ return Base::update_event(e, p, is_new); } { Base::update_event(e, p, is_new); }
/*! Update an event that corresponds to an intersection */ /*! Update an event that corresponds to an intersection */
void update_event(Event* e, Subcurve* sc) { return Base::update_event(e, sc); } void update_event(Event* e, Subcurve* sc) { Base::update_event(e, sc); }
/*! Update an event that corresponds to an intersection between curves */ /*! Update an event that corresponds to an intersection between curves */
void update_event(Event*, Subcurve*, Subcurve*, bool is_new) { m_found_x = true; } void update_event(Event* e, Subcurve* sc1, Subcurve* sc2, bool is_new, Multiplicity multiplicity) {
if ((multiplicity % 2) == 1) m_found_x = true;
Base::update_event(e, sc1, sc2, is_new, multiplicity);
}
//!
bool after_handle_event(Event* e, Status_line_iterator iter, bool flag) { bool after_handle_event(Event* e, Status_line_iterator iter, bool flag) {
auto res = Base::after_handle_event(e, iter, flag); auto res = Base::after_handle_event(e, iter, flag);
if (m_found_x) this->surface_sweep()->stop_sweep(); if (m_found_x) this->surface_sweep()->stop_sweep();

View File

@ -539,9 +539,10 @@ public:
_remove_redundant_edges(arr_vec[0].first); _remove_redundant_edges(arr_vec[0].first);
_reset_faces(arr_vec[0].first); _reset_faces(arr_vec[0].first);
return (_is_empty(arr_vec[0].first)); return ! _is_empty(arr_vec[0].first);
} }
//!
template <typename InputIterator1, typename InputIterator2> template <typename InputIterator1, typename InputIterator2>
bool do_intersect(InputIterator1 begin1, InputIterator1 end1, bool do_intersect(InputIterator1 begin1, InputIterator1 end1,
InputIterator2 begin2, InputIterator2 end2, InputIterator2 begin2, InputIterator2 end2,
@ -550,6 +551,7 @@ public:
return other._do_intersect(begin1, end1, begin2, end2, k); return other._do_intersect(begin1, end1, begin2, end2, k);
} }
//!
template <typename InputIterator1, typename InputIterator2> template <typename InputIterator1, typename InputIterator2>
bool _do_intersect(InputIterator1 begin1, InputIterator1 end1, bool _do_intersect(InputIterator1 begin1, InputIterator1 end1,
InputIterator2 begin2, InputIterator2 end2, InputIterator2 begin2, InputIterator2 end2,
@ -558,13 +560,13 @@ public:
arr_vec[0].first = this->m_arr; arr_vec[0].first = this->m_arr;
std::size_t i = 1; std::size_t i = 1;
for (InputIterator1 itr1 = begin1; itr1 != end1; ++itr1, ++i) { for (auto itr1 = begin1; itr1 != end1; ++itr1, ++i) {
ValidationPolicy::is_valid(*itr1, *m_traits); ValidationPolicy::is_valid(*itr1, *m_traits);
arr_vec[i].first = new Aos_2(m_traits); arr_vec[i].first = new Aos_2(m_traits);
_insert(*itr1, *(arr_vec[i].first)); _insert(*itr1, *(arr_vec[i].first));
} }
for (InputIterator2 itr2 = begin2; itr2 != end2; ++itr2, ++i) { for (auto itr2 = begin2; itr2 != end2; ++itr2, ++i) {
ValidationPolicy::is_valid(*itr2,*m_traits); ValidationPolicy::is_valid(*itr2,*m_traits);
arr_vec[i].first = new Aos_2(m_traits); arr_vec[i].first = new Aos_2(m_traits);
_insert(*itr2, *(arr_vec[i].first)); _insert(*itr2, *(arr_vec[i].first));
@ -586,7 +588,7 @@ public:
_remove_redundant_edges(arr_vec[0].first); _remove_redundant_edges(arr_vec[0].first);
_reset_faces(arr_vec[0].first); _reset_faces(arr_vec[0].first);
return (_is_empty(arr_vec[0].first)); return ! _is_empty(arr_vec[0].first);
} }
// joins a range of polygons // joins a range of polygons
@ -705,7 +707,6 @@ public:
// the result arrangement is at index 0 // the result arrangement is at index 0
this->m_arr = arr_vec[0].first; this->m_arr = arr_vec[0].first;
delete arr_vec[0].second; delete arr_vec[0].second;
std::cout << "XXXX 1 no. faces: " << m_arr->number_of_faces() << "\n";
} }
// intersects a range of polygons with holes // intersects a range of polygons with holes
@ -728,7 +729,6 @@ public:
// the result arrangement is at index 0 // the result arrangement is at index 0
this->m_arr = arr_vec[0].first; this->m_arr = arr_vec[0].first;
delete arr_vec[0].second; delete arr_vec[0].second;
std::cout << "XXXX 2 no. edges: " << m_arr->number_of_edges() << "\n";
} }
template <typename InputIterator1, typename InputIterator2> template <typename InputIterator1, typename InputIterator2>
@ -1267,9 +1267,9 @@ protected:
std::vector<Arr_entry>& arr_vec, std::vector<Arr_entry>& arr_vec,
std::size_t k, Merge merge_func) { std::size_t k, Merge merge_func) {
static int indent = 0; static int indent = 0;
std::cout << std::setw(indent) << "" << "D&C [" << lower << "," << upper << "," << k << "]\n"; // std::cout << std::setw(indent) << "" << "D&C [" << lower << "," << upper << "," << k << "]\n";
if ((upper - lower) < k) { if ((upper - lower) < k) {
std::cout << std::setw(indent) << "" << "Merging [" << lower << "," << upper << "," << 1 << "]\n"; // std::cout << std::setw(indent) << "" << "Merging [" << lower << "," << upper << "," << 1 << "]\n";
_build_sorted_vertices_vectors(lower, upper, arr_vec); _build_sorted_vertices_vectors(lower, upper, arr_vec);
merge_func(lower, upper, 1, arr_vec); merge_func(lower, upper, 1, arr_vec);
return; return;
@ -1286,7 +1286,7 @@ protected:
indent += 2; indent += 2;
_divide_and_conquer(curr_lower, upper, arr_vec, k, merge_func); _divide_and_conquer(curr_lower, upper, arr_vec, k, merge_func);
indent -= 2; indent -= 2;
std::cout << std::setw(indent) << "" << "Merging [" << lower << "," << curr_lower << "," << sub_size << "]\n"; // std::cout << std::setw(indent) << "" << "Merging [" << lower << "," << curr_lower << "," << sub_size << "]\n";
merge_func(lower, curr_lower, sub_size, arr_vec); merge_func(lower, curr_lower, sub_size, arr_vec);
} }

View File

@ -0,0 +1,95 @@
#include <iostream>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Boolean_set_operations_2.h>
#include <CGAL/Arr_circle_segment_traits_2.h>
#include <CGAL/General_polygon_2.h>
#include <CGAL/Boolean_set_operations_2.h>
// #include <CGAL/draw_arrangement_2.h>
using Kernel = CGAL::Exact_predicates_exact_constructions_kernel;
using Point_2 = Kernel::Point_2;
using Polygon_2 = CGAL::Polygon_2<Kernel>;
using Circle_2 = Kernel::Circle_2;
int main(int argc, char* argv[]) {
Kernel kernel;
auto ctr_circle = kernel.construct_circle_2_object();
auto circle1 = ctr_circle(Point_2(0, 1), 1);
auto circle2 = ctr_circle(Point_2(0, -1), 1);
auto circle3 = ctr_circle(Point_2(0, 2), 4);
// 1. Circular arcs and linear segments
using Circle_segment_arr_traits_2 = CGAL::Arr_circle_segment_traits_2<Kernel>;
using Circle_segment_xcv_2 = Circle_segment_arr_traits_2::X_monotone_curve_2;
using Circle_segment_pnt_2 = Circle_segment_arr_traits_2::Point_2;
using Circle_segment_gps_traits_2 = CGAL::Gps_traits_2<Circle_segment_arr_traits_2>;
using Circle_segment_polygon = Circle_segment_gps_traits_2::General_polygon_2;
using Circle_segment_polygon_with_holes = Circle_segment_gps_traits_2::General_polygon_with_holes_2;
Circle_segment_arr_traits_2 circle_segment_traits;
Circle_segment_pnt_2 cs_pnt11(1, 1);
Circle_segment_pnt_2 cs_pnt12(-1, 1);
Circle_segment_xcv_2 xcv11(circle1, cs_pnt11, cs_pnt12, CGAL::COUNTERCLOCKWISE);
Circle_segment_xcv_2 xcv12(circle1, cs_pnt12, cs_pnt11, CGAL::COUNTERCLOCKWISE);
Circle_segment_polygon pgn1;
pgn1.push_back(xcv11);
pgn1.push_back(xcv12);
Circle_segment_pnt_2 cs_pnt21(1, -1);
Circle_segment_pnt_2 cs_pnt22(-1, -1);
Circle_segment_xcv_2 xcv21(circle2, cs_pnt21, cs_pnt22, CGAL::COUNTERCLOCKWISE);
Circle_segment_xcv_2 xcv22(circle2, cs_pnt22, cs_pnt21, CGAL::COUNTERCLOCKWISE);
Circle_segment_polygon pgn2;
pgn2.push_back(xcv21);
pgn2.push_back(xcv22);
Circle_segment_pnt_2 cs_pnt31(2, 2);
Circle_segment_pnt_2 cs_pnt32(-2, 2);
Circle_segment_xcv_2 xcv31(circle3, cs_pnt31, cs_pnt32, CGAL::COUNTERCLOCKWISE);
Circle_segment_xcv_2 xcv32(circle3, cs_pnt32, cs_pnt31, CGAL::COUNTERCLOCKWISE);
Circle_segment_polygon pgn3;
pgn3.push_back(xcv31);
pgn3.push_back(xcv32);
// 1.1.
auto do_intersect = CGAL::do_intersect(pgn1, pgn2);
if (do_intersect) {
std::cerr << "The circles intersect (case 1)\n" << std::endl;
return 1;
}
// 1.2.
std::vector<Circle_segment_polygon> pgns1 = { pgn1, pgn2 };
do_intersect = CGAL::do_intersect(pgns1.begin(), pgns1.end());
if (do_intersect) {
std::cerr << "The circles intersect (case 2)\n" << std::endl;
return 1;
}
// 2.1.
do_intersect = CGAL::do_intersect(pgn1, pgn3);
if (! do_intersect) {
std::cerr << "The circles do not intersect (case 1)\n" << std::endl;
return 1;
}
// 2.2.
std::vector<Circle_segment_polygon> pgns2 = { pgn1, pgn3 };
do_intersect = CGAL::do_intersect(pgns2.begin(), pgns2.end());
if (! do_intersect) {
std::cerr << "The circles do not intersect (case 2)\n" << std::endl;
return 1;
}
// using Circle_segment_arr = CGAL::Arrangement_2<Circle_segment_arr_traits_2>;
// Circle_segment_arr arr;
// CGAL::insert_non_intersecting_curve(arr, xcv11);
// CGAL::insert_non_intersecting_curve(arr, xcv12);
// CGAL::insert_non_intersecting_curve(arr, xcv21);
// CGAL::insert_non_intersecting_curve(arr, xcv22);
// CGAL::draw(arr);
return 0;
}

View File

@ -50,28 +50,27 @@ template <typename GeometryTraits_2, typename Event_, typename Subcurve_,
typename Allocator_, typename Visitor_> typename Allocator_, typename Visitor_>
class Default_visitor_base { class Default_visitor_base {
public: public:
typedef GeometryTraits_2 Geometry_traits_2; using Geometry_traits_2 = GeometryTraits_2;
typedef Event_ Event; using Event = Event_;
typedef Subcurve_ Subcurve; using Subcurve = Subcurve_;
typedef Allocator_ Allocator; using Allocator = Allocator_;
typedef Visitor_ Visitor; using Visitor = Visitor_;
private: private:
typedef Geometry_traits_2 Gt2; using Gt2 = Geometry_traits_2;
typedef Default_visitor_base<Gt2, Event, Subcurve, Allocator, Visitor> using Self = Default_visitor_base<Gt2, Event, Subcurve, Allocator, Visitor>;
Self;
public: public:
typedef typename Subcurve::Status_line_iterator Status_line_iterator; using Status_line_iterator = typename Subcurve::Status_line_iterator;
typedef typename Gt2::X_monotone_curve_2 X_monotone_curve_2; using X_monotone_curve_2 = typename Gt2::X_monotone_curve_2;
typedef typename Gt2::Point_2 Point_2; using Point_2 = typename Gt2::Point_2;
using Multiplicity = typename Gt2::Multiplicity;
typedef typename Event::Subcurve_iterator Event_subcurve_iterator; using Event_subcurve_iterator = typename Event::Subcurve_iterator;
typedef typename Event::Subcurve_reverse_iterator using Event_subcurve_reverse_iterator = typename Event::Subcurve_reverse_iterator;
Event_subcurve_reverse_iterator;
typedef No_intersection_surface_sweep_2<Visitor> Surface_sweep_2; using Surface_sweep_2 = No_intersection_surface_sweep_2<Visitor>;
protected: protected:
// Data members: // Data members:
@ -134,7 +133,8 @@ public:
void update_event(Event* /* e */, void update_event(Event* /* e */,
Subcurve* /* sc1 */, Subcurve* /* sc1 */,
Subcurve* /* sc2 */, Subcurve* /* sc2 */,
bool /* is_new */) bool /* is_new */,
Multiplicity /* multiplicity */)
{} {}
/*! Update the event. */ /*! Update the event. */

View File

@ -39,27 +39,27 @@ template <typename GeometryTraits_2,
class Do_interior_intersect_visitor : class Do_interior_intersect_visitor :
public Default_visitor<Do_interior_intersect_visitor<GeometryTraits_2, public Default_visitor<Do_interior_intersect_visitor<GeometryTraits_2,
Allocator_>, Allocator_>,
GeometryTraits_2, Allocator_> GeometryTraits_2, Allocator_> {
{
public: public:
typedef GeometryTraits_2 Geometry_traits_2; using Geometry_traits_2 = GeometryTraits_2;
typedef Allocator_ Allocator; using Allocator = Allocator_;
private: private:
typedef Geometry_traits_2 Gt2; using Gt2 = Geometry_traits_2;
typedef Do_interior_intersect_visitor<Gt2, Allocator> Self; using Self = Do_interior_intersect_visitor<Gt2, Allocator>;
typedef Default_visitor<Self, Gt2, Allocator> Base; using Base = Default_visitor<Self, Gt2, Allocator>;
public: public:
typedef typename Base::Event Event; using Event = typename Base::Event;
typedef typename Base::Subcurve Subcurve; using Subcurve = typename Base::Subcurve;
typedef typename Subcurve::Status_line_iterator Status_line_iterator; using Status_line_iterator = typename Subcurve::Status_line_iterator;
typedef typename Gt2::X_monotone_curve_2 X_monotone_curve_2; using X_monotone_curve_2 = typename Gt2::X_monotone_curve_2;
typedef typename Gt2::Point_2 Point_2; using Point_2 = typename Gt2::Point_2;
using Multiplicity = typename Gt2::Multiplicity;
typedef typename Base::Surface_sweep_2 Surface_sweep_2; using Surface_sweep_2 = typename Base::Surface_sweep_2;
protected: protected:
// Data members: // Data members:
@ -69,8 +69,7 @@ public:
Do_interior_intersect_visitor() : m_found_x(false) {} Do_interior_intersect_visitor() : m_found_x(false) {}
template <typename CurveIterator> template <typename CurveIterator>
void sweep(CurveIterator begin, CurveIterator end) void sweep(CurveIterator begin, CurveIterator end) {
{
std::vector<X_monotone_curve_2> curves_vec; std::vector<X_monotone_curve_2> curves_vec;
std::vector<Point_2> points_vec; std::vector<Point_2> points_vec;
@ -89,7 +88,8 @@ public:
void update_event(Event* /* e */, void update_event(Event* /* e */,
Subcurve* /* sc1 */, Subcurve* /* sc1 */,
Subcurve* /* sc2 */, Subcurve* /* sc2 */,
bool /* is_new */) bool /* is_new */,
Multiplicity multiplicity = 0)
{ m_found_x = true; } { m_found_x = true; }
void update_event(Event* /* e */, void update_event(Event* /* e */,
@ -115,8 +115,7 @@ public:
{} {}
template <typename XCurveIterator> template <typename XCurveIterator>
void sweep_xcurves(XCurveIterator begin, XCurveIterator end) void sweep_xcurves(XCurveIterator begin, XCurveIterator end) {
{
// Perform the sweep. // Perform the sweep.
Surface_sweep_2* sl = this->surface_sweep(); Surface_sweep_2* sl = this->surface_sweep();
sl->sweep(begin, end); sl->sweep(begin, end);
@ -129,8 +128,7 @@ public:
bool after_handle_event(Event* /* event */, bool after_handle_event(Event* /* event */,
Status_line_iterator /* iter */, Status_line_iterator /* iter */,
bool /* flag */) bool /* flag */) {
{
if (m_found_x) { if (m_found_x) {
Surface_sweep_2* sl = this->surface_sweep(); Surface_sweep_2* sl = this->surface_sweep();
sl->stop_sweep(); sl->stop_sweep();

View File

@ -9,7 +9,7 @@
// //
// Author(s) : Baruch Zukerman <baruchzu@post.tau.ac.il> // Author(s) : Baruch Zukerman <baruchzu@post.tau.ac.il>
// Efi Fogel <efif@post.tau.ac.il> // Efi Fogel <efif@post.tau.ac.il>
// (based on old version by Tali Zvi) // (based on a previous version developed by Tali Zvi)
#ifndef CGAL_SURFACE_SWEEP_2_IMPL_H #ifndef CGAL_SURFACE_SWEEP_2_IMPL_H
#define CGAL_SURFACE_SWEEP_2_IMPL_H #define CGAL_SURFACE_SWEEP_2_IMPL_H
@ -33,8 +33,7 @@ namespace Surface_sweep_2 {
// Initialize the data structures for the sweep-line algorithm. // Initialize the data structures for the sweep-line algorithm.
// //
template <typename Vis> template <typename Vis>
void Surface_sweep_2<Vis>::_init_structures() void Surface_sweep_2<Vis>::_init_structures() {
{
// Initialize the structures maintained by the base sweep-line class. // Initialize the structures maintained by the base sweep-line class.
Base::_init_structures(); Base::_init_structures();
} }
@ -43,8 +42,7 @@ void Surface_sweep_2<Vis>::_init_structures()
// Complete the sweep (complete the data structures). // Complete the sweep (complete the data structures).
// //
template <typename Vis> template <typename Vis>
void Surface_sweep_2<Vis>::_complete_sweep() void Surface_sweep_2<Vis>::_complete_sweep() {
{
CGAL_SS_PRINT_START_EOL("completing the sweep"); CGAL_SS_PRINT_START_EOL("completing the sweep");
// Complete the sweep process using base sweep-line class. // Complete the sweep process using base sweep-line class.
@ -68,8 +66,7 @@ void Surface_sweep_2<Vis>::_complete_sweep()
// Handle the subcurves to the left of the current event point. // Handle the subcurves to the left of the current event point.
// //
template <typename Vis> template <typename Vis>
void Surface_sweep_2<Vis>::_handle_left_curves() void Surface_sweep_2<Vis>::_handle_left_curves() {
{
CGAL_SS_PRINT_START("handling left curves at ("); CGAL_SS_PRINT_START("handling left curves at (");
CGAL_SS_DEBUG(this->PrintEvent(this->m_currentEvent)); CGAL_SS_DEBUG(this->PrintEvent(this->m_currentEvent));
CGAL_SS_PRINT_TEXT(")"); CGAL_SS_PRINT_TEXT(")");
@ -189,14 +186,12 @@ void Surface_sweep_2<Vis>::_handle_left_curves()
// and with a left end not being the current event // and with a left end not being the current event
// //
template <typename Vis> template <typename Vis>
void Surface_sweep_2<Vis>::_clip_non_active_curve_at_current_event(Subcurve* subcurve) void Surface_sweep_2<Vis>::_clip_non_active_curve_at_current_event(Subcurve* subcurve) {
{
// ignore active curve (will be split at intersection point) // ignore active curve (will be split at intersection point)
if (subcurve->hint() != this->m_statusLine.end() && if (subcurve->hint() != this->m_statusLine.end() &&
subcurve->hint() != Status_line_iterator() ) return; subcurve->hint() != Status_line_iterator() ) return;
if (!subcurve->is_start_point(this->m_currentEvent)) if (! subcurve->is_start_point(this->m_currentEvent)) {
{
CGAL_SS_PRINT_TEXT("Splitting "); CGAL_SS_PRINT_TEXT("Splitting ");
CGAL_SS_PRINT_CURVE(subcurve); CGAL_SS_PRINT_CURVE(subcurve);
CGAL_SS_PRINT_EOL(); CGAL_SS_PRINT_EOL();
@ -215,13 +210,11 @@ void Surface_sweep_2<Vis>::_clip_non_active_curve_at_current_event(Subcurve* sub
// Handle the overlaps between subcurves to the right of the current event point. // Handle the overlaps between subcurves to the right of the current event point.
// //
template <typename Vis> template <typename Vis>
void Surface_sweep_2<Vis>::_handle_overlaps_in_right_curves() void Surface_sweep_2<Vis>::_handle_overlaps_in_right_curves() {
{ const std::vector< std::pair<Subcurve*, Subcurve*> >& subcurve_pairs =
const std::vector< std::pair<Subcurve*, Subcurve*> >& subcurve_pairs this->m_currentEvent->overlaps_on_right;
= this->m_currentEvent->overlaps_on_right;
if (!subcurve_pairs.empty()) if (!subcurve_pairs.empty()) {
{
// handling overlaps on the right of the current event. // handling overlaps on the right of the current event.
// Only one curve from the overlapping curve is currently // Only one curve from the overlapping curve is currently
// in the right curves of the event. Other curve overlapping // in the right curves of the event. Other curve overlapping
@ -240,11 +233,10 @@ void Surface_sweep_2<Vis>::_handle_overlaps_in_right_curves()
// in the following map having a curve on the right of the event // in the following map having a curve on the right of the event
// as key, we get all the curves that overlap with that curve // as key, we get all the curves that overlap with that curve
// on the right of the event // on the right of the event
typedef std::map<Subcurve*, std::vector<Subcurve*> > Subcurve_map; typedef std::map<Subcurve*, std::vector<Subcurve*>> Subcurve_map;
Subcurve_map tests_per_subcurve_on_right; Subcurve_map tests_per_subcurve_on_right;
for (std::size_t i=0; i<nb_p; ++i) for (std::size_t i = 0; i < nb_p; ++i) {
{
CGAL_SS_PRINT_TEXT("("); CGAL_SS_PRINT_TEXT("(");
CGAL_SS_PRINT(subcurve_pairs[i].first); CGAL_SS_PRINT(subcurve_pairs[i].first);
CGAL_SS_PRINT_TEXT(","); CGAL_SS_PRINT_TEXT(",");
@ -254,13 +246,10 @@ void Surface_sweep_2<Vis>::_handle_overlaps_in_right_curves()
tests_per_subcurve_on_right[subcurve_pairs[i].first].push_back(subcurve_pairs[i].second); tests_per_subcurve_on_right[subcurve_pairs[i].first].push_back(subcurve_pairs[i].second);
} }
for(typename Subcurve_map::iterator it = tests_per_subcurve_on_right.begin(), for (auto it = tests_per_subcurve_on_right.begin(), end = tests_per_subcurve_on_right.end(); it != end; ++it) {
end = tests_per_subcurve_on_right.end(); it!=end; ++it)
{
std::size_t nbc = it->second.size(); std::size_t nbc = it->second.size();
// remove possible duplicates // remove possible duplicates
if (nbc>1) if (nbc > 1) {
{
std::sort(it->second.begin(), it->second.end()); std::sort(it->second.begin(), it->second.end());
typename std::vector<Subcurve*>::iterator last = typename std::vector<Subcurve*>::iterator last =
std::unique(it->second.begin(), it->second.end()); std::unique(it->second.begin(), it->second.end());
@ -277,8 +266,7 @@ void Surface_sweep_2<Vis>::_handle_overlaps_in_right_curves()
else{ else{
// get the curve just after the key in the sorted set of curves on the right as it might be replaced // get the curve just after the key in the sorted set of curves on the right as it might be replaced
Subcurve_iterator next_after = this->m_currentEvent->get_curve_after_on_right(it->first); Subcurve_iterator next_after = this->m_currentEvent->get_curve_after_on_right(it->first);
for (std::size_t i=0; i<nbc; ++i) for (std::size_t i = 0; i < nbc; ++i) {
{
_intersect(it->second[i], *std::prev(next_after), this->m_currentEvent); _intersect(it->second[i], *std::prev(next_after), this->m_currentEvent);
CGAL_assertion(it->second.size()==nbc); // make sure the container was not updated CGAL_assertion(it->second.size()==nbc); // make sure the container was not updated
} }
@ -289,27 +277,19 @@ void Surface_sweep_2<Vis>::_handle_overlaps_in_right_curves()
} }
// split curves not already split. TODO: this should be done above? // split curves not already split. TODO: this should be done above?
for (Event_subcurve_iterator subcurve_it = this->m_currentEvent->right_curves_begin(); for (auto subcurve_it = this->m_currentEvent->right_curves_begin();
subcurve_it != this->m_currentEvent->right_curves_end(); subcurve_it != this->m_currentEvent->right_curves_end(); ++subcurve_it)
++subcurve_it)
{
_clip_non_active_curve_at_current_event(*subcurve_it); _clip_non_active_curve_at_current_event(*subcurve_it);
}
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Handle the subcurves to the right of the current event point. // Handle the subcurves to the right of the current event point.
// //
template <typename Vis> template <typename Vis>
void Surface_sweep_2<Vis>::_handle_right_curves() void Surface_sweep_2<Vis>::_handle_right_curves() {
{ for (auto sc_it = this->m_currentEvent->right_curves_begin(), sc_it_end = this->m_currentEvent->right_curves_end();
sc_it != sc_it_end; ++sc_it)
for(Event_subcurve_iterator sc_it = this->m_currentEvent->right_curves_begin(),
sc_it_end = this->m_currentEvent->right_curves_end();
sc_it!=sc_it_end; ++sc_it)
{
(*sc_it)->reset_left_event(); (*sc_it)->reset_left_event();
}
CGAL_SS_PRINT_START("handling right curves at ("); CGAL_SS_PRINT_START("handling right curves at (");
CGAL_SS_DEBUG(this->PrintEvent(this->m_currentEvent)); CGAL_SS_DEBUG(this->PrintEvent(this->m_currentEvent));
@ -329,15 +309,11 @@ void Surface_sweep_2<Vis>::_handle_right_curves()
// - We also check to see if the two intersect again to the right of the // - We also check to see if the two intersect again to the right of the
// point. // point.
Event_subcurve_iterator currentOne = Event_subcurve_iterator currentOne = this->m_currentEvent->right_curves_begin();
this->m_currentEvent->right_curves_begin(); Event_subcurve_iterator rightCurveEnd = this->m_currentEvent->right_curves_end();
Event_subcurve_iterator rightCurveEnd =
this->m_currentEvent->right_curves_end();
CGAL_SS_PRINT_INSERT(*currentOne); CGAL_SS_PRINT_INSERT(*currentOne);
Status_line_iterator slIter = Status_line_iterator slIter = this->m_statusLine.insert_before(this->m_status_line_insert_hint, *currentOne);
this->m_statusLine.insert_before(this->m_status_line_insert_hint,
*currentOne);
Subcurve* sc = *currentOne; Subcurve* sc = *currentOne;
sc->set_hint(slIter); sc->set_hint(slIter);
@ -352,8 +328,7 @@ void Surface_sweep_2<Vis>::_handle_right_curves()
++currentOne; ++currentOne;
while (currentOne != rightCurveEnd) { while (currentOne != rightCurveEnd) {
CGAL_SS_PRINT_INSERT(*currentOne); CGAL_SS_PRINT_INSERT(*currentOne);
slIter = this->m_statusLine.insert_before(this->m_status_line_insert_hint, slIter = this->m_statusLine.insert_before(this->m_status_line_insert_hint, *currentOne);
*currentOne);
Subcurve* sc = *currentOne; Subcurve* sc = *currentOne;
sc->set_hint(slIter); sc->set_hint(slIter);
@ -390,12 +365,8 @@ bool Surface_sweep_2<Vis>::_add_curve_to_right(Event* event, Subcurve* curve)
CGAL_SS_PRINT_CURVE(curve); CGAL_SS_PRINT_CURVE(curve);
CGAL_SS_PRINT_EOL(); CGAL_SS_PRINT_EOL();
Event_subcurve_iterator iter; for (auto iter = event->right_curves_begin(); iter != event->right_curves_end(); ++iter) {
for (iter = event->right_curves_begin(); iter != event->right_curves_end(); if (*iter == curve) {
++iter)
{
if (*iter == curve)
{
CGAL_SS_PRINT_END_EOL("adding a Curve to the right (curve exists)"); CGAL_SS_PRINT_END_EOL("adding a Curve to the right (curve exists)");
return false; return false;
} }
@ -405,8 +376,7 @@ bool Surface_sweep_2<Vis>::_add_curve_to_right(Event* event, Subcurve* curve)
if ((*iter)->are_all_leaves_contained(curve)) { if ((*iter)->are_all_leaves_contained(curve)) {
CGAL_SS_PRINT_END_EOL("adding a Curve to the right (containing curve exists)"); CGAL_SS_PRINT_END_EOL("adding a Curve to the right (containing curve exists)");
if ( (*iter)->right_event() != curve->right_event() ) if ((*iter)->right_event() != curve->right_event()) {
{
CGAL_assertion( this->m_queueEventLess((*iter)->right_event(), curve->right_event()) == SMALLER ); // subcurve has to end before CGAL_assertion( this->m_queueEventLess((*iter)->right_event(), curve->right_event()) == SMALLER ); // subcurve has to end before
_add_curve_to_right( (*iter)->right_event(), curve); // WARNING recursive _add_curve_to_right( (*iter)->right_event(), curve); // WARNING recursive
} }
@ -417,8 +387,7 @@ bool Surface_sweep_2<Vis>::_add_curve_to_right(Event* event, Subcurve* curve)
} }
if (curve->are_all_leaves_contained(*iter)) { if (curve->are_all_leaves_contained(*iter)) {
if ( (*iter)->right_event() != curve->right_event() ) if ( (*iter)->right_event() != curve->right_event()) {
{
CGAL_assertion(this->m_queueEventLess(curve->right_event(), (*iter)->right_event()) == SMALLER); // subcurve has to end before CGAL_assertion(this->m_queueEventLess(curve->right_event(), (*iter)->right_event()) == SMALLER); // subcurve has to end before
_add_curve_to_right( curve->right_event(), *iter); // WARNING recursive _add_curve_to_right( curve->right_event(), *iter); // WARNING recursive
} }
@ -426,8 +395,7 @@ bool Surface_sweep_2<Vis>::_add_curve_to_right(Event* event, Subcurve* curve)
(*iter)->right_event()->remove_curve_from_left(*iter); (*iter)->right_event()->remove_curve_from_left(*iter);
*iter = curve; // replace the current curve with the new one. *iter = curve; // replace the current curve with the new one.
CGAL_SS_PRINT_END_EOL CGAL_SS_PRINT_END_EOL("replacing a Curve to the right (curve partially overlaps)");
("replacing a Curve to the right (curve partially overlaps)");
return false; return false;
} }
@ -443,11 +411,10 @@ bool Surface_sweep_2<Vis>::_add_curve_to_right(Event* event, Subcurve* curve)
} }
// a new overlap needs to be computed // a new overlap needs to be computed
if (event!=this->m_currentEvent) if (event != this->m_currentEvent)
event->overlaps_on_right.push_back( event->overlaps_on_right.push_back(
std::make_pair(static_cast<Subcurve*>(*(pair_res.second)), std::make_pair(static_cast<Subcurve*>(*(pair_res.second)),
static_cast<Subcurve*>(curve)) static_cast<Subcurve*>(curve)));
);
else else
_intersect(static_cast<Subcurve*>(curve), _intersect(static_cast<Subcurve*>(curve),
static_cast<Subcurve*>(*(pair_res.second)), static_cast<Subcurve*>(*(pair_res.second)),
@ -467,8 +434,7 @@ bool Surface_sweep_2<Vis>::_add_curve_to_right(Event* event, Subcurve* curve)
// //
template <typename Vis> template <typename Vis>
void Surface_sweep_2<Vis>::_remove_curve_from_status_line(Subcurve* leftCurve, void Surface_sweep_2<Vis>::_remove_curve_from_status_line(Subcurve* leftCurve,
bool remove_for_good) bool remove_for_good) {
{
CGAL_SS_PRINT_START("removing a curve from the status line, "); CGAL_SS_PRINT_START("removing a curve from the status line, ");
CGAL_SS_PRINT_CURVE(leftCurve); CGAL_SS_PRINT_CURVE(leftCurve);
CGAL_SS_PRINT_EOL(); CGAL_SS_PRINT_EOL();
@ -513,8 +479,7 @@ void Surface_sweep_2<Vis>::_remove_curve_from_status_line(Subcurve* leftCurve,
// //
template <typename Vis> template <typename Vis>
void Surface_sweep_2<Vis>::_intersect(Subcurve* c1, Subcurve* c2, void Surface_sweep_2<Vis>::_intersect(Subcurve* c1, Subcurve* c2,
Event* event_for_overlap) Event* event_for_overlap) {
{
CGAL_SS_PRINT_START("computing intersection of "); CGAL_SS_PRINT_START("computing intersection of ");
CGAL_SS_PRINT_CURVE(c1); CGAL_SS_PRINT_CURVE(c1);
CGAL_SS_PRINT_TEXT(" and "); CGAL_SS_PRINT_TEXT(" and ");
@ -538,8 +503,7 @@ void Surface_sweep_2<Vis>::_intersect(Subcurve* c1, Subcurve* c2,
Subcurve_vector all_leaves_diff; Subcurve_vector all_leaves_diff;
Subcurve* first_parent = nullptr; Subcurve* first_parent = nullptr;
if ((c1->originating_subcurve1() != nullptr) || if ((c1->originating_subcurve1() != nullptr) ||
(c2->originating_subcurve2() != nullptr)) (c2->originating_subcurve2() != nullptr)) {
{
// get the subcurve leaves of c1 and of c2. Then extract from the smallest // get the subcurve leaves of c1 and of c2. Then extract from the smallest
// set the subcurves leaves that are not in the other one. If empty, it // set the subcurves leaves that are not in the other one. If empty, it
// means that a subcurves is completely contained in another one. // means that a subcurves is completely contained in another one.
@ -628,9 +592,7 @@ void Surface_sweep_2<Vis>::_intersect(Subcurve* c1, Subcurve* c2,
CGAL_SS_PRINT_CURVE(first_parent); CGAL_SS_PRINT_CURVE(first_parent);
CGAL_SS_PRINT_EOL(); CGAL_SS_PRINT_EOL();
X_monotone_curve_2 xc = first_parent->last_curve(); X_monotone_curve_2 xc = first_parent->last_curve();
for (auto sc_it = all_leaves_diff.begin(); for (auto sc_it = all_leaves_diff.begin(); sc_it != all_leaves_diff.end(); ++sc_it) {
sc_it != all_leaves_diff.end(); ++sc_it)
{
CGAL_SS_PRINT_TEXT("Inter with curve: "); CGAL_SS_PRINT_TEXT("Inter with curve: ");
CGAL_SS_PRINT_CURVE((*sc_it)); CGAL_SS_PRINT_CURVE((*sc_it));
CGAL_SS_PRINT_EOL(); CGAL_SS_PRINT_EOL();
@ -681,12 +643,10 @@ void Surface_sweep_2<Vis>::_intersect(Subcurve* c1, Subcurve* c2,
if ((ps_x1 == ps_x2) && (ps_y1 == ps_y2) && if ((ps_x1 == ps_x2) && (ps_y1 == ps_y2) &&
((ps_x1 != ARR_INTERIOR) || (ps_y1 != ARR_INTERIOR)) && ((ps_x1 != ARR_INTERIOR) || (ps_y1 != ARR_INTERIOR)) &&
this->m_traits->is_closed_2_object()(c1->last_curve(), ARR_MIN_END) && this->m_traits->is_closed_2_object()(c1->last_curve(), ARR_MIN_END) &&
this->m_traits->is_closed_2_object()(c2->last_curve(), ARR_MIN_END)) this->m_traits->is_closed_2_object()(c2->last_curve(), ARR_MIN_END)) {
{
if ((std::get_if<Intersection_point>(&(*vi)) != nullptr) && if ((std::get_if<Intersection_point>(&(*vi)) != nullptr) &&
this->m_traits->equal_2_object()(ctr_min(c1->last_curve()), this->m_traits->equal_2_object()(ctr_min(c1->last_curve()),
ctr_min(c2->last_curve()))) ctr_min(c2->last_curve()))) {
{
CGAL_SS_PRINT_TEXT("Skipping common left endpoint on boundary ..."); CGAL_SS_PRINT_TEXT("Skipping common left endpoint on boundary ...");
CGAL_SS_PRINT_EOL(); CGAL_SS_PRINT_EOL();
++vi; ++vi;
@ -719,12 +679,10 @@ void Surface_sweep_2<Vis>::_intersect(Subcurve* c1, Subcurve* c2,
if ((ps_x1 == ps_x2) && (ps_y1 == ps_y2) && if ((ps_x1 == ps_x2) && (ps_y1 == ps_y2) &&
((ps_x1 != ARR_INTERIOR) || (ps_y2 != ARR_INTERIOR)) && ((ps_x1 != ARR_INTERIOR) || (ps_y2 != ARR_INTERIOR)) &&
this->m_traits->is_closed_2_object()(c1->last_curve(), ARR_MAX_END) && this->m_traits->is_closed_2_object()(c1->last_curve(), ARR_MAX_END) &&
this->m_traits->is_closed_2_object()(c2->last_curve(), ARR_MAX_END)) this->m_traits->is_closed_2_object()(c2->last_curve(), ARR_MAX_END)) {
{
if (this->m_traits->equal_2_object() if (this->m_traits->equal_2_object()
(this->m_traits->construct_max_vertex_2_object()(c1->last_curve()), (this->m_traits->construct_max_vertex_2_object()(c1->last_curve()),
this->m_traits->construct_max_vertex_2_object()(c2->last_curve()))) this->m_traits->construct_max_vertex_2_object()(c2->last_curve()))) {
{
vector_inserter vi_last = vi_end; vector_inserter vi_last = vi_end;
--vi_last; --vi_last;
@ -791,8 +749,7 @@ template <typename Vis>
void Surface_sweep_2<Vis>::_create_intersection_point(const Point_2& xp, void Surface_sweep_2<Vis>::_create_intersection_point(const Point_2& xp,
Multiplicity multiplicity, Multiplicity multiplicity,
Subcurve*& c1, Subcurve*& c1,
Subcurve*& c2) Subcurve*& c2) {
{
CGAL_SS_PRINT_START_EOL("creating an intersection point between"); CGAL_SS_PRINT_START_EOL("creating an intersection point between");
CGAL_SS_PRINT_CURVE(c1); CGAL_SS_PRINT_CURVE(c1);
CGAL_SS_PRINT_EOL(); CGAL_SS_PRINT_EOL();
@ -814,7 +771,7 @@ void Surface_sweep_2<Vis>::_create_intersection_point(const Point_2& xp,
e->set_intersection(); e->set_intersection();
this->m_visitor->update_event(e, c1, c2, true); this->m_visitor->update_event(e, c1, c2, true, multiplicity);
e->push_back_curve_to_left(c1); e->push_back_curve_to_left(c1);
e->push_back_curve_to_left(c2); e->push_back_curve_to_left(c2);
@ -858,7 +815,7 @@ void Surface_sweep_2<Vis>::_create_intersection_point(const Point_2& xp,
_add_curve_to_right(e, c1); _add_curve_to_right(e, c1);
_add_curve_to_right(e, c2); _add_curve_to_right(e, c2);
e->set_intersection(); e->set_intersection();
this->m_visitor->update_event(e, c1, c2, false); this->m_visitor->update_event(e, c1, c2, false, multiplicity);
if (multiplicity == 0) { if (multiplicity == 0) {
if (e->is_right_curve_bigger(c1, c2, this->m_traits)) std::swap(c1, c2); if (e->is_right_curve_bigger(c1, c2, this->m_traits)) std::swap(c1, c2);
@ -895,8 +852,7 @@ _create_overlapping_curve(const X_monotone_curve_2& overlap_cv,
Subcurve*& c1 , Subcurve*& c2, Subcurve*& c1 , Subcurve*& c2,
const Subcurve_vector& all_leaves_diff, const Subcurve_vector& all_leaves_diff,
Subcurve* first_parent, Subcurve* first_parent,
Event* event_on_overlap) Event* event_on_overlap) {
{
// An overlap occurs: // An overlap occurs:
CGAL_SS_PRINT_START_EOL("creating an overlapping curve"); CGAL_SS_PRINT_START_EOL("creating an overlapping curve");
@ -935,14 +891,12 @@ _create_overlapping_curve(const X_monotone_curve_2& overlap_cv,
if ((ps_x_r != ARR_INTERIOR) || (ps_y_r != ARR_INTERIOR)) { if ((ps_x_r != ARR_INTERIOR) || (ps_y_r != ARR_INTERIOR)) {
// CGAL_assertion(c1->right_event() == c2->right_event()); // CGAL_assertion(c1->right_event() == c2->right_event());
// right_event = c1->right_event(); // right_event = c1->right_event();
right_event = this->_push_event(overlap_cv, ARR_MAX_END, Event::DEFAULT, right_event = this->_push_event(overlap_cv, ARR_MAX_END, Event::DEFAULT, ps_x_r, ps_y_r).first;
ps_x_r, ps_y_r).first;
} }
else { else {
auto max_vertex = this->m_traits->construct_max_vertex_2_object(); auto max_vertex = this->m_traits->construct_max_vertex_2_object();
auto right_end = max_vertex(overlap_cv); auto right_end = max_vertex(overlap_cv);
right_event = this->_push_event(right_end, Event::DEFAULT, ARR_INTERIOR, right_event = this->_push_event(right_end, Event::DEFAULT, ARR_INTERIOR, ARR_INTERIOR).first;
ARR_INTERIOR).first;
} }
if (!c1->is_start_point(left_event)) { if (!c1->is_start_point(left_event)) {
@ -968,12 +922,9 @@ _create_overlapping_curve(const X_monotone_curve_2& overlap_cv,
// Allocate the new Subcurve for the overlap // Allocate the new Subcurve for the overlap
Subcurve* overlap_sc=nullptr; Subcurve* overlap_sc=nullptr;
if (all_leaves_diff.empty()) if (all_leaves_diff.empty()) {
{
// first check that an equivalent curve is not already in left_event // first check that an equivalent curve is not already in left_event
for (Subcurve_iterator iter = left_event->right_curves_begin(); for (auto iter = left_event->right_curves_begin(); iter != left_event->right_curves_end(); ++iter) {
iter != left_event->right_curves_end(); ++iter)
{
if ((*iter)->has_same_leaves(c1, c2)) { if ((*iter)->has_same_leaves(c1, c2)) {
CGAL_SS_PRINT_TEXT("Reuse overlapping curve "); CGAL_SS_PRINT_TEXT("Reuse overlapping curve ");
CGAL_SS_PRINT_CURVE(*iter); CGAL_SS_PRINT_CURVE(*iter);
@ -983,8 +934,7 @@ _create_overlapping_curve(const X_monotone_curve_2& overlap_cv,
} }
} }
if (overlap_sc==nullptr) if (overlap_sc == nullptr) {
{
CGAL_SS_PRINT_TEXT("Allocate a new subcurve for the overlap (no common subcurves)"); CGAL_SS_PRINT_TEXT("Allocate a new subcurve for the overlap (no common subcurves)");
CGAL_SS_PRINT_EOL(); CGAL_SS_PRINT_EOL();
// no duplicate only one curve is needed // no duplicate only one curve is needed
@ -1005,10 +955,7 @@ _create_overlapping_curve(const X_monotone_curve_2& overlap_cv,
CGAL_SS_PRINT_EOL(); CGAL_SS_PRINT_EOL();
// create an overlapping curve per subcurve in second_parent that is not in first_parent // create an overlapping curve per subcurve in second_parent that is not in first_parent
for (typename std::vector<Subcurve*>::const_iterator sc_it = all_leaves_diff.begin(); for (auto sc_it = all_leaves_diff.begin(); sc_it != all_leaves_diff.end(); ++sc_it) {
sc_it != all_leaves_diff.end();
++sc_it)
{
overlap_sc = this->m_subCurveAlloc.allocate(1); overlap_sc = this->m_subCurveAlloc.allocate(1);
std::allocator_traits<Subcurve_alloc>::construct(this->m_subCurveAlloc,overlap_sc, this->m_masterSubcurve); std::allocator_traits<Subcurve_alloc>::construct(this->m_subCurveAlloc,overlap_sc, this->m_masterSubcurve);
overlap_sc->set_hint(this->m_statusLine.end()); overlap_sc->set_hint(this->m_statusLine.end());
@ -1063,8 +1010,7 @@ _create_overlapping_curve(const X_monotone_curve_2& overlap_cv,
// or updated. // or updated.
// //
template <typename Vis> template <typename Vis>
void Surface_sweep_2<Vis>::_add_curve(Event* e, Subcurve* sc, Attribute type) void Surface_sweep_2<Vis>::_add_curve(Event* e, Subcurve* sc, Attribute type) {
{
if (sc == nullptr) return; if (sc == nullptr) return;
if (type == Event::LEFT_END) { if (type == Event::LEFT_END) {