OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
WBoundingBox_test.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WBOUNDINGBOX_TEST_H
26 #define WBOUNDINGBOX_TEST_H
27 
28 #include <cxxtest/TestSuite.h>
29 
30 #include <osg/Vec3d>
31 
32 #include "../WBoundingBox.h"
33 #include "../WLimits.h"
34 
35 /**
36  * Unit tests for the WBoundingBox wrapper to osg::BoundingBox.
37  */
38 class WBoundingBoxTest : public CxxTest::TestSuite
39 {
40 public:
41  /**
42  * The private subclassing from osg::BoundingBoxImpl makes many member functions private. The
43  * using directive again will publish those members selectively. This is tested in this test.
44  */
46  {
47  WBoundingBox bb( 0.0, 0.0, 0.0, 1.0, 1.0, 1.0 );
48  WBoundingBox bb1( bb );
49  WBoundingBox bb2;
50  WBoundingBox bb3( WVector3d( 0.0, 0.0, 0.0 ), WVector3d( 1.0, 1.0, 1.0 ) );
51  WBoundingBox bb4( osg::Vec3d( 0.0, 0.0, 0.0 ), osg::Vec3d( 1.0, 1.0, 1.0 ) );
52  bb4.expandBy( bb3 );
53  TS_ASSERT( bb4.intersects( bb3 ) );
54  TS_ASSERT_EQUALS( bb2.valid(), false );
55  bb2.reset();
56  }
57 
58  /**
59  * The minimal distance between two bounding boxes is the minimal distance overall vertices of
60  * the first bb to every vertex in the second bb.
61  */
63  {
64  WBoundingBox bb1( 0.0, 0.0, 0.0, 1.0, 1.0, 1.0 );
65  WBoundingBox bb2( 1.5, 0.5, 0.0, 2.5, 1.5, 1.0 );
66  TS_ASSERT_DELTA( bb1.minDistance( bb2 ), 0.5, wlimits::DBL_EPS );
67  }
68 
69  /**
70  * The distance should not depend on the order in which the boxes are given.
71  */
73  {
74  WBoundingBox bb1( 0.0, 0.0, 0.0, 1.0, 1.0, 1.0 );
75  WBoundingBox bb2( 1.5, 0.5, 0.0, 2.5, 1.5, 1.0 );
76  TS_ASSERT_DELTA( bb1.minDistance( bb2 ), 0.5, wlimits::DBL_EPS );
77  TS_ASSERT_DELTA( bb2.minDistance( bb1 ), 0.5, wlimits::DBL_EPS );
78  }
79 
80  /**
81  * Expanding a bounding box by points should update the both corner positions.
82  */
84  {
85  WBoundingBox box;
86  TS_ASSERT( !box.valid() );
87  box.expandBy( WPosition( 0.0, 0.0, 0.0 ) );
88  TS_ASSERT( box.valid() );
89  TS_ASSERT_DELTA( box.xMin(), 0.0, wlimits::DBL_EPS );
90  TS_ASSERT_DELTA( box.yMin(), 0.0, wlimits::DBL_EPS );
91  TS_ASSERT_DELTA( box.zMin(), 0.0, wlimits::DBL_EPS );
92  TS_ASSERT_DELTA( box.xMax(), 0.0, wlimits::DBL_EPS );
93  TS_ASSERT_DELTA( box.yMax(), 0.0, wlimits::DBL_EPS );
94  TS_ASSERT_DELTA( box.zMax(), 0.0, wlimits::DBL_EPS );
95  box.expandBy( WPosition( 1.0, 0.0, 0.0 ) );
96  box.expandBy( WPosition( -1.0, 0.0, 0.0 ) );
97  box.expandBy( WPosition( -1.0, 3.0, 0.0 ) );
98  TS_ASSERT_DELTA( box.xMin(), -1.0, wlimits::DBL_EPS );
99  TS_ASSERT_DELTA( box.yMin(), 0.0, wlimits::DBL_EPS );
100  TS_ASSERT_DELTA( box.zMin(), 0.0, wlimits::DBL_EPS );
101  TS_ASSERT_DELTA( box.xMax(), 1.0, wlimits::DBL_EPS );
102  TS_ASSERT_DELTA( box.yMax(), 3.0, wlimits::DBL_EPS );
103  TS_ASSERT_DELTA( box.zMax(), 0.0, wlimits::DBL_EPS );
104  }
105 };
106 
107 #endif // WBOUNDINGBOX_TEST_H