[MOAB-dev] r1850 - MOAB/trunk

kraftche at mcs.anl.gov kraftche at mcs.anl.gov
Tue May 27 17:48:25 CDT 2008


Author: kraftche
Date: 2008-05-27 17:48:24 -0500 (Tue, 27 May 2008)
New Revision: 1850

Modified:
   MOAB/trunk/GeomUtilTests.cpp
   MOAB/trunk/MBGeomUtil.cpp
   MOAB/trunk/MBGeomUtil.hpp
Log:

o Rename MBGeomUtil::box_general_elem_overlap as
  MBGeomUtil::box_linear_elem_overlap

o Re-implement MBGeomUtil::box_linear_elem_overlap using more 
  efficient algorithm.

o Fix unit test that tests box/tri overlap using 
  MBGeomUtil::box_linear_elem_overlap such that all test
  cases are clear cases of overlap rather than just-
  touching cases.

o Add unit test for MBGeomUtil::box_linear_elem_overlap that
  tests box/hex overlap
  


Modified: MOAB/trunk/GeomUtilTests.cpp
===================================================================
--- MOAB/trunk/GeomUtilTests.cpp	2008-05-27 20:39:43 UTC (rev 1849)
+++ MOAB/trunk/GeomUtilTests.cpp	2008-05-27 22:48:24 UTC (rev 1850)
@@ -354,7 +354,7 @@
   ASSERT( !box_tri_overlap( coords, MBCartVect(2,2,5), MBCartVect(2,2,2) ) );
 }
 
