From f683a94eb7df1b0e66adf515d99decae75c32bad Mon Sep 17 00:00:00 2001
From: Dmitri Naumov <github@naumov.de>
Date: Fri, 26 Jun 2020 00:18:53 +0200
Subject: [PATCH] [MeL] MeshInfo::getValueBounds takes a property.

Change argument to existing property vector. This avoids
double search.

Also change return type to std::optional.
---
 MeshLib/MeshInformation.h | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/MeshLib/MeshInformation.h b/MeshLib/MeshInformation.h
index b68968597c5..bba51e35f28 100644
--- a/MeshLib/MeshInformation.h
+++ b/MeshLib/MeshInformation.h
@@ -17,6 +17,7 @@
 #include <array>
 #include <limits>
 #include <map>
+#include <optional>
 #include <string>
 
 #include "GeoLib/AABB.h"
@@ -35,24 +36,18 @@ public:
     /// Returns the smallest and largest value of a scalar array with the given
     /// name.
     template <typename T>
-    static boost::optional<std::pair<T, T>> const getValueBounds(
-        MeshLib::Mesh const& mesh, std::string const& name)
+    static std::optional<std::pair<T, T>> const getValueBounds(
+        PropertyVector<T> const& property)
     {
-        if (!mesh.getProperties().existsPropertyVector<T>(name))
+        if (property.empty())
         {
-            return {};
-        }
-
-        auto const* const data_vec =
-            mesh.getProperties().getPropertyVector<T>(name);
-        if (data_vec->empty())
-        {
-            INFO("Mesh does not contain values for the property '{:s}'.", name);
+            INFO("Mesh property vector '{:s}' is empty.",
+                 property.getPropertyName());
             return {};
         }
 
         auto const [min, max] =
-            std::minmax_element(begin(*data_vec), end(*data_vec));
+            std::minmax_element(begin(property), end(property));
         return {{*min, *max}};
     }
 
-- 
GitLab