diff --git a/library/PolyVoxCore/include/PolyVoxCore/Region.h b/library/PolyVoxCore/include/PolyVoxCore/Region.h index 55c51ee4..655b3bce 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Region.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Region.h @@ -149,6 +149,9 @@ 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; + /// Tests whether the given Region is contained in this Region. + bool containsRegion(const Region& reg, 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. diff --git a/library/PolyVoxCore/source/Region.cpp b/library/PolyVoxCore/source/Region.cpp index 3db2edd6..444a1770 100644 --- a/library/PolyVoxCore/source/Region.cpp +++ b/library/PolyVoxCore/source/Region.cpp @@ -301,6 +301,23 @@ namespace PolyVox && (pos >= m_iLowerZ + boundary); } + /** + * The boundary value can be used to ensure a region is only considered to be inside + * another Region if it is that far in in all directions. Also, the test is inclusive such + * that a region is considered to be inside of itself. + * \param reg The region to test. + * \param boundary The desired boundary value. + */ + bool Region::containsRegion(const Region& reg, uint8_t boundary) const + { + return (reg.m_iUpperX <= m_iUpperX - boundary) + && (reg.m_iUpperY <= m_iUpperY - boundary) + && (reg.m_iUpperZ <= m_iUpperZ - boundary) + && (reg.m_iLowerX >= m_iLowerX + boundary) + && (reg.m_iLowerY >= m_iLowerY + boundary) + && (reg.m_iLowerZ >= m_iLowerZ + boundary); + } + /** * After calling this functions, the extents of this Region are given by the intersection * of this Region and the one it was cropped to.