diff --git a/Packages/Sweep_line_2/include/CGAL/Sweep_line_2/Sweep_line_event.h b/Packages/Sweep_line_2/include/CGAL/Sweep_line_2/Sweep_line_event.h index 3e96cf100aa..a4ab3ea28ad 100644 --- a/Packages/Sweep_line_2/include/CGAL/Sweep_line_2/Sweep_line_event.h +++ b/Packages/Sweep_line_2/include/CGAL/Sweep_line_2/Sweep_line_event.h @@ -59,6 +59,10 @@ public: typedef typename std::list SubcurveContainer; typedef typename SubcurveContainer::iterator SubCurveIter; + typedef Status_line_curve_less_functor StatusLineCurveLess; + typedef std::set StatusLine; + typedef typename StatusLine::iterator StatusLineIter; + Sweep_line_event(const Point_2 &point, Traits *traits) { m_leftCurves = new SubcurveContainer(); m_rightCurves = new SubcurveContainer(); @@ -72,6 +76,9 @@ public: delete m_rightCurves; } + /** if the curve is already in, we will take it out and reinsert it, + since its relative position to the other curves may have changed. + */ void addCurveToLeft(SubCurve *curve) { if (m_leftCurves->empty()) @@ -79,6 +86,14 @@ public: else { SubCurveIter iter = m_leftCurves->begin(); + while ( iter != m_leftCurves->end() ) { + if ( m_traits->curve_is_same((*iter)->getCurve(), curve->getCurve())) { + m_leftCurves->erase(iter); + break; + } + ++iter; + } + iter = m_leftCurves->begin(); while ( iter != m_leftCurves->end() && m_traits->curve_compare_at_x_right(curve->getCurve(), (*iter)->getCurve(), @@ -87,9 +102,12 @@ public: { ++iter; } + if ( iter == m_leftCurves->end() || !m_traits->curve_is_same((*iter)->getCurve(), curve->getCurve())) + { m_leftCurves->insert(iter, curve); + } } } @@ -144,7 +162,9 @@ public: return m_point; } +#ifndef NDEBUG void Print(); +#endif private: @@ -157,33 +177,45 @@ private: bool m_isEndPoint; Point_2 m_point; + +#ifndef NDEBUG +public: + int id; +#endif }; - +#ifndef NDEBUG template void Sweep_line_event:: Print() { + std::cout << "\tEvent id: " << id << "\n" ; std::cout << "\tLeft curves: \n" ; for ( SubCurveIter iter = m_leftCurves->begin() ; iter != m_leftCurves->end() ; ++iter ) { - const X_curve_2 &c = (*iter)->getCurve(); - std::cout << "\t(" << c << ") \n"; + //const X_curve_2 &c = (*iter)->getCurve(); + //std::cout << "\t(" << c << ") \n"; + std::cout << "\t"; + (*iter)->Print(); + std::cout << "\n"; } std::cout << std::endl; std::cout << "\tRight curves: \n" ; for ( SubCurveIter iter = m_rightCurves->begin() ; iter != m_rightCurves->end() ; ++iter ) { - const X_curve_2 &c = (*iter)->getCurve(); - std::cout << "\t(" << c << ") \n"; + //const X_curve_2 &c = (*iter)->getCurve(); + //std::cout << "\t(" << c << ") \n"; + std::cout << "\t"; + (*iter)->Print(); + std::cout << "\n"; } std::cout << std::endl; } - +#endif diff --git a/Packages/Sweep_line_2/include/CGAL/Sweep_line_2/Sweep_line_subcurve.h b/Packages/Sweep_line_2/include/CGAL/Sweep_line_2/Sweep_line_subcurve.h index 29a7bc7840e..6cde219fd3b 100644 --- a/Packages/Sweep_line_2/include/CGAL/Sweep_line_2/Sweep_line_subcurve.h +++ b/Packages/Sweep_line_2/include/CGAL/Sweep_line_2/Sweep_line_subcurve.h @@ -85,8 +85,10 @@ public: return false; } +#ifndef NDEBUG void Print() const; - +#endif + private: Traits *m_traits; @@ -97,6 +99,11 @@ private: bool m_isRightSide; Point_2 m_source; Point_2 m_target; + +public: +#ifndef NDEBUG + int id; +#endif }; template @@ -119,17 +126,17 @@ Sweep_line_subcurve(X_curve_2 &curve, Point_2 *reference, m_isRightSide = true; } } - +#ifndef NDEBUG template void Sweep_line_subcurve:: Print() const { - std::cout << "Curve (" << m_curve << ") " - << "p = (" << m_lastPoint << ")" << std::endl; + std::cout << "Curve " << id << " (" << m_curve << ") " + << "last P = (" << m_lastPoint << ")" << std::endl; } - +#endif CGAL_END_NAMESPACE #endif // CGAL_SWEEP_LINE_SUBCURVE_H diff --git a/Packages/Sweep_line_2/include/CGAL/Sweep_line_base_2.h b/Packages/Sweep_line_2/include/CGAL/Sweep_line_base_2.h index b727bd3ed3c..aa587f541b4 100644 --- a/Packages/Sweep_line_2/include/CGAL/Sweep_line_base_2.h +++ b/Packages/Sweep_line_2/include/CGAL/Sweep_line_base_2.h @@ -506,6 +506,10 @@ private: Event *m_currentEvent; +#ifndef NDEBUG + int m_eventId; + int m_curveId; +#endif }; template @@ -546,11 +550,14 @@ Init(CurveInputIterator begin, CurveInputIterator end) StatusLineCurveLess slcurveless(m_traits); m_statusLine = new StatusLine(slcurveless); + SL_DEBUG(m_eventId = 0;) + SL_DEBUG(m_curveId = 0 ;) + int count = 0; CurveInputIterator iter; for ( iter = begin ; iter != end ; ++iter) { - if ( m_traits->is_x_monotone(*iter) ) + if ( m_traits->is_x_monotone(*iter) ) InitCurve(*iter); else { @@ -569,6 +576,7 @@ Init(CurveInputIterator begin, CurveInputIterator end) count++; } } + SL_DEBUG(m_curveId++;) } } @@ -586,6 +594,7 @@ InitCurve(X_curve_2 &curve) Event *e = 0; SubCurve *subCv = new SubCurve(curve, &m_currentPos, m_traits); + SL_DEBUG(subCv->id = m_curveId;) m_subCurves.push_back(subCv); // handle the source point @@ -594,7 +603,8 @@ InitCurve(X_curve_2 &curve) SL_DEBUG(std::cout << "event " << source << " already exists\n";) e = eventIter->second; } else { - e = new Event(source, m_traits); + e = new Event(source, m_traits); + SL_DEBUG(e->id = m_eventId++;) m_events.push_back(e); m_queue->insert(EventQueueValueType(source, e)); } @@ -607,7 +617,8 @@ InitCurve(X_curve_2 &curve) SL_DEBUG(std::cout << "event " << target << " already exists\n";) e = eventIter->second; } else { - e = new Event(target, m_traits); + e = new Event(target, m_traits); + SL_DEBUG(e->id = m_eventId++;) m_events.push_back(e); m_queue->insert(EventQueueValueType(target, e)); } @@ -717,7 +728,6 @@ FirstPass() SL_DEBUG(std::cout << "First pass - done\n" ;) } - /*! Loop over the curves to the right of the sweep line and handle them: - if we are at the beginning of the curve, we insert it to the sweep line, then we look if it intersects any of its neighbours. @@ -830,9 +840,9 @@ Intersect(SubCurve *c1, SubCurve *c2) { SL_DEBUG(std::cout << "Looking for intersection between:\n\t";) SL_DEBUG(c1->Print();) - SL_DEBUG(std::cout << "\n\t";) + SL_DEBUG(std::cout << "\t";) SL_DEBUG(c2->Print();) - SL_DEBUG(std::cout << "\n\n";) + SL_DEBUG(std::cout << "\n";) SubCurve *scv1 = c1; SubCurve *scv2 = c2; @@ -845,10 +855,13 @@ Intersect(SubCurve *c1, SubCurve *c2) p, p)) { SL_DEBUG( - std::cout << " a new event is created between:\n\t(" - << cv1 << ") and \n\t(" << cv2 << ")\n\trelative to (" - << m_sweepLinePos << ")\n\t at (" - << p << ")" << std::endl; + std::cout << " a new event is created between:\n\t"; + scv1->Print(); + std::cout << "\t"; + scv2->Print(); + std::cout << "\trelative to (" + << m_sweepLinePos << ")\n\t at (" + << p << ")" << std::endl; ) // check to see if an event at this point already exists... @@ -856,7 +869,8 @@ Intersect(SubCurve *c1, SubCurve *c2) Event *e = 0; if ( eqi == m_queue->end() ) { - e = new Event(p, m_traits); + e = new Event(p, m_traits); + SL_DEBUG(e->id = m_eventId++;) m_events.push_back(e); m_currentPos = m_sweepLinePos; @@ -869,7 +883,7 @@ Intersect(SubCurve *c1, SubCurve *c2) PRINT_NEW_EVENT(p, e); m_queue->insert(EventQueueValueType(p, e)); - + return e; } else { SL_DEBUG(std::cout << "event already exists, updating.. (" << p << ")\n";) @@ -892,6 +906,7 @@ Intersect(SubCurve *c1, SubCurve *c2) return e; } SL_DEBUG(std::cout << "not found 2\n";) + return 0; } @@ -944,7 +959,8 @@ Intersect(SubCurve *c1, SubCurve *c2, SubCurve *c3) Event *e = 0; if ( eqi == m_queue->end() ) { - e = new Event(p, m_traits); + e = new Event(p, m_traits); + SL_DEBUG(e->id = m_eventId++;) m_events.push_back(e); m_currentPos = m_sweepLinePos;