[MOAB-dev] r1976 - MOAB/trunk

kraftche at mcs.anl.gov kraftche at mcs.anl.gov
Thu Jul 3 09:56:53 CDT 2008


Author: kraftche
Date: 2008-07-03 09:56:52 -0500 (Thu, 03 Jul 2008)
New Revision: 1976

Modified:
   MOAB/trunk/GeomUtilTests.cpp
   MOAB/trunk/MBAdaptiveKDTree.cpp
   MOAB/trunk/MBGeomUtil.cpp
   MOAB/trunk/MBGeomUtil.hpp
Log:
o Increase default minimum box width (effectively the tolerance) for 
  tree construction.
  
o Remove assumption that if an element overlapped a parent box that it
  must overlap at least one of the child boxes.  While this assumption
  is true for exact calculations, it doesn't hold true in the face of
  accumulating error as tree depth increases.  This test caught a lot
  of errors in overlap tests, so it might be worth while to re-
  implement it with the tolerance proportional to depth.  On the other
  hand, eliminating false positives reduces the number of entities in
  some of the leaves.

o Add specialized box_tet_overlap test.  Decreases tree build time by
  almost half for basic subdivision algorithm on 93k tet sphere.

o Add unit test for box_tet_overlap and test the generalized 
  box_linear_elem_overlap with tets.

o Remove lots of duplicate code in GeomUtilTests.cpp (use same test
  code for box_linear_elem_overlap with hexes and triangles as is
  used with box_hex_overlap and box_tri_overlap, respectively.)




Modified: MOAB/trunk/GeomUtilTests.cpp
===================================================================
--- MOAB/trunk/GeomUtilTests.cpp	2008-07-02 04:06:20 UTC (rev 1975)
+++ MOAB/trunk/GeomUtilTests.cpp	2008-07-03 14:56:52 UTC (rev 1976)
@@ -113,248 +113,35 @@
   test_box_plane_corner( 1,-1, 1, min, max );
 }     
 
