From: Christophe Bourcier Date: Wed, 21 Feb 2024 09:57:22 +0000 (+0100) Subject: WIP: avoid division by zero if 3 points are aligned X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fcbr%2Ffix_isElementContainsPointAlg3D_polyhedron;p=tools%2Fmedcoupling.git WIP: avoid division by zero if 3 points are aligned In case of polyhedron similar to a box with 2 coplanar faces (i.e. a box's face split by an edge on its middle) TODO: add a test --- diff --git a/src/INTERP_KERNEL/InterpolationUtils.hxx b/src/INTERP_KERNEL/InterpolationUtils.hxx index 901b27a23..ce8ae5055 100644 --- a/src/INTERP_KERNEL/InterpolationUtils.hxx +++ b/src/INTERP_KERNEL/InterpolationUtils.hxx @@ -1306,7 +1306,10 @@ namespace INTERP_KERNEL double XA_cross_XB[3] = {XA[1]*XB[2]-XA[2]*XB[1], XA[2]*XB[0]-XA[0]*XB[2], XA[0]*XB[1]-XA[1]*XB[0]}; // norm is equal to double the area of the triangle double norm = std::sqrt(XA_cross_XB[0]*XA_cross_XB[0]+XA_cross_XB[1]*XA_cross_XB[1]+XA_cross_XB[2]*XA_cross_XB[2]); - + // if 3 points A B X are aligned, norm is 0 + // return 0 to avoid division by 0 + if (norm::epsilon()) + return 0; return ( XA_cross_XB[0]*XC[0]+ XA_cross_XB[1]*XC[1] + XA_cross_XB[2]*XC[2] ) / norm; }