]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use min/max rather than if statements 11004/head
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Mon, 5 Oct 2020 10:47:00 +0000 (12:47 +0200)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Mon, 5 Oct 2020 10:47:00 +0000 (12:47 +0200)
include/deal.II/base/geometry_info.h

index 41de5c5338347235f596c4a40de02824d76d3a52..3d2f4796cf82ba8e1b18c7025a03a53c1b66193d 100644 (file)
@@ -4705,12 +4705,9 @@ template <int dim>
 inline Point<dim>
 GeometryInfo<dim>::project_to_unit_cell(const Point<dim> &q)
 {
-  Point<dim> p = q;
+  Point<dim> 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<dim>::distance_to_unit_cell(const Point<dim> &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;
 }

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.