-void test_box_tri_overlap()
-{
-  MBCartVect coords[3];
-  MBCartVect center, dims;
-  
-    // test box projection within triangle, z-plane
-  coords[0] = MBCartVect( 0, 0, 0 );
-  coords[1] = MBCartVect( 0, 4, 0 );
-  coords[2] = MBCartVect(-4, 0, 0 );
-  center = MBCartVect( -2, 1, 0 );
-  dims = MBCartVect( 1, 0.5, 3 );
-  ASSERT(  box_tri_overlap( coords, center, dims ) );
-    // move box below plane of triangle
-  center[2] = -4;
-  ASSERT( !box_tri_overlap( coords, center, dims ) );
-    // move box above plane of triangle
-  center[2] =  4;
-  ASSERT( !box_tri_overlap( coords, center, dims ) );
-  
-    // test box projection within triangle, x-plane
-  coords[0] = MBCartVect( 3, 3, 0 );
-  coords[1] = MBCartVect( 3, 3, 1 );
-  coords[2] = MBCartVect( 3, 0, 0 );
-  center = MBCartVect( 3, 2.5, .25 );
-  dims = MBCartVect( 0.001, 0.4, .2 );
-  ASSERT(  box_tri_overlap( coords, center, dims ) );
-    // move box below plane of triangle
-  center[0] = 2;
-  ASSERT( !box_tri_overlap( coords, center, dims ) );
-    // move box above plane of triangle
-  center[0] = 4;
-  ASSERT( !box_tri_overlap( coords, center, dims ) );
-  
-    // test tri slices corner at +x,+y,+z
-  coords[0] = MBCartVect(3,1,1);
-  coords[1] = MBCartVect(1,3,1);
-  coords[2] = MBCartVect(1,1,3);
-  ASSERT(  box_tri_overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
-    // test with tri above the corner
-  ASSERT( !box_tri_overlap( coords, MBCartVect(0,0,0), MBCartVect(1,1,1) ) );
-    // test tri slices corner at -x,-y,-z
-  coords[0] = MBCartVect(-1,1,1);
-  coords[1] = MBCartVect(1,-1,1);
-  coords[2] = MBCartVect(1,1,-1);
-  ASSERT(  box_tri_overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
-    // test with tri below the corner
-  ASSERT( !box_tri_overlap( coords, MBCartVect(2,2,2),MBCartVect(1,1,1) ) );
-  
-    // test tri slices corner at -x,+y,+z
-  coords[0] = MBCartVect( 0.5, 0.0, 2.5);
-  coords[1] = MBCartVect( 0.5, 2.5, 0.0);
-  coords[2] = MBCartVect(-0.5, 0.0, 0.0);
-  ASSERT(  box_tri_overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
-    // test with tri above the corner
-  ASSERT( !box_tri_overlap( coords, MBCartVect(2,1,1), MBCartVect(1,1,1) ) );
-  
-    // test tri slices corner at +x,-y,-z
-  coords[0] = MBCartVect( 0.5, 0.0,-1.5);
-  coords[1] = MBCartVect( 0.5,-1.5, 0.0);
-  coords[2] = MBCartVect( 1.5, 0.0, 0.0);
-  ASSERT(  box_tri_overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
-    // test with tri above the corner
-  ASSERT( !box_tri_overlap( coords, MBCartVect(0,1,1), MBCartVect(1,1,1) ) );
 
-    // test tri slices corner at +x,-y,+z
-  coords[0] = MBCartVect( 1.0, 1.0, 2.5 );
-  coords[1] = MBCartVect( 2.5, 1.0, 1.0 );
-  coords[2] = MBCartVect( 1.0,-0.5, 1.0 );
-  ASSERT(  box_tri_overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
-    // test with tri above the corner
-  ASSERT( !box_tri_overlap( coords, MBCartVect(-1,1,1), MBCartVect(1,1,1) ) );
-
-    // test tri slices corner at -x,+y,-z  
-  coords[0] = MBCartVect( 1.0,  1.0,-0.5 );
-  coords[1] = MBCartVect(-0.5,  1.0, 1.0 );
-  coords[2] = MBCartVect( 1.0,  2.5, 1.0 );
-  ASSERT(  box_tri_overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
-    // test with tri above the corner
-  ASSERT( !box_tri_overlap( coords, MBCartVect(3,1,1), MBCartVect(1,1,1) ) );
-
-    // test tri slices corner at +x,+y,-z
-  coords[0] = MBCartVect(-0.1, 1.0, 1.0);
-  coords[1] = MBCartVect( 1.0,-0.1, 1.0);
-  coords[2] = MBCartVect( 1.0, 1.0,-0.1);
-  ASSERT(  box_tri_overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
-    // test with tri outside box
-  ASSERT( !box_tri_overlap( coords, MBCartVect(1,1,3), MBCartVect(1,1,1) ) );
+class ElemOverlapTest {
+  public:
   
-    // test tri slices corner at -x,-y,+z
-  coords[0] = MBCartVect( 2.1, 1.0, 1.0);
-  coords[1] = MBCartVect( 1.0, 2.1, 1.0);
-  coords[2] = MBCartVect( 1.0, 1.0, 2.1);
-  ASSERT(  box_tri_overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
-    // test with tri outside box
-  ASSERT( !box_tri_overlap( coords, MBCartVect(1,1,-1), MBCartVect(1,1,1) ) );
-  
-    // box edge parallel to x at +y,+z passes through triangle
-  coords[0] = MBCartVect( 1.0, 1.0, 3.0);
-  coords[1] = MBCartVect( 1.0, 3.0, 3.0);
-  coords[2] = MBCartVect( 1.0, 3.0, 1.0);
-  ASSERT(  box_tri_overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
-    // test with tri outside box
-  ASSERT( !box_tri_overlap( coords, MBCartVect(1,1,0.3), MBCartVect(1,1,1) ) );
-  
-    // box edge parallel to x at +y,-z passes through triangle
-  coords[0] = MBCartVect( 1.0, 3.0, 1.0);
-  coords[1] = MBCartVect( 1.0, 3.0,-1.0);
-  coords[2] = MBCartVect( 1.0, 1.0,-1.0);
-  ASSERT(  box_tri_overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
-    // test with tri outside box
-  ASSERT( !box_tri_overlap( coords, MBCartVect(1,1,1.7), MBCartVect(1,1,1) ) );
-  
-    // box edge parallel to x at -y,-z passes through triangle
-  coords[0] = MBCartVect( 1.0,-1.0, 1.0);
-  coords[1] = MBCartVect( 1.0,-1.0,-1.0);
-  coords[2] = MBCartVect( 1.0, 1.0,-1.0);
-  ASSERT(  box_tri_overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
-    // test with tri outside box
-  ASSERT( !box_tri_overlap( coords, MBCartVect(1,1,1.7), MBCartVect(1,1,1) ) );
-  
-    // box edge parallel to x at -y,+z passes through triangle
-  coords[0] = MBCartVect( 1.0,-1.0, 1.0);
-  coords[1] = MBCartVect( 1.0,-1.0, 3.0);
-  coords[2] = MBCartVect( 1.0, 1.0, 3.0);
-  ASSERT(  box_tri_overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
-    // test with tri outside box
-  ASSERT( !box_tri_overlap( coords, MBCartVect(1,1,0.3), MBCartVect(1,1,1) ) );
-  
-    // box edge parallel to y at +x,+z passes through triangle
-  coords[0] = MBCartVect( 1.0, 1.0, 3.0);
-  coords[1] = MBCartVect( 3.0, 1.0, 3.0);
-  coords[2] = MBCartVect( 3.0, 1.0, 1.0);
-  ASSERT(  box_tri_overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
-    // test with tri outside box
-  ASSERT( !box_tri_overlap( coords, MBCartVect(1,1,0.3), MBCartVect(1,1,1) ) );
-  
-    // box edge parallel to y at -x,+z passes through triangle
-  coords[0] = MBCartVect( 1.0, 1.0, 3.0);
-  coords[1] = MBCartVect(-1.0, 1.0, 3.0);
-  coords[2] = MBCartVect(-1.0, 1.0, 1.0);
-  ASSERT(  box_tri_overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
-    // test with tri outside box
-  ASSERT( !box_tri_overlap( coords, MBCartVect(1,1,0.3), MBCartVect(1,1,1) ) );
-  
-    // box edge parallel to y at +x,-z passes through triangle
-  coords[0] = MBCartVect( 1.0, 1.0,-1.0);
-  coords[1] = MBCartVect( 3.0, 1.0,-1.0);
-  coords[2] = MBCartVect( 3.0, 1.0, 1.0);
-  ASSERT(  box_tri_overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
-    // test with tri outside box
-  ASSERT( !box_tri_overlap( coords, MBCartVect(1,1,1.7), MBCartVect(1,1,1) ) );
-  
-    // box edge parallel to y at -x,-z passes through triangle
-  coords[0] = MBCartVect( 1.0, 1.0,-1.0);
-  coords[1] = MBCartVect(-1.0, 1.0,-1.0);
-  coords[2] = MBCartVect(-1.0, 1.0, 1.0);
-  ASSERT(  box_tri_overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
-    // test with tri outside box
-  ASSERT( !box_tri_overlap( coords, MBCartVect(1,1,1.7), MBCartVect(1,1,1) ) );
-  
-    // box edge parallel to z at +x,+y passes through triangle
-  coords[0] = MBCartVect( 1.0, 3.0, 1.0);
-  coords[1] = MBCartVect( 3.0, 3.0, 1.0);
-  coords[2] = MBCartVect( 3.0, 1.0, 1.0);
-  ASSERT(  box_tri_overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
-    // test with tri outside box
-  ASSERT( !box_tri_overlap( coords, MBCartVect(0.3,1,1), MBCartVect(1,1,1) ) );
-  
-    // box edge parallel to z at +x,-y passes through triangle
-  coords[0] = MBCartVect( 1.0,-1.0, 1.0);
-  coords[1] = MBCartVect( 3.0,-1.0, 1.0);
-  coords[2] = MBCartVect( 3.0, 1.0, 1.0);
-  ASSERT(  box_tri_overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
-    // test with tri outside box
-  ASSERT( !box_tri_overlap( coords, MBCartVect(0.3,1,1), MBCartVect(1,1,1) ) );
-  
-    // box edge parallel to z at -x,+y passes through triangle
-  coords[0] = MBCartVect( 1.0, 3.0, 1.0);
-  coords[1] = MBCartVect(-1.0, 3.0, 1.0);
-  coords[2] = MBCartVect(-1.0, 1.0, 1.0);
-  ASSERT(  box_tri_overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
-    // test with tri outside box
-  ASSERT( !box_tri_overlap( coords, MBCartVect(1.7,1,1), MBCartVect(1,1,1) ) );
-  
-    // box edge parallel to z at -x,-y passes through triangle
-  coords[0] = MBCartVect( 1.0,-1.0, 1.0);
-  coords[1] = MBCartVect(-1.0,-1.0, 1.0);
-  coords[2] = MBCartVect(-1.0, 1.0, 1.0);
-  ASSERT(  box_tri_overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
-    // test with tri outside box
-  ASSERT( !box_tri_overlap( coords, MBCartVect(1.7,1,1), MBCartVect(1,1,1) ) );
-  
-    // triangle penetrates +x face
-  coords[0] = MBCartVect( 2.0, 2.0, 2.0 );
-  coords[1] = MBCartVect( 5.0, 3.0, 2.0 );
-  coords[2] = MBCartVect( 5.0, 1.0, 2.0 );
-  ASSERT(  box_tri_overlap( coords, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
-    // test with tri outside box
-  ASSERT( !box_tri_overlap( coords, MBCartVect(-1,2,2), MBCartVect(2,2,2) ) );
-  
-    // triangle penetrates -x face
-  coords[0] = MBCartVect( 2.0, 2.0, 2.0 );
-  coords[1] = MBCartVect(-1.0, 3.0, 2.0 );
-  coords[2] = MBCartVect(-1.0, 1.0, 2.0 );
-  ASSERT(  box_tri_overlap( coords, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
-    // test with tri outside box
-  ASSERT( !box_tri_overlap( coords, MBCartVect(5,2,2), MBCartVect(2,2,2) ) );
-  
-    // triangle penetrates +y face
-  coords[0] = MBCartVect( 2.0, 2.0, 2.0 );
-  coords[1] = MBCartVect( 3.0, 5.0, 2.0 );
-  coords[2] = MBCartVect( 1.0, 5.0, 2.0 );
-  ASSERT(  box_tri_overlap( coords, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
-    // test with tri outside box
-  ASSERT( !box_tri_overlap( coords, MBCartVect(2,-1,2), MBCartVect(2,2,2) ) );
-  
-    // triangle penetrates -y face
-  coords[0] = MBCartVect( 2.0, 2.0, 2.0 );
-  coords[1] = MBCartVect( 3.0,-1.0, 2.0 );
-  coords[2] = MBCartVect( 1.0,-1.0, 2.0 );
-  ASSERT(  box_tri_overlap( coords, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
-    // test with tri outside box
-  ASSERT( !box_tri_overlap( coords, MBCartVect(2,5,2), MBCartVect(2,2,2) ) );
-  
-    // triangle penetrates +z face
-  coords[0] = MBCartVect( 2.0, 2.0, 2.0 );
-  coords[1] = MBCartVect( 2.0, 3.0, 5.0 );
-  coords[2] = MBCartVect( 2.0, 1.0, 5.0 );
-  ASSERT(  box_tri_overlap( coords, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
-    // test with tri outside box
-  ASSERT( !box_tri_overlap( coords, MBCartVect(2,2,-1), MBCartVect(2,2,2) ) );
-  
-    // triangle penetrates -z face
-  coords[0] = MBCartVect( 2.0, 2.0, 2.0 );
-  coords[1] = MBCartVect( 2.0, 3.0,-1.0 );
-  coords[2] = MBCartVect( 2.0, 1.0,-1.0 );
-  ASSERT(  box_tri_overlap( coords, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
-    // test with tri outside box
-  ASSERT( !box_tri_overlap( coords, MBCartVect(2,2,5), MBCartVect(2,2,2) ) );
-}
+    virtual bool operator()( const MBCartVect* coords, 
+                             const MBCartVect& box_center, 
+                             const MBCartVect& box_dims ) const = 0;
+};
+class LinearElemOverlapTest : public ElemOverlapTest {
+  public:
+    const MBEntityType type;
+    LinearElemOverlapTest(MBEntityType t) : type(t) {}
+    bool operator()( const MBCartVect* coords, 
+                     const MBCartVect& box_center, 
+                     const MBCartVect& box_dims ) const
+      { return box_linear_elem_overlap( coords, type, box_center, box_dims ); }
+};
+class TypeElemOverlapTest : public ElemOverlapTest {
+  public:
+    bool (*func)( const MBCartVect*, const MBCartVect&, const MBCartVect& );
+    TypeElemOverlapTest( bool (*f)( const MBCartVect*, const MBCartVect&, const MBCartVect& ) )
+      : func(f){}
+    bool operator()( const MBCartVect* coords, 
+                     const MBCartVect& box_center, 
+                     const MBCartVect& box_dims ) const
+      { return (*func)( coords, box_center, box_dims ); }
+};    
 
-void test_box_linear_elem_overlap_tri()
+void general_box_tri_overlap_test( const ElemOverlapTest& overlap )
 {
   MBCartVect coords[3];
   MBCartVect center, dims;
@@ -365,13 +152,13 @@
   coords[2] = MBCartVect(-4, 0, 0 );
   center = MBCartVect( -2, 1, 0 );
   dims = MBCartVect( 1, 0.5, 3 );
-  ASSERT(  box_linear_elem_overlap( coords, MBTRI, center, dims ) );
+  ASSERT(  overlap( coords, center, dims ) );
     // move box below plane of triangle
   center[2] = -4;
-  ASSERT( !box_linear_elem_overlap( coords, MBTRI, center, dims ) );
+  ASSERT( !overlap( coords, center, dims ) );
     // move box above plane of triangle
   center[2] =  4;
-  ASSERT( !box_linear_elem_overlap( coords, MBTRI, center, dims ) );
+  ASSERT( !overlap( coords, center, dims ) );
   
     // test box projection within triangle, x-plane
   coords[0] = MBCartVect( 3, 3, 0 );
@@ -379,223 +166,223 @@
   coords[2] = MBCartVect( 3, 0, 0 );
   center = MBCartVect( 3, 2.5, .25 );
   dims = MBCartVect( 0.001, 0.4, .2 );
-  ASSERT(  box_linear_elem_overlap( coords, MBTRI, center, dims ) );
+  ASSERT(  overlap( coords, center, dims ) );
     // move box below plane of triangle
   center[0] = 2;
-  ASSERT( !box_linear_elem_overlap( coords, MBTRI, center, dims ) );
+  ASSERT( !overlap( coords, center, dims ) );
     // move box above plane of triangle
   center[0] = 4;
-  ASSERT( !box_linear_elem_overlap( coords, MBTRI, center, dims ) );
+  ASSERT( !overlap( coords, center, dims ) );
   
     // test tri slices corner at +x,+y,+z
   coords[0] = MBCartVect(3,1,1);
   coords[1] = MBCartVect(1,3,1);
   coords[2] = MBCartVect(1,1,3);
-  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
     // test with tri above the corner
-  ASSERT( !box_linear_elem_overlap( coords, MBTRI, MBCartVect(0,0,0), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, MBCartVect(0,0,0), MBCartVect(1,1,1) ) );
     // test tri slices corner at -x,-y,-z
   coords[0] = MBCartVect(-1,1,1);
   coords[1] = MBCartVect(1,-1,1);
   coords[2] = MBCartVect(1,1,-1);
-  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
     // test with tri below the corner
-  ASSERT( !box_linear_elem_overlap( coords, MBTRI, MBCartVect(2,2,2),MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, MBCartVect(2,2,2),MBCartVect(1,1,1) ) );
   
     // test tri slices corner at -x,+y,+z
   coords[0] = MBCartVect( 0.5, 0.0, 2.5);
   coords[1] = MBCartVect( 0.5, 2.5, 0.0);
   coords[2] = MBCartVect(-0.5, 0.0, 0.0);
-  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
     // test with tri above the corner
-  ASSERT( !box_linear_elem_overlap( coords, MBTRI, MBCartVect(2,1,1), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, MBCartVect(2,1,1), MBCartVect(1,1,1) ) );
   
     // test tri slices corner at +x,-y,-z
   coords[0] = MBCartVect( 0.5, 0.0,-1.5);
   coords[1] = MBCartVect( 0.5,-1.5, 0.0);
   coords[2] = MBCartVect( 1.5, 0.0, 0.0);
-  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(0,0,0), MBCartVect(1,1,1) ) );
+  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
     // test with tri above the corner
-  ASSERT( !box_linear_elem_overlap( coords, MBTRI, MBCartVect(-0.5,0.5,0.5), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, MBCartVect(0,1,1), MBCartVect(1,1,1) ) );
 
     // test tri slices corner at +x,-y,+z
   coords[0] = MBCartVect( 1.0, 1.0, 2.5 );
   coords[1] = MBCartVect( 2.5, 1.0, 1.0 );
   coords[2] = MBCartVect( 1.0,-0.5, 1.0 );
-  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
     // test with tri above the corner
-  ASSERT( !box_linear_elem_overlap( coords, MBTRI, MBCartVect(-1,1,1), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, MBCartVect(-1,1,1), MBCartVect(1,1,1) ) );
 
     // test tri slices corner at -x,+y,-z  
   coords[0] = MBCartVect( 1.0,  1.0,-0.5 );
   coords[1] = MBCartVect(-0.5,  1.0, 1.0 );
   coords[2] = MBCartVect( 1.0,  2.5, 1.0 );
-  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
     // test with tri above the corner
-  ASSERT( !box_linear_elem_overlap( coords, MBTRI, MBCartVect(3,1,1), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, MBCartVect(3,1,1), MBCartVect(1,1,1) ) );
 
     // test tri slices corner at +x,+y,-z
   coords[0] = MBCartVect(-0.1, 1.0, 1.0);
   coords[1] = MBCartVect( 1.0,-0.1, 1.0);
   coords[2] = MBCartVect( 1.0, 1.0,-0.1);
-  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,1,3), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, MBCartVect(1,1,3), MBCartVect(1,1,1) ) );
   
     // test tri slices corner at -x,-y,+z
   coords[0] = MBCartVect( 2.1, 1.0, 1.0);
   coords[1] = MBCartVect( 1.0, 2.1, 1.0);
   coords[2] = MBCartVect( 1.0, 1.0, 2.1);
-  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  ASSERT(  box_tri_overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,1,-1), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, MBCartVect(1,1,-1), MBCartVect(1,1,1) ) );
   
     // box edge parallel to x at +y,+z passes through triangle
   coords[0] = MBCartVect( 1.0, 1.0, 3.0);
   coords[1] = MBCartVect( 1.0, 3.0, 3.0);
   coords[2] = MBCartVect( 1.0, 3.0, 1.0);
-  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,1.5,1.5), MBCartVect(1,1,1) ) );
+  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,1,0.3), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, MBCartVect(1,1,0.3), MBCartVect(1,1,1) ) );
   
     // box edge parallel to x at +y,-z passes through triangle
   coords[0] = MBCartVect( 1.0, 3.0, 1.0);
   coords[1] = MBCartVect( 1.0, 3.0,-1.0);
   coords[2] = MBCartVect( 1.0, 1.0,-1.0);
-  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,1.5,0.5), MBCartVect(1,1,1) ) );
+  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,1,1.7), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, MBCartVect(1,1,1.7), MBCartVect(1,1,1) ) );
   
     // box edge parallel to x at -y,-z passes through triangle
   coords[0] = MBCartVect( 1.0,-1.0, 1.0);
   coords[1] = MBCartVect( 1.0,-1.0,-1.0);
   coords[2] = MBCartVect( 1.0, 1.0,-1.0);
-  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,0.5,0.5), MBCartVect(1,1,1) ) );
+  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,1,1.7), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, MBCartVect(1,1,1.7), MBCartVect(1,1,1) ) );
   
     // box edge parallel to x at -y,+z passes through triangle
   coords[0] = MBCartVect( 1.0,-1.0, 1.0);
   coords[1] = MBCartVect( 1.0,-1.0, 3.0);
   coords[2] = MBCartVect( 1.0, 1.0, 3.0);
-  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,0.5,1.5), MBCartVect(1,1,1) ) );
+  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,1,0.3), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, MBCartVect(1,1,0.3), MBCartVect(1,1,1) ) );
   
     // box edge parallel to y at +x,+z passes through triangle
   coords[0] = MBCartVect( 1.0, 1.0, 3.0);
   coords[1] = MBCartVect( 3.0, 1.0, 3.0);
   coords[2] = MBCartVect( 3.0, 1.0, 1.0);
-  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(1.5,1,1.5), MBCartVect(1,1,1) ) );
+  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,1,0.3), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, MBCartVect(1,1,0.3), MBCartVect(1,1,1) ) );
   
     // box edge parallel to y at -x,+z passes through triangle
   coords[0] = MBCartVect( 1.0, 1.0, 3.0);
   coords[1] = MBCartVect(-1.0, 1.0, 3.0);
   coords[2] = MBCartVect(-1.0, 1.0, 1.0);
