From 2a839e583d5e115c090248bdb14918201541cafb Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Tue, 7 May 2013 15:41:26 +0200 Subject: [PATCH] Added stream serialisation to Region. --- library/PolyVoxCore/include/PolyVoxCore/Region.h | 5 +++++ library/PolyVoxCore/source/Region.cpp | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Region.h b/library/PolyVoxCore/include/PolyVoxCore/Region.h index 32aa7715..a0b276cd 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Region.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Region.h @@ -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 diff --git a/library/PolyVoxCore/source/Region.cpp b/library/PolyVoxCore/source/Region.cpp index 32d8454d..bf60ceb2 100644 --- a/library/PolyVoxCore/source/Region.cpp +++ b/library/PolyVoxCore/source/Region.cpp @@ -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; + } }