Salome HOME
[TetraIntersect] Avoid multiple divisions in calculatePolygonBarycenter
[tools/medcoupling.git] / 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));
     }