-  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(0.5,1,1.5), MBCartVect(1,1,1) ) );
+  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,1,0.3), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, MBCartVect(1,1,0.3), MBCartVect(1,1,1) ) );
   
     // box edge parallel to y at +x,-z passes through triangle
   coords[0] = MBCartVect( 1.0, 1.0,-1.0);
   coords[1] = MBCartVect( 3.0, 1.0,-1.0);
   coords[2] = MBCartVect( 3.0, 1.0, 1.0);
-  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(1.5,1,0.5), MBCartVect(1,1,1) ) );
+  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,1,1.7), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, MBCartVect(1,1,1.7), MBCartVect(1,1,1) ) );
   
     // box edge parallel to y at -x,-z passes through triangle
   coords[0] = MBCartVect( 1.0, 1.0,-1.0);
   coords[1] = MBCartVect(-1.0, 1.0,-1.0);
   coords[2] = MBCartVect(-1.0, 1.0, 1.0);
-  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(0.5,1,0.5), MBCartVect(1,1,1) ) );
+  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,1,1.7), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, MBCartVect(1,1,1.7), MBCartVect(1,1,1) ) );
   
     // box edge parallel to z at +x,+y passes through triangle
   coords[0] = MBCartVect( 1.0, 3.0, 1.0);
   coords[1] = MBCartVect( 3.0, 3.0, 1.0);
   coords[2] = MBCartVect( 3.0, 1.0, 1.0);
-  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(1.5,1.5,1), MBCartVect(1,1,1) ) );
+  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !box_linear_elem_overlap( coords, MBTRI, MBCartVect(0.3,1,1), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, MBCartVect(0.3,1,1), MBCartVect(1,1,1) ) );
   
     // box edge parallel to z at +x,-y passes through triangle
   coords[0] = MBCartVect( 1.0,-1.0, 1.0);
   coords[1] = MBCartVect( 3.0,-1.0, 1.0);
   coords[2] = MBCartVect( 3.0, 1.0, 1.0);
-  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(1.5,0.5,1), MBCartVect(1,1,1) ) );
+  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !box_linear_elem_overlap( coords, MBTRI, MBCartVect(0.3,1,1), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, MBCartVect(0.3,1,1), MBCartVect(1,1,1) ) );
   
     // box edge parallel to z at -x,+y passes through triangle
   coords[0] = MBCartVect( 1.0, 3.0, 1.0);
   coords[1] = MBCartVect(-1.0, 3.0, 1.0);
   coords[2] = MBCartVect(-1.0, 1.0, 1.0);
-  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(0.5,1.5,1), MBCartVect(1,1,1) ) );
+  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !box_linear_elem_overlap( coords, MBTRI, MBCartVect(1.7,1,1), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, MBCartVect(1.7,1,1), MBCartVect(1,1,1) ) );
   
     // box edge parallel to z at -x,-y passes through triangle
   coords[0] = MBCartVect( 1.0,-1.0, 1.0);
   coords[1] = MBCartVect(-1.0,-1.0, 1.0);
   coords[2] = MBCartVect(-1.0, 1.0, 1.0);
-  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(0.5,0.5,1), MBCartVect(1,1,1) ) );
+  ASSERT(  overlap( coords, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !box_linear_elem_overlap( coords, MBTRI, MBCartVect(1.7,1,1), MBCartVect(1,1,1) ) );
+  ASSERT( !overlap( coords, MBCartVect(1.7,1,1), MBCartVect(1,1,1) ) );
   
     // triangle penetrates +x face
   coords[0] = MBCartVect( 2.0, 2.0, 2.0 );
   coords[1] = MBCartVect( 5.0, 3.0, 2.0 );
   coords[2] = MBCartVect( 5.0, 1.0, 2.0 );
-  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
+  ASSERT(  overlap( coords, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
     // test with tri outside box
-  ASSERT( !box_linear_elem_overlap( coords, MBTRI, MBCartVect(-1,2,2), MBCartVect(2,2,2) ) );
+  ASSERT( !overlap( coords, MBCartVect(-1,2,2), MBCartVect(2,2,2) ) );
   
     // triangle penetrates -x face
   coords[0] = MBCartVect( 2.0, 2.0, 2.0 );
   coords[1] = MBCartVect(-1.0, 3.0, 2.0 );
   coords[2] = MBCartVect(-1.0, 1.0, 2.0 );
-  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
+  ASSERT(  overlap( coords, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
     // test with tri outside box
-  ASSERT( !box_linear_elem_overlap( coords, MBTRI, MBCartVect(5,2,2), MBCartVect(2,2,2) ) );
+  ASSERT( !overlap( coords, MBCartVect(5,2,2), MBCartVect(2,2,2) ) );
   
     // triangle penetrates +y face
   coords[0] = MBCartVect( 2.0, 2.0, 2.0 );
   coords[1] = MBCartVect( 3.0, 5.0, 2.0 );
   coords[2] = MBCartVect( 1.0, 5.0, 2.0 );
-  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
+  ASSERT(  overlap( coords, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
     // test with tri outside box
-  ASSERT( !box_linear_elem_overlap( coords, MBTRI, MBCartVect(2,-1,2), MBCartVect(2,2,2) ) );
+  ASSERT( !overlap( coords, MBCartVect(2,-1,2), MBCartVect(2,2,2) ) );
   
     // triangle penetrates -y face
   coords[0] = MBCartVect( 2.0, 2.0, 2.0 );
   coords[1] = MBCartVect( 3.0,-1.0, 2.0 );
   coords[2] = MBCartVect( 1.0,-1.0, 2.0 );
-  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
+  ASSERT(  overlap( coords, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
     // test with tri outside box
-  ASSERT( !box_linear_elem_overlap( coords, MBTRI, MBCartVect(2,5,2), MBCartVect(2,2,2) ) );
+  ASSERT( !overlap( coords, MBCartVect(2,5,2), MBCartVect(2,2,2) ) );
   
     // triangle penetrates +z face
   coords[0] = MBCartVect( 2.0, 2.0, 2.0 );
   coords[1] = MBCartVect( 2.0, 3.0, 5.0 );
   coords[2] = MBCartVect( 2.0, 1.0, 5.0 );
-  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
+  ASSERT(  overlap( coords, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
     // test with tri outside box
-  ASSERT( !box_linear_elem_overlap( coords, MBTRI, MBCartVect(2,2,-1), MBCartVect(2,2,2) ) );
+  ASSERT( !overlap( coords, MBCartVect(2,2,-1), MBCartVect(2,2,2) ) );
   
     // triangle penetrates -z face
   coords[0] = MBCartVect( 2.0, 2.0, 2.0 );
   coords[1] = MBCartVect( 2.0, 3.0,-1.0 );
   coords[2] = MBCartVect( 2.0, 1.0,-1.0 );
-  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
+  ASSERT(  overlap( coords, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
     // test with tri outside box
-  ASSERT( !box_linear_elem_overlap( coords, MBTRI, MBCartVect(2,2,5), MBCartVect(2,2,2) ) );
+  ASSERT( !overlap( coords, MBCartVect(2,2,5), MBCartVect(2,2,2) ) );
 }
 
-void test_box_linear_elem_overlap_hex()
+void general_box_hex_overlap_test( const ElemOverlapTest& overlap )
 {
   MBCartVect coords[8];
 
@@ -609,65 +396,65 @@
   coords[6] = MBCartVect( 0.5, 0.5, 0.5);
   coords[7] = MBCartVect(-0.5, 0.5, 0.5);
 
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect( 0, 0, 0), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, MBCartVect( 0, 0, 0), MBCartVect(1,1,1) ) );
 
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect( 1, 0, 0), MBCartVect(1,1,1) ) );
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect( 0, 1, 0), MBCartVect(1,1,1) ) );
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect( 0, 0, 1), MBCartVect(1,1,1) ) );
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect(-1, 0, 0), MBCartVect(1,1,1) ) );
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect( 0,-1, 0), MBCartVect(1,1,1) ) );
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect( 0, 0,-1), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, MBCartVect( 1, 0, 0), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, MBCartVect( 0, 1, 0), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, MBCartVect( 0, 0, 1), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, MBCartVect(-1, 0, 0), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, MBCartVect( 0,-1, 0), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, MBCartVect( 0, 0,-1), MBCartVect(1,1,1) ) );
 
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect( 1, 1, 0), MBCartVect(1,1,1) ) );
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect(-1, 1, 0), MBCartVect(1,1,1) ) );
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect(-1,-1, 0), MBCartVect(1,1,1) ) );
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect( 1,-1, 0), MBCartVect(1,1,1) ) );
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect( 1, 0, 1), MBCartVect(1,1,1) ) );
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect(-1, 0, 1), MBCartVect(1,1,1) ) );
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect(-1, 0,-1), MBCartVect(1,1,1) ) );
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect( 1, 0,-1), MBCartVect(1,1,1) ) );
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect( 0, 1, 1), MBCartVect(1,1,1) ) );
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect( 0,-1, 1), MBCartVect(1,1,1) ) );
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect( 0,-1,-1), MBCartVect(1,1,1) ) );
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect( 0, 1,-1), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, MBCartVect( 1, 1, 0), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, MBCartVect(-1, 1, 0), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, MBCartVect(-1,-1, 0), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, MBCartVect( 1,-1, 0), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, MBCartVect( 1, 0, 1), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, MBCartVect(-1, 0, 1), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, MBCartVect(-1, 0,-1), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, MBCartVect( 1, 0,-1), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, MBCartVect( 0, 1, 1), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, MBCartVect( 0,-1, 1), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, MBCartVect( 0,-1,-1), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, MBCartVect( 0, 1,-1), MBCartVect(1,1,1) ) );
 
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect( 1, 1, 1), MBCartVect(1,1,1) ) );
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect(-1, 1, 1), MBCartVect(1,1,1) ) );
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect(-1,-1, 1), MBCartVect(1,1,1) ) );
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect( 1,-1, 1), MBCartVect(1,1,1) ) );
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect( 1, 1,-1), MBCartVect(1,1,1) ) );
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect(-1, 1,-1), MBCartVect(1,1,1) ) );
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect(-1,-1,-1), MBCartVect(1,1,1) ) );
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect( 1,-1,-1), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, MBCartVect( 1, 1, 1), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, MBCartVect(-1, 1, 1), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, MBCartVect(-1,-1, 1), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, MBCartVect( 1,-1, 1), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, MBCartVect( 1, 1,-1), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, MBCartVect(-1, 1,-1), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, MBCartVect(-1,-1,-1), MBCartVect(1,1,1) ) );
+  ASSERT( overlap( coords, MBCartVect( 1,-1,-1), MBCartVect(1,1,1) ) );
 
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect( 3, 0, 0), MBCartVect(1,1,1) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect( 0, 3, 0), MBCartVect(1,1,1) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect( 0, 0, 3), MBCartVect(1,1,1) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect(-3, 0, 0), MBCartVect(1,1,1) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect( 0,-3, 0), MBCartVect(1,1,1) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect( 0, 0,-3), MBCartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, MBCartVect( 3, 0, 0), MBCartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, MBCartVect( 0, 3, 0), MBCartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, MBCartVect( 0, 0, 3), MBCartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, MBCartVect(-3, 0, 0), MBCartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, MBCartVect( 0,-3, 0), MBCartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, MBCartVect( 0, 0,-3), MBCartVect(1,1,1) ) );
 
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect( 3, 3, 0), MBCartVect(1,1,1) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect(-3, 3, 0), MBCartVect(1,1,1) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect(-3,-3, 0), MBCartVect(1,1,1) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect( 3,-3, 0), MBCartVect(1,1,1) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect( 3, 0, 3), MBCartVect(1,1,1) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect(-3, 0, 3), MBCartVect(1,1,1) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect(-3, 0,-3), MBCartVect(1,1,1) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect( 3, 0,-3), MBCartVect(1,1,1) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect( 0, 3, 3), MBCartVect(1,1,1) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect( 0,-3, 3), MBCartVect(1,1,1) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect( 0,-3,-3), MBCartVect(1,1,1) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect( 0, 3,-3), MBCartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, MBCartVect( 3, 3, 0), MBCartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, MBCartVect(-3, 3, 0), MBCartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, MBCartVect(-3,-3, 0), MBCartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, MBCartVect( 3,-3, 0), MBCartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, MBCartVect( 3, 0, 3), MBCartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, MBCartVect(-3, 0, 3), MBCartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, MBCartVect(-3, 0,-3), MBCartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, MBCartVect( 3, 0,-3), MBCartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, MBCartVect( 0, 3, 3), MBCartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, MBCartVect( 0,-3, 3), MBCartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, MBCartVect( 0,-3,-3), MBCartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, MBCartVect( 0, 3,-3), MBCartVect(1,1,1) ) );
 
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect( 3, 3, 3), MBCartVect(1,1,1) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect(-3, 3, 3), MBCartVect(1,1,1) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect(-3,-3, 3), MBCartVect(1,1,1) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect( 3,-3, 3), MBCartVect(1,1,1) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect( 3, 3,-3), MBCartVect(1,1,1) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect(-3, 3,-3), MBCartVect(1,1,1) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect(-3,-3,-3), MBCartVect(1,1,1) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect( 3,-3,-3), MBCartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, MBCartVect( 3, 3, 3), MBCartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, MBCartVect(-3, 3, 3), MBCartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, MBCartVect(-3,-3, 3), MBCartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, MBCartVect( 3,-3, 3), MBCartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, MBCartVect( 3, 3,-3), MBCartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, MBCartVect(-3, 3,-3), MBCartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, MBCartVect(-3,-3,-3), MBCartVect(1,1,1) ) );
+  ASSERT(!overlap( coords, MBCartVect( 3,-3,-3), MBCartVect(1,1,1) ) );
 
     // test against rectilinear hex rotated 45 degrees about z axis
   const double r = sqrt(2.0)/2.0;
