Modified method Line::intersection_infinite() to return that the intersection was not found if the input lines are near parallel, and an integer overflow would occur when saving the intersection coordinates.
This commit is contained in:
parent
324e889d5e
commit
b97c05176a
@ -29,7 +29,14 @@ bool Line::intersection_infinite(const Line &other, Point* point) const
|
||||
if (std::fabs(denom) < EPSILON)
|
||||
return false;
|
||||
double t1 = cross2(v12, v2) / denom;
|
||||
*point = (a1 + t1 * v1).cast<coord_t>();
|
||||
Vec2d result = (a1 + t1 * v1);
|
||||
if (result.x() > std::numeric_limits<coord_t>::max() || result.x() < std::numeric_limits<coord_t>::lowest() ||
|
||||
result.y() > std::numeric_limits<coord_t>::max() || result.y() < std::numeric_limits<coord_t>::lowest()) {
|
||||
// Intersection has at least one of the coordinates much bigger (or smaller) than coord_t maximum value (or minimum).
|
||||
// So it can not be stored into the Point without integer overflows. That could mean that input lines are parallel or near parallel.
|
||||
return false;
|
||||
}
|
||||
*point = (result).cast<coord_t>();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user