-void test_box_general_elem_overlap_tri()
+void test_box_linear_elem_overlap_tri()
 {
   MBCartVect coords[3];
   MBCartVect center, dims;
@@ -365,13 +365,13 @@
   coords[2] = MBCartVect(-4, 0, 0 );
   center = MBCartVect( -2, 1, 0 );
   dims = MBCartVect( 1, 0.5, 3 );
-  ASSERT(  box_general_elem_overlap( coords, MBTRI, center, dims ) );
+  ASSERT(  box_linear_elem_overlap( coords, MBTRI, center, dims ) );
     // move box below plane of triangle
   center[2] = -4;
-  ASSERT( !box_general_elem_overlap( coords, MBTRI, center, dims ) );
+  ASSERT( !box_linear_elem_overlap( coords, MBTRI, center, dims ) );
     // move box above plane of triangle
   center[2] =  4;
-  ASSERT( !box_general_elem_overlap( coords, MBTRI, center, dims ) );
+  ASSERT( !box_linear_elem_overlap( coords, MBTRI, center, dims ) );
   
     // test box projection within triangle, x-plane
   coords[0] = MBCartVect( 3, 3, 0 );
@@ -379,222 +379,334 @@
   coords[2] = MBCartVect( 3, 0, 0 );
   center = MBCartVect( 3, 2.5, .25 );
   dims = MBCartVect( 0.001, 0.4, .2 );
-  ASSERT(  box_general_elem_overlap( coords, MBTRI, center, dims ) );
+  ASSERT(  box_linear_elem_overlap( coords, MBTRI, center, dims ) );
     // move box below plane of triangle
   center[0] = 2;
-  ASSERT( !box_general_elem_overlap( coords, MBTRI, center, dims ) );
+  ASSERT( !box_linear_elem_overlap( coords, MBTRI, center, dims ) );
     // move box above plane of triangle
   center[0] = 4;
-  ASSERT( !box_general_elem_overlap( coords, MBTRI, center, dims ) );
+  ASSERT( !box_linear_elem_overlap( coords, MBTRI, 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_general_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
     // test with tri above the corner
-  ASSERT( !box_general_elem_overlap( coords, MBTRI, MBCartVect(0,0,0), MBCartVect(1,1,1) ) );
+  ASSERT( !box_linear_elem_overlap( coords, MBTRI, 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_general_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
     // test with tri below the corner
-  ASSERT( !box_general_elem_overlap( coords, MBTRI, MBCartVect(2,2,2),MBCartVect(1,1,1) ) );
+  ASSERT( !box_linear_elem_overlap( coords, MBTRI, 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_general_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
     // test with tri above the corner
-  ASSERT( !box_general_elem_overlap( coords, MBTRI, MBCartVect(2,1,1), MBCartVect(1,1,1) ) );
+  ASSERT( !box_linear_elem_overlap( coords, MBTRI, 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_general_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(0,0,0), MBCartVect(1,1,1) ) );
     // test with tri above the corner
-  ASSERT( !box_general_elem_overlap( coords, MBTRI, MBCartVect(0,1,1), MBCartVect(1,1,1) ) );
+  ASSERT( !box_linear_elem_overlap( coords, MBTRI, MBCartVect(-0.5,0.5,0.5), 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_general_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
     // test with tri above the corner
-  ASSERT( !box_general_elem_overlap( coords, MBTRI, MBCartVect(-1,1,1), MBCartVect(1,1,1) ) );
+  ASSERT( !box_linear_elem_overlap( coords, MBTRI, 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_general_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
     // test with tri above the corner
-  ASSERT( !box_general_elem_overlap( coords, MBTRI, MBCartVect(3,1,1), MBCartVect(1,1,1) ) );
+  ASSERT( !box_linear_elem_overlap( coords, MBTRI, 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_general_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !box_general_elem_overlap( coords, MBTRI, MBCartVect(1,1,3), MBCartVect(1,1,1) ) );
+  ASSERT( !box_linear_elem_overlap( coords, MBTRI, 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_general_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !box_general_elem_overlap( coords, MBTRI, MBCartVect(1,1,-1), MBCartVect(1,1,1) ) );
+  ASSERT( !box_linear_elem_overlap( coords, MBTRI, 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_general_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,1.5,1.5), MBCartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !box_general_elem_overlap( coords, MBTRI, MBCartVect(1,1,0.3), MBCartVect(1,1,1) ) );
+  ASSERT( !box_linear_elem_overlap( coords, MBTRI, 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_general_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,1.5,0.5), MBCartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !box_general_elem_overlap( coords, MBTRI, MBCartVect(1,1,1.7), MBCartVect(1,1,1) ) );
+  ASSERT( !box_linear_elem_overlap( coords, MBTRI, 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_general_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,0.5,0.5), MBCartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !box_general_elem_overlap( coords, MBTRI, MBCartVect(1,1,1.7), MBCartVect(1,1,1) ) );
+  ASSERT( !box_linear_elem_overlap( coords, MBTRI, 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_general_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(1,0.5,1.5), MBCartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !box_general_elem_overlap( coords, MBTRI, MBCartVect(1,1,0.3), MBCartVect(1,1,1) ) );
+  ASSERT( !box_linear_elem_overlap( coords, MBTRI, 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_general_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(1.5,1,1.5), MBCartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !box_general_elem_overlap( coords, MBTRI, MBCartVect(1,1,0.3), MBCartVect(1,1,1) ) );
+  ASSERT( !box_linear_elem_overlap( coords, MBTRI, 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_general_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(0.5,1,1.5), MBCartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !box_general_elem_overlap( coords, MBTRI, MBCartVect(1,1,0.3), MBCartVect(1,1,1) ) );
+  ASSERT( !box_linear_elem_overlap( coords, MBTRI, 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_general_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(1.5,1,0.5), MBCartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !box_general_elem_overlap( coords, MBTRI, MBCartVect(1,1,1.7), MBCartVect(1,1,1) ) );
+  ASSERT( !box_linear_elem_overlap( coords, MBTRI, 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_general_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(0.5,1,0.5), MBCartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !box_general_elem_overlap( coords, MBTRI, MBCartVect(1,1,1.7), MBCartVect(1,1,1) ) );
+  ASSERT( !box_linear_elem_overlap( coords, MBTRI, 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_general_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(1.5,1.5,1), MBCartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !box_general_elem_overlap( coords, MBTRI, MBCartVect(0.3,1,1), MBCartVect(1,1,1) ) );
+  ASSERT( !box_linear_elem_overlap( coords, MBTRI, 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_general_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(1.5,0.5,1), MBCartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !box_general_elem_overlap( coords, MBTRI, MBCartVect(0.3,1,1), MBCartVect(1,1,1) ) );
+  ASSERT( !box_linear_elem_overlap( coords, MBTRI, 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_general_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(0.5,1.5,1), MBCartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !box_general_elem_overlap( coords, MBTRI, MBCartVect(1.7,1,1), MBCartVect(1,1,1) ) );
+  ASSERT( !box_linear_elem_overlap( coords, MBTRI, 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_general_elem_overlap( coords, MBTRI, MBCartVect(1,1,1), MBCartVect(1,1,1) ) );
+  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(0.5,0.5,1), MBCartVect(1,1,1) ) );
     // test with tri outside box
-  ASSERT( !box_general_elem_overlap( coords, MBTRI, MBCartVect(1.7,1,1), MBCartVect(1,1,1) ) );
+  ASSERT( !box_linear_elem_overlap( coords, MBTRI, 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_general_elem_overlap( coords, MBTRI, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
+  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
     // test with tri outside box
-  ASSERT( !box_general_elem_overlap( coords, MBTRI, MBCartVect(-1,2,2), MBCartVect(2,2,2) ) );
+  ASSERT( !box_linear_elem_overlap( coords, MBTRI, 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_general_elem_overlap( coords, MBTRI, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
+  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
     // test with tri outside box
-  ASSERT( !box_general_elem_overlap( coords, MBTRI, MBCartVect(5,2,2), MBCartVect(2,2,2) ) );
+  ASSERT( !box_linear_elem_overlap( coords, MBTRI, 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_general_elem_overlap( coords, MBTRI, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
+  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
     // test with tri outside box
-  ASSERT( !box_general_elem_overlap( coords, MBTRI, MBCartVect(2,-1,2), MBCartVect(2,2,2) ) );
+  ASSERT( !box_linear_elem_overlap( coords, MBTRI, 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_general_elem_overlap( coords, MBTRI, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
+  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
     // test with tri outside box
-  ASSERT( !box_general_elem_overlap( coords, MBTRI, MBCartVect(2,5,2), MBCartVect(2,2,2) ) );
+  ASSERT( !box_linear_elem_overlap( coords, MBTRI, 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_general_elem_overlap( coords, MBTRI, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
+  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
     // test with tri outside box
-  ASSERT( !box_general_elem_overlap( coords, MBTRI, MBCartVect(2,2,-1), MBCartVect(2,2,2) ) );
+  ASSERT( !box_linear_elem_overlap( coords, MBTRI, 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_general_elem_overlap( coords, MBTRI, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
+  ASSERT(  box_linear_elem_overlap( coords, MBTRI, MBCartVect(2,2,2), MBCartVect(2,2,2) ) );
     // test with tri outside box
-  ASSERT( !box_general_elem_overlap( coords, MBTRI, MBCartVect(2,2,5), MBCartVect(2,2,2) ) );
+  ASSERT( !box_linear_elem_overlap( coords, MBTRI, MBCartVect(2,2,5), MBCartVect(2,2,2) ) );
 }
 
+void test_box_linear_elem_overlap_hex()
+{
+  MBCartVect coords[8];
+
+    // 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);
+
+  ASSERT( box_linear_elem_overlap( coords, MBHEX, 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( 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( 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(!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(!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(!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) ) );
+
+    // 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_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(!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(!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(!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( 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) ) );
+}
+
+
 void test_ray_tri_intersect()
 {
   bool xsect;
@@ -1021,7 +1133,8 @@
   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_general_elem_overlap_tri);
+  error_count += RUN_TEST(test_box_linear_elem_overlap_tri);
+  error_count += RUN_TEST(test_box_linear_elem_overlap_hex);
   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/MBGeomUtil.cpp
===================================================================
--- MOAB/trunk/MBGeomUtil.cpp	2008-05-27 20:39:43 UTC (rev 1849)
+++ MOAB/trunk/MBGeomUtil.cpp	2008-05-27 22:48:24 UTC (rev 1850)
@@ -282,106 +282,164 @@
       assert(false);
       return false;
     default:
-      return box_general_elem_overlap( elem_corners, elem_type, center, dims );
+      return box_linear_elem_overlap( elem_corners, elem_type, center, dims );
   }
 }
 
-bool box_general_elem_overlap( const MBCartVect *elem_corners,
-                               MBEntityType elem_type,
-                               const MBCartVect& box_center,
-                               const MBCartVect& dims )
+static inline MBCartVect quad_norm( const MBCartVect& v1,
+                                    const MBCartVect& v2,
+                                    const MBCartVect& v3,
+                                    const MBCartVect& v4 )
+{ return (-v1+v2+v3-v4) * (-v1-v2+v3+v4); }
+
+static inline MBCartVect tri_norm( const MBCartVect& v1,
+                                   const MBCartVect& v2,
+                                   const MBCartVect& v3 )
+{ return (v2-v1) * (v3-v1); }
+
+
+bool box_linear_elem_overlap( const MBCartVect *elem_corners,
+                              MBEntityType type,
+                              const MBCartVect& box_center,
+                              const MBCartVect& box_halfdims )
 {
-  const int num_corner = MBCN::VerticesPerEntity(elem_type);
-  int i, j, k;
-  MBCartVect corners[16];
-  if (num_corner > (int)(sizeof(corners)/sizeof(corners[0])))
-    { assert(false); return false; }
+    // 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
+
+  unsigned d, i, e, f;             // loop counters
+  bool all_less, all_greater;      // track overlap (or lack thereof)
+  double min, max, cross[2], tmp;
+  MBCartVect norm;
+  int indices[4]; // element edge/face vertex indices
+    // calculate minimum and maximum corners of extents box
+  const MBCartVect box_min( box_center - box_halfdims );
+  const MBCartVect box_max( box_center + box_halfdims );
+    // get element topology information
+  const unsigned num_corner = MBCN::VerticesPerEntity( type );
+  const unsigned num_edge = MBCN::NumSubEntities( type, 1 );
+  const unsigned num_face = MBCN::NumSubEntities( type, 2 );
   
-    // translate everything such that box center is at origin
-  for (i = 0; i < num_corner; ++i)
-    corners[i] = elem_corners[i] - box_center;
-  
-    // use separating axis theorem....
-  
-    // first test overlap in direction of box faces (on principal axes)
-  bool all_less[] = { true, true, true };
-  bool all_greater[] = { true, true, true };
-  for (i = 0; i < num_corner; ++i) {
-    for (j = 0; j< 3; ++j) {
-      if (-dims[j] <= corners[i][j])
-        all_less[j] = false;
-      if (dims[j] >= corners[i][j])
-        all_greater[j] = false;
+    // test box face normals (principal axes)
+  for (d = 0; d < 3; ++d) {  // for each principal axis
+    all_less = all_greater = true;
+    for (i = 0; i < num_corner; ++i) { // for each element corner
+      if (elem_corners[i][d] > box_min[d])
+        all_less = false;
+      if (elem_corners[i][d] < box_max[d])
+        all_greater = false;
     }
+    if (all_greater || all_less)
+      return false;
   }
-  if (all_less[0] || all_less[1] || all_less[2] ||
-      all_greater[0] || all_greater[1] || all_greater[2])
-    return false;
   
-    // next test overlap on edge-edge cross products
-  const int num_edge = MBCN::NumSubEntities( elem_type, 1 );
-  int edge_verts[2];
-  for (i = 0; i < num_edge; ++i) {
-    MBCN::SubEntityVertexIndices( elem_type, 1, i, edge_verts );
-    const MBCartVect dir( corners[edge_verts[1]] - corners[edge_verts[0]] );
-      // the range of the projection of the box onto each
-      // cross product (e.g. x-axis cross dir).  The principal
-      // axes are the directions of the box edges.
-    const MBCartVect d( fabs( dims[1] * dir[2] ) + fabs( dims[2] * dir[1] ),
-                        fabs( dims[0] * dir[2] ) + fabs( dims[2] * dir[0] ),
-                        fabs( dims[0] * dir[1] ) + fabs( dims[1] * dir[0] ) );
-    all_less[0] = all_less[1] = all_less[2] = true;
-    all_greater[0] = all_greater[1] = all_greater[2] = true;
-    for (j = 0; j < num_corner; ++j) {
-      const MBCartVect v( corners[j][2] * dir[1] - corners[j][1] * dir[2], 
-                          corners[j][0] * dir[2] - corners[j][2] * dir[0], 
-                          corners[j][1] * dir[0] - corners[j][0] * dir[1] );
-      for (k = 0; k < 3; ++k) {
-        if (v[k] >= -d[k])
-          all_less[k] = false;
-        if (v[k] <= d[k])
-          all_greater[k] = false;
+    // test edge-edge crossproducts
+  for (d = 0; d < 3; ++d) {  // for each principal axis (box edge)
+      // get indices of other two axes
+    const int idx1 = (d+1)%3;
+    const int idx2 = (d+2)%3;
+    
+    for (e = 0; e < num_edge; ++e) { // for each element edge
+        // get which element vertices bound the edge
+      MBCN::SubEntityVertexIndices( type, 1, e, indices );
+        // calculate crossproduct: axis x (v1 - v0),
+        // where v1 and v0 are edge vertices.
+      cross[0] = elem_corners[indices[0]][idx2] - elem_corners[indices[1]][idx2];
+      cross[1] = elem_corners[indices[1]][idx1] - elem_corners[indices[0]][idx1];
+        // skip if orthogonal
+      if ((cross[0]*cross[0] + cross[1]*cross[1]) < std::numeric_limits<double>::epsilon())
+        continue;
+      
+        // first box vertex
+      min = max = cross[0] * box_min[idx1] + cross[1] * box_min[idx2];
+        // second box vertex
+      tmp = cross[0] * box_min[idx1] + cross[1] * box_max[idx2];
+      if (tmp < min) min = tmp; else if (tmp > max) max = tmp;
+        // third box vertex
+      tmp = cross[0] * box_max[idx1] + cross[1] * box_max[idx2];
+      if (tmp < min) min = tmp; else if (tmp > max) max = tmp;
+        // fourth box vertex
+      tmp = cross[0] * box_max[idx1] + cross[1] * box_min[idx2];
+      if (tmp < min) min = tmp; else if (tmp > max) max = tmp;
+    
+      all_less = all_greater = true;
+      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][idx1] + cross[1] * elem_corners[i][idx2];
+        if (tmp > min)
+          all_less = false;
+        if (tmp < max)
+          all_greater = false;
       }
+      
+      if (all_less || all_greater)
+        return false;
     }
-    
-    if (all_less[0] || all_less[1] || all_less[2] ||
-        all_greater[0] || all_greater[1] || all_greater[2])
-      return false;
   }
   
-    // next test overlap in direction of element face normals
-  const int num_face = MBCN::NumSubEntities( elem_type, 2 );
-  int face[4], overlap;
-  MBCartVect n;
-  for (i = 0; i < num_face; ++i) {
-    MBEntityType type = MBCN::SubEntityType( elem_type, 2, i );
-    switch (type) {
+    // test element face normals
+  for (f = 0; f < num_face; ++f) {
+    MBCN::SubEntityVertexIndices( type, 2, f, indices );
+    switch (MBCN::SubEntityType( type, 2, f )) {
       case MBTRI:
-        MBCN::SubEntityVertexIndices( elem_type, 2, i, face );
-        n = (corners[face[1]] - corners[face[0]]) * (corners[face[2]] - corners[face[0]]);
-        if (!box_plane_overlap( n, -(n % corners[face[0]]), -dims, dims ))
-          return false;
+        norm = tri_norm( elem_corners[indices[0]], 
+                         elem_corners[indices[1]], 
+                         elem_corners[indices[2]] );
         break;
       case MBQUAD:
-        MBCN::SubEntityVertexIndices( elem_type, 2, i, face );
-        overlap = 0;
-        for (j = 0; j < 4; ++j) {
-          int c1 = face[j];
-          int c2 = face[(j+1)%4];
-          int c3 = face[(j+3)%4];
-          n = (corners[c2] - corners[c1]) * (corners[c3] - corners[c1]);
-          if (box_plane_overlap( n, -(n % corners[c1]), -dims, dims ))
-            overlap = 1;
-        }
-        if (!overlap)
-          return false;
+        norm = quad_norm( elem_corners[indices[0]], 
+                          elem_corners[indices[1]], 
+                          elem_corners[indices[2]], 
+                          elem_corners[indices[3]] );
         break;
       default:
         assert(false);
-        return false;
+        continue;
     }
+
+      // first box corner
+    min = max = norm % box_min;
+      // second corner
+    tmp = norm % MBCartVect( box_max[0], box_min[1], box_min[2] );
+    if (tmp < min) min = tmp; else if (tmp > max) max = tmp;
+      // third corner
+    tmp = norm % MBCartVect( box_max[0], box_max[1], box_min[2] );
+    if (tmp < min) min = tmp; else if (tmp > max) max = tmp;
+      // fourth corner
+    tmp = norm % MBCartVect( box_min[0], box_max[1], box_min[2] );
+    if (tmp < min) min = tmp; else if (tmp > max) max = tmp;
+      // fifth corner
+    tmp = norm % MBCartVect( box_min[0], box_min[1], box_max[2] );
+    if (tmp < min) min = tmp; else if (tmp > max) max = tmp;
+      // sixth corner
+    tmp = norm % MBCartVect( box_max[0], box_min[1], box_max[2] );
+    if (tmp < min) min = tmp; else if (tmp > max) max = tmp;
+      // seventh corner
+    tmp = norm % box_max;
+    if (tmp < min) min = tmp; else if (tmp > max) max = tmp;
+      // eighth corner
+    tmp = norm % MBCartVect( box_min[0], box_max[1], box_max[2] );
+    if (tmp < min) min = tmp; else if (tmp > max) max = tmp;
+    
+    // for each element vertex
+    all_less = all_greater = true;
+    for (i = 0; i < num_corner; ++i) { 
+      tmp = norm % elem_corners[i];
+      if (tmp > min)
+        all_less = false;
+      if (tmp < max)
+        all_greater = false;
+    }
+
+    if (all_less || all_greater)
+      return false;
   }
   
+    // Overlap on all tested axes.
   return true;
 }
         

Modified: MOAB/trunk/MBGeomUtil.hpp
===================================================================
--- MOAB/trunk/MBGeomUtil.hpp	2008-05-27 20:39:43 UTC (rev 1849)
+++ MOAB/trunk/MBGeomUtil.hpp	2008-05-27 22:48:24 UTC (rev 1850)
@@ -174,10 +174,10 @@
  *\param box_half_dims Half of the width of the box in each axial
  *                     direction.
  */
-bool box_general_elem_overlap( const MBCartVect *elem_corners,
-                               MBEntityType elem_type,
-                               const MBCartVect& box_center,
-                               const MBCartVect& box_half_dims ); 
+bool box_linear_elem_overlap( const MBCartVect *elem_corners,
+                              MBEntityType elem_type,
+                              const MBCartVect& box_center,
+                              const MBCartVect& box_half_dims ); 
 
 void closest_location_on_box( const MBCartVect& box_min_corner,
                               const MBCartVect& box_max_corner,




More information about the moab-dev mailing list