@@ -680,143 +467,309 @@
   coords[6] = MBCartVect(-r, 0, 0.5);
   coords[7] = MBCartVect( 0,-r, 0.5);
 
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect( 1, 0, 0 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect(-1, 0, 0 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect( 0, 1, 0 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect( 0,-1, 0 ), MBCartVect(0.5,0.5,0.5) ) );
+  ASSERT( overlap( coords, MBCartVect( 1, 0, 0 ), MBCartVect(0.5,0.5,0.5) ) );
+  ASSERT( overlap( coords, MBCartVect(-1, 0, 0 ), MBCartVect(0.5,0.5,0.5) ) );
+  ASSERT( overlap( coords, MBCartVect( 0, 1, 0 ), MBCartVect(0.5,0.5,0.5) ) );
+  ASSERT( overlap( coords, MBCartVect( 0,-1, 0 ), MBCartVect(0.5,0.5,0.5) ) );
 
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect( 1, 0, 2 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect(-1, 0, 2 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect( 0, 1, 2 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect( 0,-1, 2 ), MBCartVect(0.5,0.5,0.5) ) );
+  ASSERT(!overlap( coords, MBCartVect( 1, 0, 2 ), MBCartVect(0.5,0.5,0.5) ) );
+  ASSERT(!overlap( coords, MBCartVect(-1, 0, 2 ), MBCartVect(0.5,0.5,0.5) ) );
+  ASSERT(!overlap( coords, MBCartVect( 0, 1, 2 ), MBCartVect(0.5,0.5,0.5) ) );
+  ASSERT(!overlap( coords, MBCartVect( 0,-1, 2 ), MBCartVect(0.5,0.5,0.5) ) );
 
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect( 2, 0, 0 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect(-2, 0, 0 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect( 0, 2, 0 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect( 0,-2, 0 ), MBCartVect(0.5,0.5,0.5) ) );
+  ASSERT(!overlap( coords, MBCartVect( 2, 0, 0 ), MBCartVect(0.5,0.5,0.5) ) );
+  ASSERT(!overlap( coords, MBCartVect(-2, 0, 0 ), MBCartVect(0.5,0.5,0.5) ) );
+  ASSERT(!overlap( coords, MBCartVect( 0, 2, 0 ), MBCartVect(0.5,0.5,0.5) ) );
+  ASSERT(!overlap( coords, MBCartVect( 0,-2, 0 ), MBCartVect(0.5,0.5,0.5) ) );
 
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect( 1, 1, 0 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect(-1, 1, 0 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect(-1,-1, 0 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT(!box_linear_elem_overlap( coords, MBHEX, MBCartVect( 1,-1, 0 ), MBCartVect(0.5,0.5,0.5) ) );
+  ASSERT(!overlap( coords, MBCartVect( 1, 1, 0 ), MBCartVect(0.5,0.5,0.5) ) );
+  ASSERT(!overlap( coords, MBCartVect(-1, 1, 0 ), MBCartVect(0.5,0.5,0.5) ) );
+  ASSERT(!overlap( coords, MBCartVect(-1,-1, 0 ), MBCartVect(0.5,0.5,0.5) ) );
+  ASSERT(!overlap( coords, MBCartVect( 1,-1, 0 ), MBCartVect(0.5,0.5,0.5) ) );
 
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect( 1, 1, 0 ), MBCartVect(0.75,0.75,0.5) ) );
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect(-1, 1, 0 ), MBCartVect(0.75,0.75,0.5) ) );
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect(-1,-1, 0 ), MBCartVect(0.75,0.75,0.5) ) );
-  ASSERT( box_linear_elem_overlap( coords, MBHEX, MBCartVect( 1,-1, 0 ), MBCartVect(0.75,0.75,0.5) ) );
+  ASSERT( overlap( coords, MBCartVect( 1, 1, 0 ), MBCartVect(0.75,0.75,0.5) ) );
+  ASSERT( overlap( coords, MBCartVect(-1, 1, 0 ), MBCartVect(0.75,0.75,0.5) ) );
+  ASSERT( overlap( coords, MBCartVect(-1,-1, 0 ), MBCartVect(0.75,0.75,0.5) ) );
+  ASSERT( overlap( coords, MBCartVect( 1,-1, 0 ), MBCartVect(0.75,0.75,0.5) ) );
 }
 
