From b8f76fdf10507b723385cf51de30f037a3a818c8 Mon Sep 17 00:00:00 2001 From: Alexander Wiebel Date: Tue, 10 Aug 2010 14:34:57 +0200 Subject: [PATCH] [FIX #347] encloses now accepts and rejects the points as desired. Adapted test accordingly --- src/dataHandler/WGridRegular3D.cpp | 2 +- src/dataHandler/WGridRegular3D.h | 5 +++-- src/dataHandler/test/WGridRegular3D_test.h | 19 +++++++++++++++++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/dataHandler/WGridRegular3D.cpp b/src/dataHandler/WGridRegular3D.cpp index 8a426f722..0509d7f2d 100644 --- a/src/dataHandler/WGridRegular3D.cpp +++ b/src/dataHandler/WGridRegular3D.cpp @@ -389,7 +389,7 @@ int WGridRegular3D::getNVoxelCoord( const wmath::WPosition& pos, size_t axis ) c break; default : WAssert( false, "Invalid axis selected, must be between 0 and 2, including 0 and 2." ); } - if( result < 0 || result > offsetAxis * ( nbAxisPos - 1 ) ) + if( result < 0 || result >= offsetAxis * ( nbAxisPos - 1 ) ) { return -1; } diff --git a/src/dataHandler/WGridRegular3D.h b/src/dataHandler/WGridRegular3D.h index d2a624669..8d0f9b775 100644 --- a/src/dataHandler/WGridRegular3D.h +++ b/src/dataHandler/WGridRegular3D.h @@ -277,7 +277,7 @@ public: \endverbatim * * Please note the first voxel has only 1/8 of the size a normal voxel - * would have since all positions outside the grid does not belonging + * would have since all positions outside the grid do not belong * to any voxel. Note: a cell is different to a voxel in terms of position. * A voxel has a grid point as center whereas a cell has grid points as * corners. @@ -338,7 +338,8 @@ public: wmath::WValue< int > getVoxelCoord( const wmath::WPosition& pos ) const; /** - * Computes the id of the cell containing the position pos. + * Computes the id of the cell containing the position pos. Note that the upper + * bound of the grid does not belong to any cell * * \param pos The position selecting the cell. * \param success True if the position pos is inside the grid. diff --git a/src/dataHandler/test/WGridRegular3D_test.h b/src/dataHandler/test/WGridRegular3D_test.h index 1d8b2f44e..b832bfd63 100644 --- a/src/dataHandler/test/WGridRegular3D_test.h +++ b/src/dataHandler/test/WGridRegular3D_test.h @@ -564,9 +564,24 @@ public: void testEnclosesQuery( void ) { WGridRegular3D g( 2, 2, 2, 1., 1., 1. ); + + // Test bounds for X direction + TS_ASSERT( !g.encloses( wmath::WPosition( 0 - wlimits::FLT_EPS, 0, 0 ) ) ); + TS_ASSERT( g.encloses( wmath::WPosition( 0, 0, 0 ) ) ); + TS_ASSERT( g.encloses( wmath::WPosition( 1.0 - wlimits::FLT_EPS, 0.5, 0.5 ) ) ); + TS_ASSERT( !g.encloses( wmath::WPosition( 1, 0.5, 0.5 ) ) ); + + // Test bounds for Y direction + TS_ASSERT( !g.encloses( wmath::WPosition( 0, 0 - wlimits::FLT_EPS, 0 ) ) ); + TS_ASSERT( g.encloses( wmath::WPosition( 0, 0, 0 ) ) ); + TS_ASSERT( g.encloses( wmath::WPosition( 0.5, 1.0 - wlimits::FLT_EPS, 0.5 ) ) ); + TS_ASSERT( !g.encloses( wmath::WPosition( 0.5, 1.0 ,0.5 ) ) ); + + // Test bounds for Z direction + TS_ASSERT( !g.encloses( wmath::WPosition( 0, 0, 0 - wlimits::FLT_EPS ) ) ); TS_ASSERT( g.encloses( wmath::WPosition( 0, 0, 0 ) ) ); - TS_ASSERT( g.encloses( wmath::WPosition( 1, 1, 1 ) ) ); - TS_ASSERT( !g.encloses( wmath::WPosition( 1, 1, 1.0 + wlimits::DBL_EPS ) ) ); + TS_ASSERT( g.encloses( wmath::WPosition( 0.5, 0.5, 1.0 - wlimits::FLT_EPS ) ) ); + TS_ASSERT( !g.encloses( wmath::WPosition( 0.5, 0.5, 1 ) ) ); } private: -- GitLab