WBoundingBox_test.h

00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
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  * Unit tests for the WBoundingBox wrapper to osg::BoundingBox.
00037  */
00038 class WBoundingBoxTest : public CxxTest::TestSuite
00039 {
00040 public:
00041     /**
00042      * The private subclassing from osg::BoundingBoxImpl makes many member functions private.  The
00043      * using directive again will publish those members selectively. This is tested in this test.
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      * The minimal distance between two bounding boxes is the minimal distance overall vertices of
00060      * the first bb to every vertex in the second bb.
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      * The distance should not depend on the order in which the boxes are given.
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      * Expanding a bounding box by points should update the both corner positions.
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
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends