From: Martin Kronbichler Date: Mon, 5 Oct 2020 10:47:00 +0000 (+0200) Subject: Use min/max rather than if statements X-Git-Tag: v9.3.0-rc1~1037^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb48ceb6408a65892c24aa0cd03db483a7e23f8b;p=dealii.git Use min/max rather than if statements --- diff --git a/include/deal.II/base/geometry_info.h b/include/deal.II/base/geometry_info.h index 41de5c5338..3d2f4796cf 100644 --- a/include/deal.II/base/geometry_info.h +++ b/include/deal.II/base/geometry_info.h @@ -4705,12 +4705,9 @@ template inline Point GeometryInfo::project_to_unit_cell(const Point &q) { - Point p = q; + Point p; for (unsigned int i = 0; i < dim; i++) - if (p[i] < 0.) - p[i] = 0.; - else if (p[i] > 1.) - p[i] = 1.; + p[i] = std::min(std::max(q[i], 0.), 1.); return p; } @@ -4724,10 +4721,10 @@ GeometryInfo::distance_to_unit_cell(const Point &p) double result = 0.0; for (unsigned int i = 0; i < dim; i++) - if ((-p[i]) > result) - result = -p[i]; - else if ((p[i] - 1.) > result) - result = (p[i] - 1.); + { + result = std::max(result, -p[i]); + result = std::max(result, p[i] - 1.); + } return result; }