diff --git a/library/PolyVoxCore/include/PolyVoxCore/Region.h b/library/PolyVoxCore/include/PolyVoxCore/Region.h index 65af8e65..39a12f6c 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Region.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Region.h @@ -141,6 +141,13 @@ namespace PolyVox /// Tests whether the given position is contained in the 'z' range of this Region. bool containsPointInZ(int32_t pos, uint8_t boundary = 0) const; + /// Enlarges the Region so that it contains the specified position. + void accumulate(int32_t iX, int32_t iY, int32_t iZ); + /// Enlarges the Region so that it contains the specified position. + void accumulate(const Vector3DInt32& v3dPos); + /// Enlarges the Region so that it contains the specified Region. + void accumulate(const Region& reg); + /// Crops the extents of this Region accoring to another Region. void cropTo(const Region& other); diff --git a/library/PolyVoxCore/source/Region.cpp b/library/PolyVoxCore/source/Region.cpp index 1a2003c7..c736999b 100644 --- a/library/PolyVoxCore/source/Region.cpp +++ b/library/PolyVoxCore/source/Region.cpp @@ -23,6 +23,7 @@ freely, subject to the following restrictions: #include "PolyVoxCore/Region.h" +#include #include namespace PolyVox @@ -46,6 +47,48 @@ namespace PolyVox Vector3DInt32((std::numeric_limits::min)(), (std::numeric_limits::min)(), (std::numeric_limits::min)()) ); + //////////////////////////////////////////////////////////////////////////////// + /// \param iX The 'x' component of the position to accumulate. + /// \param iY The 'y' component of the position to accumulate. + /// \param iZ The 'z' component of the position to accumulate. + //////////////////////////////////////////////////////////////////////////////// + void Region::accumulate(int32_t iX, int32_t iY, int32_t iZ) + { + m_iLowerX = ((std::min)(m_iLowerX, iX)); + m_iLowerY = ((std::min)(m_iLowerY, iY)); + m_iLowerZ = ((std::min)(m_iLowerZ, iZ)); + m_iUpperX = ((std::max)(m_iUpperX, iX)); + m_iUpperY = ((std::max)(m_iUpperY, iY)); + m_iUpperZ = ((std::max)(m_iUpperZ, iZ)); + } + + //////////////////////////////////////////////////////////////////////////////// + /// \param v3dPos The position to accumulate. + //////////////////////////////////////////////////////////////////////////////// + void Region::accumulate(const Vector3DInt32& v3dPos) + { + accumulate(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); + } + + //////////////////////////////////////////////////////////////////////////////// + /// Note that this is not the same as computing the union of two Regions (as the result of + /// such a union may not be a shape which can be exactly represented by a Region). Instead, + /// the result is simply big enough to contain both this Region and the one passed as a parameter. + /// \param reg The Region to accumulate. This must be valid as defined by the isValid() function. + /// \sa isValid() + //////////////////////////////////////////////////////////////////////////////// + void Region::accumulate(const Region& reg) + { + assert(reg.isValid(), "The result of accumulating an invalid region is not defined."); + + m_iLowerX = ((std::min)(m_iLowerX, reg.getLowerX())); + m_iLowerY = ((std::min)(m_iLowerY, reg.getLowerY())); + m_iLowerZ = ((std::min)(m_iLowerZ, reg.getLowerZ())); + m_iUpperX = ((std::max)(m_iUpperX, reg.getUpperX())); + m_iUpperY = ((std::max)(m_iUpperY, reg.getUpperY())); + m_iUpperZ = ((std::max)(m_iUpperZ, reg.getUpperZ())); + } + //////////////////////////////////////////////////////////////////////////////// /// Constructs a Region and clears all extents to zero. //////////////////////////////////////////////////////////////////////////////// @@ -229,7 +272,7 @@ namespace PolyVox } //////////////////////////////////////////////////////////////////////////////// - /// After calling this functions, the extents of this Region are given by the union + /// After calling this functions, the extents of this Region are given by the intersection /// of this Region and the one it was cropped to. /// \param other The Region to crop to. ////////////////////////////////////////////////////////////////////////////////