From 01586969e8d8266f048e52a7e6ff5b382cf38e98 Mon Sep 17 00:00:00 2001
From: Thomas Fischer <thomas.fischer@ufz.de>
Date: Fri, 18 Jun 2021 08:07:40 +0200
Subject: [PATCH] [GL/Grid] Improve readability using Eigen::Vector3d.

---
 GeoLib/Grid.h | 26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)

diff --git a/GeoLib/Grid.h b/GeoLib/Grid.h
index 0d6900a6df8..3bbf90afbc8 100644
--- a/GeoLib/Grid.h
+++ b/GeoLib/Grid.h
@@ -254,29 +254,21 @@ Grid<POINT>::getPntVecsOfGridCellsIntersectingCube(P const& center,
                                                    double half_len) const
 {
     std::vector<std::vector<POINT*> const*> pnts;
-    POINT tmp_pnt{center[0] - half_len, center[1] - half_len,
-                  center[2] - half_len};  // min
-    std::array<std::size_t, 3> min_coords(getGridCoords(tmp_pnt));
+    Eigen::Vector3d const c{center[0], center[1], center[2]};
+    std::array<std::size_t, 3> min_coords(getGridCoords(c.array() - half_len));
+    std::array<std::size_t, 3> max_coords(getGridCoords(c.array() + half_len));
 
-    tmp_pnt[0] = center[0] + half_len;
-    tmp_pnt[1] = center[1] + half_len;
-    tmp_pnt[2] = center[2] + half_len;
-    std::array<std::size_t, 3> max_coords(getGridCoords(tmp_pnt));
-
-    std::size_t coords[3], steps0_x_steps1(_n_steps[0] * _n_steps[1]);
-    for (coords[0] = min_coords[0]; coords[0] < max_coords[0] + 1; coords[0]++)
+    std::size_t const steps0_x_steps1(_n_steps[0] * _n_steps[1]);
+    for (std::size_t c0 = min_coords[0]; c0 < max_coords[0] + 1; c0++)
     {
-        for (coords[1] = min_coords[1]; coords[1] < max_coords[1] + 1;
-             coords[1]++)
+        for (std::size_t c1 = min_coords[1]; c1 < max_coords[1] + 1; c1++)
         {
-            const std::size_t coords0_p_coords1_x_steps0(
-                coords[0] + coords[1] * _n_steps[0]);
-            for (coords[2] = min_coords[2]; coords[2] < max_coords[2] + 1;
-                 coords[2]++)
+            const std::size_t coords0_p_coords1_x_steps0(c0 + c1 * _n_steps[0]);
+            for (std::size_t c2 = min_coords[2]; c2 < max_coords[2] + 1; c2++)
             {
                 pnts.push_back(
                     &(_grid_cell_nodes_map[coords0_p_coords1_x_steps0 +
-                                           coords[2] * steps0_x_steps1]));
+                                           c2 * steps0_x_steps1]));
             }
         }
     }
-- 
GitLab