OpenWalnut
1.4.0
|
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 #include "../math/linearAlgebra/WPosition.h" 00032 00033 #include "../WBoundingBox.h" 00034 #include "../WLimits.h" 00035 00036 /** 00037 * Unit tests for the WBoundingBox wrapper to osg::BoundingBox. 00038 */ 00039 class WBoundingBoxTest : public CxxTest::TestSuite 00040 { 00041 public: 00042 /** 00043 * The private subclassing from osg::BoundingBoxImpl makes many member functions private. The 00044 * using directive again will publish those members selectively. This is tested in this test. 00045 */ 00046 void testForwardingFunctions( void ) 00047 { 00048 WBoundingBox bb( 0.0, 0.0, 0.0, 1.0, 1.0, 1.0 ); 00049 WBoundingBox bb1( bb ); 00050 WBoundingBox bb2; 00051 WBoundingBox bb3( WVector3d( 0.0, 0.0, 0.0 ), WVector3d( 1.0, 1.0, 1.0 ) ); 00052 WBoundingBox bb4( osg::Vec3d( 0.0, 0.0, 0.0 ), osg::Vec3d( 1.0, 1.0, 1.0 ) ); 00053 bb4.expandBy( bb3 ); 00054 TS_ASSERT( bb4.intersects( bb3 ) ); 00055 TS_ASSERT_EQUALS( bb2.valid(), false ); 00056 bb2.reset(); 00057 } 00058 00059 /** 00060 * The minimal distance between two bounding boxes is the minimal distance overall vertices of 00061 * the first bb to every vertex in the second bb. 00062 */ 00063 void testMinimalDistanceBetweenTwoBB( void ) 00064 { 00065 WBoundingBox bb1( 0.0, 0.0, 0.0, 1.0, 1.0, 1.0 ); 00066 WBoundingBox bb2( 1.5, 0.5, 0.0, 2.5, 1.5, 1.0 ); 00067 TS_ASSERT_DELTA( bb1.minDistance( bb2 ), 0.5, wlimits::DBL_EPS ); 00068 } 00069 00070 /** 00071 * The distance should not depend on the order in which the boxes are given. 00072 */ 00073 void testCommutativeIntervalDistance( void ) 00074 { 00075 WBoundingBox bb1( 0.0, 0.0, 0.0, 1.0, 1.0, 1.0 ); 00076 WBoundingBox bb2( 1.5, 0.5, 0.0, 2.5, 1.5, 1.0 ); 00077 TS_ASSERT_DELTA( bb1.minDistance( bb2 ), 0.5, wlimits::DBL_EPS ); 00078 TS_ASSERT_DELTA( bb2.minDistance( bb1 ), 0.5, wlimits::DBL_EPS ); 00079 } 00080 00081 /** 00082 * Expanding a bounding box by points should update the both corner positions. 00083 */ 00084 void testBoundingBoxComputation( void ) 00085 { 00086 WBoundingBox box; 00087 TS_ASSERT( !box.valid() ); 00088 box.expandBy( WPosition( 0.0, 0.0, 0.0 ) ); 00089 TS_ASSERT( box.valid() ); 00090 TS_ASSERT_DELTA( box.xMin(), 0.0, wlimits::DBL_EPS ); 00091 TS_ASSERT_DELTA( box.yMin(), 0.0, wlimits::DBL_EPS ); 00092 TS_ASSERT_DELTA( box.zMin(), 0.0, wlimits::DBL_EPS ); 00093 TS_ASSERT_DELTA( box.xMax(), 0.0, wlimits::DBL_EPS ); 00094 TS_ASSERT_DELTA( box.yMax(), 0.0, wlimits::DBL_EPS ); 00095 TS_ASSERT_DELTA( box.zMax(), 0.0, wlimits::DBL_EPS ); 00096 box.expandBy( WPosition( 1.0, 0.0, 0.0 ) ); 00097 box.expandBy( WPosition( -1.0, 0.0, 0.0 ) ); 00098 box.expandBy( WPosition( -1.0, 3.0, 0.0 ) ); 00099 TS_ASSERT_DELTA( box.xMin(), -1.0, wlimits::DBL_EPS ); 00100 TS_ASSERT_DELTA( box.yMin(), 0.0, wlimits::DBL_EPS ); 00101 TS_ASSERT_DELTA( box.zMin(), 0.0, wlimits::DBL_EPS ); 00102 TS_ASSERT_DELTA( box.xMax(), 1.0, wlimits::DBL_EPS ); 00103 TS_ASSERT_DELTA( box.yMax(), 3.0, wlimits::DBL_EPS ); 00104 TS_ASSERT_DELTA( box.zMax(), 0.0, wlimits::DBL_EPS ); 00105 } 00106 }; 00107 00108 #endif // WBOUNDINGBOX_TEST_H