From 24a96a21ca6f1cea0adeb958f4f812bba279c53b Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@Germany>
Date: Mon, 29 Nov 2010 13:44:59 +0100
Subject: [PATCH] ENH: add 'containsAny' and extra 'contains' methods to
 boundBox

---
 src/OpenFOAM/meshes/boundBox/boundBox.C       | 84 +++++++++++++++++++
 src/OpenFOAM/meshes/boundBox/boundBox.H       | 37 ++++++++
 .../meshes/boundBox/boundBoxTemplates.C       | 53 ++++++++++++
 3 files changed, 174 insertions(+)

diff --git a/src/OpenFOAM/meshes/boundBox/boundBox.C b/src/OpenFOAM/meshes/boundBox/boundBox.C
index f781bce5581..a5ba5332e5e 100644
--- a/src/OpenFOAM/meshes/boundBox/boundBox.C
+++ b/src/OpenFOAM/meshes/boundBox/boundBox.C
@@ -163,6 +163,90 @@ Foam::tmp<Foam::pointField> Foam::boundBox::corners() const
 }
 
 
+bool Foam::boundBox::contains(const UList<point>& points) const
+{
+    if (points.empty())
+    {
+        return true;
+    }
+
+    forAll(points, i)
+    {
+        if (!contains(points[i]))
+        {
+            return false;
+        }
+    }
+
+    return true;
+}
+
+
+bool Foam::boundBox::contains
+(
+    const UList<point>& points,
+    const labelUList& indices
+) const
+{
+    if (points.empty() || indices.empty())
+    {
+        return true;
+    }
+
+    forAll(indices, i)
+    {
+        if (!contains(points[indices[i]]))
+        {
+            return false;
+        }
+    }
+
+    return true;
+}
+
+
+bool Foam::boundBox::containsAny(const UList<point>& points) const
+{
+    if (points.empty())
+    {
+        return true;
+    }
+
+    forAll(points, i)
+    {
+        if (contains(points[i]))
+        {
+            return true;
+        }
+    }
+
+    return false;
+}
+
+
+bool Foam::boundBox::containsAny
+(
+    const UList<point>& points,
+    const labelUList& indices
+) const
+{
+    if (points.empty() || indices.empty())
+    {
+        return true;
+    }
+
+    forAll(indices, i)
+    {
+        if (contains(points[indices[i]]))
+        {
+            return true;
+        }
+    }
+
+    return false;
+}
+
+
 // * * * * * * * * * * * * * * * Ostream Operator  * * * * * * * * * * * * * //
 
 Foam::Ostream& Foam::operator<<(Ostream& os, const boundBox& bb)
diff --git a/src/OpenFOAM/meshes/boundBox/boundBox.H b/src/OpenFOAM/meshes/boundBox/boundBox.H
index 101260a3a53..cba0081f634 100644
--- a/src/OpenFOAM/meshes/boundBox/boundBox.H
+++ b/src/OpenFOAM/meshes/boundBox/boundBox.H
@@ -174,6 +174,43 @@ public:
             //- Contains point? (inside only)
             inline bool containsInside(const point&) const;
 
+            //- Contains all of the points? (inside or on edge)
+            bool contains(const UList<point>&) const;
+
+            //- Contains all of the points? (inside or on edge)
+            bool contains
+            (
+                const UList<point>&,
+                const labelUList& indices
+            ) const;
+
+            //- Contains all of the points? (inside or on edge)
+            template<unsigned Size>
+            bool contains
+            (
+                const UList<point>&,
+                const FixedList<label, Size>& indices
+            ) const;
+
+
+            //- Contains any of the points? (inside or on edge)
+            bool containsAny(const UList<point>&) const;
+
+            //- Contains any of the points? (inside or on edge)
+            bool containsAny
+            (
+                const UList<point>&,
+                const labelUList& indices
+            ) const;
+
+            //- Contains any of the points? (inside or on edge)
+            template<unsigned Size>
+            bool containsAny
+            (
+                const UList<point>&,
+                const FixedList<label, Size>& indices
+            ) const;
+
 
     // Friend Operators
 
diff --git a/src/OpenFOAM/meshes/boundBox/boundBoxTemplates.C b/src/OpenFOAM/meshes/boundBox/boundBoxTemplates.C
index 0fd6c3a40fe..82eeb67a647 100644
--- a/src/OpenFOAM/meshes/boundBox/boundBoxTemplates.C
+++ b/src/OpenFOAM/meshes/boundBox/boundBoxTemplates.C
@@ -73,4 +73,57 @@ Foam::boundBox::boundBox
 }
 
 
+// * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
+
+
+template<unsigned Size>
+bool Foam::boundBox::contains
+(
+    const UList<point>& points,
+    const FixedList<label, Size>& indices
+) const
+{
+    // a FixedList is never empty
+    if (points.empty())
+    {
+        return false;
+    }
+
+    forAll(indices, i)
+    {
+        if (!contains(points[indices[i]]))
+        {
+            return false;
+        }
+    }
+
+    return true;
+}
+
+
+template<unsigned Size>
+bool Foam::boundBox::containsAny
+(
+    const UList<point>& points,
+    const FixedList<label, Size>& indices
+) const
+{
+    // a FixedList is never empty
+    if (points.empty())
+    {
+        return false;
+    }
+
+    forAll(indices, i)
+    {
+        if (contains(points[indices[i]]))
+        {
+            return true;
+        }
+    }
+
+    return false;
+}
+
+
 // ************************************************************************* //
-- 
GitLab