diff --git a/library/PolyVoxCore/include/PolyVoxCore/Region.h b/library/PolyVoxCore/include/PolyVoxCore/Region.h index 3668d847..5c91390c 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Region.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Region.h @@ -44,6 +44,11 @@ namespace PolyVox Region(const Vector3DInt32& v3dLowerCorner, const Vector3DInt32& v3dUpperCorner); Region(int32_t iLowerX, int32_t iLowerY, int32_t iLowerZ, int32_t iUpperX, int32_t iUpperY, int32_t iUpperZ); + ///Equality Operator. + bool operator==(const Region& rhs) const throw(); + ///Inequality Operator. + bool operator!=(const Region& rhs) const throw(); + const Vector3DInt32& getLowerCorner(void) const; const Vector3DInt32& getUpperCorner(void) const; diff --git a/library/PolyVoxCore/include/PolyVoxCore/Vector.h b/library/PolyVoxCore/include/PolyVoxCore/Vector.h index 1269fe73..cbcdb6ec 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Vector.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Vector.h @@ -81,6 +81,8 @@ namespace PolyVox Vector& operator=(const Vector& rhs) throw(); ///Equality Operator. bool operator==(const Vector& rhs) const throw(); + ///Inequality Operator. + bool operator!=(const Vector& rhs) const throw(); ///Comparison Operator. bool operator<(const Vector& rhs) const throw(); ///Addition and Assignment Operator. diff --git a/library/PolyVoxCore/include/PolyVoxCore/Vector.inl b/library/PolyVoxCore/include/PolyVoxCore/Vector.inl index bd9dd88e..b6d92c15 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Vector.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Vector.inl @@ -150,6 +150,18 @@ namespace PolyVox return equal; } + /** + Checks whether two Vectors are not equal. + \param rhs The Vector to compare to. + \return true if the Vectors do not match. + \see operator== + */ + template + inline bool Vector::operator!=(const Vector &rhs) const throw() + { + return !(*this == rhs); //Just call equality operator and invert the result. + } + /** Checks whether this vector is less than the parameter. The metric is meaningless but it allows Vectors to me used as key in sdt::map, etc. diff --git a/library/PolyVoxCore/source/Region.cpp b/library/PolyVoxCore/source/Region.cpp index fcb4f6fd..436265b0 100644 --- a/library/PolyVoxCore/source/Region.cpp +++ b/library/PolyVoxCore/source/Region.cpp @@ -60,6 +60,28 @@ namespace PolyVox assert(m_v3dUpperCorner.getZ() >= m_v3dLowerCorner.getZ()); } + /** + Checks whether two Regions are equal. + \param rhs The Region to compare to. + \return true if the Regions match. + \see operator!= + */ + bool Region::operator==(const Region& rhs) const throw() + { + return ((m_v3dLowerCorner == rhs.m_v3dLowerCorner) && (m_v3dUpperCorner == rhs.m_v3dUpperCorner)); + } + + /** + Checks whether two Regions are not equal. + \param rhs The Region to compare to. + \return true if the Regions do not match. + \see operator== + */ + bool Region::operator!=(const Region& rhs) const throw() + { + return !(*this == rhs); + } + const Vector3DInt32& Region::getLowerCorner(void) const { return m_v3dLowerCorner; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 299ed23c..db002c91 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -59,10 +59,15 @@ ADD_TEST(VolumeSizeTest ${LATEST_TEST} testSize) CREATE_TEST(testmaterial.h testmaterial.cpp testmaterial) ADD_TEST(MaterialTestCompile ${LATEST_TEST} testCompile) +# Region tests +CREATE_TEST(TestRegion.h TestRegion.cpp TestRegion) +ADD_TEST(RegionEqualityTest ${LATEST_TEST} testEquality) + #Vector tests CREATE_TEST(testvector.h testvector.cpp testvector) ADD_TEST(VectorLengthTest ${LATEST_TEST} testLength) ADD_TEST(VectorDotProductTest ${LATEST_TEST} testDotProduct) +ADD_TEST(VectorEqualityTest ${LATEST_TEST} testEquality) # Volume subclass tests CREATE_TEST(TestVolumeSubclass.h TestVolumeSubclass.cpp TestVolumeSubclass) diff --git a/tests/TestRegion.cpp b/tests/TestRegion.cpp new file mode 100644 index 00000000..a0f74913 --- /dev/null +++ b/tests/TestRegion.cpp @@ -0,0 +1,42 @@ +/******************************************************************************* +Copyright (c) 2010 Matt Williams + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*******************************************************************************/ + +#include "TestRegion.h" + +#include "PolyVoxCore/Region.h" + +#include + +using namespace PolyVox; + +void TestRegion::testEquality() +{ + Region reg1(1,2,3,4,5,6); + Region reg2(0,0,0,10,20,30); + Region reg3(Vector3DInt32(1,2,3), Vector3DInt32(4,5,6)); + + QCOMPARE(reg1 != reg2, true); + QCOMPARE(reg1 == reg3, true); +} + +QTEST_MAIN(TestRegion) diff --git a/tests/TestRegion.h b/tests/TestRegion.h new file mode 100644 index 00000000..be3c29de --- /dev/null +++ b/tests/TestRegion.h @@ -0,0 +1,37 @@ +/******************************************************************************* +Copyright (c) 2010 Matt Williams + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*******************************************************************************/ + +#ifndef __PolyVox_TestRegion_H__ +#define __PolyVox_TestRegion_H__ + +#include + +class TestRegion: public QObject +{ + Q_OBJECT + + private slots: + void testEquality(); +}; + +#endif diff --git a/tests/testvector.cpp b/tests/testvector.cpp index 4f75bff6..0239bd0f 100644 --- a/tests/testvector.cpp +++ b/tests/testvector.cpp @@ -43,4 +43,12 @@ void TestVector::testDotProduct() QCOMPARE(vecxy.dot(vecz), int8_t(0)); //QCOMPARE is very strict on the types matching } +void TestVector::testEquality() +{ + Vector3DInt8 vecxy(3, 4, 0); + Vector3DInt8 vecz(0, 0, 1); + + QCOMPARE(vecxy != vecz, true); +} + QTEST_MAIN(TestVector) diff --git a/tests/testvector.h b/tests/testvector.h index f9aa2746..baad1e3d 100644 --- a/tests/testvector.h +++ b/tests/testvector.h @@ -33,6 +33,7 @@ class TestVector: public QObject private slots: void testLength(); void testDotProduct(); + void testEquality(); }; #endif