00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef WBOUNDINGBOX_TEST_H
00026 #define WBOUNDINGBOX_TEST_H
00027
00028 #include <cxxtest/TestSuite.h>
00029
00030 #include <osg/Vec3d>
00031
00032 #include "../WBoundingBox.h"
00033 #include "../WLimits.h"
00034
00035
00036
00037
00038 class WBoundingBoxTest : public CxxTest::TestSuite
00039 {
00040 public:
00041
00042
00043
00044
00045 void testForwardingFunctions( void )
00046 {
00047 WBoundingBox bb( 0.0, 0.0, 0.0, 1.0, 1.0, 1.0 );
00048 WBoundingBox bb1( bb );
00049 WBoundingBox bb2;
00050 WBoundingBox bb3( WVector3d( 0.0, 0.0, 0.0 ), WVector3d( 1.0, 1.0, 1.0 ) );
00051 WBoundingBox bb4( osg::Vec3d( 0.0, 0.0, 0.0 ), osg::Vec3d( 1.0, 1.0, 1.0 ) );
00052 bb4.expandBy( bb3 );
00053 TS_ASSERT( bb4.intersects( bb3 ) );
00054 TS_ASSERT_EQUALS( bb2.valid(), false );
00055 bb2.reset();
00056 }
00057
00058
00059
00060
00061
00062 void testMinimalDistanceBetweenTwoBB( void )
00063 {
00064 WBoundingBox bb1( 0.0, 0.0, 0.0, 1.0, 1.0, 1.0 );
00065 WBoundingBox bb2( 1.5, 0.5, 0.0, 2.5, 1.5, 1.0 );
00066 TS_ASSERT_DELTA( bb1.minDistance( bb2 ), 0.5, wlimits::DBL_EPS );
00067 }
00068
00069
00070
00071
00072 void testCommutativeIntervalDistance( void )
00073 {
00074 WBoundingBox bb1( 0.0, 0.0, 0.0, 1.0, 1.0, 1.0 );
00075 WBoundingBox bb2( 1.5, 0.5, 0.0, 2.5, 1.5, 1.0 );
00076 TS_ASSERT_DELTA( bb1.minDistance( bb2 ), 0.5, wlimits::DBL_EPS );
00077 TS_ASSERT_DELTA( bb2.minDistance( bb1 ), 0.5, wlimits::DBL_EPS );
00078 }
00079
00080
00081
00082
00083 void testBoundingBoxComputation( void )
00084 {
00085 WBoundingBox box;
00086 TS_ASSERT( !box.valid() );
00087 box.expandBy( WPosition( 0.0, 0.0, 0.0 ) );
00088 TS_ASSERT( box.valid() );
00089 TS_ASSERT_DELTA( box.xMin(), 0.0, wlimits::DBL_EPS );
00090 TS_ASSERT_DELTA( box.yMin(), 0.0, wlimits::DBL_EPS );
00091 TS_ASSERT_DELTA( box.zMin(), 0.0, wlimits::DBL_EPS );
00092 TS_ASSERT_DELTA( box.xMax(), 0.0, wlimits::DBL_EPS );
00093 TS_ASSERT_DELTA( box.yMax(), 0.0, wlimits::DBL_EPS );
00094 TS_ASSERT_DELTA( box.zMax(), 0.0, wlimits::DBL_EPS );
00095 box.expandBy( WPosition( 1.0, 0.0, 0.0 ) );
00096 box.expandBy( WPosition( -1.0, 0.0, 0.0 ) );
00097 box.expandBy( WPosition( -1.0, 3.0, 0.0 ) );
00098 TS_ASSERT_DELTA( box.xMin(), -1.0, wlimits::DBL_EPS );
00099 TS_ASSERT_DELTA( box.yMin(), 0.0, wlimits::DBL_EPS );
00100 TS_ASSERT_DELTA( box.zMin(), 0.0, wlimits::DBL_EPS );
00101 TS_ASSERT_DELTA( box.xMax(), 1.0, wlimits::DBL_EPS );
00102 TS_ASSERT_DELTA( box.yMax(), 3.0, wlimits::DBL_EPS );
00103 TS_ASSERT_DELTA( box.zMax(), 0.0, wlimits::DBL_EPS );
00104 }
00105 };
00106
00107 #endif // WBOUNDINGBOX_TEST_H