From ce516fe8316ec1c64bfc330ba474fda88af533c6 Mon Sep 17 00:00:00 2001 From: Christoph Lehmann <christoph.lehmann@ufz.de> Date: Fri, 22 Apr 2022 11:53:41 +0200 Subject: [PATCH] [MeL] Fixed point in line test --- MeshLib/Elements/LineRule2.cpp | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/MeshLib/Elements/LineRule2.cpp b/MeshLib/Elements/LineRule2.cpp index 31e68e5bbd6..a9e1f24b4ef 100644 --- a/MeshLib/Elements/LineRule2.cpp +++ b/MeshLib/Elements/LineRule2.cpp @@ -27,11 +27,34 @@ double LineRule2::computeVolume(Node const* const* _nodes) bool LineRule2::isPntInElement(Node const* const* nodes, MathLib::Point3d const& pnt, double eps) { - double tmp; - double tmp_dst(0); - double const dist = MathLib::calcProjPntToLineAndDists( - pnt, *nodes[0], *nodes[1], tmp, tmp_dst); - return (dist < eps); + auto const& a = *nodes[0]; + auto const& b = *nodes[1]; + + if (MathLib::sqrDist(a, pnt) < eps * eps) + { + return true; + } + if (MathLib::sqrDist(b, pnt) < eps * eps) + { + return true; + } + + double lambda; + double distance_of_proj_pnt_to_a; + auto const distance_from_line = MathLib::calcProjPntToLineAndDists( + pnt, a, b, lambda, distance_of_proj_pnt_to_a); + + if (lambda >= 0 && lambda <= 1) + { + // pnt has been projected to the interior of the line + return distance_from_line < eps; + } + else + { + // pnt has been projected outside the line segment + // corner cases have already been treated in the beginning + return false; + } } unsigned LineRule2::identifyFace(Node const* const* _nodes, -- GitLab