Added 'intersects' function to Region.

This commit is contained in:
David Williams 2013-01-14 23:13:17 +01:00
parent e05cb1fefc
commit 1d1dcc875a
2 changed files with 21 additions and 6 deletions

View File

@ -207,6 +207,8 @@ namespace PolyVox
int32_t m_iUpperZ; int32_t m_iUpperZ;
}; };
bool intersects(const Region& a, const Region& b);
// Functions to be inlined to to be in the header rather than the .cpp. // Functions to be inlined to to be in the header rather than the .cpp.
// 'inline' keyword is used for the definition rather than the declaration. // 'inline' keyword is used for the definition rather than the declaration.
// See also http://www.parashift.com/c++-faq-lite/inline-functions.html // See also http://www.parashift.com/c++-faq-lite/inline-functions.html

View File

@ -148,12 +148,12 @@ namespace PolyVox
&& (m_iUpperX == rhs.m_iUpperX) && (m_iUpperY == rhs.m_iUpperY) && (m_iUpperZ == rhs.m_iUpperZ)); && (m_iUpperX == rhs.m_iUpperX) && (m_iUpperY == rhs.m_iUpperY) && (m_iUpperZ == rhs.m_iUpperZ));
} }
//////////////////////////////////////////////////////////////////////////////// /**
/// Two regions are considered different if any of their extents differ. * Two regions are considered different if any of their extents differ.
/// \param rhs The Region to compare to. * \param rhs The Region to compare to.
/// \return true if the Regions are different. * \return true if the Regions are different.
/// \sa operator== * \sa operator==
//////////////////////////////////////////////////////////////////////////////// */
bool Region::operator!=(const Region& rhs) const bool Region::operator!=(const Region& rhs) const
{ {
return !(*this == rhs); return !(*this == rhs);
@ -468,4 +468,17 @@ namespace PolyVox
{ {
shrink(v3dAmount.getX(), v3dAmount.getY(), v3dAmount.getZ()); shrink(v3dAmount.getX(), v3dAmount.getY(), v3dAmount.getZ());
} }
/**
* This function only returns true if the regions are really intersecting and not simply touching.
*/
bool intersects(const Region& a, const Region& b)
{
// No intersection if seperated along an axis.
if(a.getUpperX() < b.getLowerX() || a.getLowerX() > b.getUpperX()) return false;
if(a.getUpperY() < b.getLowerY() || a.getLowerY() > b.getUpperY()) return false;
if(a.getUpperZ() < b.getLowerZ() || a.getLowerZ() > b.getUpperZ()) return false;
// Overlapping on all axes means Regions are intersecting.
return true;
}
} }