From: BRUNO LATHUILIERE Date: Wed, 21 Feb 2024 11:58:25 +0000 (+0100) Subject: avoid multiple division in calculatePolygonBarycenter : more accurate (if no overflo... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f5ff3298b29b1f772b2561b5af9021d01baf7bfc;p=tools%2Fmedcoupling.git avoid multiple division in calculatePolygonBarycenter : more accurate (if no overflow) and fastr --- diff --git a/src/INTERP_KERNEL/TransformedTriangle.cxx b/src/INTERP_KERNEL/TransformedTriangle.cxx index 65ada4f2c..4b1892045 100644 --- a/src/INTERP_KERNEL/TransformedTriangle.cxx +++ b/src/INTERP_KERNEL/TransformedTriangle.cxx @@ -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)); }