mirror of https://github.com/axmolengine/axmol.git
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:
commit
d37a43e100
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue