Merge pull request #2398 from lgb/float_comparison_issue

fixed #1935: Float comparison must not use "==" in the equal function of CCPoint and CCSize, we should compare float number by using epsilon and absolute difference.
This commit is contained in:
James Chen 2013-04-18 19:44:17 -07:00
commit d37a43e100
1 changed files with 4 additions and 2 deletions

View File

@ -57,7 +57,8 @@ void CCPoint::setPoint(float x, float y)
bool CCPoint::equals(const CCPoint& target) const
{
return ((x == target.x) && (y == target.y));
return (fabs(this->x - target.x) < FLT_EPSILON)
&& (fabs(this->y - target.y) < FLT_EPSILON);
}
// implementation of CCSize
@ -91,7 +92,8 @@ void CCSize::setSize(float width, float height)
bool CCSize::equals(const CCSize& target) const
{
return ((width == target.width) && (height == target.height));
return (fabs(this->width - target.width) < FLT_EPSILON)
&& (fabs(this->height - target.height) < FLT_EPSILON);
}
// implementation of CCRect