From 15c2b19f59c15df9b966c27bfcccdd56127c5b70 Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Wed, 9 May 2018 11:34:04 +0200 Subject: [PATCH] Slightly improve naming of epsilon/tolerance variable in plane triangle intersection. --- .../cafHexGridIntersectionTools.cpp | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Fwk/AppFwk/cafVizExtensions/cafHexGridIntersectionTools/cafHexGridIntersectionTools.cpp b/Fwk/AppFwk/cafVizExtensions/cafHexGridIntersectionTools/cafHexGridIntersectionTools.cpp index 6eaa0a4cb8..a7934f5935 100644 --- a/Fwk/AppFwk/cafVizExtensions/cafHexGridIntersectionTools/cafHexGridIntersectionTools.cpp +++ b/Fwk/AppFwk/cafVizExtensions/cafHexGridIntersectionTools/cafHexGridIntersectionTools.cpp @@ -114,7 +114,7 @@ bool HexGridIntersectionTools::planeTriangleIntersection(const cvf::Plane& plane ClipVx* newVx1, ClipVx* newVx2, bool * isMostVxesOnPositiveSide) { - const double epsilon = 1.0e-8; + const double nonDimensionalTolerance = 1.0e-8; double sqrSignedDistances[3]; sqrSignedDistances[0] = plane.distanceSquared(p1); @@ -125,6 +125,8 @@ bool HexGridIntersectionTools::planeTriangleIntersection(const cvf::Plane& plane std::max(std::abs(sqrSignedDistances[1]), std::abs(sqrSignedDistances[2]))); + const double sqrDistanceTolerance = nonDimensionalTolerance * maxSqrAbsDistance; + int onPosSide[3]; onPosSide[0] = sqrSignedDistances[0] >= 0; onPosSide[1] = sqrSignedDistances[1] >= 0; @@ -157,7 +159,7 @@ bool HexGridIntersectionTools::planeTriangleIntersection(const cvf::Plane& plane if (onPosSide[2]) topVx = 3; // Case 3a: Two negative distances and the last is within tolerance of zero. - if (sqrSignedDistances[topVx - 1] < epsilon * maxSqrAbsDistance) + if (sqrSignedDistances[topVx - 1] < sqrDistanceTolerance) { return false; } @@ -169,7 +171,7 @@ bool HexGridIntersectionTools::planeTriangleIntersection(const cvf::Plane& plane if (!onPosSide[2]) topVx = 3; // Case 3a: Two positive distances and the last is within tolerance of zero. - if (sqrSignedDistances[topVx - 1] > -epsilon * maxSqrAbsDistance) + if (sqrSignedDistances[topVx - 1] > -sqrDistanceTolerance) { return false; } @@ -184,28 +186,28 @@ bool HexGridIntersectionTools::planeTriangleIntersection(const cvf::Plane& plane if (topVx == 1) { - ok1 = planeLineIntersect(plane, p1, p2, &((*newVx1).vx), &((*newVx1).normDistFromEdgeVx1), epsilon); + ok1 = planeLineIntersect(plane, p1, p2, &((*newVx1).vx), &((*newVx1).normDistFromEdgeVx1), nonDimensionalTolerance); (*newVx1).clippedEdgeVx1Id = p1Id; (*newVx1).clippedEdgeVx2Id = p2Id; - ok2 = planeLineIntersect(plane, p1, p3, &((*newVx2).vx), &((*newVx2).normDistFromEdgeVx1), epsilon); + ok2 = planeLineIntersect(plane, p1, p3, &((*newVx2).vx), &((*newVx2).normDistFromEdgeVx1), nonDimensionalTolerance); (*newVx2).clippedEdgeVx1Id = p1Id; (*newVx2).clippedEdgeVx2Id = p3Id; } else if (topVx == 2) { - ok1 = planeLineIntersect(plane, p2, p3, &((*newVx1).vx), &((*newVx1).normDistFromEdgeVx1), epsilon); + ok1 = planeLineIntersect(plane, p2, p3, &((*newVx1).vx), &((*newVx1).normDistFromEdgeVx1), nonDimensionalTolerance); (*newVx1).clippedEdgeVx1Id = p2Id; (*newVx1).clippedEdgeVx2Id = p3Id; - ok2 = planeLineIntersect(plane, p2, p1, &((*newVx2).vx), &((*newVx2).normDistFromEdgeVx1), epsilon); + ok2 = planeLineIntersect(plane, p2, p1, &((*newVx2).vx), &((*newVx2).normDistFromEdgeVx1), nonDimensionalTolerance); (*newVx2).clippedEdgeVx1Id = p2Id; (*newVx2).clippedEdgeVx2Id = p1Id; } else if (topVx == 3) { - ok1 = planeLineIntersect(plane, p3, p1, &((*newVx1).vx), &((*newVx1).normDistFromEdgeVx1), epsilon); + ok1 = planeLineIntersect(plane, p3, p1, &((*newVx1).vx), &((*newVx1).normDistFromEdgeVx1), nonDimensionalTolerance); (*newVx1).clippedEdgeVx1Id = p3Id; (*newVx1).clippedEdgeVx2Id = p1Id; - ok2 = planeLineIntersect(plane, p3, p2, &((*newVx2).vx), &((*newVx2).normDistFromEdgeVx1), epsilon); + ok2 = planeLineIntersect(plane, p3, p2, &((*newVx2).vx), &((*newVx2).normDistFromEdgeVx1), nonDimensionalTolerance); (*newVx2).clippedEdgeVx1Id = p3Id; (*newVx2).clippedEdgeVx2Id = p2Id; }