-void test_box_hex_overlap()
+void general_box_tet_overlap_test( const ElemOverlapTest& overlap )
 {
-  MBCartVect coords[8];
+  MBCartVect coords[4];
+  
+    // Octant I
+  coords[0] = MBCartVect(0,0,0);
+  coords[1] = MBCartVect(1,0,0);
+  coords[2] = MBCartVect(0,1,0);
+  coords[3] = MBCartVect(0,0,1);
+    // tet entirely within box
+  ASSERT( overlap( coords, MBCartVect(-1,-1,-1), MBCartVect(3,3,3) ) );
+    // box entirely within tet
+  ASSERT( overlap( coords, MBCartVect(0.2,0.2,0.2), MBCartVect(0.1,0.1,0.1) ) );
+    // box corner penetrates tet face
+  ASSERT( overlap( coords, MBCartVect(0.5,0.5,0.5), MBCartVect(0.2,0.2,0.2) ) );
+    // box corner does not penetrate face
+  ASSERT( !overlap( coords, MBCartVect(0.5,0.5,0.5), MBCartVect(0.15,0.15,0.15) ) );
+  
+    // Octant II
+  coords[0] = MBCartVect(0,1,0);
+  coords[1] = MBCartVect(-1,0,0);
+  coords[2] = MBCartVect(0,0,0);
+  coords[3] = MBCartVect(0,0,1);
+    // tet entirely within box
+  ASSERT( overlap( coords, MBCartVect( 1,-1,-1), MBCartVect(3,3,3) ) );
+    // box entirely within tet
+  ASSERT( overlap( coords, MBCartVect(-0.2,0.2,0.2), MBCartVect(0.1,0.1,0.1) ) );
+    // box corner penetrates tet face
+  ASSERT( overlap( coords, MBCartVect(-0.5,0.5,0.5), MBCartVect(0.2,0.2,0.2) ) );
+    // box corner does not penetrate face
+  ASSERT( !overlap( coords, MBCartVect(-0.5,0.5,0.5), MBCartVect(0.15,0.15,0.15) ) );
+  
+    // Octant III
+  coords[0] = MBCartVect(0,-1,0);
+  coords[1] = MBCartVect(0,0,0);
+  coords[2] = MBCartVect(-1,0,0);
+  coords[3] = MBCartVect(0,0,1);
+    // tet entirely within box
+  ASSERT( overlap( coords, MBCartVect( 1, 1,-1), MBCartVect(3,3,3) ) );
+    // box entirely within tet
+  ASSERT( overlap( coords, MBCartVect(-0.2,-0.2,0.2), MBCartVect(0.1,0.1,0.1) ) );
+    // box corner penetrates tet face
+  ASSERT( overlap( coords, MBCartVect(-0.5,-0.5,0.5), MBCartVect(0.2,0.2,0.2) ) );
+    // box corner does not penetrate face
+  ASSERT( !overlap( coords, MBCartVect(-0.5,-0.5,0.5), MBCartVect(0.15,0.15,0.15) ) );
+  
+    // Octant IV
+  coords[0] = MBCartVect(1,0,0);
+  coords[1] = MBCartVect(0,-1,0);
+  coords[2] = MBCartVect(0,0,1);
+  coords[3] = MBCartVect(0,0,0);
+    // tet entirely within box
+  ASSERT( overlap( coords, MBCartVect(-1, 1,-1), MBCartVect(3,3,3) ) );
+    // box entirely within tet
+  ASSERT( overlap( coords, MBCartVect(0.2,-0.2,0.2), MBCartVect(0.1,0.1,0.1) ) );
+    // box corner penetrates tet face
+  ASSERT( overlap( coords, MBCartVect(0.5,-0.5,0.5), MBCartVect(0.2,0.2,0.2) ) );
+    // box corner does not penetrate face
+  ASSERT( !overlap( coords, MBCartVect(0.5,-0.5,0.5), MBCartVect(0.15,0.15,0.15) ) );
+   
+    // Octant V
+  coords[0] = MBCartVect(0,0,0);
+  coords[1] = MBCartVect(0,1,0);
+  coords[2] = MBCartVect(1,0,0);
+  coords[3] = MBCartVect(0,0,-1);
+    // tet entirely within box
+  ASSERT( overlap( coords, MBCartVect(-1,-1, 1), MBCartVect(3,3,3) ) );
+    // box entirely within tet
+  ASSERT( overlap( coords, MBCartVect(0.2,0.2,-0.2), MBCartVect(0.1,0.1,0.1) ) );
+    // box corner penetrates tet face
+  ASSERT( overlap( coords, MBCartVect(0.5,0.5,-0.5), MBCartVect(0.2,0.2,0.2) ) );
+    // box corner does not penetrate face
+  ASSERT( !overlap( coords, MBCartVect(0.5,0.5,-0.5), MBCartVect(0.15,0.15,0.15) ) );
+  
+    // Octant VI
+  coords[0] = MBCartVect(-1,0,0);
+  coords[1] = MBCartVect(0,1,0);
+  coords[2] = MBCartVect(0,0,0);
+  coords[3] = MBCartVect(0,0,-1);
+    // tet entirely within box
+  ASSERT( overlap( coords, MBCartVect( 1,-1, 1), MBCartVect(3,3,3) ) );
+    // box entirely within tet
+  ASSERT( overlap( coords, MBCartVect(-0.2,0.2,-0.2), MBCartVect(0.1,0.1,0.1) ) );
+    // box corner penetrates tet face
+  ASSERT( overlap( coords, MBCartVect(-0.5,0.5,-0.5), MBCartVect(0.2,0.2,0.2) ) );
+    // box corner does not penetrate face
+  ASSERT( !overlap( coords, MBCartVect(-0.5,0.5,-0.5), MBCartVect(0.15,0.15,0.15) ) );
+  
+    // Octant VII
+  coords[0] = MBCartVect(0,0,0);
+  coords[1] = MBCartVect(0,-1,0);
+  coords[2] = MBCartVect(-1,0,0);
+  coords[3] = MBCartVect(0,0,-1);
+    // tet entirely within box
+  ASSERT( overlap( coords, MBCartVect( 1, 1, 1), MBCartVect(3,3,3) ) );
+    // box entirely within tet
+  ASSERT( overlap( coords, MBCartVect(-0.2,-0.2,-0.2), MBCartVect(0.1,0.1,0.1) ) );
+    // box corner penetrates tet face
+  ASSERT( overlap( coords, MBCartVect(-0.5,-0.5,-0.5), MBCartVect(0.2,0.2,0.2) ) );
+    // box corner does not penetrate face
+  ASSERT( !overlap( coords, MBCartVect(-0.5,-0.5,-0.5), MBCartVect(0.15,0.15,0.15) ) );
+  
+    // Octant VIII
+  coords[0] = MBCartVect(0,-1,0);
+  coords[1] = MBCartVect(1,0,0);
+  coords[2] = MBCartVect(0,0,-1);
+  coords[3] = MBCartVect(0,0,0);
+    // tet entirely within box
+  ASSERT( overlap( coords, MBCartVect(-1, 1, 1), MBCartVect(3,3,3) ) );
+    // box entirely within tet
+  ASSERT( overlap( coords, MBCartVect(0.2,-0.2,-0.2), MBCartVect(0.1,0.1,0.1) ) );
+    // box corner penetrates tet face
+  ASSERT( overlap( coords, MBCartVect(0.5,-0.5,-0.5), MBCartVect(0.2,0.2,0.2) ) );
+    // box corner does not penetrate face
+  ASSERT( !overlap( coords, MBCartVect(0.5,-0.5,-0.5), MBCartVect(0.15,0.15,0.15) ) );
+ 
+  
+    // Box edge -x,-z
+  coords[0] = MBCartVect( 0, 0, 0);
+  coords[1] = MBCartVect( 2,-1, 0);
+  coords[2] = MBCartVect( 2, 1, 0);
+  coords[3] = MBCartVect( 0, 0, 2);
+    // box edge passes through tet
+  ASSERT( overlap( coords, MBCartVect(1.5,0.0,1.5), MBCartVect(1,1,1) ) );
+    // box edge does not pass through tet
+  ASSERT( !overlap( coords, MBCartVect(2.5,0.0,2.5), MBCartVect(1,1,1) ) );
+  
+    // Box edge -y,-z
+  coords[0] = MBCartVect( 1, 2, 0);
+  coords[1] = MBCartVect(-1, 2, 0);
+  coords[2] = MBCartVect( 0, 0, 0);
+  coords[3] = MBCartVect( 0, 0, 2);
+    // box edge passes through tet
+  ASSERT( overlap( coords, MBCartVect(0.0,1.5,1.5), MBCartVect(1,1,1) ) );
+    // box edge does not pass through tet
+  ASSERT( !overlap( coords, MBCartVect(0.0,2.5,2.5), MBCartVect(1,1,1) ) );
+  
+    // Box edge +x,-z
+  coords[0] = MBCartVect(-2,-1, 0);
+  coords[1] = MBCartVect(-2, 1, 0);
+  coords[2] = MBCartVect( 0, 0, 2);
+  coords[3] = MBCartVect( 0, 0, 0);
+    // box edge passes through tet
+  ASSERT( overlap( coords, MBCartVect(-1.5,0.0,1.5), MBCartVect(1,1,1) ) );
+    // box edge does not pass through tet
+  ASSERT( !overlap( coords, MBCartVect(-2.5,0.0,2.5), MBCartVect(1,1,1) ) );
+  
+    // Box edge +y,-z
+  coords[0] = MBCartVect( 2,-1, 0);
+  coords[1] = MBCartVect( 0, 0, 0);
+  coords[2] = MBCartVect(-2,-1, 0);
+  coords[3] = MBCartVect( 0, 0, 2);
+    // box edge passes through tet
+  ASSERT( overlap( coords, MBCartVect(0.0,-1.5,1.5), MBCartVect(1,1,1) ) );
+    // box edge does not pass through tet
+  ASSERT( !overlap( coords, MBCartVect(0.0,-2.5,2.5), MBCartVect(1,1,1) ) );
+  
+    // Box edge -x,+z
+  coords[0] = MBCartVect( 2,-1, 0);
+  coords[1] = MBCartVect( 0, 0, 0);
+  coords[2] = MBCartVect( 2, 1, 0);
+  coords[3] = MBCartVect( 0, 0,-2);
+    // box edge passes through tet
+  ASSERT( overlap( coords, MBCartVect(1.5,0.0,-1.5), MBCartVect(1,1,1) ) );
+    // box edge does not pass through tet
+  ASSERT( !overlap( coords, MBCartVect(2.5,0.0,-2.5), MBCartVect(1,1,1) ) );
+  
+    // Box edge -y,+z
+  coords[0] = MBCartVect(-1, 2, 0);
+  coords[1] = MBCartVect( 1, 2, 0);
+  coords[2] = MBCartVect( 0, 0, 0);
+  coords[3] = MBCartVect( 0, 0,-2);
+    // box edge passes through tet
+  ASSERT( overlap( coords, MBCartVect(0.0,1.5,-1.5), MBCartVect(1,1,1) ) );
+    // box edge does not pass through tet
+  ASSERT( !overlap( coords, MBCartVect(0.0,2.5,-2.5), MBCartVect(1,1,1) ) );
+  
+    // Box edge +x,+z
+  coords[0] = MBCartVect(-2, 1, 0);
+  coords[1] = MBCartVect(-2,-1, 0);
+  coords[2] = MBCartVect( 0, 0,-2);
+  coords[3] = MBCartVect( 0, 0, 0);
+    // box edge passes through tet
+  ASSERT( overlap( coords, MBCartVect(-1.5,0.0,-1.5), MBCartVect(1,1,1) ) );
+    // box edge does not pass through tet
+  ASSERT( !overlap( coords, MBCartVect(-2.5,0.0,-2.5), MBCartVect(1,1,1) ) );
+  
+    // Box edge +y,+z
+  coords[0] = MBCartVect( 0, 0, 0);
+  coords[1] = MBCartVect( 2,-1, 0);
+  coords[2] = MBCartVect(-2,-1, 0);
+  coords[3] = MBCartVect( 0, 0,-2);
+    // box edge passes through tet
+  ASSERT( overlap( coords, MBCartVect(0.0,-1.5,-1.5), MBCartVect(1,1,1) ) );
+    // box edge does not pass through tet
+  ASSERT( !overlap( coords, MBCartVect(0.0,-2.5,-2.5), MBCartVect(1,1,1) ) );
+    
+    // Box edge -x,-y
+  coords[0] = MBCartVect( 0, 0, 0);
+  coords[1] = MBCartVect( 0, 2,-1);
+  coords[2] = MBCartVect( 0, 2, 1);
+  coords[3] = MBCartVect( 2, 0, 0);
+    // box edge passes through tet
+  ASSERT( overlap( coords, MBCartVect(1.5,1.5,0.0), MBCartVect(1,1,1) ) );
+    // box edge does not pass through tet
+  ASSERT( !overlap( coords, MBCartVect(2.5,2.5,0.0), MBCartVect(1,1,1) ) );
+    
+    // Box edge +x,-y
+  coords[0] = MBCartVect( 0, 2,-1);
+  coords[1] = MBCartVect( 0, 0, 0);
+  coords[2] = MBCartVect( 0, 2, 1);
+  coords[3] = MBCartVect(-2, 0, 0);
+    // box edge passes through tet
+  ASSERT( overlap( coords, MBCartVect(-1.5,1.5,0.0), MBCartVect(1,1,1) ) );
+    // box edge does not pass through tet
+  ASSERT( !overlap( coords, MBCartVect(-2.5,2.5,0.0), MBCartVect(1,1,1) ) );
+    
+    // Box edge -x,+y
+  coords[0] = MBCartVect( 0,-2, 1);
+  coords[1] = MBCartVect( 0,-2,-1);
+  coords[2] = MBCartVect( 0, 0, 0);
+  coords[3] = MBCartVect( 2, 0, 0);
+    // box edge passes through tet
+  ASSERT( overlap( coords, MBCartVect(1.5,-1.5,0.0), MBCartVect(1,1,1) ) );
+    // box edge does not pass through tet
+  ASSERT( !overlap( coords, MBCartVect(2.5,-2.5,0.0), MBCartVect(1,1,1) ) );
+    
+    // Box edge +x,+y
+  coords[0] = MBCartVect( 0,-2,-1);
+  coords[1] = MBCartVect(-2, 0, 0);
+  coords[2] = MBCartVect( 0,-2, 1);
+  coords[3] = MBCartVect( 0, 0, 0);
+    // box edge passes through tet
+  ASSERT( overlap( coords, MBCartVect(-1.5,-1.5,0.0), MBCartVect(1,1,1) ) );
+    // box edge does not pass through tet
+  ASSERT( !overlap( coords, MBCartVect(-2.5,-2.5,0.0), MBCartVect(1,1,1) ) );
+  
+  
+    // Test tet edge through box 
+  coords[0] = MBCartVect( -0.13369421660900116, -2.9871494770050049,  0.0526076555252075 );
+  coords[1] = MBCartVect( -0.00350524857640266, -3.3236153125762939,  0.2924639880657196 );
+  coords[2] = MBCartVect(  0.16473215818405151, -2.9966945648193359, -0.1936169415712357 );
+  coords[3] = MBCartVect(  0.26740345358848572, -2.8492588996887207,  0.1519143134355545 );
+  ASSERT( overlap( coords, MBCartVect( -2.5, -2.8, -2.5 ), MBCartVect( 2.5, 0.31, 2.5 ) ) );
+}
 
