diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h
index 04d70756..4eeb5c62 100644
--- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h
+++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h
@@ -147,9 +147,9 @@ namespace PolyVox
/// Gets the length of the diagonal in voxels
float getDiagonalLength(void) const;
/// Gets a voxel at the position given by x,y,z coordinates
- VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
+ VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, bool bPerformBoundsChecks = true) const;
/// Gets a voxel at the position given by a 3D vector
- VoxelType getVoxel(const Vector3DInt32& v3dPos) const;
+ VoxelType getVoxel(const Vector3DInt32& v3dPos, bool bPerformBoundsChecks = true) const;
/// Gets a voxel at the position given by x,y,z coordinates
VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
/// Gets a voxel at the position given by a 3D vector
diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl
index 2103726d..b4237b18 100644
--- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl
+++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl
@@ -160,7 +160,7 @@ namespace PolyVox
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template
- VoxelType BaseVolume::getVoxel(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/) const
+ VoxelType BaseVolume::getVoxel(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/, bool /*bPerformBoundsChecks*/) const
{
POLYVOX_THROW(not_implemented, "You should never call the base class version of this function.");
return VoxelType();
@@ -171,7 +171,7 @@ namespace PolyVox
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template
- VoxelType BaseVolume::getVoxel(const Vector3DInt32& /*v3dPos*/) const
+ VoxelType BaseVolume::getVoxel(const Vector3DInt32& /*v3dPos*/, bool /*bPerformBoundsChecks*/) const
{
POLYVOX_THROW(not_implemented, "You should never call the base class version of this function.");
return VoxelType();
diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h
index 2be3f87d..ca4a8bb4 100644
--- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h
+++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h
@@ -266,9 +266,9 @@ namespace PolyVox
~LargeVolume();
/// Gets a voxel at the position given by x,y,z coordinates
- VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
+ VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, bool bPerformBoundsChecks = true) const;
/// Gets a voxel at the position given by a 3D vector
- VoxelType getVoxel(const Vector3DInt32& v3dPos) const;
+ VoxelType getVoxel(const Vector3DInt32& v3dPos, bool bPerformBoundsChecks = true) const;
/// Gets a voxel at the position given by x,y,z coordinates
VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
/// Gets a voxel at the position given by a 3D vector
diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl
index 76d4049a..0f2826b6 100644
--- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl
+++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl
@@ -122,10 +122,17 @@ namespace PolyVox
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template
- VoxelType LargeVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const
+ VoxelType LargeVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, bool bPerformBoundsChecks) const
{
- // PolyVox does not throw an exception when a voxel is out of range. Please see 'Error Handling' in the User Manual.
- POLYVOX_ASSERT(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)), "Position is outside valid region");
+ // If bounds checking is enabled then we validate the
+ // bounds, and throw an exception if they are violated.
+ if(bPerformBoundsChecks)
+ {
+ if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false)
+ {
+ POLYVOX_THROW(std::out_of_range, "Position is outside valid region");
+ }
+ }
const int32_t blockX = uXPos >> m_uBlockSideLengthPower;
const int32_t blockY = uYPos >> m_uBlockSideLengthPower;
@@ -145,9 +152,9 @@ namespace PolyVox
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template
- VoxelType LargeVolume::getVoxel(const Vector3DInt32& v3dPos) const
+ VoxelType LargeVolume::getVoxel(const Vector3DInt32& v3dPos, bool bPerformBoundsChecks) const
{
- return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
+ return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), bPerformBoundsChecks);
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h
index e4549e1f..f50087a7 100644
--- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h
+++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h
@@ -116,9 +116,9 @@ namespace PolyVox
~RawVolume();
/// Gets a voxel at the position given by x,y,z coordinates
- VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
+ VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, bool bPerformBoundsChecks = true) const;
/// Gets a voxel at the position given by a 3D vector
- VoxelType getVoxel(const Vector3DInt32& v3dPos) const;
+ VoxelType getVoxel(const Vector3DInt32& v3dPos, bool bPerformBoundsChecks = true) const;
/// Gets a voxel at the position given by x,y,z coordinates
VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
/// Gets a voxel at the position given by a 3D vector
diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl
index c6face08..668ad929 100644
--- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl
+++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl
@@ -80,10 +80,17 @@ namespace PolyVox
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template
- VoxelType RawVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const
+ VoxelType RawVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, bool bPerformBoundsChecks) const
{
- // PolyVox does not throw an exception when a voxel is out of range. Please see 'Error Handling' in the User Manual.
- POLYVOX_ASSERT(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)), "Position is outside valid region");
+ // If bounds checking is enabled then we validate the
+ // bounds, and throw an exception if they are violated.
+ if(bPerformBoundsChecks)
+ {
+ if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false)
+ {
+ POLYVOX_THROW(std::out_of_range, "Position is outside valid region");
+ }
+ }
const Vector3DInt32& v3dLowerCorner = this->m_regValidRegion.getLowerCorner();
int32_t iLocalXPos = uXPos - v3dLowerCorner.getX();
@@ -103,9 +110,9 @@ namespace PolyVox
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template
- VoxelType RawVolume::getVoxel(const Vector3DInt32& v3dPos) const
+ VoxelType RawVolume::getVoxel(const Vector3DInt32& v3dPos, bool bPerformBoundsChecks) const
{
- return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
+ return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), bPerformBoundsChecks);
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h
index 8ce2083e..7b4b11b0 100644
--- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h
+++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h
@@ -155,9 +155,9 @@ namespace PolyVox
~SimpleVolume();
/// Gets a voxel at the position given by x,y,z coordinates
- VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
+ VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, bool bPerformBoundsChecks = true) const;
/// Gets a voxel at the position given by a 3D vector
- VoxelType getVoxel(const Vector3DInt32& v3dPos) const;
+ VoxelType getVoxel(const Vector3DInt32& v3dPos, bool bPerformBoundsChecks = true) const;
/// Gets a voxel at the position given by x,y,z coordinates
VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
/// Gets a voxel at the position given by a 3D vector
diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl
index 573f3c83..13fdfae9 100644
--- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl
+++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl
@@ -80,10 +80,17 @@ namespace PolyVox
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template
- VoxelType SimpleVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const
+ VoxelType SimpleVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, bool bPerformBoundsChecks) const
{
- // PolyVox does not throw an exception when a voxel is out of range. Please see 'Error Handling' in the User Manual.
- POLYVOX_ASSERT(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)), "Position is outside valid region");
+ // If bounds checking is enabled then we validate the
+ // bounds, and throw an exception if they are violated.
+ if(bPerformBoundsChecks)
+ {
+ if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false)
+ {
+ POLYVOX_THROW(std::out_of_range, "Position is outside valid region");
+ }
+ }
const int32_t blockX = uXPos >> m_uBlockSideLengthPower;
const int32_t blockY = uYPos >> m_uBlockSideLengthPower;
@@ -103,9 +110,9 @@ namespace PolyVox
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template
- VoxelType SimpleVolume::getVoxel(const Vector3DInt32& v3dPos) const
+ VoxelType SimpleVolume::getVoxel(const Vector3DInt32& v3dPos, bool bPerformBoundsChecks) const
{
- return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
+ return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), bPerformBoundsChecks);
}
////////////////////////////////////////////////////////////////////////////////