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