From c19ce07d8d954372c6c96f5b477c131f88a80a97 Mon Sep 17 00:00:00 2001
From: Thomas Fischer <thomas.fischer@ufz.de>
Date: Fri, 29 May 2020 14:58:29 +0200
Subject: [PATCH] [MathLib] Add explicit to TemplateVector3.

This needs some changes in other files, too.
---
 GeoLib/AnalyticalGeometry-impl.h                     |  7 ++++---
 GeoLib/MinimalBoundingSphere.cpp                     | 12 ++++++------
 MathLib/Vector3.h                                    |  2 +-
 MeshGeoToolsLib/GeoMapper.cpp                        |  2 +-
 MeshLib/MeshEditing/ProjectPointOnMesh.cpp           |  3 ++-
 .../NormalTractionBoundaryConditionLocalAssembler.h  |  3 ++-
 ProcessLib/LIE/Common/Utils.cpp                      |  3 ++-
 7 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/GeoLib/AnalyticalGeometry-impl.h b/GeoLib/AnalyticalGeometry-impl.h
index a1f3dc7cae2..6ad53498b19 100644
--- a/GeoLib/AnalyticalGeometry-impl.h
+++ b/GeoLib/AnalyticalGeometry-impl.h
@@ -27,7 +27,7 @@ void getNewellPlane (InputIterator pnts_begin, InputIterator pnts_end,
         plane_normal[2] += (pt_i[0] - pt_j[0])
                            * (pt_i[1] + pt_j[1]); // projection on xy
 
-        centroid += pt_j;
+        centroid += MathLib::Vector3(pt_j);
     }
 
     plane_normal.normalize();
@@ -48,7 +48,8 @@ void getNewellPlane (const std::vector<T_POINT*>& pnts,
 }
 
 template <class T_POINT>
-std::pair<MathLib::Vector3, double> getNewellPlane (const std::vector<T_POINT>& pnts)
+std::pair<MathLib::Vector3, double> getNewellPlane(
+    const std::vector<T_POINT>& pnts)
 {
     MathLib::Vector3 plane_normal;
     MathLib::Vector3 centroid;
@@ -61,7 +62,7 @@ std::pair<MathLib::Vector3, double> getNewellPlane (const std::vector<T_POINT>&
         plane_normal[2] += (pnts[i][0] - pnts[j][0])
                            * (pnts[i][1] + pnts[j][1]); // projection on xy
 
-        centroid += pnts[j];
+        centroid += MathLib::Vector3(pnts[j]);
     }
 
     plane_normal.normalize();
diff --git a/GeoLib/MinimalBoundingSphere.cpp b/GeoLib/MinimalBoundingSphere.cpp
index 0fd40c5b188..b29448a77d2 100644
--- a/GeoLib/MinimalBoundingSphere.cpp
+++ b/GeoLib/MinimalBoundingSphere.cpp
@@ -72,7 +72,7 @@ MinimalBoundingSphere::MinimalBoundingSphere(MathLib::Point3d const& p,
             two_pnts_sphere = MinimalBoundingSphere(p, q);
         }
         _radius = two_pnts_sphere.getRadius();
-        _center = two_pnts_sphere.getCenter();
+        _center = MathLib::Vector3(two_pnts_sphere.getCenter());
     }
 }
 
@@ -103,21 +103,21 @@ MinimalBoundingSphere::MinimalBoundingSphere(MathLib::Point3d const& p,
         MinimalBoundingSphere const prs(p, r , s);
         MinimalBoundingSphere const qrs(q, r , s);
         _radius = pqr.getRadius();
-        _center = pqr.getCenter();
+        _center = MathLib::Vector3(pqr.getCenter());
         if (_radius < pqs.getRadius())
         {
             _radius = pqs.getRadius();
-            _center = pqs.getCenter();
+            _center = MathLib::Vector3(pqs.getCenter());
         }
         if (_radius < prs.getRadius())
         {
             _radius = prs.getRadius();
-            _center = prs.getCenter();
+            _center = MathLib::Vector3(prs.getCenter());
         }
         if (_radius < qrs.getRadius())
         {
             _radius = qrs.getRadius();
-            _center = qrs.getCenter();
+            _center = MathLib::Vector3(qrs.getCenter());
         }
     }
 }
