1
0
forked from 0ad/0ad

# Fixed minor shadow bug

CBound operator+= updated the minimum value or the maximum value, but
never both. (I think the operator+=(CVector3D) has always been buggy
(because it assumes min<max, which isn't true of empty bounds), and I
propagated the error to operator+=(CBound) ages ago.)
Added test cases, and fixed.

This was SVN commit r4244.
This commit is contained in:
Ykkrosh 2006-08-25 12:52:26 +00:00
parent 50e5e9acd9
commit 147d4f2bd3
4 changed files with 51 additions and 5 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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);
}
};

View File

@ -2,8 +2,12 @@
// "test"-specific PCH:
#if HAVE_PCH
#include "lib/self_test.h"
#include <cxxtest/TestListener.h>
#include <cxxtest/TestTracker.h>
#include <cxxtest/TestRunner.h>
#include <cxxtest/RealDescriptions.h>
#endif // HAVE_PCH