From 0f848e950ed1faa94ca2e3de90ba2f3503d3aed4 Mon Sep 17 00:00:00 2001
From: Dmitri Naumov <github@naumov.de>
Date: Sun, 16 Jul 2023 17:01:07 +0200
Subject: [PATCH] [MGTL] Move static class methods into TU

---
 .../BoundaryElementsAlongPolyline.cpp         | 137 ++++++++++--------
 .../BoundaryElementsAlongPolyline.h           |  31 ----
 2 files changed, 80 insertions(+), 88 deletions(-)

diff --git a/MeshGeoToolsLib/BoundaryElementsAlongPolyline.cpp b/MeshGeoToolsLib/BoundaryElementsAlongPolyline.cpp
index ea5e57b4719..8278e89f0da 100644
--- a/MeshGeoToolsLib/BoundaryElementsAlongPolyline.cpp
+++ b/MeshGeoToolsLib/BoundaryElementsAlongPolyline.cpp
@@ -21,6 +21,86 @@
 #include "MeshLib/MeshSearch/ElementSearch.h"
 #include "MeshLib/Node.h"
 
+namespace
+{
+/**
+ * Check if a vector of node IDs includes all nodes of a given element
+ * \param vec_node_ids         a vector of Node IDs
+ * \param edge                 Edge object whose node IDs are checked
+ * \param edge_node_distances  a vector of distances of the edge nodes from the
+ * beginning of the given node ID vector
+ * \return true if all element nodes are included in the vector
+ */
+bool includesAllEdgeNodeIDs(std::vector<std::size_t> const& vec_node_ids,
+                            MeshLib::Element const& edge,
+                            std::vector<std::size_t>& edge_node_distances)
+{
+    unsigned j = 0;
+    for (; j < edge.getNumberOfBaseNodes(); j++)
+    {
+        auto itr = std::find(vec_node_ids.begin(), vec_node_ids.end(),
+                             getNodeIndex(edge, j));
+        if (itr != vec_node_ids.end())
+        {
+            edge_node_distances.push_back(
+                std::distance(vec_node_ids.begin(), itr));
+        }
+        else
+        {
+            break;
+        }
+    }
+    return j == edge.getNumberOfBaseNodes();
+}
+
+/**
+ * Modify node ordering of an edge so that its first node is closer to the
+ * beginning of a polyline than others
+ * \param edge                           Element object
+ * \param ply                            Polyline object
+ * \param edge_node_distances_along_ply  A vector of current edge node
+ * distances along poly
+ * \param node_ids_on_poly               A vector of node IDs along the polyine
+ * \return A pointer to the new modified edge object. A pointer to the original
+ * edge is returned if the modification is unnecessary.
+ */
+MeshLib::Element* modifyEdgeNodeOrdering(
+    const MeshLib::Element& edge, const GeoLib::Polyline& ply,
+    const std::vector<std::size_t>& edge_node_distances_along_ply,
+    const std::vector<std::size_t>& node_ids_on_poly)
+{
+    // The first node of the edge should be always closer to the beginning of
+    // the polyline than other nodes.
+    if (edge_node_distances_along_ply.front() >
+            edge_node_distances_along_ply.back() ||
+        (ply.isClosed() &&
+         edge_node_distances_along_ply.back() == node_ids_on_poly.size() - 1))
+    {  // Create a new element with reversed local node index
+        if (auto const* e = dynamic_cast<MeshLib::Line const*>(&edge))
+        {
+            std::array nodes = {const_cast<MeshLib::Node*>(e->getNode(1)),
+                                const_cast<MeshLib::Node*>(e->getNode(0))};
+            return new MeshLib::Line(nodes);
+        }
+        else if (auto const* e = dynamic_cast<MeshLib::Line3 const*>(&edge))
+        {
+            std::array nodes = {const_cast<MeshLib::Node*>(e->getNode(1)),
+                                const_cast<MeshLib::Node*>(e->getNode(0)),
+                                const_cast<MeshLib::Node*>(e->getNode(2))};
+            return new MeshLib::Line3(nodes);
+        }
+        else
+        {
+            OGS_FATAL("Not implemented for element type {:s}",
+                      typeid(edge).name());
+        }
+    }
+
+    // Return the original edge otherwise.
+    return const_cast<MeshLib::Element*>(&edge);
+}
+}  // namespace
+
 namespace MeshGeoToolsLib
 {
 BoundaryElementsAlongPolyline::BoundaryElementsAlongPolyline(
@@ -101,61 +181,4 @@ BoundaryElementsAlongPolyline::~BoundaryElementsAlongPolyline()
     }
 }
 
