Skip to content

Commit 30c1237

Browse files
committed
Add Tolerance to Floating Point Comparisons in find_intersection()
closes libMesh#3496
1 parent 7523403 commit 30c1237

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/mesh/mesh_triangle_holes.C

+4-3
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ namespace
123123
const Real denom = edgedx * raydy - edgedy * raydx;
124124

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

129129
const Real one_over_denom = 1 / denom;
@@ -136,12 +136,13 @@ namespace
136136
const Real t = t_num * one_over_denom;
137137

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

0 commit comments

Comments
 (0)