Using the attached data set, it goes into an infinite loop because, in DTSweep.edgeEvent, ep, p1, and eq are collinear, BUT p1 is NOT between ep and eq.
So I have made the following changes. If these changes produce some unexpected side effect or if the data is somehow bad, I'd like to know so I can make appropriate adjustments.
I added this method to TriangulationPoint
<code>
/**
* returns true if this point is in bounds a->b, inclusive of ends<br/>
* reduced number of method calls and (hidden) comparisons at expense of
* additional storage (two doubles) and possibly some code clarity.<br/>
* if (getX() < Math.min(a.getX(), b.getX())) { return false; }<br/>
* might be easier to understand.
* @param a
* @param b
* @return
*/
public boolean inBounds(TriangulationPoint a, TriangulationPoint b)
{
// check if x in bounds
double min = a.getX(),
max = b.getX(),
value = getX();
if (min > max)
{
double temp = min;
min = max;
max = temp;
}
if (value < min)
{
return false;
}
else if (value > max)
{
return false;
}
// end check if x in bounds
// check if y in bounds
min = a.getY();
max = b.getY();
value = getY();
if (min > max)
{
double temp = min;
min = max;
max = temp;
}
if (value < min)
{
return false;
}
else if (value > max)
{
return false;
}
// end check if y in bounds
return true;
}
</code>
Then I added the following to DTSweep.edgeEvent
<code>
if( o1 == Orientation.Collinear )
{
// start added code here
if (! p1.inBounds(eq, ep))
{
return; // not really collinear
}
// end added code
</code>
and
<code> if( o2 == Orientation.Collinear )
{
// start added code here
if (! p2.inBounds(eq, ep))
{
return; // not really collinear
}
// end added code
</code>