OpenWalnut  1.5.0dev
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 #include "../math/linearAlgebra/WPosition.h"
32 
33 #include "../WBoundingBox.h"
34 #include "../WLimits.h"
35 
36 /**
37  * Unit tests for the WBoundingBox wrapper to osg::BoundingBox.
38  */
39 class WBoundingBoxTest : public CxxTest::TestSuite
40 {
41 public:
42  /**
43  * The private subclassing from osg::BoundingBoxImpl makes many member functions private. The
44  * using directive again will publish those members selectively. This is tested in this test.
45  */
47  {
48  WBoundingBox bb( 0.0, 0.0, 0.0, 1.0, 1.0, 1.0 );
49  WBoundingBox bb1( bb );
50  WBoundingBox bb2;
51  WBoundingBox bb3( WVector3d( 0.0, 0.0, 0.0 ), WVector3d( 1.0, 1.0, 1.0 ) );
52  WBoundingBox bb4( osg::Vec3d( 0.0, 0.0, 0.0 ), osg::Vec3d( 1.0, 1.0, 1.0 ) );
53  bb4.expandBy( bb3 );
54  TS_ASSERT( bb4.intersects( bb3 ) );
55  TS_ASSERT_EQUALS( bb2.valid(), false );
56  bb2.reset();
57  }
58 
59  /**
60  * The minimal distance between two bounding boxes is the minimal distance overall vertices of
61  * the first bb to every vertex in the second bb.
62  */
64  {
65  WBoundingBox bb1( 0.0, 0.0, 0.0, 1.0, 1.0, 1.0 );
66  WBoundingBox bb2( 1.5, 0.5, 0.0, 2.5, 1.5, 1.0 );
67  TS_ASSERT_DELTA( bb1.minDistance( bb2 ), 0.5, wlimits::DBL_EPS );
68  }
69 
70  /**
71  * The distance should not depend on the order in which the boxes are given.
72  */
74  {
75  WBoundingBox bb1( 0.0, 0.0, 0.0, 1.0, 1.0, 1.0 );
76  WBoundingBox bb2( 1.5, 0.5, 0.0, 2.5, 1.5, 1.0 );
77  TS_ASSERT_DELTA( bb1.minDistance( bb2 ), 0.5, wlimits::DBL_EPS );
78  TS_ASSERT_DELTA( bb2.minDistance( bb1 ), 0.5, wlimits::DBL_EPS );
79  }
80 
81  /**
82  * Expanding a bounding box by points should update the both corner positions.
83  */
85  {
86  WBoundingBox box;
87  TS_ASSERT( !box.valid() );
88  box.expandBy( WPosition( 0.0, 0.0, 0.0 ) );
89  TS_ASSERT( box.valid() );
90  TS_ASSERT_DELTA( box.xMin(), 0.0, wlimits::DBL_EPS );
91  TS_ASSERT_DELTA( box.yMin(), 0.0, wlimits::DBL_EPS );
92  TS_ASSERT_DELTA( box.zMin(), 0.0, wlimits::DBL_EPS );
93  TS_ASSERT_DELTA( box.xMax(), 0.0, wlimits::DBL_EPS );
94  TS_ASSERT_DELTA( box.yMax(), 0.0, wlimits::DBL_EPS );
95  TS_ASSERT_DELTA( box.zMax(), 0.0, wlimits::DBL_EPS );
96  box.expandBy( WPosition( 1.0, 0.0, 0.0 ) );
97  box.expandBy( WPosition( -1.0, 0.0, 0.0 ) );
98  box.expandBy( WPosition( -1.0, 3.0, 0.0 ) );
99  TS_ASSERT_DELTA( box.xMin(), -1.0, wlimits::DBL_EPS );
100  TS_ASSERT_DELTA( box.yMin(), 0.0, wlimits::DBL_EPS );
101  TS_ASSERT_DELTA( box.zMin(), 0.0, wlimits::DBL_EPS );
102  TS_ASSERT_DELTA( box.xMax(), 1.0, wlimits::DBL_EPS );
103  TS_ASSERT_DELTA( box.yMax(), 3.0, wlimits::DBL_EPS );
104  TS_ASSERT_DELTA( box.zMax(), 0.0, wlimits::DBL_EPS );
105  }
106 };
107 
108 #endif // WBOUNDINGBOX_TEST_H
bool intersects(const WBoundingBoxImpl< VT > &bb) const
Checks for intersection of this bounding box with the specified bounding box.
Definition: WBoundingBox.h:246
value_type minDistance(const WBoundingBoxImpl< VT > &bb) const
Computes the minimal distance of tow axis parallel bounding boxes.
Definition: WBoundingBox.h:266
void expandBy(const WBoundingBoxImpl< VT > &bb)
Expands this bounding box to include the given bounding box.
Definition: WBoundingBox.h:240
void reset()
Resets this box to an initial state where max is FLT_MIN and min FLT_MAX.
Definition: WBoundingBox.h:222
Unit tests for the WBoundingBox wrapper to osg::BoundingBox.
void testBoundingBoxComputation(void)
Expanding a bounding box by points should update the both corner positions.
void testForwardingFunctions(void)
The private subclassing from osg::BoundingBoxImpl makes many member functions private.
void testMinimalDistanceBetweenTwoBB(void)
The minimal distance between two bounding boxes is the minimal distance overall vertices of the first...
void testCommutativeIntervalDistance(void)
The distance should not depend on the order in which the boxes are given.
This only is a 3d double vector.
const double DBL_EPS
Smallest double such: 1.0 + DBL_EPS == 1.0 is still true.
Definition: WLimits.cpp:46