-    // test against axis-aligned rectilinear hex
-  coords[0] = MBCartVect(-0.5,-0.5,-0.5);
-  coords[1] = MBCartVect( 0.5,-0.5,-0.5);
-  coords[2] = MBCartVect( 0.5, 0.5,-0.5);
-  coords[3] = MBCartVect(-0.5, 0.5,-0.5);
-  coords[4] = MBCartVect(-0.5,-0.5, 0.5);
-  coords[5] = MBCartVect( 0.5,-0.5, 0.5);
-  coords[6] = MBCartVect( 0.5, 0.5, 0.5);
-  coords[7] = MBCartVect(-0.5, 0.5, 0.5);
+void test_box_tri_overlap()
+{
+  general_box_tri_overlap_test( TypeElemOverlapTest(&box_tri_overlap) );
+}
 
-  ASSERT( box_hex_overlap( coords, MBCartVect( 0, 0, 0), MBCartVect(1,1,1) ) );
+void test_box_linear_elem_overlap_tri()
+{
+  general_box_tri_overlap_test( LinearElemOverlapTest(MBTRI) );
+}
 
-  ASSERT( box_hex_overlap( coords, MBCartVect( 1, 0, 0), MBCartVect(1,1,1) ) );
-  ASSERT( box_hex_overlap( coords, MBCartVect( 0, 1, 0), MBCartVect(1,1,1) ) );
-  ASSERT( box_hex_overlap( coords, MBCartVect( 0, 0, 1), MBCartVect(1,1,1) ) );
-  ASSERT( box_hex_overlap( coords, MBCartVect(-1, 0, 0), MBCartVect(1,1,1) ) );
-  ASSERT( box_hex_overlap( coords, MBCartVect( 0,-1, 0), MBCartVect(1,1,1) ) );
-  ASSERT( box_hex_overlap( coords, MBCartVect( 0, 0,-1), MBCartVect(1,1,1) ) );
+void test_box_hex_overlap()
+{
+  general_box_hex_overlap_test( TypeElemOverlapTest(&box_hex_overlap) );
+}
 
-  ASSERT( box_hex_overlap( coords, MBCartVect( 1, 1, 0), MBCartVect(1,1,1) ) );
-  ASSERT( box_hex_overlap( coords, MBCartVect(-1, 1, 0), MBCartVect(1,1,1) ) );
-  ASSERT( box_hex_overlap( coords, MBCartVect(-1,-1, 0), MBCartVect(1,1,1) ) );
-  ASSERT( box_hex_overlap( coords, MBCartVect( 1,-1, 0), MBCartVect(1,1,1) ) );
-  ASSERT( box_hex_overlap( coords, MBCartVect( 1, 0, 1), MBCartVect(1,1,1) ) );
-  ASSERT( box_hex_overlap( coords, MBCartVect(-1, 0, 1), MBCartVect(1,1,1) ) );
-  ASSERT( box_hex_overlap( coords, MBCartVect(-1, 0,-1), MBCartVect(1,1,1) ) );
-  ASSERT( box_hex_overlap( coords, MBCartVect( 1, 0,-1), MBCartVect(1,1,1) ) );
-  ASSERT( box_hex_overlap( coords, MBCartVect( 0, 1, 1), MBCartVect(1,1,1) ) );
-  ASSERT( box_hex_overlap( coords, MBCartVect( 0,-1, 1), MBCartVect(1,1,1) ) );
-  ASSERT( box_hex_overlap( coords, MBCartVect( 0,-1,-1), MBCartVect(1,1,1) ) );
-  ASSERT( box_hex_overlap( coords, MBCartVect( 0, 1,-1), MBCartVect(1,1,1) ) );
+void test_box_linear_elem_overlap_hex()
+{
+  general_box_hex_overlap_test( LinearElemOverlapTest(MBHEX) );
+}
 
-  ASSERT( box_hex_overlap( coords, MBCartVect( 1, 1, 1), MBCartVect(1,1,1) ) );
-  ASSERT( box_hex_overlap( coords, MBCartVect(-1, 1, 1), MBCartVect(1,1,1) ) );
-  ASSERT( box_hex_overlap( coords, MBCartVect(-1,-1, 1), MBCartVect(1,1,1) ) );
-  ASSERT( box_hex_overlap( coords, MBCartVect( 1,-1, 1), MBCartVect(1,1,1) ) );
-  ASSERT( box_hex_overlap( coords, MBCartVect( 1, 1,-1), MBCartVect(1,1,1) ) );
-  ASSERT( box_hex_overlap( coords, MBCartVect(-1, 1,-1), MBCartVect(1,1,1) ) );
-  ASSERT( box_hex_overlap( coords, MBCartVect(-1,-1,-1), MBCartVect(1,1,1) ) );
-  ASSERT( box_hex_overlap( coords, MBCartVect( 1,-1,-1), MBCartVect(1,1,1) ) );
+void test_box_tet_overlap()
+{
+  general_box_tet_overlap_test( TypeElemOverlapTest(&box_tet_overlap) );
+}
 
