From 212a70a17b17f9657b3e1bdfbb728d4ce3554869 Mon Sep 17 00:00:00 2001
From: mattijs <mattijs@hunt.opencfd.co.uk>
Date: Thu, 28 Aug 2008 15:50:11 +0100
Subject: [PATCH] boundbox intersect renaming

---
 .../preProcessing/mapFields/mapFields.C       |  4 +-
 src/OpenFOAM/meshes/boundBox/boundBox.H       |  2 +-
 .../boundaryMesh/octreeDataFaceList.C         |  2 +-
 src/meshTools/indexedOctree/indexedOctree.C   | 20 +++++-----
 src/meshTools/indexedOctree/indexedOctree.H   |  6 +--
 src/meshTools/indexedOctree/treeDataCell.C    |  4 +-
 src/meshTools/indexedOctree/treeDataEdge.C    |  4 +-
 src/meshTools/indexedOctree/treeDataFace.C    |  4 +-
 .../indexedOctree/treeDataTriSurface.C        |  4 +-
 src/meshTools/octree/octreeDataCell.C         |  2 +-
 src/meshTools/octree/octreeDataEdges.C        |  2 +-
 src/meshTools/octree/octreeDataFace.C         |  4 +-
 src/meshTools/octree/treeBoundBox.C           | 39 +++++++++++++++++++
 src/meshTools/octree/treeBoundBox.H           |  7 +++-
 src/meshTools/octree/treeBoundBoxI.H          |  6 +--
 src/meshTools/octree/treeNode.C               | 16 ++++----
 .../octreeData/octreeDataTriSurface.C         |  4 +-
 .../octreeData/octreeDataTriSurfaceTreeLeaf.C |  2 +-
 18 files changed, 86 insertions(+), 46 deletions(-)

