Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion kratos/geometries/line_3d_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,12 @@ class Line3D2 : public Geometry<TPointType>
PointLocalCoordinates( rResult, rPoint );

if ( std::abs( rResult[0] ) <= (1.0 + Tolerance) ) {
// Check if point is too far away from the line, if so, return false
const double distance = this->CalculateDistance(rPoint, Tolerance);
const double length = Length();
if (distance > std::max(Tolerance, 1e-6 * length)) {
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tolerance in IsInside is used as a local-space boundary tolerance (dimensionless), but here it is also compared directly against a global-space distance. This mixes units and can make the “allowed” perpendicular distance unexpectedly large/small depending on the caller-provided Tolerance. Consider using a distance tolerance expressed in length units (e.g., scale Tolerance by Length() or follow the existing Line2D2 approach using a relative 1e-6*Length() threshold) and avoid using the raw Tolerance value as a distance.

Suggested change
if (distance > std::max(Tolerance, 1e-6 * length)) {
const double distance_tolerance = std::max(Tolerance * length, 1e-6 * length);
if (distance > distance_tolerance) {

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For better copilot , related: #14334 @roigcarlo ?

return false;
}
return true;
}

Expand Down Expand Up @@ -880,7 +886,6 @@ class Line3D2 : public Geometry<TPointType>

// Project point
const double tolerance = 1e-14; // Tolerance

const double length = Length();

const double length_1 = std::sqrt( std::pow(rPoint[0] - r_first_point[0], 2)
Expand Down
15 changes: 15 additions & 0 deletions kratos/tests/cpp_tests/geometries/test_line_3d_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ namespace Testing {
);
}

/** Generates a point type sample Line3D2N
* @return Pointer to a Line3D2N
*/
Line3D2<Point>::Pointer GenerateCornerCasePointsLine3D2() {
return Kratos::make_shared<Line3D2<Point>>(
Kratos::make_shared<Point>(-20.0, 0.0, 0.0),
Kratos::make_shared<Point>(-20.0, 5.0, 0.0)
);
}

/** Generates a point type sample Line3D2N.
* @return Pointer to a Line3D2N
*/
Expand Down Expand Up @@ -121,6 +131,11 @@ namespace Testing {
KRATOS_EXPECT_FALSE(p_geom->IsInside(PointOutside, LocalCoords, EPSILON));
KRATOS_EXPECT_TRUE(p_geom->IsInside(PointInVertex, LocalCoords, EPSILON));
KRATOS_EXPECT_TRUE(p_geom->IsInside(PointInEdge, LocalCoords, EPSILON));

// testing Corner Case
Geometry<Point>::Pointer p_geom2 = GenerateCornerCasePointsLine3D2();
Point PointOutside2(-16.0, 2.5, 0.0);
KRATOS_EXPECT_FALSE(p_geom2->IsInside(PointOutside2, LocalCoords, EPSILON));
}

/** Checks the point local coordinates for a given point respect to the
Expand Down
Loading