-  ASSERT(!box_hex_overlap( coords, MBCartVect( 3, 0, 0), MBCartVect(1,1,1) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect( 0, 3, 0), MBCartVect(1,1,1) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect( 0, 0, 3), MBCartVect(1,1,1) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect(-3, 0, 0), MBCartVect(1,1,1) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect( 0,-3, 0), MBCartVect(1,1,1) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect( 0, 0,-3), MBCartVect(1,1,1) ) );
-
-  ASSERT(!box_hex_overlap( coords, MBCartVect( 3, 3, 0), MBCartVect(1,1,1) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect(-3, 3, 0), MBCartVect(1,1,1) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect(-3,-3, 0), MBCartVect(1,1,1) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect( 3,-3, 0), MBCartVect(1,1,1) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect( 3, 0, 3), MBCartVect(1,1,1) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect(-3, 0, 3), MBCartVect(1,1,1) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect(-3, 0,-3), MBCartVect(1,1,1) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect( 3, 0,-3), MBCartVect(1,1,1) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect( 0, 3, 3), MBCartVect(1,1,1) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect( 0,-3, 3), MBCartVect(1,1,1) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect( 0,-3,-3), MBCartVect(1,1,1) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect( 0, 3,-3), MBCartVect(1,1,1) ) );
-
-  ASSERT(!box_hex_overlap( coords, MBCartVect( 3, 3, 3), MBCartVect(1,1,1) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect(-3, 3, 3), MBCartVect(1,1,1) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect(-3,-3, 3), MBCartVect(1,1,1) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect( 3,-3, 3), MBCartVect(1,1,1) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect( 3, 3,-3), MBCartVect(1,1,1) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect(-3, 3,-3), MBCartVect(1,1,1) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect(-3,-3,-3), MBCartVect(1,1,1) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect( 3,-3,-3), MBCartVect(1,1,1) ) );
-
-    // test against rectilinear hex rotated 45 degrees about z axis
-  const double r = sqrt(2.0)/2.0;
-  coords[0] = MBCartVect( r, 0,-0.5);
-  coords[1] = MBCartVect( 0, r,-0.5);
-  coords[2] = MBCartVect(-r, 0,-0.5);
-  coords[3] = MBCartVect( 0,-r,-0.5);
-  coords[4] = MBCartVect( r, 0, 0.5);
-  coords[5] = MBCartVect( 0, r, 0.5);
-  coords[6] = MBCartVect(-r, 0, 0.5);
-  coords[7] = MBCartVect( 0,-r, 0.5);
-
-  ASSERT( box_hex_overlap( coords, MBCartVect( 1, 0, 0 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT( box_hex_overlap( coords, MBCartVect(-1, 0, 0 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT( box_hex_overlap( coords, MBCartVect( 0, 1, 0 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT( box_hex_overlap( coords, MBCartVect( 0,-1, 0 ), MBCartVect(0.5,0.5,0.5) ) );
-
-  ASSERT(!box_hex_overlap( coords, MBCartVect( 1, 0, 2 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect(-1, 0, 2 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect( 0, 1, 2 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect( 0,-1, 2 ), MBCartVect(0.5,0.5,0.5) ) );
-
-  ASSERT(!box_hex_overlap( coords, MBCartVect( 2, 0, 0 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect(-2, 0, 0 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect( 0, 2, 0 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect( 0,-2, 0 ), MBCartVect(0.5,0.5,0.5) ) );
-
-  ASSERT(!box_hex_overlap( coords, MBCartVect( 1, 1, 0 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect(-1, 1, 0 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect(-1,-1, 0 ), MBCartVect(0.5,0.5,0.5) ) );
-  ASSERT(!box_hex_overlap( coords, MBCartVect( 1,-1, 0 ), MBCartVect(0.5,0.5,0.5) ) );
-
-  ASSERT( box_hex_overlap( coords, MBCartVect( 1, 1, 0 ), MBCartVect(0.75,0.75,0.5) ) );
-  ASSERT( box_hex_overlap( coords, MBCartVect(-1, 1, 0 ), MBCartVect(0.75,0.75,0.5) ) );
-  ASSERT( box_hex_overlap( coords, MBCartVect(-1,-1, 0 ), MBCartVect(0.75,0.75,0.5) ) );
-  ASSERT( box_hex_overlap( coords, MBCartVect( 1,-1, 0 ), MBCartVect(0.75,0.75,0.5) ) );
+void test_box_linear_elem_overlap_tet()
+{
+  general_box_tet_overlap_test( LinearElemOverlapTest(MBTET) );
 }
 
+
 void test_ray_tri_intersect()
 {
   bool xsect;
@@ -1242,10 +1195,12 @@
 {
   int error_count = 0;
   error_count += RUN_TEST(test_box_plane_overlap);
-  error_count += RUN_TEST(test_box_tri_overlap);
-  error_count += RUN_TEST(test_box_hex_overlap);
   error_count += RUN_TEST(test_box_linear_elem_overlap_tri);
+  error_count += RUN_TEST(test_box_linear_elem_overlap_tet);
   error_count += RUN_TEST(test_box_linear_elem_overlap_hex);
+  error_count += RUN_TEST(test_box_tri_overlap);
+  error_count += RUN_TEST(test_box_tet_overlap);
+  error_count += RUN_TEST(test_box_hex_overlap);
   error_count += RUN_TEST(test_ray_tri_intersect);
   error_count += RUN_TEST(test_closest_location_on_tri);
   error_count += RUN_TEST(test_closest_location_on_polygon);

Modified: MOAB/trunk/MBAdaptiveKDTree.cpp
===================================================================
--- MOAB/trunk/MBAdaptiveKDTree.cpp	2008-07-02 04:06:20 UTC (rev 1975)
+++ MOAB/trunk/MBAdaptiveKDTree.cpp	2008-07-03 14:56:52 UTC (rev 1976)
@@ -38,7 +38,7 @@
     maxTreeDepth(30),
     candidateSplitsPerDir(3),
     candidatePlaneSet(SUBDIVISION_SNAP),
-    minBoxWidth( std::numeric_limits<double>::epsilon() )
+    minBoxWidth( 1e-10 )
   {}
 
 
@@ -690,6 +690,7 @@
 static MBErrorCode intersect_children_with_elems( MBInterface* moab,
                                         const MBRange& elems,
                                         MBAdaptiveKDTree::Plane plane,
+                                        double eps,
                                         MBCartVect box_min,
                                         MBCartVect box_max,
                                         MBRange& left_tris,
@@ -705,14 +706,11 @@
     // get extents of boxes for left and right sides
   MBCartVect right_min( box_min ), left_max( box_max );
   right_min[plane.norm] = left_max[plane.norm] = plane.coord;
-  right_min *= 0.5;
-  left_max *= 0.5;
-  box_min *= 0.5;
-  box_max *= 0.5;
-  const MBCartVect left_cen = left_max + box_min;
-  const MBCartVect left_dim = left_max - box_min;
-  const MBCartVect right_cen = box_max + right_min;
-  const MBCartVect right_dim = box_max - right_min;
+  const MBCartVect left_cen = 0.5*(left_max + box_min);
+  const MBCartVect left_dim = 0.5*(left_max - box_min);
+  const MBCartVect right_cen = 0.5*(box_max + right_min);
+  const MBCartVect right_dim = 0.5*(box_max - right_min);
+  const MBCartVect dim = box_max - box_min;
   
   
     // test each triangle
@@ -742,33 +740,19 @@
     if (lo && ro) {
       lo = MBGeomUtil::box_elem_overlap( coords, TYPE_FROM_HANDLE(*i), left_cen, left_dim );
       ro = MBGeomUtil::box_elem_overlap( coords, TYPE_FROM_HANDLE(*i),right_cen,right_dim );
+      double tol = std::numeric_limits<double>::epsilon();
         // didn't intersect either - tolerance issue
-      while (!lo && !ro) {
-          // calculate a good tolerance
-        MBCartVect dim = box_max - box_min;
-        double max_dim;
-        if (dim[0] > dim[1] && dim[1] > dim[2])
-          max_dim = dim[0];
-        else if (dim[1] > dim[2])
-          max_dim = dim[1];
-        else
-          max_dim = dim[2];
-          // loop with increasing tolerance until we intersect something
-        double tol = std::numeric_limits<double>::epsilon();
-        while (!lo && !ro) {
-          lo = MBGeomUtil::box_elem_overlap( coords, TYPE_FROM_HANDLE(*i), left_cen,tol*max_dim+ left_dim );
-          ro = MBGeomUtil::box_elem_overlap( coords, TYPE_FROM_HANDLE(*i),right_cen,tol*max_dim+right_dim );
-          tol *= 10.0;
-          if (tol > 1e-3)
-            return MB_FAILURE;
-        }
+      while (!lo && !ro && tol < eps) {
+        lo = MBGeomUtil::box_elem_overlap( coords, TYPE_FROM_HANDLE(*i), left_cen,left_dim+tol*dim );
+        ro = MBGeomUtil::box_elem_overlap( coords, TYPE_FROM_HANDLE(*i),right_cen,right_dim+tol*dim );
+        tol *= 10.0;
       }
     }
     if (lo && ro)
       both_tris.insert( *i );
     else if (lo)
       left_tris.insert( *i );
-    else //if (ro)
+    else if (ro)
       right_tris.insert( *i );
   }
   
@@ -811,7 +795,7 @@
       MBRange left, right, both;
       double val;
       r = intersect_children_with_elems( iter.tool()->moab(),
-                                         entities, plane,
+                                         entities, plane, eps,
                                          box_min, box_max,
                                          left, right, both, 
                                          val );
@@ -877,25 +861,24 @@
     for (int p = 1; p <= plane_count; ++p) {
       double coord = box_min[axis] + (p/(1.0+plane_count)) * diff[axis];
       double closest_coord = tmp_data[0];
-      if (closest_coord - box_min[axis] <= tol[axis] || closest_coord - box_max[axis] >= -tol[axis])
-        closest_coord = 0.5 * (box_min[axis] + box_max[axis]);
       for (unsigned i = 1; i < tmp_data.size(); ++i) 
-        if ((fabs(coord-tmp_data[i]) < fabs(coord-closest_coord)) &&
-            (coord - box_min[axis] > tol[axis]) && 
-            (coord - box_max[axis] < -tol[axis]))
+        if (fabs(coord-tmp_data[i]) < fabs(coord-closest_coord))
           closest_coord = tmp_data[i];
+      if (closest_coord - box_min[axis] <= eps || box_max[axis] - closest_coord <= eps)
+        continue;
+          
       MBAdaptiveKDTree::Plane plane = { closest_coord, axis };
       MBRange left, right, both;
       double val;
       r = intersect_children_with_elems( iter.tool()->moab(),
-                                         entities, plane,
+                                         entities, plane, eps,
                                          box_min, box_max,
                                          left, right, both, 
                                          val );
       if (MB_SUCCESS != r)
         return r;
-      const size_t diff = p_count - both.size();
-      if (left.size() == diff || right.size() == diff)
+      const size_t d = p_count - both.size();
+      if (left.size() == d || right.size() == d)
         continue;
       
       if (val >= metric_val)
@@ -908,7 +891,7 @@
       best_both.swap(both);
     }
   }
-      
+     
   return MB_SUCCESS;
 }
 
@@ -967,7 +950,7 @@
       MBRange left, right, both;
       double val;
       r = intersect_children_with_elems( iter.tool()->moab(),
-                                         entities, plane,
+                                         entities, plane, eps,
                                          box_min, box_max,
                                          left, right, both, 
                                          val );
@@ -1083,7 +1066,7 @@
       MBRange left, right, both;
       double val;
       r = intersect_children_with_elems( iter.tool()->moab(),
-                                         entities, plane,
+                                         entities, plane, eps,
                                          box_min, box_max,
                                          left, right, both, 
                                          val );

Modified: MOAB/trunk/MBGeomUtil.cpp
===================================================================
--- MOAB/trunk/MBGeomUtil.cpp	2008-07-02 04:06:20 UTC (rev 1975)
+++ MOAB/trunk/MBGeomUtil.cpp	2008-07-03 14:56:52 UTC (rev 1976)
@@ -34,6 +34,33 @@
 
 namespace MBGeomUtil {
 
+static inline 
+void min_max_3( double a, double b, double c, double& min, double& max )
+{
+  if (a < b) {
+    if (a < c) {
+      min = a;
+      max = b > c ? b : c;
+    }
+    else {
+      min = c;
+      max = b;
+    }
+  }
+  else if (b < c) {
+    min = b;
+    max = a > c ? a : c;
+  }
+  else {
+    min = c;
+    max = a;
+  }
+}
+
+static inline
+double dot_abs( const MBCartVect& u, const MBCartVect& v )
+  { return fabs(u[0]*v[0]) + fabs(u[1]*v[1]) + fabs(u[2]*v[2]); }
+
 bool segment_box_intersect( MBCartVect box_min,
                             MBCartVect box_max,
                             const MBCartVect& seg_pt,
@@ -275,6 +302,8 @@
   switch (elem_type) {
     case MBTRI:
       return box_tri_overlap( elem_corners, center, dims );
+    case MBTET:
+      return box_tet_overlap( elem_corners, center, dims );
     case MBHEX:
       return box_hex_overlap( elem_corners, center, dims );
     case MBPOLYGON:
@@ -391,8 +420,8 @@
       not_less[0] = not_greater[0] = num_corner - 1;
       for (i = (unsigned)(indices[0]+1)%num_corner; i != (unsigned)indices[0]; i = (i+1)%num_corner) { // for each element corner
         tmp = cross[0] * elem_corners[i][1] + cross[1] * elem_corners[i][2];
-        not_less[0] -= tmp < -dot;
-        not_greater[0] -= tmp > dot;
+        not_less[0] -= (tmp < -dot);
+        not_greater[0] -= (tmp > dot);
       }
 
       if (not_less[0] * not_greater[0] == 0)
@@ -411,8 +440,8 @@
       not_less[0] = not_greater[0] = num_corner - 1;
       for (i = (unsigned)(indices[0]+1)%num_corner; i != (unsigned)indices[0]; i = (i+1)%num_corner) { // for each element corner
         tmp = cross[0] * elem_corners[i][2] + cross[1] * elem_corners[i][0];
-        not_less[0] -= tmp < -dot;
-        not_greater[0] -= tmp > dot;
+        not_less[0] -= (tmp < -dot);
+        not_greater[0] -= (tmp > dot);
       }
 
       if (not_less[0] * not_greater[0] == 0)
@@ -431,8 +460,8 @@
       not_less[0] = not_greater[0] = num_corner - 1;
       for (i = (unsigned)(indices[0]+1)%num_corner; i != (unsigned)indices[0]; i = (i+1)%num_corner) { // for each element corner
         tmp = cross[0] * elem_corners[i][0] + cross[1] * elem_corners[i][1];
-        not_less[0] -= tmp < -dot;
-        not_greater[0] -= tmp > dot;
+        not_less[0] -= (tmp < -dot);
+        not_greater[0] -= (tmp > dot);
       }
 
       if (not_less[0] * not_greater[0] == 0)
@@ -462,14 +491,14 @@
         continue;
     }
     
-    dot = fabs(norm[0] * dims[0]) + fabs(norm[1] * dims[1]) + fabs(norm[2] * dims[2]); 
-   
+    dot = dot_abs(norm, dims);
+    
     // for each element vertex
     not_less[0] = not_greater[0] = num_corner;
     for (i = 0; i < num_corner; ++i) { 
       tmp = norm % elem_corners[i];
-      not_less[0] -= tmp < -dot;
-      not_greater[0] -= tmp > dot;
+      not_less[0] -= (tmp < -dot);
+      not_greater[0] -= (tmp > dot);
     }
 
     if (not_less[0] * not_greater[0] == 0)
@@ -570,8 +599,8 @@
       not_less[0] = not_greater[0] = 7;
       for (i = (edges[e][0]+1)%8; i != edges[e][0]; i = (i+1)%8) { // for each element corner
         tmp = cross[0] * corners[i][1] + cross[1] * corners[i][2];
-        not_less[0] -= tmp < -dot;
-        not_greater[0] -= tmp > dot;
+        not_less[0] -= (tmp < -dot);
+        not_greater[0] -= (tmp > dot);
       }
 
       if (not_less[0] * not_greater[0] == 0)
@@ -590,8 +619,8 @@
       not_less[0] = not_greater[0] = 7;
       for (i = (edges[e][0]+1)%8; i != edges[e][0]; i = (i+1)%8) { // for each element corner
         tmp = cross[0] * corners[i][2] + cross[1] * corners[i][0];
-        not_less[0] -= tmp < -dot;
-        not_greater[0] -= tmp > dot;
+        not_less[0] -= (tmp < -dot);
+        not_greater[0] -= (tmp > dot);
       }
 
       if (not_less[0] * not_greater[0] == 0)
@@ -610,8 +639,8 @@
       not_less[0] = not_greater[0] = 7;
       for (i = (edges[e][0]+1)%8; i != edges[e][0]; i = (i+1)%8) { // for each element corner
         tmp = cross[0] * corners[i][0] + cross[1] * corners[i][1];
-        not_less[0] -= tmp < -dot;
-        not_greater[0] -= tmp > dot;
+        not_less[0] -= (tmp < -dot);
+        not_greater[0] -= (tmp > dot);
       }
 
       if (not_less[0] * not_greater[0] == 0)
@@ -633,14 +662,14 @@
                       corners[faces[f][2]], 
                       corners[faces[f][3]] );
     
-    dot = fabs(norm[0] * dims[0]) + fabs(norm[1] * dims[1]) + fabs(norm[2] * dims[2]); 
+    dot = dot_abs(norm, dims);
    
     // for each element vertex
     not_less[0] = not_greater[0] = 8;
     for (i = 0; i < 8; ++i) { 
       tmp = norm % corners[i];
-      not_less[0] -= tmp < -dot;
-      not_greater[0] -= tmp > dot;
+      not_less[0] -= (tmp < -dot);
+      not_greater[0] -= (tmp > dot);
     }
 
     if (not_less[0] * not_greater[0] == 0)
@@ -651,6 +680,184 @@
   return true;
 }
 
+static inline 
+bool box_tet_overlap_edge( const MBCartVect& dims,
+                           const MBCartVect& edge,
+                           const MBCartVect& ve,
+                           const MBCartVect& v1,
+                           const MBCartVect& v2 )
+{
+  double dot, dot1, dot2, dot3, min, max;
+  
+    // edge x X
+  if (fabs(edge[1]*edge[2]) > std::numeric_limits<double>::epsilon()) {
+    dot = fabs(edge[2]) * dims[1] + fabs(edge[1]) * dims[2];
+    dot1 = edge[2] * ve[1] - edge[1] * ve[2];
+    dot2 = edge[2] * v1[1] - edge[1] * v1[2];
+    dot3 = edge[2] * v2[1] - edge[1] * v2[2];
+    min_max_3( dot1, dot2, dot3, min, max );
+    if (max < -dot || min > dot)
+      return false;
+  }
+  
+    // edge x Y
+  if (fabs(edge[1]*edge[2]) > std::numeric_limits<double>::epsilon()) {
+    dot = fabs(edge[2]) * dims[0] + fabs(edge[0]) * dims[2];
+    dot1 = -edge[2] * ve[0] + edge[0] * ve[2];
+    dot2 = -edge[2] * v1[0] + edge[0] * v1[2];
+    dot3 = -edge[2] * v2[0] + edge[0] * v2[2];
+    min_max_3( dot1, dot2, dot3, min, max );
+    if (max < -dot || min > dot)
+      return false;
+  }
+  
+    // edge x Z
+  if (fabs(edge[1]*edge[2]) > std::numeric_limits<double>::epsilon()) {
+    dot = fabs(edge[1]) * dims[0] + fabs(edge[0]) * dims[1];
+    dot1 = edge[1] * ve[0] - edge[0] * ve[1];
+    dot2 = edge[1] * v1[0] - edge[0] * v1[1];
+    dot3 = edge[1] * v2[0] - edge[0] * v2[1];
+    min_max_3( dot1, dot2, dot3, min, max );
+    if (max < -dot || min > dot)
+      return false;
+  }
+
+  return true;
+}
+
+bool box_tet_overlap( const MBCartVect *corners_in,
+                      const MBCartVect& center,
+                      const MBCartVect& dims )
+{
+    // Do Separating Axis Theorem:
+    // If the element and the box overlap, then the 1D projections
+    // onto at least one of the axes in the following three sets
+    // must overlap (assuming convex polyhedral element).
+    // 1) The normals of the faces of the box (the principal axes)
+    // 2) The crossproduct of each element edge with each box edge
+    //    (crossproduct of each edge with each principal axis)
+    // 3) The normals of the faces of the element
+
+    // Translate problem such that box center is at origin.
+  const MBCartVect corners[4] = { corners_in[0] - center,
+                                  corners_in[1] - center,
+                                  corners_in[2] - center,
+                                  corners_in[3] - center };
+
+    // 0) Check if any vertex is within the box
+  if (fabs(corners[0][0]) <= dims[0] &&
+      fabs(corners[0][1]) <= dims[1] &&
+      fabs(corners[0][2]) <= dims[2])
+    return true;
+  if (fabs(corners[1][0]) <= dims[0] &&
+      fabs(corners[1][1]) <= dims[1] &&
+      fabs(corners[1][2]) <= dims[2])
+    return true;
+  if (fabs(corners[2][0]) <= dims[0] &&
+      fabs(corners[2][1]) <= dims[1] &&
+      fabs(corners[2][2]) <= dims[2])
+    return true;
+  if (fabs(corners[3][0]) <= dims[0] &&
+      fabs(corners[3][1]) <= dims[1] &&
+      fabs(corners[3][2]) <= dims[2])
+    return true;
+  
+
+    // 1) Check for overlap on each principal axis (box face normal)
+    // X
+  if (corners[0][0] < -dims[0] &&
+      corners[1][0] < -dims[0] &&
+      corners[2][0] < -dims[0] &&
+      corners[3][0] < -dims[0])
+    return false;
+  if (corners[0][0] >  dims[0] &&
+      corners[1][0] >  dims[0] &&
+      corners[2][0] >  dims[0] &&
+      corners[3][0] >  dims[0])
+    return false;
+    // Y
+  if (corners[0][1] < -dims[1] &&
+      corners[1][1] < -dims[1] &&
+      corners[2][1] < -dims[1] &&
+      corners[3][1] < -dims[1])
+    return false;
+  if (corners[0][1] >  dims[1] &&
+      corners[1][1] >  dims[1] &&
+      corners[2][1] >  dims[1] &&
+      corners[3][1] >  dims[1])
+    return false;
+    // Z
+  if (corners[0][2] < -dims[2] &&
+      corners[1][2] < -dims[2] &&
+      corners[2][2] < -dims[2] &&
+      corners[3][2] < -dims[2])
+    return false;
+  if (corners[0][2] >  dims[2] &&
+      corners[1][2] >  dims[2] &&
+      corners[2][2] >  dims[2] &&
+      corners[3][2] >  dims[2])
+    return false;
+ 
+    // 3) test element face normals
+  MBCartVect norm;
+  double dot, dot1, dot2;
+  
+  const MBCartVect v01 = corners[1] - corners[0];
+  const MBCartVect v02 = corners[2] - corners[0];
+  norm = v01 * v02;
+  dot = dot_abs(norm, dims);
+  dot1 = norm % corners[0];
+  dot2 = norm % corners[3];
+  if (dot1 > dot2)
+    std::swap(dot1, dot2);
+  if (dot2 < -dot || dot1 > dot)
+    return false;
+  
+  const MBCartVect v03 = corners[3] - corners[0];
+  norm = v03 * v01;
+  dot = dot_abs(norm, dims);
+  dot1 = norm % corners[0];
+  dot2 = norm % corners[2];
+  if (dot1 > dot2)
+    std::swap(dot1, dot2);
+  if (dot2 < -dot || dot1 > dot)
+    return false;
+  
+  norm = v02 * v03;
+  dot = dot_abs(norm, dims);
+  dot1 = norm % corners[0];
+  dot2 = norm % corners[1];
+  if (dot1 > dot2)
+    std::swap(dot1, dot2);
+  if (dot2 < -dot || dot1 > dot)
+    return false;
+  
+  const MBCartVect v12 = corners[2] - corners[1];
+  const MBCartVect v13 = corners[3] - corners[1];
+  norm = v13 * v12;
+  dot = dot_abs(norm, dims);
+  dot1 = norm % corners[0];
+  dot2 = norm % corners[1];
+  if (dot1 > dot2)
+    std::swap(dot1, dot2);
+  if (dot2 < -dot || dot1 > dot)
+    return false;
+  
+
+    // 2) test edge-edge cross products
+    
+  const MBCartVect v23 = corners[3] - corners[2];
+  return box_tet_overlap_edge( dims, v01, corners[0], corners[2], corners[3] )
+      && box_tet_overlap_edge( dims, v02, corners[0], corners[1], corners[3] )
+      && box_tet_overlap_edge( dims, v03, corners[0], corners[1], corners[2] )
+      && box_tet_overlap_edge( dims, v12, corners[1], corners[0], corners[3] )
+      && box_tet_overlap_edge( dims, v13, corners[1], corners[0], corners[2] )
+      && box_tet_overlap_edge( dims, v23, corners[2], corners[0], corners[1] );
+}
+    
+
+
+
 //from: http://www.geometrictools.com/Documentation/DistancePoint3Triangle3.pdf#search=%22closest%20point%20on%20triangle%22
 /*       t
  *   \(2)^

Modified: MOAB/trunk/MBGeomUtil.hpp
===================================================================
--- MOAB/trunk/MBGeomUtil.hpp	2008-07-02 04:06:20 UTC (rev 1975)
+++ MOAB/trunk/MBGeomUtil.hpp	2008-07-03 14:56:52 UTC (rev 1976)
@@ -248,6 +248,12 @@
                       const MBCartVect& box_center,
                       const MBCartVect& box_dims);
 
+// Finds whether or not a box defined by the center and the half
+// width intersects a linear tetrahedron defined by its four vertices.
+bool box_tet_overlap( const MBCartVect tet_corners[4],
+                      const MBCartVect& box_center,
+                      const MBCartVect& box_dims);
+
 //
 // point_in_trilinear_hex
 // Tests if a point in xyz space is within a hex element defined with




More information about the moab-dev mailing list