-bool BoundaryElementsAlongPolyline::includesAllEdgeNodeIDs(
-    const std::vector<std::size_t>& vec_node_ids, const MeshLib::Element& edge,
-    std::vector<std::size_t>& edge_node_distances)
-{
-    unsigned j = 0;
-    for (; j < edge.getNumberOfBaseNodes(); j++)
-    {
-        auto itr = std::find(vec_node_ids.begin(), vec_node_ids.end(),
-                             getNodeIndex(edge, j));
-        if (itr != vec_node_ids.end())
-        {
-            edge_node_distances.push_back(
-                std::distance(vec_node_ids.begin(), itr));
-        }
-        else
-        {
-            break;
-        }
-    }
-    return (j == edge.getNumberOfBaseNodes());
-}
-
-MeshLib::Element* BoundaryElementsAlongPolyline::modifyEdgeNodeOrdering(
-    const MeshLib::Element& edge, const GeoLib::Polyline& ply,
-    const std::vector<std::size_t>& edge_node_distances_along_ply,
-    const std::vector<std::size_t>& node_ids_on_poly) const
-{
-    // The first node of the edge should be always closer to the beginning of
-    // the polyline than other nodes.
-    if (edge_node_distances_along_ply.front() >
-            edge_node_distances_along_ply.back() ||
-        (ply.isClosed() &&
-         edge_node_distances_along_ply.back() == node_ids_on_poly.size() - 1))
-    {  // Create a new element with reversed local node index
-        if (auto const* e = dynamic_cast<MeshLib::Line const*>(&edge))
-        {
-            std::array nodes = {const_cast<MeshLib::Node*>(e->getNode(1)),
-                                const_cast<MeshLib::Node*>(e->getNode(0))};
-            return new MeshLib::Line(nodes);
-        }
-        else if (auto const* e = dynamic_cast<MeshLib::Line3 const*>(&edge))
-        {
-            std::array nodes = {const_cast<MeshLib::Node*>(e->getNode(1)),
-                                const_cast<MeshLib::Node*>(e->getNode(0)),
-                                const_cast<MeshLib::Node*>(e->getNode(2))};
-            return new MeshLib::Line3(nodes);
-        }
-        else
-        {
-            OGS_FATAL("Not implemented for element type {:s}",
-                      typeid(edge).name());
-        }
-    }
-
-    // Return the original edge otherwise.
-    return const_cast<MeshLib::Element*>(&edge);
-}
 }  // end namespace MeshGeoToolsLib
diff --git a/MeshGeoToolsLib/BoundaryElementsAlongPolyline.h b/MeshGeoToolsLib/BoundaryElementsAlongPolyline.h
index 44b5ad16101..3043e0a33e5 100644
--- a/MeshGeoToolsLib/BoundaryElementsAlongPolyline.h
+++ b/MeshGeoToolsLib/BoundaryElementsAlongPolyline.h
@@ -67,37 +67,6 @@ public:
     }
 
 private:
-    /**
-     * Check if a vector of node IDs includes all nodes of a given element
-     * @param vec_node_ids         a vector of Node IDs
-     * @param edge                 Edge object whose node IDs are checked
-     * @param edge_node_distances  a vector of distances of the edge nodes from
-     * the beginning of the given node ID vector
-     * @return true if all element nodes are included in the vector
-     */
-    static bool includesAllEdgeNodeIDs(
-        const std::vector<std::size_t>& vec_node_ids,
-        const MeshLib::Element& edge,
-        std::vector<std::size_t>& edge_node_distances);
-
-    /**
-     * Modify node ordering of an edge so that its first node is closer to the
-     * beginning of a polyline than others
-     * @param edge                           Element object
-     * @param ply                            Polyline object
-     * @param edge_node_distances_along_ply  A vector of current edge node
-     * distances along poly
-     * @param node_ids_on_poly               A vector of node IDs along the
-     * polyine
-     * @return A pointer to the new modified edge object. A pointer to the
-     * original edge is returned if the modification is unnecessary.
-     */
-    MeshLib::Element* modifyEdgeNodeOrdering(
-        const MeshLib::Element& edge,
-        const GeoLib::Polyline& ply,
-        const std::vector<std::size_t>& edge_node_distances_along_ply,
-        const std::vector<std::size_t>& node_ids_on_poly) const;
-
     MeshLib::Mesh const& _mesh;
     GeoLib::Polyline const& _ply;
     std::vector<MeshLib::Element*> _boundary_elements;
-- 
GitLab