mirror of https://github.com/CGAL/cgal
Fixed a bug in the "sorting" of the left curves in an event.
Added ids to events and curves for debug purposes.
This commit is contained in:
parent
128082a6ee
commit
d237c67ee9
|
|
@ -59,6 +59,10 @@ public:
|
|||
typedef typename std::list<SubCurve *> SubcurveContainer;
|
||||
typedef typename SubcurveContainer::iterator SubCurveIter;
|
||||
|
||||
typedef Status_line_curve_less_functor<Traits> StatusLineCurveLess;
|
||||
typedef std::set<SubCurve*, StatusLineCurveLess> 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<class SweepLineTraits_2>
|
||||
void
|
||||
Sweep_line_event<SweepLineTraits_2>::
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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<class SweepLineTraits_2>
|
||||
|
|
@ -119,17 +126,17 @@ Sweep_line_subcurve(X_curve_2 &curve, Point_2 *reference,
|
|||
m_isRightSide = true;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
template<class SweepLineTraits_2>
|
||||
void
|
||||
Sweep_line_subcurve<SweepLineTraits_2>::
|
||||
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
|
||||
|
|
|
|||
|
|
@ -506,6 +506,10 @@ private:
|
|||
|
||||
Event *m_currentEvent;
|
||||
|
||||
#ifndef NDEBUG
|
||||
int m_eventId;
|
||||
int m_curveId;
|
||||
#endif
|
||||
};
|
||||
|
||||
template <class CurveInputIterator, class SweepLineTraits_2>
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue