MOAB: Mesh Oriented datABase
(version 5.4.1)
|
00001 #include "moab/Core.hpp" 00002 #include "moab/GeomUtil.hpp" 00003 00004 using namespace moab; 00005 using namespace moab::GeomUtil; 00006 00007 #include <iostream> 00008 00009 #include "TestUtil.hpp" 00010 const double TOL = 1e-6; 00011 #define ASSERT_VECTORS_EQUAL( A, B ) assert_vectors_equal( ( A ), ( B ), #A, #B, __LINE__ ) 00012 #define ASSERT_DOUBLES_EQUAL( A, B ) CHECK_REAL_EQUAL( A, B, TOL ) 00013 #define ASSERT( B ) CHECK( B ) 00014 00015 void assert_vectors_equal( const CartVect& a, const CartVect& b, const char* sa, const char* sb, int lineno ) 00016 { 00017 if( fabs( a[0] - b[0] ) > TOL || fabs( a[1] - b[1] ) > TOL || fabs( a[2] - b[2] ) > TOL ) 00018 { 00019 std::cerr << "Assertion failed at line " << lineno << std::endl 00020 << "\t" << sa << " == " << sb << std::endl 00021 << "\t[" << a[0] << ", " << a[1] << ", " << a[2] << "] == [" << b[0] << ", " << b[1] << ", " << b[2] 00022 << "]" << std::endl; 00023 FLAG_ERROR; 00024 } 00025 } 00026 00027 void test_box_plane_norm( CartVect norm, CartVect min, CartVect max ) 00028 { 00029 CartVect c_lower = min; 00030 CartVect c_upper = max; 00031 for( int i = 0; i < 3; ++i ) 00032 if( norm[i] < 0.0 ) std::swap( c_lower[i], c_upper[i] ); 00033 00034 CartVect p_below = c_lower - norm; 00035 CartVect p_lower = c_lower + norm; 00036 CartVect p_upper = c_upper - norm; 00037 CartVect p_above = c_upper + norm; 00038 00039 double below = -( p_below % norm ); 00040 double lower = -( p_lower % norm ); 00041 double upper = -( p_upper % norm ); 00042 double above = -( p_above % norm ); 00043 00044 ASSERT( !box_plane_overlap( norm, below, min, max ) ); 00045 ASSERT( box_plane_overlap( norm, lower, min, max ) ); 00046 ASSERT( box_plane_overlap( norm, upper, min, max ) ); 00047 ASSERT( !box_plane_overlap( norm, above, min, max ) ); 00048 } 00049 00050 void test_box_plane_axis( int axis, double ns, const CartVect& min, const CartVect& max ) 00051 { 00052 CartVect norm( 0.0 ); 00053 norm[axis] = ns; 00054 test_box_plane_norm( norm, min, max ); 00055 } 00056 00057 void test_box_plane_edge( int axis1, int axis2, bool flip_axis2, CartVect min, CartVect max ) 00058 { 00059 CartVect norm( 0.0 ); 00060 norm[axis1] = max[axis1] - min[axis1]; 00061 if( flip_axis2 ) 00062 norm[axis2] = min[axis2] - max[axis2]; 00063 else 00064 norm[axis2] = max[axis2] - min[axis2]; 00065 norm.normalize(); 00066 00067 test_box_plane_norm( norm, min, max ); 00068 } 00069 00070 void test_box_plane_corner( int xdir, int ydir, int zdir, CartVect min, CartVect max ) 00071 { 00072 CartVect norm( max - min ); 00073 norm[0] *= xdir; 00074 norm[1] *= ydir; 00075 norm[2] *= zdir; 00076 test_box_plane_norm( norm, min, max ); 00077 } 00078 00079 void test_box_plane_overlap() 00080 { 00081 const CartVect min( -1, -2, -3 ); 00082 const CartVect max( 6, 4, 2 ); 00083 00084 // test with planes orthogonal to Z axis 00085 test_box_plane_axis( 2, 2.0, min, max ); 00086 // test with planes orthogonal to X axis 00087 test_box_plane_axis( 1, -2.0, min, max ); 00088 // test with planes orthogonal to Y axis 00089 test_box_plane_axis( 1, 1.0, min, max ); 00090 00091 // test with plane orthogonal to face diagonals 00092 test_box_plane_edge( 0, 1, true, min, max ); 00093 test_box_plane_edge( 0, 1, false, min, max ); 00094 test_box_plane_edge( 0, 2, true, min, max ); 00095 test_box_plane_edge( 0, 2, false, min, max ); 00096 test_box_plane_edge( 2, 1, true, min, max ); 00097 test_box_plane_edge( 2, 1, false, min, max ); 00098 00099 // test with plane orthogonal to box diagonals 00100 test_box_plane_corner( 1, 1, 1, min, max ); 00101 test_box_plane_corner( 1, 1, -1, min, max ); 00102 test_box_plane_corner( 1, -1, -1, min, max ); 00103 test_box_plane_corner( 1, -1, 1, min, max ); 00104 } 00105 00106 class ElemOverlapTest 00107 { 00108 public: 00109 virtual bool operator()( const CartVect* coords, const CartVect& box_center, const CartVect& box_dims ) const = 0; 00110 }; 00111 class LinearElemOverlapTest : public ElemOverlapTest 00112 { 00113 public: 00114 const EntityType type; 00115 LinearElemOverlapTest( EntityType t ) : type( t ) {} 00116 bool operator()( const CartVect* coords, const CartVect& box_center, const CartVect& box_dims ) const 00117 { 00118 return box_linear_elem_overlap( coords, type, box_center, box_dims ); 00119 } 00120 }; 00121 class TypeElemOverlapTest : public ElemOverlapTest 00122 { 00123 public: 00124 bool ( *func )( const CartVect*, const CartVect&, const CartVect& ); 00125 TypeElemOverlapTest( bool ( *f )( const CartVect*, const CartVect&, const CartVect& ) ) : func( f ) {} 00126 bool operator()( const CartVect* coords, const CartVect& box_center, const CartVect& box_dims ) const 00127 { 00128 return ( *func )( coords, box_center, box_dims ); 00129 } 00130 }; 00131 00132 void general_box_tri_overlap_test( const ElemOverlapTest& overlap ) 00133 { 00134 CartVect coords[3]; 00135 CartVect center, dims; 00136 00137 // test box projection within triangle, z-plane 00138 coords[0] = CartVect( 0, 0, 0 ); 00139 coords[1] = CartVect( 0, 4, 0 ); 00140 coords[2] = CartVect( -4, 0, 0 ); 00141 center = CartVect( -2, 1, 0 ); 00142 dims = CartVect( 1, 0.5, 3 ); 00143 ASSERT( overlap( coords, center, dims ) ); 00144 // move box below plane of triangle 00145 center[2] = -4; 00146 ASSERT( !overlap( coords, center, dims ) ); 00147 // move box above plane of triangle 00148 center[2] = 4; 00149 ASSERT( !overlap( coords, center, dims ) ); 00150 00151 // test box projection within triangle, x-plane 00152 coords[0] = CartVect( 3, 3, 0 ); 00153 coords[1] = CartVect( 3, 3, 1 ); 00154 coords[2] = CartVect( 3, 0, 0 ); 00155 center = CartVect( 3, 2.5, .25 ); 00156 dims = CartVect( 0.001, 0.4, .2 ); 00157 ASSERT( overlap( coords, center, dims ) ); 00158 // move box below plane of triangle 00159 center[0] = 2; 00160 ASSERT( !overlap( coords, center, dims ) ); 00161 // move box above plane of triangle 00162 center[0] = 4; 00163 ASSERT( !overlap( coords, center, dims ) ); 00164 00165 // test tri slices corner at +x,+y,+z 00166 coords[0] = CartVect( 3, 1, 1 ); 00167 coords[1] = CartVect( 1, 3, 1 ); 00168 coords[2] = CartVect( 1, 1, 3 ); 00169 ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00170 // test with tri above the corner 00171 ASSERT( !overlap( coords, CartVect( 0, 0, 0 ), CartVect( 1, 1, 1 ) ) ); 00172 // test tri slices corner at -x,-y,-z 00173 coords[0] = CartVect( -1, 1, 1 ); 00174 coords[1] = CartVect( 1, -1, 1 ); 00175 coords[2] = CartVect( 1, 1, -1 ); 00176 ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00177 // test with tri below the corner 00178 ASSERT( !overlap( coords, CartVect( 2, 2, 2 ), CartVect( 1, 1, 1 ) ) ); 00179 00180 // test tri slices corner at -x,+y,+z 00181 coords[0] = CartVect( 0.5, 0.0, 2.5 ); 00182 coords[1] = CartVect( 0.5, 2.5, 0.0 ); 00183 coords[2] = CartVect( -0.5, 0.0, 0.0 ); 00184 ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00185 // test with tri above the corner 00186 ASSERT( !overlap( coords, CartVect( 2, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00187 00188 // test tri slices corner at +x,-y,-z 00189 coords[0] = CartVect( 0.5, 0.0, -1.5 ); 00190 coords[1] = CartVect( 0.5, -1.5, 0.0 ); 00191 coords[2] = CartVect( 1.5, 0.0, 0.0 ); 00192 ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00193 // test with tri above the corner 00194 ASSERT( !overlap( coords, CartVect( 0, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00195 00196 // test tri slices corner at +x,-y,+z 00197 coords[0] = CartVect( 1.0, 1.0, 2.5 ); 00198 coords[1] = CartVect( 2.5, 1.0, 1.0 ); 00199 coords[2] = CartVect( 1.0, -0.5, 1.0 ); 00200 ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00201 // test with tri above the corner 00202 ASSERT( !overlap( coords, CartVect( -1, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00203 00204 // test tri slices corner at -x,+y,-z 00205 coords[0] = CartVect( 1.0, 1.0, -0.5 ); 00206 coords[1] = CartVect( -0.5, 1.0, 1.0 ); 00207 coords[2] = CartVect( 1.0, 2.5, 1.0 ); 00208 ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00209 // test with tri above the corner 00210 ASSERT( !overlap( coords, CartVect( 3, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00211 00212 // test tri slices corner at +x,+y,-z 00213 coords[0] = CartVect( -0.1, 1.0, 1.0 ); 00214 coords[1] = CartVect( 1.0, -0.1, 1.0 ); 00215 coords[2] = CartVect( 1.0, 1.0, -0.1 ); 00216 ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00217 // test with tri outside box 00218 ASSERT( !overlap( coords, CartVect( 1, 1, 3 ), CartVect( 1, 1, 1 ) ) ); 00219 00220 // test tri slices corner at -x,-y,+z 00221 coords[0] = CartVect( 2.1, 1.0, 1.0 ); 00222 coords[1] = CartVect( 1.0, 2.1, 1.0 ); 00223 coords[2] = CartVect( 1.0, 1.0, 2.1 ); 00224 ASSERT( box_tri_overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00225 // test with tri outside box 00226 ASSERT( !overlap( coords, CartVect( 1, 1, -1 ), CartVect( 1, 1, 1 ) ) ); 00227 00228 // box edge parallel to x at +y,+z passes through triangle 00229 coords[0] = CartVect( 1.0, 1.0, 3.0 ); 00230 coords[1] = CartVect( 1.0, 3.0, 3.0 ); 00231 coords[2] = CartVect( 1.0, 3.0, 1.0 ); 00232 ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00233 // test with tri outside box 00234 ASSERT( !overlap( coords, CartVect( 1, 1, 0.3 ), CartVect( 1, 1, 1 ) ) ); 00235 00236 // box edge parallel to x at +y,-z passes through triangle 00237 coords[0] = CartVect( 1.0, 3.0, 1.0 ); 00238 coords[1] = CartVect( 1.0, 3.0, -1.0 ); 00239 coords[2] = CartVect( 1.0, 1.0, -1.0 ); 00240 ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00241 // test with tri outside box 00242 ASSERT( !overlap( coords, CartVect( 1, 1, 1.7 ), CartVect( 1, 1, 1 ) ) ); 00243 00244 // box edge parallel to x at -y,-z passes through triangle 00245 coords[0] = CartVect( 1.0, -1.0, 1.0 ); 00246 coords[1] = CartVect( 1.0, -1.0, -1.0 ); 00247 coords[2] = CartVect( 1.0, 1.0, -1.0 ); 00248 ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00249 // test with tri outside box 00250 ASSERT( !overlap( coords, CartVect( 1, 1, 1.7 ), CartVect( 1, 1, 1 ) ) ); 00251 00252 // box edge parallel to x at -y,+z passes through triangle 00253 coords[0] = CartVect( 1.0, -1.0, 1.0 ); 00254 coords[1] = CartVect( 1.0, -1.0, 3.0 ); 00255 coords[2] = CartVect( 1.0, 1.0, 3.0 ); 00256 ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00257 // test with tri outside box 00258 ASSERT( !overlap( coords, CartVect( 1, 1, 0.3 ), CartVect( 1, 1, 1 ) ) ); 00259 00260 // box edge parallel to y at +x,+z passes through triangle 00261 coords[0] = CartVect( 1.0, 1.0, 3.0 ); 00262 coords[1] = CartVect( 3.0, 1.0, 3.0 ); 00263 coords[2] = CartVect( 3.0, 1.0, 1.0 ); 00264 ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00265 // test with tri outside box 00266 ASSERT( !overlap( coords, CartVect( 1, 1, 0.3 ), CartVect( 1, 1, 1 ) ) ); 00267 00268 // box edge parallel to y at -x,+z passes through triangle 00269 coords[0] = CartVect( 1.0, 1.0, 3.0 ); 00270 coords[1] = CartVect( -1.0, 1.0, 3.0 ); 00271 coords[2] = CartVect( -1.0, 1.0, 1.0 ); 00272 ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00273 // test with tri outside box 00274 ASSERT( !overlap( coords, CartVect( 1, 1, 0.3 ), CartVect( 1, 1, 1 ) ) ); 00275 00276 // box edge parallel to y at +x,-z passes through triangle 00277 coords[0] = CartVect( 1.0, 1.0, -1.0 ); 00278 coords[1] = CartVect( 3.0, 1.0, -1.0 ); 00279 coords[2] = CartVect( 3.0, 1.0, 1.0 ); 00280 ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00281 // test with tri outside box 00282 ASSERT( !overlap( coords, CartVect( 1, 1, 1.7 ), CartVect( 1, 1, 1 ) ) ); 00283 00284 // box edge parallel to y at -x,-z passes through triangle 00285 coords[0] = CartVect( 1.0, 1.0, -1.0 ); 00286 coords[1] = CartVect( -1.0, 1.0, -1.0 ); 00287 coords[2] = CartVect( -1.0, 1.0, 1.0 ); 00288 ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00289 // test with tri outside box 00290 ASSERT( !overlap( coords, CartVect( 1, 1, 1.7 ), CartVect( 1, 1, 1 ) ) ); 00291 00292 // box edge parallel to z at +x,+y passes through triangle 00293 coords[0] = CartVect( 1.0, 3.0, 1.0 ); 00294 coords[1] = CartVect( 3.0, 3.0, 1.0 ); 00295 coords[2] = CartVect( 3.0, 1.0, 1.0 ); 00296 ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00297 // test with tri outside box 00298 ASSERT( !overlap( coords, CartVect( 0.3, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00299 00300 // box edge parallel to z at +x,-y passes through triangle 00301 coords[0] = CartVect( 1.0, -1.0, 1.0 ); 00302 coords[1] = CartVect( 3.0, -1.0, 1.0 ); 00303 coords[2] = CartVect( 3.0, 1.0, 1.0 ); 00304 ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00305 // test with tri outside box 00306 ASSERT( !overlap( coords, CartVect( 0.3, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00307 00308 // box edge parallel to z at -x,+y passes through triangle 00309 coords[0] = CartVect( 1.0, 3.0, 1.0 ); 00310 coords[1] = CartVect( -1.0, 3.0, 1.0 ); 00311 coords[2] = CartVect( -1.0, 1.0, 1.0 ); 00312 ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00313 // test with tri outside box 00314 ASSERT( !overlap( coords, CartVect( 1.7, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00315 00316 // box edge parallel to z at -x,-y passes through triangle 00317 coords[0] = CartVect( 1.0, -1.0, 1.0 ); 00318 coords[1] = CartVect( -1.0, -1.0, 1.0 ); 00319 coords[2] = CartVect( -1.0, 1.0, 1.0 ); 00320 ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00321 // test with tri outside box 00322 ASSERT( !overlap( coords, CartVect( 1.7, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00323 00324 // triangle penetrates +x face 00325 coords[0] = CartVect( 2.0, 2.0, 2.0 ); 00326 coords[1] = CartVect( 5.0, 3.0, 2.0 ); 00327 coords[2] = CartVect( 5.0, 1.0, 2.0 ); 00328 ASSERT( overlap( coords, CartVect( 2, 2, 2 ), CartVect( 2, 2, 2 ) ) ); 00329 // test with tri outside box 00330 ASSERT( !overlap( coords, CartVect( -1, 2, 2 ), CartVect( 2, 2, 2 ) ) ); 00331 00332 // triangle penetrates -x face 00333 coords[0] = CartVect( 2.0, 2.0, 2.0 ); 00334 coords[1] = CartVect( -1.0, 3.0, 2.0 ); 00335 coords[2] = CartVect( -1.0, 1.0, 2.0 ); 00336 ASSERT( overlap( coords, CartVect( 2, 2, 2 ), CartVect( 2, 2, 2 ) ) ); 00337 // test with tri outside box 00338 ASSERT( !overlap( coords, CartVect( 5, 2, 2 ), CartVect( 2, 2, 2 ) ) ); 00339 00340 // triangle penetrates +y face 00341 coords[0] = CartVect( 2.0, 2.0, 2.0 ); 00342 coords[1] = CartVect( 3.0, 5.0, 2.0 ); 00343 coords[2] = CartVect( 1.0, 5.0, 2.0 ); 00344 ASSERT( overlap( coords, CartVect( 2, 2, 2 ), CartVect( 2, 2, 2 ) ) ); 00345 // test with tri outside box 00346 ASSERT( !overlap( coords, CartVect( 2, -1, 2 ), CartVect( 2, 2, 2 ) ) ); 00347 00348 // triangle penetrates -y face 00349 coords[0] = CartVect( 2.0, 2.0, 2.0 ); 00350 coords[1] = CartVect( 3.0, -1.0, 2.0 ); 00351 coords[2] = CartVect( 1.0, -1.0, 2.0 ); 00352 ASSERT( overlap( coords, CartVect( 2, 2, 2 ), CartVect( 2, 2, 2 ) ) ); 00353 // test with tri outside box 00354 ASSERT( !overlap( coords, CartVect( 2, 5, 2 ), CartVect( 2, 2, 2 ) ) ); 00355 00356 // triangle penetrates +z face 00357 coords[0] = CartVect( 2.0, 2.0, 2.0 ); 00358 coords[1] = CartVect( 2.0, 3.0, 5.0 ); 00359 coords[2] = CartVect( 2.0, 1.0, 5.0 ); 00360 ASSERT( overlap( coords, CartVect( 2, 2, 2 ), CartVect( 2, 2, 2 ) ) ); 00361 // test with tri outside box 00362 ASSERT( !overlap( coords, CartVect( 2, 2, -1 ), CartVect( 2, 2, 2 ) ) ); 00363 00364 // triangle penetrates -z face 00365 coords[0] = CartVect( 2.0, 2.0, 2.0 ); 00366 coords[1] = CartVect( 2.0, 3.0, -1.0 ); 00367 coords[2] = CartVect( 2.0, 1.0, -1.0 ); 00368 ASSERT( overlap( coords, CartVect( 2, 2, 2 ), CartVect( 2, 2, 2 ) ) ); 00369 // test with tri outside box 00370 ASSERT( !overlap( coords, CartVect( 2, 2, 5 ), CartVect( 2, 2, 2 ) ) ); 00371 } 00372 00373 void general_box_hex_overlap_test( const ElemOverlapTest& overlap ) 00374 { 00375 CartVect coords[8]; 00376 00377 // test against axis-aligned rectilinear hex 00378 coords[0] = CartVect( -0.5, -0.5, -0.5 ); 00379 coords[1] = CartVect( 0.5, -0.5, -0.5 ); 00380 coords[2] = CartVect( 0.5, 0.5, -0.5 ); 00381 coords[3] = CartVect( -0.5, 0.5, -0.5 ); 00382 coords[4] = CartVect( -0.5, -0.5, 0.5 ); 00383 coords[5] = CartVect( 0.5, -0.5, 0.5 ); 00384 coords[6] = CartVect( 0.5, 0.5, 0.5 ); 00385 coords[7] = CartVect( -0.5, 0.5, 0.5 ); 00386 00387 ASSERT( overlap( coords, CartVect( 0, 0, 0 ), CartVect( 1, 1, 1 ) ) ); 00388 00389 ASSERT( overlap( coords, CartVect( 1, 0, 0 ), CartVect( 1, 1, 1 ) ) ); 00390 ASSERT( overlap( coords, CartVect( 0, 1, 0 ), CartVect( 1, 1, 1 ) ) ); 00391 ASSERT( overlap( coords, CartVect( 0, 0, 1 ), CartVect( 1, 1, 1 ) ) ); 00392 ASSERT( overlap( coords, CartVect( -1, 0, 0 ), CartVect( 1, 1, 1 ) ) ); 00393 ASSERT( overlap( coords, CartVect( 0, -1, 0 ), CartVect( 1, 1, 1 ) ) ); 00394 ASSERT( overlap( coords, CartVect( 0, 0, -1 ), CartVect( 1, 1, 1 ) ) ); 00395 00396 ASSERT( overlap( coords, CartVect( 1, 1, 0 ), CartVect( 1, 1, 1 ) ) ); 00397 ASSERT( overlap( coords, CartVect( -1, 1, 0 ), CartVect( 1, 1, 1 ) ) ); 00398 ASSERT( overlap( coords, CartVect( -1, -1, 0 ), CartVect( 1, 1, 1 ) ) ); 00399 ASSERT( overlap( coords, CartVect( 1, -1, 0 ), CartVect( 1, 1, 1 ) ) ); 00400 ASSERT( overlap( coords, CartVect( 1, 0, 1 ), CartVect( 1, 1, 1 ) ) ); 00401 ASSERT( overlap( coords, CartVect( -1, 0, 1 ), CartVect( 1, 1, 1 ) ) ); 00402 ASSERT( overlap( coords, CartVect( -1, 0, -1 ), CartVect( 1, 1, 1 ) ) ); 00403 ASSERT( overlap( coords, CartVect( 1, 0, -1 ), CartVect( 1, 1, 1 ) ) ); 00404 ASSERT( overlap( coords, CartVect( 0, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00405 ASSERT( overlap( coords, CartVect( 0, -1, 1 ), CartVect( 1, 1, 1 ) ) ); 00406 ASSERT( overlap( coords, CartVect( 0, -1, -1 ), CartVect( 1, 1, 1 ) ) ); 00407 ASSERT( overlap( coords, CartVect( 0, 1, -1 ), CartVect( 1, 1, 1 ) ) ); 00408 00409 ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00410 ASSERT( overlap( coords, CartVect( -1, 1, 1 ), CartVect( 1, 1, 1 ) ) ); 00411 ASSERT( overlap( coords, CartVect( -1, -1, 1 ), CartVect( 1, 1, 1 ) ) ); 00412 ASSERT( overlap( coords, CartVect( 1, -1, 1 ), CartVect( 1, 1, 1 ) ) ); 00413 ASSERT( overlap( coords, CartVect( 1, 1, -1 ), CartVect( 1, 1, 1 ) ) ); 00414 ASSERT( overlap( coords, CartVect( -1, 1, -1 ), CartVect( 1, 1, 1 ) ) ); 00415 ASSERT( overlap( coords, CartVect( -1, -1, -1 ), CartVect( 1, 1, 1 ) ) ); 00416 ASSERT( overlap( coords, CartVect( 1, -1, -1 ), CartVect( 1, 1, 1 ) ) ); 00417 00418 ASSERT( !overlap( coords, CartVect( 3, 0, 0 ), CartVect( 1, 1, 1 ) ) ); 00419 ASSERT( !overlap( coords, CartVect( 0, 3, 0 ), CartVect( 1, 1, 1 ) ) ); 00420 ASSERT( !overlap( coords, CartVect( 0, 0, 3 ), CartVect( 1, 1, 1 ) ) ); 00421 ASSERT( !overlap( coords, CartVect( -3, 0, 0 ), CartVect( 1, 1, 1 ) ) ); 00422 ASSERT( !overlap( coords, CartVect( 0, -3, 0 ), CartVect( 1, 1, 1 ) ) ); 00423 ASSERT( !overlap( coords, CartVect( 0, 0, -3 ), CartVect( 1, 1, 1 ) ) ); 00424 00425 ASSERT( !overlap( coords, CartVect( 3, 3, 0 ), CartVect( 1, 1, 1 ) ) ); 00426 ASSERT( !overlap( coords, CartVect( -3, 3, 0 ), CartVect( 1, 1, 1 ) ) ); 00427 ASSERT( !overlap( coords, CartVect( -3, -3, 0 ), CartVect( 1, 1, 1 ) ) ); 00428 ASSERT( !overlap( coords, CartVect( 3, -3, 0 ), CartVect( 1, 1, 1 ) ) ); 00429 ASSERT( !overlap( coords, CartVect( 3, 0, 3 ), CartVect( 1, 1, 1 ) ) ); 00430 ASSERT( !overlap( coords, CartVect( -3, 0, 3 ), CartVect( 1, 1, 1 ) ) ); 00431 ASSERT( !overlap( coords, CartVect( -3, 0, -3 ), CartVect( 1, 1, 1 ) ) ); 00432 ASSERT( !overlap( coords, CartVect( 3, 0, -3 ), CartVect( 1, 1, 1 ) ) ); 00433 ASSERT( !overlap( coords, CartVect( 0, 3, 3 ), CartVect( 1, 1, 1 ) ) ); 00434 ASSERT( !overlap( coords, CartVect( 0, -3, 3 ), CartVect( 1, 1, 1 ) ) ); 00435 ASSERT( !overlap( coords, CartVect( 0, -3, -3 ), CartVect( 1, 1, 1 ) ) ); 00436 ASSERT( !overlap( coords, CartVect( 0, 3, -3 ), CartVect( 1, 1, 1 ) ) ); 00437 00438 ASSERT( !overlap( coords, CartVect( 3, 3, 3 ), CartVect( 1, 1, 1 ) ) ); 00439 ASSERT( !overlap( coords, CartVect( -3, 3, 3 ), CartVect( 1, 1, 1 ) ) ); 00440 ASSERT( !overlap( coords, CartVect( -3, -3, 3 ), CartVect( 1, 1, 1 ) ) ); 00441 ASSERT( !overlap( coords, CartVect( 3, -3, 3 ), CartVect( 1, 1, 1 ) ) ); 00442 ASSERT( !overlap( coords, CartVect( 3, 3, -3 ), CartVect( 1, 1, 1 ) ) ); 00443 ASSERT( !overlap( coords, CartVect( -3, 3, -3 ), CartVect( 1, 1, 1 ) ) ); 00444 ASSERT( !overlap( coords, CartVect( -3, -3, -3 ), CartVect( 1, 1, 1 ) ) ); 00445 ASSERT( !overlap( coords, CartVect( 3, -3, -3 ), CartVect( 1, 1, 1 ) ) ); 00446 00447 // test against rectilinear hex rotated 45 degrees about z axis 00448 const double r = sqrt( 2.0 ) / 2.0; 00449 coords[0] = CartVect( r, 0, -0.5 ); 00450 coords[1] = CartVect( 0, r, -0.5 ); 00451 coords[2] = CartVect( -r, 0, -0.5 ); 00452 coords[3] = CartVect( 0, -r, -0.5 ); 00453 coords[4] = CartVect( r, 0, 0.5 ); 00454 coords[5] = CartVect( 0, r, 0.5 ); 00455 coords[6] = CartVect( -r, 0, 0.5 ); 00456 coords[7] = CartVect( 0, -r, 0.5 ); 00457 00458 ASSERT( overlap( coords, CartVect( 1, 0, 0 ), CartVect( 0.5, 0.5, 0.5 ) ) ); 00459 ASSERT( overlap( coords, CartVect( -1, 0, 0 ), CartVect( 0.5, 0.5, 0.5 ) ) ); 00460 ASSERT( overlap( coords, CartVect( 0, 1, 0 ), CartVect( 0.5, 0.5, 0.5 ) ) ); 00461 ASSERT( overlap( coords, CartVect( 0, -1, 0 ), CartVect( 0.5, 0.5, 0.5 ) ) ); 00462 00463 ASSERT( !overlap( coords, CartVect( 1, 0, 2 ), CartVect( 0.5, 0.5, 0.5 ) ) ); 00464 ASSERT( !overlap( coords, CartVect( -1, 0, 2 ), CartVect( 0.5, 0.5, 0.5 ) ) ); 00465 ASSERT( !overlap( coords, CartVect( 0, 1, 2 ), CartVect( 0.5, 0.5, 0.5 ) ) ); 00466 ASSERT( !overlap( coords, CartVect( 0, -1, 2 ), CartVect( 0.5, 0.5, 0.5 ) ) ); 00467 00468 ASSERT( !overlap( coords, CartVect( 2, 0, 0 ), CartVect( 0.5, 0.5, 0.5 ) ) ); 00469 ASSERT( !overlap( coords, CartVect( -2, 0, 0 ), CartVect( 0.5, 0.5, 0.5 ) ) ); 00470 ASSERT( !overlap( coords, CartVect( 0, 2, 0 ), CartVect( 0.5, 0.5, 0.5 ) ) ); 00471 ASSERT( !overlap( coords, CartVect( 0, -2, 0 ), CartVect( 0.5, 0.5, 0.5 ) ) ); 00472 00473 ASSERT( !overlap( coords, CartVect( 1, 1, 0 ), CartVect( 0.5, 0.5, 0.5 ) ) ); 00474 ASSERT( !overlap( coords, CartVect( -1, 1, 0 ), CartVect( 0.5, 0.5, 0.5 ) ) ); 00475 ASSERT( !overlap( coords, CartVect( -1, -1, 0 ), CartVect( 0.5, 0.5, 0.5 ) ) ); 00476 ASSERT( !overlap( coords, CartVect( 1, -1, 0 ), CartVect( 0.5, 0.5, 0.5 ) ) ); 00477 00478 ASSERT( overlap( coords, CartVect( 1, 1, 0 ), CartVect( 0.75, 0.75, 0.5 ) ) ); 00479 ASSERT( overlap( coords, CartVect( -1, 1, 0 ), CartVect( 0.75, 0.75, 0.5 ) ) ); 00480 ASSERT( overlap( coords, CartVect( -1, -1, 0 ), CartVect( 0.75, 0.75, 0.5 ) ) ); 00481 ASSERT( overlap( coords, CartVect( 1, -1, 0 ), CartVect( 0.75, 0.75, 0.5 ) ) ); 00482 } 00483 00484 void general_box_tet_overlap_test( const ElemOverlapTest& overlap ) 00485 { 00486 CartVect coords[4]; 00487 00488 // Octant I 00489 coords[0] = CartVect( 0, 0, 0 ); 00490 coords[1] = CartVect( 1, 0, 0 ); 00491 coords[2] = CartVect( 0, 1, 0 ); 00492 coords[3] = CartVect( 0, 0, 1 ); 00493 // tet entirely within box 00494 ASSERT( overlap( coords, CartVect( -1, -1, -1 ), CartVect( 3, 3, 3 ) ) ); 00495 // box entirely within tet 00496 ASSERT( overlap( coords, CartVect( 0.2, 0.2, 0.2 ), CartVect( 0.1, 0.1, 0.1 ) ) ); 00497 // box corner penetrates tet face 00498 ASSERT( overlap( coords, CartVect( 0.5, 0.5, 0.5 ), CartVect( 0.2, 0.2, 0.2 ) ) ); 00499 // box corner does not penetrate face 00500 ASSERT( !overlap( coords, CartVect( 0.5, 0.5, 0.5 ), CartVect( 0.15, 0.15, 0.15 ) ) ); 00501 00502 // Octant II 00503 coords[0] = CartVect( 0, 1, 0 ); 00504 coords[1] = CartVect( -1, 0, 0 ); 00505 coords[2] = CartVect( 0, 0, 0 ); 00506 coords[3] = CartVect( 0, 0, 1 ); 00507 // tet entirely within box 00508 ASSERT( overlap( coords, CartVect( 1, -1, -1 ), CartVect( 3, 3, 3 ) ) ); 00509 // box entirely within tet 00510 ASSERT( overlap( coords, CartVect( -0.2, 0.2, 0.2 ), CartVect( 0.1, 0.1, 0.1 ) ) ); 00511 // box corner penetrates tet face 00512 ASSERT( overlap( coords, CartVect( -0.5, 0.5, 0.5 ), CartVect( 0.2, 0.2, 0.2 ) ) ); 00513 // box corner does not penetrate face 00514 ASSERT( !overlap( coords, CartVect( -0.5, 0.5, 0.5 ), CartVect( 0.15, 0.15, 0.15 ) ) ); 00515 00516 // Octant III 00517 coords[0] = CartVect( 0, -1, 0 ); 00518 coords[1] = CartVect( 0, 0, 0 ); 00519 coords[2] = CartVect( -1, 0, 0 ); 00520 coords[3] = CartVect( 0, 0, 1 ); 00521 // tet entirely within box 00522 ASSERT( overlap( coords, CartVect( 1, 1, -1 ), CartVect( 3, 3, 3 ) ) ); 00523 // box entirely within tet 00524 ASSERT( overlap( coords, CartVect( -0.2, -0.2, 0.2 ), CartVect( 0.1, 0.1, 0.1 ) ) ); 00525 // box corner penetrates tet face 00526 ASSERT( overlap( coords, CartVect( -0.5, -0.5, 0.5 ), CartVect( 0.2, 0.2, 0.2 ) ) ); 00527 // box corner does not penetrate face 00528 ASSERT( !overlap( coords, CartVect( -0.5, -0.5, 0.5 ), CartVect( 0.15, 0.15, 0.15 ) ) ); 00529 00530 // Octant IV 00531 coords[0] = CartVect( 1, 0, 0 ); 00532 coords[1] = CartVect( 0, -1, 0 ); 00533 coords[2] = CartVect( 0, 0, 1 ); 00534 coords[3] = CartVect( 0, 0, 0 ); 00535 // tet entirely within box 00536 ASSERT( overlap( coords, CartVect( -1, 1, -1 ), CartVect( 3, 3, 3 ) ) ); 00537 // box entirely within tet 00538 ASSERT( overlap( coords, CartVect( 0.2, -0.2, 0.2 ), CartVect( 0.1, 0.1, 0.1 ) ) ); 00539 // box corner penetrates tet face 00540 ASSERT( overlap( coords, CartVect( 0.5, -0.5, 0.5 ), CartVect( 0.2, 0.2, 0.2 ) ) ); 00541 // box corner does not penetrate face 00542 ASSERT( !overlap( coords, CartVect( 0.5, -0.5, 0.5 ), CartVect( 0.15, 0.15, 0.15 ) ) ); 00543 00544 // Octant V 00545 coords[0] = CartVect( 0, 0, 0 ); 00546 coords[1] = CartVect( 0, 1, 0 ); 00547 coords[2] = CartVect( 1, 0, 0 ); 00548 coords[3] = CartVect( 0, 0, -1 ); 00549 // tet entirely within box 00550 ASSERT( overlap( coords, CartVect( -1, -1, 1 ), CartVect( 3, 3, 3 ) ) ); 00551 // box entirely within tet 00552 ASSERT( overlap( coords, CartVect( 0.2, 0.2, -0.2 ), CartVect( 0.1, 0.1, 0.1 ) ) ); 00553 // box corner penetrates tet face 00554 ASSERT( overlap( coords, CartVect( 0.5, 0.5, -0.5 ), CartVect( 0.2, 0.2, 0.2 ) ) ); 00555 // box corner does not penetrate face 00556 ASSERT( !overlap( coords, CartVect( 0.5, 0.5, -0.5 ), CartVect( 0.15, 0.15, 0.15 ) ) ); 00557 00558 // Octant VI 00559 coords[0] = CartVect( -1, 0, 0 ); 00560 coords[1] = CartVect( 0, 1, 0 ); 00561 coords[2] = CartVect( 0, 0, 0 ); 00562 coords[3] = CartVect( 0, 0, -1 ); 00563 // tet entirely within box 00564 ASSERT( overlap( coords, CartVect( 1, -1, 1 ), CartVect( 3, 3, 3 ) ) ); 00565 // box entirely within tet 00566 ASSERT( overlap( coords, CartVect( -0.2, 0.2, -0.2 ), CartVect( 0.1, 0.1, 0.1 ) ) ); 00567 // box corner penetrates tet face 00568 ASSERT( overlap( coords, CartVect( -0.5, 0.5, -0.5 ), CartVect( 0.2, 0.2, 0.2 ) ) ); 00569 // box corner does not penetrate face 00570 ASSERT( !overlap( coords, CartVect( -0.5, 0.5, -0.5 ), CartVect( 0.15, 0.15, 0.15 ) ) ); 00571 00572 // Octant VII 00573 coords[0] = CartVect( 0, 0, 0 ); 00574 coords[1] = CartVect( 0, -1, 0 ); 00575 coords[2] = CartVect( -1, 0, 0 ); 00576 coords[3] = CartVect( 0, 0, -1 ); 00577 // tet entirely within box 00578 ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 3, 3, 3 ) ) ); 00579 // box entirely within tet 00580 ASSERT( overlap( coords, CartVect( -0.2, -0.2, -0.2 ), CartVect( 0.1, 0.1, 0.1 ) ) ); 00581 // box corner penetrates tet face 00582 ASSERT( overlap( coords, CartVect( -0.5, -0.5, -0.5 ), CartVect( 0.2, 0.2, 0.2 ) ) ); 00583 // box corner does not penetrate face 00584 ASSERT( !overlap( coords, CartVect( -0.5, -0.5, -0.5 ), CartVect( 0.15, 0.15, 0.15 ) ) ); 00585 00586 // Octant VIII 00587 coords[0] = CartVect( 0, -1, 0 ); 00588 coords[1] = CartVect( 1, 0, 0 ); 00589 coords[2] = CartVect( 0, 0, -1 ); 00590 coords[3] = CartVect( 0, 0, 0 ); 00591 // tet entirely within box 00592 ASSERT( overlap( coords, CartVect( -1, 1, 1 ), CartVect( 3, 3, 3 ) ) ); 00593 // box entirely within tet 00594 ASSERT( overlap( coords, CartVect( 0.2, -0.2, -0.2 ), CartVect( 0.1, 0.1, 0.1 ) ) ); 00595 // box corner penetrates tet face 00596 ASSERT( overlap( coords, CartVect( 0.5, -0.5, -0.5 ), CartVect( 0.2, 0.2, 0.2 ) ) ); 00597 // box corner does not penetrate face 00598 ASSERT( !overlap( coords, CartVect( 0.5, -0.5, -0.5 ), CartVect( 0.15, 0.15, 0.15 ) ) ); 00599 00600 // Box edge -x,-z 00601 coords[0] = CartVect( 0, 0, 0 ); 00602 coords[1] = CartVect( 2, -1, 0 ); 00603 coords[2] = CartVect( 2, 1, 0 ); 00604 coords[3] = CartVect( 0, 0, 2 ); 00605 // box edge passes through tet 00606 ASSERT( overlap( coords, CartVect( 1.5, 0.0, 1.5 ), CartVect( 1, 1, 1 ) ) ); 00607 // box edge does not pass through tet 00608 ASSERT( !overlap( coords, CartVect( 2.5, 0.0, 2.5 ), CartVect( 1, 1, 1 ) ) ); 00609 00610 // Box edge -y,-z 00611 coords[0] = CartVect( 1, 2, 0 ); 00612 coords[1] = CartVect( -1, 2, 0 ); 00613 coords[2] = CartVect( 0, 0, 0 ); 00614 coords[3] = CartVect( 0, 0, 2 ); 00615 // box edge passes through tet 00616 ASSERT( overlap( coords, CartVect( 0.0, 1.5, 1.5 ), CartVect( 1, 1, 1 ) ) ); 00617 // box edge does not pass through tet 00618 ASSERT( !overlap( coords, CartVect( 0.0, 2.5, 2.5 ), CartVect( 1, 1, 1 ) ) ); 00619 00620 // Box edge +x,-z 00621 coords[0] = CartVect( -2, -1, 0 ); 00622 coords[1] = CartVect( -2, 1, 0 ); 00623 coords[2] = CartVect( 0, 0, 2 ); 00624 coords[3] = CartVect( 0, 0, 0 ); 00625 // box edge passes through tet 00626 ASSERT( overlap( coords, CartVect( -1.5, 0.0, 1.5 ), CartVect( 1, 1, 1 ) ) ); 00627 // box edge does not pass through tet 00628 ASSERT( !overlap( coords, CartVect( -2.5, 0.0, 2.5 ), CartVect( 1, 1, 1 ) ) ); 00629 00630 // Box edge +y,-z 00631 coords[0] = CartVect( 2, -1, 0 ); 00632 coords[1] = CartVect( 0, 0, 0 ); 00633 coords[2] = CartVect( -2, -1, 0 ); 00634 coords[3] = CartVect( 0, 0, 2 ); 00635 // box edge passes through tet 00636 ASSERT( overlap( coords, CartVect( 0.0, -1.5, 1.5 ), CartVect( 1, 1, 1 ) ) ); 00637 // box edge does not pass through tet 00638 ASSERT( !overlap( coords, CartVect( 0.0, -2.5, 2.5 ), CartVect( 1, 1, 1 ) ) ); 00639 00640 // Box edge -x,+z 00641 coords[0] = CartVect( 2, -1, 0 ); 00642 coords[1] = CartVect( 0, 0, 0 ); 00643 coords[2] = CartVect( 2, 1, 0 ); 00644 coords[3] = CartVect( 0, 0, -2 ); 00645 // box edge passes through tet 00646 ASSERT( overlap( coords, CartVect( 1.5, 0.0, -1.5 ), CartVect( 1, 1, 1 ) ) ); 00647 // box edge does not pass through tet 00648 ASSERT( !overlap( coords, CartVect( 2.5, 0.0, -2.5 ), CartVect( 1, 1, 1 ) ) ); 00649 00650 // Box edge -y,+z 00651 coords[0] = CartVect( -1, 2, 0 ); 00652 coords[1] = CartVect( 1, 2, 0 ); 00653 coords[2] = CartVect( 0, 0, 0 ); 00654 coords[3] = CartVect( 0, 0, -2 ); 00655 // box edge passes through tet 00656 ASSERT( overlap( coords, CartVect( 0.0, 1.5, -1.5 ), CartVect( 1, 1, 1 ) ) ); 00657 // box edge does not pass through tet 00658 ASSERT( !overlap( coords, CartVect( 0.0, 2.5, -2.5 ), CartVect( 1, 1, 1 ) ) ); 00659 00660 // Box edge +x,+z 00661 coords[0] = CartVect( -2, 1, 0 ); 00662 coords[1] = CartVect( -2, -1, 0 ); 00663 coords[2] = CartVect( 0, 0, -2 ); 00664 coords[3] = CartVect( 0, 0, 0 ); 00665 // box edge passes through tet 00666 ASSERT( overlap( coords, CartVect( -1.5, 0.0, -1.5 ), CartVect( 1, 1, 1 ) ) ); 00667 // box edge does not pass through tet 00668 ASSERT( !overlap( coords, CartVect( -2.5, 0.0, -2.5 ), CartVect( 1, 1, 1 ) ) ); 00669 00670 // Box edge +y,+z 00671 coords[0] = CartVect( 0, 0, 0 ); 00672 coords[1] = CartVect( 2, -1, 0 ); 00673 coords[2] = CartVect( -2, -1, 0 ); 00674 coords[3] = CartVect( 0, 0, -2 ); 00675 // box edge passes through tet 00676 ASSERT( overlap( coords, CartVect( 0.0, -1.5, -1.5 ), CartVect( 1, 1, 1 ) ) ); 00677 // box edge does not pass through tet 00678 ASSERT( !overlap( coords, CartVect( 0.0, -2.5, -2.5 ), CartVect( 1, 1, 1 ) ) ); 00679 00680 // Box edge -x,-y 00681 coords[0] = CartVect( 0, 0, 0 ); 00682 coords[1] = CartVect( 0, 2, -1 ); 00683 coords[2] = CartVect( 0, 2, 1 ); 00684 coords[3] = CartVect( 2, 0, 0 ); 00685 // box edge passes through tet 00686 ASSERT( overlap( coords, CartVect( 1.5, 1.5, 0.0 ), CartVect( 1, 1, 1 ) ) ); 00687 // box edge does not pass through tet 00688 ASSERT( !overlap( coords, CartVect( 2.5, 2.5, 0.0 ), CartVect( 1, 1, 1 ) ) ); 00689 00690 // Box edge +x,-y 00691 coords[0] = CartVect( 0, 2, -1 ); 00692 coords[1] = CartVect( 0, 0, 0 ); 00693 coords[2] = CartVect( 0, 2, 1 ); 00694 coords[3] = CartVect( -2, 0, 0 ); 00695 // box edge passes through tet 00696 ASSERT( overlap( coords, CartVect( -1.5, 1.5, 0.0 ), CartVect( 1, 1, 1 ) ) ); 00697 // box edge does not pass through tet 00698 ASSERT( !overlap( coords, CartVect( -2.5, 2.5, 0.0 ), CartVect( 1, 1, 1 ) ) ); 00699 00700 // Box edge -x,+y 00701 coords[0] = CartVect( 0, -2, 1 ); 00702 coords[1] = CartVect( 0, -2, -1 ); 00703 coords[2] = CartVect( 0, 0, 0 ); 00704 coords[3] = CartVect( 2, 0, 0 ); 00705 // box edge passes through tet 00706 ASSERT( overlap( coords, CartVect( 1.5, -1.5, 0.0 ), CartVect( 1, 1, 1 ) ) ); 00707 // box edge does not pass through tet 00708 ASSERT( !overlap( coords, CartVect( 2.5, -2.5, 0.0 ), CartVect( 1, 1, 1 ) ) ); 00709 00710 // Box edge +x,+y 00711 coords[0] = CartVect( 0, -2, -1 ); 00712 coords[1] = CartVect( -2, 0, 0 ); 00713 coords[2] = CartVect( 0, -2, 1 ); 00714 coords[3] = CartVect( 0, 0, 0 ); 00715 // box edge passes through tet 00716 ASSERT( overlap( coords, CartVect( -1.5, -1.5, 0.0 ), CartVect( 1, 1, 1 ) ) ); 00717 // box edge does not pass through tet 00718 ASSERT( !overlap( coords, CartVect( -2.5, -2.5, 0.0 ), CartVect( 1, 1, 1 ) ) ); 00719 00720 // Test tet edge through box 00721 coords[0] = CartVect( -0.13369421660900116, -2.9871494770050049, 0.0526076555252075 ); 00722 coords[1] = CartVect( -0.00350524857640266, -3.3236153125762939, 0.2924639880657196 ); 00723 coords[2] = CartVect( 0.16473215818405151, -2.9966945648193359, -0.1936169415712357 ); 00724 coords[3] = CartVect( 0.26740345358848572, -2.8492588996887207, 0.1519143134355545 ); 00725 ASSERT( overlap( coords, CartVect( -2.5, -2.8, -2.5 ), CartVect( 2.5, 0.31, 2.5 ) ) ); 00726 } 00727 00728 void test_box_tri_overlap() 00729 { 00730 general_box_tri_overlap_test( TypeElemOverlapTest( &box_tri_overlap ) ); 00731 } 00732 00733 void test_box_linear_elem_overlap_tri() 00734 { 00735 general_box_tri_overlap_test( LinearElemOverlapTest( MBTRI ) ); 00736 } 00737 00738 void test_box_hex_overlap() 00739 { 00740 general_box_hex_overlap_test( TypeElemOverlapTest( &box_hex_overlap ) ); 00741 } 00742 00743 void test_box_linear_elem_overlap_hex() 00744 { 00745 general_box_hex_overlap_test( LinearElemOverlapTest( MBHEX ) ); 00746 } 00747 00748 void test_box_tet_overlap() 00749 { 00750 general_box_tet_overlap_test( TypeElemOverlapTest( &box_tet_overlap ) ); 00751 } 00752 00753 void test_box_linear_elem_overlap_tet() 00754 { 00755 general_box_tet_overlap_test( LinearElemOverlapTest( MBTET ) ); 00756 } 00757 00758 void test_ray_tri_intersect() 00759 { 00760 bool xsect; 00761 double t; 00762 00763 // define a triangle 00764 const CartVect tri[3] = { CartVect( 1.0, 0.0, 0.0 ), CartVect( 0.0, 1.0, 0.0 ), CartVect( 0.0, 0.0, 1.0 ) }; 00765 00766 // try a ray through the center of the triangle 00767 xsect = ray_tri_intersect( tri, CartVect( 0.0, 0.0, 0.0 ), CartVect( 1.0, 1.0, 1.0 ), t ); 00768 ASSERT( xsect ); 00769 ASSERT_DOUBLES_EQUAL( 1.0 / 3.0, t ); 00770 00771 // try a same ray, but move base point above triangle 00772 xsect = ray_tri_intersect( tri, CartVect( 1.0, 1.0, 1.0 ), CartVect( 1.0, 1.0, 1.0 ), t ); 00773 ASSERT( !xsect ); 00774 00775 // try a same ray the other direction with base point below triangle 00776 xsect = ray_tri_intersect( tri, CartVect( 0.0, 0.0, 0.0 ), CartVect( -1.0, -1.0, -1.0 ), t ); 00777 ASSERT( !xsect ); 00778 00779 // try a ray that passes above the triangle 00780 xsect = ray_tri_intersect( tri, CartVect( 1.0, 1.0, 1.0 ), CartVect( -1.0, -1.0, 1.0 ), t ); 00781 ASSERT( !xsect ); 00782 00783 // try a skew ray 00784 xsect = ray_tri_intersect( tri, CartVect( 0.0, 0.0, 0.0 ), CartVect( 1.0, 1.0, -0.1 ), t ); 00785 ASSERT( !xsect ); 00786 } 00787 00788 void test_plucker_ray_tri_intersect() 00789 { 00790 bool xsect; 00791 double t; 00792 00793 // define a triangle 00794 const CartVect tri[3] = { CartVect( 1.0, 0.0, 0.0 ), CartVect( 0.0, 1.0, 0.0 ), CartVect( 0.0, 0.0, 1.0 ) }; 00795 00796 // try a ray through the center of the triangle 00797 xsect = plucker_ray_tri_intersect( tri, CartVect( 0.0, 0.0, 0.0 ), CartVect( 1.0, 1.0, 1.0 ), t ); 00798 ASSERT( xsect ); 00799 ASSERT_DOUBLES_EQUAL( 1.0 / 3.0, t ); 00800 00801 // try a same ray, but move base point above triangle 00802 xsect = plucker_ray_tri_intersect( tri, CartVect( 1.0, 1.0, 1.0 ), CartVect( 1.0, 1.0, 1.0 ), t ); 00803 ASSERT( !xsect ); 00804 00805 // try a same ray the other direction with base point below triangle 00806 xsect = plucker_ray_tri_intersect( tri, CartVect( 0.0, 0.0, 0.0 ), CartVect( -1.0, -1.0, -1.0 ), t ); 00807 ASSERT( !xsect ); 00808 00809 // try a ray that passes above the triangle 00810 xsect = plucker_ray_tri_intersect( tri, CartVect( 1.0, 1.0, 1.0 ), CartVect( -1.0, -1.0, 1.0 ), t ); 00811 ASSERT( !xsect ); 00812 00813 // try a skew ray 00814 xsect = plucker_ray_tri_intersect( tri, CartVect( 0.0, 0.0, 0.0 ), CartVect( 1.0, 1.0, -0.1 ), t ); 00815 ASSERT( !xsect ); 00816 00817 // try a ray that intersects with wrong orientation 00818 const int orientation = -1.0; 00819 xsect = plucker_ray_tri_intersect( tri, CartVect( 0.0, 0.0, 0.0 ), CartVect( 1.0, 1.0, 1.0 ), t, NULL, NULL, 00820 &orientation ); 00821 ASSERT( !xsect ); 00822 00823 // try a ray that intersects beyond the nonneg_ray_len 00824 const double nonneg_ray_len = 0.25; 00825 xsect = plucker_ray_tri_intersect( tri, CartVect( 0.0, 0.0, 0.0 ), CartVect( 1.0, 1.0, 1.0 ), t, &nonneg_ray_len ); 00826 ASSERT( !xsect ); 00827 00828 // try a ray that intersects behind the origin 00829 const double neg_ray_len = -2.0; 00830 xsect = plucker_ray_tri_intersect( tri, CartVect( 0.0, 0.0, 0.0 ), CartVect( -1.0, -1.0, -1.0 ), t, NULL, 00831 &neg_ray_len ); 00832 ASSERT( xsect ); 00833 00834 // try a ray that intersects a node 00835 intersection_type int_type; 00836 xsect = plucker_ray_tri_intersect( tri, CartVect( 0.0, 0.0, 0.0 ), CartVect( 1.0, 0.0, 0.0 ), t, NULL, NULL, NULL, 00837 &int_type ); 00838 ASSERT( xsect ); 00839 ASSERT( NODE0 == int_type ); 00840 00841 // try a ray that intersects an edge 00842 xsect = plucker_ray_tri_intersect( tri, CartVect( 0.0, 0.0, 0.0 ), CartVect( 1.0, 1.0, 0.0 ), t, NULL, NULL, NULL, 00843 &int_type ); 00844 ASSERT( xsect ); 00845 ASSERT( EDGE0 == int_type ); 00846 } 00847 00848 void test_closest_location_on_tri() 00849 { 00850 CartVect result, input; 00851 00852 // define a triangle 00853 const CartVect tri[3] = { CartVect( 1.0, 0.0, 0.0 ), CartVect( 0.0, 1.0, 0.0 ), CartVect( 0.0, 0.0, 1.0 ) }; 00854 00855 // try point at triangle centroid 00856 input = CartVect( 1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0 ); 00857 closest_location_on_tri( input, tri, result ); 00858 ASSERT_VECTORS_EQUAL( result, input ); 00859 00860 // try point at each vertex 00861 closest_location_on_tri( tri[0], tri, result ); 00862 ASSERT_VECTORS_EQUAL( result, tri[0] ); 00863 closest_location_on_tri( tri[1], tri, result ); 00864 ASSERT_VECTORS_EQUAL( result, tri[1] ); 00865 closest_location_on_tri( tri[2], tri, result ); 00866 ASSERT_VECTORS_EQUAL( result, tri[2] ); 00867 00868 // try point at center of each edge 00869 input = 0.5 * ( tri[0] + tri[1] ); 00870 closest_location_on_tri( input, tri, result ); 00871 ASSERT_VECTORS_EQUAL( result, input ); 00872 input = 0.5 * ( tri[0] + tri[2] ); 00873 closest_location_on_tri( input, tri, result ); 00874 ASSERT_VECTORS_EQUAL( result, input ); 00875 input = 0.5 * ( tri[2] + tri[1] ); 00876 closest_location_on_tri( input, tri, result ); 00877 ASSERT_VECTORS_EQUAL( result, input ); 00878 00879 // try a point above the center of the triangle 00880 input = CartVect( 1.0, 1.0, 1.0 ); 00881 closest_location_on_tri( input, tri, result ); 00882 ASSERT_VECTORS_EQUAL( result, CartVect( 1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0 ) ); 00883 00884 // try a point below the center of the triangle 00885 input = CartVect( 0.0, 0.0, 0.0 ); 00886 closest_location_on_tri( input, tri, result ); 00887 ASSERT_VECTORS_EQUAL( result, CartVect( 1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0 ) ); 00888 00889 // try a point closest to each vertex and 'outside' of both adjacent edges. 00890 input = 2 * tri[0]; 00891 closest_location_on_tri( input, tri, result ); 00892 ASSERT_VECTORS_EQUAL( result, tri[0] ); 00893 input = 2 * tri[1]; 00894 closest_location_on_tri( input, tri, result ); 00895 ASSERT_VECTORS_EQUAL( result, tri[1] ); 00896 input = 2 * tri[2]; 00897 closest_location_on_tri( input, tri, result ); 00898 ASSERT_VECTORS_EQUAL( result, tri[2] ); 00899 00900 // try a point outside and closest to each edge 00901 input = tri[0] + tri[1]; 00902 closest_location_on_tri( input, tri, result ); 00903 ASSERT_VECTORS_EQUAL( result, 0.5 * input ); 00904 input = tri[2] + tri[1]; 00905 closest_location_on_tri( input, tri, result ); 00906 ASSERT_VECTORS_EQUAL( result, 0.5 * input ); 00907 input = tri[0] + tri[2]; 00908 closest_location_on_tri( input, tri, result ); 00909 ASSERT_VECTORS_EQUAL( result, 0.5 * input ); 00910 00911 // define an equilateral triangle in the xy-plane 00912 const CartVect tri_xy[3] = { CartVect( 0.0, sqrt( 3.0 ) / 2.0, 0.0 ), CartVect( 0.5, 0.0, 0.0 ), 00913 CartVect( -0.5, 0.0, 0.0 ) }; 00914 00915 // for each vertex, test point that is 00916 // - outside triangle 00917 // - closest to vertex 00918 // - 'inside' one of the adjacent edges 00919 // - 'outside' the other adjacent edge 00920 closest_location_on_tri( CartVect( -0.3, 1.2, 0.0 ), tri_xy, result ); 00921 ASSERT_VECTORS_EQUAL( result, tri_xy[0] ); 00922 closest_location_on_tri( CartVect( 0.3, 1.2, 0.0 ), tri_xy, result ); 00923 ASSERT_VECTORS_EQUAL( result, tri_xy[0] ); 00924 closest_location_on_tri( CartVect( 1.0, 0.1, 0.0 ), tri_xy, result ); 00925 ASSERT_VECTORS_EQUAL( result, tri_xy[1] ); 00926 closest_location_on_tri( CartVect( 0.6, -0.5, 0.0 ), tri_xy, result ); 00927 ASSERT_VECTORS_EQUAL( result, tri_xy[1] ); 00928 closest_location_on_tri( CartVect( -0.6, -0.5, 0.0 ), tri_xy, result ); 00929 ASSERT_VECTORS_EQUAL( result, tri_xy[2] ); 00930 closest_location_on_tri( CartVect( -1.0, 0.1, 0.0 ), tri_xy, result ); 00931 ASSERT_VECTORS_EQUAL( result, tri_xy[2] ); 00932 } 00933 00934 void test_closest_location_on_polygon() 00935 { 00936 CartVect result, input; 00937 00938 // define a unit square in xy plane 00939 const CartVect quad[4] = { CartVect( 0.0, 0.0, 0.0 ), CartVect( 1.0, 0.0, 0.0 ), CartVect( 1.0, 1.0, 0.0 ), 00940 CartVect( 0.0, 1.0, 0.0 ) }; 00941 00942 // test input in center of square 00943 closest_location_on_polygon( CartVect( 0.5, 0.5, 0.0 ), quad, 4, result ); 00944 ASSERT_VECTORS_EQUAL( result, CartVect( 0.5, 0.5, 0.0 ) ); 00945 // test above center of square 00946 closest_location_on_polygon( CartVect( 0.5, 0.5, 1.0 ), quad, 4, result ); 00947 ASSERT_VECTORS_EQUAL( result, CartVect( 0.5, 0.5, 0.0 ) ); 00948 // test below center of square 00949 closest_location_on_polygon( CartVect( 0.5, 0.5, -1.0 ), quad, 4, result ); 00950 ASSERT_VECTORS_EQUAL( result, CartVect( 0.5, 0.5, 0.0 ) ); 00951 00952 // test points within square, but not at center 00953 input = CartVect( 0.25, 0.25, 0 ); 00954 closest_location_on_polygon( input, quad, 4, result ); 00955 ASSERT_VECTORS_EQUAL( result, input ); 00956 input = CartVect( 0.75, 0.25, 0 ); 00957 closest_location_on_polygon( input, quad, 4, result ); 00958 ASSERT_VECTORS_EQUAL( result, input ); 00959 input = CartVect( 0.75, 0.75, 0 ); 00960 closest_location_on_polygon( input, quad, 4, result ); 00961 ASSERT_VECTORS_EQUAL( result, input ); 00962 input = CartVect( 0.25, 0.75, 0 ); 00963 closest_location_on_polygon( input, quad, 4, result ); 00964 ASSERT_VECTORS_EQUAL( result, input ); 00965 00966 // test at each corner 00967 closest_location_on_polygon( quad[0], quad, 4, result ); 00968 ASSERT_VECTORS_EQUAL( result, quad[0] ); 00969 closest_location_on_polygon( quad[1], quad, 4, result ); 00970 ASSERT_VECTORS_EQUAL( result, quad[1] ); 00971 closest_location_on_polygon( quad[2], quad, 4, result ); 00972 ASSERT_VECTORS_EQUAL( result, quad[2] ); 00973 closest_location_on_polygon( quad[3], quad, 4, result ); 00974 ASSERT_VECTORS_EQUAL( result, quad[3] ); 00975 00976 // test at point on each edge 00977 input = 0.5 * quad[0] + 0.5 * quad[1]; 00978 closest_location_on_polygon( input, quad, 4, result ); 00979 ASSERT_VECTORS_EQUAL( result, input ); 00980 input = 0.2 * quad[1] + 0.8 * quad[2]; 00981 closest_location_on_polygon( input, quad, 4, result ); 00982 ASSERT_VECTORS_EQUAL( result, input ); 00983 input = 0.7 * quad[2] + 0.3 * quad[3]; 00984 closest_location_on_polygon( input, quad, 4, result ); 00985 ASSERT_VECTORS_EQUAL( result, input ); 00986 input = 0.6 * quad[3] + 0.4 * quad[0]; 00987 closest_location_on_polygon( input, quad, 4, result ); 00988 ASSERT_VECTORS_EQUAL( result, input ); 00989 00990 // test at point outside and closest to each corner 00991 closest_location_on_polygon( CartVect( -1.0, -1.0, 0.0 ), quad, 4, result ); 00992 ASSERT_VECTORS_EQUAL( result, quad[0] ); 00993 closest_location_on_polygon( CartVect( 2.0, -1.0, 0.0 ), quad, 4, result ); 00994 ASSERT_VECTORS_EQUAL( result, quad[1] ); 00995 closest_location_on_polygon( CartVect( 2.0, 2.0, 0.0 ), quad, 4, result ); 00996 ASSERT_VECTORS_EQUAL( result, quad[2] ); 00997 closest_location_on_polygon( CartVect( -1.0, 2.0, 0.0 ), quad, 4, result ); 00998 ASSERT_VECTORS_EQUAL( result, quad[3] ); 00999 01000 // test at point outside and closest to an edge 01001 CartVect x( 1.0, 0.0, 0.0 ), y( 0.0, 1.0, 0.0 ); 01002 input = 0.5 * quad[0] + 0.5 * quad[1]; 01003 closest_location_on_polygon( input - y, quad, 4, result ); 01004 ASSERT_VECTORS_EQUAL( result, input ); 01005 input = 0.2 * quad[1] + 0.8 * quad[2]; 01006 closest_location_on_polygon( input + x, quad, 4, result ); 01007 ASSERT_VECTORS_EQUAL( result, input ); 01008 input = 0.7 * quad[2] + 0.3 * quad[3]; 01009 closest_location_on_polygon( input + y, quad, 4, result ); 01010 ASSERT_VECTORS_EQUAL( result, input ); 01011 input = 0.6 * quad[3] + 0.4 * quad[0]; 01012 closest_location_on_polygon( input - x, quad, 4, result ); 01013 ASSERT_VECTORS_EQUAL( result, input ); 01014 } 01015 01016 void test_segment_box_intersect() 01017 { 01018 const double box_min = 0.0; 01019 const double box_max = 2.0; 01020 const double box_wid = box_max - box_min; 01021 const double box_mid = 0.5 * ( box_min + box_max ); 01022 const CartVect min( box_min ); 01023 const CartVect max( box_max ); 01024 const CartVect X( 1, 0, 0 ), Y( 0, 1, 0 ), Z( 0, 0, 1 ); 01025 CartVect pt; 01026 double start, end; 01027 bool r; 01028 01029 // test line through box in +x direction 01030 double offset = 1; 01031 pt = CartVect( box_min - offset, box_mid, box_mid ); 01032 start = -HUGE_VAL; 01033 end = HUGE_VAL; 01034 r = segment_box_intersect( min, max, pt, X, start, end ); 01035 ASSERT( r ); 01036 ASSERT_DOUBLES_EQUAL( start, box_min + offset ); 01037 ASSERT_DOUBLES_EQUAL( end - start, box_wid ); 01038 01039 // test with ray ending left of the box 01040 start = -HUGE_VAL; 01041 end = 0; 01042 r = segment_box_intersect( min, max, pt, X, start, end ); 01043 ASSERT( !r ); 01044 01045 // test with ray ending within box 01046 start = -HUGE_VAL; 01047 end = box_mid + offset; 01048 r = segment_box_intersect( min, max, pt, X, start, end ); 01049 ASSERT( r ); 01050 ASSERT_DOUBLES_EQUAL( start, box_min + offset ); 01051 ASSERT_DOUBLES_EQUAL( end, box_mid + offset ); 01052 01053 // test with ray beginning within box 01054 start = box_mid + offset; 01055 end = HUGE_VAL; 01056 r = segment_box_intersect( min, max, pt, X, start, end ); 01057 ASSERT( r ); 01058 ASSERT_DOUBLES_EQUAL( start, box_mid + offset ); 01059 ASSERT_DOUBLES_EQUAL( end, box_max + offset ); 01060 01061 // test with ray right of box 01062 start = offset + offset + box_max; 01063 end = HUGE_VAL; 01064 r = segment_box_intersect( min, max, pt, X, start, end ); 01065 ASSERT( !r ); 01066 01067 // test line through box in -y direction 01068 offset = 1; 01069 pt = CartVect( box_mid, box_min - offset, box_mid ); 01070 start = -HUGE_VAL; 01071 end = HUGE_VAL; 01072 r = segment_box_intersect( min, max, pt, -Y, start, end ); 01073 ASSERT( r ); 01074 ASSERT_DOUBLES_EQUAL( end - start, box_wid ); 01075 ASSERT_DOUBLES_EQUAL( end, box_min - offset ); 01076 01077 // test with ray ending left of the box 01078 start = box_min; 01079 end = HUGE_VAL; 01080 r = segment_box_intersect( min, max, pt, -Y, start, end ); 01081 ASSERT( !r ); 01082 01083 // test with ray beginning within box 01084 start = -box_mid - offset; 01085 end = HUGE_VAL; 01086 r = segment_box_intersect( min, max, pt, -Y, start, end ); 01087 ASSERT( r ); 01088 ASSERT_DOUBLES_EQUAL( start, -box_mid - offset ); 01089 ASSERT_DOUBLES_EQUAL( end, box_min - offset ); 01090 01091 // test with ray ending within box 01092 start = -HUGE_VAL; 01093 end = -box_mid - offset; 01094 r = segment_box_intersect( min, max, pt, -Y, start, end ); 01095 ASSERT( r ); 01096 ASSERT_DOUBLES_EQUAL( start, -box_max - offset ); 01097 ASSERT_DOUBLES_EQUAL( end, -box_mid - offset ); 01098 01099 // test with ray right of box 01100 start = -HUGE_VAL; 01101 end = -box_max - offset - offset; 01102 r = segment_box_intersect( min, max, pt, -Y, start, end ); 01103 ASSERT( !r ); 01104 01105 // test ray outside in Z direction, parallel to Z plane, and 01106 // intersecting in projections into other planes 01107 pt = CartVect( box_mid, box_mid, box_max + 1 ); 01108 start = 0; 01109 end = box_wid; 01110 r = segment_box_intersect( min, max, pt, X, start, end ); 01111 ASSERT( !r ); 01112 start = 0; 01113 end = box_wid; 01114 r = segment_box_intersect( min, max, pt, -X, start, end ); 01115 ASSERT( !r ); 01116 start = 0; 01117 end = box_wid; 01118 r = segment_box_intersect( min, max, pt, Y, start, end ); 01119 ASSERT( !r ); 01120 start = 0; 01121 end = box_wid; 01122 r = segment_box_intersect( min, max, pt, -Y, start, end ); 01123 ASSERT( !r ); 01124 01125 // try the other side (less than the min Z); 01126 pt = CartVect( box_mid, box_mid, box_min - 1 ); 01127 start = 0; 01128 end = box_wid; 01129 r = segment_box_intersect( min, max, pt, X, start, end ); 01130 ASSERT( !r ); 01131 start = 0; 01132 end = box_wid; 01133 r = segment_box_intersect( min, max, pt, -X, start, end ); 01134 ASSERT( !r ); 01135 start = 0; 01136 end = box_wid; 01137 r = segment_box_intersect( min, max, pt, Y, start, end ); 01138 ASSERT( !r ); 01139 start = 0; 01140 end = box_wid; 01141 r = segment_box_intersect( min, max, pt, -Y, start, end ); 01142 ASSERT( !r ); 01143 01144 // now move the ray such that it lies exactly on the side of the box 01145 pt = CartVect( box_mid, box_mid, box_min ); 01146 start = 0; 01147 end = box_wid; 01148 r = segment_box_intersect( min, max, pt, X, start, end ); 01149 ASSERT( r ); 01150 ASSERT_DOUBLES_EQUAL( start, 0 ); 01151 ASSERT_DOUBLES_EQUAL( end, 0.5 * box_wid ); 01152 start = 0; 01153 end = box_wid; 01154 r = segment_box_intersect( min, max, pt, -X, start, end ); 01155 ASSERT( r ); 01156 ASSERT_DOUBLES_EQUAL( start, 0 ); 01157 ASSERT_DOUBLES_EQUAL( end, 0.5 * box_wid ); 01158 start = 0; 01159 end = box_wid; 01160 r = segment_box_intersect( min, max, pt, Y, start, end ); 01161 ASSERT( r ); 01162 ASSERT_DOUBLES_EQUAL( start, 0 ); 01163 ASSERT_DOUBLES_EQUAL( end, 0.5 * box_wid ); 01164 start = 0; 01165 end = box_wid; 01166 r = segment_box_intersect( min, max, pt, -Y, start, end ); 01167 ASSERT( r ); 01168 ASSERT_DOUBLES_EQUAL( start, 0 ); 01169 ASSERT_DOUBLES_EQUAL( end, 0.5 * box_wid ); 01170 01171 // try a skew line segment 01172 pt = CartVect( box_min - 0.25 * box_wid, box_mid, box_mid ); 01173 CartVect dir( 1.0 / sqrt( 2.0 ), 1.0 / sqrt( 2.0 ), 0 ); 01174 start = 0; 01175 end = 1.5 / sqrt( 2.0 ) * box_wid; 01176 r = segment_box_intersect( min, max, pt, dir, start, end ); 01177 ASSERT( r ); 01178 ASSERT_DOUBLES_EQUAL( start, 0.5 / sqrt( 2.0 ) * box_wid ); 01179 ASSERT_DOUBLES_EQUAL( end, box_wid / sqrt( 2.0 ) ); 01180 01181 // try with skew line segment that just touches edge of box 01182 pt = CartVect( box_min - 0.5 * box_wid, box_mid, box_mid ); 01183 start = 0; 01184 end = 3.0 / sqrt( 2.0 ) * box_wid; 01185 r = segment_box_intersect( min, max, pt, dir, start, end ); 01186 ASSERT( r ); 01187 ASSERT_DOUBLES_EQUAL( start, box_wid / sqrt( 2.0 ) ); 01188 ASSERT_DOUBLES_EQUAL( end, box_wid / sqrt( 2.0 ) ); 01189 01190 // try with skew line segment outside of box 01191 pt = CartVect( box_min - 0.75 * box_wid, box_mid, box_mid ); 01192 start = 0; 01193 end = 3.0 / sqrt( 2.0 ) * box_wid; 01194 r = segment_box_intersect( min, max, pt, dir, start, end ); 01195 ASSERT( !r ); 01196 } 01197 01198 void test_closest_location_on_box() 01199 { 01200 const CartVect min( 0, 0, 0 ), max( 1, 2, 3 ); 01201 CartVect pt; 01202 01203 // inside 01204 closest_location_on_box( min, max, CartVect( 0.5, 0.5, 0.5 ), pt ); 01205 ASSERT_VECTORS_EQUAL( CartVect( 0.5, 0.5, 0.5 ), pt ); 01206 01207 // closest to min x side 01208 closest_location_on_box( min, max, CartVect( -1.0, 0.5, 0.5 ), pt ); 01209 ASSERT_VECTORS_EQUAL( CartVect( 0.0, 0.5, 0.5 ), pt ); 01210 01211 // closest to max x side 01212 closest_location_on_box( min, max, CartVect( 2.0, 0.5, 0.5 ), pt ); 01213 ASSERT_VECTORS_EQUAL( CartVect( 1.0, 0.5, 0.5 ), pt ); 01214 01215 // closest to min y side 01216 closest_location_on_box( min, max, CartVect( 0.5, -1.0, 0.5 ), pt ); 01217 ASSERT_VECTORS_EQUAL( CartVect( 0.5, 0.0, 0.5 ), pt ); 01218 01219 // closest to max y side 01220 closest_location_on_box( min, max, CartVect( 0.5, 2.5, 0.5 ), pt ); 01221 ASSERT_VECTORS_EQUAL( CartVect( 0.5, 2.0, 0.5 ), pt ); 01222 01223 // closest to min z side 01224 closest_location_on_box( min, max, CartVect( 0.5, 0.5, -0.1 ), pt ); 01225 ASSERT_VECTORS_EQUAL( CartVect( 0.5, 0.5, 0.0 ), pt ); 01226 01227 // closest to max z side 01228 closest_location_on_box( min, max, CartVect( 0.5, 0.5, 100.0 ), pt ); 01229 ASSERT_VECTORS_EQUAL( CartVect( 0.5, 0.5, 3.0 ), pt ); 01230 01231 // closest to min corner 01232 closest_location_on_box( min, max, CartVect( -1, -1, -1 ), pt ); 01233 ASSERT_VECTORS_EQUAL( min, pt ); 01234 01235 // closest to max corner 01236 closest_location_on_box( min, max, CartVect( 2, 3, 4 ), pt ); 01237 ASSERT_VECTORS_EQUAL( max, pt ); 01238 } 01239 01240 int main() 01241 { 01242 int error_count = 0; 01243 error_count += RUN_TEST( test_box_plane_overlap ); 01244 error_count += RUN_TEST( test_box_linear_elem_overlap_tri ); 01245 error_count += RUN_TEST( test_box_linear_elem_overlap_tet ); 01246 error_count += RUN_TEST( test_box_linear_elem_overlap_hex ); 01247 error_count += RUN_TEST( test_box_tri_overlap ); 01248 error_count += RUN_TEST( test_box_tet_overlap ); 01249 error_count += RUN_TEST( test_box_hex_overlap ); 01250 error_count += RUN_TEST( test_ray_tri_intersect ); 01251 error_count += RUN_TEST( test_plucker_ray_tri_intersect ); 01252 error_count += RUN_TEST( test_closest_location_on_tri ); 01253 error_count += RUN_TEST( test_closest_location_on_polygon ); 01254 error_count += RUN_TEST( test_segment_box_intersect ); 01255 error_count += RUN_TEST( test_closest_location_on_box ); 01256 return error_count; 01257 }