MOAB: Mesh Oriented datABase  (version 5.3.0)
oriented_box_test.cpp
Go to the documentation of this file.
00001 #include "moab/OrientedBox.hpp"
00002 #include "moab/CartVect.hpp"
00003 #include "moab/Core.hpp"
00004 #include "moab/Range.hpp"
00005 
00006 using namespace moab;
00007 
00008 #include <cassert>
00009 
00010 const double TOL = 1e-6;
00011 int error_count  = 0;
00012 
00013 static void test_basic();  // test basic properties (volume(), etc.)
00014 static void test_contained();
00015 static void test_ray_intersect();
00016 static void test_closest_point();
00017 static void test_build_from_tri();
00018 static void test_build_from_pts();
00019 static void test_save();
00020 
00021 #include <iostream>
00022 #define ASSERT_VECTOR_ELEMENT( A, B ) assert_vector_element( ( A ), ( B ), #A, #B, __LINE__ )
00023 #define ASSERT_VECTORS_EQUAL( A, B )  assert_vectors_equal( ( A ), ( B ), #A, #B, __LINE__ )
00024 #define ASSERT_DOUBLES_EQUAL( A, B )  assert_doubles_equal( ( A ), ( B ), #A, #B, __LINE__ )
00025 #define ASSERT( B )                   assert_bool( ( B ), #B, __LINE__ )
00026 
00027 static void assert_vector_element( const CartVect& a, const Matrix3& b, const char* sa, const char* sb, int lineno );
00028 static void assert_vectors_equal( const CartVect& a, const CartVect& b, const char* sa, const char* sb, int lineno );
00029 static void assert_doubles_equal( double a, double b, const char* sa, const char* sb, int lineno );
00030 static void assert_bool( bool b, const char* sb, int lineno );
00031 
00032 int main()
00033 {
00034     test_basic();
00035     test_contained();
00036     test_ray_intersect();
00037     test_closest_point();
00038     test_build_from_tri();
00039     test_build_from_pts();
00040     test_save();
00041     return error_count;
00042 }
00043 
00044 /********************* Declare some boxes to test ***************************/
00045 
00046 // define unit box centered at origin
00047 const CartVect origin( 0.0, 0.0, 0.0 );
00048 const Matrix3 unitaxes( 0.5, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.5 );
00049 const OrientedBox unitbox( unitaxes, origin );
00050 
00051 // define axis-aligned unit box outside origin
00052 const CartVect unitcenter( 10, 20, 30 );
00053 const OrientedBox offsetbox( unitaxes, unitcenter );
00054 
00055 // define non-unit centered at origin
00056 const Matrix3 origaxes( 5 * unitaxes.col( 0 ), 10 * unitaxes.col( 1 ), 0.1 * unitaxes.col( 2 ), true );
00057 const OrientedBox oblongbox( origaxes, origin );
00058 
00059 // define non-axis-aligned box at origin (non unit) ;
00060 // the constructor of OrientedBox normalizes the vectors, and keeps the scales
00061 const CartVect rotax0   = CartVect( 1.0, 1.0, 0.0 );
00062 const CartVect rotax1   = CartVect( 1.0, -1.0, 1.0 );
00063 const CartVect rotax2   = CartVect( 1.0, 1.0, 0.0 ) * CartVect( 1.0, -1.0, 1.0 );
00064 const CartVect rotax[3] = { rotax0, rotax1, rotax2 };
00065 const OrientedBox rotbox_cv( rotax, origin );
00066 
00067 const Matrix3 rotaxes( rotax0, rotax1, rotax2,
00068                        false );  // so these are columns, as in the constructor that takes 3 "CartVect"s
00069 const OrientedBox rotbox( rotaxes, origin );
00070 
00071 /********************* Utility methods for tests ***************************/
00072 
00073 // return point at specified fraction between box center and specified box corner
00074 static CartVect scaled_corner( const OrientedBox& box, int corner, double factor )
00075 {
00076     static const int signs[][3] = { { 1, 1, -1 }, { -1, 1, -1 }, { -1, -1, -1 }, { 1, -1, -1 },
00077                                     { 1, 1, 1 },  { -1, 1, 1 },  { -1, -1, 1 },  { 1, -1, 1 } };
00078     return box.center + signs[corner][0] * factor * box.scaled_axis( 0 ) +
00079            signs[corner][1] * factor * box.scaled_axis( 1 ) + signs[corner][2] * factor * box.scaled_axis( 2 );
00080 }
00081 
00082 // return point at specified fraction between box center and specified box face
00083 static CartVect scaled_face( const OrientedBox& box, int face, double factor )
00084 {
00085     assert( face >= 0 && face <= 6 );
00086     int sign = face % 2 ? -1 : 1;
00087     return box.center + factor * sign * box.scaled_axis( face / 2 );
00088 }
00089 
00090 // get vector containing axis lengths, ordered from smallest to largest
00091 static void axis_dims( const Matrix3& axis, CartVect& dims )
00092 {
00093     dims = CartVect( axis.col( 0 ).length(), axis.col( 1 ).length(), axis.col( 2 ).length() );
00094     if( dims[0] > dims[1] ) std::swap( dims[0], dims[1] );
00095     if( dims[1] > dims[2] ) std::swap( dims[1], dims[2] );
00096     if( dims[0] > dims[1] ) std::swap( dims[0], dims[1] );
00097 }
00098 
00099 /********************* The Actual Tests ***************************/
00100 // \test Check all basic Oriented Box tests
00101 static void test_basic()
00102 {
00103     CartVect dims;
00104 
00105     axis_dims( unitaxes, dims );
00106     ASSERT_VECTORS_EQUAL( unitbox.center, origin );
00107     ASSERT_VECTOR_ELEMENT( unitbox.scaled_axis( 0 ), unitaxes );
00108     ASSERT_VECTOR_ELEMENT( unitbox.scaled_axis( 1 ), unitaxes );
00109     ASSERT_VECTOR_ELEMENT( unitbox.scaled_axis( 2 ), unitaxes );
00110     ASSERT_DOUBLES_EQUAL( unitbox.inner_radius(), dims[0] );
00111     ASSERT_DOUBLES_EQUAL( unitbox.outer_radius(), dims.length() );
00112     ASSERT_DOUBLES_EQUAL( unitbox.volume(), 8.0 * dims[0] * dims[1] * dims[2] );
00113     ASSERT_VECTORS_EQUAL( unitbox.dimensions(), 2 * dims );
00114 
00115     axis_dims( unitaxes, dims );
00116     ASSERT_VECTORS_EQUAL( offsetbox.center, unitcenter );
00117     ASSERT_VECTOR_ELEMENT( offsetbox.scaled_axis( 0 ), unitaxes );
00118     ASSERT_VECTOR_ELEMENT( offsetbox.scaled_axis( 1 ), unitaxes );
00119     ASSERT_VECTOR_ELEMENT( offsetbox.scaled_axis( 2 ), unitaxes );
00120     ASSERT_DOUBLES_EQUAL( offsetbox.inner_radius(), dims[0] );
00121     ASSERT_DOUBLES_EQUAL( offsetbox.outer_radius(), dims.length() );
00122     ASSERT_DOUBLES_EQUAL( offsetbox.volume(), 8.0 * dims[0] * dims[1] * dims[2] );
00123     ASSERT_VECTORS_EQUAL( offsetbox.dimensions(), 2 * dims );
00124 
00125     axis_dims( origaxes, dims );
00126     ASSERT_VECTORS_EQUAL( oblongbox.center, origin );
00127     ASSERT_VECTOR_ELEMENT( oblongbox.scaled_axis( 0 ), origaxes );
00128     ASSERT_VECTOR_ELEMENT( oblongbox.scaled_axis( 1 ), origaxes );
00129     ASSERT_VECTOR_ELEMENT( oblongbox.scaled_axis( 2 ), origaxes );
00130     ASSERT_DOUBLES_EQUAL( oblongbox.inner_radius(), dims[0] );
00131     ASSERT_DOUBLES_EQUAL( oblongbox.outer_radius(), dims.length() );
00132     ASSERT_DOUBLES_EQUAL( oblongbox.volume(), 8.0 * dims[0] * dims[1] * dims[2] );
00133     ASSERT_VECTORS_EQUAL( oblongbox.dimensions(), 2 * dims );
00134 
00135     // test matrix constructor
00136     axis_dims( rotaxes, dims );
00137     ASSERT_VECTORS_EQUAL( rotbox.center, origin );
00138     ASSERT_VECTOR_ELEMENT( rotbox.scaled_axis( 0 ), rotaxes );
00139     ASSERT_VECTOR_ELEMENT( rotbox.scaled_axis( 1 ), rotaxes );
00140     ASSERT_VECTOR_ELEMENT( rotbox.scaled_axis( 2 ), rotaxes );
00141     ASSERT_DOUBLES_EQUAL( rotbox.inner_radius(), dims[0] );
00142     ASSERT_DOUBLES_EQUAL( rotbox.outer_radius(), dims.length() );
00143     ASSERT_DOUBLES_EQUAL( rotbox.volume(), 8.0 * dims[0] * dims[1] * dims[2] );
00144     ASSERT_VECTORS_EQUAL( rotbox.dimensions(), 2 * dims );
00145 
00146     // test cartvect constructor; ordering of the axes by length happens in the constructor
00147     ASSERT_VECTORS_EQUAL( rotbox_cv.center, origin );
00148     ASSERT_VECTORS_EQUAL( rotbox_cv.scaled_axis( 0 ), rotax0 );
00149     ASSERT_VECTORS_EQUAL( rotbox_cv.scaled_axis( 1 ), rotax1 );
00150     ASSERT_VECTORS_EQUAL( rotbox_cv.scaled_axis( 2 ), rotax2 );
00151     ASSERT_DOUBLES_EQUAL( rotbox_cv.inner_radius(), dims[0] );
00152     ASSERT_DOUBLES_EQUAL( rotbox_cv.outer_radius(), dims.length() );
00153     ASSERT_DOUBLES_EQUAL( rotbox_cv.volume(), 8.0 * dims[0] * dims[1] * dims[2] );
00154     ASSERT_VECTORS_EQUAL( rotbox_cv.dimensions(), 2 * dims );
00155 }
00156 
00157 // \test Check all is_contained Oriented Box tests
00158 static void test_contained()
00159 {
00160     // first do tests of unit box
00161 
00162     // test points inside box
00163     ASSERT( unitbox.contained( unitbox.center, TOL ) );
00164     ASSERT( unitbox.contained( scaled_corner( unitbox, 0, 0.6 ), TOL ) );
00165     ASSERT( unitbox.contained( scaled_corner( unitbox, 1, 0.6 ), TOL ) );
00166     ASSERT( unitbox.contained( scaled_corner( unitbox, 2, 0.6 ), TOL ) );
00167     ASSERT( unitbox.contained( scaled_corner( unitbox, 3, 0.6 ), TOL ) );
00168     ASSERT( unitbox.contained( scaled_corner( unitbox, 4, 0.6 ), TOL ) );
00169     ASSERT( unitbox.contained( scaled_corner( unitbox, 5, 0.6 ), TOL ) );
00170     ASSERT( unitbox.contained( scaled_corner( unitbox, 6, 0.6 ), TOL ) );
00171     ASSERT( unitbox.contained( scaled_corner( unitbox, 7, 0.6 ), TOL ) );
00172 
00173     // test points at box corners
00174     ASSERT( unitbox.contained( scaled_corner( unitbox, 0, 1.0 ), TOL ) );
00175     ASSERT( unitbox.contained( scaled_corner( unitbox, 1, 1.0 ), TOL ) );
00176     ASSERT( unitbox.contained( scaled_corner( unitbox, 2, 1.0 ), TOL ) );
00177     ASSERT( unitbox.contained( scaled_corner( unitbox, 3, 1.0 ), TOL ) );
00178     ASSERT( unitbox.contained( scaled_corner( unitbox, 4, 1.0 ), TOL ) );
00179     ASSERT( unitbox.contained( scaled_corner( unitbox, 5, 1.0 ), TOL ) );
00180     ASSERT( unitbox.contained( scaled_corner( unitbox, 6, 1.0 ), TOL ) );
00181     ASSERT( unitbox.contained( scaled_corner( unitbox, 7, 1.0 ), TOL ) );
00182 
00183     // test points at center of each face
00184     ASSERT( unitbox.contained( scaled_face( unitbox, 0, 1.0 ), TOL ) );
00185     ASSERT( unitbox.contained( scaled_face( unitbox, 1, 1.0 ), TOL ) );
00186     ASSERT( unitbox.contained( scaled_face( unitbox, 2, 1.0 ), TOL ) );
00187     ASSERT( unitbox.contained( scaled_face( unitbox, 3, 1.0 ), TOL ) );
00188     ASSERT( unitbox.contained( scaled_face( unitbox, 4, 1.0 ), TOL ) );
00189     ASSERT( unitbox.contained( scaled_face( unitbox, 5, 1.0 ), TOL ) );
00190 
00191     // test points beyond each corner
00192     ASSERT( !unitbox.contained( scaled_corner( unitbox, 0, 1.2 ), TOL ) );
00193     ASSERT( !unitbox.contained( scaled_corner( unitbox, 1, 1.2 ), TOL ) );
00194     ASSERT( !unitbox.contained( scaled_corner( unitbox, 2, 1.2 ), TOL ) );
00195     ASSERT( !unitbox.contained( scaled_corner( unitbox, 3, 1.2 ), TOL ) );
00196     ASSERT( !unitbox.contained( scaled_corner( unitbox, 4, 1.2 ), TOL ) );
00197     ASSERT( !unitbox.contained( scaled_corner( unitbox, 5, 1.2 ), TOL ) );
00198     ASSERT( !unitbox.contained( scaled_corner( unitbox, 6, 1.2 ), TOL ) );
00199     ASSERT( !unitbox.contained( scaled_corner( unitbox, 7, 1.2 ), TOL ) );
00200 
00201     // test points beyond the center of each face
00202     ASSERT( !unitbox.contained( scaled_face( unitbox, 0, 1.3 ), TOL ) );
00203     ASSERT( !unitbox.contained( scaled_face( unitbox, 1, 1.3 ), TOL ) );
00204     ASSERT( !unitbox.contained( scaled_face( unitbox, 2, 1.3 ), TOL ) );
00205     ASSERT( !unitbox.contained( scaled_face( unitbox, 3, 1.3 ), TOL ) );
00206     ASSERT( !unitbox.contained( scaled_face( unitbox, 4, 1.3 ), TOL ) );
00207     ASSERT( !unitbox.contained( scaled_face( unitbox, 5, 1.3 ), TOL ) );
00208 
00209     // now do offset box
00210 
00211     // test points inside box
00212     ASSERT( offsetbox.contained( offsetbox.center, TOL ) );
00213     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 0, 0.6 ), TOL ) );
00214     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 1, 0.6 ), TOL ) );
00215     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 2, 0.6 ), TOL ) );
00216     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 3, 0.6 ), TOL ) );
00217     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 4, 0.6 ), TOL ) );
00218     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 5, 0.6 ), TOL ) );
00219     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 6, 0.6 ), TOL ) );
00220     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 7, 0.6 ), TOL ) );
00221 
00222     // test points at box corners
00223     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 0, 1.0 ), TOL ) );
00224     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 1, 1.0 ), TOL ) );
00225     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 2, 1.0 ), TOL ) );
00226     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 3, 1.0 ), TOL ) );
00227     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 4, 1.0 ), TOL ) );
00228     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 5, 1.0 ), TOL ) );
00229     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 6, 1.0 ), TOL ) );
00230     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 7, 1.0 ), TOL ) );
00231 
00232     // test points at center of each face
00233     ASSERT( offsetbox.contained( scaled_face( offsetbox, 0, 1.0 ), TOL ) );
00234     ASSERT( offsetbox.contained( scaled_face( offsetbox, 1, 1.0 ), TOL ) );
00235     ASSERT( offsetbox.contained( scaled_face( offsetbox, 2, 1.0 ), TOL ) );
00236     ASSERT( offsetbox.contained( scaled_face( offsetbox, 3, 1.0 ), TOL ) );
00237     ASSERT( offsetbox.contained( scaled_face( offsetbox, 4, 1.0 ), TOL ) );
00238     ASSERT( offsetbox.contained( scaled_face( offsetbox, 5, 1.0 ), TOL ) );
00239 
00240     // test points beyond each corner
00241     ASSERT( !offsetbox.contained( scaled_corner( offsetbox, 0, 1.2 ), TOL ) );
00242     ASSERT( !offsetbox.contained( scaled_corner( offsetbox, 1, 1.2 ), TOL ) );
00243     ASSERT( !offsetbox.contained( scaled_corner( offsetbox, 2, 1.2 ), TOL ) );
00244     ASSERT( !offsetbox.contained( scaled_corner( offsetbox, 3, 1.2 ), TOL ) );
00245     ASSERT( !offsetbox.contained( scaled_corner( offsetbox, 4, 1.2 ), TOL ) );
00246     ASSERT( !offsetbox.contained( scaled_corner( offsetbox, 5, 1.2 ), TOL ) );
00247     ASSERT( !offsetbox.contained( scaled_corner( offsetbox, 6, 1.2 ), TOL ) );
00248     ASSERT( !offsetbox.contained( scaled_corner( offsetbox, 7, 1.2 ), TOL ) );
00249 
00250     // test points beyond the center of each face
00251     ASSERT( !offsetbox.contained( scaled_face( offsetbox, 0, 1.3 ), TOL ) );
00252     ASSERT( !offsetbox.contained( scaled_face( offsetbox, 1, 1.3 ), TOL ) );
00253     ASSERT( !offsetbox.contained( scaled_face( offsetbox, 2, 1.3 ), TOL ) );
00254     ASSERT( !offsetbox.contained( scaled_face( offsetbox, 3, 1.3 ), TOL ) );
00255     ASSERT( !offsetbox.contained( scaled_face( offsetbox, 4, 1.3 ), TOL ) );
00256     ASSERT( !offsetbox.contained( scaled_face( offsetbox, 5, 1.3 ), TOL ) );
00257 
00258     // now do oblong box
00259 
00260     // test points inside box
00261     ASSERT( oblongbox.contained( oblongbox.center, TOL ) );
00262     ASSERT( oblongbox.contained( scaled_corner( oblongbox, 0, 0.6 ), TOL ) );
00263     ASSERT( oblongbox.contained( scaled_corner( oblongbox, 1, 0.6 ), TOL ) );
00264     ASSERT( oblongbox.contained( scaled_corner( oblongbox, 2, 0.6 ), TOL ) );
00265     ASSERT( oblongbox.contained( scaled_corner( oblongbox, 3, 0.6 ), TOL ) );
00266     ASSERT( oblongbox.contained( scaled_corner( oblongbox, 4, 0.6 ), TOL ) );
00267     ASSERT( oblongbox.contained( scaled_corner( oblongbox, 5, 0.6 ), TOL ) );
00268     ASSERT( oblongbox.contained( scaled_corner( oblongbox, 6, 0.6 ), TOL ) );
00269     ASSERT( oblongbox.contained( scaled_corner( oblongbox, 7, 0.6 ), TOL ) );
00270 
00271     // test points at box corners
00272     ASSERT( oblongbox.contained( scaled_corner( oblongbox, 0, 1.0 ), TOL ) );
00273     ASSERT( oblongbox.contained( scaled_corner( oblongbox, 1, 1.0 ), TOL ) );
00274     ASSERT( oblongbox.contained( scaled_corner( oblongbox, 2, 1.0 ), TOL ) );
00275     ASSERT( oblongbox.contained( scaled_corner( oblongbox, 3, 1.0 ), TOL ) );
00276     ASSERT( oblongbox.contained( scaled_corner( oblongbox, 4, 1.0 ), TOL ) );
00277     ASSERT( oblongbox.contained( scaled_corner( oblongbox, 5, 1.0 ), TOL ) );
00278     ASSERT( oblongbox.contained( scaled_corner( oblongbox, 6, 1.0 ), TOL ) );
00279     ASSERT( oblongbox.contained( scaled_corner( oblongbox, 7, 1.0 ), TOL ) );
00280 
00281     // test points at center of each face
00282     ASSERT( oblongbox.contained( scaled_face( oblongbox, 0, 1.0 ), TOL ) );
00283     ASSERT( oblongbox.contained( scaled_face( oblongbox, 1, 1.0 ), TOL ) );
00284     ASSERT( oblongbox.contained( scaled_face( oblongbox, 2, 1.0 ), TOL ) );
00285     ASSERT( oblongbox.contained( scaled_face( oblongbox, 3, 1.0 ), TOL ) );
00286     ASSERT( oblongbox.contained( scaled_face( oblongbox, 4, 1.0 ), TOL ) );
00287     ASSERT( oblongbox.contained( scaled_face( oblongbox, 5, 1.0 ), TOL ) );
00288 
00289     // test points beyond each corner
00290     ASSERT( !oblongbox.contained( scaled_corner( oblongbox, 0, 1.2 ), TOL ) );
00291     ASSERT( !oblongbox.contained( scaled_corner( oblongbox, 1, 1.2 ), TOL ) );
00292     ASSERT( !oblongbox.contained( scaled_corner( oblongbox, 2, 1.2 ), TOL ) );
00293     ASSERT( !oblongbox.contained( scaled_corner( oblongbox, 3, 1.2 ), TOL ) );
00294     ASSERT( !oblongbox.contained( scaled_corner( oblongbox, 4, 1.2 ), TOL ) );
00295     ASSERT( !oblongbox.contained( scaled_corner( oblongbox, 5, 1.2 ), TOL ) );
00296     ASSERT( !oblongbox.contained( scaled_corner( oblongbox, 6, 1.2 ), TOL ) );
00297     ASSERT( !oblongbox.contained( scaled_corner( oblongbox, 7, 1.2 ), TOL ) );
00298 
00299     // test points beyond the center of each face
00300     ASSERT( !oblongbox.contained( scaled_face( oblongbox, 0, 1.3 ), TOL ) );
00301     ASSERT( !oblongbox.contained( scaled_face( oblongbox, 1, 1.3 ), TOL ) );
00302     ASSERT( !oblongbox.contained( scaled_face( oblongbox, 2, 1.3 ), TOL ) );
00303     ASSERT( !oblongbox.contained( scaled_face( oblongbox, 3, 1.3 ), TOL ) );
00304     ASSERT( !oblongbox.contained( scaled_face( oblongbox, 4, 1.3 ), TOL ) );
00305     ASSERT( !oblongbox.contained( scaled_face( oblongbox, 5, 1.3 ), TOL ) );
00306 
00307     // now do offset box
00308 
00309     // test points inside box
00310     ASSERT( offsetbox.contained( offsetbox.center, TOL ) );
00311     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 0, 0.6 ), TOL ) );
00312     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 1, 0.6 ), TOL ) );
00313     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 2, 0.6 ), TOL ) );
00314     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 3, 0.6 ), TOL ) );
00315     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 4, 0.6 ), TOL ) );
00316     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 5, 0.6 ), TOL ) );
00317     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 6, 0.6 ), TOL ) );
00318     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 7, 0.6 ), TOL ) );
00319 
00320     // test points at box corners
00321     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 0, 1.0 ), TOL ) );
00322     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 1, 1.0 ), TOL ) );
00323     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 2, 1.0 ), TOL ) );
00324     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 3, 1.0 ), TOL ) );
00325     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 4, 1.0 ), TOL ) );
00326     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 5, 1.0 ), TOL ) );
00327     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 6, 1.0 ), TOL ) );
00328     ASSERT( offsetbox.contained( scaled_corner( offsetbox, 7, 1.0 ), TOL ) );
00329 
00330     // test points at center of each face
00331     ASSERT( offsetbox.contained( scaled_face( offsetbox, 0, 1.0 ), TOL ) );
00332     ASSERT( offsetbox.contained( scaled_face( offsetbox, 1, 1.0 ), TOL ) );
00333     ASSERT( offsetbox.contained( scaled_face( offsetbox, 2, 1.0 ), TOL ) );
00334     ASSERT( offsetbox.contained( scaled_face( offsetbox, 3, 1.0 ), TOL ) );
00335     ASSERT( offsetbox.contained( scaled_face( offsetbox, 4, 1.0 ), TOL ) );
00336     ASSERT( offsetbox.contained( scaled_face( offsetbox, 5, 1.0 ), TOL ) );
00337 
00338     // test points beyond each corner
00339     ASSERT( !offsetbox.contained( scaled_corner( offsetbox, 0, 1.2 ), TOL ) );
00340     ASSERT( !offsetbox.contained( scaled_corner( offsetbox, 1, 1.2 ), TOL ) );
00341     ASSERT( !offsetbox.contained( scaled_corner( offsetbox, 2, 1.2 ), TOL ) );
00342     ASSERT( !offsetbox.contained( scaled_corner( offsetbox, 3, 1.2 ), TOL ) );
00343     ASSERT( !offsetbox.contained( scaled_corner( offsetbox, 4, 1.2 ), TOL ) );
00344     ASSERT( !offsetbox.contained( scaled_corner( offsetbox, 5, 1.2 ), TOL ) );
00345     ASSERT( !offsetbox.contained( scaled_corner( offsetbox, 6, 1.2 ), TOL ) );
00346     ASSERT( !offsetbox.contained( scaled_corner( offsetbox, 7, 1.2 ), TOL ) );
00347 
00348     // test points beyond the center of each face
00349     ASSERT( !offsetbox.contained( scaled_face( offsetbox, 0, 1.3 ), TOL ) );
00350     ASSERT( !offsetbox.contained( scaled_face( offsetbox, 1, 1.3 ), TOL ) );
00351     ASSERT( !offsetbox.contained( scaled_face( offsetbox, 2, 1.3 ), TOL ) );
00352     ASSERT( !offsetbox.contained( scaled_face( offsetbox, 3, 1.3 ), TOL ) );
00353     ASSERT( !offsetbox.contained( scaled_face( offsetbox, 4, 1.3 ), TOL ) );
00354     ASSERT( !offsetbox.contained( scaled_face( offsetbox, 5, 1.3 ), TOL ) );
00355 
00356     // now do rotated box
00357 
00358     // test points inside box
00359     ASSERT( rotbox.contained( rotbox.center, TOL ) );
00360     ASSERT( rotbox.contained( scaled_corner( rotbox, 0, 0.6 ), TOL ) );
00361     ASSERT( rotbox.contained( scaled_corner( rotbox, 1, 0.6 ), TOL ) );
00362     ASSERT( rotbox.contained( scaled_corner( rotbox, 2, 0.6 ), TOL ) );
00363     ASSERT( rotbox.contained( scaled_corner( rotbox, 3, 0.6 ), TOL ) );
00364     ASSERT( rotbox.contained( scaled_corner( rotbox, 4, 0.6 ), TOL ) );
00365     ASSERT( rotbox.contained( scaled_corner( rotbox, 5, 0.6 ), TOL ) );
00366     ASSERT( rotbox.contained( scaled_corner( rotbox, 6, 0.6 ), TOL ) );
00367     ASSERT( rotbox.contained( scaled_corner( rotbox, 7, 0.6 ), TOL ) );
00368 
00369     // test points at box corners
00370     ASSERT( rotbox.contained( scaled_corner( rotbox, 0, 1.0 ), TOL ) );
00371     ASSERT( rotbox.contained( scaled_corner( rotbox, 1, 1.0 ), TOL ) );
00372     ASSERT( rotbox.contained( scaled_corner( rotbox, 2, 1.0 ), TOL ) );
00373     ASSERT( rotbox.contained( scaled_corner( rotbox, 3, 1.0 ), TOL ) );
00374     ASSERT( rotbox.contained( scaled_corner( rotbox, 4, 1.0 ), TOL ) );
00375     ASSERT( rotbox.contained( scaled_corner( rotbox, 5, 1.0 ), TOL ) );
00376     ASSERT( rotbox.contained( scaled_corner( rotbox, 6, 1.0 ), TOL ) );
00377     ASSERT( rotbox.contained( scaled_corner( rotbox, 7, 1.0 ), TOL ) );
00378 
00379     // test points at center of each face
00380     ASSERT( rotbox.contained( scaled_face( rotbox, 0, 1.0 ), TOL ) );
00381     ASSERT( rotbox.contained( scaled_face( rotbox, 1, 1.0 ), TOL ) );
00382     ASSERT( rotbox.contained( scaled_face( rotbox, 2, 1.0 ), TOL ) );
00383     ASSERT( rotbox.contained( scaled_face( rotbox, 3, 1.0 ), TOL ) );
00384     ASSERT( rotbox.contained( scaled_face( rotbox, 4, 1.0 ), TOL ) );
00385     ASSERT( rotbox.contained( scaled_face( rotbox, 5, 1.0 ), TOL ) );
00386 
00387     // test points beyond each corner
00388     ASSERT( !rotbox.contained( scaled_corner( rotbox, 0, 1.2 ), TOL ) );
00389     ASSERT( !rotbox.contained( scaled_corner( rotbox, 1, 1.2 ), TOL ) );
00390     ASSERT( !rotbox.contained( scaled_corner( rotbox, 2, 1.2 ), TOL ) );
00391     ASSERT( !rotbox.contained( scaled_corner( rotbox, 3, 1.2 ), TOL ) );
00392     ASSERT( !rotbox.contained( scaled_corner( rotbox, 4, 1.2 ), TOL ) );
00393     ASSERT( !rotbox.contained( scaled_corner( rotbox, 5, 1.2 ), TOL ) );
00394     ASSERT( !rotbox.contained( scaled_corner( rotbox, 6, 1.2 ), TOL ) );
00395     ASSERT( !rotbox.contained( scaled_corner( rotbox, 7, 1.2 ), TOL ) );
00396 
00397     // test points beyond the center of each face
00398     ASSERT( !rotbox.contained( scaled_face( rotbox, 0, 1.3 ), TOL ) );
00399     ASSERT( !rotbox.contained( scaled_face( rotbox, 1, 1.3 ), TOL ) );
00400     ASSERT( !rotbox.contained( scaled_face( rotbox, 2, 1.3 ), TOL ) );
00401     ASSERT( !rotbox.contained( scaled_face( rotbox, 3, 1.3 ), TOL ) );
00402     ASSERT( !rotbox.contained( scaled_face( rotbox, 4, 1.3 ), TOL ) );
00403     ASSERT( !rotbox.contained( scaled_face( rotbox, 5, 1.3 ), TOL ) );
00404 }
00405 
00406 // \test Check all closest point query on Oriented Box tests
00407 static void test_closest_point()
00408 {
00409     CartVect result;
00410 
00411     // start with unit box
00412 
00413     // test locations inside box
00414     unitbox.closest_location_in_box( unitbox.center, result );
00415     ASSERT_VECTORS_EQUAL( result, unitbox.center );
00416     double f = 0.5;
00417     unitbox.closest_location_in_box( scaled_corner( unitbox, 0, f ), result );
00418     ASSERT_VECTORS_EQUAL( result, scaled_corner( unitbox, 0, f ) );
00419     unitbox.closest_location_in_box( scaled_corner( unitbox, 1, f ), result );
00420     ASSERT_VECTORS_EQUAL( result, scaled_corner( unitbox, 1, f ) );
00421     unitbox.closest_location_in_box( scaled_corner( unitbox, 2, f ), result );
00422     ASSERT_VECTORS_EQUAL( result, scaled_corner( unitbox, 2, f ) );
00423     unitbox.closest_location_in_box( scaled_corner( unitbox, 3, f ), result );
00424     ASSERT_VECTORS_EQUAL( result, scaled_corner( unitbox, 3, f ) );
00425     unitbox.closest_location_in_box( scaled_corner( unitbox, 4, f ), result );
00426     ASSERT_VECTORS_EQUAL( result, scaled_corner( unitbox, 4, f ) );
00427     unitbox.closest_location_in_box( scaled_corner( unitbox, 5, f ), result );
00428     ASSERT_VECTORS_EQUAL( result, scaled_corner( unitbox, 5, f ) );
00429     unitbox.closest_location_in_box( scaled_corner( unitbox, 6, f ), result );
00430     ASSERT_VECTORS_EQUAL( result, scaled_corner( unitbox, 6, f ) );
00431     unitbox.closest_location_in_box( scaled_corner( unitbox, 7, f ), result );
00432     ASSERT_VECTORS_EQUAL( result, scaled_corner( unitbox, 7, f ) );
00433 
00434     // test each corner
00435     f = 1.0;
00436     unitbox.closest_location_in_box( scaled_corner( unitbox, 0, f ), result );
00437     ASSERT_VECTORS_EQUAL( result, scaled_corner( unitbox, 0, f ) );
00438     unitbox.closest_location_in_box( scaled_corner( unitbox, 1, f ), result );
00439     ASSERT_VECTORS_EQUAL( result, scaled_corner( unitbox, 1, f ) );
00440     unitbox.closest_location_in_box( scaled_corner( unitbox, 2, f ), result );
00441     ASSERT_VECTORS_EQUAL( result, scaled_corner( unitbox, 2, f ) );
00442     unitbox.closest_location_in_box( scaled_corner( unitbox, 3, f ), result );
00443     ASSERT_VECTORS_EQUAL( result, scaled_corner( unitbox, 3, f ) );
00444     unitbox.closest_location_in_box( scaled_corner( unitbox, 4, f ), result );
00445     ASSERT_VECTORS_EQUAL( result, scaled_corner( unitbox, 4, f ) );
00446     unitbox.closest_location_in_box( scaled_corner( unitbox, 5, f ), result );
00447     ASSERT_VECTORS_EQUAL( result, scaled_corner( unitbox, 5, f ) );
00448     unitbox.closest_location_in_box( scaled_corner( unitbox, 6, f ), result );
00449     ASSERT_VECTORS_EQUAL( result, scaled_corner( unitbox, 6, f ) );
00450     unitbox.closest_location_in_box( scaled_corner( unitbox, 7, f ), result );
00451     ASSERT_VECTORS_EQUAL( result, scaled_corner( unitbox, 7, f ) );
00452 
00453     // test outside each corner
00454     f = 1.5;
00455     unitbox.closest_location_in_box( scaled_corner( unitbox, 0, f ), result );
00456     ASSERT_VECTORS_EQUAL( result, scaled_corner( unitbox, 0, 1 ) );
00457     unitbox.closest_location_in_box( scaled_corner( unitbox, 1, f ), result );
00458     ASSERT_VECTORS_EQUAL( result, scaled_corner( unitbox, 1, 1 ) );
00459     unitbox.closest_location_in_box( scaled_corner( unitbox, 2, f ), result );
00460     ASSERT_VECTORS_EQUAL( result, scaled_corner( unitbox, 2, 1 ) );
00461     unitbox.closest_location_in_box( scaled_corner( unitbox, 3, f ), result );
00462     ASSERT_VECTORS_EQUAL( result, scaled_corner( unitbox, 3, 1 ) );
00463     unitbox.closest_location_in_box( scaled_corner( unitbox, 4, f ), result );
00464     ASSERT_VECTORS_EQUAL( result, scaled_corner( unitbox, 4, 1 ) );
00465     unitbox.closest_location_in_box( scaled_corner( unitbox, 5, f ), result );
00466     ASSERT_VECTORS_EQUAL( result, scaled_corner( unitbox, 5, 1 ) );
00467     unitbox.closest_location_in_box( scaled_corner( unitbox, 6, f ), result );
00468     ASSERT_VECTORS_EQUAL( result, scaled_corner( unitbox, 6, 1 ) );
00469     unitbox.closest_location_in_box( scaled_corner( unitbox, 7, f ), result );
00470     ASSERT_VECTORS_EQUAL( result, scaled_corner( unitbox, 7, 1 ) );
00471 
00472     // test on each face
00473     f = 1.0;
00474     unitbox.closest_location_in_box( scaled_face( unitbox, 0, f ), result );
00475     ASSERT_VECTORS_EQUAL( result, scaled_face( unitbox, 0, f ) );
00476     unitbox.closest_location_in_box( scaled_face( unitbox, 1, f ), result );
00477     ASSERT_VECTORS_EQUAL( result, scaled_face( unitbox, 1, f ) );
00478     unitbox.closest_location_in_box( scaled_face( unitbox, 2, f ), result );
00479     ASSERT_VECTORS_EQUAL( result, scaled_face( unitbox, 2, f ) );
00480     unitbox.closest_location_in_box( scaled_face( unitbox, 3, f ), result );
00481     ASSERT_VECTORS_EQUAL( result, scaled_face( unitbox, 3, f ) );
00482     unitbox.closest_location_in_box( scaled_face( unitbox, 4, f ), result );
00483     ASSERT_VECTORS_EQUAL( result, scaled_face( unitbox, 4, f ) );
00484     unitbox.closest_location_in_box( scaled_face( unitbox, 5, f ), result );
00485     ASSERT_VECTORS_EQUAL( result, scaled_face( unitbox, 5, f ) );
00486 
00487     // test outside each face
00488     f = 1.5;
00489     unitbox.closest_location_in_box( scaled_face( unitbox, 0, f ), result );
00490     ASSERT_VECTORS_EQUAL( result, scaled_face( unitbox, 0, 1 ) );
00491     unitbox.closest_location_in_box( scaled_face( unitbox, 1, f ), result );
00492     ASSERT_VECTORS_EQUAL( result, scaled_face( unitbox, 1, 1 ) );
00493     unitbox.closest_location_in_box( scaled_face( unitbox, 2, f ), result );
00494     ASSERT_VECTORS_EQUAL( result, scaled_face( unitbox, 2, 1 ) );
00495     unitbox.closest_location_in_box( scaled_face( unitbox, 3, f ), result );
00496     ASSERT_VECTORS_EQUAL( result, scaled_face( unitbox, 3, 1 ) );
00497     unitbox.closest_location_in_box( scaled_face( unitbox, 4, f ), result );
00498     ASSERT_VECTORS_EQUAL( result, scaled_face( unitbox, 4, 1 ) );
00499     unitbox.closest_location_in_box( scaled_face( unitbox, 5, f ), result );
00500     ASSERT_VECTORS_EQUAL( result, scaled_face( unitbox, 5, 1 ) );
00501 
00502     // next offset box
00503 
00504     // test locations inside box
00505     offsetbox.closest_location_in_box( offsetbox.center, result );
00506     ASSERT_VECTORS_EQUAL( result, offsetbox.center );
00507     f = 0.5;
00508     offsetbox.closest_location_in_box( scaled_corner( offsetbox, 0, f ), result );
00509     ASSERT_VECTORS_EQUAL( result, scaled_corner( offsetbox, 0, f ) );
00510     offsetbox.closest_location_in_box( scaled_corner( offsetbox, 1, f ), result );
00511     ASSERT_VECTORS_EQUAL( result, scaled_corner( offsetbox, 1, f ) );
00512     offsetbox.closest_location_in_box( scaled_corner( offsetbox, 2, f ), result );
00513     ASSERT_VECTORS_EQUAL( result, scaled_corner( offsetbox, 2, f ) );
00514     offsetbox.closest_location_in_box( scaled_corner( offsetbox, 3, f ), result );
00515     ASSERT_VECTORS_EQUAL( result, scaled_corner( offsetbox, 3, f ) );
00516     offsetbox.closest_location_in_box( scaled_corner( offsetbox, 4, f ), result );
00517     ASSERT_VECTORS_EQUAL( result, scaled_corner( offsetbox, 4, f ) );
00518     offsetbox.closest_location_in_box( scaled_corner( offsetbox, 5, f ), result );
00519     ASSERT_VECTORS_EQUAL( result, scaled_corner( offsetbox, 5, f ) );
00520     offsetbox.closest_location_in_box( scaled_corner( offsetbox, 6, f ), result );
00521     ASSERT_VECTORS_EQUAL( result, scaled_corner( offsetbox, 6, f ) );
00522     offsetbox.closest_location_in_box( scaled_corner( offsetbox, 7, f ), result );
00523     ASSERT_VECTORS_EQUAL( result, scaled_corner( offsetbox, 7, f ) );
00524 
00525     // test each corner
00526     f = 1.0;
00527     offsetbox.closest_location_in_box( scaled_corner( offsetbox, 0, f ), result );
00528     ASSERT_VECTORS_EQUAL( result, scaled_corner( offsetbox, 0, f ) );
00529     offsetbox.closest_location_in_box( scaled_corner( offsetbox, 1, f ), result );
00530     ASSERT_VECTORS_EQUAL( result, scaled_corner( offsetbox, 1, f ) );
00531     offsetbox.closest_location_in_box( scaled_corner( offsetbox, 2, f ), result );
00532     ASSERT_VECTORS_EQUAL( result, scaled_corner( offsetbox, 2, f ) );
00533     offsetbox.closest_location_in_box( scaled_corner( offsetbox, 3, f ), result );
00534     ASSERT_VECTORS_EQUAL( result, scaled_corner( offsetbox, 3, f ) );
00535     offsetbox.closest_location_in_box( scaled_corner( offsetbox, 4, f ), result );
00536     ASSERT_VECTORS_EQUAL( result, scaled_corner( offsetbox, 4, f ) );
00537     offsetbox.closest_location_in_box( scaled_corner( offsetbox, 5, f ), result );
00538     ASSERT_VECTORS_EQUAL( result, scaled_corner( offsetbox, 5, f ) );
00539     offsetbox.closest_location_in_box( scaled_corner( offsetbox, 6, f ), result );
00540     ASSERT_VECTORS_EQUAL( result, scaled_corner( offsetbox, 6, f ) );
00541     offsetbox.closest_location_in_box( scaled_corner( offsetbox, 7, f ), result );
00542     ASSERT_VECTORS_EQUAL( result, scaled_corner( offsetbox, 7, f ) );
00543 
00544     // test outside each corner
00545     f = 1.5;
00546     offsetbox.closest_location_in_box( scaled_corner( offsetbox, 0, f ), result );
00547     ASSERT_VECTORS_EQUAL( result, scaled_corner( offsetbox, 0, 1 ) );
00548     offsetbox.closest_location_in_box( scaled_corner( offsetbox, 1, f ), result );
00549     ASSERT_VECTORS_EQUAL( result, scaled_corner( offsetbox, 1, 1 ) );
00550     offsetbox.closest_location_in_box( scaled_corner( offsetbox, 2, f ), result );
00551     ASSERT_VECTORS_EQUAL( result, scaled_corner( offsetbox, 2, 1 ) );
00552     offsetbox.closest_location_in_box( scaled_corner( offsetbox, 3, f ), result );
00553     ASSERT_VECTORS_EQUAL( result, scaled_corner( offsetbox, 3, 1 ) );
00554     offsetbox.closest_location_in_box( scaled_corner( offsetbox, 4, f ), result );
00555     ASSERT_VECTORS_EQUAL( result, scaled_corner( offsetbox, 4, 1 ) );
00556     offsetbox.closest_location_in_box( scaled_corner( offsetbox, 5, f ), result );
00557     ASSERT_VECTORS_EQUAL( result, scaled_corner( offsetbox, 5, 1 ) );
00558     offsetbox.closest_location_in_box( scaled_corner( offsetbox, 6, f ), result );
00559     ASSERT_VECTORS_EQUAL( result, scaled_corner( offsetbox, 6, 1 ) );
00560     offsetbox.closest_location_in_box( scaled_corner( offsetbox, 7, f ), result );
00561     ASSERT_VECTORS_EQUAL( result, scaled_corner( offsetbox, 7, 1 ) );
00562 
00563     // test on each face
00564     f = 1.0;
00565     offsetbox.closest_location_in_box( scaled_face( offsetbox, 0, f ), result );
00566     ASSERT_VECTORS_EQUAL( result, scaled_face( offsetbox, 0, f ) );
00567     offsetbox.closest_location_in_box( scaled_face( offsetbox, 1, f ), result );
00568     ASSERT_VECTORS_EQUAL( result, scaled_face( offsetbox, 1, f ) );
00569     offsetbox.closest_location_in_box( scaled_face( offsetbox, 2, f ), result );
00570     ASSERT_VECTORS_EQUAL( result, scaled_face( offsetbox, 2, f ) );
00571     offsetbox.closest_location_in_box( scaled_face( offsetbox, 3, f ), result );
00572     ASSERT_VECTORS_EQUAL( result, scaled_face( offsetbox, 3, f ) );
00573     offsetbox.closest_location_in_box( scaled_face( offsetbox, 4, f ), result );
00574     ASSERT_VECTORS_EQUAL( result, scaled_face( offsetbox, 4, f ) );
00575     offsetbox.closest_location_in_box( scaled_face( offsetbox, 5, f ), result );
00576     ASSERT_VECTORS_EQUAL( result, scaled_face( offsetbox, 5, f ) );
00577 
00578     // test outside each face
00579     f = 1.5;
00580     offsetbox.closest_location_in_box( scaled_face( offsetbox, 0, f ), result );
00581     ASSERT_VECTORS_EQUAL( result, scaled_face( offsetbox, 0, 1 ) );
00582     offsetbox.closest_location_in_box( scaled_face( offsetbox, 1, f ), result );
00583     ASSERT_VECTORS_EQUAL( result, scaled_face( offsetbox, 1, 1 ) );
00584     offsetbox.closest_location_in_box( scaled_face( offsetbox, 2, f ), result );
00585     ASSERT_VECTORS_EQUAL( result, scaled_face( offsetbox, 2, 1 ) );
00586     offsetbox.closest_location_in_box( scaled_face( offsetbox, 3, f ), result );
00587     ASSERT_VECTORS_EQUAL( result, scaled_face( offsetbox, 3, 1 ) );
00588     offsetbox.closest_location_in_box( scaled_face( offsetbox, 4, f ), result );
00589     ASSERT_VECTORS_EQUAL( result, scaled_face( offsetbox, 4, 1 ) );
00590     offsetbox.closest_location_in_box( scaled_face( offsetbox, 5, f ), result );
00591     ASSERT_VECTORS_EQUAL( result, scaled_face( offsetbox, 5, 1 ) );
00592 
00593     // next oblong box
00594 
00595     // test locations inside box
00596     oblongbox.closest_location_in_box( oblongbox.center, result );
00597     ASSERT_VECTORS_EQUAL( result, oblongbox.center );
00598     f = 0.5;
00599     oblongbox.closest_location_in_box( scaled_corner( oblongbox, 0, f ), result );
00600     ASSERT_VECTORS_EQUAL( result, scaled_corner( oblongbox, 0, f ) );
00601     oblongbox.closest_location_in_box( scaled_corner( oblongbox, 1, f ), result );
00602     ASSERT_VECTORS_EQUAL( result, scaled_corner( oblongbox, 1, f ) );
00603     oblongbox.closest_location_in_box( scaled_corner( oblongbox, 2, f ), result );
00604     ASSERT_VECTORS_EQUAL( result, scaled_corner( oblongbox, 2, f ) );
00605     oblongbox.closest_location_in_box( scaled_corner( oblongbox, 3, f ), result );
00606     ASSERT_VECTORS_EQUAL( result, scaled_corner( oblongbox, 3, f ) );
00607     oblongbox.closest_location_in_box( scaled_corner( oblongbox, 4, f ), result );
00608     ASSERT_VECTORS_EQUAL( result, scaled_corner( oblongbox, 4, f ) );
00609     oblongbox.closest_location_in_box( scaled_corner( oblongbox, 5, f ), result );
00610     ASSERT_VECTORS_EQUAL( result, scaled_corner( oblongbox, 5, f ) );
00611     oblongbox.closest_location_in_box( scaled_corner( oblongbox, 6, f ), result );
00612     ASSERT_VECTORS_EQUAL( result, scaled_corner( oblongbox, 6, f ) );
00613     oblongbox.closest_location_in_box( scaled_corner( oblongbox, 7, f ), result );
00614     ASSERT_VECTORS_EQUAL( result, scaled_corner( oblongbox, 7, f ) );
00615 
00616     // test each corner
00617     f = 1.0;
00618     oblongbox.closest_location_in_box( scaled_corner( oblongbox, 0, f ), result );
00619     ASSERT_VECTORS_EQUAL( result, scaled_corner( oblongbox, 0, f ) );
00620     oblongbox.closest_location_in_box( scaled_corner( oblongbox, 1, f ), result );
00621     ASSERT_VECTORS_EQUAL( result, scaled_corner( oblongbox, 1, f ) );
00622     oblongbox.closest_location_in_box( scaled_corner( oblongbox, 2, f ), result );
00623     ASSERT_VECTORS_EQUAL( result, scaled_corner( oblongbox, 2, f ) );
00624     oblongbox.closest_location_in_box( scaled_corner( oblongbox, 3, f ), result );
00625     ASSERT_VECTORS_EQUAL( result, scaled_corner( oblongbox, 3, f ) );
00626     oblongbox.closest_location_in_box( scaled_corner( oblongbox, 4, f ), result );
00627     ASSERT_VECTORS_EQUAL( result, scaled_corner( oblongbox, 4, f ) );
00628     oblongbox.closest_location_in_box( scaled_corner( oblongbox, 5, f ), result );
00629     ASSERT_VECTORS_EQUAL( result, scaled_corner( oblongbox, 5, f ) );
00630     oblongbox.closest_location_in_box( scaled_corner( oblongbox, 6, f ), result );
00631     ASSERT_VECTORS_EQUAL( result, scaled_corner( oblongbox, 6, f ) );
00632     oblongbox.closest_location_in_box( scaled_corner( oblongbox, 7, f ), result );
00633     ASSERT_VECTORS_EQUAL( result, scaled_corner( oblongbox, 7, f ) );
00634 
00635     // test outside each corner
00636     f = 1.5;
00637     oblongbox.closest_location_in_box( scaled_corner( oblongbox, 0, f ), result );
00638     ASSERT_VECTORS_EQUAL( result, scaled_corner( oblongbox, 0, 1 ) );
00639     oblongbox.closest_location_in_box( scaled_corner( oblongbox, 1, f ), result );
00640     ASSERT_VECTORS_EQUAL( result, scaled_corner( oblongbox, 1, 1 ) );
00641     oblongbox.closest_location_in_box( scaled_corner( oblongbox, 2, f ), result );
00642     ASSERT_VECTORS_EQUAL( result, scaled_corner( oblongbox, 2, 1 ) );
00643     oblongbox.closest_location_in_box( scaled_corner( oblongbox, 3, f ), result );
00644     ASSERT_VECTORS_EQUAL( result, scaled_corner( oblongbox, 3, 1 ) );
00645     oblongbox.closest_location_in_box( scaled_corner( oblongbox, 4, f ), result );
00646     ASSERT_VECTORS_EQUAL( result, scaled_corner( oblongbox, 4, 1 ) );
00647     oblongbox.closest_location_in_box( scaled_corner( oblongbox, 5, f ), result );
00648     ASSERT_VECTORS_EQUAL( result, scaled_corner( oblongbox, 5, 1 ) );
00649     oblongbox.closest_location_in_box( scaled_corner( oblongbox, 6, f ), result );
00650     ASSERT_VECTORS_EQUAL( result, scaled_corner( oblongbox, 6, 1 ) );
00651     oblongbox.closest_location_in_box( scaled_corner( oblongbox, 7, f ), result );
00652     ASSERT_VECTORS_EQUAL( result, scaled_corner( oblongbox, 7, 1 ) );
00653 
00654     // test on each face
00655     f = 1.0;
00656     oblongbox.closest_location_in_box( scaled_face( oblongbox, 0, f ), result );
00657     ASSERT_VECTORS_EQUAL( result, scaled_face( oblongbox, 0, f ) );
00658     oblongbox.closest_location_in_box( scaled_face( oblongbox, 1, f ), result );
00659     ASSERT_VECTORS_EQUAL( result, scaled_face( oblongbox, 1, f ) );
00660     oblongbox.closest_location_in_box( scaled_face( oblongbox, 2, f ), result );
00661     ASSERT_VECTORS_EQUAL( result, scaled_face( oblongbox, 2, f ) );
00662     oblongbox.closest_location_in_box( scaled_face( oblongbox, 3, f ), result );
00663     ASSERT_VECTORS_EQUAL( result, scaled_face( oblongbox, 3, f ) );
00664     oblongbox.closest_location_in_box( scaled_face( oblongbox, 4, f ), result );
00665     ASSERT_VECTORS_EQUAL( result, scaled_face( oblongbox, 4, f ) );
00666     oblongbox.closest_location_in_box( scaled_face( oblongbox, 5, f ), result );
00667     ASSERT_VECTORS_EQUAL( result, scaled_face( oblongbox, 5, f ) );
00668 
00669     // test outside each face
00670     f = 1.5;
00671     oblongbox.closest_location_in_box( scaled_face( oblongbox, 0, f ), result );
00672     ASSERT_VECTORS_EQUAL( result, scaled_face( oblongbox, 0, 1 ) );
00673     oblongbox.closest_location_in_box( scaled_face( oblongbox, 1, f ), result );
00674     ASSERT_VECTORS_EQUAL( result, scaled_face( oblongbox, 1, 1 ) );
00675     oblongbox.closest_location_in_box( scaled_face( oblongbox, 2, f ), result );
00676     ASSERT_VECTORS_EQUAL( result, scaled_face( oblongbox, 2, 1 ) );
00677     oblongbox.closest_location_in_box( scaled_face( oblongbox, 3, f ), result );
00678     ASSERT_VECTORS_EQUAL( result, scaled_face( oblongbox, 3, 1 ) );
00679     oblongbox.closest_location_in_box( scaled_face( oblongbox, 4, f ), result );
00680     ASSERT_VECTORS_EQUAL( result, scaled_face( oblongbox, 4, 1 ) );
00681     oblongbox.closest_location_in_box( scaled_face( oblongbox, 5, f ), result );
00682     ASSERT_VECTORS_EQUAL( result, scaled_face( oblongbox, 5, 1 ) );
00683 
00684     // next rotated box
00685 
00686     // test locations inside box
00687     rotbox.closest_location_in_box( rotbox.center, result );
00688     ASSERT_VECTORS_EQUAL( result, rotbox.center );
00689     f = 0.5;
00690     rotbox.closest_location_in_box( scaled_corner( rotbox, 0, f ), result );
00691     ASSERT_VECTORS_EQUAL( result, scaled_corner( rotbox, 0, f ) );
00692     rotbox.closest_location_in_box( scaled_corner( rotbox, 1, f ), result );
00693     ASSERT_VECTORS_EQUAL( result, scaled_corner( rotbox, 1, f ) );
00694     rotbox.closest_location_in_box( scaled_corner( rotbox, 2, f ), result );
00695     ASSERT_VECTORS_EQUAL( result, scaled_corner( rotbox, 2, f ) );
00696     rotbox.closest_location_in_box( scaled_corner( rotbox, 3, f ), result );
00697     ASSERT_VECTORS_EQUAL( result, scaled_corner( rotbox, 3, f ) );
00698     rotbox.closest_location_in_box( scaled_corner( rotbox, 4, f ), result );
00699     ASSERT_VECTORS_EQUAL( result, scaled_corner( rotbox, 4, f ) );
00700     rotbox.closest_location_in_box( scaled_corner( rotbox, 5, f ), result );
00701     ASSERT_VECTORS_EQUAL( result, scaled_corner( rotbox, 5, f ) );
00702     rotbox.closest_location_in_box( scaled_corner( rotbox, 6, f ), result );
00703     ASSERT_VECTORS_EQUAL( result, scaled_corner( rotbox, 6, f ) );
00704     rotbox.closest_location_in_box( scaled_corner( rotbox, 7, f ), result );
00705     ASSERT_VECTORS_EQUAL( result, scaled_corner( rotbox, 7, f ) );
00706 
00707     // test each corner
00708     f = 1.0;
00709     rotbox.closest_location_in_box( scaled_corner( rotbox, 0, f ), result );
00710     ASSERT_VECTORS_EQUAL( result, scaled_corner( rotbox, 0, f ) );
00711     rotbox.closest_location_in_box( scaled_corner( rotbox, 1, f ), result );
00712     ASSERT_VECTORS_EQUAL( result, scaled_corner( rotbox, 1, f ) );
00713     rotbox.closest_location_in_box( scaled_corner( rotbox, 2, f ), result );
00714     ASSERT_VECTORS_EQUAL( result, scaled_corner( rotbox, 2, f ) );
00715     rotbox.closest_location_in_box( scaled_corner( rotbox, 3, f ), result );
00716     ASSERT_VECTORS_EQUAL( result, scaled_corner( rotbox, 3, f ) );
00717     rotbox.closest_location_in_box( scaled_corner( rotbox, 4, f ), result );
00718     ASSERT_VECTORS_EQUAL( result, scaled_corner( rotbox, 4, f ) );
00719     rotbox.closest_location_in_box( scaled_corner( rotbox, 5, f ), result );
00720     ASSERT_VECTORS_EQUAL( result, scaled_corner( rotbox, 5, f ) );
00721     rotbox.closest_location_in_box( scaled_corner( rotbox, 6, f ), result );
00722     ASSERT_VECTORS_EQUAL( result, scaled_corner( rotbox, 6, f ) );
00723     rotbox.closest_location_in_box( scaled_corner( rotbox, 7, f ), result );
00724     ASSERT_VECTORS_EQUAL( result, scaled_corner( rotbox, 7, f ) );
00725 
00726     // test outside each corner
00727     f = 1.5;
00728     rotbox.closest_location_in_box( scaled_corner( rotbox, 0, f ), result );
00729     ASSERT_VECTORS_EQUAL( result, scaled_corner( rotbox, 0, 1 ) );
00730     rotbox.closest_location_in_box( scaled_corner( rotbox, 1, f ), result );
00731     ASSERT_VECTORS_EQUAL( result, scaled_corner( rotbox, 1, 1 ) );
00732     rotbox.closest_location_in_box( scaled_corner( rotbox, 2, f ), result );
00733     ASSERT_VECTORS_EQUAL( result, scaled_corner( rotbox, 2, 1 ) );
00734     rotbox.closest_location_in_box( scaled_corner( rotbox, 3, f ), result );
00735     ASSERT_VECTORS_EQUAL( result, scaled_corner( rotbox, 3, 1 ) );
00736     rotbox.closest_location_in_box( scaled_corner( rotbox, 4, f ), result );
00737     ASSERT_VECTORS_EQUAL( result, scaled_corner( rotbox, 4, 1 ) );
00738     rotbox.closest_location_in_box( scaled_corner( rotbox, 5, f ), result );
00739     ASSERT_VECTORS_EQUAL( result, scaled_corner( rotbox, 5, 1 ) );
00740     rotbox.closest_location_in_box( scaled_corner( rotbox, 6, f ), result );
00741     ASSERT_VECTORS_EQUAL( result, scaled_corner( rotbox, 6, 1 ) );
00742     rotbox.closest_location_in_box( scaled_corner( rotbox, 7, f ), result );
00743     ASSERT_VECTORS_EQUAL( result, scaled_corner( rotbox, 7, 1 ) );
00744 
00745     // test on each face
00746     f = 1.0;
00747     rotbox.closest_location_in_box( scaled_face( rotbox, 0, f ), result );
00748     ASSERT_VECTORS_EQUAL( result, scaled_face( rotbox, 0, f ) );
00749     rotbox.closest_location_in_box( scaled_face( rotbox, 1, f ), result );
00750     ASSERT_VECTORS_EQUAL( result, scaled_face( rotbox, 1, f ) );
00751     rotbox.closest_location_in_box( scaled_face( rotbox, 2, f ), result );
00752     ASSERT_VECTORS_EQUAL( result, scaled_face( rotbox, 2, f ) );
00753     rotbox.closest_location_in_box( scaled_face( rotbox, 3, f ), result );
00754     ASSERT_VECTORS_EQUAL( result, scaled_face( rotbox, 3, f ) );
00755     rotbox.closest_location_in_box( scaled_face( rotbox, 4, f ), result );
00756     ASSERT_VECTORS_EQUAL( result, scaled_face( rotbox, 4, f ) );
00757     rotbox.closest_location_in_box( scaled_face( rotbox, 5, f ), result );
00758     ASSERT_VECTORS_EQUAL( result, scaled_face( rotbox, 5, f ) );
00759 
00760     // test outside each face
00761     f = 1.5;
00762     rotbox.closest_location_in_box( scaled_face( rotbox, 0, f ), result );
00763     ASSERT_VECTORS_EQUAL( result, scaled_face( rotbox, 0, 1 ) );
00764     rotbox.closest_location_in_box( scaled_face( rotbox, 1, f ), result );
00765     ASSERT_VECTORS_EQUAL( result, scaled_face( rotbox, 1, 1 ) );
00766     rotbox.closest_location_in_box( scaled_face( rotbox, 2, f ), result );
00767     ASSERT_VECTORS_EQUAL( result, scaled_face( rotbox, 2, 1 ) );
00768     rotbox.closest_location_in_box( scaled_face( rotbox, 3, f ), result );
00769     ASSERT_VECTORS_EQUAL( result, scaled_face( rotbox, 3, 1 ) );
00770     rotbox.closest_location_in_box( scaled_face( rotbox, 4, f ), result );
00771     ASSERT_VECTORS_EQUAL( result, scaled_face( rotbox, 4, 1 ) );
00772     rotbox.closest_location_in_box( scaled_face( rotbox, 5, f ), result );
00773     ASSERT_VECTORS_EQUAL( result, scaled_face( rotbox, 5, 1 ) );
00774 }
00775 
00776 // \test Check all ray_intersect tests on Oriented Box
00777 void test_ray_intersect()
00778 {
00779     CartVect dir, pt;
00780 
00781     // start with unit box
00782 
00783     // test ray from box center towards each face
00784     dir = scaled_face( unitbox, 0, 1.0 ) - unitbox.center;
00785     dir.normalize();
00786     ASSERT( unitbox.intersect_ray( unitbox.center, dir, TOL ) );
00787     dir = scaled_face( unitbox, 1, 1.0 ) - unitbox.center;
00788     dir.normalize();
00789     ASSERT( unitbox.intersect_ray( unitbox.center, dir, TOL ) );
00790     dir = scaled_face( unitbox, 2, 1.0 ) - unitbox.center;
00791     dir.normalize();
00792     ASSERT( unitbox.intersect_ray( unitbox.center, dir, TOL ) );
00793     dir = scaled_face( unitbox, 3, 1.0 ) - unitbox.center;
00794     dir.normalize();
00795     ASSERT( unitbox.intersect_ray( unitbox.center, dir, TOL ) );
00796     dir = scaled_face( unitbox, 4, 1.0 ) - unitbox.center;
00797     dir.normalize();
00798     ASSERT( unitbox.intersect_ray( unitbox.center, dir, TOL ) );
00799     dir = scaled_face( unitbox, 5, 1.0 ) - unitbox.center;
00800     dir.normalize();
00801     ASSERT( unitbox.intersect_ray( unitbox.center, dir, TOL ) );
00802 
00803     // test ray starting outside each face and pointing towards box center
00804     pt  = scaled_face( unitbox, 0, 3.0 );
00805     dir = unitbox.center - pt;
00806     dir.normalize();
00807     ASSERT( unitbox.intersect_ray( pt, dir, TOL ) );
00808     pt  = scaled_face( unitbox, 1, 3.0 );
00809     dir = unitbox.center - pt;
00810     dir.normalize();
00811     ASSERT( unitbox.intersect_ray( pt, dir, TOL ) );
00812     pt  = scaled_face( unitbox, 2, 3.0 );
00813     dir = unitbox.center - pt;
00814     dir.normalize();
00815     ASSERT( unitbox.intersect_ray( pt, dir, TOL ) );
00816     pt  = scaled_face( unitbox, 3, 3.0 );
00817     dir = unitbox.center - pt;
00818     dir.normalize();
00819     ASSERT( unitbox.intersect_ray( pt, dir, TOL ) );
00820     pt  = scaled_face( unitbox, 4, 3.0 );
00821     dir = unitbox.center - pt;
00822     dir.normalize();
00823     ASSERT( unitbox.intersect_ray( pt, dir, TOL ) );
00824     pt  = scaled_face( unitbox, 5, 3.0 );
00825     dir = unitbox.center - pt;
00826     dir.normalize();
00827     ASSERT( unitbox.intersect_ray( pt, dir, TOL ) );
00828 
00829     // test ray from outside first face toward box center, with nonnegative ray length
00830     pt  = scaled_face( unitbox, 0, 3.0 );
00831     dir = unitbox.center - pt;
00832     dir.normalize();
00833     const double short_pos = 0.99;
00834     const double short_neg = -0.99;
00835     const double long_pos  = 1.01;
00836     const double long_neg  = -1.01;
00837     ASSERT( unitbox.intersect_ray( pt, dir, TOL, &long_pos ) );
00838     ASSERT( !unitbox.intersect_ray( pt, dir, TOL, &short_pos ) );
00839 
00840     // test ray from outside first face away from box center, with negative ray length
00841     ASSERT( unitbox.intersect_ray( pt, -dir, TOL, NULL, &long_neg ) );
00842     ASSERT( !unitbox.intersect_ray( pt, -dir, TOL, NULL, &short_neg ) );
00843 
00844     // test ray from outside first face toward box center, with both ray lengths
00845     // Note that box.intersect_ray requires neg_ray_len<0 and -neg_ray_len<=nonneg_ray_len
00846     ASSERT( unitbox.intersect_ray( pt, dir, TOL, &long_pos, &long_neg ) );
00847     ASSERT( !unitbox.intersect_ray( pt, dir, TOL, &short_pos, &long_neg ) );
00848     ASSERT( unitbox.intersect_ray( pt, dir, TOL, &long_pos, &short_neg ) );
00849     ASSERT( !unitbox.intersect_ray( pt, dir, TOL, &short_pos, &short_neg ) );
00850 
00851     // test ray starting inside box and passing through a corner
00852     pt  = scaled_corner( unitbox, 0, 0.3 );
00853     dir = pt - unitbox.center;
00854     dir.normalize();
00855     ASSERT( unitbox.intersect_ray( pt, dir, TOL ) );
00856     pt  = scaled_corner( unitbox, 1, 0.3 );
00857     dir = pt - unitbox.center;
00858     dir.normalize();
00859     ASSERT( unitbox.intersect_ray( pt, dir, TOL ) );
00860     pt  = scaled_corner( unitbox, 2, 0.3 );
00861     dir = pt - unitbox.center;
00862     dir.normalize();
00863     ASSERT( unitbox.intersect_ray( pt, dir, TOL ) );
00864     pt  = scaled_corner( unitbox, 3, 0.3 );
00865     dir = pt - unitbox.center;
00866     dir.normalize();
00867     ASSERT( unitbox.intersect_ray( pt, dir, TOL ) );
00868     pt  = scaled_corner( unitbox, 4, 0.3 );
00869     dir = pt - unitbox.center;
00870     dir.normalize();
00871     ASSERT( unitbox.intersect_ray( pt, dir, TOL ) );
00872     pt  = scaled_corner( unitbox, 5, 0.3 );
00873     dir = pt - unitbox.center;
00874     dir.normalize();
00875     ASSERT( unitbox.intersect_ray( pt, dir, TOL ) );
00876     pt  = scaled_corner( unitbox, 6, 0.3 );
00877     dir = pt - unitbox.center;
00878     dir.normalize();
00879     ASSERT( unitbox.intersect_ray( pt, dir, TOL ) );
00880     pt  = scaled_corner( unitbox, 7, 0.3 );
00881     dir = pt - unitbox.center;
00882     dir.normalize();
00883     ASSERT( unitbox.intersect_ray( pt, dir, TOL ) );
00884 
00885     // test ray starting outside box and passing through opposite corners
00886     pt  = scaled_corner( unitbox, 0, 3.0 );
00887     dir = unitbox.center - pt;
00888     dir.normalize();
00889     ASSERT( unitbox.intersect_ray( pt, dir, TOL ) );
00890     pt  = scaled_corner( unitbox, 1, 3.0 );
00891     dir = unitbox.center - pt;
00892     dir.normalize();
00893     ASSERT( unitbox.intersect_ray( pt, dir, TOL ) );
00894     pt  = scaled_corner( unitbox, 2, 3.0 );
00895     dir = unitbox.center - pt;
00896     dir.normalize();
00897     ASSERT( unitbox.intersect_ray( pt, dir, TOL ) );
00898     pt  = scaled_corner( unitbox, 3, 3.0 );
00899     dir = unitbox.center - pt;
00900     dir.normalize();
00901     ASSERT( unitbox.intersect_ray( pt, dir, TOL ) );
00902     pt  = scaled_corner( unitbox, 4, 3.0 );
00903     dir = unitbox.center - pt;
00904     dir.normalize();
00905     ASSERT( unitbox.intersect_ray( pt, dir, TOL ) );
00906     pt  = scaled_corner( unitbox, 5, 3.0 );
00907     dir = unitbox.center - pt;
00908     dir.normalize();
00909     ASSERT( unitbox.intersect_ray( pt, dir, TOL ) );
00910     pt  = scaled_corner( unitbox, 6, 3.0 );
00911     dir = unitbox.center - pt;
00912     dir.normalize();
00913     ASSERT( unitbox.intersect_ray( pt, dir, TOL ) );
00914     pt  = scaled_corner( unitbox, 7, 3.0 );
00915     dir = unitbox.center - pt;
00916     dir.normalize();
00917     ASSERT( unitbox.intersect_ray( pt, dir, TOL ) );
00918 
00919     // test ray starting outside face and pointing away from box
00920     pt  = scaled_face( unitbox, 0, 3.0 );
00921     dir = pt - unitbox.center;
00922     dir.normalize();
00923     ASSERT( !unitbox.intersect_ray( pt, dir, TOL ) );
00924     pt  = scaled_face( unitbox, 1, 3.0 );
00925     dir = pt - unitbox.center;
00926     dir.normalize();
00927     ASSERT( !unitbox.intersect_ray( pt, dir, TOL ) );
00928     pt  = scaled_face( unitbox, 2, 3.0 );
00929     dir = pt - unitbox.center;
00930     dir.normalize();
00931     ASSERT( !unitbox.intersect_ray( pt, dir, TOL ) );
00932     pt  = scaled_face( unitbox, 3, 3.0 );
00933     dir = pt - unitbox.center;
00934     dir.normalize();
00935     ASSERT( !unitbox.intersect_ray( pt, dir, TOL ) );
00936     pt  = scaled_face( unitbox, 4, 3.0 );
00937     dir = pt - unitbox.center;
00938     dir.normalize();
00939     ASSERT( !unitbox.intersect_ray( pt, dir, TOL ) );
00940     pt  = scaled_face( unitbox, 5, 3.0 );
00941     dir = pt - unitbox.center;
00942     dir.normalize();
00943     ASSERT( !unitbox.intersect_ray( pt, dir, TOL ) );
00944 
00945     // test ray starting outside face and parallel to face
00946     pt  = scaled_face( unitbox, 0, 3.0 );
00947     dir = unitbox.scaled_axis( 1 );
00948     dir.normalize();
00949     ASSERT( !unitbox.intersect_ray( pt, dir, TOL ) );
00950     pt  = scaled_face( unitbox, 1, 3.0 );
00951     dir = unitbox.scaled_axis( 2 );
00952     dir.normalize();
00953     ASSERT( !unitbox.intersect_ray( pt, dir, TOL ) );
00954     pt  = scaled_face( unitbox, 2, 3.0 );
00955     dir = unitbox.scaled_axis( 0 );
00956     dir.normalize();
00957     ASSERT( !unitbox.intersect_ray( pt, dir, TOL ) );
00958     pt  = scaled_face( unitbox, 3, 3.0 );
00959     dir = unitbox.scaled_axis( 2 );
00960     dir.normalize();
00961     ASSERT( !unitbox.intersect_ray( pt, dir, TOL ) );
00962     pt  = scaled_face( unitbox, 4, 3.0 );
00963     dir = unitbox.scaled_axis( 0 );
00964     dir.normalize();
00965     ASSERT( !unitbox.intersect_ray( pt, dir, TOL ) );
00966     pt  = scaled_face( unitbox, 5, 3.0 );
00967     dir = unitbox.scaled_axis( 1 );
00968     dir.normalize();
00969     ASSERT( !unitbox.intersect_ray( pt, dir, TOL ) );
00970 
00971     // next do offset box
00972 
00973     // test ray from box center towards each face
00974     dir = scaled_face( offsetbox, 0, 1.0 ) - offsetbox.center;
00975     dir.normalize();
00976     ASSERT( offsetbox.intersect_ray( offsetbox.center, dir, TOL ) );
00977     dir = scaled_face( offsetbox, 1, 1.0 ) - offsetbox.center;
00978     dir.normalize();
00979     ASSERT( offsetbox.intersect_ray( offsetbox.center, dir, TOL ) );
00980     dir = scaled_face( offsetbox, 2, 1.0 ) - offsetbox.center;
00981     dir.normalize();
00982     ASSERT( offsetbox.intersect_ray( offsetbox.center, dir, TOL ) );
00983     dir = scaled_face( offsetbox, 3, 1.0 ) - offsetbox.center;
00984     dir.normalize();
00985     ASSERT( offsetbox.intersect_ray( offsetbox.center, dir, TOL ) );
00986     dir = scaled_face( offsetbox, 4, 1.0 ) - offsetbox.center;
00987     dir.normalize();
00988     ASSERT( offsetbox.intersect_ray( offsetbox.center, dir, TOL ) );
00989     dir = scaled_face( offsetbox, 5, 1.0 ) - offsetbox.center;
00990     dir.normalize();
00991     ASSERT( offsetbox.intersect_ray( offsetbox.center, dir, TOL ) );
00992 
00993     // test ray starting outside each face and pointing towards box center
00994     pt  = scaled_face( offsetbox, 0, 3.0 );
00995     dir = offsetbox.center - pt;
00996     dir.normalize();
00997     ASSERT( offsetbox.intersect_ray( pt, dir, TOL ) );
00998     pt  = scaled_face( offsetbox, 1, 3.0 );
00999     dir = offsetbox.center - pt;
01000     dir.normalize();
01001     ASSERT( offsetbox.intersect_ray( pt, dir, TOL ) );
01002     pt  = scaled_face( offsetbox, 2, 3.0 );
01003     dir = offsetbox.center - pt;
01004     dir.normalize();
01005     ASSERT( offsetbox.intersect_ray( pt, dir, TOL ) );
01006     pt  = scaled_face( offsetbox, 3, 3.0 );
01007     dir = offsetbox.center - pt;
01008     dir.normalize();
01009     ASSERT( offsetbox.intersect_ray( pt, dir, TOL ) );
01010     pt  = scaled_face( offsetbox, 4, 3.0 );
01011     dir = offsetbox.center - pt;
01012     dir.normalize();
01013     ASSERT( offsetbox.intersect_ray( pt, dir, TOL ) );
01014     pt  = scaled_face( offsetbox, 5, 3.0 );
01015     dir = offsetbox.center - pt;
01016     dir.normalize();
01017     ASSERT( offsetbox.intersect_ray( pt, dir, TOL ) );
01018 
01019     // test ray starting inside box and passing through a corner
01020     pt  = scaled_corner( offsetbox, 0, 0.3 );
01021     dir = pt - offsetbox.center;
01022     dir.normalize();
01023     ASSERT( offsetbox.intersect_ray( pt, dir, TOL ) );
01024     pt  = scaled_corner( offsetbox, 1, 0.3 );
01025     dir = pt - offsetbox.center;
01026     dir.normalize();
01027     ASSERT( offsetbox.intersect_ray( pt, dir, TOL ) );
01028     pt  = scaled_corner( offsetbox, 2, 0.3 );
01029     dir = pt - offsetbox.center;
01030     dir.normalize();
01031     ASSERT( offsetbox.intersect_ray( pt, dir, TOL ) );
01032     pt  = scaled_corner( offsetbox, 3, 0.3 );
01033     dir = pt - offsetbox.center;
01034     dir.normalize();
01035     ASSERT( offsetbox.intersect_ray( pt, dir, TOL ) );
01036     pt  = scaled_corner( offsetbox, 4, 0.3 );
01037     dir = pt - offsetbox.center;
01038     dir.normalize();
01039     ASSERT( offsetbox.intersect_ray( pt, dir, TOL ) );
01040     pt  = scaled_corner( offsetbox, 5, 0.3 );
01041     dir = pt - offsetbox.center;
01042     dir.normalize();
01043     ASSERT( offsetbox.intersect_ray( pt, dir, TOL ) );
01044     pt  = scaled_corner( offsetbox, 6, 0.3 );
01045     dir = pt - offsetbox.center;
01046     dir.normalize();
01047     ASSERT( offsetbox.intersect_ray( pt, dir, TOL ) );
01048     pt  = scaled_corner( offsetbox, 7, 0.3 );
01049     dir = pt - offsetbox.center;
01050     dir.normalize();
01051     ASSERT( offsetbox.intersect_ray( pt, dir, TOL ) );
01052 
01053     // test ray starting outside box and passing through opposite corners
01054     pt  = scaled_corner( offsetbox, 0, 3.0 );
01055     dir = offsetbox.center - pt;
01056     dir.normalize();
01057     ASSERT( offsetbox.intersect_ray( pt, dir, TOL ) );
01058     pt  = scaled_corner( offsetbox, 1, 3.0 );
01059     dir = offsetbox.center - pt;
01060     dir.normalize();
01061     ASSERT( offsetbox.intersect_ray( pt, dir, TOL ) );
01062     pt  = scaled_corner( offsetbox, 2, 3.0 );
01063     dir = offsetbox.center - pt;
01064     dir.normalize();
01065     ASSERT( offsetbox.intersect_ray( pt, dir, TOL ) );
01066     pt  = scaled_corner( offsetbox, 3, 3.0 );
01067     dir = offsetbox.center - pt;
01068     dir.normalize();
01069     ASSERT( offsetbox.intersect_ray( pt, dir, TOL ) );
01070     pt  = scaled_corner( offsetbox, 4, 3.0 );
01071     dir = offsetbox.center - pt;
01072     dir.normalize();
01073     ASSERT( offsetbox.intersect_ray( pt, dir, TOL ) );
01074     pt  = scaled_corner( offsetbox, 5, 3.0 );
01075     dir = offsetbox.center - pt;
01076     dir.normalize();
01077     ASSERT( offsetbox.intersect_ray( pt, dir, TOL ) );
01078     pt  = scaled_corner( offsetbox, 6, 3.0 );
01079     dir = offsetbox.center - pt;
01080     dir.normalize();
01081     ASSERT( offsetbox.intersect_ray( pt, dir, TOL ) );
01082     pt  = scaled_corner( offsetbox, 7, 3.0 );
01083     dir = offsetbox.center - pt;
01084     dir.normalize();
01085     ASSERT( offsetbox.intersect_ray( pt, dir, TOL ) );
01086 
01087     // test ray starting outside face and pointing away from box
01088     pt  = scaled_face( offsetbox, 0, 3.0 );
01089     dir = pt - offsetbox.center;
01090     dir.normalize();
01091     ASSERT( !offsetbox.intersect_ray( pt, dir, TOL ) );
01092     pt  = scaled_face( offsetbox, 1, 3.0 );
01093     dir = pt - offsetbox.center;
01094     dir.normalize();
01095     ASSERT( !offsetbox.intersect_ray( pt, dir, TOL ) );
01096     pt  = scaled_face( offsetbox, 2, 3.0 );
01097     dir = pt - offsetbox.center;
01098     dir.normalize();
01099     ASSERT( !offsetbox.intersect_ray( pt, dir, TOL ) );
01100     pt  = scaled_face( offsetbox, 3, 3.0 );
01101     dir = pt - offsetbox.center;
01102     dir.normalize();
01103     ASSERT( !offsetbox.intersect_ray( pt, dir, TOL ) );
01104     pt  = scaled_face( offsetbox, 4, 3.0 );
01105     dir = pt - offsetbox.center;
01106     dir.normalize();
01107     ASSERT( !offsetbox.intersect_ray( pt, dir, TOL ) );
01108     pt  = scaled_face( offsetbox, 5, 3.0 );
01109     dir = pt - offsetbox.center;
01110     dir.normalize();
01111     ASSERT( !offsetbox.intersect_ray( pt, dir, TOL ) );
01112 
01113     // test ray starting outside face and parallel to face
01114     pt  = scaled_face( offsetbox, 0, 3.0 );
01115     dir = offsetbox.scaled_axis( 1 );
01116     dir.normalize();
01117     ASSERT( !offsetbox.intersect_ray( pt, dir, TOL ) );
01118     pt  = scaled_face( offsetbox, 1, 3.0 );
01119     dir = offsetbox.scaled_axis( 2 );
01120     dir.normalize();
01121     ASSERT( !offsetbox.intersect_ray( pt, dir, TOL ) );
01122     pt  = scaled_face( offsetbox, 2, 3.0 );
01123     dir = offsetbox.scaled_axis( 0 );
01124     dir.normalize();
01125     ASSERT( !offsetbox.intersect_ray( pt, dir, TOL ) );
01126     pt  = scaled_face( offsetbox, 3, 3.0 );
01127     dir = offsetbox.scaled_axis( 2 );
01128     dir.normalize();
01129     ASSERT( !offsetbox.intersect_ray( pt, dir, TOL ) );
01130     pt  = scaled_face( offsetbox, 4, 3.0 );
01131     dir = offsetbox.scaled_axis( 0 );
01132     dir.normalize();
01133     ASSERT( !offsetbox.intersect_ray( pt, dir, TOL ) );
01134     pt  = scaled_face( offsetbox, 5, 3.0 );
01135     dir = offsetbox.scaled_axis( 1 );
01136     dir.normalize();
01137     ASSERT( !offsetbox.intersect_ray( pt, dir, TOL ) );
01138 
01139     // next do oblong box
01140 
01141     // test ray from box center towards each face
01142     dir = scaled_face( oblongbox, 0, 1.0 ) - oblongbox.center;
01143     dir.normalize();
01144     ASSERT( oblongbox.intersect_ray( oblongbox.center, dir, TOL ) );
01145     dir = scaled_face( oblongbox, 1, 1.0 ) - oblongbox.center;
01146     dir.normalize();
01147     ASSERT( oblongbox.intersect_ray( oblongbox.center, dir, TOL ) );
01148     dir = scaled_face( oblongbox, 2, 1.0 ) - oblongbox.center;
01149     dir.normalize();
01150     ASSERT( oblongbox.intersect_ray( oblongbox.center, dir, TOL ) );
01151     dir = scaled_face( oblongbox, 3, 1.0 ) - oblongbox.center;
01152     dir.normalize();
01153     ASSERT( oblongbox.intersect_ray( oblongbox.center, dir, TOL ) );
01154     dir = scaled_face( oblongbox, 4, 1.0 ) - oblongbox.center;
01155     dir.normalize();
01156     ASSERT( oblongbox.intersect_ray( oblongbox.center, dir, TOL ) );
01157     dir = scaled_face( oblongbox, 5, 1.0 ) - oblongbox.center;
01158     dir.normalize();
01159     ASSERT( oblongbox.intersect_ray( oblongbox.center, dir, TOL ) );
01160 
01161     // test ray starting outside each face and pointing towards box center
01162     pt  = scaled_face( oblongbox, 0, 3.0 );
01163     dir = oblongbox.center - pt;
01164     dir.normalize();
01165     ASSERT( oblongbox.intersect_ray( pt, dir, TOL ) );
01166     pt  = scaled_face( oblongbox, 1, 3.0 );
01167     dir = oblongbox.center - pt;
01168     dir.normalize();
01169     ASSERT( oblongbox.intersect_ray( pt, dir, TOL ) );
01170     pt  = scaled_face( oblongbox, 2, 3.0 );
01171     dir = oblongbox.center - pt;
01172     dir.normalize();
01173     ASSERT( oblongbox.intersect_ray( pt, dir, TOL ) );
01174     pt  = scaled_face( oblongbox, 3, 3.0 );
01175     dir = oblongbox.center - pt;
01176     dir.normalize();
01177     ASSERT( oblongbox.intersect_ray( pt, dir, TOL ) );
01178     pt  = scaled_face( oblongbox, 4, 3.0 );
01179     dir = oblongbox.center - pt;
01180     dir.normalize();
01181     ASSERT( oblongbox.intersect_ray( pt, dir, TOL ) );
01182     pt  = scaled_face( oblongbox, 5, 3.0 );
01183     dir = oblongbox.center - pt;
01184     dir.normalize();
01185     ASSERT( oblongbox.intersect_ray( pt, dir, TOL ) );
01186 
01187     // test ray starting inside box and passing through a corner
01188     pt  = scaled_corner( oblongbox, 0, 0.3 );
01189     dir = pt - oblongbox.center;
01190     dir.normalize();
01191     ASSERT( oblongbox.intersect_ray( pt, dir, TOL ) );
01192     pt  = scaled_corner( oblongbox, 1, 0.3 );
01193     dir = pt - oblongbox.center;
01194     dir.normalize();
01195     ASSERT( oblongbox.intersect_ray( pt, dir, TOL ) );
01196     pt  = scaled_corner( oblongbox, 2, 0.3 );
01197     dir = pt - oblongbox.center;
01198     dir.normalize();
01199     ASSERT( oblongbox.intersect_ray( pt, dir, TOL ) );
01200     pt  = scaled_corner( oblongbox, 3, 0.3 );
01201     dir = pt - oblongbox.center;
01202     dir.normalize();
01203     ASSERT( oblongbox.intersect_ray( pt, dir, TOL ) );
01204     pt  = scaled_corner( oblongbox, 4, 0.3 );
01205     dir = pt - oblongbox.center;
01206     dir.normalize();
01207     ASSERT( oblongbox.intersect_ray( pt, dir, TOL ) );
01208     pt  = scaled_corner( oblongbox, 5, 0.3 );
01209     dir = pt - oblongbox.center;
01210     dir.normalize();
01211     ASSERT( oblongbox.intersect_ray( pt, dir, TOL ) );
01212     pt  = scaled_corner( oblongbox, 6, 0.3 );
01213     dir = pt - oblongbox.center;
01214     dir.normalize();
01215     ASSERT( oblongbox.intersect_ray( pt, dir, TOL ) );
01216     pt  = scaled_corner( oblongbox, 7, 0.3 );
01217     dir = pt - oblongbox.center;
01218     dir.normalize();
01219     ASSERT( oblongbox.intersect_ray( pt, dir, TOL ) );
01220 
01221     // test ray starting outside box and passing through opposite corners
01222     pt  = scaled_corner( oblongbox, 0, 3.0 );
01223     dir = oblongbox.center - pt;
01224     dir.normalize();
01225     ASSERT( oblongbox.intersect_ray( pt, dir, TOL ) );
01226     pt  = scaled_corner( oblongbox, 1, 3.0 );
01227     dir = oblongbox.center - pt;
01228     dir.normalize();
01229     ASSERT( oblongbox.intersect_ray( pt, dir, TOL ) );
01230     pt  = scaled_corner( oblongbox, 2, 3.0 );
01231     dir = oblongbox.center - pt;
01232     dir.normalize();
01233     ASSERT( oblongbox.intersect_ray( pt, dir, TOL ) );
01234     pt  = scaled_corner( oblongbox, 3, 3.0 );
01235     dir = oblongbox.center - pt;
01236     dir.normalize();
01237     ASSERT( oblongbox.intersect_ray( pt, dir, TOL ) );
01238     pt  = scaled_corner( oblongbox, 4, 3.0 );
01239     dir = oblongbox.center - pt;
01240     dir.normalize();
01241     ASSERT( oblongbox.intersect_ray( pt, dir, TOL ) );
01242     pt  = scaled_corner( oblongbox, 5, 3.0 );
01243     dir = oblongbox.center - pt;
01244     dir.normalize();
01245     ASSERT( oblongbox.intersect_ray( pt, dir, TOL ) );
01246     pt  = scaled_corner( oblongbox, 6, 3.0 );
01247     dir = oblongbox.center - pt;
01248     dir.normalize();
01249     ASSERT( oblongbox.intersect_ray( pt, dir, TOL ) );
01250     pt  = scaled_corner( oblongbox, 7, 3.0 );
01251     dir = oblongbox.center - pt;
01252     dir.normalize();
01253     ASSERT( oblongbox.intersect_ray( pt, dir, TOL ) );
01254 
01255     // test ray starting outside face and pointing away from box
01256     pt  = scaled_face( oblongbox, 0, 3.0 );
01257     dir = pt - oblongbox.center;
01258     dir.normalize();
01259     ASSERT( !oblongbox.intersect_ray( pt, dir, TOL ) );
01260     pt  = scaled_face( oblongbox, 1, 3.0 );
01261     dir = pt - oblongbox.center;
01262     dir.normalize();
01263     ASSERT( !oblongbox.intersect_ray( pt, dir, TOL ) );
01264     pt  = scaled_face( oblongbox, 2, 3.0 );
01265     dir = pt - oblongbox.center;
01266     dir.normalize();
01267     ASSERT( !oblongbox.intersect_ray( pt, dir, TOL ) );
01268     pt  = scaled_face( oblongbox, 3, 3.0 );
01269     dir = pt - oblongbox.center;
01270     dir.normalize();
01271     ASSERT( !oblongbox.intersect_ray( pt, dir, TOL ) );
01272     pt  = scaled_face( oblongbox, 4, 3.0 );
01273     dir = pt - oblongbox.center;
01274     dir.normalize();
01275     ASSERT( !oblongbox.intersect_ray( pt, dir, TOL ) );
01276     pt  = scaled_face( oblongbox, 5, 3.0 );
01277     dir = pt - oblongbox.center;
01278     dir.normalize();
01279     ASSERT( !oblongbox.intersect_ray( pt, dir, TOL ) );
01280 
01281     // test ray starting outside face and parallel to face
01282     pt  = scaled_face( oblongbox, 0, 3.0 );
01283     dir = oblongbox.scaled_axis( 1 );
01284     dir.normalize();
01285     ASSERT( !oblongbox.intersect_ray( pt, dir, TOL ) );
01286     pt  = scaled_face( oblongbox, 1, 3.0 );
01287     dir = oblongbox.scaled_axis( 2 );
01288     dir.normalize();
01289     ASSERT( !oblongbox.intersect_ray( pt, dir, TOL ) );
01290     pt  = scaled_face( oblongbox, 2, 3.0 );
01291     dir = oblongbox.scaled_axis( 0 );
01292     dir.normalize();
01293     ASSERT( !oblongbox.intersect_ray( pt, dir, TOL ) );
01294     pt  = scaled_face( oblongbox, 3, 3.0 );
01295     dir = oblongbox.scaled_axis( 2 );
01296     dir.normalize();
01297     ASSERT( !oblongbox.intersect_ray( pt, dir, TOL ) );
01298     pt  = scaled_face( oblongbox, 4, 3.0 );
01299     dir = oblongbox.scaled_axis( 0 );
01300     dir.normalize();
01301     ASSERT( !oblongbox.intersect_ray( pt, dir, TOL ) );
01302     pt  = scaled_face( oblongbox, 5, 3.0 );
01303     dir = oblongbox.scaled_axis( 1 );
01304     dir.normalize();
01305     ASSERT( !oblongbox.intersect_ray( pt, dir, TOL ) );
01306 
01307     // next do rotated box
01308 
01309     // test ray from box center towards each face
01310     dir = scaled_face( rotbox, 0, 1.0 ) - rotbox.center;
01311     dir.normalize();
01312     ASSERT( rotbox.intersect_ray( rotbox.center, dir, TOL ) );
01313     dir = scaled_face( rotbox, 1, 1.0 ) - rotbox.center;
01314     dir.normalize();
01315     ASSERT( rotbox.intersect_ray( rotbox.center, dir, TOL ) );
01316     dir = scaled_face( rotbox, 2, 1.0 ) - rotbox.center;
01317     dir.normalize();
01318     ASSERT( rotbox.intersect_ray( rotbox.center, dir, TOL ) );
01319     dir = scaled_face( rotbox, 3, 1.0 ) - rotbox.center;
01320     dir.normalize();
01321     ASSERT( rotbox.intersect_ray( rotbox.center, dir, TOL ) );
01322     dir = scaled_face( rotbox, 4, 1.0 ) - rotbox.center;
01323     dir.normalize();
01324     ASSERT( rotbox.intersect_ray( rotbox.center, dir, TOL ) );
01325     dir = scaled_face( rotbox, 5, 1.0 ) - rotbox.center;
01326     dir.normalize();
01327     ASSERT( rotbox.intersect_ray( rotbox.center, dir, TOL ) );
01328 
01329     // test ray starting outside each face and pointing towards box center
01330     pt  = scaled_face( rotbox, 0, 3.0 );
01331     dir = rotbox.center - pt;
01332     dir.normalize();
01333     ASSERT( rotbox.intersect_ray( pt, dir, TOL ) );
01334     pt  = scaled_face( rotbox, 1, 3.0 );
01335     dir = rotbox.center - pt;
01336     dir.normalize();
01337     ASSERT( rotbox.intersect_ray( pt, dir, TOL ) );
01338     pt  = scaled_face( rotbox, 2, 3.0 );
01339     dir = rotbox.center - pt;
01340     dir.normalize();
01341     ASSERT( rotbox.intersect_ray( pt, dir, TOL ) );
01342     pt  = scaled_face( rotbox, 3, 3.0 );
01343     dir = rotbox.center - pt;
01344     dir.normalize();
01345     ASSERT( rotbox.intersect_ray( pt, dir, TOL ) );
01346     pt  = scaled_face( rotbox, 4, 3.0 );
01347     dir = rotbox.center - pt;
01348     dir.normalize();
01349     ASSERT( rotbox.intersect_ray( pt, dir, TOL ) );
01350     pt  = scaled_face( rotbox, 5, 3.0 );
01351     dir = rotbox.center - pt;
01352     dir.normalize();
01353     ASSERT( rotbox.intersect_ray( pt, dir, TOL ) );
01354 
01355     // test ray starting inside box and passing through a corner
01356     pt  = scaled_corner( rotbox, 0, 0.3 );
01357     dir = pt - rotbox.center;
01358     dir.normalize();
01359     ASSERT( rotbox.intersect_ray( pt, dir, TOL ) );
01360     pt  = scaled_corner( rotbox, 1, 0.3 );
01361     dir = pt - rotbox.center;
01362     dir.normalize();
01363     ASSERT( rotbox.intersect_ray( pt, dir, TOL ) );
01364     pt  = scaled_corner( rotbox, 2, 0.3 );
01365     dir = pt - rotbox.center;
01366     dir.normalize();
01367     ASSERT( rotbox.intersect_ray( pt, dir, TOL ) );
01368     pt  = scaled_corner( rotbox, 3, 0.3 );
01369     dir = pt - rotbox.center;
01370     dir.normalize();
01371     ASSERT( rotbox.intersect_ray( pt, dir, TOL ) );
01372     pt  = scaled_corner( rotbox, 4, 0.3 );
01373     dir = pt - rotbox.center;
01374     dir.normalize();
01375     ASSERT( rotbox.intersect_ray( pt, dir, TOL ) );
01376     pt  = scaled_corner( rotbox, 5, 0.3 );
01377     dir = pt - rotbox.center;
01378     dir.normalize();
01379     ASSERT( rotbox.intersect_ray( pt, dir, TOL ) );
01380     pt  = scaled_corner( rotbox, 6, 0.3 );
01381     dir = pt - rotbox.center;
01382     dir.normalize();
01383     ASSERT( rotbox.intersect_ray( pt, dir, TOL ) );
01384     pt  = scaled_corner( rotbox, 7, 0.3 );
01385     dir = pt - rotbox.center;
01386     dir.normalize();
01387     ASSERT( rotbox.intersect_ray( pt, dir, TOL ) );
01388 
01389     // test ray starting outside box and passing through opposite corners
01390     pt  = scaled_corner( rotbox, 0, 3.0 );
01391     dir = rotbox.center - pt;
01392     dir.normalize();
01393     ASSERT( rotbox.intersect_ray( pt, dir, TOL ) );
01394     pt  = scaled_corner( rotbox, 1, 3.0 );
01395     dir = rotbox.center - pt;
01396     dir.normalize();
01397     ASSERT( rotbox.intersect_ray( pt, dir, TOL ) );
01398     pt  = scaled_corner( rotbox, 2, 3.0 );
01399     dir = rotbox.center - pt;
01400     dir.normalize();
01401     ASSERT( rotbox.intersect_ray( pt, dir, TOL ) );
01402     pt  = scaled_corner( rotbox, 3, 3.0 );
01403     dir = rotbox.center - pt;
01404     dir.normalize();
01405     ASSERT( rotbox.intersect_ray( pt, dir, TOL ) );
01406     pt  = scaled_corner( rotbox, 4, 3.0 );
01407     dir = rotbox.center - pt;
01408     dir.normalize();
01409     ASSERT( rotbox.intersect_ray( pt, dir, TOL ) );
01410     pt  = scaled_corner( rotbox, 5, 3.0 );
01411     dir = rotbox.center - pt;
01412     dir.normalize();
01413     ASSERT( rotbox.intersect_ray( pt, dir, TOL ) );
01414     pt  = scaled_corner( rotbox, 6, 3.0 );
01415     dir = rotbox.center - pt;
01416     dir.normalize();
01417     ASSERT( rotbox.intersect_ray( pt, dir, TOL ) );
01418     pt  = scaled_corner( rotbox, 7, 3.0 );
01419     dir = rotbox.center - pt;
01420     dir.normalize();
01421     ASSERT( rotbox.intersect_ray( pt, dir, TOL ) );
01422 
01423     // test ray starting outside face and pointing away from box
01424     pt  = scaled_face( rotbox, 0, 3.0 );
01425     dir = pt - rotbox.center;
01426     dir.normalize();
01427     ASSERT( !rotbox.intersect_ray( pt, dir, TOL ) );
01428     pt  = scaled_face( rotbox, 1, 3.0 );
01429     dir = pt - rotbox.center;
01430     dir.normalize();
01431     ASSERT( !rotbox.intersect_ray( pt, dir, TOL ) );
01432     pt  = scaled_face( rotbox, 2, 3.0 );
01433     dir = pt - rotbox.center;
01434     dir.normalize();
01435     ASSERT( !rotbox.intersect_ray( pt, dir, TOL ) );
01436     pt  = scaled_face( rotbox, 3, 3.0 );
01437     dir = pt - rotbox.center;
01438     dir.normalize();
01439     ASSERT( !rotbox.intersect_ray( pt, dir, TOL ) );
01440     pt  = scaled_face( rotbox, 4, 3.0 );
01441     dir = pt - rotbox.center;
01442     dir.normalize();
01443     ASSERT( !rotbox.intersect_ray( pt, dir, TOL ) );
01444     pt  = scaled_face( rotbox, 5, 3.0 );
01445     dir = pt - rotbox.center;
01446     dir.normalize();
01447     ASSERT( !rotbox.intersect_ray( pt, dir, TOL ) );
01448 
01449     // test ray starting outside face and parallel to face
01450     pt  = scaled_face( rotbox, 0, 3.0 );
01451     dir = rotbox.scaled_axis( 1 );
01452     dir.normalize();
01453     ASSERT( !rotbox.intersect_ray( pt, dir, TOL ) );
01454     pt  = scaled_face( rotbox, 1, 3.0 );
01455     dir = rotbox.scaled_axis( 2 );
01456     dir.normalize();
01457     ASSERT( !rotbox.intersect_ray( pt, dir, TOL ) );
01458     pt  = scaled_face( rotbox, 2, 3.0 );
01459     dir = rotbox.scaled_axis( 0 );
01460     dir.normalize();
01461     ASSERT( !rotbox.intersect_ray( pt, dir, TOL ) );
01462     pt  = scaled_face( rotbox, 3, 3.0 );
01463     dir = rotbox.scaled_axis( 2 );
01464     dir.normalize();
01465     ASSERT( !rotbox.intersect_ray( pt, dir, TOL ) );
01466     pt  = scaled_face( rotbox, 4, 3.0 );
01467     dir = rotbox.scaled_axis( 0 );
01468     dir.normalize();
01469     ASSERT( !rotbox.intersect_ray( pt, dir, TOL ) );
01470     pt  = scaled_face( rotbox, 5, 3.0 );
01471     dir = rotbox.scaled_axis( 1 );
01472     dir.normalize();
01473     ASSERT( !rotbox.intersect_ray( pt, dir, TOL ) );
01474 }
01475 
01476 /*!
01477   @test
01478   Construct OBB Box from triangles
01479   @li Check building OBB box from triangles
01480 */
01481 void test_build_from_tri()
01482 {
01483     ErrorCode rval;
01484     Core moab;
01485     int i;
01486 
01487     // define a planar patch of triangles
01488     const double coords[] = { 0,  0,  0, 5,   0,  0, 5,  5,  0, 0,  5,  0, -5, 5,   0, -5, 0,  0, -5, -5, 0,
01489                               0,  -5, 0, 5,   -5, 0, 10, 0,  0, 8,  5,  0, 5,  8,   0, 0,  10, 0, -5, 8,  0,
01490                               -8, 5,  0, -10, 0,  0, -8, -5, 0, -5, -8, 0, 0,  -10, 0, 5,  -8, 0, 8,  -5, 0 };
01491     const int conn[]      = { 3, 12, 13, 3, 11, 12, 4, 13, 14, 4, 3,  13, 3, 2, 11, 2, 10, 11,
01492 
01493                          5, 14, 15, 5, 4,  14, 3, 4,  5,  0, 3,  5,  0, 1, 3,  1, 2,  3,  2, 1, 10, 1, 9, 10,
01494 
01495                          5, 15, 16, 6, 5,  16, 5, 6,  7,  0, 5,  7,  1, 0, 7,  1, 7,  8,  1, 8, 20, 9, 1, 20,
01496 
01497                          6, 16, 17, 7, 6,  17, 7, 17, 18, 7, 18, 19, 8, 7, 19, 8, 19, 20 };
01498 
01499     // build triangle mesh
01500     std::vector< EntityHandle > vertices( 21 );
01501     for( i = 0; i < 21; ++i )
01502     {
01503         rval = moab.create_vertex( coords + 3 * i, vertices[i] );
01504         ASSERT( MB_SUCCESS == rval );
01505     }
01506     Range tris;
01507     for( i = 0; i < 28; ++i )
01508     {
01509         EntityHandle tri;
01510         EntityHandle c[3] = { vertices[conn[3 * i]], vertices[conn[3 * i + 1]], vertices[conn[3 * i + 2]] };
01511         rval              = moab.create_element( MBTRI, c, 3, tri );
01512         ASSERT( MB_SUCCESS == rval );
01513         tris.insert( tri );
01514     }
01515 
01516     // create box from triangles
01517     OrientedBox box;
01518     rval = OrientedBox::compute_from_2d_cells( box, &moab, tris );
01519     ASSERT( MB_SUCCESS == rval );
01520 
01521     // compute range along each box axis for input vertices
01522     const Matrix3 axis( box.scaled_axis( 0 ), box.scaled_axis( 1 ), box.scaled_axis( 2 ), false );
01523     double min[3], max[3];
01524     CartVect v = CartVect( coords ) - box.center;
01525     min[0] = max[0] = box.scaled_axis( 0 ) % v;
01526     min[1] = max[1] = box.scaled_axis( 1 ) % v;
01527     min[2] = max[2] = box.scaled_axis( 2 ) % v;
01528     for( i = 1; i < 21; ++i )
01529     {
01530         CartVect vi( coords + 3 * i );
01531         CartVect vLocal = vi - box.center;
01532         for( int j = 0; j < 3; ++j )
01533         {
01534             double d = ( axis.col( j ) % vLocal ) / ( axis.col( j ) % axis.col( j ) );
01535             if( d < min[j] ) min[j] = d;
01536             if( d > max[j] ) max[j] = d;
01537         }
01538     }
01539 
01540     // Vrify that all points are contained in box
01541     // and that box fits points tightly.
01542     // Triangles line in xy plane, so assuming axes are
01543     // sorted by length, first axis should be zero.
01544     ASSERT_DOUBLES_EQUAL( min[1], -1 );
01545     ASSERT_DOUBLES_EQUAL( min[2], -1 );
01546     ASSERT_DOUBLES_EQUAL( max[1], 1 );
01547     ASSERT_DOUBLES_EQUAL( max[2], 1 );
01548 
01549     // verify that the box is flat along first axis
01550     ASSERT( box.dimensions()[0] <= TOL );
01551     // verify that other two axes are in XY plane
01552     const CartVect z_axis( 0.0, 0.0, 1.0 );
01553     ASSERT( fabs( box.axis( 1 ) % z_axis ) <= TOL );
01554     ASSERT( fabs( box.axis( 2 ) % z_axis ) <= TOL );
01555 }
01556 
01557 void test_build_from_pts()
01558 {
01559     ErrorCode rval;
01560     Core moab;
01561     Interface* const gMB = &moab;
01562 
01563     const double vertex_coords[] = { 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1 };
01564     const int num_double         = sizeof( vertex_coords ) / ( sizeof( double ) );
01565     const int num_vertex         = num_double / 3;
01566     assert( 0 == num_double % 3 );
01567 
01568     // create some vertices
01569     Range vertices;
01570     double min[3] = { HUGE_VAL, HUGE_VAL, HUGE_VAL };
01571     double max[3] = { -HUGE_VAL, -HUGE_VAL, -HUGE_VAL };
01572     for( int i = 0; i < num_vertex; ++i )
01573     {
01574         EntityHandle h;
01575         rval = gMB->create_vertex( vertex_coords + 3 * i, h );
01576         ASSERT( MB_SUCCESS == rval );
01577         vertices.insert( h );
01578         for( int j = 0; j < 3; ++j )
01579         {
01580             const double c = vertex_coords[3 * i + j];
01581             if( c < min[j] ) min[j] = c;
01582             if( c > max[j] ) max[j] = c;
01583         }
01584     }
01585 
01586     // create box containing vertices
01587     OrientedBox box;
01588     rval = OrientedBox::compute_from_vertices( box, gMB, vertices );
01589     ASSERT( MB_SUCCESS == rval );
01590 
01591     for( int i = 0; i < num_vertex; ++i )
01592     {
01593         ASSERT( box.contained( CartVect( vertex_coords[3 * i] ), 1e-6 ) );
01594     }
01595 
01596     // define a set of points otside of the box to test
01597     double center[3]   = { 0.5 * ( max[0] + min[0] ), 0.5 * ( max[1] + min[1] ), 0.5 * ( max[2] + min[2] ) };
01598     double diag[3]     = { max[0] - min[0], max[1] - min[1], max[2] - min[2] };
01599     double outside1[3] = { center[0] + diag[0], center[1] + diag[1], center[2] + diag[2] };
01600     double outside2[3] = { center[0] + diag[0], center[1] + diag[1], center[2] };
01601     double outside3[3] = { center[0] + diag[0], center[1], center[2] };
01602     double* outside[3] = { outside1, outside2, outside3 };
01603     // test 'contained' method for all points
01604     for( int i = 0; i < 3; ++i )
01605     {
01606         ASSERT( !box.contained( CartVect( outside[i] ), 1e-6 ) );
01607     }
01608 }
01609 
01610 static void test_save()
01611 {
01612     ErrorCode rval;
01613     Core moab;
01614     OrientedBox box;
01615 
01616     // create a tag to store the data in
01617     Tag tag;
01618     rval = OrientedBox::tag_handle( tag, &moab, "FOO" );
01619     ASSERT( MB_SUCCESS == rval );
01620 
01621     // check tag size
01622     int size;
01623     rval = moab.tag_get_bytes( tag, size );
01624     ASSERT( MB_SUCCESS == rval );
01625     ASSERT( size == sizeof( OrientedBox ) );
01626 }
01627 
01628 /********************* Error Checking Code ***************************/
01629 
01630 static void assert_vector_element( const CartVect& a, const Matrix3& b, const char* sa, const char* sb, int lineno )
01631 {
01632     int i;
01633     bool ismatch = false;
01634     for( i = 0; i < 3; ++i )
01635     {
01636         if( fabs( a[0] - b( 0, i ) ) <= TOL && fabs( a[1] - b( 1, i ) ) <= TOL && fabs( a[2] - b( 2, i ) ) <= TOL )
01637         {
01638             ismatch = true;
01639             break;
01640         }
01641     }
01642     if( !ismatch )
01643     {
01644         ++error_count;
01645         std::cerr << "Assertion failed at line " << lineno << std::endl
01646                   << "\t" << sa << " in " << sb << std::endl
01647                   << "\t" << sa << " = " << a << std::endl
01648                   << "\t" << sb << " = " << b << std::endl;
01649     }
01650     return;
01651 }
01652 
01653 void assert_vectors_equal( const CartVect& a, const CartVect& b, const char* sa, const char* sb, int lineno )
01654 {
01655     if( fabs( a[0] - b[0] ) > TOL || fabs( a[1] - b[1] ) > TOL || fabs( a[2] - b[2] ) > TOL )
01656     {
01657         std::cerr << "Assertion failed at line " << lineno << std::endl
01658                   << "\t" << sa << " == " << sb << std::endl
01659                   << "\t[" << a[0] << ", " << a[1] << ", " << a[2] << "] == [" << b[0] << ", " << b[1] << ", " << b[2]
01660                   << "]" << std::endl;
01661         ++error_count;
01662     }
01663 }
01664 
01665 void assert_doubles_equal( double a, double b, const char* sa, const char* sb, int lineno )
01666 {
01667     if( fabs( a - b ) > TOL )
01668     {
01669         std::cerr << "Assertion failed at line " << lineno << std::endl
01670                   << "\t" << sa << " == " << sb << std::endl
01671                   << "\t" << a << " == " << b << std::endl;
01672         ++error_count;
01673     }
01674 }
01675 
01676 void assert_bool( bool b, const char* sb, int lineno )
01677 {
01678     if( !b )
01679     {
01680         std::cerr << "Assertion failed at line " << lineno << std::endl << "\t" << sb << std::endl;
01681         ++error_count;
01682     }
01683 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines