Skip to content
Snippets Groups Projects
Commit 5078140c authored by Tom Fischer's avatar Tom Fischer
Browse files

[GeoLib] Handle special case in lineSegmentIntersect().

parent 8c418afb
No related branches found
No related tags found
No related merge requests found
......@@ -103,6 +103,19 @@ bool lineSegmentIntersect(
if (!isCoplanar(a, b, c, d))
return false;
// handle special cases here to avoid computing intersection numerical
if (MathLib::sqrDist(a, c) < std::numeric_limits<double>::epsilon() ||
MathLib::sqrDist(a, d) < std::numeric_limits<double>::epsilon()) {
s = a;
return true;
}
if (MathLib::sqrDist(b, c) < std::numeric_limits<double>::epsilon() ||
MathLib::sqrDist(b, d) < std::numeric_limits<double>::epsilon()) {
s = b;
return true;
}
// general case
MathLib::Vector3 const v(a, b);
MathLib::Vector3 const w(c, d);
MathLib::Vector3 const qp(a, c);
......
......@@ -120,18 +120,6 @@ std::vector<GeoLib::Point> Polygon::getAllIntersectionPoints(
const std::size_t n_segments(getNumberOfPoints() - 1);
GeoLib::Point s;
for (std::size_t k(0); k < n_segments; k++) {
// handle special cases here to avoid computing intersection numerical
if (MathLib::sqrDist(*(getPoint(k)), a) < std::numeric_limits<double>::epsilon() ||
MathLib::sqrDist(*(getPoint(k)), b) < std::numeric_limits<double>::epsilon()) {
intersections.emplace_back(*(getPoint(k)));
continue;
}
if (MathLib::sqrDist(*(getPoint(k+1)), a) < std::numeric_limits<double>::epsilon() ||
MathLib::sqrDist(*(getPoint(k+1)), b) < std::numeric_limits<double>::epsilon()) {
intersections.emplace_back(*(getPoint(k+1)));
continue;
}
// general case
if (GeoLib::lineSegmentIntersect(*(getPoint(k)), *(getPoint(k+1)), a, b, s)) {
intersections.push_back(s);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment