Commit ea44396c authored by rogerborg's avatar rogerborg

Make the integral versions of irr::core::equals() do a direct == comparison...

Make the integral versions of irr::core::equals() do a direct == comparison when no explicit tolerance is specified, rather than using an implicit tolerance of 0.  The floating point versions are unchanged. New unit test added.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1999 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 7657b29e
...@@ -170,18 +170,31 @@ namespace core ...@@ -170,18 +170,31 @@ namespace core
return (a + tolerance >= b) && (a - tolerance <= b); return (a + tolerance >= b) && (a - tolerance <= b);
} }
//! returns if a equals b, taking possible rounding errors into account //! returns if a equals b, not using any rounding tolerance
inline bool equals(const s32 a, const s32 b, const s32 tolerance = 0) inline bool equals(const s32 a, const s32 b)
{
return (a == b);
}
//! returns if a equals b, not using any rounding tolerance
inline bool equals(const u32 a, const u32 b)
{
return (a == b);
}
//! returns if a equals b, taking an explicit rounding tolerance into account
inline bool equals(const s32 a, const s32 b, const s32 tolerance)
{ {
return (a + tolerance >= b) && (a - tolerance <= b); return (a + tolerance >= b) && (a - tolerance <= b);
} }
//! returns if a equals b, taking possible rounding errors into account //! returns if a equals b, taking an explicit rounding tolerance into account
inline bool equals(const u32 a, const u32 b, const u32 tolerance = 0) inline bool equals(const u32 a, const u32 b, const u32 tolerance)
{ {
return (a + tolerance >= b) && (a - tolerance <= b); return (a + tolerance >= b) && (a - tolerance <= b);
} }
//! returns if a equals zero, taking rounding errors into account //! returns if a equals zero, taking rounding errors into account
inline bool iszero(const f32 a, const f32 tolerance = ROUNDING_ERROR_32) inline bool iszero(const f32 a, const f32 tolerance = ROUNDING_ERROR_32)
{ {
......
...@@ -49,6 +49,7 @@ int main(int argumentCount, char * arguments[]) ...@@ -49,6 +49,7 @@ int main(int argumentCount, char * arguments[])
// (temporarily) to the beginning of the list, since each test runs in its own // (temporarily) to the beginning of the list, since each test runs in its own
// process. // process.
TEST(disambiguateTextures); // Normally you should run this first, since it validates the working directory. TEST(disambiguateTextures); // Normally you should run this first, since it validates the working directory.
TEST(irrCoreEquals);
TEST(sceneNodeAnimator); TEST(sceneNodeAnimator);
TEST(sceneCollisionManager); TEST(sceneCollisionManager);
TEST(collisionResponseAnimator); TEST(collisionResponseAnimator);
......
Test suite pass at GMT Mon Dec 29 12:52:03 2008 Test suite pass at GMT Mon Dec 29 13:31:01 2008
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
<Unit filename="drawPixel.cpp" /> <Unit filename="drawPixel.cpp" />
<Unit filename="exports.cpp" /> <Unit filename="exports.cpp" />
<Unit filename="fast_atof.cpp" /> <Unit filename="fast_atof.cpp" />
<Unit filename="irrCoreEquals.cpp" />
<Unit filename="guiDisabledMenu.cpp" /> <Unit filename="guiDisabledMenu.cpp" />
<Unit filename="line2dIntersectWith.cpp" /> <Unit filename="line2dIntersectWith.cpp" />
<Unit filename="main.cpp" /> <Unit filename="main.cpp" />
......
...@@ -197,6 +197,10 @@ ...@@ -197,6 +197,10 @@
RelativePath=".\guiDisabledMenu.cpp" RelativePath=".\guiDisabledMenu.cpp"
> >
</File> </File>
<File
RelativePath=".\irrCoreEquals.cpp"
>
</File>
<File <File
RelativePath=".\line2dIntersectWith.cpp" RelativePath=".\line2dIntersectWith.cpp"
> >
......
...@@ -190,6 +190,10 @@ ...@@ -190,6 +190,10 @@
RelativePath=".\fast_atof.cpp" RelativePath=".\fast_atof.cpp"
> >
</File> </File>
<File
RelativePath=".\irrCoreEquals.cpp"
>
</File>
<File <File
RelativePath=".\guiDisabledMenu.cpp" RelativePath=".\guiDisabledMenu.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