diff --git a/applications/utilities/preProcessing/mapFields/mapFields.C b/applications/utilities/preProcessing/mapFields/mapFields.C
index 0fb8e40fff2..5d4a6471e49 100644
--- a/applications/utilities/preProcessing/mapFields/mapFields.C
+++ b/applications/utilities/preProcessing/mapFields/mapFields.C
@@ -504,7 +504,7 @@ int main(int argc, char *argv[])
                     !bbsTargetSet[procITarget]
                   || (
                       bbsTargetSet[procITarget]
-                   && bbsTarget[procITarget].intersects(bbSource)
+                   && bbsTarget[procITarget].overlaps(bbSource)
                      )
                 )
                 {
@@ -533,7 +533,7 @@ int main(int argc, char *argv[])
                     bbsTarget[procITarget] = meshTarget.bounds();
                     bbsTargetSet[procITarget] = true;
 
-                    if (bbsTarget[procITarget].intersects(bbSource))
+                    if (bbsTarget[procITarget].overlaps(bbSource))
                     {
                         if (consistent)
                         {
diff --git a/src/OpenFOAM/meshes/boundBox/boundBox.H b/src/OpenFOAM/meshes/boundBox/boundBox.H
index a11aa682662..40287e53ebe 100644
--- a/src/OpenFOAM/meshes/boundBox/boundBox.H
+++ b/src/OpenFOAM/meshes/boundBox/boundBox.H
@@ -118,7 +118,7 @@ public:
         // Query
 
             //- Intersects other boundingbox?
-            bool intersects(const boundBox& bb) const
+            bool overlaps(const boundBox& bb) const
             {
                 if
                 (
diff --git a/src/dynamicMesh/boundaryMesh/octreeDataFaceList.C b/src/dynamicMesh/boundaryMesh/octreeDataFaceList.C
index 2249bc006ec..2ce870af9d7 100644
--- a/src/dynamicMesh/boundaryMesh/octreeDataFaceList.C
+++ b/src/dynamicMesh/boundaryMesh/octreeDataFaceList.C
@@ -399,7 +399,7 @@ bool Foam::octreeDataFaceList::overlaps
     const treeBoundBox& sampleBb
 ) const
 {
-    return sampleBb.intersects(allBb_[index]);
+    return sampleBb.overlaps(allBb_[index]);
 }
 
 
diff --git a/src/meshTools/indexedOctree/indexedOctree.C b/src/meshTools/indexedOctree/indexedOctree.C
index f0f8bd94d0a..1a55a88547e 100644
--- a/src/meshTools/indexedOctree/indexedOctree.C
+++ b/src/meshTools/indexedOctree/indexedOctree.C
@@ -40,7 +40,7 @@ namespace Foam
 // Does bb intersect a sphere around sample? Or is any corner point of bb
 // closer than nearestDistSqr to sample.
 template <class Type>
-bool indexedOctree<Type>::intersects
+bool indexedOctree<Type>::overlaps
 (
     const point& p0,
     const point& p1,
@@ -84,7 +84,7 @@ bool indexedOctree<Type>::intersects
 // Does bb intersect a sphere around sample? Or is any corner point of bb
 // closer than nearestDistSqr to sample.
 template <class Type>
-bool indexedOctree<Type>::intersects
+bool indexedOctree<Type>::overlaps
 (
     const treeBoundBox& parentBb,
     const direction octant,
@@ -94,7 +94,7 @@ bool indexedOctree<Type>::intersects
 {
     //- Speeded up version of
     //     treeBoundBox subBb(parentBb.subBbox(mid, octant))
-    //     intersects
+    //     overlaps
     //     (
     //          subBb.min(),
     //          subBb.max(),
@@ -136,7 +136,7 @@ bool indexedOctree<Type>::intersects
 
     const point mid(0.5*(min+max));
 
-    return intersects(mid, other, nearestDistSqr, sample);
+    return overlaps(mid, other, nearestDistSqr, sample);
 }
 
 
@@ -567,7 +567,7 @@ void indexedOctree<Type>::findNearest
 
             const treeBoundBox& subBb = nodes_[subNodeI].bb_;
 
-            if (intersects(subBb.min(), subBb.max(), nearestDistSqr, sample))
+            if (overlaps(subBb.min(), subBb.max(), nearestDistSqr, sample))
             {
                 findNearest
                 (
@@ -584,7 +584,7 @@ void indexedOctree<Type>::findNearest
         {
             if
             (
-                intersects
+                overlaps
                 (
                     nod.bb_,
                     octant,
@@ -639,7 +639,7 @@ void indexedOctree<Type>::findNearest
         {
             const treeBoundBox& subBb = nodes_[getNode(index)].bb_;
 
-            if (subBb.intersects(tightest))
+            if (subBb.overlaps(tightest))
             {
                 findNearest
                 (
@@ -657,7 +657,7 @@ void indexedOctree<Type>::findNearest
         {
             const treeBoundBox subBb(nodeBb.subBbox(octant));
 
-            if (subBb.intersects(tightest))
+            if (subBb.overlaps(tightest))
             {
                 shapes_.findNearest
                 (
@@ -1121,7 +1121,7 @@ void indexedOctree<Type>::findBox
         {
             const treeBoundBox& subBb = nodes_[getNode(index)].bb_;
 
-            if (subBb.intersects(searchBox))
+            if (subBb.overlaps(searchBox))
             {
                 findBox(getNode(index), searchBox, elements);
             }
@@ -1130,7 +1130,7 @@ void indexedOctree<Type>::findBox
         {
             const treeBoundBox subBb(nodeBb.subBbox(octant));
 
-            if (subBb.intersects(searchBox))
+            if (subBb.overlaps(searchBox))
             {
                 const labelList& indices = contents_[getContent(index)];
 
diff --git a/src/meshTools/indexedOctree/indexedOctree.H b/src/meshTools/indexedOctree/indexedOctree.H
index 249eb1b5f14..97b6ab607c6 100644
--- a/src/meshTools/indexedOctree/indexedOctree.H
+++ b/src/meshTools/indexedOctree/indexedOctree.H
@@ -36,9 +36,9 @@ SourceFiles
 #ifndef indexedOctree_H
 #define indexedOctree_H
 
+#include "treeBoundBox.H"
 #include "pointIndexHit.H"
 #include "FixedList.H"
-#include "treeBoundBox.H"
 #include "Ostream.H"
 #include "labelHashSet.H"
 #include "labelBits.H"
@@ -146,7 +146,7 @@ private:
 
         //- Like above but now bb is implicitly provided as parent bb + mid
         //  + octant
-        static bool intersects
+        static bool overlaps
         (
             const treeBoundBox& parentBb,
             const direction octant,
@@ -497,7 +497,7 @@ public:
 
             //- Helper: does bb intersect a sphere around sample? Or is any
             //  corner point of bb closer than nearestDistSqr to sample.
-            static bool intersects
+            static bool overlaps
             (
                 const point& bbMin,
                 const point& bbMax,
diff --git a/src/meshTools/indexedOctree/treeDataCell.C b/src/meshTools/indexedOctree/treeDataCell.C
index 2ade66780ca..cb41899306b 100644
--- a/src/meshTools/indexedOctree/treeDataCell.C
+++ b/src/meshTools/indexedOctree/treeDataCell.C
@@ -137,11 +137,11 @@ bool Foam::treeDataCell::overlaps
 {
     if (cacheBb_)
     {
-        return cubeBb.intersects(bbs_[index]);
+        return cubeBb.overlaps(bbs_[index]);
     }
     else
     {
-        return cubeBb.intersects(calcCellBb(cellLabels_[index]));
+        return cubeBb.overlaps(calcCellBb(cellLabels_[index]));
     }
 }
 
diff --git a/src/meshTools/indexedOctree/treeDataEdge.C b/src/meshTools/indexedOctree/treeDataEdge.C
index d918fab9447..6b8d54399ee 100644
--- a/src/meshTools/indexedOctree/treeDataEdge.C
+++ b/src/meshTools/indexedOctree/treeDataEdge.C
@@ -110,11 +110,11 @@ bool Foam::treeDataEdge::overlaps
 {
     if (cacheBb_)
     {
-        return cubeBb.intersects(bbs_[index]);
+        return cubeBb.overlaps(bbs_[index]);
     }
     else
     {
-        return cubeBb.intersects(calcBb(edgeLabels_[index]));
+        return cubeBb.overlaps(calcBb(edgeLabels_[index]));
     }
 }
 
diff --git a/src/meshTools/indexedOctree/treeDataFace.C b/src/meshTools/indexedOctree/treeDataFace.C
index e8d148ec230..5764841bbd2 100644
--- a/src/meshTools/indexedOctree/treeDataFace.C
+++ b/src/meshTools/indexedOctree/treeDataFace.C
@@ -412,14 +412,14 @@ bool Foam::treeDataFace::overlaps
     // 1. Quick rejection: bb does not intersect face bb at all
     if (cacheBb_)
     {
-        if (!cubeBb.intersects(bbs_[index]))
+        if (!cubeBb.overlaps(bbs_[index]))
         {
             return false;
         }
     }
     else
     {
-        if (!cubeBb.intersects(calcBb(faceLabels_[index])))
+        if (!cubeBb.overlaps(calcBb(faceLabels_[index])))
         {
             return false;
         }
diff --git a/src/meshTools/indexedOctree/treeDataTriSurface.C b/src/meshTools/indexedOctree/treeDataTriSurface.C
index 23ba7f5116b..c226de94998 100644
--- a/src/meshTools/indexedOctree/treeDataTriSurface.C
+++ b/src/meshTools/indexedOctree/treeDataTriSurface.C
@@ -284,13 +284,13 @@ bool Foam::treeDataTriSurface::overlaps
     triBb.max() = max(triBb.max(), p2);
 
     //- For testing: robust one
-    //return cubeBb.intersects(triBb);
+    //return cubeBb.overlaps(triBb);
 
     //- Exact test of triangle intersecting bb
 
     // Quick rejection. If whole bounding box of tri is outside cubeBb then
     // there will be no intersection.
-    if (!cubeBb.intersects(triBb))
+    if (!cubeBb.overlaps(triBb))
     {
         return false;
     }
diff --git a/src/meshTools/octree/octreeDataCell.C b/src/meshTools/octree/octreeDataCell.C
index 81a3600be94..17bba8b2c99 100644
--- a/src/meshTools/octree/octreeDataCell.C
+++ b/src/meshTools/octree/octreeDataCell.C
@@ -113,7 +113,7 @@ bool Foam::octreeDataCell::overlaps
     const treeBoundBox& cubeBb
 ) const
 {
-    return cubeBb.intersects(bbs_[index]);
+    return cubeBb.overlaps(bbs_[index]);
 }
 
 
diff --git a/src/meshTools/octree/octreeDataEdges.C b/src/meshTools/octree/octreeDataEdges.C
index 3974a0b91d1..9828599e616 100644
--- a/src/meshTools/octree/octreeDataEdges.C
+++ b/src/meshTools/octree/octreeDataEdges.C
@@ -107,7 +107,7 @@ bool Foam::octreeDataEdges::overlaps
     const treeBoundBox& sampleBb
 ) const
 {
-    return sampleBb.intersects(allBb_[index]);
+    return sampleBb.overlaps(allBb_[index]);
 }
 
 
diff --git a/src/meshTools/octree/octreeDataFace.C b/src/meshTools/octree/octreeDataFace.C
index 46f03993cc5..6a8c3f875a6 100644
--- a/src/meshTools/octree/octreeDataFace.C
+++ b/src/meshTools/octree/octreeDataFace.C
@@ -507,12 +507,12 @@ bool Foam::octreeDataFace::overlaps
     const treeBoundBox& sampleBb
 ) const
 {
-    //return sampleBb.intersects(allBb_[index]);
+    //return sampleBb.overlaps(allBb_[index]);
 
     //- Exact test of face intersecting bb
 
     // 1. Quick rejection: bb does not intersect face bb at all
-    if (!sampleBb.intersects(allBb_[index]))
+    if (!sampleBb.overlaps(allBb_[index]))
     {
         return false;
     }
diff --git a/src/meshTools/octree/treeBoundBox.C b/src/meshTools/octree/treeBoundBox.C
index 042209ec7c9..26530b5a3ab 100644
--- a/src/meshTools/octree/treeBoundBox.C
+++ b/src/meshTools/octree/treeBoundBox.C
@@ -297,6 +297,45 @@ Foam::treeBoundBox Foam::treeBoundBox::subBbox
 }
 
 
+bool Foam::treeBoundBox::overlaps
+(
+    const point& centre,
+    const scalar radiusSqr
+) const
+{
+    // Find out where centre is in relation to bb.
+    // Find nearest point on bb.
+    scalar distSqr = 0;
+
+    for (direction dir = 0; dir < vector::nComponents; dir++)
+    {
+        scalar d0 = min()[dir] - centre[dir];
+        scalar d1 = max()[dir] - centre[dir];
+
+        if ((d0 > 0) != (d1 > 0))
+        {
+            // centre inside both extrema. This component does not add any
+            // distance.
+        }
+        else if (Foam::mag(d0) < Foam::mag(d1))
+        {
+            distSqr += d0*d0;
+        }
+        else
+        {
+            distSqr += d1*d1;
+        }
+
+        if (distSqr > radiusSqr)
+        {
+            return false;
+        }
+    }
+
+    return true;
+}
+
+
 // line intersection. Returns true if line (start to end) inside
 // bb or intersects bb. Sets pt to intersection.
 //
diff --git a/src/meshTools/octree/treeBoundBox.H b/src/meshTools/octree/treeBoundBox.H
index 01d7a9a6bd6..02dbac38afb 100644
--- a/src/meshTools/octree/treeBoundBox.H
+++ b/src/meshTools/octree/treeBoundBox.H
@@ -263,8 +263,11 @@ public:
                  FixedList<direction, 8>& octantOrder
             ) const;
 
-            //- Intersects other boundingbox?
-            inline bool intersects(const treeBoundBox&) const;
+            //- Overlaps other boundingbox?
+            inline bool overlaps(const treeBoundBox&) const;
+
+            //- Overlaps boundingSphere (centre + sqr(radius))?
+            bool overlaps(const point&, const scalar radiusSqr) const;
 
             //- Intersects segment; set point to intersection position,
             //  return true if intersection found.
diff --git a/src/meshTools/octree/treeBoundBoxI.H b/src/meshTools/octree/treeBoundBoxI.H
index 431eb8a04d3..c444b2808ae 100644
--- a/src/meshTools/octree/treeBoundBoxI.H
+++ b/src/meshTools/octree/treeBoundBoxI.H
@@ -24,9 +24,7 @@ License
 
 \*---------------------------------------------------------------------------*/
 
-#include "error.H"
 #include "treeBoundBox.H"
-#include "point.H"
 #include "Random.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@@ -414,9 +412,9 @@ inline void treeBoundBox::searchOrder
 
 // true if bb's intersect or overlap.
 // Note: <= to make sure we catch all.
-inline bool treeBoundBox::intersects(const treeBoundBox& bb) const
+inline bool treeBoundBox::overlaps(const treeBoundBox& bb) const
 {
-    return boundBox::intersects(bb);
+    return boundBox::overlaps(bb);
 }
 
 
diff --git a/src/meshTools/octree/treeNode.C b/src/meshTools/octree/treeNode.C
index 678bcfb694d..771ef2cdd98 100644
--- a/src/meshTools/octree/treeNode.C
+++ b/src/meshTools/octree/treeNode.C
@@ -798,7 +798,7 @@ bool treeNode<Type>::findTightest
                 // Node: recurse into subnodes
                 const treeNode<Type>* subNodePtr = getNodePtr(octant);
 
-                if (subNodePtr->bb().intersects(tightest))
+                if (subNodePtr->bb().overlaps(tightest))
                 {
                     // there might be a better fit inside this subNode
                     changed |=
@@ -815,7 +815,7 @@ bool treeNode<Type>::findTightest
                 // Leaf: let leaf::find handle this
                 const treeLeaf<Type>* subLeafPtr = getLeafPtr(octant);
 
-                if (subLeafPtr->bb().intersects(tightest))
+                if (subLeafPtr->bb().overlaps(tightest))
                 {
                     // there might be a better fit inside this subLeaf
                     changed |=
@@ -884,7 +884,7 @@ bool treeNode<Type>::findNearest
                 // Node
                 const treeNode<Type>* subNodePtr = getNodePtr(octant);
 
-                if (subNodePtr->bb().intersects(tightest))
+                if (subNodePtr->bb().overlaps(tightest))
                 {
                     // there might be a better fit inside this subNode
                     changed |=
@@ -903,7 +903,7 @@ bool treeNode<Type>::findNearest
                 // Leaf: let leaf::find handle this
                 const treeLeaf<Type>* subLeafPtr = getLeafPtr(octant);
 
-                if (subLeafPtr->bb().intersects(tightest))
+                if (subLeafPtr->bb().overlaps(tightest))
                 {
                     // there might be a better fit inside this subNode
                     changed |=
@@ -975,7 +975,7 @@ bool treeNode<Type>::findNearest
                 // Node
                 const treeNode<Type>* subNodePtr = getNodePtr(octant);
 
-                if (subNodePtr->bb().intersects(tightest))
+                if (subNodePtr->bb().overlaps(tightest))
                 {
                     // there might be a better fit inside this subNode
                     changed |=
@@ -995,7 +995,7 @@ bool treeNode<Type>::findNearest
                 // Leaf: let leaf::find handle this
                 const treeLeaf<Type>* subLeafPtr = getLeafPtr(octant);
 
-                if (subLeafPtr->bb().intersects(tightest))
+                if (subLeafPtr->bb().overlaps(tightest))
                 {
                     // there might be a better fit inside this subNode
                     changed |=
@@ -1060,7 +1060,7 @@ bool treeNode<Type>::findBox
                 // Node
                 const treeNode<Type>* subNodePtr = getNodePtr(octant);
 
-                if (subNodePtr->bb().intersects(box))
+                if (subNodePtr->bb().overlaps(box))
                 {
                     // Visit sub node.
                     changed |= subNodePtr->findBox(shapes, box, elements);
@@ -1071,7 +1071,7 @@ bool treeNode<Type>::findBox
                 // Leaf: let leaf::find handle this
                 const treeLeaf<Type>* subLeafPtr = getLeafPtr(octant);
 
-                if (subLeafPtr->bb().intersects(box))
+                if (subLeafPtr->bb().overlaps(box))
                 {
                     // Visit sub leaf.
                     changed |= subLeafPtr->findBox(shapes, box, elements);
diff --git a/src/meshTools/triSurface/octreeData/octreeDataTriSurface.C b/src/meshTools/triSurface/octreeData/octreeDataTriSurface.C
index 6a21879f35e..f3dd4f3e03e 100644
--- a/src/meshTools/triSurface/octreeData/octreeDataTriSurface.C
+++ b/src/meshTools/triSurface/octreeData/octreeDataTriSurface.C
@@ -385,12 +385,12 @@ bool Foam::octreeDataTriSurface::overlaps
     const treeBoundBox& cubeBb
 ) const
 {
-    //return cubeBb.intersects(allBb_[index]);
+    //return cubeBb.overlaps(allBb_[index]);
 
     //- Exact test of triangle intersecting bb
 
     // Quick rejection.
-    if (!cubeBb.intersects(allBb_[index]))
+    if (!cubeBb.overlaps(allBb_[index]))
     {
         return false;
     }
diff --git a/src/meshTools/triSurface/octreeData/octreeDataTriSurfaceTreeLeaf.C b/src/meshTools/triSurface/octreeData/octreeDataTriSurfaceTreeLeaf.C
index 6582cfd2399..ca4a34975c3 100644
--- a/src/meshTools/triSurface/octreeData/octreeDataTriSurfaceTreeLeaf.C
+++ b/src/meshTools/triSurface/octreeData/octreeDataTriSurfaceTreeLeaf.C
@@ -54,7 +54,7 @@ bool Foam::treeLeaf<Foam::octreeDataTriSurface>::findNearest
         label faceI = indices_[i];
 
         // Quick rejection test.
-        if (tightest.intersects(allBb[faceI]))
+        if (tightest.overlaps(allBb[faceI]))
         {
             // Full calculation
             scalar dist = shapes.calcNearest(faceI, sample, nearest);
-- 
GitLab