From b9712c9b831997bf72d2376e6225835b257d64a5 Mon Sep 17 00:00:00 2001
From: "Dmitry Yu. Naumov" <github@naumov.de>
Date: Thu, 23 Aug 2018 11:34:38 +0200
Subject: [PATCH] [MeL] Add isBaseNode predicate.

---
 MeshLib/Node.cpp | 13 +++++++++++++
 MeshLib/Node.h   |  4 ++++
 2 files changed, 17 insertions(+)

diff --git a/MeshLib/Node.cpp b/MeshLib/Node.cpp
index e147769af02..a212f11539b 100644
--- a/MeshLib/Node.cpp
+++ b/MeshLib/Node.cpp
@@ -49,5 +49,18 @@ void Node::updateCoordinates(double x, double y, double z)
         _elements[i]->computeVolume();
 }
 
+bool isBaseNode(Node const& node)
+{
+    // Check if node is connected.
+    if (node.getNumberOfElements() == 0)
+        return true;
+
+    // In a mesh a node always belongs to at least one element.
+    auto const e = node.getElement(0);
+
+    auto const n_base_nodes = e->getNumberOfBaseNodes();
+    auto const local_index = e->getNodeIDinElement(&node);
+    return local_index < n_base_nodes;
+}
 }
 
diff --git a/MeshLib/Node.h b/MeshLib/Node.h
index dc105a3a24b..558561ef257 100644
--- a/MeshLib/Node.h
+++ b/MeshLib/Node.h
@@ -102,4 +102,8 @@ protected:
     std::vector<Element*> _elements;
 }; /* class */
 
+/// Returns true if the given node is a base node of a (first) element, or if it
+/// is not connected to any element i.e. an unconnected node.
+bool isBaseNode(Node const& node);
+
 } /* namespace */
-- 
GitLab