Skip to content

Commit

Permalink
Add Tolerance to Floating Point Comparisons in find_intersection()
Browse files Browse the repository at this point in the history
closes #3496
  • Loading branch information
miaoyinb committed May 2, 2023
1 parent 0fc5f5a commit 3767c48
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/mesh/mesh_triangle_holes.C
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ namespace
const Real denom = edgedx * raydy - edgedy * raydx;

// divide-by-zero means the segments are parallel
if (denom == 0)
if (std::abs(denom) <= libMesh::TOLERANCE * libMesh::TOLERANCE)
return -1;

const Real one_over_denom = 1 / denom;
Expand All @@ -136,12 +136,13 @@ namespace
const Real t = t_num * one_over_denom;

// There's an intersection between the ray line and the edge?
if (t >= 0 && t < 1)
if (t >= -libMesh::TOLERANCE * libMesh::TOLERANCE &&
t - 1.0 < libMesh::TOLERANCE * libMesh::TOLERANCE)
{
// There's an intersection right on a vertex? We'll count it
// if and only if it isn't a "double-intersection", if the
// *next* edge in line is on the other side of our ray.
if (!t)
if (std::abs(t) <= libMesh::TOLERANCE * libMesh::TOLERANCE)
{
const Real prevdx = edge_pt0(0)-ray_target(0),
prevdy = edge_pt0(1)-ray_target(1);
Expand Down

0 comments on commit 3767c48

Please sign in to comment.