Added stream serialisation to Region.

This commit is contained in:
Daviw Williams 2013-05-07 15:41:26 +02:00
parent 055539ef75
commit 2a839e583d
2 changed files with 19 additions and 0 deletions

View File

@ -207,8 +207,13 @@ namespace PolyVox
int32_t m_iUpperZ;
};
// Non-member functions
bool intersects(const Region& a, const Region& b);
// Non-member overloaded operators.
/// Stream insertion operator.
std::ostream& operator<<(std::ostream& os, const Region& region);
// 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.
// See also http://www.parashift.com/c++-faq-lite/inline-functions.html

View File

@ -470,6 +470,7 @@ namespace PolyVox
/**
* 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.
@ -480,4 +481,17 @@ namespace PolyVox
// Overlapping on all axes means Regions are intersecting.
return true;
}
/**
* Enables the Region to be used intuitively with output streams such as cout.
* \param os The output stream to write to.
* \param region The Region to write to the stream.
* \return A reference to the output stream to allow chaining.
*/
std::ostream& operator<<(std::ostream& os, const Region& region)
{
os << "(" << region.getLowerX() << "," << region.getLowerY() << "," << region.getLowerZ() <<
") to (" << region.getUpperX() << "," << region.getUpperY() << "," << region.getUpperZ() << ")";
return os;
}
}