@@ -128,7 +128,7 @@ MinimalBoundingSphere::MinimalBoundingSphere(
 {
     const std::vector<MathLib::Point3d*>& sphere_points(points);
     MinimalBoundingSphere const bounding_sphere = recurseCalculation(sphere_points, 0, sphere_points.size(), 0);
-    _center = bounding_sphere.getCenter();
+    _center = MathLib::Vector3(bounding_sphere.getCenter());
     _radius = bounding_sphere.getRadius();
 }
 
diff --git a/MathLib/Vector3.h b/MathLib/Vector3.h
index 575ef025bb0..004304a8c3d 100644
--- a/MathLib/Vector3.h
+++ b/MathLib/Vector3.h
@@ -52,7 +52,7 @@ public:
     /**
      * Construct Vector3 from TemplatePoint.
      */
-    TemplateVector3(TemplatePoint<T,3> const& p) :
+    explicit TemplateVector3(TemplatePoint<T,3> const& p) :
         TemplatePoint<T>(p)
     {}
 
diff --git a/MeshGeoToolsLib/GeoMapper.cpp b/MeshGeoToolsLib/GeoMapper.cpp
index 57809f0367a..971eda9f1b3 100644
--- a/MeshGeoToolsLib/GeoMapper.cpp
+++ b/MeshGeoToolsLib/GeoMapper.cpp
@@ -420,7 +420,7 @@ static void mapPointOnSurfaceElement(MeshLib::Element const& elem,
                                      MathLib::Point3d& q)
 {
     // create plane equation: n*p = d
-    MathLib::Vector3 const& p(*(elem.getNode(0)));
+    MathLib::Vector3 const p(*(elem.getNode(0)));
     MathLib::Vector3 const n(MeshLib::FaceRule::getSurfaceNormal(&elem));
     if (n[2] == 0.0) { // vertical plane, z coordinate is arbitrary
         q[2] = p[2];
diff --git a/MeshLib/MeshEditing/ProjectPointOnMesh.cpp b/MeshLib/MeshEditing/ProjectPointOnMesh.cpp
index b1ab4f265b3..0453a133d43 100644
--- a/MeshLib/MeshEditing/ProjectPointOnMesh.cpp
+++ b/MeshLib/MeshEditing/ProjectPointOnMesh.cpp
@@ -61,7 +61,8 @@ MeshLib::Element const* getProjectedElement(
 double getElevation(MeshLib::Element const& element,
                     MeshLib::Node const& node)
 {
-    MathLib::Vector3 const v = node - *element.getNode(0);
+    MathLib::Vector3 const v =
+        MathLib::Vector3(node) - MathLib::Vector3(*element.getNode(0));
     MathLib::Vector3 const n =
         MeshLib::FaceRule::getSurfaceNormal(&element).getNormalizedVector();
     return node[2] - scalarProduct(n, v) * n[2];
diff --git a/ProcessLib/BoundaryCondition/NormalTractionBoundaryConditionLocalAssembler.h b/ProcessLib/BoundaryCondition/NormalTractionBoundaryConditionLocalAssembler.h
index 76bec33b3d0..8ed02b06f01 100644
--- a/ProcessLib/BoundaryCondition/NormalTractionBoundaryConditionLocalAssembler.h
+++ b/ProcessLib/BoundaryCondition/NormalTractionBoundaryConditionLocalAssembler.h
@@ -86,7 +86,8 @@ public:
         // TODO Extend to rotated 2d meshes and line elements.
         if (e.getGeomType() == MeshLib::MeshElemType::LINE)
         {
-            auto v1 = (*e.getNode(1)) - (*e.getNode(0));
+            auto v1 = MathLib::Vector3(*e.getNode(1)) -
+                      MathLib::Vector3(*e.getNode(0));
             element_normal[0] = -v1[1];
             element_normal[1] = v1[0];
             element_normal.normalize();
diff --git a/ProcessLib/LIE/Common/Utils.cpp b/ProcessLib/LIE/Common/Utils.cpp
index 3866fb50c94..d6c52f604c1 100644
--- a/ProcessLib/LIE/Common/Utils.cpp
+++ b/ProcessLib/LIE/Common/Utils.cpp
@@ -21,7 +21,8 @@ void computeNormalVector(MeshLib::Element const& e, unsigned const global_dim,
     if (global_dim == 2)
     {
         assert(e.getGeomType() == MeshLib::MeshElemType::LINE);
-        auto v1 = (*e.getNode(1)) - (*e.getNode(0));
+        auto v1 =
+            MathLib::Vector3(*e.getNode(1)) - MathLib::Vector3(*e.getNode(0));
         element_normal[0] = -v1[1];
         element_normal[1] = v1[0];
         element_normal[2] = 0;  // not used in 2d but needed for normalization
-- 
GitLab