]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
avoid multiple division in calculatePolygonBarycenter : more accurate (if no overflo...
authorBRUNO LATHUILIERE <bruno.lathuiliere@edf.fr>
Wed, 21 Feb 2024 11:58:25 +0000 (12:58 +0100)
committerBRUNO LATHUILIERE <bruno.lathuiliere@edf.fr>
Wed, 21 Feb 2024 11:58:25 +0000 (12:58 +0100)
src/INTERP_KERNEL/TransformedTriangle.cxx

index 65ada4f2c6ca27d4fe006c5a776e78dbeab39343..4b18920459bb3980300a9a93a6c33766f9e68211 100644 (file)
@@ -646,20 +646,19 @@ namespace INTERP_KERNEL
       const std::size_t m = polygon.size();
 
       for(int j = 0 ; j < 3 ; ++j)
-        {
-          barycenter[j] = 0.0;
-        }
+       barycenter[j] = 0.0;
+
+      for(std::size_t i = 0 ; i < m ; ++i)
+       {
+         const double* pt = polygon[i];
+         for(int j = 0 ; j < 3 ; ++j)
+           barycenter[j] += pt[j];
+       }
 
       if(m != 0)
         {
-          for(std::size_t i = 0 ; i < m ; ++i)
-            {
-              const double* pt = polygon[i];
-              for(int j = 0 ; j < 3 ; ++j)
-                {
-                  barycenter[j] += pt[j] / double(m);
-                }
-            }
+         for(int j = 0 ; j < 3 ; ++j)
+           barycenter[j] = barycenter[j] / double(m);
         }
       LOG(3,"Barycenter is " << vToStr(barycenter));
     }