]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Bug fix: IsPolygonWellOriented() was not working properly QPLOYG
authorabn <adrien.bruneton@cea.fr>
Mon, 29 Oct 2018 13:58:16 +0000 (14:58 +0100)
committerabn <adrien.bruneton@cea.fr>
Mon, 29 Oct 2018 14:10:14 +0000 (15:10 +0100)
If the linearized version was self-intersecting, algo was faulty.

src/MEDCoupling/MEDCouplingUMesh.cxx

index 21cbde8cdbfb6e243174b5c2a7f8f679b584f1e3..fb1c2f9349135912e529cc4efae99a6b277494ca 100644 (file)
@@ -8417,21 +8417,18 @@ bool MEDCouplingUMesh::IsPolygonWellOriented(bool isQuadratic, const double *vec
   std::size_t i, ip1;
   double v[3]={0.,0.,0.};
   std::size_t sz=std::distance(begin,end);
-  if(isQuadratic)
-    sz/=2;
-  for(i=0;i<sz;i++)
-    {
-      v[0]+=coords[3*begin[i]+1]*coords[3*begin[(i+1)%sz]+2]-coords[3*begin[i]+2]*coords[3*begin[(i+1)%sz]+1];
-      v[1]+=coords[3*begin[i]+2]*coords[3*begin[(i+1)%sz]]-coords[3*begin[i]]*coords[3*begin[(i+1)%sz]+2];
-      v[2]+=coords[3*begin[i]]*coords[3*begin[(i+1)%sz]+1]-coords[3*begin[i]+1]*coords[3*begin[(i+1)%sz]];
-    }
-  double ret = vec[0]*v[0]+vec[1]*v[1]+vec[2]*v[2];
-
-  // Try using quadratic points if standard points are degenerated (for example a QPOLYG with two
-  // SEG3 forming a circle):
-  if (fabs(ret) < INTERP_KERNEL::DEFAULT_ABS_TOL && isQuadratic)
+  if(!isQuadratic)
+    for(i=0;i<sz;i++)
+      {
+        v[0]+=coords[3*begin[i]+1]*coords[3*begin[(i+1)%sz]+2]-coords[3*begin[i]+2]*coords[3*begin[(i+1)%sz]+1];
+        v[1]+=coords[3*begin[i]+2]*coords[3*begin[(i+1)%sz]]-coords[3*begin[i]]*coords[3*begin[(i+1)%sz]+2];
+        v[2]+=coords[3*begin[i]]*coords[3*begin[(i+1)%sz]+1]-coords[3*begin[i]+1]*coords[3*begin[(i+1)%sz]];
+      }
+  else
     {
-      v[0] = 0.0; v[1] = 0.0; v[2] = 0.0;
+      // Use all points if quadratic (taking only linear points might lead to issues if the linearized version of the
+      // polygon is not convex or self-intersecting ... see testCellOrientation4)
+      sz /= 2;
       for(std::size_t j=0;j<sz;j++)
         {
           if (j%2)  // current point i is quadratic, next point i+1 is standard
@@ -8448,8 +8445,8 @@ bool MEDCouplingUMesh::IsPolygonWellOriented(bool isQuadratic, const double *vec
           v[1]+=coords[3*begin[i]+2]*coords[3*begin[ip1]]-coords[3*begin[i]]*coords[3*begin[ip1]+2];
           v[2]+=coords[3*begin[i]]*coords[3*begin[ip1]+1]-coords[3*begin[i]+1]*coords[3*begin[ip1]];
         }
-      ret = vec[0]*v[0]+vec[1]*v[1]+vec[2]*v[2];
     }
+  double ret = vec[0]*v[0]+vec[1]*v[1]+vec[2]*v[2];
   return (ret>0.);
 }