From d0c9b7ba3d21ca82d674d01833a1e45e24d359f7 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Fri, 7 Dec 2012 13:38:39 +0100 Subject: [PATCH] Added extra tests to move functions. --- .../PolyVoxCore/LargeVolumeSampler.inl | 12 ++--- .../include/PolyVoxCore/RawVolumeSampler.inl | 54 ++++++++++++++++--- .../PolyVoxCore/SimpleVolumeSampler.inl | 12 ++--- tests/testvolume.cpp | 8 +-- 4 files changed, 64 insertions(+), 22 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl index 733de9b3..81d5baa9 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl @@ -145,7 +145,7 @@ namespace PolyVox BaseVolume::template Sampler< LargeVolume >::movePositiveX(); // Then we update the voxel pointer - if((this->mXPosInVolume) % this->mVolume->m_uBlockSideLength != 0) + if((this->isCurrentPositionValid()) && ((this->mXPosInVolume) % this->mVolume->m_uBlockSideLength != 0)) { //No need to compute new block. ++mCurrentVoxel; @@ -164,7 +164,7 @@ namespace PolyVox BaseVolume::template Sampler< LargeVolume >::movePositiveY(); // Then we update the voxel pointer - if((this->mYPosInVolume) % this->mVolume->m_uBlockSideLength != 0) + if((this->isCurrentPositionValid()) && ((this->mYPosInVolume) % this->mVolume->m_uBlockSideLength != 0)) { //No need to compute new block. mCurrentVoxel += this->mVolume->m_uBlockSideLength; @@ -183,7 +183,7 @@ namespace PolyVox BaseVolume::template Sampler< LargeVolume >::movePositiveZ(); // Then we update the voxel pointer - if((this->mZPosInVolume) % this->mVolume->m_uBlockSideLength != 0) + if((this->isCurrentPositionValid()) && ((this->mZPosInVolume) % this->mVolume->m_uBlockSideLength != 0)) { //No need to compute new block. mCurrentVoxel += this->mVolume->m_uBlockSideLength * this->mVolume->m_uBlockSideLength; @@ -202,7 +202,7 @@ namespace PolyVox BaseVolume::template Sampler< LargeVolume >::moveNegativeX(); // Then we update the voxel pointer - if((this->mXPosInVolume + 1) % this->mVolume->m_uBlockSideLength != 0) + if((this->isCurrentPositionValid()) && ((this->mXPosInVolume + 1) % this->mVolume->m_uBlockSideLength != 0)) { //No need to compute new block. --mCurrentVoxel; @@ -221,7 +221,7 @@ namespace PolyVox BaseVolume::template Sampler< LargeVolume >::moveNegativeY(); // Then we update the voxel pointer - if((this->mYPosInVolume + 1) % this->mVolume->m_uBlockSideLength != 0) + if((this->isCurrentPositionValid()) && ((this->mYPosInVolume + 1) % this->mVolume->m_uBlockSideLength != 0)) { //No need to compute new block. mCurrentVoxel -= this->mVolume->m_uBlockSideLength; @@ -240,7 +240,7 @@ namespace PolyVox BaseVolume::template Sampler< LargeVolume >::moveNegativeZ(); // Then we update the voxel pointer - if((this->mZPosInVolume + 1) % this->mVolume->m_uBlockSideLength != 0) + if((this->isCurrentPositionValid()) && ((this->mZPosInVolume + 1) % this->mVolume->m_uBlockSideLength != 0)) { //No need to compute new block. mCurrentVoxel -= this->mVolume->m_uBlockSideLength * this->mVolume->m_uBlockSideLength; diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl index 1f4b5864..165a1505 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl @@ -102,7 +102,14 @@ namespace PolyVox BaseVolume::template Sampler< RawVolume >::movePositiveX(); // Then we update the voxel pointer - ++mCurrentVoxel; + if(this->isCurrentPositionValid()) + { + ++mCurrentVoxel; + } + else + { + setPosition(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); + } } template @@ -112,7 +119,14 @@ namespace PolyVox BaseVolume::template Sampler< RawVolume >::movePositiveY(); // Then we update the voxel pointer - mCurrentVoxel += this->mVolume->getWidth(); + if(this->isCurrentPositionValid()) + { + mCurrentVoxel += this->mVolume->getWidth(); + } + else + { + setPosition(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); + } } template @@ -122,7 +136,14 @@ namespace PolyVox BaseVolume::template Sampler< RawVolume >::movePositiveZ(); // Then we update the voxel pointer - mCurrentVoxel += this->mVolume->getWidth() * this->mVolume->getHeight(); + if(this->isCurrentPositionValid()) + { + mCurrentVoxel += this->mVolume->getWidth() * this->mVolume->getHeight(); + } + else + { + setPosition(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); + } } template @@ -132,7 +153,14 @@ namespace PolyVox BaseVolume::template Sampler< RawVolume >::moveNegativeX(); // Then we update the voxel pointer - --mCurrentVoxel; + if(this->isCurrentPositionValid()) + { + --mCurrentVoxel; + } + else + { + setPosition(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); + } } template @@ -142,7 +170,14 @@ namespace PolyVox BaseVolume::template Sampler< RawVolume >::moveNegativeY(); // Then we update the voxel pointer - mCurrentVoxel -= this->mVolume->getWidth(); + if(this->isCurrentPositionValid()) + { + mCurrentVoxel -= this->mVolume->getWidth(); + } + else + { + setPosition(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); + } } template @@ -152,7 +187,14 @@ namespace PolyVox BaseVolume::template Sampler< RawVolume >::moveNegativeZ(); // Then we update the voxel pointer - mCurrentVoxel -= this->mVolume->getWidth() * this->mVolume->getHeight(); + if(this->isCurrentPositionValid()) + { + mCurrentVoxel -= this->mVolume->getWidth() * this->mVolume->getHeight(); + } + else + { + setPosition(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); + } } template diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl index 2f6f62f8..395f104b 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl @@ -164,7 +164,7 @@ namespace PolyVox BaseVolume::template Sampler< SimpleVolume >::movePositiveX(); // Then we update the voxel pointer - if((this->mXPosInVolume) % this->mVolume->m_uBlockSideLength != 0) + if((this->isCurrentPositionValid()) && ((this->mXPosInVolume) % this->mVolume->m_uBlockSideLength != 0)) { //No need to compute new block. ++mCurrentVoxel; @@ -183,7 +183,7 @@ namespace PolyVox BaseVolume::template Sampler< SimpleVolume >::movePositiveY(); // Then we update the voxel pointer - if((this->mYPosInVolume) % this->mVolume->m_uBlockSideLength != 0) + if((this->isCurrentPositionValid()) && ((this->mYPosInVolume) % this->mVolume->m_uBlockSideLength != 0)) { //No need to compute new block. mCurrentVoxel += this->mVolume->m_uBlockSideLength; @@ -202,7 +202,7 @@ namespace PolyVox BaseVolume::template Sampler< SimpleVolume >::movePositiveZ(); // Then we update the voxel pointer - if((this->mZPosInVolume) % this->mVolume->m_uBlockSideLength != 0) + if((this->isCurrentPositionValid()) && ((this->mZPosInVolume) % this->mVolume->m_uBlockSideLength != 0)) { //No need to compute new block. mCurrentVoxel += this->mVolume->m_uBlockSideLength * this->mVolume->m_uBlockSideLength; @@ -221,7 +221,7 @@ namespace PolyVox BaseVolume::template Sampler< SimpleVolume >::moveNegativeX(); // Then we update the voxel pointer - if((this->mXPosInVolume + 1) % this->mVolume->m_uBlockSideLength != 0) + if((this->isCurrentPositionValid()) && ((this->mXPosInVolume + 1) % this->mVolume->m_uBlockSideLength != 0)) { //No need to compute new block. --mCurrentVoxel; @@ -240,7 +240,7 @@ namespace PolyVox BaseVolume::template Sampler< SimpleVolume >::moveNegativeY(); // Then we update the voxel pointer - if((this->mYPosInVolume + 1) % this->mVolume->m_uBlockSideLength != 0) + if((this->isCurrentPositionValid()) && ((this->mYPosInVolume + 1) % this->mVolume->m_uBlockSideLength != 0)) { //No need to compute new block. mCurrentVoxel -= this->mVolume->m_uBlockSideLength; @@ -259,7 +259,7 @@ namespace PolyVox BaseVolume::template Sampler< SimpleVolume >::moveNegativeZ(); // Then we update the voxel pointer - if((this->mZPosInVolume + 1) % this->mVolume->m_uBlockSideLength != 0) + if((this->isCurrentPositionValid()) && ((this->mZPosInVolume + 1) % this->mVolume->m_uBlockSideLength != 0)) { //No need to compute new block. mCurrentVoxel -= this->mVolume->m_uBlockSideLength * this->mVolume->m_uBlockSideLength; diff --git a/tests/testvolume.cpp b/tests/testvolume.cpp index 4f77a5b0..a00771b5 100644 --- a/tests/testvolume.cpp +++ b/tests/testvolume.cpp @@ -116,11 +116,11 @@ int32_t complexVolumeTest(void) zSampler.setWrapMode(WrapModes::Border, 1); sampler.setWrapMode(WrapModes::Border, 1); - //zSampler.setPosition(testVolume.getEnclosingRegion().getLowerX() - 4, testVolume.getEnclosingRegion().getLowerY() - 1, testVolume.getEnclosingRegion().getLowerZ() - 2); + zSampler.setPosition(testVolume.getEnclosingRegion().getLowerX() - 4, testVolume.getEnclosingRegion().getLowerY() - 1, testVolume.getEnclosingRegion().getLowerZ() - 2); for(int z = testVolume.getEnclosingRegion().getLowerZ() - 2; z <= testVolume.getEnclosingRegion().getUpperZ() + 1; z++) { - //ySampler = zSampler; - ySampler.setPosition(testVolume.getEnclosingRegion().getLowerX() - 4, testVolume.getEnclosingRegion().getLowerY() - 1, z); + ySampler = zSampler; + //ySampler.setPosition(testVolume.getEnclosingRegion().getLowerX() - 4, testVolume.getEnclosingRegion().getLowerY() - 1, z); for(int y = testVolume.getEnclosingRegion().getLowerY() - 1; y <= testVolume.getEnclosingRegion().getUpperY() + 3; y++) { xSampler = ySampler; @@ -137,7 +137,7 @@ int32_t complexVolumeTest(void) } ySampler.movePositiveY(); } - //zSampler.movePositiveZ(); + zSampler.movePositiveZ(); } return result;