diff --git a/source/maths/Bound.cpp b/source/maths/Bound.cpp index 5cb2162710..3604dc5603 100644 --- a/source/maths/Bound.cpp +++ b/source/maths/Bound.cpp @@ -22,8 +22,9 @@ // operator+=: extend this bound to include given bound CBound& CBound::operator+=(const CBound& b) { -#define CMPT(c) if (b[0].c < m_Data[0].c) m_Data[0].c = b[0].c; \ - else if (b[1].c > m_Data[1].c) m_Data[1].c = b[1].c +#define CMPT(c) \ + if (b[0].c < m_Data[0].c) m_Data[0].c = b[0].c; \ + if (b[1].c > m_Data[1].c) m_Data[1].c = b[1].c CMPT(X); CMPT(Y); CMPT(Z); @@ -36,8 +37,9 @@ CBound& CBound::operator+=(const CBound& b) // operator+=: extend this bound to include given point CBound& CBound::operator+=(const CVector3D& pt) { -#define CMPT(c) if (pt.c < m_Data[0].c) m_Data[0].c = pt.c; \ - else if (pt.c > m_Data[1].c) m_Data[1].c = pt.c +#define CMPT(c) \ + if (pt.c < m_Data[0].c) m_Data[0].c = pt.c; \ + if (pt.c > m_Data[1].c) m_Data[1].c = pt.c CMPT(X); CMPT(Y); CMPT(Z); diff --git a/source/maths/Bound.h b/source/maths/Bound.h index 0de2c48337..02b0869820 100644 --- a/source/maths/Bound.h +++ b/source/maths/Bound.h @@ -20,7 +20,7 @@ class CFrustum; class CBound { public: - CBound() {} + CBound() { SetEmpty(); } CBound(const CVector3D& min,const CVector3D& max) { m_Data[0]=min; m_Data[1]=max; } diff --git a/source/maths/tests/test_Bound.h b/source/maths/tests/test_Bound.h new file mode 100644 index 0000000000..6c7e80d20d --- /dev/null +++ b/source/maths/tests/test_Bound.h @@ -0,0 +1,40 @@ +#include "lib/self_test.h" + +#include "maths/Bound.h" + +class TestBound : public CxxTest::TestSuite +{ +public: + void test_empty() + { + CBound bound; + TS_ASSERT(bound.IsEmpty()); + bound += CVector3D(1, 2, 3); + TS_ASSERT(! bound.IsEmpty()); + bound.SetEmpty(); + TS_ASSERT(bound.IsEmpty()); + } + + void test_extend_vector() + { + CBound bound; + CVector3D v (1, 2, 3); + bound += v; + + CVector3D centre; + bound.GetCentre(centre); + TS_ASSERT_EQUALS(centre, v); + } + + void test_extend_bound() + { + CBound bound; + CVector3D v (1, 2, 3); + CBound b (v, v); + bound += b; + + CVector3D centre; + bound.GetCentre(centre); + TS_ASSERT_EQUALS(centre, v); + } +}; diff --git a/source/pch/test/precompiled.h b/source/pch/test/precompiled.h index 1f990e198a..8a19191f0b 100644 --- a/source/pch/test/precompiled.h +++ b/source/pch/test/precompiled.h @@ -2,8 +2,12 @@ // "test"-specific PCH: +#if HAVE_PCH + #include "lib/self_test.h" #include #include #include #include + +#endif // HAVE_PCH