Commit 2616e60e authored by rogerborg's avatar rogerborg

https://sourceforge.net/tracker2/?func=detail&aid=2473523&group_id=74339&atid=540676

Fix bug in dimension2d::operator+=.  Add operator-= and have operator == use core::equals() while I'm in there.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1984 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 2a3eb2c2
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define __IRR_DIMENSION2D_H_INCLUDED__ #define __IRR_DIMENSION2D_H_INCLUDED__
#include "irrTypes.h" #include "irrTypes.h"
#include "irrMath.h" // for irr::core::equals()
namespace irr namespace irr
{ {
...@@ -26,7 +27,8 @@ namespace core ...@@ -26,7 +27,8 @@ namespace core
//! Equality operator //! Equality operator
bool operator==(const dimension2d<T>& other) const bool operator==(const dimension2d<T>& other) const
{ {
return Width == other.Width && Height == other.Height; return core::equals(Width, other.Width) &&
core::equals(Height, other.Height);
} }
//! Inequality operator //! Inequality operator
...@@ -72,14 +74,23 @@ namespace core ...@@ -72,14 +74,23 @@ namespace core
return dimension2d<T>(Width*scale, Height*scale); return dimension2d<T>(Width*scale, Height*scale);
} }
//! Add two dimensions //! Add another dimension to this one.
dimension2d<T>& operator+=(const dimension2d<T>& other) dimension2d<T>& operator+=(const dimension2d<T>& other)
{ {
Width *= other.Width; Width += other.Width;
Height *= other.Height; Height += other.Height;
return *this;
}
//! Subtract a dimension from this one
dimension2d<T>& operator-=(const dimension2d<T>& other)
{
Width -= other.Width;
Height -= other.Height;
return *this; return *this;
} }
//! Add two dimensions //! Add two dimensions
dimension2d<T> operator+(const dimension2d<T>& other) const dimension2d<T> operator+(const dimension2d<T>& other) const
{ {
......
...@@ -58,6 +58,7 @@ int main(int argumentCount, char * arguments[]) ...@@ -58,6 +58,7 @@ int main(int argumentCount, char * arguments[])
TEST(planeMatrix); TEST(planeMatrix);
TEST(fast_atof); TEST(fast_atof);
TEST(line2dIntersectWith); TEST(line2dIntersectWith);
TEST(testDimension2d);
TEST(drawPixel); TEST(drawPixel);
TEST(md2Animation); TEST(md2Animation);
TEST(guiDisabledMenu); TEST(guiDisabledMenu);
......
// Copyright (C) 2008 Colin MacDonald
// No rights reserved: this software is in the public domain.
#include "testUtils.h"
#include "irrlicht.h"
#include <assert.h>
using namespace irr;
using namespace core;
/** Some very basic testing of dimension2df:
operator+=
operator!= (and thus implicitly operator==) */
bool testDimension2d(void)
{
dimension2df dimension(100.f, 100.f);
const dimension2df addDimension(200.f, -200.f);
(void)(dimension += addDimension);
if(dimension != dimension2df(300.f, -100.f))
{
logTestString("dimension2df != produced unexpected result.\n");
assert(false);
return false;
}
(void)(dimension -= addDimension);
if(dimension != dimension2df(100.f, 100.f))
{
logTestString("dimension2df -= produced unexpected result.\n");
assert(false);
return false;
}
return true;
}
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
<Unit filename="sceneCollisionManager.cpp" /> <Unit filename="sceneCollisionManager.cpp" />
<Unit filename="sceneNodeAnimator.cpp" /> <Unit filename="sceneNodeAnimator.cpp" />
<Unit filename="softwareDevice.cpp" /> <Unit filename="softwareDevice.cpp" />
<Unit filename="testDimension2d.cpp" />
<Unit filename="testUtils.cpp" /> <Unit filename="testUtils.cpp" />
<Unit filename="testVector2d.cpp" /> <Unit filename="testVector2d.cpp" />
<Unit filename="testVector3d.cpp" /> <Unit filename="testVector3d.cpp" />
......
...@@ -225,6 +225,10 @@ ...@@ -225,6 +225,10 @@
RelativePath=".\softwareDevice.cpp" RelativePath=".\softwareDevice.cpp"
> >
</File> </File>
<File
RelativePath=".\testDimension2d.cpp"
>
</File>
<File <File
RelativePath=".\testUtils.cpp" RelativePath=".\testUtils.cpp"
> >
......
<?xml version="1.0" encoding="Windows-1252"?> <?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject <VisualStudioProject
ProjectType="Visual C++" ProjectType="Visual C++"
...@@ -221,6 +222,10 @@ ...@@ -221,6 +222,10 @@
RelativePath=".\softwareDevice.cpp" RelativePath=".\softwareDevice.cpp"
> >
</File> </File>
<File
RelativePath=".\testDimension2d.cpp"
>
</File>
<File <File
RelativePath=".\testUtils.cpp" RelativePath=".\testUtils.cpp"
> >
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment